@copilotkit/react-textarea 1.3.7-fix-chat-interactions-rerenders.0 → 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.
Files changed (45) hide show
  1. package/CHANGELOG.md +15 -5
  2. package/dist/{chunk-PKEWYNJ2.mjs → chunk-2FAXLWPD.mjs} +4 -4
  3. package/dist/{chunk-D2SUDM2O.mjs → chunk-BG4GF6PP.mjs} +5 -5
  4. package/dist/chunk-BG4GF6PP.mjs.map +1 -0
  5. package/dist/{chunk-SDHH6DI6.mjs → chunk-GUZIMGGZ.mjs} +2 -1
  6. package/dist/chunk-GUZIMGGZ.mjs.map +1 -0
  7. package/dist/{chunk-2XDYLKPH.mjs → chunk-VPGMB7K3.mjs} +2 -2
  8. package/dist/chunk-VPGMB7K3.mjs.map +1 -0
  9. package/dist/{chunk-HL7EF7KA.mjs → chunk-ZTYA6QOT.mjs} +2 -2
  10. package/dist/components/copilot-textarea/copilot-textarea.js +6 -5
  11. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  12. package/dist/components/copilot-textarea/copilot-textarea.mjs +5 -5
  13. package/dist/components/index.js +6 -5
  14. package/dist/components/index.js.map +1 -1
  15. package/dist/components/index.mjs +5 -5
  16. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +4 -4
  17. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  18. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  19. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +1 -1
  20. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  21. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  22. package/dist/index.js +6 -5
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +6 -6
  25. package/dist/types/autosuggestions-config/autosuggestions-config.js +1 -0
  26. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
  27. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
  28. package/dist/types/autosuggestions-config/index.js +1 -0
  29. package/dist/types/autosuggestions-config/index.js.map +1 -1
  30. package/dist/types/autosuggestions-config/index.mjs +2 -2
  31. package/dist/types/autosuggestions-config/suggestions-api-config.js +1 -0
  32. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
  33. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +1 -1
  34. package/dist/types/index.js +1 -0
  35. package/dist/types/index.js.map +1 -1
  36. package/dist/types/index.mjs +2 -2
  37. package/package.json +8 -8
  38. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +9 -6
  39. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +1 -1
  40. package/src/types/autosuggestions-config/suggestions-api-config.tsx +1 -0
  41. package/dist/chunk-2XDYLKPH.mjs.map +0 -1
  42. package/dist/chunk-D2SUDM2O.mjs.map +0 -1
  43. package/dist/chunk-SDHH6DI6.mjs.map +0 -1
  44. /package/dist/{chunk-PKEWYNJ2.mjs.map → chunk-2FAXLWPD.mjs.map} +0 -0
  45. /package/dist/{chunk-HL7EF7KA.mjs.map → chunk-ZTYA6QOT.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,14 +1,24 @@
1
1
  # ui
2
2
 
3
- ## 1.3.7-fix-chat-interactions-rerenders.0
3
+ ## 1.3.8-fix-memoize-chat-ui-context.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Split messages into their own context
7
+ - fix memoization and multiple provider usages
8
8
  - Updated dependencies
9
- - @copilotkit/react-core@1.3.7-fix-chat-interactions-rerenders.0
10
- - @copilotkit/runtime-client-gql@1.3.7-fix-chat-interactions-rerenders.0
11
- - @copilotkit/shared@1.3.7-fix-chat-interactions-rerenders.0
9
+ - @copilotkit/react-core@1.3.8-fix-memoize-chat-ui-context.0
10
+ - @copilotkit/runtime-client-gql@1.3.8-fix-memoize-chat-ui-context.0
11
+ - @copilotkit/shared@1.3.8-fix-memoize-chat-ui-context.0
12
+
13
+ ## 1.3.7
14
+
15
+ ### Patch Changes
16
+
17
+ - Fix libraries for React 19 and Next.js 15 support
18
+ - Updated dependencies
19
+ - @copilotkit/react-core@1.3.7
20
+ - @copilotkit/runtime-client-gql@1.3.7
21
+ - @copilotkit/shared@1.3.7
12
22
 
13
23
  ## 1.3.6
14
24
 
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  useMakeStandardInsertionOrEditingFunction
3
- } from "./chunk-2XDYLKPH.mjs";
3
+ } from "./chunk-VPGMB7K3.mjs";
4
4
  import {
5
5
  useMakeStandardAutosuggestionFunction
6
- } from "./chunk-D2SUDM2O.mjs";
6
+ } from "./chunk-BG4GF6PP.mjs";
7
7
  import {
8
8
  defaultAutosuggestionsConfig
9
- } from "./chunk-HL7EF7KA.mjs";
9
+ } from "./chunk-ZTYA6QOT.mjs";
10
10
  import {
11
11
  BaseCopilotTextarea
12
12
  } from "./chunk-J62KUPFZ.mjs";
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
57
57
  export {
58
58
  CopilotTextarea
59
59
  };
