@copilotkit/react-textarea 0.18.0 → 0.19.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +304 -190
- package/CHANGELOG.md +11 -0
- package/dist/chunk-2NURR2DX.mjs +47 -0
- package/dist/chunk-2NURR2DX.mjs.map +1 -0
- package/dist/chunk-3YJ63D5D.mjs +106 -0
- package/dist/chunk-3YJ63D5D.mjs.map +1 -0
- package/dist/chunk-4S5ZJH3I.mjs +18 -0
- package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
- package/dist/chunk-4T72ROFJ.mjs +469 -0
- package/dist/chunk-4T72ROFJ.mjs.map +1 -0
- package/dist/chunk-55EGOC5T.mjs +87 -0
- package/dist/chunk-55EGOC5T.mjs.map +1 -0
- package/dist/{chunk-3A2CNIG5.mjs → chunk-5ARCOTW3.mjs} +8 -5
- package/dist/chunk-5ARCOTW3.mjs.map +1 -0
- package/dist/chunk-5EJ5XOGP.mjs +22 -0
- package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
- package/dist/chunk-5FO6ISW4.mjs +3 -0
- package/dist/{chunk-JWN2VEE3.mjs → chunk-A2RRLD23.mjs} +13 -12
- package/dist/chunk-A2RRLD23.mjs.map +1 -0
- package/dist/chunk-ASPOPGV7.mjs +47 -0
- package/dist/chunk-ASPOPGV7.mjs.map +1 -0
- package/dist/chunk-CDB7HFCY.mjs +65 -0
- package/dist/chunk-CDB7HFCY.mjs.map +1 -0
- package/dist/chunk-CIFH63LP.mjs +107 -0
- package/dist/chunk-CIFH63LP.mjs.map +1 -0
- package/dist/{chunk-MFJNLKRC.mjs → chunk-D7SEV5PR.mjs} +4 -3
- package/dist/chunk-D7SEV5PR.mjs.map +1 -0
- package/dist/chunk-HAFHLU4N.mjs +55 -0
- package/dist/chunk-HAFHLU4N.mjs.map +1 -0
- package/dist/{chunk-3UQM3NLM.mjs → chunk-IXJ2HCOA.mjs} +42 -7
- package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
- package/dist/{chunk-UW3ITU2Y.mjs → chunk-JAFCXEPU.mjs} +1 -1
- package/dist/chunk-JAFCXEPU.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +3 -0
- package/dist/{chunk-5GGCWNTT.mjs → chunk-MA4NHL3H.mjs} +68 -30
- package/dist/chunk-MA4NHL3H.mjs.map +1 -0
- package/dist/chunk-ND5PXTAW.mjs +17 -0
- package/dist/chunk-ND5PXTAW.mjs.map +1 -0
- package/dist/chunk-O5OWT5GE.mjs +114 -0
- package/dist/chunk-O5OWT5GE.mjs.map +1 -0
- package/dist/chunk-OD7ZMOVE.mjs +45 -0
- package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
- package/dist/chunk-QL2GYGG5.mjs +19 -0
- package/dist/chunk-QL2GYGG5.mjs.map +1 -0
- package/dist/{chunk-HZGSG7ST.mjs → chunk-UHD44NC5.mjs} +10 -5
- package/dist/chunk-UHD44NC5.mjs.map +1 -0
- package/dist/chunk-VBIJPE3H.mjs +108 -0
- package/dist/chunk-VBIJPE3H.mjs.map +1 -0
- package/dist/chunk-VHIS7RTM.mjs +44 -0
- package/dist/chunk-VHIS7RTM.mjs.map +1 -0
- package/dist/chunk-XDT7BF3V.mjs +81 -0
- package/dist/chunk-XDT7BF3V.mjs.map +1 -0
- package/dist/chunk-XHUMROEY.mjs +91 -0
- package/dist/chunk-XHUMROEY.mjs.map +1 -0
- package/dist/{chunk-LWVCQYWV.mjs → chunk-YQU7WG7T.mjs} +2 -2
- package/dist/chunk-YTOPHPSG.mjs +45 -0
- package/dist/chunk-YTOPHPSG.mjs.map +1 -0
- package/dist/chunk-YW3REYX6.mjs +23 -0
- package/dist/chunk-YW3REYX6.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +3 -5
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +22 -8
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +6 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +5 -0
- package/dist/components/copilot-textarea/copilot-textarea.d.ts +13 -10
- package/dist/components/copilot-textarea/copilot-textarea.mjs +32 -13
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +13 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +4 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +4 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +8 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +17 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +12 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +12 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +3 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +13 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.d.ts +16 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.mjs +5 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.d.ts +37 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.mjs +10 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.mjs.map +1 -0
- package/dist/components/index.d.ts +9 -4
- package/dist/components/index.mjs +32 -13
- package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
- package/dist/components/manual-ui/chip-with-icon.mjs +25 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
- package/dist/components/source-search-box/source-search-box.d.ts +17 -0
- package/dist/components/source-search-box/source-search-box.mjs +10 -0
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
- package/dist/components/ui/button.d.ts +14 -0
- package/dist/components/ui/button.mjs +5 -0
- package/dist/components/ui/button.mjs.map +1 -0
- package/dist/components/ui/card.d.ts +10 -0
- package/dist/components/ui/card.mjs +63 -0
- package/dist/components/ui/card.mjs.map +1 -0
- package/dist/components/ui/command.d.ts +48 -0
- package/dist/components/ui/command.mjs +6 -0
- package/dist/components/ui/command.mjs.map +1 -0
- package/dist/components/ui/dialog.d.ts +18 -0
- package/dist/components/ui/dialog.mjs +5 -0
- package/dist/components/ui/dialog.mjs.map +1 -0
- package/dist/components/ui/label.d.ts +8 -0
- package/dist/components/ui/label.mjs +5 -0
- package/dist/components/ui/label.mjs.map +1 -0
- package/dist/components/ui/separator.d.ts +6 -0
- package/dist/components/ui/separator.mjs +26 -0
- package/dist/components/ui/separator.mjs.map +1 -0
- package/dist/components/ui/textarea.d.ts +7 -0
- package/dist/components/ui/textarea.mjs +22 -0
- package/dist/components/ui/textarea.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +2 -2
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +2 -2
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +2 -2
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +5 -7
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +2 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +5 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs +4 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
- package/dist/index.css +674 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.mjs +33 -14
- package/dist/lib/editor-to-text.mjs +1 -42
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.d.ts +10 -3
- package/dist/lib/get-text-around-cursor.mjs +1 -1
- package/dist/lib/retry.d.ts +3 -0
- package/dist/lib/retry.mjs +4 -0
- package/dist/lib/retry.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +25 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +3 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +10 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +17 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs +5 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/index.d.ts +10 -0
- package/dist/types/autosuggestions-config/index.mjs +11 -0
- package/dist/types/autosuggestions-config/index.mjs.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +17 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +5 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
- package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/chatlike-api-endpoint.d.ts +7 -4
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +4 -0
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +3 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +17 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +5 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.d.ts +16 -2
- package/dist/types/base/base-autosuggestions-config.d.ts +5 -1
- package/dist/types/base/base-autosuggestions-config.mjs +1 -1
- package/dist/types/base/base-copilot-textarea-props.d.ts +3 -1
- package/dist/types/base/editor-autocomplete-state.mjs +1 -1
- package/dist/types/base/index.mjs +1 -1
- package/dist/types/index.d.ts +8 -3
- package/dist/types/index.mjs +7 -4
- package/package.json +19 -5
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +64 -13
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +61 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +29 -17
- package/src/components/hovering-toolbar/hovering-editor-provider.tsx +29 -0
- package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +115 -0
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +156 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +70 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/index.ts +2 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.tsx +83 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.tsx +399 -0
- package/src/components/manual-ui/chip-with-icon.tsx +29 -0
- package/src/components/source-search-box/source-search-box.tsx +127 -0
- package/src/components/ui/button.tsx +56 -0
- package/src/components/ui/card.tsx +86 -0
- package/src/components/ui/command.tsx +155 -0
- package/src/components/ui/dialog.tsx +123 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +10 -3
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +29 -44
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +150 -0
- package/src/hooks/misc/use-autosize-textarea.tsx +21 -0
- package/src/lib/get-text-around-cursor.ts +71 -6
- package/src/lib/retry.tsx +23 -0
- package/src/styles.css +2 -0
- package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +27 -0
- package/src/types/autosuggestions-config/autosuggestions-config.tsx +43 -0
- package/src/types/autosuggestions-config/editing-api-config.tsx +102 -0
- package/src/types/autosuggestions-config/index.ts +11 -0
- package/src/types/autosuggestions-config/insertions-api-config.tsx +95 -0
- package/src/types/{standard-autosuggestions → autosuggestions-config/subtypes}/chatlike-api-endpoint.tsx +19 -7
- package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +4 -0
- package/src/types/{standard-autosuggestions/autosuggestions-config.tsx → autosuggestions-config/suggestions-api-config.tsx} +12 -23
- package/src/types/base/autosuggestions-bare-function.ts +24 -2
- package/src/types/base/base-autosuggestions-config.tsx +7 -2
- package/src/types/base/base-copilot-textarea-props.tsx +3 -1
- package/src/types/base/editor-autocomplete-state.ts +1 -0
- package/src/types/index.ts +1 -1
- package/tailwind.config.js +2 -0
- package/dist/chunk-3A2CNIG5.mjs.map +0 -1
- package/dist/chunk-3UQM3NLM.mjs.map +0 -1
- package/dist/chunk-5GGCWNTT.mjs.map +0 -1
- package/dist/chunk-BLRD23HM.mjs +0 -32
- package/dist/chunk-BLRD23HM.mjs.map +0 -1
- package/dist/chunk-BTAUKCBN.mjs +0 -60
- package/dist/chunk-BTAUKCBN.mjs.map +0 -1
- package/dist/chunk-HZGSG7ST.mjs.map +0 -1
- package/dist/chunk-JWN2VEE3.mjs.map +0 -1
- package/dist/chunk-MFJNLKRC.mjs.map +0 -1
- package/dist/chunk-SL4J5HMW.mjs +0 -3
- package/dist/chunk-UW3ITU2Y.mjs.map +0 -1
- package/dist/types/standard-autosuggestions/autosuggestions-config.d.ts +0 -19
- package/dist/types/standard-autosuggestions/autosuggestions-config.mjs +0 -6
- package/dist/types/standard-autosuggestions/chatlike-api-endpoint.mjs +0 -4
- package/dist/types/standard-autosuggestions/index.d.ts +0 -4
- package/dist/types/standard-autosuggestions/index.mjs +0 -8
- package/src/types/standard-autosuggestions/index.ts +0 -14
- /package/dist/{chunk-SL4J5HMW.mjs.map → chunk-5FO6ISW4.mjs.map} +0 -0
- /package/dist/{types/standard-autosuggestions/autosuggestions-config.mjs.map → chunk-L7VVZH4Q.mjs.map} +0 -0
- /package/dist/{chunk-LWVCQYWV.mjs.map → chunk-YQU7WG7T.mjs.map} +0 -0
- /package/dist/{types/standard-autosuggestions/chatlike-api-endpoint.mjs.map → components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map} +0 -0
- /package/dist/{types/standard-autosuggestions/index.mjs.map → components/hovering-toolbar/hovering-editor-provider.mjs.map} +0 -0
- /package/dist/{types/standard-autosuggestions/minimal-chat-gpt-message.mjs.map → components/hovering-toolbar/hovering-toolbar-components.mjs.map} +0 -0
- /package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.d.ts +0 -0
- /package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.mjs +0 -0
- /package/src/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.tsx +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { CopilotContext } from "@copilotkit/react-core";
|
|
2
|
+
import { useCallback, useContext } from "react";
|
|
3
|
+
import { MinimalChatGPTMessage } from "../../types";
|
|
4
|
+
import { retry } from "../../lib/retry";
|
|
5
|
+
import {
|
|
6
|
+
EditingEditorState,
|
|
7
|
+
Generator_InsertionOrEditingSuggestion,
|
|
8
|
+
InsertionEditorApiConfig,
|
|
9
|
+
InsertionEditorState,
|
|
10
|
+
} from "../../types/base/autosuggestions-bare-function";
|
|
11
|
+
import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
|
|
12
|
+
import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
16
|
+
* The function takes in the text before and after the cursor, and an abort signal.
|
|
17
|
+
* It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
|
|
18
|
+
* The function returns the suggestion from the API response.
|
|
19
|
+
*
|
|
20
|
+
* @param textareaPurpose - The purpose of the textarea. This is included in the system message.
|
|
21
|
+
* @param apiEndpoint - The API endpoint to send the autosuggestion request to.
|
|
22
|
+
* @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
|
|
23
|
+
* @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
|
|
24
|
+
* @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
|
|
25
|
+
* @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
26
|
+
*/
|
|
27
|
+
export function useMakeStandardInsertionOrEditingFunction(
|
|
28
|
+
textareaPurpose: string,
|
|
29
|
+
contextCategories: string[] | undefined,
|
|
30
|
+
insertionApiConfig: InsertionsApiConfig,
|
|
31
|
+
editingApiConfig: EditingApiConfig
|
|
32
|
+
): Generator_InsertionOrEditingSuggestion {
|
|
33
|
+
const { getContextString } = useContext(CopilotContext);
|
|
34
|
+
|
|
35
|
+
const insertionFunction = useCallback(
|
|
36
|
+
async (
|
|
37
|
+
editorState: EditingEditorState,
|
|
38
|
+
insertionPrompt: string,
|
|
39
|
+
abortSignal: AbortSignal
|
|
40
|
+
) => {
|
|
41
|
+
const res = await retry(async () => {
|
|
42
|
+
const messages: MinimalChatGPTMessage[] = [
|
|
43
|
+
{
|
|
44
|
+
role: "system",
|
|
45
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
46
|
+
textareaPurpose,
|
|
47
|
+
getContextString(contextCategories)
|
|
48
|
+
),
|
|
49
|
+
},
|
|
50
|
+
...insertionApiConfig.fewShotMessages,
|
|
51
|
+
{
|
|
52
|
+
role: "user",
|
|
53
|
+
name: "TextAfterCursor",
|
|
54
|
+
content: editorState.textAfterCursor,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
role: "user",
|
|
58
|
+
name: "TextBeforeCursor",
|
|
59
|
+
content: editorState.textBeforeCursor,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
role: "user",
|
|
63
|
+
name: "InsertionPrompt",
|
|
64
|
+
content: insertionPrompt,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
return await insertionApiConfig.apiEndpoint.run(
|
|
69
|
+
abortSignal,
|
|
70
|
+
messages,
|
|
71
|
+
insertionApiConfig.forwardedParams
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return res;
|
|
76
|
+
},
|
|
77
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const editingFunction = useCallback(
|
|
81
|
+
async (
|
|
82
|
+
editorState: EditingEditorState,
|
|
83
|
+
editingPrompt: string,
|
|
84
|
+
abortSignal: AbortSignal
|
|
85
|
+
) => {
|
|
86
|
+
const res = await retry(async () => {
|
|
87
|
+
const messages: MinimalChatGPTMessage[] = [
|
|
88
|
+
{
|
|
89
|
+
role: "system",
|
|
90
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
91
|
+
textareaPurpose,
|
|
92
|
+
getContextString(contextCategories)
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
...editingApiConfig.fewShotMessages,
|
|
96
|
+
{
|
|
97
|
+
role: "user",
|
|
98
|
+
name: "TextBeforeCursor",
|
|
99
|
+
content: editorState.textBeforeCursor,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
role: "user",
|
|
103
|
+
name: "TextToEdit",
|
|
104
|
+
content: editorState.selectedText,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
role: "user",
|
|
108
|
+
name: "TextAfterCursor",
|
|
109
|
+
content: editorState.textAfterCursor,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
role: "user",
|
|
113
|
+
name: "EditingPrompt",
|
|
114
|
+
content: editingPrompt,
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
return await editingApiConfig.apiEndpoint.run(
|
|
119
|
+
abortSignal,
|
|
120
|
+
messages,
|
|
121
|
+
editingApiConfig.forwardedParams
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return res;
|
|
126
|
+
},
|
|
127
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const insertionOrEditingFunction = useCallback(
|
|
131
|
+
async (
|
|
132
|
+
editorState: EditingEditorState,
|
|
133
|
+
insertionPrompt: string,
|
|
134
|
+
abortSignal: AbortSignal
|
|
135
|
+
) => {
|
|
136
|
+
if (editorState.selectedText === "") {
|
|
137
|
+
return await insertionFunction(
|
|
138
|
+
editorState,
|
|
139
|
+
insertionPrompt,
|
|
140
|
+
abortSignal
|
|
141
|
+
);
|
|
142
|
+
} else {
|
|
143
|
+
return await editingFunction(editorState, insertionPrompt, abortSignal);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
[insertionFunction, editingFunction]
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
return insertionOrEditingFunction;
|
|
150
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Ref, RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
// Updates the height of a <textarea> when the value changes.
|
|
4
|
+
const useAutosizeTextArea = (
|
|
5
|
+
textAreaRef: RefObject<HTMLTextAreaElement>,
|
|
6
|
+
value: string
|
|
7
|
+
) => {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (textAreaRef.current !== null) {
|
|
10
|
+
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
|
|
11
|
+
textAreaRef.current.style.height = "0px";
|
|
12
|
+
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
13
|
+
|
|
14
|
+
// We then set the height directly, outside of the render loop
|
|
15
|
+
// Trying to set this with state or a ref will product an incorrect value.
|
|
16
|
+
textAreaRef.current.style.height = scrollHeight + "px";
|
|
17
|
+
}
|
|
18
|
+
}, [textAreaRef, value]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default useAutosizeTextArea;
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Editor,
|
|
3
|
+
Node,
|
|
4
|
+
Path,
|
|
5
|
+
Range,
|
|
6
|
+
Text,
|
|
7
|
+
Element,
|
|
8
|
+
BasePoint,
|
|
9
|
+
BaseRange,
|
|
10
|
+
Point,
|
|
11
|
+
} from "slate";
|
|
2
12
|
import { EditorAutocompleteState } from "../types/base/editor-autocomplete-state";
|
|
3
13
|
|
|
4
|
-
export
|
|
14
|
+
export interface EditorTextState {
|
|
15
|
+
selection: BaseRange;
|
|
16
|
+
|
|
17
|
+
textBeforeCursor: string;
|
|
18
|
+
selectedText: string;
|
|
19
|
+
textAfterCursor: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getTextAroundCollapsedCursor(
|
|
5
23
|
editor: Editor
|
|
6
24
|
): EditorAutocompleteState | null {
|
|
7
25
|
const { selection } = editor;
|
|
8
|
-
|
|
9
26
|
if (!selection || !Range.isCollapsed(selection)) {
|
|
10
27
|
return null;
|
|
11
28
|
}
|
|
29
|
+
|
|
30
|
+
const cursorPoint = selection.anchor;
|
|
31
|
+
|
|
12
32
|
// Create two ranges: one before the anchor and one after
|
|
13
33
|
const beforeRange: Range = {
|
|
14
34
|
anchor: Editor.start(editor, []),
|
|
15
|
-
focus:
|
|
35
|
+
focus: cursorPoint,
|
|
16
36
|
};
|
|
17
37
|
const afterRange: Range = {
|
|
18
|
-
anchor:
|
|
38
|
+
anchor: cursorPoint,
|
|
19
39
|
focus: Editor.end(editor, []),
|
|
20
40
|
};
|
|
21
41
|
|
|
@@ -24,12 +44,43 @@ export function getTextAroundCursor(
|
|
|
24
44
|
const after = extractTextWithNewlines(editor, afterRange);
|
|
25
45
|
|
|
26
46
|
return {
|
|
27
|
-
cursorPoint:
|
|
47
|
+
cursorPoint: cursorPoint,
|
|
28
48
|
textBeforeCursor: before,
|
|
29
49
|
textAfterCursor: after,
|
|
30
50
|
};
|
|
31
51
|
}
|
|
32
52
|
|
|
53
|
+
export function getTextAroundSelection(editor: Editor): EditorTextState | null {
|
|
54
|
+
const { selection } = editor;
|
|
55
|
+
if (!selection) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
60
|
+
|
|
61
|
+
// Create two ranges: one before the anchor and one after
|
|
62
|
+
const beforeRange: Range = {
|
|
63
|
+
anchor: Editor.start(editor, []),
|
|
64
|
+
focus: wellOrderedSelection.anchor,
|
|
65
|
+
};
|
|
66
|
+
const afterRange: Range = {
|
|
67
|
+
anchor: wellOrderedSelection.focus,
|
|
68
|
+
focus: Editor.end(editor, []),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Extract text for these ranges
|
|
72
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
73
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
74
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
selection: wellOrderedSelection,
|
|
78
|
+
textBeforeCursor: before,
|
|
79
|
+
selectedText,
|
|
80
|
+
textAfterCursor: after,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
33
84
|
export function getFullEditorTextWithNewlines(editor: Editor): string {
|
|
34
85
|
const fullDocumentRange: Range = {
|
|
35
86
|
anchor: Editor.start(editor, []),
|
|
@@ -80,3 +131,17 @@ export function extractTextWithNewlines(editor: Editor, range: Range): string {
|
|
|
80
131
|
|
|
81
132
|
return text;
|
|
82
133
|
}
|
|
134
|
+
|
|
135
|
+
function wellOrderedRange(range: BaseRange): BaseRange {
|
|
136
|
+
const { anchor, focus } = range;
|
|
137
|
+
// if anchor is before focus, return range as is
|
|
138
|
+
if (Point.isBefore(anchor, focus)) {
|
|
139
|
+
return range;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// if focus is before anchor, return range with anchor and focus swapped
|
|
143
|
+
return {
|
|
144
|
+
anchor: focus,
|
|
145
|
+
focus: anchor,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function retry<T>(
|
|
2
|
+
fn: () => Promise<T>,
|
|
3
|
+
retriesLeft: number = 2,
|
|
4
|
+
interval: number = 200,
|
|
5
|
+
backoff: number = 1.5
|
|
6
|
+
): Promise<T> {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
fn()
|
|
9
|
+
.then(resolve)
|
|
10
|
+
.catch((error) => {
|
|
11
|
+
if (retriesLeft === 1) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff)
|
|
18
|
+
.then(resolve)
|
|
19
|
+
.catch(reject);
|
|
20
|
+
}, interval);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
package/src/styles.css
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AutosuggestionsConfig, ChatlikeApiEndpoint } from ".";
|
|
2
|
+
import { InsertionsApiConfig } from "./insertions-api-config";
|
|
3
|
+
import { SuggestionsApiConfig } from "./suggestions-api-config";
|
|
4
|
+
|
|
5
|
+
// Mostly mirrors a partial SuggestionsApiConfig, but with some fields MANDATORY.
|
|
6
|
+
export interface SuggestionsApiConfigUserSpecified
|
|
7
|
+
extends Partial<Omit<SuggestionsApiConfig, "apiEndpoint">> {
|
|
8
|
+
apiEndpoint: ChatlikeApiEndpoint;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Mostly mirrors a partial InsertionsApiConfig, but with some fields MANDATORY.
|
|
12
|
+
export interface InsertionsApiConfigUserSpecified
|
|
13
|
+
extends Partial<Omit<InsertionsApiConfig, "apiEndpoint">> {
|
|
14
|
+
apiEndpoint: ChatlikeApiEndpoint;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Mostly mirrors a partial AutosuggestionsConfig, but with some fields MANDATORY.
|
|
18
|
+
export interface AutosuggestionsConfigUserSpecified
|
|
19
|
+
extends Partial<
|
|
20
|
+
Omit<AutosuggestionsConfig, "chatApiConfigs" | "textareaPurpose">
|
|
21
|
+
> {
|
|
22
|
+
textareaPurpose: string; // the user MUST specify textareaPurpose - it's not optional
|
|
23
|
+
chatApiConfigs: {
|
|
24
|
+
suggestionsApiConfig?: SuggestionsApiConfigUserSpecified;
|
|
25
|
+
insertionApiConfig?: InsertionsApiConfigUserSpecified;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseAutosuggestionsConfig,
|
|
3
|
+
defaultBaseAutosuggestionsConfig,
|
|
4
|
+
} from "../base";
|
|
5
|
+
import {
|
|
6
|
+
SuggestionsApiConfig,
|
|
7
|
+
defaultSuggestionsApiConfig,
|
|
8
|
+
} from "./suggestions-api-config";
|
|
9
|
+
import {
|
|
10
|
+
InsertionsApiConfig,
|
|
11
|
+
defaultInsertionsApiConfig,
|
|
12
|
+
} from "./insertions-api-config";
|
|
13
|
+
import { ChatlikeApiEndpoint } from ".";
|
|
14
|
+
import {
|
|
15
|
+
EditingApiConfig,
|
|
16
|
+
defaultEditingApiConfig,
|
|
17
|
+
} from "./editing-api-config";
|
|
18
|
+
|
|
19
|
+
// Like the base autosuggestions config, with 2 additional fields:
|
|
20
|
+
// 1. externalContextCategories: string[] | undefined;
|
|
21
|
+
// 2. instead of apiConfigs, we have chatApiConfigs: a higher-level abstraction that uses a ChatGPT-like API endpoint.
|
|
22
|
+
export interface AutosuggestionsConfig
|
|
23
|
+
extends Omit<BaseAutosuggestionsConfig, "apiConfig"> {
|
|
24
|
+
externalContextCategories: string[] | undefined;
|
|
25
|
+
chatApiConfigs: {
|
|
26
|
+
suggestionsApiConfig: SuggestionsApiConfig;
|
|
27
|
+
insertionApiConfig: InsertionsApiConfig;
|
|
28
|
+
editingApiConfig: EditingApiConfig;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const defaultAutosuggestionsConfig: Omit<
|
|
33
|
+
AutosuggestionsConfig,
|
|
34
|
+
"textareaPurpose" | "apiEndpoint"
|
|
35
|
+
> = {
|
|
36
|
+
...defaultBaseAutosuggestionsConfig,
|
|
37
|
+
externalContextCategories: undefined,
|
|
38
|
+
chatApiConfigs: {
|
|
39
|
+
suggestionsApiConfig: defaultSuggestionsApiConfig,
|
|
40
|
+
insertionApiConfig: defaultInsertionsApiConfig,
|
|
41
|
+
editingApiConfig: defaultEditingApiConfig,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ChatlikeApiEndpoint } from "./subtypes/chatlike-api-endpoint";
|
|
2
|
+
import { MakeSystemPrompt } from "./subtypes/make-system-prompt";
|
|
3
|
+
import { MinimalChatGPTMessage } from "./subtypes/minimal-chat-gpt-message";
|
|
4
|
+
|
|
5
|
+
export interface EditingApiConfig {
|
|
6
|
+
apiEndpoint: ChatlikeApiEndpoint;
|
|
7
|
+
makeSystemPrompt: MakeSystemPrompt;
|
|
8
|
+
fewShotMessages: MinimalChatGPTMessage[];
|
|
9
|
+
forwardedParams: { [key: string]: any } | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (
|
|
13
|
+
textareaPurpose,
|
|
14
|
+
contextString
|
|
15
|
+
) => {
|
|
16
|
+
return `You are a versatile writing assistant.
|
|
17
|
+
|
|
18
|
+
The user is writing some text.
|
|
19
|
+
The purpose is: \"${textareaPurpose}\"
|
|
20
|
+
|
|
21
|
+
The user also provides you with a prompt for EDITING some text they are writing.
|
|
22
|
+
Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
|
|
23
|
+
|
|
24
|
+
Adjust yourself to the user's style and implied intent.
|
|
25
|
+
|
|
26
|
+
The user will provide the following information; use this to infer the best relevant EDIT:
|
|
27
|
+
<TextBeforeCursor>
|
|
28
|
+
<TextToEdit>
|
|
29
|
+
<TextAfterCursor>
|
|
30
|
+
<EditingPrompt>
|
|
31
|
+
|
|
32
|
+
<YourEditSuggestion>
|
|
33
|
+
|
|
34
|
+
If we need to add a whitespace character to the suggested edit text, make sure to explicitly add it in.
|
|
35
|
+
|
|
36
|
+
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
37
|
+
\`\`\`
|
|
38
|
+
${contextString}
|
|
39
|
+
\`\`\`
|
|
40
|
+
`;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [
|
|
44
|
+
{
|
|
45
|
+
role: "user",
|
|
46
|
+
name: "TextBeforeCursor",
|
|
47
|
+
content: "This morning I woke up and went straight to the grocery store. ",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
role: "user",
|
|
51
|
+
name: "TextToEdit",
|
|
52
|
+
content:
|
|
53
|
+
"While I was there I also picked up some apples, oranges, and bananas. ",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
role: "user",
|
|
57
|
+
name: "TextAfterCursor",
|
|
58
|
+
content:
|
|
59
|
+
"The grocery store was having a sale on fruit, so I decided to stock up.",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
role: "user",
|
|
63
|
+
name: "EditingPrompt",
|
|
64
|
+
content: "I bought a big watermelon",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
role: "assistant",
|
|
68
|
+
content:
|
|
69
|
+
" When I arrived I went straight to the produce section and picked out a big watermelon. ",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
role: "user",
|
|
73
|
+
name: "TextAfterCursor",
|
|
74
|
+
content:
|
|
75
|
+
"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
role: "user",
|
|
79
|
+
name: "TextBeforeCursor",
|
|
80
|
+
content:
|
|
81
|
+
'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;',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
role: "user",
|
|
85
|
+
name: "InsertionPrompt",
|
|
86
|
+
content: "add section about the optionholder's pro rata share",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
role: "assistant",
|
|
90
|
+
content:
|
|
91
|
+
' (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"; ',
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
export const defaultEditingApiConfig: EditingApiConfig = {
|
|
96
|
+
apiEndpoint: ChatlikeApiEndpoint.standardOpenAIEndpoint(
|
|
97
|
+
"/api/copilotkit_chatlike"
|
|
98
|
+
),
|
|
99
|
+
makeSystemPrompt: defaultEditingMakeSystemPrompt,
|
|
100
|
+
fewShotMessages: defaultEditingFewShotMessages,
|
|
101
|
+
forwardedParams: undefined,
|
|
102
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { defaultAutosuggestionsConfig } from "./autosuggestions-config";
|
|
2
|
+
export type { AutosuggestionsConfig } from "./autosuggestions-config";
|
|
3
|
+
|
|
4
|
+
export type { MinimalChatGPTMessage } from "./subtypes/minimal-chat-gpt-message";
|
|
5
|
+
export type { MakeSystemPrompt } from "./subtypes/make-system-prompt";
|
|
6
|
+
export { ChatlikeApiEndpoint } from "./subtypes/chatlike-api-endpoint";
|
|
7
|
+
export type { ChatlikeApiEndpointImpl } from "./subtypes/chatlike-api-endpoint";
|
|
8
|
+
|
|
9
|
+
export type { AutosuggestionsConfigUserSpecified } from "./autosuggestions-config-user-specified";
|
|
10
|
+
export type { SuggestionsApiConfigUserSpecified } from "./autosuggestions-config-user-specified";
|
|
11
|
+
export type { InsertionsApiConfigUserSpecified } from "./autosuggestions-config-user-specified";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ChatlikeApiEndpoint } from "./subtypes/chatlike-api-endpoint";
|
|
2
|
+
import { MakeSystemPrompt } from "./subtypes/make-system-prompt";
|
|
3
|
+
import { MinimalChatGPTMessage } from "./subtypes/minimal-chat-gpt-message";
|
|
4
|
+
|
|
5
|
+
export interface InsertionsApiConfig {
|
|
6
|
+
apiEndpoint: ChatlikeApiEndpoint;
|
|
7
|
+
makeSystemPrompt: MakeSystemPrompt;
|
|
8
|
+
fewShotMessages: MinimalChatGPTMessage[];
|
|
9
|
+
forwardedParams: { [key: string]: any } | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (
|
|
13
|
+
textareaPurpose,
|
|
14
|
+
contextString
|
|
15
|
+
) => {
|
|
16
|
+
return `You are a versatile writing assistant.
|
|
17
|
+
|
|
18
|
+
The user is writing some text.
|
|
19
|
+
The purpose is: \"${textareaPurpose}\"
|
|
20
|
+
|
|
21
|
+
The user also provides you with a prompt for INSERTIONS into the text they are writing.
|
|
22
|
+
Your job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.
|
|
23
|
+
Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
|
|
24
|
+
|
|
25
|
+
Adjust yourself to the user's style and implied intent.
|
|
26
|
+
|
|
27
|
+
The 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.
|
|
28
|
+
<TextAfterCursor>
|
|
29
|
+
<TextBeforeCursor>
|
|
30
|
+
<InsertionPrompt>
|
|
31
|
+
<YourSuggestion>
|
|
32
|
+
|
|
33
|
+
If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
|
|
34
|
+
|
|
35
|
+
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
36
|
+
\`\`\`
|
|
37
|
+
${contextString}
|
|
38
|
+
\`\`\`
|
|
39
|
+
`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const defaultInsertionsFewShotMessages: MinimalChatGPTMessage[] = [
|
|
43
|
+
{
|
|
44
|
+
role: "user",
|
|
45
|
+
name: "TextAfterCursor",
|
|
46
|
+
content:
|
|
47
|
+
"While I was there I also picked up some apples, oranges, and bananas.",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
role: "user",
|
|
51
|
+
name: "TextBeforeCursor",
|
|
52
|
+
content: "This morning I woke up and went straight to the grocery store.",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
role: "user",
|
|
56
|
+
name: "InsertionPrompt",
|
|
57
|
+
content: "I bought a big watermelon",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
role: "assistant",
|
|
61
|
+
content:
|
|
62
|
+
" When I arrived I went straight to the produce section and picked out a big watermelon. ",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
role: "user",
|
|
66
|
+
name: "TextAfterCursor",
|
|
67
|
+
content:
|
|
68
|
+
"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
role: "user",
|
|
72
|
+
name: "TextBeforeCursor",
|
|
73
|
+
content:
|
|
74
|
+
'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;',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
role: "user",
|
|
78
|
+
name: "InsertionPrompt",
|
|
79
|
+
content: "add section about the optionholder's pro rata share",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
role: "assistant",
|
|
83
|
+
content:
|
|
84
|
+
' (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"; ',
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export const defaultInsertionsApiConfig: InsertionsApiConfig = {
|
|
89
|
+
apiEndpoint: ChatlikeApiEndpoint.standardOpenAIEndpoint(
|
|
90
|
+
"/api/copilotkit_chatlike"
|
|
91
|
+
),
|
|
92
|
+
makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
|
|
93
|
+
fewShotMessages: defaultInsertionsFewShotMessages,
|
|
94
|
+
forwardedParams: undefined,
|
|
95
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MinimalChatGPTMessage } from "
|
|
1
|
+
import { MinimalChatGPTMessage } from "./minimal-chat-gpt-message";
|
|
2
2
|
|
|
3
3
|
export type ChatlikeApiEndpointImpl = (
|
|
4
4
|
abortSignal: AbortSignal,
|
|
@@ -6,10 +6,16 @@ export type ChatlikeApiEndpointImpl = (
|
|
|
6
6
|
forwardedProps?: { [key: string]: any }
|
|
7
7
|
) => Promise<string>;
|
|
8
8
|
|
|
9
|
+
export type StreamingChatlikeApiEndpointImpl = (
|
|
10
|
+
abortSignal: AbortSignal,
|
|
11
|
+
messages: MinimalChatGPTMessage[],
|
|
12
|
+
forwardedProps?: { [key: string]: any }
|
|
13
|
+
) => Promise<ReadableStream<string>>;
|
|
14
|
+
|
|
9
15
|
export class ChatlikeApiEndpoint {
|
|
10
|
-
public run:
|
|
16
|
+
public run: StreamingChatlikeApiEndpointImpl;
|
|
11
17
|
|
|
12
|
-
constructor(run:
|
|
18
|
+
constructor(run: StreamingChatlikeApiEndpointImpl) {
|
|
13
19
|
this.run = run;
|
|
14
20
|
}
|
|
15
21
|
|
|
@@ -34,9 +40,15 @@ export class ChatlikeApiEndpoint {
|
|
|
34
40
|
signal: abortSignal,
|
|
35
41
|
});
|
|
36
42
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
const bodySteram: ReadableStream<Uint8Array> | null = res.body;
|
|
44
|
+
if (!bodySteram) {
|
|
45
|
+
throw new Error("The response body is empty.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// map the stream to a stream of strings
|
|
49
|
+
const stringStream = bodySteram.pipeThrough(new TextDecoderStream());
|
|
50
|
+
|
|
51
|
+
return stringStream;
|
|
40
52
|
}
|
|
41
53
|
);
|
|
42
54
|
}
|
|
@@ -46,7 +58,7 @@ export class ChatlikeApiEndpoint {
|
|
|
46
58
|
* @param run - The implementation of the ChatlikeApiEndpointImpl interface.
|
|
47
59
|
* @returns A new instance of ChatlikeApiEndpoint .
|
|
48
60
|
*/
|
|
49
|
-
static custom(run:
|
|
61
|
+
static custom(run: StreamingChatlikeApiEndpointImpl): ChatlikeApiEndpoint {
|
|
50
62
|
return new ChatlikeApiEndpoint(run);
|
|
51
63
|
}
|
|
52
64
|
}
|