@copilotkit/react-textarea 1.0.0-beta.0 → 1.0.0-beta.2
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 +240 -240
- package/CHANGELOG.md +20 -0
- package/dist/{chunk-3SVQJA5A.mjs → chunk-PAP4ZNRG.mjs} +21 -14
- package/dist/chunk-PAP4ZNRG.mjs.map +1 -0
- package/dist/{chunk-5KLAWLCD.mjs → chunk-TTOZXUEA.mjs} +12 -8
- package/dist/chunk-TTOZXUEA.mjs.map +1 -0
- package/dist/{chunk-IF7CDWEH.mjs → chunk-WPV52EMI.mjs} +3 -3
- package/dist/components/copilot-textarea/copilot-textarea.js +27 -18
- 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 +27 -18
- 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 +9 -6
- 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 +18 -12
- 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 +27 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +4 -4
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +9 -6
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +17 -10
- package/dist/chunk-3SVQJA5A.mjs.map +0 -1
- package/dist/chunk-5KLAWLCD.mjs.map +0 -1
- /package/dist/{chunk-IF7CDWEH.mjs.map → chunk-WPV52EMI.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Set default Copilot Cloud runtime URL to versioned URL (v1)
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @copilotkit/runtime-client-gql@1.0.0-beta.2
|
|
10
|
+
- @copilotkit/react-core@1.0.0-beta.2
|
|
11
|
+
- @copilotkit/shared@1.0.0-beta.2
|
|
12
|
+
|
|
13
|
+
## 1.0.0-beta.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Introduce anonymous telemetry
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @copilotkit/runtime-client-gql@1.0.0-beta.1
|
|
20
|
+
- @copilotkit/react-core@1.0.0-beta.1
|
|
21
|
+
- @copilotkit/shared@1.0.0-beta.1
|
|
22
|
+
|
|
3
23
|
## 1.0.0-beta.0
|
|
4
24
|
|
|
5
25
|
### Major Changes
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
Role,
|
|
16
16
|
TextMessage,
|
|
17
17
|
convertGqlOutputToMessages,
|
|
18
|
-
convertMessagesToGqlInput
|
|
18
|
+
convertMessagesToGqlInput,
|
|
19
|
+
CopilotRequestType
|
|
19
20
|
} from "@copilotkit/runtime-client-gql";
|
|
20
21
|
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
21
22
|
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
@@ -83,16 +84,19 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
83
84
|
})
|
|
84
85
|
];
|
|
85
86
|
return runtimeClientResponseToStringStream(
|
|
86
|
-
runtimeClient.generateCopilotResponse(
|
|
87
|
-
{
|
|
87
|
+
runtimeClient.generateCopilotResponse({
|
|
88
|
+
data: {
|
|
88
89
|
frontend: {
|
|
89
90
|
actions: []
|
|
90
91
|
},
|
|
91
|
-
messages: convertMessagesToGqlInput(messages)
|
|
92
|
+
messages: convertMessagesToGqlInput(messages),
|
|
93
|
+
metadata: {
|
|
94
|
+
requestType: CopilotRequestType.TextareaCompletion
|
|
95
|
+
}
|
|
92
96
|
},
|
|
93
|
-
copilotApiConfig.properties,
|
|
94
|
-
abortSignal
|
|
95
|
-
)
|
|
97
|
+
properties: copilotApiConfig.properties,
|
|
98
|
+
signal: abortSignal
|
|
99
|
+
})
|
|
96
100
|
);
|
|
97
101
|
}));
|
|
98
102
|
return res;
|
|
@@ -134,16 +138,19 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
134
138
|
headers
|
|
135
139
|
});
|
|
136
140
|
return runtimeClientResponseToStringStream(
|
|
137
|
-
runtimeClient2.generateCopilotResponse(
|
|
138
|
-
{
|
|
141
|
+
runtimeClient2.generateCopilotResponse({
|
|
142
|
+
data: {
|
|
139
143
|
frontend: {
|
|
140
144
|
actions: []
|
|
141
145
|
},
|
|
142
|
-
messages: convertMessagesToGqlInput(messages)
|
|
146
|
+
messages: convertMessagesToGqlInput(messages),
|
|
147
|
+
metadata: {
|
|
148
|
+
requestType: CopilotRequestType.TextareaCompletion
|
|
149
|
+
}
|
|
143
150
|
},
|
|
144
|
-
copilotApiConfig.properties,
|
|
145
|
-
abortSignal
|
|
146
|
-
)
|
|
151
|
+
properties: copilotApiConfig.properties,
|
|
152
|
+
signal: abortSignal
|
|
153
|
+
})
|
|
147
154
|
);
|
|
148
155
|
}));
|
|
149
156
|
return res;
|
|
@@ -166,4 +173,4 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
166
173
|
export {
|
|
167
174
|
useMakeStandardInsertionOrEditingFunction
|
|
168
175
|
};
|
|
169
|
-
//# sourceMappingURL=chunk-
|
|
176
|
+
//# sourceMappingURL=chunk-PAP4ZNRG.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 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\";\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 data: {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(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 const runtimeClient = new CopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers,\n });\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(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,S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,YACd,MAAM,KAAK;AAAA,YACX,SAAS,eAAe,YAAY;AAAA,UACtC,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,kBAAkB;AAAA,UAC7B,CAAC;AAAA,QACH;AAEA,cAAMA,iBAAgB,IAAI,qBAAqB;AAAA,UAC7C,KAAK,iBAAiB;AAAA,UACtB,cAAc,iBAAiB;AAAA,UAC/B;AAAA,QACF,CAAC;AAED,eAAO;AAAA,UACLA,eAAc,wBAAwB;AAAA,YACpC,MAAM;AAAA,cACJ,UAAU;AAAA,gBACR,SAAS,CAAC;AAAA,cACZ;AAAA,cACA,UAAU,0BAA0B,QAAQ;AAAA,cAC5C,UAAU;AAAA,gBACR,aAAa,mBAAmB;AAAA,cAClC;AAAA,YACF;AAAA,YACA,YAAY,iBAAiB;AAAA,YAC7B,QAAQ;AAAA,UACV,CAAC;AAAA,QACH;AAAA,MACF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,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":["runtimeClient"]}
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
Role,
|
|
16
16
|
TextMessage,
|
|
17
17
|
convertGqlOutputToMessages,
|
|
18
|
-
convertMessagesToGqlInput
|
|
18
|
+
convertMessagesToGqlInput,
|
|
19
|
+
CopilotRequestType
|
|
19
20
|
} from "@copilotkit/runtime-client-gql";
|
|
20
21
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
21
22
|
const { getContextString, copilotApiConfig } = useContext(CopilotContext);
|
|
@@ -52,16 +53,19 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
52
53
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
53
54
|
headers: copilotApiConfig.headers
|
|
54
55
|
});
|
|
55
|
-
const response = yield runtimeClient.generateCopilotResponse(
|
|
56
|
-
{
|
|
56
|
+
const response = yield runtimeClient.generateCopilotResponse({
|
|
57
|
+
data: {
|
|
57
58
|
frontend: {
|
|
58
59
|
actions: []
|
|
59
60
|
},
|
|
60
|
-
messages: convertMessagesToGqlInput(messages)
|
|
61
|
+
messages: convertMessagesToGqlInput(messages),
|
|
62
|
+
metadata: {
|
|
63
|
+
requestType: CopilotRequestType.TextareaCompletion
|
|
64
|
+
}
|
|
61
65
|
},
|
|
62
|
-
copilotApiConfig.properties,
|
|
63
|
-
abortSignal
|
|
64
|
-
).toPromise();
|
|
66
|
+
properties: copilotApiConfig.properties,
|
|
67
|
+
signal: abortSignal
|
|
68
|
+
}).toPromise();
|
|
65
69
|
let result = "";
|
|
66
70
|
for (const message of convertGqlOutputToMessages(
|
|
67
71
|
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
@@ -85,4 +89,4 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
85
89
|
export {
|
|
86
90
|
useMakeStandardAutosuggestionFunction
|
|
87
91
|
};
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-TTOZXUEA.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 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 } = 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 data: {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.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 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,EACA;AAAA,OACK;AAeA,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,Y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[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useMakeStandardInsertionOrEditingFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PAP4ZNRG.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useMakeStandardAutosuggestionFunction
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TTOZXUEA.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defaultAutosuggestionsConfig
|
|
9
9
|
} from "./chunk-H3PGQHLG.mjs";
|
|
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
|
|
|
57
57
|
export {
|
|
58
58
|
CopilotTextarea
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-WPV52EMI.mjs.map
|
|
@@ -141,16 +141,19 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
141
141
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
142
142
|
headers: copilotApiConfig.headers
|
|
143
143
|
});
|
|
144
|
-
const response = yield runtimeClient.generateCopilotResponse(
|
|
145
|
-
{
|
|
144
|
+
const response = yield runtimeClient.generateCopilotResponse({
|
|
145
|
+
data: {
|
|
146
146
|
frontend: {
|
|
147
147
|
actions: []
|
|
148
148
|
},
|
|
149
|
-
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
|
|
149
|
+
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages),
|
|
150
|
+
metadata: {
|
|
151
|
+
requestType: import_runtime_client_gql.CopilotRequestType.TextareaCompletion
|
|
152
|
+
}
|
|
150
153
|
},
|
|
151
|
-
copilotApiConfig.properties,
|
|
152
|
-
abortSignal
|
|
153
|
-
).toPromise();
|
|
154
|
+
properties: copilotApiConfig.properties,
|
|
155
|
+
signal: abortSignal
|
|
156
|
+
}).toPromise();
|
|
154
157
|
let result = "";
|
|
155
158
|
for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
|
|
156
159
|
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
@@ -2165,16 +2168,19 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
2165
2168
|
})
|
|
2166
2169
|
];
|
|
2167
2170
|
return runtimeClientResponseToStringStream(
|
|
2168
|
-
runtimeClient.generateCopilotResponse(
|
|
2169
|
-
{
|
|
2171
|
+
runtimeClient.generateCopilotResponse({
|
|
2172
|
+
data: {
|
|
2170
2173
|
frontend: {
|
|
2171
2174
|
actions: []
|
|
2172
2175
|
},
|
|
2173
|
-
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
|
|
2176
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages),
|
|
2177
|
+
metadata: {
|
|
2178
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
|
|
2179
|
+
}
|
|
2174
2180
|
},
|
|
2175
|
-
copilotApiConfig.properties,
|
|
2176
|
-
abortSignal
|
|
2177
|
-
)
|
|
2181
|
+
properties: copilotApiConfig.properties,
|
|
2182
|
+
signal: abortSignal
|
|
2183
|
+
})
|
|
2178
2184
|
);
|
|
2179
2185
|
}));
|
|
2180
2186
|
return res;
|
|
@@ -2216,16 +2222,19 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
2216
2222
|
headers
|
|
2217
2223
|
});
|
|
2218
2224
|
return runtimeClientResponseToStringStream(
|
|
2219
|
-
runtimeClient2.generateCopilotResponse(
|
|
2220
|
-
{
|
|
2225
|
+
runtimeClient2.generateCopilotResponse({
|
|
2226
|
+
data: {
|
|
2221
2227
|
frontend: {
|
|
2222
2228
|
actions: []
|
|
2223
2229
|
},
|
|
2224
|
-
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
|
|
2230
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages),
|
|
2231
|
+
metadata: {
|
|
2232
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
|
|
2233
|
+
}
|
|
2225
2234
|
},
|
|
2226
|
-
copilotApiConfig.properties,
|
|
2227
|
-
abortSignal
|
|
2228
|
-
)
|
|
2235
|
+
properties: copilotApiConfig.properties,
|
|
2236
|
+
signal: abortSignal
|
|
2237
|
+
})
|
|
2229
2238
|
);
|
|
2230
2239
|
}));
|
|
2231
2240
|
return res;
|