@copilotkit/react-textarea 1.4.1-pre.2 → 1.4.1-pre.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -4
- package/dist/{chunk-DS52LMD2.mjs → chunk-53RID4IZ.mjs} +3 -3
- package/dist/{chunk-BG4GF6PP.mjs → chunk-PTPNOBEI.mjs} +2 -9
- package/dist/chunk-PTPNOBEI.mjs.map +1 -0
- package/dist/{chunk-VPGMB7K3.mjs → chunk-RXV67GJN.mjs} +4 -17
- package/dist/chunk-RXV67GJN.mjs.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +4 -22
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +3 -3
- package/dist/components/index.js +4 -22
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +3 -3
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +1 -7
- 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.js +3 -15
- 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.js +4 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/package.json +7 -7
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +1 -8
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +2 -16
- package/dist/chunk-BG4GF6PP.mjs.map +0 -1
- package/dist/chunk-VPGMB7K3.mjs.map +0 -1
- /package/dist/{chunk-DS52LMD2.mjs.map → chunk-53RID4IZ.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,56 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.4.1-pre.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1721cbd: lower case copilotkit property
|
|
8
|
+
- 1721cbd: add zod conversion
|
|
9
|
+
- 1721cbd: Add convertActionsToDynamicStructuredTools to sdk-js
|
|
10
|
+
- fix assistant message CSS and propagate actions to LG JS
|
|
11
|
+
- Updated dependencies [1721cbd]
|
|
12
|
+
- Updated dependencies [1721cbd]
|
|
13
|
+
- Updated dependencies [1721cbd]
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @copilotkit/react-core@1.4.1-pre.6
|
|
16
|
+
- @copilotkit/runtime-client-gql@1.4.1-pre.6
|
|
17
|
+
- @copilotkit/shared@1.4.1-pre.6
|
|
18
|
+
|
|
19
|
+
## 1.4.1-pre.5
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- bump
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
- @copilotkit/runtime-client-gql@1.4.1-pre.5
|
|
26
|
+
- @copilotkit/react-core@1.4.1-pre.5
|
|
27
|
+
- @copilotkit/shared@1.4.1-pre.5
|
|
28
|
+
|
|
29
|
+
## 1.4.1-pre.4
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- bump
|
|
34
|
+
- Updated dependencies
|
|
35
|
+
- @copilotkit/runtime-client-gql@1.4.1-pre.4
|
|
36
|
+
- @copilotkit/react-core@1.4.1-pre.4
|
|
37
|
+
- @copilotkit/shared@1.4.1-pre.4
|
|
38
|
+
|
|
39
|
+
## 1.4.1-pre.3
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- bump
|
|
44
|
+
- Updated dependencies
|
|
45
|
+
- @copilotkit/runtime-client-gql@1.4.1-pre.3
|
|
46
|
+
- @copilotkit/react-core@1.4.1-pre.3
|
|
47
|
+
- @copilotkit/shared@1.4.1-pre.3
|
|
48
|
+
|
|
3
49
|
## 1.4.1-pre.2
|
|
4
50
|
|
|
5
51
|
### Patch Changes
|
|
6
52
|
|
|
7
|
-
-
|
|
53
|
+
- bump
|
|
8
54
|
- Updated dependencies
|
|
9
55
|
- @copilotkit/runtime-client-gql@1.4.1-pre.2
|
|
10
56
|
- @copilotkit/react-core@1.4.1-pre.2
|
|
@@ -14,7 +60,7 @@
|
|
|
14
60
|
|
|
15
61
|
### Patch Changes
|
|
16
62
|
|
|
17
|
-
-
|
|
63
|
+
- bump
|
|
18
64
|
- Updated dependencies
|
|
19
65
|
- @copilotkit/runtime-client-gql@1.4.1-pre.1
|
|
20
66
|
- @copilotkit/react-core@1.4.1-pre.1
|
|
@@ -24,10 +70,10 @@
|
|
|
24
70
|
|
|
25
71
|
### Patch Changes
|
|
26
72
|
|
|
27
|
-
-
|
|
73
|
+
- New prerelease
|
|
28
74
|
- Updated dependencies
|
|
29
|
-
- @copilotkit/react-core@1.4.1-pre.0
|
|
30
75
|
- @copilotkit/runtime-client-gql@1.4.1-pre.0
|
|
76
|
+
- @copilotkit/react-core@1.4.1-pre.0
|
|
31
77
|
- @copilotkit/shared@1.4.1-pre.0
|
|
32
78
|
|
|
33
79
|
## 1.4.0
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useMakeStandardInsertionOrEditingFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RXV67GJN.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useMakeStandardAutosuggestionFunction
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PTPNOBEI.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defaultAutosuggestionsConfig
|
|
9
9
|
} from "./chunk-ZTYA6QOT.mjs";
|
|
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
|
|
|
57
57
|
export {
|
|
58
58
|
CopilotTextarea
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-53RID4IZ.mjs.map
|
|
@@ -11,7 +11,6 @@ import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
|
11
11
|
import { useCopilotContext } from "@copilotkit/react-core";
|
|
12
12
|
import { useCallback } from "react";
|
|
13
13
|
import {
|
|
14
|
-
CopilotRuntimeClient,
|
|
15
14
|
Role,
|
|
16
15
|
TextMessage,
|
|
17
16
|
convertGqlOutputToMessages,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
CopilotRequestType
|
|
21
20
|
} from "@copilotkit/runtime-client-gql";
|
|
22
21
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
23
|
-
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
22
|
+
const { getContextString, copilotApiConfig, runtimeClient } = useCopilotContext();
|
|
24
23
|
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
25
24
|
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
26
25
|
const { maxTokens, stop } = apiConfig;
|
|
@@ -50,12 +49,6 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
50
49
|
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
51
50
|
})
|
|
52
51
|
].filter(Boolean);
|
|
53
|
-
const runtimeClient = new CopilotRuntimeClient({
|
|
54
|
-
url,
|
|
55
|
-
publicApiKey,
|
|
56
|
-
headers,
|
|
57
|
-
credentials
|
|
58
|
-
});
|
|
59
52
|
const response = yield runtimeClient.generateCopilotResponse({
|
|
60
53
|
data: {
|
|
61
54
|
frontend: {
|
|
@@ -96,4 +89,4 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
96
89
|
export {
|
|
97
90
|
useMakeStandardAutosuggestionFunction
|
|
98
91
|
};
|
|
99
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-PTPNOBEI.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 { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } 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 filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\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, runtimeClient } = useCopilotContext();\n const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;\n const headers = {\n ...copilotApiConfig.headers,\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n const { maxTokens, stop } = apiConfig;\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n // @ts-expect-error -- Passing null is forbidden, but we're filtering it later\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 editorState.textAfterCursor != \"\"\n ? new TextMessage({\n role: Role.User,\n content: editorState.textAfterCursor,\n })\n : null,\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 ].filter(Boolean);\n\n const response = await runtimeClient\n .generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n forwardedParameters: {\n maxTokens,\n stop,\n },\n },\n properties,\n signal: 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.isTextMessage()) {\n result += 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,yBAAyB;AAClC,SAAS,mBAAmB;AAK5B;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeA,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,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,mBAAW,WAAW;AAAA,WACpB,0BAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAxC,YAAoD,CAAC;AAAA,QACvD,GAAG;AACD,cAAI,YAAY,SAAS;AACvB;AAAA,UACF;AACA,cAAI,QAAQ,cAAc,GAAG;AAC3B,sBAAU,QAAQ;AAAA,UACpB;AAAA,QACF;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -11,7 +11,6 @@ import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
|
11
11
|
import { useCopilotContext } from "@copilotkit/react-core";
|
|
12
12
|
import { useCallback } from "react";
|
|
13
13
|
import {
|
|
14
|
-
CopilotRuntimeClient,
|
|
15
14
|
Role,
|
|
16
15
|
TextMessage,
|
|
17
16
|
convertGqlOutputToMessages,
|
|
@@ -20,17 +19,11 @@ import {
|
|
|
20
19
|
CopilotRequestType
|
|
21
20
|
} from "@copilotkit/runtime-client-gql";
|
|
22
21
|
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
23
|
-
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
22
|
+
const { getContextString, copilotApiConfig, runtimeClient } = useCopilotContext();
|
|
24
23
|
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
25
|
-
const runtimeClient = new CopilotRuntimeClient({
|
|
26
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
27
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
28
|
-
headers,
|
|
29
|
-
credentials: copilotApiConfig.credentials
|
|
30
|
-
});
|
|
31
24
|
function runtimeClientResponseToStringStream(responsePromise) {
|
|
32
25
|
return __async(this, null, function* () {
|
|
33
|
-
const messagesStream =
|
|
26
|
+
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
34
27
|
return new ReadableStream({
|
|
35
28
|
start(controller) {
|
|
36
29
|
return __async(this, null, function* () {
|
|
@@ -135,14 +128,8 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
135
128
|
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
136
129
|
})
|
|
137
130
|
];
|
|
138
|
-
const runtimeClient2 = new CopilotRuntimeClient({
|
|
139
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
140
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
141
|
-
headers,
|
|
142
|
-
credentials: copilotApiConfig.credentials
|
|
143
|
-
});
|
|
144
131
|
return runtimeClientResponseToStringStream(
|
|
145
|
-
|
|
132
|
+
runtimeClient.generateCopilotResponse({
|
|
146
133
|
data: {
|
|
147
134
|
frontend: {
|
|
148
135
|
actions: [],
|
|
@@ -178,4 +165,4 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
178
165
|
export {
|
|
179
166
|
useMakeStandardInsertionOrEditingFunction
|
|
180
167
|
};
|
|
181
|
-
//# sourceMappingURL=chunk-
|
|
168
|
+
//# sourceMappingURL=chunk-RXV67GJN.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 { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\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\";\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, runtimeClient } = useCopilotContext();\n const headers = {\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\n : {}),\n };\n\n async function runtimeClientResponseToStringStream(\n responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,\n ) {\n const messagesStream = runtimeClient.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.isTextMessage()) {\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 data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: 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 return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: 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":";;;;;;;;;AAAA,SAAS,2CAA2C;AACpD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAuBA,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,kBAAkB,cAAc,IAAI,kBAAkB;AAChF,QAAM,UAAU,mBACV,iBAAiB,eACjB,EAAE,CAAC,mCAAmC,GAAG,iBAAiB,aAAa,IACvE,CAAC;AAGP,WAAe,oCACb,iBACA;AAAA;AACA,YAAM,iBAAiB,cAAc,SAAS,eAAe;AAE7D,aAAO,IAAI,eAAe;AAAA,QAClB,MAAM,YAAY;AAAA;AACtB,kBAAM,SAAS,eAAe,UAAU;AACxC,gBAAI,cAAc;AAElB,mBAAO,MAAM;AACX,oBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,kBAAI,MAAM;AACR;A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BAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,6BAA6B;AAAA,IACjC,CACE,aACA,iBACA,WACA,gBACG;AACH,UAAI,YAAY,iBAAiB,IAAI;AACnC,eAAO,MAAM,kBAAkB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACrF,OAAO;AACL,eAAO,MAAM,gBAAgB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACnF;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,eAAe;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -107,7 +107,7 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
|
107
107
|
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
108
108
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
109
109
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
110
|
-
const { getContextString, copilotApiConfig } = (0, import_react_core.useCopilotContext)();
|
|
110
|
+
const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core.useCopilotContext)();
|
|
111
111
|
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
112
112
|
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
113
113
|
const { maxTokens, stop } = apiConfig;
|
|
@@ -137,12 +137,6 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
137
137
|
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
138
138
|
})
|
|
139
139
|
].filter(Boolean);
|
|
140
|
-
const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
|
|
141
|
-
url,
|
|
142
|
-
publicApiKey,
|
|
143
|
-
headers,
|
|
144
|
-
credentials
|
|
145
|
-
});
|
|
146
140
|
const response = yield runtimeClient.generateCopilotResponse({
|
|
147
141
|
data: {
|
|
148
142
|
frontend: {
|
|
@@ -2108,17 +2102,11 @@ var import_react_core5 = require("@copilotkit/react-core");
|
|
|
2108
2102
|
var import_react14 = require("react");
|
|
2109
2103
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
2110
2104
|
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
2111
|
-
const { getContextString, copilotApiConfig } = (0, import_react_core5.useCopilotContext)();
|
|
2105
|
+
const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core5.useCopilotContext)();
|
|
2112
2106
|
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
2113
|
-
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
2114
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
2115
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2116
|
-
headers,
|
|
2117
|
-
credentials: copilotApiConfig.credentials
|
|
2118
|
-
});
|
|
2119
2107
|
function runtimeClientResponseToStringStream(responsePromise) {
|
|
2120
2108
|
return __async(this, null, function* () {
|
|
2121
|
-
const messagesStream =
|
|
2109
|
+
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
2122
2110
|
return new ReadableStream({
|
|
2123
2111
|
start(controller) {
|
|
2124
2112
|
return __async(this, null, function* () {
|
|
@@ -2223,14 +2211,8 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
2223
2211
|
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
2224
2212
|
})
|
|
2225
2213
|
];
|
|
2226
|
-
const runtimeClient2 = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
2227
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
2228
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2229
|
-
headers,
|
|
2230
|
-
credentials: copilotApiConfig.credentials
|
|
2231
|
-
});
|
|
2232
2214
|
return runtimeClientResponseToStringStream(
|
|
2233
|
-
|
|
2215
|
+
runtimeClient.generateCopilotResponse({
|
|
2234
2216
|
data: {
|
|
2235
2217
|
frontend: {
|
|
2236
2218
|
actions: [],
|