@copilotkit/react-textarea 0.35.0-function-calling-fixes.2 → 0.35.0-mme-cloud.1
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 -432
- package/CHANGELOG.md +8 -20
- package/dist/{chunk-VPEH6V7T.mjs → chunk-FMQG2ZM3.mjs} +1 -1
- package/dist/chunk-FMQG2ZM3.mjs.map +1 -0
- package/dist/{chunk-SP5HFO3H.mjs → chunk-HWM2CVKO.mjs} +2 -2
- package/dist/{chunk-22TYLEZZ.mjs → chunk-XU5Z5BWV.mjs} +2 -2
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +36 -1752
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +4 -48
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +4 -46
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +5 -83
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +4 -54
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +45 -2196
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +5 -13
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +8 -130
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +19 -876
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +14 -569
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +15 -592
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +7 -98
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +16 -592
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +48 -2196
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +2 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +8 -207
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +6 -81
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +7 -42
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +14 -232
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +11 -134
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +5 -56
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +7 -42
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +7 -42
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +7 -155
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +5 -165
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- 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 +6 -145
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +5 -111
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +5 -160
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +4 -12
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -2196
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +4 -48
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +4 -40
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +7 -96
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +4 -14
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +4 -22
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +4 -17
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +4 -24
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +5 -102
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +4 -44
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +9 -63
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +9 -271
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +6 -82
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -271
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +6 -73
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +6 -59
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +4 -23
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +5 -14
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +5 -23
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +1 -0
- package/dist/types/index.mjs +14 -271
- package/dist/types/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +4 -1
- package/dist/chunk-VPEH6V7T.mjs.map +0 -1
- /package/dist/{chunk-SP5HFO3H.mjs.map → chunk-HWM2CVKO.mjs.map} +0 -0
- /package/dist/{chunk-22TYLEZZ.mjs.map → chunk-XU5Z5BWV.mjs.map} +0 -0
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,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AO,KAAK;AAAA,QACrB;AAAA,QAEQ,mBAAmB,KAAuC;AAChE,iBAAO,OAAO,KAAK;AAAA,QACrB;AAAA,MACF;AAEA,YAAM,UAAU;AAAA,QACd,IAAI,QAAa,SAAkD;AACjE,iBAAO,OAAO,IAAI,QAAQ,OAAO;AAAA,QACnC;AAAA,QACA,IAAI,QAAa,SAAkD,OAAY;AAC7E,iBAAO,OAAO,IAAI,QAAQ,SAAS,KAAK;AAAA,QAC1C;AAAA,MACF;AAEA,YAAM,cAAc;AAAA,QAClB,YAAoBC,SAAsB;AAAtB,wBAAAA;AAAA,QAAuB;AAAA,QAE3C,QAAQ;AACN,yCAAY,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,S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,KAAK;AAAA,QAC1C;AAAA,MACF;AAEA,YAAM,cAAc;AAAA,QAClB,YAAoBC,SAAsB;AAAtB,wBAAAA;AAAA,QAAuB;AAAA,QAE3C,QAAQ;AACN,yCAAY,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"]}
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs
CHANGED
|
@@ -1,148 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
function getFullEditorTextWithNewlines(editor) {
|
|
8
|
-
const fullDocumentRange = {
|
|
9
|
-
anchor: Editor.start(editor, []),
|
|
10
|
-
focus: Editor.end(editor, [])
|
|
11
|
-
};
|
|
12
|
-
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
13
|
-
}
|
|
14
|
-
function extractTextWithNewlines(editor, range) {
|
|
15
|
-
const voids = false;
|
|
16
|
-
const [start, end] = Range.edges(range);
|
|
17
|
-
let text = "";
|
|
18
|
-
let lastBlock = null;
|
|
19
|
-
for (const [node, path] of Editor.nodes(editor, {
|
|
20
|
-
at: range,
|
|
21
|
-
match: Text.isText,
|
|
22
|
-
voids
|
|
23
|
-
})) {
|
|
24
|
-
let t = node.text;
|
|
25
|
-
const [block] = Editor.above(editor, {
|
|
26
|
-
at: path,
|
|
27
|
-
match: (n) => Element.isElement(n) && n.type === "paragraph"
|
|
28
|
-
}) || [null];
|
|
29
|
-
if (lastBlock !== block && block) {
|
|
30
|
-
if (lastBlock) {
|
|
31
|
-
text += "\n";
|
|
32
|
-
}
|
|
33
|
-
lastBlock = block;
|
|
34
|
-
}
|
|
35
|
-
if (Path.equals(path, end.path)) {
|
|
36
|
-
t = t.slice(0, end.offset);
|
|
37
|
-
}
|
|
38
|
-
if (Path.equals(path, start.path)) {
|
|
39
|
-
t = t.slice(start.offset);
|
|
40
|
-
}
|
|
41
|
-
text += t;
|
|
42
|
-
}
|
|
43
|
-
return text;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/lib/slatejs-edits/replace-text.ts
|
|
47
|
-
import { Editor as Editor2, Transforms } from "slate";
|
|
48
|
-
function replaceEditorText(editor, newText) {
|
|
49
|
-
Transforms.delete(editor, {
|
|
50
|
-
at: {
|
|
51
|
-
anchor: Editor2.start(editor, []),
|
|
52
|
-
focus: Editor2.end(editor, [])
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
if (newText && newText !== "") {
|
|
56
|
-
Transforms.insertNodes(
|
|
57
|
-
editor,
|
|
58
|
-
[
|
|
59
|
-
{
|
|
60
|
-
type: "paragraph",
|
|
61
|
-
children: [{ text: newText }]
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
{
|
|
65
|
-
at: [0]
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
72
|
-
function usePopulateCopilotTextareaRef(editor, ref) {
|
|
73
|
-
React.useImperativeHandle(
|
|
74
|
-
ref,
|
|
75
|
-
() => {
|
|
76
|
-
class Combined {
|
|
77
|
-
constructor(customMethods2, editorHtmlElement2) {
|
|
78
|
-
this.customMethods = customMethods2;
|
|
79
|
-
this.editorHtmlElement = editorHtmlElement2;
|
|
80
|
-
}
|
|
81
|
-
get(target, propKey) {
|
|
82
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
83
|
-
const value = this.customMethods[propKey];
|
|
84
|
-
if (typeof value === "function") {
|
|
85
|
-
return value.bind(this.customMethods);
|
|
86
|
-
}
|
|
87
|
-
return value;
|
|
88
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
89
|
-
const value = this.editorHtmlElement[propKey];
|
|
90
|
-
if (typeof value === "function") {
|
|
91
|
-
return value.bind(this.editorHtmlElement);
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
set(target, propKey, value) {
|
|
97
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
98
|
-
this.customMethods[propKey] = value;
|
|
99
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
100
|
-
this.editorHtmlElement[propKey] = value;
|
|
101
|
-
} else {
|
|
102
|
-
target[propKey] = value;
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
isKeyOfCustomMethods(key) {
|
|
107
|
-
return key in this.customMethods;
|
|
108
|
-
}
|
|
109
|
-
isKeyOfHTMLElement(key) {
|
|
110
|
-
return key in this.editorHtmlElement;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const handler = {
|
|
114
|
-
get(target, propKey) {
|
|
115
|
-
return target.get(target, propKey);
|
|
116
|
-
},
|
|
117
|
-
set(target, propKey, value) {
|
|
118
|
-
return target.set(target, propKey, value);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
class CustomMethods {
|
|
122
|
-
constructor(editor2) {
|
|
123
|
-
this.editor = editor2;
|
|
124
|
-
}
|
|
125
|
-
focus() {
|
|
126
|
-
ReactEditor.focus(this.editor);
|
|
127
|
-
}
|
|
128
|
-
blur() {
|
|
129
|
-
ReactEditor.blur(this.editor);
|
|
130
|
-
}
|
|
131
|
-
get value() {
|
|
132
|
-
return getFullEditorTextWithNewlines(this.editor);
|
|
133
|
-
}
|
|
134
|
-
set value(value) {
|
|
135
|
-
replaceEditorText(this.editor, value);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
|
|
139
|
-
const customMethods = new CustomMethods(editor);
|
|
140
|
-
const combined = new Combined(customMethods, editorHtmlElement);
|
|
141
|
-
return new Proxy(combined, handler);
|
|
142
|
-
},
|
|
143
|
-
[editor]
|
|
144
|
-
);
|
|
145
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
usePopulateCopilotTextareaRef
|
|
3
|
+
} from "../../chunk-FMQG2ZM3.mjs";
|
|
4
|
+
import "../../chunk-5UNJXFUO.mjs";
|
|
5
|
+
import "../../chunk-ECR45NSD.mjs";
|
|
6
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
146
7
|
export {
|
|
147
8
|
usePopulateCopilotTextareaRef
|
|
148
9
|
};
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.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,OAAO,WAAW;AAElB,SAAS,mBAAmB;;;ACF5B,SAAS,QAAc,MAAM,OAAO,MAAM,SAA+B,aAAa;AAuE/E,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,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,MAAM,MAAM,KAAK;AACtC,MAAI,OAAO;AACX,MAAI,YAAyB;AAE7B,aAAW,CAAC,MAAM,IAAI,KAAK,OAAO,MA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QAEA,OAAO;AACL,sBAAY,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,YAAY,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":["Editor","customMethods","editorHtmlElement","editor"]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/hooks/index.mjs
CHANGED
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs
CHANGED
|
@@ -1,114 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
42
|
-
import { CopilotContext } from "@copilotkit/react-core";
|
|
43
|
-
import { useCallback, useContext } from "react";
|
|
44
|
-
|
|
45
|
-
// src/lib/retry.tsx
|
|
46
|
-
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
fn().then(resolve).catch((error) => {
|
|
49
|
-
if (retriesLeft === 1) {
|
|
50
|
-
reject(error);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
55
|
-
}, interval);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
61
|
-
import { fetchAndDecodeChatCompletionAsText } from "@copilotkit/react-core";
|
|
62
|
-
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
63
|
-
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
64
|
-
return useCallback(
|
|
65
|
-
(editorState, abortSignal) => __async(this, null, function* () {
|
|
66
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
67
|
-
const messages = [
|
|
68
|
-
{
|
|
69
|
-
role: "system",
|
|
70
|
-
content: apiConfig.makeSystemPrompt(
|
|
71
|
-
textareaPurpose,
|
|
72
|
-
getContextString([], contextCategories)
|
|
73
|
-
)
|
|
74
|
-
},
|
|
75
|
-
...apiConfig.fewShotMessages,
|
|
76
|
-
{
|
|
77
|
-
role: "user",
|
|
78
|
-
name: "TextAfterCursor",
|
|
79
|
-
content: editorState.textAfterCursor
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
role: "user",
|
|
83
|
-
name: "TextBeforeCursor",
|
|
84
|
-
content: editorState.textBeforeCursor
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
const response = yield fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
88
|
-
messages
|
|
89
|
-
}, apiConfig.forwardedParams), {
|
|
90
|
-
copilotConfig: copilotApiConfig,
|
|
91
|
-
signal: abortSignal
|
|
92
|
-
}));
|
|
93
|
-
if (!response.events) {
|
|
94
|
-
throw new Error("Failed to fetch chat completion");
|
|
95
|
-
}
|
|
96
|
-
const reader = response.events.getReader();
|
|
97
|
-
let result = "";
|
|
98
|
-
while (!abortSignal.aborted) {
|
|
99
|
-
const { done, value } = yield reader.read();
|
|
100
|
-
if (done) {
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
result += value;
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}));
|
|
107
|
-
return res;
|
|
108
|
-
}),
|
|
109
|
-
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
110
|
-
);
|
|
111
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useMakeStandardAutosuggestionFunction
|
|
3
|
+
} from "../../chunk-RT4UTBH3.mjs";
|
|
4
|
+
import "../../chunk-KNQIEOFP.mjs";
|
|
5
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
112
6
|
export {
|
|
113
7
|
useMakeStandardAutosuggestionFunction
|
|
114
8
|
};
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,163 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
42
|
-
import { CopilotContext } from "@copilotkit/react-core";
|
|
43
|
-
import { useCallback, useContext } from "react";
|
|
44
|
-
|
|
45
|
-
// src/lib/retry.tsx
|
|
46
|
-
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
fn().then(resolve).catch((error) => {
|
|
49
|
-
if (retriesLeft === 1) {
|
|
50
|
-
reject(error);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
55
|
-
}, interval);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
61
|
-
import { fetchAndDecodeChatCompletionAsText } from "@copilotkit/react-core";
|
|
62
|
-
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
63
|
-
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
64
|
-
const insertionFunction = useCallback(
|
|
65
|
-
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
66
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
67
|
-
const messages = [
|
|
68
|
-
{
|
|
69
|
-
role: "system",
|
|
70
|
-
content: insertionApiConfig.makeSystemPrompt(
|
|
71
|
-
textareaPurpose,
|
|
72
|
-
getContextString(documents, contextCategories)
|
|
73
|
-
)
|
|
74
|
-
},
|
|
75
|
-
...insertionApiConfig.fewShotMessages,
|
|
76
|
-
{
|
|
77
|
-
role: "user",
|
|
78
|
-
name: "TextAfterCursor",
|
|
79
|
-
content: editorState.textAfterCursor
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
role: "user",
|
|
83
|
-
name: "TextBeforeCursor",
|
|
84
|
-
content: editorState.textBeforeCursor
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
role: "user",
|
|
88
|
-
name: "InsertionPrompt",
|
|
89
|
-
content: insertionPrompt
|
|
90
|
-
}
|
|
91
|
-
];
|
|
92
|
-
const stream = yield fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
93
|
-
messages
|
|
94
|
-
}, insertionApiConfig.forwardedParams), {
|
|
95
|
-
copilotConfig: copilotApiConfig,
|
|
96
|
-
signal: abortSignal
|
|
97
|
-
}));
|
|
98
|
-
return stream.events;
|
|
99
|
-
}));
|
|
100
|
-
return res;
|
|
101
|
-
}),
|
|
102
|
-
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
103
|
-
);
|
|
104
|
-
const editingFunction = useCallback(
|
|
105
|
-
(editorState, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
106
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
107
|
-
const messages = [
|
|
108
|
-
{
|
|
109
|
-
role: "system",
|
|
110
|
-
content: editingApiConfig.makeSystemPrompt(
|
|
111
|
-
textareaPurpose,
|
|
112
|
-
getContextString(documents, contextCategories)
|
|
113
|
-
)
|
|
114
|
-
},
|
|
115
|
-
...editingApiConfig.fewShotMessages,
|
|
116
|
-
{
|
|
117
|
-
role: "user",
|
|
118
|
-
name: "TextBeforeCursor",
|
|
119
|
-
content: editorState.textBeforeCursor
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
role: "user",
|
|
123
|
-
name: "TextToEdit",
|
|
124
|
-
content: editorState.selectedText
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
role: "user",
|
|
128
|
-
name: "TextAfterCursor",
|
|
129
|
-
content: editorState.textAfterCursor
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
role: "user",
|
|
133
|
-
name: "EditingPrompt",
|
|
134
|
-
content: editingPrompt
|
|
135
|
-
}
|
|
136
|
-
];
|
|
137
|
-
const stream = yield fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
138
|
-
messages
|
|
139
|
-
}, editingApiConfig.forwardedParams), {
|
|
140
|
-
copilotConfig: copilotApiConfig,
|
|
141
|
-
signal: abortSignal
|
|
142
|
-
}));
|
|
143
|
-
return stream.events;
|
|
144
|
-
}));
|
|
145
|
-
return res;
|
|
146
|
-
}),
|
|
147
|
-
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
148
|
-
);
|
|
149
|
-
const insertionOrEditingFunction = useCallback(
|
|
150
|
-
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
151
|
-
if (editorState.selectedText === "") {
|
|
152
|
-
return yield insertionFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
153
|
-
} else {
|
|
154
|
-
return yield editingFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
155
|
-
}
|
|
156
|
-
}),
|
|
157
|
-
[insertionFunction, editingFunction]
|
|
158
|
-
);
|
|
159
|
-
return insertionOrEditingFunction;
|
|
160
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useMakeStandardInsertionOrEditingFunction
|
|
3
|
+
} from "../../chunk-QCPS6IYI.mjs";
|
|
4
|
+
import "../../chunk-KNQIEOFP.mjs";
|
|
5
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
161
6
|
export {
|
|
162
7
|
useMakeStandardInsertionOrEditingFunction
|
|
163
8
|
};
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (textAreaRef.current !== null) {
|
|
6
|
-
textAreaRef.current.style.height = "0px";
|
|
7
|
-
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
8
|
-
textAreaRef.current.style.height = scrollHeight + "px";
|
|
9
|
-
}
|
|
10
|
-
}, [textAreaRef, value]);
|
|
11
|
-
};
|
|
12
|
-
var use_autosize_textarea_default = useAutosizeTextArea;
|
|
1
|
+
import {
|
|
2
|
+
use_autosize_textarea_default
|
|
3
|
+
} from "../../chunk-3PQ7GSFE.mjs";
|
|
4
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
13
5
|
export {
|
|
14
6
|
use_autosize_textarea_default as default
|
|
15
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|