@copilotkit/react-textarea 0.37.0 → 0.38.0-beta.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 +216 -224
- package/CHANGELOG.md +13 -0
- package/dist/chunk-3SVQJA5A.mjs +169 -0
- package/dist/chunk-3SVQJA5A.mjs.map +1 -0
- package/dist/chunk-5KLAWLCD.mjs +88 -0
- package/dist/chunk-5KLAWLCD.mjs.map +1 -0
- package/dist/{chunk-QKS2IOUH.mjs → chunk-7QFH4E7C.mjs} +7 -5
- package/dist/chunk-7QFH4E7C.mjs.map +1 -0
- package/dist/chunk-CVO5T3PA.mjs +82 -0
- package/dist/chunk-CVO5T3PA.mjs.map +1 -0
- package/dist/{chunk-DKE57EAC.mjs → chunk-H3PGQHLG.mjs} +5 -5
- package/dist/{chunk-RKQ6RTZM.mjs → chunk-I6DJQ7D7.mjs} +33 -38
- package/dist/chunk-I6DJQ7D7.mjs.map +1 -0
- package/dist/{chunk-VAJHETSN.mjs → chunk-IF7CDWEH.mjs} +5 -5
- package/dist/{chunk-VAJHETSN.mjs.map → chunk-IF7CDWEH.mjs.map} +1 -1
- package/dist/{chunk-LCDTIJSD.mjs → chunk-OJXLHIYQ.mjs} +4 -2
- package/dist/chunk-OJXLHIYQ.mjs.map +1 -0
- package/dist/{chunk-ZRKQLLC7.mjs → chunk-R77MK6QS.mjs} +10 -5
- package/dist/{chunk-ZRKQLLC7.mjs.map → chunk-R77MK6QS.mjs.map} +1 -1
- package/dist/{chunk-O4LDWYJB.mjs → chunk-TNGDQV3I.mjs} +1 -2
- package/dist/{chunk-O4LDWYJB.mjs.map → chunk-TNGDQV3I.mjs.map} +1 -1
- package/dist/{chunk-KDVMG3XF.mjs → chunk-WMHVBGPR.mjs} +23 -25
- package/dist/chunk-WMHVBGPR.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +15 -7
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +4 -4
- package/dist/components/copilot-textarea/copilot-textarea.d.ts +2 -2
- package/dist/components/copilot-textarea/copilot-textarea.js +255 -207
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
- package/dist/components/hovering-toolbar/hovering-toolbar.js +0 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +251 -203
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +11 -11
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +2 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +6 -4
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +39 -31
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +100 -60
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +251 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.js +96 -108
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +5 -5
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/editing-api-config.js +39 -46
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
- package/dist/types/autosuggestions-config/index.d.ts +1 -1
- package/dist/types/autosuggestions-config/index.js +96 -108
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +5 -5
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/insertions-api-config.js +32 -37
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/suggestions-api-config.js +22 -24
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +1 -1
- package/dist/types/base/base-autosuggestions-config.d.ts +14 -0
- package/dist/types/base/base-autosuggestions-config.js +3 -1
- 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 +3 -1
- package/dist/types/base/index.js.map +1 -1
- package/dist/types/base/index.mjs +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +96 -108
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +5 -5
- package/package.json +7 -6
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +5 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +0 -1
- package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +11 -4
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +51 -31
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +116 -62
- package/src/types/autosuggestions-config/editing-api-config.tsx +48 -49
- package/src/types/autosuggestions-config/index.ts +0 -1
- package/src/types/autosuggestions-config/insertions-api-config.tsx +38 -40
- package/src/types/autosuggestions-config/suggestions-api-config.tsx +26 -27
- package/src/types/base/base-autosuggestions-config.tsx +17 -0
- package/dist/chunk-4OJ3H65F.mjs +0 -89
- package/dist/chunk-4OJ3H65F.mjs.map +0 -1
- package/dist/chunk-HE4GMS2P.mjs +0 -121
- package/dist/chunk-HE4GMS2P.mjs.map +0 -1
- package/dist/chunk-KDVMG3XF.mjs.map +0 -1
- package/dist/chunk-LCDTIJSD.mjs.map +0 -1
- package/dist/chunk-QKS2IOUH.mjs.map +0 -1
- package/dist/chunk-RKQ6RTZM.mjs.map +0 -1
- package/dist/chunk-SJ2TM5GA.mjs +0 -72
- package/dist/chunk-SJ2TM5GA.mjs.map +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +0 -7
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +0 -19
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +0 -1
- package/src/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.tsx +0 -5
- /package/dist/{chunk-DKE57EAC.mjs.map → chunk-H3PGQHLG.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 0.38.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Beta
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @copilotkit/react-core@0.38.0-beta.0
|
|
13
|
+
- @copilotkit/runtime-client-gql@0.38.0-beta.0
|
|
14
|
+
- @copilotkit/shared@0.38.0-beta.0
|
|
15
|
+
|
|
3
16
|
## 0.37.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
retry
|
|
3
|
+
} from "./chunk-KNQIEOFP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__async,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "./chunk-MRXNTQOX.mjs";
|
|
8
|
+
|
|
9
|
+
// src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
10
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
11
|
+
import { CopilotContext } from "@copilotkit/react-core";
|
|
12
|
+
import { useCallback, useContext } from "react";
|
|
13
|
+
import {
|
|
14
|
+
CopilotRuntimeClient,
|
|
15
|
+
Role,
|
|
16
|
+
TextMessage,
|
|
17
|
+
convertGqlOutputToMessages,
|
|
18
|
+
convertMessagesToGqlInput
|
|
19
|
+
} from "@copilotkit/runtime-client-gql";
|
|
20
|
+
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
21
|
+
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
22
|
+
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
23
|
+
const runtimeClient = new CopilotRuntimeClient({
|
|
24
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
25
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
26
|
+
headers
|
|
27
|
+
});
|
|
28
|
+
function runtimeClientResponseToStringStream(responsePromise) {
|
|
29
|
+
return __async(this, null, function* () {
|
|
30
|
+
const messagesStream = yield CopilotRuntimeClient.asStream(responsePromise);
|
|
31
|
+
return new ReadableStream({
|
|
32
|
+
start(controller) {
|
|
33
|
+
return __async(this, null, function* () {
|
|
34
|
+
const reader = messagesStream.getReader();
|
|
35
|
+
let sentContent = "";
|
|
36
|
+
while (true) {
|
|
37
|
+
const { done, value } = yield reader.read();
|
|
38
|
+
if (done) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
|
|
42
|
+
let newContent = "";
|
|
43
|
+
for (const message of messages) {
|
|
44
|
+
if (message instanceof TextMessage) {
|
|
45
|
+
newContent += message.content;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (newContent) {
|
|
49
|
+
const contentToSend = newContent.slice(sentContent.length);
|
|
50
|
+
controller.enqueue(contentToSend);
|
|
51
|
+
sentContent += contentToSend;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
controller.close();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const insertionFunction = useCallback(
|
|
61
|
+
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
62
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
63
|
+
const messages = [
|
|
64
|
+
new TextMessage({
|
|
65
|
+
role: Role.System,
|
|
66
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
67
|
+
textareaPurpose,
|
|
68
|
+
getContextString(documents, contextCategories)
|
|
69
|
+
)
|
|
70
|
+
}),
|
|
71
|
+
...insertionApiConfig.fewShotMessages,
|
|
72
|
+
new TextMessage({
|
|
73
|
+
role: Role.User,
|
|
74
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
75
|
+
}),
|
|
76
|
+
new TextMessage({
|
|
77
|
+
role: Role.User,
|
|
78
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
79
|
+
}),
|
|
80
|
+
new TextMessage({
|
|
81
|
+
role: Role.User,
|
|
82
|
+
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
|
|
83
|
+
})
|
|
84
|
+
];
|
|
85
|
+
return runtimeClientResponseToStringStream(
|
|
86
|
+
runtimeClient.generateCopilotResponse(
|
|
87
|
+
{
|
|
88
|
+
frontend: {
|
|
89
|
+
actions: []
|
|
90
|
+
},
|
|
91
|
+
messages: convertMessagesToGqlInput(messages)
|
|
92
|
+
},
|
|
93
|
+
copilotApiConfig.properties,
|
|
94
|
+
abortSignal
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
}));
|
|
98
|
+
return res;
|
|
99
|
+
}),
|
|
100
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
101
|
+
);
|
|
102
|
+
const editingFunction = useCallback(
|
|
103
|
+
(editorState, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
104
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
105
|
+
const messages = [
|
|
106
|
+
new TextMessage({
|
|
107
|
+
role: Role.System,
|
|
108
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
109
|
+
textareaPurpose,
|
|
110
|
+
getContextString(documents, contextCategories)
|
|
111
|
+
)
|
|
112
|
+
}),
|
|
113
|
+
...editingApiConfig.fewShotMessages,
|
|
114
|
+
new TextMessage({
|
|
115
|
+
role: Role.User,
|
|
116
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
117
|
+
}),
|
|
118
|
+
new TextMessage({
|
|
119
|
+
role: Role.User,
|
|
120
|
+
content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`
|
|
121
|
+
}),
|
|
122
|
+
new TextMessage({
|
|
123
|
+
role: Role.User,
|
|
124
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
125
|
+
}),
|
|
126
|
+
new TextMessage({
|
|
127
|
+
role: Role.User,
|
|
128
|
+
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
129
|
+
})
|
|
130
|
+
];
|
|
131
|
+
const runtimeClient2 = new CopilotRuntimeClient({
|
|
132
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
133
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
134
|
+
headers
|
|
135
|
+
});
|
|
136
|
+
return runtimeClientResponseToStringStream(
|
|
137
|
+
runtimeClient2.generateCopilotResponse(
|
|
138
|
+
{
|
|
139
|
+
frontend: {
|
|
140
|
+
actions: []
|
|
141
|
+
},
|
|
142
|
+
messages: convertMessagesToGqlInput(messages)
|
|
143
|
+
},
|
|
144
|
+
copilotApiConfig.properties,
|
|
145
|
+
abortSignal
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}));
|
|
149
|
+
return res;
|
|
150
|
+
}),
|
|
151
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
152
|
+
);
|
|
153
|
+
const insertionOrEditingFunction = useCallback(
|
|
154
|
+
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
155
|
+
if (editorState.selectedText === "") {
|
|
156
|
+
return yield insertionFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
157
|
+
} else {
|
|
158
|
+
return yield editingFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
[insertionFunction, editingFunction]
|
|
162
|
+
);
|
|
163
|
+
return insertionOrEditingFunction;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
useMakeStandardInsertionOrEditingFunction
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=chunk-3SVQJA5A.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../types/base/autosuggestions-bare-function\";\nimport { InsertionsApiConfig } from \"../../types/autosuggestions-config/insertions-api-config\";\nimport { EditingApiConfig } from \"../../types/autosuggestions-config/editing-api-config\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { nanoid } from \"nanoid\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardInsertionOrEditingFunction(\n textareaPurpose: string,\n contextCategories: string[],\n insertionApiConfig: InsertionsApiConfig,\n editingApiConfig: EditingApiConfig,\n): Generator_InsertionOrEditingSuggestion {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n const headers = {\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\n : {}),\n };\n\n const runtimeClient = new CopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers,\n });\n\n async function runtimeClientResponseToStringStream(\n responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,\n ) {\n const messagesStream = await CopilotRuntimeClient.asStream(responsePromise);\n\n return new ReadableStream({\n async start(controller) {\n const reader = messagesStream.getReader();\n let sentContent = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);\n\n let newContent = \"\";\n\n for (const message of messages) {\n if (message instanceof TextMessage) {\n newContent += message.content;\n }\n }\n if (newContent) {\n const contentToSend = newContent.slice(sentContent.length);\n controller.enqueue(contentToSend);\n sentContent += contentToSend;\n }\n }\n controller.close();\n },\n });\n }\n\n const insertionFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...insertionApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,\n }),\n ];\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse(\n {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n abortSignal,\n ),\n );\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...editingApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,\n }),\n ];\n\n const runtimeClient = new CopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers,\n });\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse(\n {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n abortSignal,\n ),\n );\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);\n } else {\n return await editingFunction(editorState, insertionPrompt, documents, abortSignal);\n }\n },\n [insertionFunction, editingFunction],\n );\n\n return insertionOrEditingFunction;\n}\n"],"mappings":"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","names":["runtimeClient"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
retry
|
|
3
|
+
} from "./chunk-KNQIEOFP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__async,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "./chunk-MRXNTQOX.mjs";
|
|
8
|
+
|
|
9
|
+
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
10
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
11
|
+
import { CopilotContext } from "@copilotkit/react-core";
|
|
12
|
+
import { useCallback, useContext } from "react";
|
|
13
|
+
import {
|
|
14
|
+
CopilotRuntimeClient,
|
|
15
|
+
Role,
|
|
16
|
+
TextMessage,
|
|
17
|
+
convertGqlOutputToMessages,
|
|
18
|
+
convertMessagesToGqlInput
|
|
19
|
+
} from "@copilotkit/runtime-client-gql";
|
|
20
|
+
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
21
|
+
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
22
|
+
const publicApiKey = copilotApiConfig.publicApiKey;
|
|
23
|
+
const headers = __spreadValues({}, publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
24
|
+
return useCallback(
|
|
25
|
+
(editorState, abortSignal) => __async(this, null, function* () {
|
|
26
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const messages = [
|
|
29
|
+
new TextMessage({
|
|
30
|
+
role: Role.System,
|
|
31
|
+
content: apiConfig.makeSystemPrompt(
|
|
32
|
+
textareaPurpose,
|
|
33
|
+
getContextString([], contextCategories)
|
|
34
|
+
)
|
|
35
|
+
}),
|
|
36
|
+
...apiConfig.fewShotMessages,
|
|
37
|
+
new TextMessage({
|
|
38
|
+
role: Role.User,
|
|
39
|
+
content: editorState.textAfterCursor
|
|
40
|
+
}),
|
|
41
|
+
new TextMessage({
|
|
42
|
+
role: Role.User,
|
|
43
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
44
|
+
}),
|
|
45
|
+
new TextMessage({
|
|
46
|
+
role: Role.User,
|
|
47
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
48
|
+
})
|
|
49
|
+
];
|
|
50
|
+
const runtimeClient = new CopilotRuntimeClient({
|
|
51
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
52
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
53
|
+
headers: copilotApiConfig.headers
|
|
54
|
+
});
|
|
55
|
+
const response = yield runtimeClient.generateCopilotResponse(
|
|
56
|
+
{
|
|
57
|
+
frontend: {
|
|
58
|
+
actions: []
|
|
59
|
+
},
|
|
60
|
+
messages: convertMessagesToGqlInput(messages)
|
|
61
|
+
},
|
|
62
|
+
copilotApiConfig.properties,
|
|
63
|
+
abortSignal
|
|
64
|
+
).toPromise();
|
|
65
|
+
let result = "";
|
|
66
|
+
for (const message of convertGqlOutputToMessages(
|
|
67
|
+
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
68
|
+
)) {
|
|
69
|
+
if (abortSignal.aborted) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (message instanceof TextMessage) {
|
|
73
|
+
result += message.content;
|
|
74
|
+
console.log(message.content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}));
|
|
79
|
+
return res;
|
|
80
|
+
}),
|
|
81
|
+
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
useMakeStandardAutosuggestionFunction
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=chunk-5KLAWLCD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { nanoid } from \"nanoid\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n const publicApiKey = copilotApiConfig.publicApiKey;\n const headers = {\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n }),\n ...apiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: editorState.textAfterCursor,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n ];\n\n const runtimeClient = new CopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers: copilotApiConfig.headers,\n });\n\n const response = await runtimeClient\n .generateCopilotResponse(\n {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n abortSignal,\n )\n .toPromise();\n\n let result = \"\";\n for (const message of convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages ?? [],\n )) {\n if (abortSignal.aborted) {\n break;\n }\n if (message instanceof TextMessage) {\n result += message.content;\n console.log(message.content);\n }\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,2CAA2C;AACpD,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAKxC;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBA,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AACxE,QAAM,eAAe,iBAAiB;AACtC,QAAM,UAAU,mBACV,eAAe,EAAE,CAAC,mCAAmC,GAAG,aAAa,IAAI,CAAC;AAGhF,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AA3C1C;AA4CQ,cAAM,WAAsB;AAAA,UAC1B,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF,CAAC;AAAA,UACD,GAAG,UAAU;AAAA,UACb,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,YAAY;AAAA,UACvB,CAAC;AAAA,UACD,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,oBAAoB,YAAY;AAAA,UAC3C,CAAC;AAAA,UACD,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,qBAAqB,YAAY;AAAA,UAC5C,CAAC;AAAA,QACH;AAEA,cAAM,gBAAgB,IAAI,qBAAqB;AAAA,UAC7C,KAAK,iBAAiB;AAAA,UACtB,cAAc,iBAAiB;AAAA,UAC/B,SAAS,iBAAiB;AAAA,QAC5B,CAAC;AAED,cAAM,WAAW,MAAM,cACpB;AAAA,UACC;AAAA,YACE,UAAU;AAAA,cACR,SAAS,CAAC;AAAA,YACZ;AAAA,YACA,UAAU,0BAA0B,QAAQ;AAAA,UAC9C;AAAA,UACA,iBAAiB;AAAA,UACjB;AAAA,QACF,EACC,UAAU;AAEb,YAAI,SAAS;AACb,mBAAW,WAAW;AAAA,WACpB,0BAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAxC,YAAoD,CAAC;AAAA,QACvD,GAAG;AACD,cAAI,YAAY,SAAS;AACvB;AAAA,UACF;AACA,cAAI,mBAAmB,aAAa;AAClC,sBAAU,QAAQ;AAClB,oBAAQ,IAAI,QAAQ,OAAO;AAAA,UAC7B;AAAA,QACF;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
// src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
|
|
15
15
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
16
|
-
function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
|
|
16
|
+
function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
|
|
17
17
|
const [previousAutocompleteState, setPreviousAutocompleteState] = useState(null);
|
|
18
18
|
const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = useState(null);
|
|
19
19
|
const awaitForAndAppendSuggestion = useCallback(
|
|
@@ -71,10 +71,11 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
|
|
|
71
71
|
setCurrentAutocompleteSuggestion
|
|
72
72
|
]
|
|
73
73
|
);
|
|
74
|
-
const
|
|
74
|
+
const keyDownOrTouchHandler = useCallback(
|
|
75
75
|
(event) => {
|
|
76
76
|
if (currentAutocompleteSuggestion) {
|
|
77
|
-
|
|
77
|
+
const shouldAcceptSuggestion = event instanceof KeyboardEvent ? shouldAcceptAutosuggestionOnKeyPress(event) : shouldAcceptAutosuggestionOnTouch(event);
|
|
78
|
+
if (shouldAcceptSuggestion) {
|
|
78
79
|
event.preventDefault();
|
|
79
80
|
insertAutocompleteSuggestion(currentAutocompleteSuggestion);
|
|
80
81
|
setCurrentAutocompleteSuggestion(null);
|
|
@@ -91,11 +92,12 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
|
|
|
91
92
|
return {
|
|
92
93
|
currentAutocompleteSuggestion,
|
|
93
94
|
onChangeHandler: onChange,
|
|
94
|
-
onKeyDownHandler:
|
|
95
|
+
onKeyDownHandler: keyDownOrTouchHandler,
|
|
96
|
+
onTouchStartHandler: keyDownOrTouchHandler
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
export {
|
|
99
101
|
useAutosuggestions
|
|
100
102
|
};
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
103
|
+
//# sourceMappingURL=chunk-7QFH4E7C.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Debouncer } from \"../../lib/debouncer\";\nimport { nullableCompatibleEqualityCheck } from \"../../lib/utils\";\nimport { AutosuggestionsBareFunction } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport {\n EditorAutocompleteState,\n areEqual_autocompleteState,\n} from \"../../types/base/editor-autocomplete-state\";\n\nexport interface UseAutosuggestionsResult {\n currentAutocompleteSuggestion: AutosuggestionState | null;\n onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;\n onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;\n onTouchStartHandler: (event: React.TouchEvent<HTMLDivElement>) => void;\n}\n\nexport function useAutosuggestions(\n debounceTime: number,\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean,\n shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean,\n autosuggestionFunction: AutosuggestionsBareFunction,\n insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void,\n disableWhenEmpty: boolean,\n disabled: boolean,\n): UseAutosuggestionsResult {\n const [previousAutocompleteState, setPreviousAutocompleteState] =\n useState<EditorAutocompleteState | null>(null);\n\n const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] =\n useState<AutosuggestionState | null>(null);\n\n const awaitForAndAppendSuggestion: (\n editorAutocompleteState: EditorAutocompleteState,\n abortSignal: AbortSignal,\n ) => Promise<void> = useCallback(\n async (editorAutocompleteState: EditorAutocompleteState, abortSignal: AbortSignal) => {\n // early return if disabled\n if (disabled) {\n return;\n }\n\n if (\n disableWhenEmpty &&\n editorAutocompleteState.textBeforeCursor === \"\" &&\n editorAutocompleteState.textAfterCursor === \"\"\n ) {\n return;\n }\n\n // fetch the suggestion\n const suggestion = await autosuggestionFunction(editorAutocompleteState, abortSignal);\n\n // We'll assume for now that the autocomplete function might or might not respect the abort signal.\n if (!suggestion || abortSignal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n\n setCurrentAutocompleteSuggestion({\n text: suggestion,\n point: editorAutocompleteState.cursorPoint,\n });\n },\n [autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled],\n );\n\n const debouncedFunction = useMemo(\n () => new Debouncer<[editorAutocompleteState: EditorAutocompleteState]>(debounceTime),\n [debounceTime],\n );\n\n // clean current state when unmounting or disabling\n useEffect(() => {\n return () => {\n debouncedFunction.cancel();\n setCurrentAutocompleteSuggestion(null);\n };\n }, [debouncedFunction, disabled]);\n\n const onChange = useCallback(\n (newEditorState: EditorAutocompleteState | null) => {\n const editorStateHasChanged = !nullableCompatibleEqualityCheck(\n areEqual_autocompleteState,\n previousAutocompleteState,\n newEditorState,\n );\n setPreviousAutocompleteState(newEditorState);\n\n // if no change, do nothing\n if (!editorStateHasChanged) {\n return;\n }\n\n // if change, then first null out the current suggestion\n setCurrentAutocompleteSuggestion(null);\n\n // then try to get a new suggestion, debouncing to avoid too many requests while typing\n if (newEditorState) {\n debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);\n } else {\n debouncedFunction.cancel();\n }\n },\n [\n previousAutocompleteState,\n setPreviousAutocompleteState,\n debouncedFunction,\n awaitForAndAppendSuggestion,\n setCurrentAutocompleteSuggestion,\n ],\n );\n\n const keyDownOrTouchHandler = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>) => {\n if (currentAutocompleteSuggestion) {\n const shouldAcceptSuggestion =\n event instanceof KeyboardEvent\n ? shouldAcceptAutosuggestionOnKeyPress(event as React.KeyboardEvent<HTMLDivElement>)\n : shouldAcceptAutosuggestionOnTouch(event as React.TouchEvent<HTMLDivElement>);\n if (shouldAcceptSuggestion) {\n event.preventDefault();\n insertAutocompleteSuggestion(currentAutocompleteSuggestion);\n setCurrentAutocompleteSuggestion(null);\n }\n }\n },\n [\n currentAutocompleteSuggestion,\n setCurrentAutocompleteSuggestion,\n insertAutocompleteSuggestion,\n shouldAcceptAutosuggestionOnKeyPress,\n ],\n );\n\n return {\n currentAutocompleteSuggestion,\n onChangeHandler: onChange,\n onKeyDownHandler: keyDownOrTouchHandler,\n onTouchStartHandler: keyDownOrTouchHandler,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,WAAW,SAAS,gBAAgB;AAiBnD,SAAS,mBACd,cACA,sCACA,mCACA,wBACA,8BACA,kBACA,UAC0B;AAC1B,QAAM,CAAC,2BAA2B,4BAA4B,IAC5D,SAAyC,IAAI;AAE/C,QAAM,CAAC,+BAA+B,gCAAgC,IACpE,SAAqC,IAAI;AAE3C,QAAM,8BAGe;AAAA,IACnB,CAAO,yBAAkD,gBAA6B;AAEpF,UAAI,UAAU;AACZ;AAAA,MACF;AAEA,UACE,oBACA,wBAAwB,qBAAqB,MAC7C,wBAAwB,oBAAoB,IAC5C;AACA;AAAA,MACF;AAGA,YAAM,aAAa,MAAM,uBAAuB,yBAAyB,WAAW;AAGpF,UAAI,CAAC,cAAc,YAAY,SAAS;AACtC,cAAM,IAAI,aAAa,WAAW,YAAY;AAAA,MAChD;AAEA,uCAAiC;AAAA,QAC/B,MAAM;AAAA,QACN,OAAO,wBAAwB;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,IACA,CAAC,wBAAwB,kCAAkC,kBAAkB,QAAQ;AAAA,EACvF;AAEA,QAAM,oBAAoB;AAAA,IACxB,MAAM,IAAI,UAA8D,YAAY;AAAA,IACpF,CAAC,YAAY;AAAA,EACf;AAGA,YAAU,MAAM;AACd,WAAO,MAAM;AACX,wBAAkB,OAAO;AACzB,uCAAiC,IAAI;AAAA,IACvC;AAAA,EACF,GAAG,CAAC,mBAAmB,QAAQ,CAAC;AAEhC,QAAM,WAAW;AAAA,IACf,CAAC,mBAAmD;AAClD,YAAM,wBAAwB,CAAC;AAAA,QAC7B;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,mCAA6B,cAAc;AAG3C,UAAI,CAAC,uBAAuB;AAC1B;AAAA,MACF;AAGA,uCAAiC,IAAI;AAGrC,UAAI,gBAAgB;AAClB,0BAAkB,SAAS,6BAA6B,cAAc;AAAA,MACxE,OAAO;AACL,0BAAkB,OAAO;AAAA,MAC3B;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,wBAAwB;AAAA,IAC5B,CAAC,UAAkF;AACjF,UAAI,+BAA+B;AACjC,cAAM,yBACJ,iBAAiB,gBACb,qCAAqC,KAA4C,IACjF,kCAAkC,KAAyC;AACjF,YAAI,wBAAwB;AAC1B,gBAAM,eAAe;AACrB,uCAA6B,6BAA6B;AAC1D,2CAAiC,IAAI;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,IAClB,qBAAqB;AAAA,EACvB;AACF;","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/types/autosuggestions-config/editing-api-config.tsx
|
|
2
|
+
import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
3
|
+
var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
4
|
+
return `You are a versatile writing assistant helping the user edit a portion of their text.
|
|
5
|
+
|
|
6
|
+
The user is writing some text.
|
|
7
|
+
The purpose is: "${textareaPurpose}"
|
|
8
|
+
|
|
9
|
+
The following external context is also provided. Use it when relevant.
|
|
10
|
+
\`\`\`
|
|
11
|
+
${contextString}
|
|
12
|
+
\`\`\`
|
|
13
|
+
|
|
14
|
+
The user has provided you with a PROMPT for EDITING a PORTION of the text.
|
|
15
|
+
Your job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.
|
|
16
|
+
Only rewrite the portion of the text that the user has marked as "TextToEdit"!!!
|
|
17
|
+
|
|
18
|
+
Adjust yourself to the user's style and implied intent.
|
|
19
|
+
|
|
20
|
+
The conversation will be structured as follows:
|
|
21
|
+
<TextBeforeCursor>
|
|
22
|
+
<TextToEdit>
|
|
23
|
+
<TextAfterCursor>
|
|
24
|
+
<EditingPrompt>
|
|
25
|
+
|
|
26
|
+
<YourEditSuggestion>
|
|
27
|
+
`;
|
|
28
|
+
};
|
|
29
|
+
var defaultEditingFewShotMessages = [
|
|
30
|
+
new TextMessage({
|
|
31
|
+
role: Role.User,
|
|
32
|
+
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
|
|
33
|
+
}),
|
|
34
|
+
new TextMessage({
|
|
35
|
+
role: Role.User,
|
|
36
|
+
content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
|
|
37
|
+
}),
|
|
38
|
+
new TextMessage({
|
|
39
|
+
role: Role.User,
|
|
40
|
+
content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
|
|
41
|
+
}),
|
|
42
|
+
new TextMessage({
|
|
43
|
+
role: Role.User,
|
|
44
|
+
content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
|
|
45
|
+
}),
|
|
46
|
+
new TextMessage({
|
|
47
|
+
role: Role.Assistant,
|
|
48
|
+
content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
|
|
49
|
+
}),
|
|
50
|
+
new TextMessage({
|
|
51
|
+
role: Role.User,
|
|
52
|
+
content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
|
|
53
|
+
}),
|
|
54
|
+
new TextMessage({
|
|
55
|
+
role: Role.User,
|
|
56
|
+
content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
|
|
57
|
+
}),
|
|
58
|
+
new TextMessage({
|
|
59
|
+
role: Role.User,
|
|
60
|
+
content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
|
|
61
|
+
}),
|
|
62
|
+
new TextMessage({
|
|
63
|
+
role: Role.User,
|
|
64
|
+
content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
|
|
65
|
+
}),
|
|
66
|
+
new TextMessage({
|
|
67
|
+
role: Role.Assistant,
|
|
68
|
+
content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
|
|
69
|
+
})
|
|
70
|
+
];
|
|
71
|
+
var defaultEditingApiConfig = {
|
|
72
|
+
makeSystemPrompt: defaultEditingMakeSystemPrompt,
|
|
73
|
+
fewShotMessages: defaultEditingFewShotMessages,
|
|
74
|
+
forwardedParams: void 0
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
defaultEditingMakeSystemPrompt,
|
|
79
|
+
defaultEditingFewShotMessages,
|
|
80
|
+
defaultEditingApiConfig
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=chunk-CVO5T3PA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/autosuggestions-config/editing-api-config.tsx"],"sourcesContent":["import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { nanoid } from \"nanoid\";\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"],"mappings":";AAAA,SAAkB,MAAM,mBAAmB;AAUpC,IAAM,iCAAmD,CAC9D,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA,EAIlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBF;AAEO,IAAM,gCAA2C;AAAA,EACtD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EAED,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AACH;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultEditingApiConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CVO5T3PA.mjs";
|
|
4
4
|
import {
|
|
5
5
|
defaultInsertionsApiConfig
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-I6DJQ7D7.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defaultSuggestionsApiConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WMHVBGPR.mjs";
|
|
10
10
|
import {
|
|
11
11
|
defaultBaseAutosuggestionsConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-OJXLHIYQ.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__spreadProps,
|
|
15
15
|
__spreadValues
|
|
@@ -29,4 +29,4 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
|
|
|
29
29
|
export {
|
|
30
30
|
defaultAutosuggestionsConfig
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-H3PGQHLG.mjs.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/types/autosuggestions-config/insertions-api-config.tsx
|
|
2
|
+
import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
2
3
|
var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
3
4
|
return `You are a versatile writing assistant helping the user insert new text into their existing work.
|
|
4
5
|
|
|
@@ -27,44 +28,38 @@ The conversation will be structured as follows:
|
|
|
27
28
|
`;
|
|
28
29
|
};
|
|
29
30
|
var defaultInsertionsFewShotMessages = [
|
|
30
|
-
{
|
|
31
|
-
role:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
content:
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
role:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
role: "user",
|
|
61
|
-
name: "InsertionPrompt",
|
|
62
|
-
content: "add section about the optionholder's pro rata share"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
role: "assistant",
|
|
31
|
+
new TextMessage({
|
|
32
|
+
role: Role.User,
|
|
33
|
+
content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
|
|
34
|
+
}),
|
|
35
|
+
new TextMessage({
|
|
36
|
+
role: Role.User,
|
|
37
|
+
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
|
|
38
|
+
}),
|
|
39
|
+
new TextMessage({
|
|
40
|
+
role: Role.User,
|
|
41
|
+
content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
|
|
42
|
+
}),
|
|
43
|
+
new TextMessage({
|
|
44
|
+
role: Role.Assistant,
|
|
45
|
+
content: "When I arrived I went straight to the produce section and picked out a big watermelon."
|
|
46
|
+
}),
|
|
47
|
+
new TextMessage({
|
|
48
|
+
role: Role.User,
|
|
49
|
+
content: "<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>"
|
|
50
|
+
}),
|
|
51
|
+
new TextMessage({
|
|
52
|
+
role: Role.User,
|
|
53
|
+
content: `<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>`
|
|
54
|
+
}),
|
|
55
|
+
new TextMessage({
|
|
56
|
+
role: Role.User,
|
|
57
|
+
content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
|
|
58
|
+
}),
|
|
59
|
+
new TextMessage({
|
|
60
|
+
role: Role.Assistant,
|
|
66
61
|
content: ` (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"; `
|
|
67
|
-
}
|
|
62
|
+
})
|
|
68
63
|
];
|
|
69
64
|
var defaultInsertionsApiConfig = {
|
|
70
65
|
makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
|
|
@@ -77,4 +72,4 @@ export {
|
|
|
77
72
|
defaultInsertionsFewShotMessages,
|
|
78
73
|
defaultInsertionsApiConfig
|
|
79
74
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
75
|
+
//# sourceMappingURL=chunk-I6DJQ7D7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/autosuggestions-config/insertions-api-config.tsx"],"sourcesContent":["import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { nanoid } from \"nanoid\";\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"],"mappings":";AAAA,SAAkB,MAAM,mBAAmB;AAUpC,IAAM,oCAAsD,CACjE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA,EAIlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBF;AAEO,IAAM,mCAA8C;AAAA,EACzD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AAAA,EACD,IAAI,YAAY;AAAA,IACd,MAAM,KAAK;AAAA,IACX,SACE;AAAA,EACJ,CAAC;AACH;AAEO,IAAM,6BAAkD;AAAA,EAC7D,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useMakeStandardInsertionOrEditingFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3SVQJA5A.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useMakeStandardAutosuggestionFunction
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5KLAWLCD.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defaultAutosuggestionsConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-H3PGQHLG.mjs";
|
|
10
10
|
import {
|
|
11
11
|
BaseCopilotTextarea
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-R77MK6QS.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__objRest,
|
|
15
15
|
__spreadProps,
|
|
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
|
|
|
57
57
|
export {
|
|
58
58
|
CopilotTextarea
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-IF7CDWEH.mjs.map
|