@copilotkit/react-textarea 1.3.7-fix-chat-interactions-rerenders.0 → 1.3.7

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/{chunk-PKEWYNJ2.mjs → chunk-2WEVAO3P.mjs} +3 -3
  3. package/dist/{chunk-2XDYLKPH.mjs → chunk-VPGMB7K3.mjs} +2 -2
  4. package/dist/chunk-VPGMB7K3.mjs.map +1 -0
  5. package/dist/{chunk-D2SUDM2O.mjs → chunk-XBU5TSXH.mjs} +2 -2
  6. package/dist/{chunk-D2SUDM2O.mjs.map → chunk-XBU5TSXH.mjs.map} +1 -1
  7. package/dist/components/copilot-textarea/copilot-textarea.js +2 -2
  8. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  9. package/dist/components/copilot-textarea/copilot-textarea.mjs +3 -3
  10. package/dist/components/index.js +2 -2
  11. package/dist/components/index.js.map +1 -1
  12. package/dist/components/index.mjs +3 -3
  13. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +1 -1
  14. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  15. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  16. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +1 -1
  17. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  18. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +3 -3
  22. package/package.json +8 -8
  23. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +1 -1
  24. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +1 -1
  25. package/dist/chunk-2XDYLKPH.mjs.map +0 -1
  26. /package/dist/{chunk-PKEWYNJ2.mjs.map → chunk-2WEVAO3P.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -4,9 +4,9 @@ import "./chunk-WADHCMPK.mjs";
4
4
  import "./chunk-MMVDU6DF.mjs";
5
5
  import {
6
6
  CopilotTextarea
7
- } from "./chunk-PKEWYNJ2.mjs";
8
- import "./chunk-2XDYLKPH.mjs";
9
- import "./chunk-D2SUDM2O.mjs";
7
+ } from "./chunk-2WEVAO3P.mjs";
8
+ import "./chunk-VPGMB7K3.mjs";
9
+ import "./chunk-XBU5TSXH.mjs";
10
10
  import "./chunk-RUV6NBIF.mjs";
11
11
  import {
12
12
  defaultAutosuggestionsConfig
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.3.7-fix-chat-interactions-rerenders.0",
12
+ "version": "1.3.7",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -26,7 +26,7 @@
26
26
  "types": "./dist/index.d.ts",
27
27
  "license": "MIT",
28
28
  "peerDependencies": {
29
- "react": "^18.2.0"
29
+ "react": "^18 || ^19 || ^19.0.0-rc"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/jest": "^29.5.4",
@@ -43,9 +43,9 @@
43
43
  "ts-jest": "^29.1.1",
44
44
  "tsup": "^6.7.0",
45
45
  "typescript": "^5.2.3",
46
- "eslint-config-custom": "1.3.7-fix-chat-interactions-rerenders.0",
47
- "tailwind-config": "1.3.7-fix-chat-interactions-rerenders.0",
48
- "tsconfig": "1.3.7-fix-chat-interactions-rerenders.0"
46
+ "eslint-config-custom": "1.3.7",
47
+ "tailwind-config": "1.3.7",
48
+ "tsconfig": "1.3.7"
49
49
  },
50
50
  "dependencies": {
51
51
  "@emotion/css": "^11.11.2",
@@ -67,9 +67,9 @@
67
67
  "slate-history": "^0.93.0",
68
68
  "slate-react": "^0.98.1",
69
69
  "tailwind-merge": "^1.13.2",
70
- "@copilotkit/react-core": "1.3.7-fix-chat-interactions-rerenders.0",
71
- "@copilotkit/runtime-client-gql": "1.3.7-fix-chat-interactions-rerenders.0",
72
- "@copilotkit/shared": "1.3.7-fix-chat-interactions-rerenders.0"
70
+ "@copilotkit/react-core": "1.3.7",
71
+ "@copilotkit/runtime-client-gql": "1.3.7",
72
+ "@copilotkit/shared": "1.3.7"
73
73
  },
74
74
  "keywords": [
75
75
  "copilotkit",
@@ -103,7 +103,7 @@ export function useMakeStandardAutosuggestionFunction(
103
103
  if (abortSignal.aborted) {
104
104
  break;
105
105
  }
106
- if (message instanceof TextMessage) {
106
+ if (message.isTextMessage()) {
107
107
  result += message.content;
108
108
  }
109
109
  }
@@ -74,7 +74,7 @@ export function useMakeStandardInsertionOrEditingFunction(
74
74
  let newContent = "";
75
75
 
76
76
  for (const message of messages) {
77
- if (message instanceof TextMessage) {
77
+ if (message.isTextMessage()) {
78
78
  newContent += message.content;
79
79
  }
80
80
  }
@@ -1 +0,0 @@
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 } = useCopilotContext();\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 credentials: copilotApiConfig.credentials,\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 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 const runtimeClient = new CopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers,\n credentials: copilotApiConfig.credentials,\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,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAuBA,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,kBAAkB;AACjE,QAAM,UAAU,mBACV,iBAAiB,eACjB,EAAE,CAAC,mCAAmC,GAAG,iBAAiB,aAAa,IACvE,CAAC;AAGP,QAAM,gBAAgB,IAAI,qBAAqB;AAAA,IAC7C,KAAK,iBAAiB;AAAA,IACtB,cAAc,iBAAiB;AAAA,IAC/B;AAAA,IACA,aAAa,iBAAiB;AAAA,EAChC,CAAC;AAED,WAAe,oCACb,iBACA;AAAA;AACA,YAAM,iBAAiB,MAAM,qBAAqB,SAAS,eAAe;AAE1E,aAAO,IAAI,eAAe;AAAA,QAClB,MAAM,Y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