@copilotkit/react-textarea 0.35.0-multi-feature-usecopilotreadable.3 → 0.35.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/.turbo/turbo-build.log +428 -428
- package/CHANGELOG.md +100 -4
- package/dist/{chunk-3B3LGEDJ.mjs → chunk-COQISBP2.mjs} +2 -2
- package/dist/{chunk-FWZ23PN7.mjs → chunk-DMLXXOXD.mjs} +2 -2
- package/dist/{chunk-VPEH6V7T.mjs → chunk-FMQG2ZM3.mjs} +1 -1
- package/dist/chunk-FMQG2ZM3.mjs.map +1 -0
- package/dist/{chunk-Y5LVLSUK.mjs → chunk-OGLVRSCO.mjs} +7 -7
- package/dist/{chunk-HXEH4QQL.mjs → chunk-PQIOU3E5.mjs} +5 -5
- package/dist/{chunk-RT4UTBH3.mjs → chunk-SJ2TM5GA.mjs} +6 -2
- package/dist/chunk-SJ2TM5GA.mjs.map +1 -0
- package/dist/{chunk-QFG55HEW.mjs → chunk-XU5Z5BWV.mjs} +20 -20
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +16 -16
- package/dist/components/copilot-textarea/copilot-textarea.js +5 -1
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +23 -23
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +5 -5
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +3 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +4 -4
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +4 -4
- package/dist/components/index.js +5 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +23 -23
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +5 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -27
- package/package.json +6 -6
- package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +4 -1
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +6 -1
- package/dist/chunk-RT4UTBH3.mjs.map +0 -1
- package/dist/chunk-VPEH6V7T.mjs.map +0 -1
- /package/dist/{chunk-3B3LGEDJ.mjs.map → chunk-COQISBP2.mjs.map} +0 -0
- /package/dist/{chunk-FWZ23PN7.mjs.map → chunk-DMLXXOXD.mjs.map} +0 -0
- /package/dist/{chunk-Y5LVLSUK.mjs.map → chunk-OGLVRSCO.mjs.map} +0 -0
- /package/dist/{chunk-HXEH4QQL.mjs.map → chunk-PQIOU3E5.mjs.map} +0 -0
- /package/dist/{chunk-QFG55HEW.mjs.map → chunk-XU5Z5BWV.mjs.map} +0 -0
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import "../chunk-MMVDU6DF.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotTextarea
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-PQIOU3E5.mjs";
|
|
5
|
+
import "../chunk-SJ2TM5GA.mjs";
|
|
6
6
|
import "../chunk-QCPS6IYI.mjs";
|
|
7
|
+
import "../chunk-RUV6NBIF.mjs";
|
|
8
|
+
import "../chunk-DKE57EAC.mjs";
|
|
9
|
+
import "../chunk-4OJ3H65F.mjs";
|
|
10
|
+
import "../chunk-RKQ6RTZM.mjs";
|
|
11
|
+
import "../chunk-KDVMG3XF.mjs";
|
|
7
12
|
import {
|
|
8
13
|
BaseCopilotTextarea
|
|
9
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-XU5Z5BWV.mjs";
|
|
15
|
+
import "../chunk-DRV2FOHZ.mjs";
|
|
16
|
+
import "../chunk-4NHVQZ67.mjs";
|
|
17
|
+
import "../chunk-FMQG2ZM3.mjs";
|
|
10
18
|
import "../chunk-2C7O2EVM.mjs";
|
|
11
19
|
import "../chunk-GQN2HYFJ.mjs";
|
|
20
|
+
import "../chunk-5UNJXFUO.mjs";
|
|
21
|
+
import "../chunk-QKS2IOUH.mjs";
|
|
22
|
+
import "../chunk-JJLQVT7S.mjs";
|
|
23
|
+
import "../chunk-LQ2OWQU7.mjs";
|
|
12
24
|
import "../chunk-7LSRNPNI.mjs";
|
|
13
|
-
import "../chunk-
|
|
25
|
+
import "../chunk-DMLXXOXD.mjs";
|
|
14
26
|
import "../chunk-L7VVZH4Q.mjs";
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-
|
|
27
|
+
import "../chunk-COQISBP2.mjs";
|
|
28
|
+
import "../chunk-OGLVRSCO.mjs";
|
|
17
29
|
import "../chunk-YNXNMCDX.mjs";
|
|
30
|
+
import "../chunk-3PQ7GSFE.mjs";
|
|
31
|
+
import "../chunk-WFTAAA7R.mjs";
|
|
18
32
|
import "../chunk-YFK5BFEI.mjs";
|
|
19
33
|
import "../chunk-LYB4B6MK.mjs";
|
|
20
34
|
import "../chunk-CF5GISTC.mjs";
|
|
21
35
|
import "../chunk-4OZR65UB.mjs";
|
|
22
36
|
import "../chunk-FFSICDS5.mjs";
|
|
23
37
|
import "../chunk-4HBKWUCT.mjs";
|
|
24
|
-
import "../chunk-WFTAAA7R.mjs";
|
|
25
|
-
import "../chunk-3PQ7GSFE.mjs";
|
|
26
|
-
import "../chunk-224UKA7C.mjs";
|
|
27
|
-
import "../chunk-XW3ICO4S.mjs";
|
|
28
|
-
import "../chunk-LQ2OWQU7.mjs";
|
|
29
38
|
import "../chunk-2QDCE7PD.mjs";
|
|
30
|
-
import "../chunk-
|
|
31
|
-
import "../chunk-DKE57EAC.mjs";
|
|
32
|
-
import "../chunk-4OJ3H65F.mjs";
|
|
33
|
-
import "../chunk-RKQ6RTZM.mjs";
|
|
34
|
-
import "../chunk-KDVMG3XF.mjs";
|
|
39
|
+
import "../chunk-7SUZ6CXM.mjs";
|
|
35
40
|
import "../chunk-WJHSY5T6.mjs";
|
|
36
41
|
import "../chunk-LCDTIJSD.mjs";
|
|
37
|
-
import "../chunk-
|
|
38
|
-
import "../chunk-
|
|
39
|
-
import "../chunk-7SUZ6CXM.mjs";
|
|
40
|
-
import "../chunk-DRV2FOHZ.mjs";
|
|
41
|
-
import "../chunk-4NHVQZ67.mjs";
|
|
42
|
-
import "../chunk-VPEH6V7T.mjs";
|
|
43
|
-
import "../chunk-5UNJXFUO.mjs";
|
|
42
|
+
import "../chunk-224UKA7C.mjs";
|
|
43
|
+
import "../chunk-XW3ICO4S.mjs";
|
|
44
44
|
import "../chunk-DFTV4TST.mjs";
|
|
45
45
|
import "../chunk-T6MTDQZ7.mjs";
|
|
46
46
|
import "../chunk-ECR45NSD.mjs";
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts","../../../src/lib/get-text-around-cursor.ts","../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(\n ref,\n () => {\n class Combined {\n constructor(private customMethods: CustomMethods, private editorHtmlElement: HTMLElement) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n },\n [editor],\n );\n}\n","import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n","import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,yBAA4B;;;ACF5B,mBAAsF;AAuE/E,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,oBAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,oBAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACA,SAAO,wBAAwB,QAAQ,iBAAiB;AAC1D;AAGO,SAAS,wBAAwB,QAAgB,OAAsB;AAC5E,QAAM,QAAQ;AACd,QAAM,CAAC,OAAO,GAAG,IAAI,mBAAM,MAAM,KAAK;AACtC,MAAI,OAAO;AACX,MAAI,YAAyB;AAE7B,aA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AY,MAAM,KAAK,MAAM;AAAA,QAC/B;AAAA,QAEA,OAAO;AACL,yCAAY,KAAK,KAAK,MAAM;AAAA,QAC9B;AAAA,QAEA,IAAI,QAAQ;AACV,iBAAO,8BAA8B,KAAK,MAAM;AAAA,QAClD;AAAA,QACA,IAAI,MAAM,OAAe;AACvB,4BAAkB,KAAK,QAAQ,KAAK;AAAA,QACtC;AAAA,MACF;AAEA,YAAM,oBAAoB,+BAAY,UAAU,QAAQ,MAAM;AAC9D,YAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,YAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,aAAO,IAAI,MAAM,UAAU,OAAO;AAAA,IACpC;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;","names":["import_slate","React","customMethods","editorHtmlElement","editor"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts","../../../src/lib/get-text-around-cursor.ts","../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(\n ref,\n () => {\n class Combined {\n constructor(\n private customMethods: CustomMethods,\n private editorHtmlElement: HTMLElement,\n ) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n },\n [editor],\n );\n}\n","import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n","import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,yBAA4B;;;ACF5B,mBAAsF;AAuE/E,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,oBAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,oBAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACA,SAAO,wBAAwB,QAAQ,iBAAiB;AAC1D;AAGO,SAAS,wBAAwB,QAAgB,OAAsB;AAC5E,QAAM,QAAQ;AACd,QAAM,CAAC,OAAO,GAAG,IAAI,mBAAM,MAAM,KAAK;AACtC,MAAI,OAAO;AACX,MAAI,YAAyB;AAE7B,aAAW,CAAC,MAAM,IAAI,KAAK,oBAAO,MAAM,QAAQ;AAAA,IAC9C,IAAI;AAAA,IACJ,OAAO,kBAAK;AAAA,IACZ;AAAA,EACF,CAAC,GAAG;AACF,QAAI,IAAI,KAAK;AAGb,UAAM,CAAC,KAAK,IAAI,oBAAO,MAAM,QAAQ;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO,CAAC,MAAM,qBAAQ,U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+BAAY,UAAU,QAAQ,MAAM;AAC9D,YAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,YAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,aAAO,IAAI,MAAM,UAAU,OAAO;AAAA,IACpC;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;","names":["import_slate","React","customMethods","editorHtmlElement","editor"]}
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js
CHANGED
|
@@ -60,6 +60,7 @@ __export(use_make_standard_autosuggestions_function_exports, {
|
|
|
60
60
|
useMakeStandardAutosuggestionFunction: () => useMakeStandardAutosuggestionFunction
|
|
61
61
|
});
|
|
62
62
|
module.exports = __toCommonJS(use_make_standard_autosuggestions_function_exports);
|
|
63
|
+
var import_shared = require("@copilotkit/shared");
|
|
63
64
|
var import_react_core = require("@copilotkit/react-core");
|
|
64
65
|
var import_react = require("react");
|
|
65
66
|
|
|
@@ -82,6 +83,8 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
|
82
83
|
var import_react_core2 = require("@copilotkit/react-core");
|
|
83
84
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
84
85
|
const { getContextString, copilotApiConfig } = (0, import_react.useContext)(import_react_core.CopilotContext);
|
|
86
|
+
const publicApiKey = copilotApiConfig.publicApiKey;
|
|
87
|
+
const headers = __spreadValues({}, publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
85
88
|
return (0, import_react.useCallback)(
|
|
86
89
|
(editorState, abortSignal) => __async(this, null, function* () {
|
|
87
90
|
const res = yield retry(() => __async(this, null, function* () {
|
|
@@ -109,7 +112,8 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
109
112
|
messages
|
|
110
113
|
}, apiConfig.forwardedParams), {
|
|
111
114
|
copilotConfig: copilotApiConfig,
|
|
112
|
-
signal: abortSignal
|
|
115
|
+
signal: abortSignal,
|
|
116
|
+
headers
|
|
113
117
|
}));
|
|
114
118
|
if (!response.events) {
|
|
115
119
|
throw new Error("Failed to fetch chat completion");
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.tsx"],"sourcesContent":["import { Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport { fetchAndDecodeChatCompletionAsText } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const response = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...apiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n let result = \"\";\n while (!abortSignal.aborted) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport { fetchAndDecodeChatCompletionAsText } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n const publicApiKey = copilotApiConfig.publicApiKey;\n const headers = {\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const response = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...apiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n headers: headers,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n let result = \"\";\n while (!abortSignal.aborted) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6D;AAC7D,wBAA+B;AAC/B,mBAAwC;;;ACFjC,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADfA,IAAAA,qBAAmD;AAe5C,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,QAAI,yBAAW,gCAAc;AACxE,QAAM,eAAe,iBAAiB;AACtC,QAAM,UAAU,mBACV,eAAe,EAAE,CAAC,iDAAmC,GAAG,aAAa,IAAI,CAAC;AAGhF,aAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF;AAAA,UACA,GAAG,UAAU;AAAA,UACb;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,QACF;AAEA,cAAM,WAAW,UAAM,uDAAmC;AAAA,UACxD;AAAA,WACG,UAAU,kBAF2C;AAAA,UAGxD,eAAe;AAAA,UACf,QAAQ;AAAA,UACR;AAAA,QACF,EAAC;AAED,YAAI,CAAC,SAAS,QAAQ;AACpB,gBAAM,IAAI,MAAM,iCAAiC;AAAA,QACnD;AAEA,cAAM,SAAS,SAAS,OAAO,UAAU;AAEzC,YAAI,SAAS;AACb,eAAO,CAAC,YAAY,SAAS;AAC3B,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AACA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":["import_react_core"]}
|
package/dist/index.js
CHANGED
|
@@ -1792,6 +1792,7 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
|
1792
1792
|
var import_react15 = __toESM(require("react"));
|
|
1793
1793
|
|
|
1794
1794
|
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
1795
|
+
var import_shared = require("@copilotkit/shared");
|
|
1795
1796
|
var import_react_core3 = require("@copilotkit/react-core");
|
|
1796
1797
|
var import_react13 = require("react");
|
|
1797
1798
|
|
|
@@ -1814,6 +1815,8 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
|
1814
1815
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1815
1816
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
1816
1817
|
const { getContextString, copilotApiConfig } = (0, import_react13.useContext)(import_react_core3.CopilotContext);
|
|
1818
|
+
const publicApiKey = copilotApiConfig.publicApiKey;
|
|
1819
|
+
const headers = __spreadValues({}, publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1817
1820
|
return (0, import_react13.useCallback)(
|
|
1818
1821
|
(editorState2, abortSignal) => __async(this, null, function* () {
|
|
1819
1822
|
const res = yield retry(() => __async(this, null, function* () {
|
|
@@ -1841,7 +1844,8 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
1841
1844
|
messages
|
|
1842
1845
|
}, apiConfig.forwardedParams), {
|
|
1843
1846
|
copilotConfig: copilotApiConfig,
|
|
1844
|
-
signal: abortSignal
|
|
1847
|
+
signal: abortSignal,
|
|
1848
|
+
headers
|
|
1845
1849
|
}));
|
|
1846
1850
|
if (!response.events) {
|
|
1847
1851
|
throw new Error("Failed to fetch chat completion");
|