@copilotkit/react-textarea 1.3.7 → 1.3.8-fix-memoize-chat-ui-context.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/CHANGELOG.md +10 -0
- package/dist/{chunk-2WEVAO3P.mjs → chunk-2FAXLWPD.mjs} +3 -3
- package/dist/{chunk-XBU5TSXH.mjs → chunk-BG4GF6PP.mjs} +4 -4
- package/dist/chunk-BG4GF6PP.mjs.map +1 -0
- package/dist/{chunk-SDHH6DI6.mjs → chunk-GUZIMGGZ.mjs} +2 -1
- package/dist/chunk-GUZIMGGZ.mjs.map +1 -0
- package/dist/{chunk-HL7EF7KA.mjs → chunk-ZTYA6QOT.mjs} +2 -2
- package/dist/components/copilot-textarea/copilot-textarea.js +4 -3
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +4 -4
- package/dist/components/index.js +4 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +3 -3
- 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/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/types/autosuggestions-config/autosuggestions-config.js +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
- package/dist/types/autosuggestions-config/index.js +1 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +2 -2
- package/dist/types/autosuggestions-config/suggestions-api-config.js +1 -0
- 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/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -2
- package/package.json +7 -7
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +8 -5
- package/src/types/autosuggestions-config/suggestions-api-config.tsx +1 -0
- package/dist/chunk-SDHH6DI6.mjs.map +0 -1
- package/dist/chunk-XBU5TSXH.mjs.map +0 -1
- /package/dist/{chunk-2WEVAO3P.mjs.map → chunk-2FAXLWPD.mjs.map} +0 -0
- /package/dist/{chunk-HL7EF7KA.mjs.map → chunk-ZTYA6QOT.mjs.map} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import "../chunk-MMVDU6DF.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotTextarea
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-2FAXLWPD.mjs";
|
|
5
5
|
import "../chunk-VPGMB7K3.mjs";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-BG4GF6PP.mjs";
|
|
7
7
|
import "../chunk-RUV6NBIF.mjs";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-ZTYA6QOT.mjs";
|
|
9
9
|
import "../chunk-EJGGLWWR.mjs";
|
|
10
10
|
import "../chunk-MCNXIA4Q.mjs";
|
|
11
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-GUZIMGGZ.mjs";
|
|
12
12
|
import {
|
|
13
13
|
BaseCopilotTextarea
|
|
14
14
|
} from "../chunk-J62KUPFZ.mjs";
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js
CHANGED
|
@@ -96,10 +96,10 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
96
96
|
)
|
|
97
97
|
}),
|
|
98
98
|
...apiConfig.fewShotMessages,
|
|
99
|
-
new import_runtime_client_gql.TextMessage({
|
|
99
|
+
editorState.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
|
|
100
100
|
role: import_runtime_client_gql.Role.User,
|
|
101
101
|
content: editorState.textAfterCursor
|
|
102
|
-
}),
|
|
102
|
+
}) : null,
|
|
103
103
|
new import_runtime_client_gql.TextMessage({
|
|
104
104
|
role: import_runtime_client_gql.Role.User,
|
|
105
105
|
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
@@ -108,7 +108,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
108
108
|
role: import_runtime_client_gql.Role.User,
|
|
109
109
|
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
110
110
|
})
|
|
111
|
-
];
|
|
111
|
+
].filter(Boolean);
|
|
112
112
|
const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
|
|
113
113
|
url,
|
|
114
114
|
publicApiKey,
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.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 } = 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 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
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.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 } = 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 runtimeClient = new CopilotRuntimeClient({\n url,\n publicApiKey,\n headers,\n credentials,\n });\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","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoD;AACpD,wBAAkC;AAClC,mBAA4B;;;ACFrB,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAA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Q,CAAC;AAAA,YACtE,UAAU;AAAA,cACR,aAAa,6CAAmB;AAAA,YAClC;AAAA,YACA,qBAAqB;AAAA,cACnB;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,QACV,CAAC,EACA,UAAU;AAEb,YAAI,SAAS;AACb,mBAAW,eAAW;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":[]}
|
package/dist/index.js
CHANGED
|
@@ -1831,10 +1831,10 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
1831
1831
|
)
|
|
1832
1832
|
}),
|
|
1833
1833
|
...apiConfig.fewShotMessages,
|
|
1834
|
-
new import_runtime_client_gql.TextMessage({
|
|
1834
|
+
editorState2.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
|
|
1835
1835
|
role: import_runtime_client_gql.Role.User,
|
|
1836
1836
|
content: editorState2.textAfterCursor
|
|
1837
|
-
}),
|
|
1837
|
+
}) : null,
|
|
1838
1838
|
new import_runtime_client_gql.TextMessage({
|
|
1839
1839
|
role: import_runtime_client_gql.Role.User,
|
|
1840
1840
|
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
@@ -1843,7 +1843,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
1843
1843
|
role: import_runtime_client_gql.Role.User,
|
|
1844
1844
|
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
1845
1845
|
})
|
|
1846
|
-
];
|
|
1846
|
+
].filter(Boolean);
|
|
1847
1847
|
const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
|
|
1848
1848
|
url,
|
|
1849
1849
|
publicApiKey,
|
|
@@ -1906,6 +1906,7 @@ The user will provide both the text before and after the cursor. You should use
|
|
|
1906
1906
|
<YourSuggestion>
|
|
1907
1907
|
|
|
1908
1908
|
If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
|
|
1909
|
+
Refrain from adding <YourSuggestion> tags when responding
|
|
1909
1910
|
|
|
1910
1911
|
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
1911
1912
|
\`\`\`
|