@platejs/ai 52.1.0 → 52.3.8

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.
@@ -1,8 +1,6 @@
1
- import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-Dyi5V2wm.js";
2
- import * as platejs0 from "platejs";
3
- import { Descendant, EditorNodesOptions, ExtendConfig, NodeEntry, OmitFirst, Path, PluginConfig, Range, RemoveNodesOptions, SlateEditor, TElement, TIdElement, TRange, TTableElement, TText } from "platejs";
1
+ import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-B_bqJoKL";
2
+ import { Descendant, EditorNodesOptions, ExtendConfig, NodeEntry, OmitFirst, Path, PluginConfig, Range, RemoveNodesOptions, SlateEditor, TElement as TElement$1, TIdElement, TRange, TTableElement, TText } from "platejs";
4
3
  import { DeserializeMdOptions, SerializeMdOptions } from "@platejs/markdown";
5
- import * as platejs_react0 from "platejs/react";
6
4
  import { OverrideEditor, PlateEditor, RenderNodeWrapperProps } from "platejs/react";
7
5
  import React from "react";
8
6
  import { ChatRequestOptions, UIMessage } from "ai";
@@ -11,18 +9,7 @@ import { TriggerComboboxPluginOptions } from "@platejs/combobox";
11
9
 
12
10
  //#region src/react/ai/AIPlugin.d.ts
13
11
  type AIPluginConfig = ExtendConfig<BaseAIPluginConfig>;
14
- declare const AIPlugin: platejs_react0.PlatePlugin<platejs0.PluginConfig<any, {}, {}, Record<any, {
15
- insertNodes: (nodes: platejs0.Descendant[], args_1?: {
16
- target?: platejs0.Path;
17
- } | undefined) => void;
18
- removeMarks: (args_0?: {
19
- at?: platejs0.TLocation;
20
- } | undefined) => void;
21
- removeNodes: (args_0?: {
22
- at?: platejs0.Path;
23
- } | undefined) => void;
24
- undo: () => void;
25
- }>, {}>>;
12
+ declare const AIPlugin: any;
26
13
  //#endregion
27
14
  //#region src/react/ai-chat/internal/types.d.ts
28
15
  type ToolName = 'comment' | 'edit' | 'generate';
@@ -71,10 +58,10 @@ declare const createFormattedBlocks: ({
71
58
  format,
72
59
  sourceBlock
73
60
  }: {
74
- blocks: TElement[];
61
+ blocks: TElement$1[];
75
62
  format: "all" | "none" | "single";
76
63
  sourceBlock: NodeEntry;
77
- }) => any[] | null;
64
+ }) => TElement$1[] | null;
78
65
  declare const replaceSelectionAIChat: (editor: PlateEditor, sourceEditor: SlateEditor, {
79
66
  format
80
67
  }?: {
@@ -151,87 +138,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
151
138
  removeAnchor: (options?: EditorNodesOptions) => void;
152
139
  };
153
140
  }>;