60
- //# sourceMappingURL=chunk-PKEWYNJ2.mjs.map
60
+ //# sourceMappingURL=chunk-2FAXLWPD.mjs.map
@@ -37,10 +37,10 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
37
37
  )
38
38
  }),
39
39
  ...apiConfig.fewShotMessages,
40
- new TextMessage({
40
+ editorState.textAfterCursor != "" ? new TextMessage({
41
41
  role: Role.User,
42
42
  content: editorState.textAfterCursor
43
- }),
43
+ }) : null,
44
44
  new TextMessage({
45
45
  role: Role.User,
46
46
  content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
@@ -49,7 +49,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
49
49
  role: Role.User,
50
50
  content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
51
51
  })
52
- ];
52
+ ].filter(Boolean);
53
53
  const runtimeClient = new CopilotRuntimeClient({
54
54
  url,
55
55
  publicApiKey,
@@ -81,7 +81,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
81
81
  if (abortSignal.aborted) {
82
82
  break;
83
83
  }
84
- if (message instanceof TextMessage) {
84
+ if (message.isTextMessage()) {
85
85
  result += message.content;
86
86
  }
87
87
  }
@@ -96,4 +96,4 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
96
96
  export {
97
97
  useMakeStandardAutosuggestionFunction
98
98
  };
99
- //# sourceMappingURL=chunk-D2SUDM2O.mjs.map
99
+ //# sourceMappingURL=chunk-BG4GF6PP.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 } = 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"],"mappings":";;;;;;;;;AAAA,SAAS,2CAA2C;AACpD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAK5B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeA,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,kBAAkB;AACjE,QAAM,EAAE,iBAAiB,KAAK,cAAc,aAAa,WAAW,IAAI;AACxE,QAAM,UAAU,kCACX,iBAAiB,UAChB,eAAe,EAAE,CAAC,mCAAmC,GAAG,aAAa,IAAI,CAAC;AAEhF,QAAM,EAAE,WAAW,KAAK,IAAI;AAE5B,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AA9C1C;AAgDQ,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,YAAY,mBAAmB,KAC3B,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,YAAY;AAAA,UACvB,CAAC,IACD;AAAA,UACJ,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,EAAE,OAAO,OAAO;AAEhB,cAAM,gBAAgB,IAAI,qBAAqB;AAAA,UAC7C;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AAED,cAAM,WAAW,MAAM,cACpB,wBAAwB;AAAA,UACvB,MAAM;AAAA,YACJ,UAAU;AAAA,cACR,SAAS,CAAC;AAAA,cACV,KAAK,OAAO,SAAS;AAAA,YACvB;AAAA,YACA,UAAU,0BAA0B,yBAAyB,QAAQ,CAAC;AAAA,YACtE,UAAU;AAAA,cACR,aAAa,mBAAmB;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,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":[]}
@@ -17,6 +17,7 @@ The user will provide both the text before and after the cursor. You should use
17
17
  <YourSuggestion>
18
18
 
19
19
  If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
20
+ Refrain from adding <YourSuggestion> tags when responding
20
21
 
21
22
  The following external context is also provided. Use it to help you make better suggestions!!!
22
23
  \`\`\`
@@ -60,4 +61,4 @@ export {
60
61
  defaultSuggestionsFewShotMessages,
61
62
  defaultSuggestionsApiConfig
62
63
  };
63
- //# sourceMappingURL=chunk-SDHH6DI6.mjs.map
64
+ //# sourceMappingURL=chunk-GUZIMGGZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/suggestions-api-config.tsx"],"sourcesContent":["import { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: Message[];\n maxTokens?: number;\n stop?: string[];\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\nRefrain from adding <YourSuggestion> tags when responding\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: 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: \"This morning I woke up and went straight to the grocery store.\",\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.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 defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n};\n"],"mappings":";AAAA,SAAkB,MAAM,mBAAmB;AAUpC,IAAM,qCAAuD,CAClE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBlB;AAAA;AAAA;AAGF;AAEO,IAAM,oCAA+C;AAAA,EAC1D,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;AACH;AAEO,IAAM,8BAAoD;AAAA,EAC/D,kBAAkB;AAAA,EAClB,iBAAiB;AACnB;","names":[]}
@@ -44,7 +44,7 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
44
44
  const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
45
45
  let newContent = "";
46
46
  for (const message of messages) {
47
- if (message instanceof TextMessage) {
47
+ if (message.isTextMessage()) {
48
48
  newContent += message.content;
49
49
  }
50
50
  }
@@ -178,4 +178,4 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
178
178
  export {
179
179
  useMakeStandardInsertionOrEditingFunction
180
180
  };
181
- //# sourceMappingURL=chunk-2XDYLKPH.mjs.map
181
+ //# sourceMappingURL=chunk-VPGMB7K3.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 } = 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.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 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,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;AAAA,cACF;AAEA,oBAAM,WAAW,2BAA2B,MAAM,wBAAwB,QAAQ;AAElF,kBA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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"]}
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-MCNXIA4Q.mjs";
7
7
  import {
8
8
  defaultSuggestionsApiConfig
9
- } from "./chunk-SDHH6DI6.mjs";
9
+ } from "./chunk-GUZIMGGZ.mjs";
10
10
  import {
11
11
  defaultBaseAutosuggestionsConfig
12
12
  } from "./chunk-4CVSOOJY.mjs";
@@ -29,4 +29,4 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
29
29
  export {
30
30
  defaultAutosuggestionsConfig
31
31
  };
32
- //# sourceMappingURL=chunk-HL7EF7KA.mjs.map
32
+ //# sourceMappingURL=chunk-ZTYA6QOT.mjs.map
@@ -124,10 +124,10 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
124
124
  )
125
125
  }),
126
126
  ...apiConfig.fewShotMessages,
127
- new import_runtime_client_gql.TextMessage({
127
+ editorState2.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
128
128
  role: import_runtime_client_gql.Role.User,
129
129
  content: editorState2.textAfterCursor
130
- }),
130
+ }) : null,
131
131
  new import_runtime_client_gql.TextMessage({
132
132
  role: import_runtime_client_gql.Role.User,
133
133
  content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
@@ -136,7 +136,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
136
136
  role: import_runtime_client_gql.Role.User,
137
137
  content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
138
138
  })
139
- ];
139
+ ].filter(Boolean);
140
140
  const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
141
141
  url,
142
142
  publicApiKey,
@@ -168,7 +168,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
168
168
  if (abortSignal.aborted) {
169
169
  break;
170
170
  }
171
- if (message instanceof import_runtime_client_gql.TextMessage) {
171
+ if (message.isTextMessage()) {
172
172
  result += message.content;
173
173
  }
174
174
  }
@@ -225,6 +225,7 @@ The user will provide both the text before and after the cursor. You should use
225
225
  <YourSuggestion>
226
226
 
227
227
  If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
228
+ Refrain from adding <YourSuggestion> tags when responding
228
229
 
229
230
  The following external context is also provided. Use it to help you make better suggestions!!!
230
231
  \`\`\`
@@ -2124,7 +2125,7 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
2124
2125
  const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
2125
2126
  let newContent = "";
2126
2127
  for (const message of messages) {
2127
- if (message instanceof import_runtime_client_gql5.TextMessage) {
2128
+ if (message.isTextMessage()) {
2128
2129
  newContent += message.content;
2129
2130
  }
2130
2131
  }