@copilotkit/react-textarea 1.8.13 → 1.8.14-next.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/CHANGELOG.md +19 -0
- package/dist/{chunk-MGYT7RNL.mjs → chunk-4ECCCOFV.mjs} +2 -2
- package/dist/{chunk-4XXU5BSA.mjs → chunk-B7WYSFPJ.mjs} +18 -23
- package/dist/chunk-B7WYSFPJ.mjs.map +1 -0
- package/dist/{chunk-4CVSOOJY.mjs → chunk-F6RLSVG3.mjs} +5 -5
- package/dist/chunk-F6RLSVG3.mjs.map +1 -0
- package/dist/{chunk-PZYM7K4Y.mjs → chunk-FQHMDD6N.mjs} +15 -11
- package/dist/chunk-FQHMDD6N.mjs.map +1 -0
- package/dist/{chunk-BNBGJBBM.mjs → chunk-KNH7OQAM.mjs} +5 -5
- package/dist/{chunk-2VMZ5ZWT.mjs → chunk-YHMWPA3C.mjs} +1 -4
- package/dist/chunk-YHMWPA3C.mjs.map +1 -0
- package/dist/{chunk-ABYCGF77.mjs → chunk-YNYXWS2H.mjs} +2 -2
- package/dist/chunk-YNYXWS2H.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +219 -223
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -8
- package/dist/components/copilot-textarea/copilot-textarea.js +221 -225
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +15 -15
- package/dist/components/hovering-toolbar/hovering-toolbar.js +281 -289
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +4 -4
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +0 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +0 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +0 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +2 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +0 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +2 -2
- package/dist/components/index.js +223 -227
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +15 -15
- package/dist/index.js +223 -227
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -21
- package/dist/types/autosuggestions-config/autosuggestions-config.js +4 -4
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
- package/dist/types/autosuggestions-config/index.js +4 -4
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +2 -2
- package/dist/types/base/base-autosuggestions-config.d.ts +4 -0
- package/dist/types/base/base-autosuggestions-config.js +4 -4
- package/dist/types/base/base-autosuggestions-config.js.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +1 -1
- package/dist/types/base/index.js +4 -4
- package/dist/types/base/index.js.map +1 -1
- package/dist/types/base/index.mjs +1 -1
- package/dist/types/index.js +4 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +3 -3
- package/package.json +4 -4
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +7 -1
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +43 -40
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +0 -3
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +0 -1
- package/src/types/base/base-autosuggestions-config.tsx +9 -4
- package/dist/chunk-2VMZ5ZWT.mjs.map +0 -1
- package/dist/chunk-4CVSOOJY.mjs.map +0 -1
- package/dist/chunk-4XXU5BSA.mjs.map +0 -1
- package/dist/chunk-ABYCGF77.mjs.map +0 -1
- package/dist/chunk-PZYM7K4Y.mjs.map +0 -1
- /package/dist/{chunk-MGYT7RNL.mjs.map → chunk-4ECCCOFV.mjs.map} +0 -0
- /package/dist/{chunk-BNBGJBBM.mjs.map → chunk-KNH7OQAM.mjs.map} +0 -0
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts","../../src/types/base/base-autosuggestions-config.tsx","../../src/types/autosuggestions-config/suggestions-api-config.tsx","../../src/types/autosuggestions-config/insertions-api-config.tsx","../../src/types/autosuggestions-config/editing-api-config.tsx","../../src/types/autosuggestions-config/autosuggestions-config.tsx"],"sourcesContent":["export * from \"./base\";\nexport * from \"./html-copilot-textarea-element\";\nexport * from \"./autosuggestions-config\";\n","import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.TouchEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the current autosuggestion based on a mobile touch event. By default, the touching the end of a suggestion will accept it. Example code:\n *\n * ```typescript\n * const shouldAcceptAutosuggestionOnTouch = (event: React.TouchEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.type === \"touchstart\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n ) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === shortcut && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnTouch = () => false;\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n * @property {() => boolean} defaultShouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the autosuggestion based on a mobile touch event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n maxTokens?: number;\n stop?: string[];\n temperature?: number;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\nRefrain from adding <YourSuggestion> tags when responding\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"This morning I woke up and went straight to the grocery store.\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n '<TextBeforeCursor>The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;</TextBeforeCursor>',\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n }),\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user insert new text into their existing work.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to inform your suggestions when relevant!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user will provide you with a prompt for an INSERTION into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.\nOnly insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\n\nThe user will provide the text before and after the cursor, as well as the INSERTION prompt. You should use this to infer the best relevant insertion.\nThe conversation will be structured as follows:\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\n\n<YourInsertionSuggestion>\n`;\n};\n\nexport const defaultInsertionsFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<InsertionPrompt>I bought a big watermelon</InsertionPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"When I arrived I went straight to the produce section and picked out a big watermelon.\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n '<TextBeforeCursor>The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;</TextBeforeCursor>',\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n }),\n];\n\nexport const defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user edit a portion of their text.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it when relevant.\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user has provided you with a PROMPT for EDITING a PORTION of the text. \nYour job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.\nOnly rewrite the portion of the text that the user has marked as \"TextToEdit\"!!!\n\nAdjust yourself to the user's style and implied intent.\n\nThe conversation will be structured as follows:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<EditingPrompt>I also bought a big watermelon</EditingPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"While I was there I picked up some apples, oranges, and bananas, and a big watermelon.\",\n }),\n\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project.\",\n }),\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n","import { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../base\";\nimport { SuggestionsApiConfig, defaultSuggestionsApiConfig } from \"./suggestions-api-config\";\nimport { InsertionsApiConfig, defaultInsertionsApiConfig } from \"./insertions-api-config\";\nimport { EditingApiConfig, defaultEditingApiConfig } from \"./editing-api-config\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n// Like the base autosuggestions config, with 2 additional fields:\n// 1. contextCategories: string[] | undefined;\n// 2. instead of apiConfigs, we have chatApiConfigs: a higher-level abstraction that uses a ChatGPT-like API endpoint.\nexport interface AutosuggestionsConfig extends Omit<BaseAutosuggestionsConfig, \"apiConfig\"> {\n contextCategories: string[];\n chatApiConfigs: {\n suggestionsApiConfig: SuggestionsApiConfig;\n insertionApiConfig: InsertionsApiConfig;\n editingApiConfig: EditingApiConfig;\n };\n}\n\nexport const defaultAutosuggestionsConfig: Omit<\n AutosuggestionsConfig,\n \"textareaPurpose\" | \"apiEndpoint\"\n> = {\n ...defaultBaseAutosuggestionsConfig,\n contextCategories: defaultCopilotContextCategories,\n chatApiConfigs: {\n suggestionsApiConfig: defaultSuggestionsApiConfig,\n insertionApiConfig: defaultInsertionsApiConfig,\n editingApiConfig: defaultEditingApiConfig,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,wBAAgD;AAyEhD,IAAM,8CAA8C,CAClD,OACA,aACG;AAEH,MAAI,MAAM,QAAQ,YAAY,MAAM,SAAS;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,2CAA2C,MAAM;AAehD,IAAM,mCAGT;AAAA,EACF,c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,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EAED,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AACH;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB;;;AC3FA,IAAAC,qBAAgD;AAczC,IAAM,+BAGT,iCACC,mCADD;AAAA,EAEF,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,IACd,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,kBAAkB;AAAA,EACpB;AACF;","names":["import_runtime_client_gql","import_runtime_client_gql","import_react_core"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts","../../src/types/base/base-autosuggestions-config.tsx","../../src/types/autosuggestions-config/suggestions-api-config.tsx","../../src/types/autosuggestions-config/insertions-api-config.tsx","../../src/types/autosuggestions-config/editing-api-config.tsx","../../src/types/autosuggestions-config/autosuggestions-config.tsx"],"sourcesContent":["export * from \"./base\";\nexport * from \"./html-copilot-textarea-element\";\nexport * from \"./autosuggestions-config\";\n","import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\nimport { isMacOS } from \"@copilotkit/shared\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.TouchEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the current autosuggestion based on a mobile touch event. By default, the touching the end of a suggestion will accept it. Example code:\n *\n * ```typescript\n * const shouldAcceptAutosuggestionOnTouch = (event: React.TouchEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.type === \"touchstart\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n temporarilyDisableNotTrustedEvents: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n ) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n) => {\n const isMetaKey = isMacOS() ? event.metaKey : event.ctrlKey;\n\n // if command-k, toggle the hovering editor\n return event.key === shortcut && isMetaKey;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnTouch = () => false;\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable the autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n * @property {() => boolean} defaultShouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the autosuggestion based on a mobile touch event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n temporarilyDisableNotTrustedEvents: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n maxTokens?: number;\n stop?: string[];\n temperature?: number;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\nRefrain from adding <YourSuggestion> tags when responding\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"This morning I woke up and went straight to the grocery store.\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n '<TextBeforeCursor>The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;</TextBeforeCursor>',\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n }),\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user insert new text into their existing work.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to inform your suggestions when relevant!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user will provide you with a prompt for an INSERTION into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.\nOnly insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\n\nThe user will provide the text before and after the cursor, as well as the INSERTION prompt. You should use this to infer the best relevant insertion.\nThe conversation will be structured as follows:\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\n\n<YourInsertionSuggestion>\n`;\n};\n\nexport const defaultInsertionsFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<InsertionPrompt>I bought a big watermelon</InsertionPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"When I arrived I went straight to the produce section and picked out a big watermelon.\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n '<TextBeforeCursor>The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;</TextBeforeCursor>',\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n }),\n];\n\nexport const defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user edit a portion of their text.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it when relevant.\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user has provided you with a PROMPT for EDITING a PORTION of the text. \nYour job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.\nOnly rewrite the portion of the text that the user has marked as \"TextToEdit\"!!!\n\nAdjust yourself to the user's style and implied intent.\n\nThe conversation will be structured as follows:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: Message[] = [\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<EditingPrompt>I also bought a big watermelon</EditingPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"While I was there I picked up some apples, oranges, and bananas, and a big watermelon.\",\n }),\n\n new TextMessage({\n role: Role.User,\n content:\n \"<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content: \"<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>\",\n }),\n new TextMessage({\n role: Role.User,\n content:\n \"<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>\",\n }),\n new TextMessage({\n role: Role.Assistant,\n content:\n \"It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project.\",\n }),\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n","import { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../base\";\nimport { SuggestionsApiConfig, defaultSuggestionsApiConfig } from \"./suggestions-api-config\";\nimport { InsertionsApiConfig, defaultInsertionsApiConfig } from \"./insertions-api-config\";\nimport { EditingApiConfig, defaultEditingApiConfig } from \"./editing-api-config\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n// Like the base autosuggestions config, with 2 additional fields:\n// 1. contextCategories: string[] | undefined;\n// 2. instead of apiConfigs, we have chatApiConfigs: a higher-level abstraction that uses a ChatGPT-like API endpoint.\nexport interface AutosuggestionsConfig extends Omit<BaseAutosuggestionsConfig, \"apiConfig\"> {\n contextCategories: string[];\n chatApiConfigs: {\n suggestionsApiConfig: SuggestionsApiConfig;\n insertionApiConfig: InsertionsApiConfig;\n editingApiConfig: EditingApiConfig;\n };\n}\n\nexport const defaultAutosuggestionsConfig: Omit<\n AutosuggestionsConfig,\n \"textareaPurpose\" | \"apiEndpoint\"\n> = {\n ...defaultBaseAutosuggestionsConfig,\n contextCategories: defaultCopilotContextCategories,\n chatApiConfigs: {\n suggestionsApiConfig: defaultSuggestionsApiConfig,\n insertionApiConfig: defaultInsertionsApiConfig,\n editingApiConfig: defaultEditingApiConfig,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,wBAAgD;AAChD,oBAAwB;AA4ExB,IAAM,8CAA8C,CAClD,OACA,aACG;AACH,QAAM,gBAAY,uBAAQ,IAAI,MAAM,UAAU,MAAM;AAGpD,SAAO,MAAM,QAAQ,YAAY;AACnC;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,2CAA2C,MAAM;AAgBhD,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,oCAAoC;AAAA,EACpC,sCAAsC;AAAA,EACtC,sCAAsC;AAAA,EACtC,mCAAmC;AACrC;;;AC/HA,gCAA2C;AAWpC,IAAM,qCAAuD,CAClE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBlB;AAAA;AAAA;AAGF;AAEO,IAAM,oCAA+C;AAAA,EAC1D,IAAI,sCAAY;AAAA,IACd,MAAM,+BAAK;AAAA,IACX,SACE;AAAA,EACJ,CA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ACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,uCAAY;AAAA,IACd,MAAM,gCAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AACH;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB;;;AC3FA,IAAAC,qBAAgD;AAczC,IAAM,+BAGT,iCACC,mCADD;AAAA,EAEF,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,IACd,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,kBAAkB;AAAA,EACpB;AACF;","names":["import_runtime_client_gql","import_runtime_client_gql","import_react_core"]}
|
package/dist/types/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../chunk-DE5K76I2.mjs";
|
|
2
|
-
import "../chunk-WADHCMPK.mjs";
|
|
3
2
|
import "../chunk-RUV6NBIF.mjs";
|
|
4
3
|
import {
|
|
5
4
|
defaultAutosuggestionsConfig
|
|
6
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-4ECCCOFV.mjs";
|
|
7
6
|
import "../chunk-EJGGLWWR.mjs";
|
|
8
7
|
import "../chunk-MCNXIA4Q.mjs";
|
|
9
8
|
import "../chunk-QFXR6DOA.mjs";
|
|
10
9
|
import "../chunk-WJHSY5T6.mjs";
|
|
11
10
|
import {
|
|
12
11
|
defaultBaseAutosuggestionsConfig
|
|
13
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-F6RLSVG3.mjs";
|
|
13
|
+
import "../chunk-WADHCMPK.mjs";
|
|
14
14
|
import "../chunk-MRXNTQOX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
defaultAutosuggestionsConfig,
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.8.
|
|
12
|
+
"version": "1.8.14-next.1",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"**/*.css"
|
|
15
15
|
],
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"slate-history": "^0.93.0",
|
|
68
68
|
"slate-react": "^0.98.1",
|
|
69
69
|
"tailwind-merge": "^1.13.2",
|
|
70
|
-
"@copilotkit/react-core": "1.8.
|
|
71
|
-
"@copilotkit/runtime-client-gql": "1.8.
|
|
72
|
-
"@copilotkit/shared": "1.8.
|
|
70
|
+
"@copilotkit/react-core": "1.8.14-next.1",
|
|
71
|
+
"@copilotkit/runtime-client-gql": "1.8.14-next.1",
|
|
72
|
+
"@copilotkit/shared": "1.8.14-next.1"
|
|
73
73
|
},
|
|
74
74
|
"keywords": [
|
|
75
75
|
"copilotkit",
|
|
@@ -92,6 +92,7 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
92
92
|
const valueOnInitialRender = useMemo(() => props.value ?? "", []);
|
|
93
93
|
const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);
|
|
94
94
|
const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);
|
|
95
|
+
const [isUserInputActive, setIsUserInputActive] = useState(false);
|
|
95
96
|
|
|
96
97
|
// // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.
|
|
97
98
|
// useEffect(() => {
|
|
@@ -128,7 +129,9 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
128
129
|
hoveringEditorIsDisplayed ||
|
|
129
130
|
// the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
|
|
130
131
|
(cursorMovedSinceLastTextChange &&
|
|
131
|
-
autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText)
|
|
132
|
+
autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText) ||
|
|
133
|
+
// not user input and we want to disable non-trusted events (like text insertion from autocomplete plugins):
|
|
134
|
+
(!isUserInputActive && autosuggestionsConfig.temporarilyDisableNotTrustedEvents);
|
|
132
135
|
|
|
133
136
|
const {
|
|
134
137
|
currentAutocompleteSuggestion,
|
|
@@ -251,6 +254,7 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
251
254
|
}
|
|
252
255
|
return fullEditorText;
|
|
253
256
|
});
|
|
257
|
+
|
|
254
258
|
onChangeHandlerForAutocomplete(newEditorState);
|
|
255
259
|
|
|
256
260
|
props.onValueChange?.(fullEditorText);
|
|
@@ -269,6 +273,7 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
269
273
|
renderElement={renderElementMemoized}
|
|
270
274
|
renderPlaceholder={renderPlaceholderMemoized}
|
|
271
275
|
onKeyDown={(event) => {
|
|
276
|
+
setIsUserInputActive(true);
|
|
272
277
|
onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use
|
|
273
278
|
onKeyDownHandlerForAutocomplete(event); // forward the event for internal use
|
|
274
279
|
props.onKeyDown?.(event); // forward the event for external use
|
|
@@ -282,6 +287,7 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
282
287
|
// clear autocompletion on blur
|
|
283
288
|
props.onBlur?.(ev);
|
|
284
289
|
clearAutocompletionsFromEditor(editor);
|
|
290
|
+
setIsUserInputActive(false);
|
|
285
291
|
}}
|
|
286
292
|
{...propsToForward}
|
|
287
293
|
/>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
import { Editor, Location, Transforms } from "slate";
|
|
3
3
|
import { useSlate, useSlateSelection } from "slate-react";
|
|
4
|
-
import { HoveringInsertionPromptBox } from "./text-insertion-prompt-box";
|
|
5
|
-
import { Menu, Portal } from "./hovering-toolbar-components";
|
|
6
|
-
import { useHoveringEditorContext } from "./hovering-editor-provider";
|
|
7
4
|
import {
|
|
8
5
|
getFullEditorTextWithNewlines,
|
|
9
6
|
getTextAroundSelection,
|
|
@@ -12,6 +9,9 @@ import {
|
|
|
12
9
|
EditingEditorState,
|
|
13
10
|
InsertionEditorApiConfig,
|
|
14
11
|
} from "../../types/base/autosuggestions-bare-function";
|
|
12
|
+
import { useHoveringEditorContext } from "./hovering-editor-provider";
|
|
13
|
+
import { Menu, Portal } from "./hovering-toolbar-components";
|
|
14
|
+
import { HoveringInsertionPromptBox } from "./text-insertion-prompt-box";
|
|
15
15
|
|
|
16
16
|
export interface HoveringToolbarProps {
|
|
17
17
|
apiConfig: InsertionEditorApiConfig;
|
|
@@ -31,11 +31,13 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
31
31
|
setIsClient(true);
|
|
32
32
|
}, []);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
const isShown = isClient && isDisplayed && selection;
|
|
35
|
+
|
|
36
|
+
useLayoutEffect(() => {
|
|
35
37
|
const el = ref.current;
|
|
36
38
|
const { selection } = editor;
|
|
37
39
|
|
|
38
|
-
if (!el) {
|
|
40
|
+
if (!el || !isShown) {
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -59,24 +61,29 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
59
61
|
if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
const verticalOffsetFromCorner =
|
|
64
|
-
const horizontalOffsetFromCorner =
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
|
|
65
|
+
const verticalOffsetFromCorner = 0;
|
|
66
|
+
const horizontalOffsetFromCorner = 0;
|
|
67
|
+
|
|
68
|
+
// position the toolbar below the selection
|
|
69
|
+
let top = rect.bottom + window.scrollY + verticalOffsetFromCorner;
|
|
70
|
+
|
|
71
|
+
// no space left at bottom, move up
|
|
72
|
+
if (rect.bottom + el.offsetHeight > window.innerHeight - verticalOffsetFromCorner) {
|
|
73
|
+
top = rect.top + window.scrollY - el.offsetHeight - verticalOffsetFromCorner;
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
// position the toolbar in the center of the selection
|
|
73
77
|
let left =
|
|
74
78
|
rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
// no space left at left, move right
|
|
81
|
+
if (left < horizontalOffsetFromCorner) {
|
|
82
|
+
left = horizontalOffsetFromCorner;
|
|
83
|
+
}
|
|
84
|
+
// no space left at right, move left
|
|
85
|
+
else if (left + el.offsetWidth > window.innerWidth - horizontalOffsetFromCorner) {
|
|
86
|
+
left = window.innerWidth - el.offsetWidth - horizontalOffsetFromCorner;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
el.style.opacity = "1";
|
|
@@ -84,7 +91,7 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
84
91
|
|
|
85
92
|
el.style.top = `${top}px`;
|
|
86
93
|
el.style.left = `${left}px`;
|
|
87
|
-
});
|
|
94
|
+
}, [isShown]);
|
|
88
95
|
|
|
89
96
|
useEffect(() => {
|
|
90
97
|
const handleClickOutside = (event: MouseEvent) => {
|
|
@@ -94,12 +101,13 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
94
101
|
};
|
|
95
102
|
|
|
96
103
|
document.addEventListener("mousedown", handleClickOutside);
|
|
104
|
+
|
|
97
105
|
return () => {
|
|
98
106
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
99
107
|
};
|
|
100
108
|
}, [ref, setIsDisplayed]);
|
|
101
109
|
|
|
102
|
-
if (!
|
|
110
|
+
if (!isShown) {
|
|
103
111
|
return null;
|
|
104
112
|
}
|
|
105
113
|
|
|
@@ -114,24 +122,19 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
114
122
|
}
|
|
115
123
|
data-testid="hovering-toolbar"
|
|
116
124
|
>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
setIsDisplayed(false);
|
|
131
|
-
}}
|
|
132
|
-
contextCategories={props.contextCategories}
|
|
133
|
-
/>
|
|
134
|
-
)}
|
|
125
|
+
<HoveringInsertionPromptBox
|
|
126
|
+
editorState={editorState(editor, selection)}
|
|
127
|
+
apiConfig={props.apiConfig}
|
|
128
|
+
performInsertion={(insertedText) => {
|
|
129
|
+
// replace the selection with the inserted text
|
|
130
|
+
Transforms.delete(editor, { at: selection });
|
|
131
|
+
Transforms.insertText(editor, insertedText, {
|
|
132
|
+
at: selection,
|
|
133
|
+
});
|
|
134
|
+
setIsDisplayed(false);
|
|
135
|
+
}}
|
|
136
|
+
contextCategories={props.contextCategories}
|
|
137
|
+
/>
|
|
135
138
|
</Menu>
|
|
136
139
|
</Portal>
|
|
137
140
|
);
|
|
@@ -177,9 +177,6 @@ export const HoveringInsertionPromptBoxCore = ({
|
|
|
177
177
|
} else if (e.key === "Enter") {
|
|
178
178
|
e.preventDefault();
|
|
179
179
|
beginGeneratingAdjustment();
|
|
180
|
-
} else if (e.key == "Escape") {
|
|
181
|
-
e.preventDefault();
|
|
182
|
-
setIsDisplayed(false);
|
|
183
180
|
}
|
|
184
181
|
}}
|
|
185
182
|
placeholder={placeholder}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseCopilotTextareaApiConfig } from "./autosuggestions-bare-function";
|
|
2
2
|
import { defaultCopilotContextCategories } from "@copilotkit/react-core";
|
|
3
|
+
import { isMacOS } from "@copilotkit/shared";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @interface BaseAutosuggestionsConfig
|
|
@@ -18,6 +19,8 @@ import { defaultCopilotContextCategories } from "@copilotkit/react-core";
|
|
|
18
19
|
*
|
|
19
20
|
* @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.
|
|
20
21
|
*
|
|
22
|
+
* @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)
|
|
23
|
+
*
|
|
21
24
|
* @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:
|
|
22
25
|
*
|
|
23
26
|
* ```typescript
|
|
@@ -63,6 +66,7 @@ export interface BaseAutosuggestionsConfig {
|
|
|
63
66
|
disableWhenEmpty: boolean;
|
|
64
67
|
disabled: boolean;
|
|
65
68
|
temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;
|
|
69
|
+
temporarilyDisableNotTrustedEvents: boolean;
|
|
66
70
|
shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;
|
|
67
71
|
shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean;
|
|
68
72
|
shouldToggleHoveringEditorOnKeyPress: (
|
|
@@ -76,11 +80,10 @@ const defaultShouldToggleHoveringEditorOnKeyPress = (
|
|
|
76
80
|
event: React.KeyboardEvent<HTMLDivElement>,
|
|
77
81
|
shortcut: string,
|
|
78
82
|
) => {
|
|
83
|
+
const isMetaKey = isMacOS() ? event.metaKey : event.ctrlKey;
|
|
84
|
+
|
|
79
85
|
// if command-k, toggle the hovering editor
|
|
80
|
-
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
86
|
+
return event.key === shortcut && isMetaKey;
|
|
84
87
|
};
|
|
85
88
|
|
|
86
89
|
const defaultShouldAcceptAutosuggestionOnKeyPress = (
|
|
@@ -103,6 +106,7 @@ const defaultShouldAcceptAutosuggestionOnTouch = () => false;
|
|
|
103
106
|
* @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.
|
|
104
107
|
* @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.
|
|
105
108
|
* @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.
|
|
109
|
+
* @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable the autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)
|
|
106
110
|
* @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.
|
|
107
111
|
* @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.
|
|
108
112
|
* @property {() => boolean} defaultShouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the autosuggestion based on a mobile touch event.
|
|
@@ -117,6 +121,7 @@ export const defaultBaseAutosuggestionsConfig: Omit<
|
|
|
117
121
|
disableWhenEmpty: true,
|
|
118
122
|
disabled: false,
|
|
119
123
|
temporarilyDisableWhenMovingCursorWithoutChangingText: true,
|
|
124
|
+
temporarilyDisableNotTrustedEvents: true,
|
|
120
125
|
shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
|
|
121
126
|
shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
|
|
122
127
|
shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx"],"sourcesContent":["import useAutosizeTextArea from \"../../../hooks/misc/use-autosize-textarea\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../../types/base/autosuggestions-bare-function\";\nimport { SourceSearchBox } from \"../../source-search-box/source-search-box\";\nimport { DocumentPointer, useCopilotContext } from \"@copilotkit/react-core\";\nimport { Button } from \"../../ui/button\";\nimport { Label } from \"../../ui/label\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { streamPromiseFlatten } from \"../../../lib/stream-promise-flatten\";\nimport { IncludedFilesPreview } from \"./included-files-preview\";\nimport { useHoveringEditorContext } from \"../hovering-editor-provider\";\n\nexport type SuggestionState = {\n editorState: EditingEditorState;\n};\n\nexport interface HoveringInsertionPromptBoxCoreProps {\n state: SuggestionState;\n performInsertion: (insertedText: string) => void;\n insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBoxCore = ({\n performInsertion,\n state,\n insertionOrEditingFunction,\n contextCategories,\n}: HoveringInsertionPromptBoxCoreProps) => {\n const { getDocumentsContext } = useCopilotContext();\n\n const [editSuggestion, setEditSuggestion] = useState<string>(\"\");\n const [suggestionIsLoading, setSuggestionIsLoading] = useState<boolean>(false);\n\n const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>(\"\");\n\n const [generatingSuggestion, setGeneratingSuggestion] = useState<ReadableStream<string> | null>(\n null,\n );\n\n const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);\n const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [filePointers, setFilePointers] = useState<DocumentPointer[]>([]);\n\n const [suggestedFiles, setSuggestedFiles] = useState<DocumentPointer[]>([]);\n useEffect(() => {\n setSuggestedFiles(getDocumentsContext(contextCategories));\n }, [contextCategories, getDocumentsContext]);\n\n useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || \"\");\n useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || \"\");\n\n // initially focus on the adjustment prompt text area\n useEffect(() => {\n adjustmentTextAreaRef.current?.focus();\n }, []);\n\n // continuously read the generating suggestion stream and update the edit suggestion\n useEffect(() => {\n // if no generating suggestion, do nothing\n if (!generatingSuggestion) {\n return;\n }\n\n // Check if the stream is already locked (i.e. already reading from it)\n if (generatingSuggestion.locked) {\n return;\n }\n\n // reset the edit suggestion\n setEditSuggestion(\"\");\n\n // read the generating suggestion stream and continuously update the edit suggestion\n const reader = generatingSuggestion.getReader();\n const read = async () => {\n setSuggestionIsLoading(true);\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n setEditSuggestion((prev) => {\n const newSuggestion = prev + value;\n\n // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.\n if (suggestionTextAreaRef.current) {\n suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;\n }\n return newSuggestion;\n });\n }\n\n setSuggestionIsLoading(false);\n };\n read();\n\n return () => {\n // release the lock if the reader is not closed on unmount\n const releaseLockIfNotClosed = async () => {\n try {\n await reader.closed;\n } catch {\n reader.releaseLock();\n }\n };\n\n releaseLockIfNotClosed();\n };\n }, [generatingSuggestion]);\n\n // generate an adjustment to the completed text, based on the adjustment prompt\n const beginGeneratingAdjustment = useCallback(async () => {\n // don't generate text if the prompt is empty\n if (!adjustmentPrompt.trim()) {\n return;\n }\n\n // editor state includes the text being edited, and the text before/after the selection\n // if the current edit suggestion is not empty, then use *it* as the \"selected text\" - instead of the editor state's selected text\n let modificationState = state.editorState;\n if (editSuggestion !== \"\") {\n modificationState.selectedText = editSuggestion;\n }\n\n // generate the adjustment suggestion\n const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(\n modificationState,\n adjustmentPrompt,\n filePointers,\n new AbortController().signal,\n );\n const adjustmentSuggestionTextStream = streamPromiseFlatten(\n adjustmentSuggestionTextStreamPromise,\n );\n\n setGeneratingSuggestion(adjustmentSuggestionTextStream);\n }, [\n adjustmentPrompt,\n editSuggestion,\n state.editorState,\n insertionOrEditingFunction,\n filePointers,\n ]);\n\n const isLoading = suggestionIsLoading;\n\n const textToEdit = editSuggestion || state.editorState.selectedText;\n const adjustmentLabel =\n textToEdit === \"\"\n ? \"Describe the text you want to insert\"\n : \"Describe adjustments to the suggested text\";\n const placeholder =\n textToEdit === \"\"\n ? \"e.g. 'summarize the client's top 3 pain-points from @CallTranscript'\"\n : \"e.g. 'make it more formal', 'be more specific', ...\";\n\n const { setIsDisplayed } = useHoveringEditorContext();\n\n const AdjustmentPromptComponent = (\n <>\n <Label className=\"\">{adjustmentLabel}</Label>\n <div className=\"relative w-full flex items-center\">\n <textarea\n data-testid=\"adjustment-prompt\"\n disabled={suggestionIsLoading}\n ref={adjustmentTextAreaRef}\n value={adjustmentPrompt}\n onChange={(e) => setAdjustmentPrompt(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && e.shiftKey) {\n e.preventDefault();\n setAdjustmentPrompt(adjustmentPrompt + \"\\n\");\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n beginGeneratingAdjustment();\n } else if (e.key == \"Escape\") {\n e.preventDefault();\n setIsDisplayed(false);\n }\n }}\n placeholder={placeholder}\n style={{ minHeight: \"3rem\" }}\n className=\"w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]\"\n rows={1}\n />\n <button\n onClick={beginGeneratingAdjustment}\n className=\"absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center\"\n data-testid=\"generate-button\"\n >\n <i className=\"material-icons\">arrow_forward</i>\n </button>\n </div>\n </>\n );\n\n const SuggestionComponent = (\n <>\n <div className=\"flex justify-between items-end w-full\">\n <Label className=\"mt-4\">Suggested:</Label>\n <div className=\"ml-auto\">\n {isLoading && (\n <div className=\"flex justify-center items-center\">\n <div\n className=\"inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]\"\n role=\"status\"\n >\n <span className=\"!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]\">\n Loading...\n </span>\n </div>\n </div>\n )}\n </div>\n </div>\n <textarea\n data-testid=\"suggestion-result\"\n ref={suggestionTextAreaRef}\n value={editSuggestion}\n disabled={suggestionIsLoading}\n onChange={(e) => setEditSuggestion(e.target.value)}\n className=\"w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50\"\n style={{ overflow: \"auto\", maxHeight: \"10em\" }}\n />\n </>\n );\n\n const SubmitComponent = (\n <div className=\"flex w-full gap-4 justify-start\">\n <Button\n data-testid=\"insert-button\"\n className=\" bg-green-700 text-white\"\n onClick={() => {\n performInsertion(editSuggestion);\n }}\n >\n Insert <i className=\"material-icons\">check</i>\n </Button>\n </div>\n );\n\n // show source search if the last word in the adjustment prompt BEGINS with an @\n const sourceSearchCandidate = adjustmentPrompt.split(\" \").pop();\n // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined\n const sourceSearchWord = sourceSearchCandidate?.startsWith(\"@\")\n ? sourceSearchCandidate.slice(1)\n : undefined;\n\n return (\n <div className=\"w-full flex flex-col items-start relative gap-2\">\n {AdjustmentPromptComponent}\n {filePointers.length > 0 && (\n <IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />\n )}\n {sourceSearchWord !== undefined && (\n <SourceSearchBox\n searchTerm={sourceSearchWord}\n suggestedFiles={suggestedFiles}\n onSelectedFile={(filePointer) => {\n setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), \"\"));\n setFilePointers((prev) => [...prev, filePointer]);\n\n // focus back on the adjustment prompt, and move the cursor to the end\n adjustmentTextAreaRef.current?.focus();\n }}\n />\n )}\n {generatingSuggestion ? SuggestionComponent : null}\n {generatingSuggestion ? SubmitComponent : null}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAA0B,yBAAyB;AAGnD,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AA0JrD,mBACE,KACA,YAF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Q,oBAAC,OAAE,WAAU,kBAAiB,mBAAK;AAAA;AAAA;AAAA,EAC5C,GACF;AAIF,QAAM,wBAAwB,iBAAiB,MAAM,GAAG,EAAE,IAAI;AAE9D,QAAM,oBAAmB,+DAAuB,WAAW,QACvD,sBAAsB,MAAM,CAAC,IAC7B;AAEJ,SACE,qBAAC,SAAI,WAAU,mDACZ;AAAA;AAAA,IACA,aAAa,SAAS,KACrB,oBAAC,wBAAqB,eAAe,cAAc,kBAAkB,iBAAiB;AAAA,IAEvF,qBAAqB,UACpB;AAAA,MAAC;AAAA;AAAA,QACC,YAAY;AAAA,QACZ;AAAA,QACA,gBAAgB,CAAC,gBAAgB;AAtQ3C;AAuQY,8BAAoB,iBAAiB,QAAQ,IAAI,OAAO,IAAI,mBAAmB,GAAG,EAAE,CAAC;AACrF,0BAAgB,CAAC,SAAS,CAAC,GAAG,MAAM,WAAW,CAAC;AAGhD,sCAAsB,YAAtB,mBAA+B;AAAA,QACjC;AAAA;AAAA,IACF;AAAA,IAED,uBAAuB,sBAAsB;AAAA,IAC7C,uBAAuB,kBAAkB;AAAA,KAC5C;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.TouchEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the current autosuggestion based on a mobile touch event. By default, the touching the end of a suggestion will accept it. Example code:\n *\n * ```typescript\n * const shouldAcceptAutosuggestionOnTouch = (event: React.TouchEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.type === \"touchstart\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n ) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === shortcut && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnTouch = () => false;\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n * @property {() => boolean} defaultShouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the autosuggestion based on a mobile touch event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch,\n};\n"],"mappings":";AACA,SAAS,uCAAuC;AAyEhD,IAAM,8CAA8C,CAClD,OACA,aACG;AAEH,MAAI,MAAM,QAAQ,YAAY,MAAM,SAAS;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,2CAA2C,MAAM;AAehD,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,sCAAsC;AAAA,EACtC,sCAAsC;AAAA,EACtC,mCAAmC;AACrC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/hovering-toolbar/hovering-toolbar.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Editor, Location, Transforms } from \"slate\";\nimport { useSlate, useSlateSelection } from \"slate-react\";\nimport { HoveringInsertionPromptBox } from \"./text-insertion-prompt-box\";\nimport { Menu, Portal } from \"./hovering-toolbar-components\";\nimport { useHoveringEditorContext } from \"./hovering-editor-provider\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundSelection,\n} from \"../../lib/get-text-around-cursor\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../types/base/autosuggestions-bare-function\";\n\nexport interface HoveringToolbarProps {\n apiConfig: InsertionEditorApiConfig;\n contextCategories: string[];\n hoverMenuClassname: string | undefined;\n}\n\nexport const HoveringToolbar = (props: HoveringToolbarProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const editor = useSlate();\n const selection = useSlateSelection();\n const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();\n\n // only render on client\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n setIsClient(true);\n }, []);\n\n useEffect(() => {\n const el = ref.current;\n const { selection } = editor;\n\n if (!el) {\n return;\n }\n\n if (!selection) {\n el.removeAttribute(\"style\");\n return;\n }\n\n const domSelection = window.getSelection();\n if (!domSelection || domSelection.rangeCount === 0) {\n return;\n }\n\n const domRange = domSelection.getRangeAt(0);\n const rect = domRange.getBoundingClientRect();\n\n // We use window = (0,0,0,0) as a signal that the selection is not in the original copilot-textarea,\n // but inside the hovering window.\n //\n // in such case, we simply do nothing.\n if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {\n return;\n }\n const minGapFromEdge = 60;\n const verticalOffsetFromCorner = 35;\n const horizontalOffsetFromCorner = 15;\n let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;\n // make sure top is in the viewport and not too close to the edge\n if (top < minGapFromEdge) {\n top = rect.bottom + window.scrollY + minGapFromEdge;\n } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {\n top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;\n }\n\n let left =\n rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;\n // make sure left is in the viewport and not too close to the edge\n if (left < minGapFromEdge) {\n left = minGapFromEdge;\n } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {\n left = window.innerWidth - el.offsetWidth - minGapFromEdge;\n }\n\n el.style.opacity = \"1\";\n el.style.position = \"absolute\";\n\n el.style.top = `${top}px`;\n el.style.left = `${left}px`;\n });\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n setIsDisplayed(false);\n }\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [ref, setIsDisplayed]);\n\n if (!isClient) {\n return null;\n }\n\n return (\n <Portal>\n <Menu\n ref={ref}\n className={\n \"copilot-kit-textarea-css-scope \" +\n (props.hoverMenuClassname ||\n \"p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700\")\n }\n data-testid=\"hovering-toolbar\"\n >\n {isDisplayed && selection && (\n <HoveringInsertionPromptBox\n editorState={editorState(editor, selection)}\n apiConfig={props.apiConfig}\n closeWindow={() => {\n setIsDisplayed(false);\n }}\n performInsertion={(insertedText) => {\n // replace the selection with the inserted text\n Transforms.delete(editor, { at: selection });\n Transforms.insertText(editor, insertedText, {\n at: selection,\n });\n setIsDisplayed(false);\n }}\n contextCategories={props.contextCategories}\n />\n )}\n </Menu>\n </Portal>\n );\n};\n\nfunction editorState(editor: Editor, selection: Location): EditingEditorState {\n const textAroundCursor = getTextAroundSelection(editor);\n if (textAroundCursor) {\n return textAroundCursor;\n }\n\n return {\n textBeforeCursor: getFullEditorTextWithNewlines(editor),\n textAfterCursor: \"\",\n selectedText: \"\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAA2B,kBAAkB;AAC7C,SAAS,UAAU,yBAAyB;AAmHlC;AAhGH,IAAM,kBAAkB,CAAC,UAAgC;AAC9D,QAAM,MAAM,OAAuB,IAAI;AACvC,QAAM,SAAS,SAAS;AACxB,QAAM,YAAY,kBAAkB;AACpC,QAAM,EAAE,aAAa,eAAe,IAAI,yBAAyB;AAGjE,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,YAAU,MAAM;AACd,gBAAY,IAAI;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM,KAAK,IAAI;AACf,UAAM,EAAE,WAAAA,WAAU,IAAI;AAEtB,QAAI,CAAC,IAAI;AACP;AAAA,IACF;AAEA,QAAI,CAACA,YAAW;AACd,SAAG,gBAAgB,OAAO;AAC1B;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,aAAa;AACzC,QAAI,CAA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AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WACE,qCACC,MAAM,sBACL;AAAA,MAEJ,eAAY;AAAA,MAEX,yBAAe,aACd;AAAA,QAAC;AAAA;AAAA,UACC,aAAa,YAAY,QAAQ,SAAS;AAAA,UAC1C,WAAW,MAAM;AAAA,UACjB,aAAa,MAAM;AACjB,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,kBAAkB,CAAC,iBAAiB;AAElC,uBAAW,OAAO,QAAQ,EAAE,IAAI,UAAU,CAAC;AAC3C,uBAAW,WAAW,QAAQ,cAAc;AAAA,cAC1C,IAAI;AAAA,YACN,CAAC;AACD,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EAEJ,GACF;AAEJ;AAEA,SAAS,YAAY,QAAgB,WAAyC;AAC5E,QAAM,mBAAmB,uBAAuB,MAAM;AACtD,MAAI,kBAAkB;AACpB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,kBAAkB,8BAA8B,MAAM;AAAA,IACtD,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AACF;","names":["selection"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx"],"sourcesContent":["import { HoveringInsertionPromptBoxCore } from \"./hovering-insertion-prompt-box-core\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../../types/base/autosuggestions-bare-function\";\n\nexport interface Props {\n editorState: EditingEditorState;\n apiConfig: InsertionEditorApiConfig;\n performInsertion: (insertedText: string) => void;\n closeWindow: () => void;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBox = (props: Props) => {\n return (\n <div\n className=\"flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white\"\n style={{ width: \"35rem\" }}\n >\n <HoveringInsertionPromptBoxCore\n state={{\n editorState: props.editorState,\n }}\n insertionOrEditingFunction={props.apiConfig.insertionOrEditingFunction}\n performInsertion={props.performInsertion}\n contextCategories={props.contextCategories}\n />\n </div>\n );\n};\n"],"mappings":";;;;;AAoBM;AANC,IAAM,6BAA6B,CAAC,UAAiB;AAC1D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,OAAO,QAAQ;AAAA,MAExB;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,aAAa,MAAM;AAAA,UACrB;AAAA,UACA,4BAA4B,MAAM,UAAU;AAAA,UAC5C,kBAAkB,MAAM;AAAA,UACxB,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Descendant, Editor } from \"slate\";\nimport { Editable, Slate } from \"slate-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { useAutosuggestions } from \"../../hooks/base-copilot-textarea-implementation/use-autosuggestions\";\nimport { useCopilotTextareaEditor } from \"../../hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor\";\nimport { usePopulateCopilotTextareaRef } from \"../../hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundCollapsedCursor,\n} from \"../../lib/get-text-around-cursor\";\nimport { addAutocompletionsToEditor } from \"../../lib/slatejs-edits/add-autocompletions\";\nimport { clearAutocompletionsFromEditor } from \"../../lib/slatejs-edits/clear-autocompletions\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport \"./base-copilot-textarea.css\";\nimport { HoveringToolbar } from \"../hovering-toolbar/hovering-toolbar\";\nimport { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\nimport {\n HoveringEditorProvider,\n useHoveringEditorContext,\n} from \"../hovering-toolbar/hovering-editor-provider\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\n/**\n * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.\n *\n * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that \"actually matters\".\n * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:\n * - `value`: the current value of the textarea\n * - `focus`: make the textarea focused\n * - `blur`: make the textarea unfocused\n */\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n /**\n * The current value of the textarea.\n */\n value: string;\n\n /**\n * focus on the textarea\n */\n focus: () => void;\n\n /**\n * unfocus the textarea.\n *\n * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.\n */\n blur: () => void;\n}\n\n/**\n * Not intended for direct use. Use CopilotTextarea instead.\n *\n * The `BaseCopilotTextarea` includes the basic UX component,\n * without the business logic / AI logic that makes the content useful and coherent.\n *\n * It is useful if you want to build your own backend, with fully custom business logic\n * for figuring out which contnet to fill in.\n */\nexport const BaseCopilotTextarea = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n },\n);\n\n/**\n * Not intended for direct use. Use `CopilotTextarea` instead.\n *\n * This is the private core of the `BaseCopilotTextarea` component.\n * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.\n *\n * Therefore we separate the core logic into this component,\n * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.\n */\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.baseAutosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);\n const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);\n\n // // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.\n // useEffect(() => {\n // setCursorMovedSinceLastTextChange(false);\n // }, [lastKnownFullEditorText]);\n\n const initialValue: Descendant[] = useMemo(() => {\n return [\n {\n type: \"paragraph\",\n children: [{ text: valueOnInitialRender }],\n },\n ];\n }, [valueOnInitialRender]);\n\n const editor = useCopilotTextareaEditor();\n\n const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } =\n useHoveringEditorContext();\n\n const insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor],\n );\n\n const shouldDisableAutosuggestions =\n // textarea is manually disabled:\n autosuggestionsConfig.disabled ||\n // hovering editor is displayed:\n hoveringEditorIsDisplayed ||\n // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText);\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n onTouchStartHandler: onTouchStartHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n shouldDisableAutosuggestions,\n );\n\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, props.shortcut ?? \"k\")\n ) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [\n hoveringEditorIsDisplayed,\n setHoveringEditorIsDisplayed,\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress,\n ],\n );\n\n // sync autosuggestions state with the editor\n useEffect(() => {\n clearAutocompletionsFromEditor(editor);\n if (currentAutocompleteSuggestion) {\n addAutocompletionsToEditor(\n editor,\n currentAutocompleteSuggestion.text,\n currentAutocompleteSuggestion.point,\n );\n }\n }, [currentAutocompleteSuggestion]);\n\n const suggestionStyleAugmented: React.CSSProperties = useMemo(() => {\n return {\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n };\n }, [props.suggestionsStyle]);\n\n const renderElementMemoized = useMemo(() => {\n return makeRenderElementFunction(suggestionStyleAugmented);\n }, [suggestionStyleAugmented]);\n\n const renderPlaceholderMemoized = useMemo(() => {\n // For some reason slateJS specifies a top value of 0, which makes for strange styling. We override this here.\n const placeholderStyleSlatejsOverrides: React.CSSProperties = {\n top: undefined,\n };\n\n const placeholderStyleAugmented: React.CSSProperties = {\n ...placeholderStyleSlatejsOverrides,\n ...props.placeholderStyle,\n };\n\n return makeRenderPlaceholderFunction(placeholderStyleAugmented);\n }, [props.placeholderStyle]);\n\n // update the editor text, but only when the value changes from outside the component\n useEffect(() => {\n if (props.value === lastKnownFullEditorText) {\n return;\n }\n\n setLastKnownFullEditorText(props.value ?? \"\");\n replaceEditorText(editor, props.value ?? \"\");\n }, [props.value]);\n\n // separate into TextareaHTMLAttributes<HTMLDivElement> and CopilotTextareaProps\n const {\n placeholderStyle,\n value,\n hoverMenuClassname,\n onValueChange,\n baseAutosuggestionsConfig: autosuggestionsConfigFromProps,\n className,\n onChange,\n onKeyDown,\n disableBranding,\n ...propsToForward\n } = props;\n\n useAddBrandingCss(suggestionStyleAugmented, disableBranding);\n usePopulateCopilotTextareaRef(editor, ref);\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = disableBranding ? \"no-branding\" : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(defaultTailwindClassName, className ?? \"\");\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCollapsedCursor(editor);\n\n const fullEditorText = newEditorState\n ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor\n : getFullEditorTextWithNewlines(editor); // we don't double-parse the editor. When `newEditorState` is null, we didn't parse the editor yet.\n\n setLastKnownFullEditorText((prev) => {\n if (prev !== fullEditorText) {\n setCursorMovedSinceLastTextChange(false);\n }\n return fullEditorText;\n });\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar\n apiConfig={autosuggestionsConfig.apiConfig}\n contextCategories={autosuggestionsConfig.contextCategories}\n hoverMenuClassname={hoverMenuClassname}\n />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\n onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use\n onKeyDownHandlerForAutocomplete(event); // forward the event for internal use\n props.onKeyDown?.(event); // forward the event for external use\n }}\n onTouchStart={(event) => {\n onTouchStartHandlerForAutocomplete(event); // forward the event for internal use\n }}\n data-testid=\"copilot-textarea-editable\"\n className={moddedClassName}\n onBlur={(ev) => {\n // clear autocompletion on blur\n props.onBlur?.(ev);\n clearAutocompletionsFromEditor(editor);\n }}\n {...propsToForward}\n />\n </Slate>\n );\n },\n);\n\n// Consumers of <textarea> expect a `onChange: (React.ChangeEvent<HTMLTextAreaElement>) => void` event handler to be passed in.\n// This is *extremely* common, and we want to support it.\n//\n// We can't support the full functionality, but in 99% of cases, the consumer only cares about the `event.target.value` property --\n// that's how they get the new value of the textarea.\n//\n// So, the tradeoff we are making is minimizing compiler complaint, with a small chance of runtime error.\n// The alternative would be defining a different onChange entrypoint (we actually do have that in `onValueChange`),\n// And starting to explain subtleties to users the moment they try to use the component for the first time for very basic functionality.\n//\n// If this proves problematic, we can always revisit this decision.\nfunction makeSemiFakeReactTextAreaEvent(\n currentText: string,\n): React.ChangeEvent<HTMLTextAreaElement> {\n return {\n target: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n currentTarget: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n } as React.ChangeEvent<HTMLTextAreaElement>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AAkEhB,cAwKF,YAxKE;AAJD,IAAM,sBAAsB,MAAM;AAAA,EACvC,CAAC,OAAiC,QAA+C;AAC/E,WACE,oBAAC,0BACC,8BAAC,yEAA2C,QAA3C,EAAkD,MAAU,GAC/D;AAAA,EAEJ;AACF;AAWA,IAAM,yCAAyC,MAAM;AAAA,EACnD,CAAC,OAAiC,QAA+C;AAC/E,UAAM,wBAAmD,kCACpD,mCACA,MAAM;AAGX,UAAM,uBAAuB,QAAQ,MAAG;AA3F5C,UAAAA;AA2F+C,cAAAA,MAAA,MAAM,UAAN,OAAAA,MAAe;AAAA,OAAI,CAAC,CAAC;AAChE,UA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