154
- declare const AIChatPlugin: platejs_react0.PlatePlugin<PluginConfig<"aiChat", {
155
- _blockChunks: string;
156
- _blockPath: Path | null;
157
- /** @private Using For streamInsertChunk */
158
- _mdxName: string | null;
159
- _replaceIds: string[];
160
- /** @private The Editor used to generate the AI response. */
161
- aiEditor: SlateEditor | null;
162
- chat: UseChatHelpers<ChatMessage>;
163
- chatNodes: TIdElement[];
164
- chatSelection: TRange | null;
165
- /** @deprecated Use api.aiChat.node({streaming:true}) instead */
166
- experimental_lastTextId: string | null;
167
- /**
168
- * Specifies how the assistant message is handled:
169
- *
170
- * - 'insert': Directly inserts content into the editor without preview.
171
- * - 'chat': Initiates an interactive session to review and refine content
172
- * before insertion.
173
- */
174
- mode: AIMode;
175
- open: boolean;
176
- /** Whether the AI response is currently streaming. Cursor mode only. */
177
- streaming: boolean;
178
- toolName: AIToolName;
179
- } & TriggerComboboxPluginOptions, {
180
- aiChat: {
181
- reset: OmitFirst<typeof resetAIChat>;
182
- submit: OmitFirst<typeof submitAIChat>;
183
- hide: (options?: {
184
- focus?: boolean;
185
- undo?: boolean;
186
- }) => void;
187
- node: (options?: EditorNodesOptions & {
188
- anchor?: boolean;
189
- streaming?: boolean;
190
- }) => NodeEntry | undefined;
191
- reload: () => void;
192
- show: () => void;
193
- stop: () => void;
194
- };
195
- } & Record<"aiChat", Pick<{
196
- reset: OmitFirst<typeof resetAIChat>;
197
- submit: OmitFirst<typeof submitAIChat>;
198
- hide: (options?: {
199
- focus?: boolean;
200
- undo?: boolean;
201
- }) => void;
202
- node: (options?: EditorNodesOptions & {
203
- anchor?: boolean;
204
- streaming?: boolean;
205
- }) => NodeEntry | undefined;
206
- reload: () => void;
207
- show: () => void;
208
- stop: () => void;
209
- }, "node" | "stop" | "reset" | "submit">> & Record<"aiChat", {
210
- hide: ({
211
- focus,
212
- undo
213
- }?: {
214
- focus?: boolean;
215
- undo?: boolean;
216
- }) => void;
217
- show: () => void;
218
- }>, {
219
- aiChat: {
220
- accept: OmitFirst<typeof acceptAIChat>;
221
- insertBelow: OmitFirst<typeof insertBelowAIChat>;
222
- replaceSelection: OmitFirst<typeof replaceSelectionAIChat>;
223
- removeAnchor: (options?: EditorNodesOptions) => void;
224
- };
225
- } & Record<"aiChat", {
226
- accept: () => void;
227
- insertBelow: (sourceEditor: SlateEditor, args_1?: {
228
- format?: "all" | "none" | "single";
229
- } | undefined) => void;
230
- removeAnchor: (options?: platejs0.RemoveNodesOptions | undefined) => void;
231
- replaceSelection: (sourceEditor: SlateEditor, args_1?: {
232
- format?: "all" | "none" | "single";
233
- } | undefined) => void;
234
- }>, {}>>;
141
+ declare const AIChatPlugin: any;
235
142
  //#endregion
236
143
  //#region src/react/ai-chat/withAIChat.d.ts
237
144
  declare const withAIChat: OverrideEditor<AIChatPluginConfig>;
@@ -245,7 +152,7 @@ declare const withAIChat: OverrideEditor<AIChatPluginConfig>;
245
152
  */
246
153
  declare const useAIChatEditor: (editor: SlateEditor, content: string, {
247
154
  parser
248
- }?: DeserializeMdOptions) => platejs0.Value;
155
+ }?: DeserializeMdOptions) => any;
249
156
  //#endregion
250
157
  //#region src/react/ai-chat/hooks/useChatChunk.d.ts
251
158
  declare const useChatChunk: ({
@@ -281,15 +188,10 @@ declare const useEditorChat: ({
281
188
  }: UseEditorChatOptions) => void;
282
189
  //#endregion
283
190
  //#region src/react/ai-chat/streaming/streamDeserializeInlineMd.d.ts
284
- declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) => platejs0.Descendant[];
191
+ declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) => any;
285
192
  //#endregion
286
193
  //#region src/react/ai-chat/streaming/streamDeserializeMd.d.ts
287
- declare const streamDeserializeMd: (editor: PlateEditor, data: string, options?: DeserializeMdOptions) => TElement[] | {
288
- children: {
289
- text: string;
290
- }[];
291
- type: string;
292
- }[];
194
+ declare const streamDeserializeMd: (editor: PlateEditor, data: string, options?: DeserializeMdOptions) => TElement[];
293
195
  //#endregion
294
196
  //#region src/react/ai-chat/streaming/streamInsertChunk.d.ts
