@platejs/ai 53.1.6 → 53.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-tNeux7Mo.d.ts → index-D2hJDomP.d.ts} +13 -13
- package/dist/index.d.ts +1 -1
- package/dist/react/index.d.ts +22 -22
- package/dist/react/index.js +42 -1
- package/package.json +17 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as platejs0 from "platejs";
|
|
2
2
|
import { Descendant, History, OmitFirst, Path, PluginConfig, SlateEditor, TLocation, Value } from "platejs";
|
|
3
3
|
|
|
4
4
|
//#region src/lib/transforms/aiStreamSnapshot.d.ts
|
|
@@ -67,31 +67,31 @@ type BaseAIPluginConfig = PluginConfig<'ai', {}, {}, {
|
|
|
67
67
|
undo: OmitFirst<typeof undoAI>;
|
|
68
68
|
};
|
|
69
69
|
}>;
|
|
70
|
-
declare const BaseAIPlugin:
|
|
70
|
+
declare const BaseAIPlugin: platejs0.SlatePlugin<PluginConfig<"ai", {}, {}, {
|
|
71
71
|
ai: {
|
|
72
|
-
acceptPreview: ((_value?:
|
|
72
|
+
acceptPreview: ((_value?: platejs0.Value | undefined) => boolean) & ((_value?: platejs0.Value | undefined) => boolean);
|
|
73
73
|
beginPreview: ((args_0?: {
|
|
74
|
-
originalBlocks?:
|
|
74
|
+
originalBlocks?: platejs0.Value;
|
|
75
75
|
} | undefined) => boolean) & ((args_0?: {
|
|
76
|
-
originalBlocks?:
|
|
76
|
+
originalBlocks?: platejs0.Value;
|
|
77
77
|
} | undefined) => boolean);
|
|
78
78
|
cancelPreview: (() => boolean) & (() => boolean);
|
|
79
79
|
discardPreview: (() => boolean) & (() => boolean);
|
|
80
80
|
hasPreview: (() => boolean) & (() => boolean);
|
|
81
|
-
insertNodes: ((nodes:
|
|
82
|
-
target?:
|
|
83
|
-
} | undefined) => void) & ((nodes:
|
|
84
|
-
target?:
|
|
81
|
+
insertNodes: ((nodes: platejs0.Descendant[], args_1?: {
|
|
82
|
+
target?: platejs0.Path;
|
|
83
|
+
} | undefined) => void) & ((nodes: platejs0.Descendant[], args_1?: {
|
|
84
|
+
target?: platejs0.Path;
|
|
85
85
|
} | undefined) => void);
|
|
86
86
|
removeMarks: ((args_0?: {
|
|
87
|
-
at?:
|
|
87
|
+
at?: platejs0.TLocation;
|
|
88
88
|
} | undefined) => void) & ((args_0?: {
|
|
89
|
-
at?:
|
|
89
|
+
at?: platejs0.TLocation;
|
|
90
90
|
} | undefined) => void);
|
|
91
91
|
removeNodes: ((args_0?: {
|
|
92
|
-
at?:
|
|
92
|
+
at?: platejs0.Path;
|
|
93
93
|
} | undefined) => void) & ((args_0?: {
|
|
94
|
-
at?:
|
|
94
|
+
at?: platejs0.Path;
|
|
95
95
|
} | undefined) => void);
|
|
96
96
|
undo: (() => void) & (() => void);
|
|
97
97
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as hasAIPreview, S as discardAIPreview, _ as insertAINodes, a as EditorPromptParams, b as beginAIPreview, c as AIMode, d as BaseAIPluginConfig, f as AIBatch, g as removeAIMarks, h as removeAINodes, i as EditorPrompt, l as AIToolName, m as undoAI, n as MarkdownType, o as PromptConfig, p as withAIBatch, r as replacePlaceholders, s as getEditorPrompt, t as getMarkdown, u as BaseAIPlugin, v as AI_PREVIEW_KEY, x as cancelAIPreview, y as acceptAIPreview } from "./index-
|
|
1
|
+
import { C as hasAIPreview, S as discardAIPreview, _ as insertAINodes, a as EditorPromptParams, b as beginAIPreview, c as AIMode, d as BaseAIPluginConfig, f as AIBatch, g as removeAIMarks, h as removeAINodes, i as EditorPrompt, l as AIToolName, m as undoAI, n as MarkdownType, o as PromptConfig, p as withAIBatch, r as replacePlaceholders, s as getEditorPrompt, t as getMarkdown, u as BaseAIPlugin, v as AI_PREVIEW_KEY, x as cancelAIPreview, y as acceptAIPreview } from "./index-D2hJDomP";
|
|
2
2
|
export { AIBatch, AIMode, AIToolName, AI_PREVIEW_KEY, BaseAIPlugin, BaseAIPluginConfig, EditorPrompt, EditorPromptParams, MarkdownType, PromptConfig, acceptAIPreview, beginAIPreview, cancelAIPreview, discardAIPreview, getEditorPrompt, getMarkdown, hasAIPreview, insertAINodes, removeAIMarks, removeAINodes, replacePlaceholders, undoAI, withAIBatch };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-
|
|
2
|
-
import * as
|
|
1
|
+
import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-D2hJDomP";
|
|
2
|
+
import * as platejs13 from "platejs";
|
|
3
3
|
import { Descendant, EditorNodesOptions, ExtendConfig, NodeEntry, OmitFirst, Path, PluginConfig, Range, RemoveNodesOptions, SlateEditor, TElement, TIdElement, TRange, TTableElement, TText } from "platejs";
|
|
4
4
|
import { DeserializeMdOptions, SerializeMdOptions } from "@platejs/markdown";
|
|
5
|
-
import * as
|
|
5
|
+
import * as platejs_react1 from "platejs/react";
|
|
6
6
|
import { OverrideEditor, PlateEditor, RenderNodeWrapperProps } from "platejs/react";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { ChatRequestOptions, UIMessage } from "ai";
|
|
@@ -11,31 +11,31 @@ import { TriggerComboboxPluginOptions } from "@platejs/combobox";
|
|
|
11
11
|
|
|
12
12
|
//#region src/react/ai/AIPlugin.d.ts
|
|
13
13
|
type AIPluginConfig = ExtendConfig<BaseAIPluginConfig>;
|
|
14
|
-
declare const AIPlugin:
|
|
14
|
+
declare const AIPlugin: platejs_react1.PlatePlugin<platejs13.PluginConfig<"ai", {}, {}, {
|
|
15
15
|
ai: {
|
|
16
|
-
acceptPreview: ((_value?:
|
|
16
|
+
acceptPreview: ((_value?: platejs13.Value | undefined) => boolean) & ((_value?: platejs13.Value | undefined) => boolean);
|
|
17
17
|
beginPreview: ((args_0?: {
|
|
18
|
-
originalBlocks?:
|
|
18
|
+
originalBlocks?: platejs13.Value;
|
|
19
19
|
} | undefined) => boolean) & ((args_0?: {
|
|
20
|
-
originalBlocks?:
|
|
20
|
+
originalBlocks?: platejs13.Value;
|
|
21
21
|
} | undefined) => boolean);
|
|
22
22
|
cancelPreview: (() => boolean) & (() => boolean);
|
|
23
23
|
discardPreview: (() => boolean) & (() => boolean);
|
|
24
24
|
hasPreview: (() => boolean) & (() => boolean);
|
|
25
|
-
insertNodes: ((nodes:
|
|
26
|
-
target?:
|
|
27
|
-
} | undefined) => void) & ((nodes:
|
|
28
|
-
target?:
|
|
25
|
+
insertNodes: ((nodes: platejs13.Descendant[], args_1?: {
|
|
26
|
+
target?: platejs13.Path;
|
|
27
|
+
} | undefined) => void) & ((nodes: platejs13.Descendant[], args_1?: {
|
|
28
|
+
target?: platejs13.Path;
|
|
29
29
|
} | undefined) => void);
|
|
30
30
|
removeMarks: ((args_0?: {
|
|
31
|
-
at?:
|
|
31
|
+
at?: platejs13.TLocation;
|
|
32
32
|
} | undefined) => void) & ((args_0?: {
|
|
33
|
-
at?:
|
|
33
|
+
at?: platejs13.TLocation;
|
|
34
34
|
} | undefined) => void);
|
|
35
35
|
removeNodes: ((args_0?: {
|
|
36
|
-
at?:
|
|
36
|
+
at?: platejs13.Path;
|
|
37
37
|
} | undefined) => void) & ((args_0?: {
|
|
38
|
-
at?:
|
|
38
|
+
at?: platejs13.Path;
|
|
39
39
|
} | undefined) => void);
|
|
40
40
|
undo: (() => void) & (() => void);
|
|
41
41
|
};
|
|
@@ -168,7 +168,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
|
|
|
168
168
|
removeAnchor: (options?: EditorNodesOptions) => void;
|
|
169
169
|
};
|
|
170
170
|
}>;
|
|
171
|
-
declare const AIChatPlugin:
|
|
171
|
+
declare const AIChatPlugin: platejs_react1.PlatePlugin<PluginConfig<"aiChat", {
|
|
172
172
|
_blockChunks: string;
|
|
173
173
|
_blockPath: Path | null;
|
|
174
174
|
/** @private Using For streamInsertChunk */
|
|
@@ -223,7 +223,7 @@ declare const AIChatPlugin: platejs_react0.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
223
223
|
reload: () => void;
|
|
224
224
|
show: () => void;
|
|
225
225
|
stop: () => void;
|
|
226
|
-
}, "node" | "
|
|
226
|
+
}, "node" | "reset" | "stop" | "submit">> & Record<"aiChat", {
|
|
227
227
|
hide: ({
|
|
228
228
|
focus,
|
|
229
229
|
undo
|
|
@@ -244,7 +244,7 @@ declare const AIChatPlugin: platejs_react0.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
244
244
|
insertBelow: (sourceEditor: SlateEditor, args_1?: {
|
|
245
245
|
format?: "all" | "none" | "single";
|
|
246
246
|
} | undefined) => void;
|
|
247
|
-
removeAnchor: (options?:
|
|
247
|
+
removeAnchor: (options?: platejs13.RemoveNodesOptions | undefined) => void;
|
|
248
248
|
replaceSelection: (sourceEditor: SlateEditor, args_1?: {
|
|
249
249
|
format?: "all" | "none" | "single";
|
|
250
250
|
} | undefined) => void;
|
|
@@ -262,7 +262,7 @@ declare const withAIChat: OverrideEditor<AIChatPluginConfig>;
|
|
|
262
262
|
*/
|
|
263
263
|
declare const useAIChatEditor: (editor: SlateEditor, content: string, {
|
|
264
264
|
parser
|
|
265
|
-
}?: DeserializeMdOptions) =>
|
|
265
|
+
}?: DeserializeMdOptions) => platejs13.Value;
|
|
266
266
|
//#endregion
|
|
267
267
|
//#region src/react/ai-chat/hooks/useChatChunk.d.ts
|
|
268
268
|
declare const useChatChunk: ({
|
|
@@ -298,7 +298,7 @@ declare const useEditorChat: ({
|
|
|
298
298
|
}: UseEditorChatOptions) => void;
|
|
299
299
|
//#endregion
|
|
300
300
|
//#region src/react/ai-chat/streaming/streamDeserializeInlineMd.d.ts
|
|
301
|
-
declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) =>
|
|
301
|
+
declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) => platejs13.Descendant[] | {
|
|
302
302
|
text: string;
|
|
303
303
|
}[];
|
|
304
304
|
//#endregion
|
|
@@ -317,7 +317,7 @@ type SteamInsertChunkOptions = {
|
|
|
317
317
|
};
|
|
318
318
|
declare const getInsertPreviewStart: (editor: SlateEditor) => {
|
|
319
319
|
path: Path;
|
|
320
|
-
startBlock:
|
|
320
|
+
startBlock: platejs13.TElement | platejs13.TText | undefined;
|
|
321
321
|
startInEmptyParagraph: boolean;
|
|
322
322
|
};
|
|
323
323
|
/** @experimental */
|
|
@@ -510,7 +510,7 @@ type CompletionState = {
|
|
|
510
510
|
error?: Error | null;
|
|
511
511
|
isLoading?: boolean;
|
|
512
512
|
};
|
|
513
|
-
declare const CopilotPlugin:
|
|
513
|
+
declare const CopilotPlugin: platejs_react1.PlatePlugin<PluginConfig<"copilot", CompletionState & {
|
|
514
514
|
/**
|
|
515
515
|
* AI completion options. See:
|
|
516
516
|
* {@link https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-completion#parameters | AI SDK UI useCompletion Parameters}
|
package/dist/react/index.js
CHANGED
|
@@ -947,6 +947,7 @@ const withoutDeserializeInMdx = (editor, input) => {
|
|
|
947
947
|
|
|
948
948
|
//#endregion
|
|
949
949
|
//#region src/react/ai-chat/streaming/streamSerializeMd.ts
|
|
950
|
+
const STREAM_LINE_BREAK_PLACEHOLDER = "platejs-stream-line-break";
|
|
950
951
|
const trimEndHeading = (editor, value) => {
|
|
951
952
|
const headingKeys = new Set([
|
|
952
953
|
KEYS.h1,
|
|
@@ -977,9 +978,40 @@ const trimEndHeading = (editor, value) => {
|
|
|
977
978
|
value
|
|
978
979
|
};
|
|
979
980
|
};
|
|
981
|
+
const escapeEmbeddedTextLineBreaks = (nodes) => {
|
|
982
|
+
let hasLineBreaks = false;
|
|
983
|
+
const value = nodes.map((node) => {
|
|
984
|
+
if (TextApi.isText(node)) {
|
|
985
|
+
if (node.text !== "\n" && node.text.includes("\n")) {
|
|
986
|
+
hasLineBreaks = true;
|
|
987
|
+
return {
|
|
988
|
+
...node,
|
|
989
|
+
text: node.text.replaceAll("\n", STREAM_LINE_BREAK_PLACEHOLDER)
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
return node;
|
|
993
|
+
}
|
|
994
|
+
if (ElementApi.isElement(node)) {
|
|
995
|
+
const escapedChildren = escapeEmbeddedTextLineBreaks(node.children);
|
|
996
|
+
if (escapedChildren.hasLineBreaks) {
|
|
997
|
+
hasLineBreaks = true;
|
|
998
|
+
return {
|
|
999
|
+
...node,
|
|
1000
|
+
children: escapedChildren.value
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return node;
|
|
1005
|
+
});
|
|
1006
|
+
return {
|
|
1007
|
+
hasLineBreaks,
|
|
1008
|
+
value
|
|
1009
|
+
};
|
|
1010
|
+
};
|
|
980
1011
|
const streamSerializeMd = (editor, options, chunk) => {
|
|
981
1012
|
const { value: optionsValue, ...restOptions } = options;
|
|
982
|
-
const { value } = trimEndHeading(editor, optionsValue ?? editor.children);
|
|
1013
|
+
const { value: trimmedValue } = trimEndHeading(editor, optionsValue ?? editor.children);
|
|
1014
|
+
const { hasLineBreaks, value } = escapeEmbeddedTextLineBreaks(trimmedValue);
|
|
983
1015
|
let result = "";
|
|
984
1016
|
result = editor.getApi(MarkdownPlugin).markdown.serialize({
|
|
985
1017
|
value,
|
|
@@ -991,6 +1023,15 @@ const streamSerializeMd = (editor, options, chunk) => {
|
|
|
991
1023
|
result = result.replace(/ /g, " ");
|
|
992
1024
|
result = result.replace(/​/g, " ");
|
|
993
1025
|
result = result.replace(/\u200B/g, "");
|
|
1026
|
+
if (hasLineBreaks) result = result.replaceAll(STREAM_LINE_BREAK_PLACEHOLDER, "\n");
|
|
1027
|
+
if (trimmedChunk.includes("\n") && trimmedChunk !== "\n\n") {
|
|
1028
|
+
const trimmedResult = result.trimEnd();
|
|
1029
|
+
if (trimmedResult.endsWith("\n<br />")) result = trimmedResult.slice(0, -6);
|
|
1030
|
+
else {
|
|
1031
|
+
const trailingWhitespaceBreakSuffix = `${trimmedChunk}\n`;
|
|
1032
|
+
if (result.endsWith(trailingWhitespaceBreakSuffix)) result = result.slice(0, -trailingWhitespaceBreakSuffix.length);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
994
1035
|
if (trimmedChunk !== "\n\n") result = result.trimEnd() + trimmedChunk;
|
|
995
1036
|
if (chunk.endsWith("\n\n")) {
|
|
996
1037
|
if (result === "\n") result = "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platejs/ai",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.3.0",
|
|
4
4
|
"description": "Text AI plugin for Plate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plate",
|
|
@@ -32,22 +32,32 @@
|
|
|
32
32
|
"fastest-levenshtein": "1.0.16",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"react-compiler-runtime": "^1.0.0",
|
|
35
|
-
"@platejs/markdown": "^53.
|
|
35
|
+
"@platejs/markdown": "^53.2.2",
|
|
36
36
|
"@platejs/selection": "^53.1.6",
|
|
37
|
-
"@platejs/
|
|
38
|
-
"@platejs/
|
|
37
|
+
"@platejs/table": "^53.0.9",
|
|
38
|
+
"@platejs/suggestion": "^53.2.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@ai-sdk/react": "^
|
|
42
|
-
"ai": "^
|
|
41
|
+
"@ai-sdk/react": "^4.0.0",
|
|
42
|
+
"ai": "^7.0.0",
|
|
43
43
|
"@plate/scripts": "1.0.0",
|
|
44
|
-
"platejs": "^53.
|
|
44
|
+
"platejs": "^53.2.4"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
+
"@ai-sdk/react": "^4.0.0",
|
|
48
|
+
"ai": "^7.0.0",
|
|
47
49
|
"platejs": ">=53.0.7",
|
|
48
50
|
"react": ">=18.0.0",
|
|
49
51
|
"react-dom": ">=18.0.0"
|
|
50
52
|
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@ai-sdk/react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"ai": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
},
|
|
51
61
|
"publishConfig": {
|
|
52
62
|
"access": "public"
|
|
53
63
|
},
|