295
197
  type SteamInsertChunkOptions = {
@@ -298,7 +200,7 @@ type SteamInsertChunkOptions = {
298
200
  };
299
201
  /** @experimental */
300
202
  declare function streamInsertChunk(editor: PlateEditor, chunk: string, options?: SteamInsertChunkOptions): void;
301
- declare const getCurrentBlockPath: (editor: SlateEditor) => Path;
203
+ declare const getCurrentBlockPath: (editor: SlateEditor) => any;
302
204
  //#endregion
303
205
  //#region src/react/ai-chat/streaming/streamSerializeMd.d.ts
304
206
  declare const streamSerializeMd: (editor: PlateEditor, options: SerializeMdOptions, chunk: string) => string;
@@ -307,10 +209,10 @@ declare const streamSerializeMd: (editor: PlateEditor, options: SerializeMdOptio
307
209
  declare const escapeInput: (data: string) => string;
308
210
  //#endregion
309
211
  //#region src/react/ai-chat/streaming/utils/getListNode.d.ts
310
- declare const getListNode: (editor: PlateEditor, node: TElement) => TElement;
212
+ declare const getListNode: (editor: PlateEditor, node: TElement$1) => TElement$1;
311
213
  //#endregion
312
214
  //#region src/react/ai-chat/streaming/utils/isSameNode.d.ts
313
- declare const isSameNode: (editor: PlateEditor, node1: TElement | TText, node2: TElement | TText) => boolean;
215
+ declare const isSameNode: (editor: PlateEditor, node1: TElement$1 | TText, node2: TElement$1 | TText) => boolean;
314
216
  //#endregion
315
217
  //#region src/react/ai-chat/streaming/utils/nodesWithProps.d.ts
316
218
  declare const nodesWithProps: (editor: PlateEditor, nodes: Descendant[], options: SteamInsertChunkOptions) => Descendant[];
@@ -348,8 +250,8 @@ type TableCellUpdate = {
348
250
  declare const applyTableCellSuggestion: (editor: SlateEditor, cellUpdate: TableCellUpdate) => void;
349
251
  //#endregion
350
252
  //#region src/react/ai-chat/utils/getLastAssistantMessage.d.ts
351
- declare function getLastAssistantMessage(editor: PlateEditor): ChatMessage | undefined;
352
- declare function useLastAssistantMessage(): ChatMessage | undefined;
253
+ declare function getLastAssistantMessage(editor: PlateEditor): any;
254
+ declare function useLastAssistantMessage(): any;
353
255
  //#endregion
354
256
  //#region src/react/ai-chat/utils/nestedContainerUtils.d.ts
355
257
  /** Check if nodes is a single table with single cell */
@@ -486,86 +388,7 @@ type CompletionState = {
486
388
  error?: Error | null;
487
389
  isLoading?: boolean;
488
390
  };
489
- declare const CopilotPlugin: platejs_react0.PlatePlugin<PluginConfig<"copilot", CompletionState & {
490
- /**
491
- * AI completion options. See:
492
- * {@link https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-completion#parameters | AI SDK UI useCompletion Parameters}
493
- */
494
- completeOptions?: Partial<CompleteOptions>;
495
- /**
496
- * Debounce delay for auto triggering AI completion.
497
- *
498
- * @default 0
499
- */
500
- debounceDelay?: number;
501
- /** Get the next word to be inserted. */
502
- getNextWord?: GetNextWord;
503
- /** Render the ghost text. */
504
- renderGhostText?: (() => React.ReactNode) | null;
505
- shouldAbort?: boolean;
506
- /** The node id where the suggestion is located. */
507
- suggestionNodeId?: string | null;
508
- /** The text of the suggestion. */
509
- suggestionText?: string | null;
510
- /**
511
- * Conditions to auto trigger copilot, used in addition to triggerQuery.
512
- * Disabling defaults to:
513
- *
514
- * - Block above is empty
515
- * - Block above ends with a space
516
- * - There is already a suggestion
517
- */
518
- autoTriggerQuery?: (options: {
519
- editor: PlateEditor;
520
- }) => boolean;
521
- /**
522
- * Get the prompt for AI completion.
523
- *
524
- * @default serializeMdNodes(editor.api.block({ highest: true }))
525
- */
526
- getPrompt?: (options: {
527
- editor: PlateEditor;
528
- }) => string;
529
- /**
530
- * Conditions to trigger copilot. Disabling defaults to:
531
- *
532
- * - Selection is expanded
533
- * - Selection is not at the end of block
534
- */
535
- triggerQuery?: (options: {
536
- editor: PlateEditor;
537
- }) => boolean;
538
- }, {
539
- copilot: {
540
- triggerSuggestion: OmitFirst<typeof triggerCopilotSuggestion>;
541
- reject: () => false | undefined;
542
- setBlockSuggestion: (options: {
543
- text: string;
544
- id?: string;
545
- }) => void;
546
- stop: () => void;
547
- };
548
- } & Record<"copilot", Omit<{
549
- triggerSuggestion: OmitFirst<typeof triggerCopilotSuggestion>;
550
- reject: () => false | undefined;
551
- setBlockSuggestion: (options: {
552
- text: string;
553
- id?: string;
554
- }) => void;
555
- stop: () => void;
556
- }, "reject">> & Record<"copilot", {
557
- reject: () => false | undefined;
558
- }>, {
559
- copilot: {
560
- accept: OmitFirst<typeof acceptCopilot>;
561
- acceptNextWord: OmitFirst<typeof acceptCopilotNextWord>;
562
- };
563
- } & Record<"copilot", {
564
- accept: () => false | undefined;
565
- acceptNextWord: () => false | undefined;
566
- }>, {
567
- isSuggested?: (id: string) => boolean;
568
- }>>;
391
+ declare const CopilotPlugin: any;
569
392
  //#endregion
570
393
  //#region src/react/copilot/renderCopilotBelowNodes.d.ts
571
394
  declare const renderCopilotBelowNodes: ({
@@ -3,11 +3,11 @@ import { ElementApi, KEYS, NodeApi, PathApi, RangeApi, TextApi, bindFirst, getPl
3
3
  import { SkipSuggestionDeletes, acceptSuggestion, diffToSuggestions, getSuggestionKey, getTransientSuggestionKey, rejectSuggestion } from "@platejs/suggestion";
4
4
  import { isSelecting } from "@platejs/selection";
5
5
  import { MarkdownPlugin, deserializeInlineMd, deserializeMd, serializeInlineMd, serializeMd } from "@platejs/markdown";
6
- import cloneDeep from "lodash/cloneDeep.js";
7
- import { createTPlatePlugin, getEditorPlugin as getEditorPlugin$1, toPlatePlugin, useEditorPlugin, usePluginOption } from "platejs/react";
6
+ import { createTPlatePlugin, getEditorPlugin, toPlatePlugin, useEditorPlugin, usePluginOption } from "platejs/react";
8
7
  import { distance } from "fastest-levenshtein";
9
8
  import { BlockSelectionPlugin, removeBlockSelectionNodes } from "@platejs/selection/react";
10
9
  import { SuggestionPlugin } from "@platejs/suggestion/react";
10
+ import cloneDeep from "lodash/cloneDeep.js";
11
11
  import { c } from "react-compiler-runtime";
12
12
  import React, { useEffect, useMemo, useRef } from "react";
13
13
  import debounce from "lodash/debounce.js";
@@ -171,7 +171,7 @@ const acceptAISuggestions = (editor) => {
171
171
  const acceptAIChat = (editor) => {
172
172
  const mode = editor.getOption(AIChatPlugin, "mode");
173
173
  if (mode === "insert") {
174
- const { tf } = getEditorPlugin$1(editor, AIPlugin);
174
+ const { tf } = getEditorPlugin(editor, AIPlugin);
175
175
  const api = editor.getApi({ key: KEYS.ai });
176
176
  const lastAINodePath = api.aiChat.node({
177
177
  at: [],
@@ -379,7 +379,7 @@ const rejectAISuggestions = (editor) => {
379
379
  //#endregion
380
380
  //#region src/react/ai-chat/utils/resetAIChat.ts
381
381
  const resetAIChat = (editor, { undo = true } = {}) => {
382
- const { api, getOptions, setOptions } = getEditorPlugin$1(editor, { key: KEYS.aiChat });
382
+ const { api, getOptions, setOptions } = getEditorPlugin(editor, { key: KEYS.aiChat });
383
383
  api.aiChat.stop();
384
384
  const chat = getOptions().chat;
385
385
  if (chat.messages && chat.messages.length > 0) chat.setMessages?.([]);
@@ -395,7 +395,7 @@ const resetAIChat = (editor, { undo = true } = {}) => {
395
395
  //#endregion
396
396
  //#region src/react/ai-chat/utils/submitAIChat.ts
397
397
  const submitAIChat = (editor, input, { mode, options, prompt, toolName: toolNameProps } = {}) => {
398
- const { getOptions, setOption } = getEditorPlugin$1(editor, { key: KEYS.aiChat });
398
+ const { getOptions, setOption } = getEditorPlugin(editor, { key: KEYS.aiChat });
399
399
  const { chat, toolName: toolNameOption } = getOptions();
400
400
  const toolName = toolNameProps ?? toolNameOption ?? null;
401
401
  if (!prompt && input?.length === 0) return;
@@ -1091,7 +1091,7 @@ const getCurrentBlockPath = (editor) => {
1091
1091
  //#endregion
1092
1092
  //#region src/react/copilot/renderCopilotBelowNodes.tsx
1093
1093
  const renderCopilotBelowNodes = ({ editor }) => {
1094
- const { renderGhostText: GhostText } = getEditorPlugin$1(editor, { key: KEYS.copilot }).getOptions();
1094
+ const { renderGhostText: GhostText } = getEditorPlugin(editor, { key: KEYS.copilot }).getOptions();
1095
1095
  if (!GhostText) return;
1096
1096
  return ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, children, /* @__PURE__ */ React.createElement(GhostText, null));
1097
1097
  };
@@ -1199,7 +1199,7 @@ const getNextWord = ({ text }) => {
1199
1199
  //#endregion
1200
1200
  //#region src/react/copilot/utils/triggerCopilotSuggestion.ts
1201
1201
  const triggerCopilotSuggestion = async (editor) => {
1202
- const { api, getOptions, setOption } = getEditorPlugin$1(editor, { key: KEYS.copilot });
1202
+ const { api, getOptions, setOption } = getEditorPlugin(editor, { key: KEYS.copilot });
1203
1203
  const { completeOptions, getPrompt, isLoading, triggerQuery } = getOptions();
1204
1204
  if (isLoading || editor.getOptions({ key: KEYS.aiChat }).chat?.isLoading) return false;
1205
1205
  if (!triggerQuery({ editor })) return false;
@@ -1234,7 +1234,7 @@ const withoutAbort = (editor, fn) => {
1234
1234
  //#endregion
1235
1235
  //#region src/react/copilot/transforms/acceptCopilotNextWord.ts
1236
1236
  const acceptCopilotNextWord = (editor) => {
1237
- const { api, getOptions } = getEditorPlugin$1(editor, { key: KEYS.copilot });
1237
+ const { api, getOptions } = getEditorPlugin(editor, { key: KEYS.copilot });
1238
1238
  const { getNextWord: getNextWord$1, suggestionText } = getOptions();
1239
1239
  if (!suggestionText?.length) return false;
1240
1240
  const { firstWord, remainingText } = getNextWord$1({ text: suggestionText });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platejs/ai",
3
- "version": "52.1.0",
3
+ "version": "52.3.8",
4
4
  "description": "Text AI plugin for Plate",
5
5
  "keywords": [
6
6
  "plate",
@@ -28,29 +28,19 @@
28
28
  "files": [
29
29
  "dist/**/*"
30
30
  ],
31
- "scripts": {
32
- "brl": "yarn p:brl",
33
- "build": "yarn p:build",
34
- "build:watch": "yarn p:build:watch",
35
- "clean": "yarn p:clean",
36
- "lint": "yarn p:lint",
37
- "lint:fix": "yarn p:lint:fix",
38
- "test": "yarn p:test",
39
- "test:watch": "yarn p:test:watch",
40
- "typecheck": "yarn p:typecheck"
41
- },
42
31
  "dependencies": {
43
- "@platejs/markdown": "52.1.0",
44
- "@platejs/selection": "52.0.16",
45
- "@platejs/suggestion": "52.0.11",
46
32
  "fastest-levenshtein": "1.0.16",
47
33
  "lodash": "^4.17.21",
48
- "react-compiler-runtime": "^1.0.0"
34
+ "react-compiler-runtime": "^1.0.0",
35
+ "@platejs/markdown": "^52.3.7",
36
+ "@platejs/selection": "^52.3.6",
37
+ "@platejs/suggestion": "^52.3.8",
38
+ "@platejs/table": "^52.3.6"
49
39
  },
50
40
  "devDependencies": {
51
41
  "@ai-sdk/react": "^3.0.0",
52
- "@platejs/combobox": "52.0.15",
53
- "ai": "^6.0.0"
42
+ "ai": "^6.0.0",
43
+ "@plate/scripts": "1.0.0"
54
44
  },
55
45
  "peerDependencies": {
56
46
  "platejs": ">=52.0.15",
@@ -61,5 +51,16 @@
61
51
  "access": "public"
62
52
  },
63
53
  "type": "module",
64
- "module": "./dist/index.js"
65
- }
54
+ "module": "./dist/index.js",
55
+ "scripts": {
56
+ "brl": "plate-pkg p:brl",
57
+ "build": "plate-pkg p:build",
58
+ "build:watch": "plate-pkg p:build:watch",
59
+ "clean": "plate-pkg p:clean",
60
+ "lint": "plate-pkg p:lint",
61
+ "lint:fix": "plate-pkg p:lint:fix",
62
+ "test": "plate-pkg p:test",
63
+ "test:watch": "plate-pkg p:test:watch",
64
+ "typecheck": "plate-pkg p:typecheck"
65
+ }
66
+ }