@copilotkit/react-textarea 0.37.0 → 0.38.0-beta.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 (114) hide show
  1. package/.turbo/turbo-build.log +216 -224
  2. package/CHANGELOG.md +13 -0
  3. package/dist/chunk-3SVQJA5A.mjs +169 -0
  4. package/dist/chunk-3SVQJA5A.mjs.map +1 -0
  5. package/dist/chunk-5KLAWLCD.mjs +88 -0
  6. package/dist/chunk-5KLAWLCD.mjs.map +1 -0
  7. package/dist/{chunk-QKS2IOUH.mjs → chunk-7QFH4E7C.mjs} +7 -5
  8. package/dist/chunk-7QFH4E7C.mjs.map +1 -0
  9. package/dist/chunk-CVO5T3PA.mjs +82 -0
  10. package/dist/chunk-CVO5T3PA.mjs.map +1 -0
  11. package/dist/{chunk-DKE57EAC.mjs → chunk-H3PGQHLG.mjs} +5 -5
  12. package/dist/{chunk-RKQ6RTZM.mjs → chunk-I6DJQ7D7.mjs} +33 -38
  13. package/dist/chunk-I6DJQ7D7.mjs.map +1 -0
  14. package/dist/{chunk-VAJHETSN.mjs → chunk-IF7CDWEH.mjs} +5 -5
  15. package/dist/{chunk-VAJHETSN.mjs.map → chunk-IF7CDWEH.mjs.map} +1 -1
  16. package/dist/{chunk-LCDTIJSD.mjs → chunk-OJXLHIYQ.mjs} +4 -2
  17. package/dist/chunk-OJXLHIYQ.mjs.map +1 -0
  18. package/dist/{chunk-ZRKQLLC7.mjs → chunk-R77MK6QS.mjs} +10 -5
  19. package/dist/{chunk-ZRKQLLC7.mjs.map → chunk-R77MK6QS.mjs.map} +1 -1
  20. package/dist/{chunk-O4LDWYJB.mjs → chunk-TNGDQV3I.mjs} +1 -2
  21. package/dist/{chunk-O4LDWYJB.mjs.map → chunk-TNGDQV3I.mjs.map} +1 -1
  22. package/dist/{chunk-KDVMG3XF.mjs → chunk-WMHVBGPR.mjs} +23 -25
  23. package/dist/chunk-WMHVBGPR.mjs.map +1 -0
  24. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +15 -7
  25. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  26. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +4 -4
  27. package/dist/components/copilot-textarea/copilot-textarea.d.ts +2 -2
  28. package/dist/components/copilot-textarea/copilot-textarea.js +255 -207
  29. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  30. package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
  31. package/dist/components/hovering-toolbar/hovering-toolbar.js +0 -1
  32. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  33. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1 -1
  34. package/dist/components/index.d.ts +1 -1
  35. package/dist/components/index.js +251 -203
  36. package/dist/components/index.js.map +1 -1
  37. package/dist/components/index.mjs +11 -11
  38. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +2 -1
  39. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +6 -4
  40. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
  41. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +1 -1
  42. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +1 -1
  43. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +39 -31
  44. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  45. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  46. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +1 -1
  47. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +100 -60
  48. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  49. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  50. package/dist/index.d.ts +1 -1
  51. package/dist/index.js +251 -203
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.mjs +11 -11
  54. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -1
  55. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -1
  56. package/dist/types/autosuggestions-config/autosuggestions-config.js +96 -108
  57. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
  58. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +5 -5
  59. package/dist/types/autosuggestions-config/editing-api-config.d.ts +3 -3
  60. package/dist/types/autosuggestions-config/editing-api-config.js +39 -46
  61. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
  62. package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
  63. package/dist/types/autosuggestions-config/index.d.ts +1 -1
  64. package/dist/types/autosuggestions-config/index.js +96 -108
  65. package/dist/types/autosuggestions-config/index.js.map +1 -1
  66. package/dist/types/autosuggestions-config/index.mjs +5 -5
  67. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +3 -3
  68. package/dist/types/autosuggestions-config/insertions-api-config.js +32 -37
  69. package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -1
  70. package/dist/types/autosuggestions-config/insertions-api-config.mjs +1 -1
  71. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +3 -3
  72. package/dist/types/autosuggestions-config/suggestions-api-config.js +22 -24
  73. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
  74. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +1 -1
  75. package/dist/types/base/base-autosuggestions-config.d.ts +14 -0
  76. package/dist/types/base/base-autosuggestions-config.js +3 -1
  77. package/dist/types/base/base-autosuggestions-config.js.map +1 -1
  78. package/dist/types/base/base-autosuggestions-config.mjs +1 -1
  79. package/dist/types/base/index.js +3 -1
  80. package/dist/types/base/index.js.map +1 -1
  81. package/dist/types/base/index.mjs +1 -1
  82. package/dist/types/index.d.ts +1 -1
  83. package/dist/types/index.js +96 -108
  84. package/dist/types/index.js.map +1 -1
  85. package/dist/types/index.mjs +5 -5
  86. package/package.json +7 -6
  87. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +5 -0
  88. package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
  89. package/src/components/hovering-toolbar/hovering-toolbar.tsx +0 -1
  90. package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +11 -4
  91. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +51 -31
  92. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +116 -62
  93. package/src/types/autosuggestions-config/editing-api-config.tsx +48 -49
  94. package/src/types/autosuggestions-config/index.ts +0 -1
  95. package/src/types/autosuggestions-config/insertions-api-config.tsx +38 -40
  96. package/src/types/autosuggestions-config/suggestions-api-config.tsx +26 -27
  97. package/src/types/base/base-autosuggestions-config.tsx +17 -0
  98. package/dist/chunk-4OJ3H65F.mjs +0 -89
  99. package/dist/chunk-4OJ3H65F.mjs.map +0 -1
  100. package/dist/chunk-HE4GMS2P.mjs +0 -121
  101. package/dist/chunk-HE4GMS2P.mjs.map +0 -1
  102. package/dist/chunk-KDVMG3XF.mjs.map +0 -1
  103. package/dist/chunk-LCDTIJSD.mjs.map +0 -1
  104. package/dist/chunk-QKS2IOUH.mjs.map +0 -1
  105. package/dist/chunk-RKQ6RTZM.mjs.map +0 -1
  106. package/dist/chunk-SJ2TM5GA.mjs +0 -72
  107. package/dist/chunk-SJ2TM5GA.mjs.map +0 -1
  108. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +0 -7
  109. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +0 -19
  110. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +0 -1
  111. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -1
  112. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +0 -1
  113. package/src/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.tsx +0 -5
  114. /package/dist/{chunk-DKE57EAC.mjs.map → chunk-H3PGQHLG.mjs.map} +0 -0
@@ -1,20 +1,20 @@
1
1
  import "../chunk-MMVDU6DF.mjs";
2
2
  import {
3
3
  CopilotTextarea
4
- } from "../chunk-VAJHETSN.mjs";
5
- import "../chunk-HE4GMS2P.mjs";
6
- import "../chunk-SJ2TM5GA.mjs";
4
+ } from "../chunk-IF7CDWEH.mjs";
5
+ import "../chunk-3SVQJA5A.mjs";
6
+ import "../chunk-5KLAWLCD.mjs";
7
7
  import "../chunk-RUV6NBIF.mjs";
8
- import "../chunk-DKE57EAC.mjs";
9
- import "../chunk-4OJ3H65F.mjs";
10
- import "../chunk-RKQ6RTZM.mjs";
11
- import "../chunk-KDVMG3XF.mjs";
8
+ import "../chunk-H3PGQHLG.mjs";
9
+ import "../chunk-CVO5T3PA.mjs";
10
+ import "../chunk-I6DJQ7D7.mjs";
11
+ import "../chunk-WMHVBGPR.mjs";
12
12
  import {
13
13
  BaseCopilotTextarea
14
- } from "../chunk-ZRKQLLC7.mjs";
14
+ } from "../chunk-R77MK6QS.mjs";
15
15
  import "../chunk-2C7O2EVM.mjs";
16
16
  import "../chunk-GQN2HYFJ.mjs";
17
- import "../chunk-QKS2IOUH.mjs";
17
+ import "../chunk-7QFH4E7C.mjs";
18
18
  import "../chunk-JJLQVT7S.mjs";
19
19
  import "../chunk-DRV2FOHZ.mjs";
20
20
  import "../chunk-4NHVQZ67.mjs";
@@ -22,7 +22,7 @@ import "../chunk-FMQG2ZM3.mjs";
22
22
  import "../chunk-5UNJXFUO.mjs";
23
23
  import "../chunk-LQ2OWQU7.mjs";
24
24
  import "../chunk-7LSRNPNI.mjs";
25
- import "../chunk-O4LDWYJB.mjs";
25
+ import "../chunk-TNGDQV3I.mjs";
26
26
  import "../chunk-L7VVZH4Q.mjs";
27
27
  import "../chunk-COQISBP2.mjs";
28
28
  import "../chunk-OGLVRSCO.mjs";
@@ -38,7 +38,7 @@ import "../chunk-4HBKWUCT.mjs";
38
38
  import "../chunk-2QDCE7PD.mjs";
39
39
  import "../chunk-7SUZ6CXM.mjs";
40
40
  import "../chunk-WJHSY5T6.mjs";
41
- import "../chunk-LCDTIJSD.mjs";
41
+ import "../chunk-OJXLHIYQ.mjs";
42
42
  import "../chunk-224UKA7C.mjs";
43
43
  import "../chunk-XW3ICO4S.mjs";
44
44
  import "../chunk-DFTV4TST.mjs";
@@ -8,7 +8,8 @@ interface UseAutosuggestionsResult {
8
8
  currentAutocompleteSuggestion: AutosuggestionState | null;
9
9
  onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;
10
10
  onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;
11
+ onTouchStartHandler: (event: React.TouchEvent<HTMLDivElement>) => void;
11
12
  }
12
- declare function useAutosuggestions(debounceTime: number, shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean, autosuggestionFunction: AutosuggestionsBareFunction, insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void, disableWhenEmpty: boolean, disabled: boolean): UseAutosuggestionsResult;
13
+ declare function useAutosuggestions(debounceTime: number, shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean, shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean, autosuggestionFunction: AutosuggestionsBareFunction, insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void, disableWhenEmpty: boolean, disabled: boolean): UseAutosuggestionsResult;
13
14
 
14
15
  export { UseAutosuggestionsResult, useAutosuggestions };
@@ -95,7 +95,7 @@ function areEqual_autocompleteState(prev, next) {
95
95
  }
96
96
 
97
97
  // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
98
- function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
98
+ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
99
99
  const [previousAutocompleteState, setPreviousAutocompleteState] = (0, import_react.useState)(null);
100
100
  const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = (0, import_react.useState)(null);
101
101
  const awaitForAndAppendSuggestion = (0, import_react.useCallback)(
@@ -153,10 +153,11 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
153
153
  setCurrentAutocompleteSuggestion
154
154
  ]
155
155
  );
156
- const keyDownHandler = (0, import_react.useCallback)(
156
+ const keyDownOrTouchHandler = (0, import_react.useCallback)(
157
157
  (event) => {
158
158
  if (currentAutocompleteSuggestion) {
159
- if (shouldAcceptAutosuggestionOnKeyPress(event)) {
159
+ const shouldAcceptSuggestion = event instanceof KeyboardEvent ? shouldAcceptAutosuggestionOnKeyPress(event) : shouldAcceptAutosuggestionOnTouch(event);
160
+ if (shouldAcceptSuggestion) {
160
161
  event.preventDefault();
161
162
  insertAutocompleteSuggestion(currentAutocompleteSuggestion);
162
163
  setCurrentAutocompleteSuggestion(null);
@@ -173,7 +174,8 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
173
174
  return {
174
175
  currentAutocompleteSuggestion,
175
176
  onChangeHandler: onChange,
176
- onKeyDownHandler: keyDownHandler
177
+ onKeyDownHandler: keyDownOrTouchHandler,
178
+ onTouchStartHandler: keyDownOrTouchHandler
177
179
  };
178
180
  }
179
181
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts","../../../src/lib/debouncer.ts","../../../src/lib/utils.ts","../../../src/types/base/editor-autocomplete-state.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Debouncer } from \"../../lib/debouncer\";\nimport { nullableCompatibleEqualityCheck } from \"../../lib/utils\";\nimport { AutosuggestionsBareFunction } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport {\n EditorAutocompleteState,\n areEqual_autocompleteState,\n} from \"../../types/base/editor-autocomplete-state\";\n\nexport interface UseAutosuggestionsResult {\n currentAutocompleteSuggestion: AutosuggestionState | null;\n onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;\n onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;\n}\n\nexport function useAutosuggestions(\n debounceTime: number,\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean,\n autosuggestionFunction: AutosuggestionsBareFunction,\n insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void,\n disableWhenEmpty: boolean,\n disabled: boolean,\n): UseAutosuggestionsResult {\n const [previousAutocompleteState, setPreviousAutocompleteState] =\n useState<EditorAutocompleteState | null>(null);\n\n const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] =\n useState<AutosuggestionState | null>(null);\n\n const awaitForAndAppendSuggestion: (\n editorAutocompleteState: EditorAutocompleteState,\n abortSignal: AbortSignal,\n ) => Promise<void> = useCallback(\n async (editorAutocompleteState: EditorAutocompleteState, abortSignal: AbortSignal) => {\n // early return if disabled\n if (disabled) {\n return;\n }\n\n if (\n disableWhenEmpty &&\n editorAutocompleteState.textBeforeCursor === \"\" &&\n editorAutocompleteState.textAfterCursor === \"\"\n ) {\n return;\n }\n\n // fetch the suggestion\n const suggestion = await autosuggestionFunction(editorAutocompleteState, abortSignal);\n\n // We'll assume for now that the autocomplete function might or might not respect the abort signal.\n if (!suggestion || abortSignal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n\n setCurrentAutocompleteSuggestion({\n text: suggestion,\n point: editorAutocompleteState.cursorPoint,\n });\n },\n [autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled],\n );\n\n const debouncedFunction = useMemo(\n () => new Debouncer<[editorAutocompleteState: EditorAutocompleteState]>(debounceTime),\n [debounceTime],\n );\n\n // clean current state when unmounting or disabling\n useEffect(() => {\n return () => {\n debouncedFunction.cancel();\n setCurrentAutocompleteSuggestion(null);\n };\n }, [debouncedFunction, disabled]);\n\n const onChange = useCallback(\n (newEditorState: EditorAutocompleteState | null) => {\n const editorStateHasChanged = !nullableCompatibleEqualityCheck(\n areEqual_autocompleteState,\n previousAutocompleteState,\n newEditorState,\n );\n setPreviousAutocompleteState(newEditorState);\n\n // if no change, do nothing\n if (!editorStateHasChanged) {\n return;\n }\n\n // if change, then first null out the current suggestion\n setCurrentAutocompleteSuggestion(null);\n\n // then try to get a new suggestion, debouncing to avoid too many requests while typing\n if (newEditorState) {\n debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);\n } else {\n debouncedFunction.cancel();\n }\n },\n [\n previousAutocompleteState,\n setPreviousAutocompleteState,\n debouncedFunction,\n awaitForAndAppendSuggestion,\n setCurrentAutocompleteSuggestion,\n ],\n );\n\n const keyDownHandler = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (currentAutocompleteSuggestion) {\n if (shouldAcceptAutosuggestionOnKeyPress(event)) {\n event.preventDefault();\n insertAutocompleteSuggestion(currentAutocompleteSuggestion);\n setCurrentAutocompleteSuggestion(null);\n }\n }\n },\n [\n currentAutocompleteSuggestion,\n setCurrentAutocompleteSuggestion,\n insertAutocompleteSuggestion,\n shouldAcceptAutosuggestionOnKeyPress,\n ],\n );\n\n return {\n currentAutocompleteSuggestion,\n onChangeHandler: onChange,\n onKeyDownHandler: keyDownHandler,\n };\n}\n","export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;\n\nexport class Debouncer<T extends any[]> {\n private timeoutId?: ReturnType<typeof setTimeout>;\n private activeAbortController?: AbortController;\n\n constructor(private wait: number) {}\n\n debounce = async (func: AsyncFunction<T>, ...args: T) => {\n // Abort the previous promise immediately\n this.cancel();\n\n this.timeoutId = setTimeout(async () => {\n try {\n this.activeAbortController = new AbortController();\n\n // Pass the signal to the async function, assuming it supports it\n await func(...args, this.activeAbortController.signal);\n\n this.activeAbortController = undefined;\n } catch (error) {}\n }, this.wait);\n };\n\n cancel = () => {\n if (this.activeAbortController) {\n this.activeAbortController.abort();\n this.activeAbortController = undefined;\n }\n\n if (this.timeoutId !== undefined) {\n clearTimeout(this.timeoutId);\n this.timeoutId = undefined;\n }\n };\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined,\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n","import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState,\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) &&\n prev.textBeforeCursor === next.textBeforeCursor &&\n prev.textAfterCursor === next.textAfterCursor\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0D;;;ACEnD,IAAM,YAAN,MAAiC;AAAA,EAItC,YAAoB,MAAc;AAAd;AAEpB,oBAAW,CAAO,SAA2B,SAAY;AAEvD,WAAK,OAAO;AAEZ,WAAK,YAAY,WAAW,MAAY;AACtC,YAAI;AACF,eAAK,wBAAwB,IAAI,gBAAgB;AAGjD,gBAAM,KAAK,GAAG,MAAM,KAAK,sBAAsB,MAAM;AAErD,eAAK,wBAAwB;AAAA,QAC/B,SAAS,OAAP;AAAA,QAAe;AAAA,MACnB,IAAG,KAAK,IAAI;AAAA,IACd;AAEA,kBAAS,MAAM;AACb,UAAI,KAAK,uBAAuB;AAC9B,aAAK,sBAAsB,MAAM;AACjC,aAAK,wBAAwB;AAAA,MAC/B;AAEA,UAAI,KAAK,cAAc,QAAW;AAChC,qBAAa,KAAK,SAAS;AAC3B,aAAK,YAAY;AAAA,MACnB;AAAA,IACF;AAAA,EA5BmC;AA6BrC;;;ACnCA,kBAAsC;AACtC,oBAA+B;AAC/B,4BAAwB;AAMjB,IAAM,aAAS;AAAA,EACpB;AAAA,EACA;AACF;AA8BO,IAAM,iBAAiB,CAAC,MAAgB,SAC7C,KAAK,WAAW,KAAK,UAAU,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,KAAK,CAAC;AAE5E,SAAS,gCACd,oBACA,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,UAAa,MAAM,QAAQ,MAAM,QAAW;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,SAAO,mBAAmB,GAAG,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uCAAiC,IAAI;AAGrC,UAAI,gBAAgB;AAClB,0BAAkB,SAAS,6BAA6B,cAAc;AAAA,MACxE,OAAO;AACL,0BAAkB,OAAO;AAAA,MAC3B;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAiB;AAAA,IACrB,CAAC,UAA+C;AAC9C,UAAI,+BAA+B;AACjC,YAAI,qCAAqC,KAAK,GAAG;AAC/C,gBAAM,eAAe;AACrB,uCAA6B,6BAA6B;AAC1D,2CAAiC,IAAI;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,EACpB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts","../../../src/lib/debouncer.ts","../../../src/lib/utils.ts","../../../src/types/base/editor-autocomplete-state.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Debouncer } from \"../../lib/debouncer\";\nimport { nullableCompatibleEqualityCheck } from \"../../lib/utils\";\nimport { AutosuggestionsBareFunction } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport {\n EditorAutocompleteState,\n areEqual_autocompleteState,\n} from \"../../types/base/editor-autocomplete-state\";\n\nexport interface UseAutosuggestionsResult {\n currentAutocompleteSuggestion: AutosuggestionState | null;\n onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;\n onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;\n onTouchStartHandler: (event: React.TouchEvent<HTMLDivElement>) => void;\n}\n\nexport function useAutosuggestions(\n debounceTime: number,\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean,\n shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean,\n autosuggestionFunction: AutosuggestionsBareFunction,\n insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void,\n disableWhenEmpty: boolean,\n disabled: boolean,\n): UseAutosuggestionsResult {\n const [previousAutocompleteState, setPreviousAutocompleteState] =\n useState<EditorAutocompleteState | null>(null);\n\n const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] =\n useState<AutosuggestionState | null>(null);\n\n const awaitForAndAppendSuggestion: (\n editorAutocompleteState: EditorAutocompleteState,\n abortSignal: AbortSignal,\n ) => Promise<void> = useCallback(\n async (editorAutocompleteState: EditorAutocompleteState, abortSignal: AbortSignal) => {\n // early return if disabled\n if (disabled) {\n return;\n }\n\n if (\n disableWhenEmpty &&\n editorAutocompleteState.textBeforeCursor === \"\" &&\n editorAutocompleteState.textAfterCursor === \"\"\n ) {\n return;\n }\n\n // fetch the suggestion\n const suggestion = await autosuggestionFunction(editorAutocompleteState, abortSignal);\n\n // We'll assume for now that the autocomplete function might or might not respect the abort signal.\n if (!suggestion || abortSignal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n\n setCurrentAutocompleteSuggestion({\n text: suggestion,\n point: editorAutocompleteState.cursorPoint,\n });\n },\n [autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled],\n );\n\n const debouncedFunction = useMemo(\n () => new Debouncer<[editorAutocompleteState: EditorAutocompleteState]>(debounceTime),\n [debounceTime],\n );\n\n // clean current state when unmounting or disabling\n useEffect(() => {\n return () => {\n debouncedFunction.cancel();\n setCurrentAutocompleteSuggestion(null);\n };\n }, [debouncedFunction, disabled]);\n\n const onChange = useCallback(\n (newEditorState: EditorAutocompleteState | null) => {\n const editorStateHasChanged = !nullableCompatibleEqualityCheck(\n areEqual_autocompleteState,\n previousAutocompleteState,\n newEditorState,\n );\n setPreviousAutocompleteState(newEditorState);\n\n // if no change, do nothing\n if (!editorStateHasChanged) {\n return;\n }\n\n // if change, then first null out the current suggestion\n setCurrentAutocompleteSuggestion(null);\n\n // then try to get a new suggestion, debouncing to avoid too many requests while typing\n if (newEditorState) {\n debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);\n } else {\n debouncedFunction.cancel();\n }\n },\n [\n previousAutocompleteState,\n setPreviousAutocompleteState,\n debouncedFunction,\n awaitForAndAppendSuggestion,\n setCurrentAutocompleteSuggestion,\n ],\n );\n\n const keyDownOrTouchHandler = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>) => {\n if (currentAutocompleteSuggestion) {\n const shouldAcceptSuggestion =\n event instanceof KeyboardEvent\n ? shouldAcceptAutosuggestionOnKeyPress(event as React.KeyboardEvent<HTMLDivElement>)\n : shouldAcceptAutosuggestionOnTouch(event as React.TouchEvent<HTMLDivElement>);\n if (shouldAcceptSuggestion) {\n event.preventDefault();\n insertAutocompleteSuggestion(currentAutocompleteSuggestion);\n setCurrentAutocompleteSuggestion(null);\n }\n }\n },\n [\n currentAutocompleteSuggestion,\n setCurrentAutocompleteSuggestion,\n insertAutocompleteSuggestion,\n shouldAcceptAutosuggestionOnKeyPress,\n ],\n );\n\n return {\n currentAutocompleteSuggestion,\n onChangeHandler: onChange,\n onKeyDownHandler: keyDownOrTouchHandler,\n onTouchStartHandler: keyDownOrTouchHandler,\n };\n}\n","export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;\n\nexport class Debouncer<T extends any[]> {\n private timeoutId?: ReturnType<typeof setTimeout>;\n private activeAbortController?: AbortController;\n\n constructor(private wait: number) {}\n\n debounce = async (func: AsyncFunction<T>, ...args: T) => {\n // Abort the previous promise immediately\n this.cancel();\n\n this.timeoutId = setTimeout(async () => {\n try {\n this.activeAbortController = new AbortController();\n\n // Pass the signal to the async function, assuming it supports it\n await func(...args, this.activeAbortController.signal);\n\n this.activeAbortController = undefined;\n } catch (error) {}\n }, this.wait);\n };\n\n cancel = () => {\n if (this.activeAbortController) {\n this.activeAbortController.abort();\n this.activeAbortController = undefined;\n }\n\n if (this.timeoutId !== undefined) {\n clearTimeout(this.timeoutId);\n this.timeoutId = undefined;\n }\n };\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined,\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n","import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState,\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next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AAAA,MAC3B;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,4BAAwB;AAAA,IAC5B,CAAC,UAAkF;AACjF,UAAI,+BAA+B;AACjC,cAAM,yBACJ,iBAAiB,gBACb,qCAAqC,KAA4C,IACjF,kCAAkC,KAAyC;AACjF,YAAI,wBAAwB;AAC1B,gBAAM,eAAe;AACrB,uCAA6B,6BAA6B;AAC1D,2CAAiC,IAAI;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,IAClB,qBAAqB;AAAA,EACvB;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useAutosuggestions
3
- } from "../../chunk-QKS2IOUH.mjs";
3
+ } from "../../chunk-7QFH4E7C.mjs";
4
4
  import "../../chunk-JJLQVT7S.mjs";
5
5
  import "../../chunk-7SUZ6CXM.mjs";
6
6
  import "../../chunk-DFTV4TST.mjs";
@@ -1,7 +1,7 @@
1
1
  import { AutosuggestionsBareFunction } from '../../types/base/autosuggestions-bare-function.js';
2
2
  import { SuggestionsApiConfig } from '../../types/autosuggestions-config/suggestions-api-config.js';
3
3
  import '@copilotkit/react-core';
4
- import '../../types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js';
4
+ import '@copilotkit/runtime-client-gql';
5
5
  import '../../types/autosuggestions-config/subtypes/make-system-prompt.js';
6
6
 
7
7
  /**
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -19,7 +17,6 @@ var __spreadValues = (a, b) => {
19
17
  }
20
18
  return a;
21
19
  };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
20
  var __export = (target, all) => {
24
21
  for (var name in all)
25
22
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -80,7 +77,7 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
80
77
  }
81
78
 
82
79
  // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
83
- var import_react_core2 = require("@copilotkit/react-core");
80
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
84
81
  function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
85
82
  const { getContextString, copilotApiConfig } = (0, import_react.useContext)(import_react_core.CopilotContext);
86
83
  const publicApiKey = copilotApiConfig.publicApiKey;
@@ -88,44 +85,55 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
88
85
  return (0, import_react.useCallback)(
89
86
  (editorState, abortSignal) => __async(this, null, function* () {
90
87
  const res = yield retry(() => __async(this, null, function* () {
88
+ var _a, _b, _c;
91
89
  const messages = [
92
- {
93
- role: "system",
90
+ new import_runtime_client_gql.TextMessage({
91
+ role: import_runtime_client_gql.Role.System,
94
92
  content: apiConfig.makeSystemPrompt(
95
93
  textareaPurpose,
96
94
  getContextString([], contextCategories)
97
95
  )
98
- },
96
+ }),
99
97
  ...apiConfig.fewShotMessages,
100
- {
101
- role: "user",
102
- name: "TextAfterCursor",
98
+ new import_runtime_client_gql.TextMessage({
99
+ role: import_runtime_client_gql.Role.User,
103
100
  content: editorState.textAfterCursor
104
- },
105
- {
106
- role: "user",
107
- name: "TextBeforeCursor",
108
- content: editorState.textBeforeCursor
109
- }
101
+ }),
102
+ new import_runtime_client_gql.TextMessage({
103
+ role: import_runtime_client_gql.Role.User,
104
+ content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
105
+ }),
106
+ new import_runtime_client_gql.TextMessage({
107
+ role: import_runtime_client_gql.Role.User,
108
+ content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
109
+ })
110
110
  ];
111
- const response = yield (0, import_react_core2.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
112
- messages
113
- }, apiConfig.forwardedParams), {
114
- copilotConfig: copilotApiConfig,
115
- signal: abortSignal,
116
- headers
117
- }));
118
- if (!response.events) {
119
- throw new Error("Failed to fetch chat completion");
120
- }
121
- const reader = response.events.getReader();
111
+ const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
112
+ url: copilotApiConfig.chatApiEndpoint,
113
+ publicApiKey: copilotApiConfig.publicApiKey,
114
+ headers: copilotApiConfig.headers
115
+ });
116
+ const response = yield runtimeClient.generateCopilotResponse(
117
+ {
118
+ frontend: {
119
+ actions: []
120
+ },
121
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
122
+ },
123
+ copilotApiConfig.properties,
124
+ abortSignal
125
+ ).toPromise();
122
126
  let result = "";
123
- while (!abortSignal.aborted) {
124
- const { done, value } = yield reader.read();
125
- if (done) {
127
+ for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
128
+ (_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
129
+ )) {
130
+ if (abortSignal.aborted) {
126
131
  break;
127
132
  }
128
- result += value;
133
+ if (message instanceof import_runtime_client_gql.TextMessage) {
134
+ result += message.content;
135
+ console.log(message.content);
136
+ }
129
137
  }
130
138
  return result;
131
139
  }));
@@ -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, Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction, MinimalChatGPTMessage } 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 { fetchAndDecodeChatCompletionAsText } 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 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: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const response = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...apiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n headers: headers,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n let result = \"\";\n while (!abortSignal.aborted) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\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,oBAA6D;AAC7D,wBAA+B;AAC/B,mBAAwC;;;ACFjC,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,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADfA,IAAAA,qBAAmD;AAe5C,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,QAAI,yBAAW,gCAAc;AACxE,QAAM,eAAe,iBAAiB;AACtC,QAAM,UAAU,mBACV,eAAe,EAAE,CAAC,iDAAmC,GAAG,aAAa,IAAI,CAAC;AAGhF,aAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF;AAAA,UACA,GAAG,UAAU;AAAA,UACb;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,QACF;AAEA,cAAM,WAAW,UAAM,uDAAmC;AAAA,UACxD;AAAA,WACG,UAAU,kBAF2C;AAAA,UAGxD,eAAe;AAAA,UACf,QAAQ;AAAA,UACR;AAAA,QACF,EAAC;AAED,YAAI,CAAC,SAAS,QAAQ;AACpB,gBAAM,IAAI,MAAM,iCAAiC;AAAA,QACnD;AAEA,cAAM,SAAS,SAAS,OAAO,UAAU;AAEzC,YAAI,SAAS;AACb,eAAO,CAAC,YAAY,SAAS;AAC3B,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AACA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":["import_react_core"]}
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 { 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} from \"@copilotkit/runtime-client-gql\";\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 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 {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n 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","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,wBAA+B;AAC/B,mBAAwC;;;ACFjC,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,GA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AA,YACA,cAAU,qDAA0B,QAAQ;AAAA,UAC9C;AAAA,UACA,iBAAiB;AAAA,UACjB;AAAA,QACF,EACC,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,mBAAmB,uCAAa;AAClC,sBAAU,QAAQ;AAClB,oBAAQ,IAAI,QAAQ,OAAO;AAAA,UAC7B;AAAA,QACF;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useMakeStandardAutosuggestionFunction
3
- } from "../../chunk-SJ2TM5GA.mjs";
3
+ } from "../../chunk-5KLAWLCD.mjs";
4
4
  import "../../chunk-KNQIEOFP.mjs";
5
5
  import "../../chunk-MRXNTQOX.mjs";
6
6
  export {
@@ -2,8 +2,8 @@ import { Generator_InsertionOrEditingSuggestion } from '../../types/base/autosug
2
2
  import { InsertionsApiConfig } from '../../types/autosuggestions-config/insertions-api-config.js';
3
3
  import { EditingApiConfig } from '../../types/autosuggestions-config/editing-api-config.js';
4
4
  import '@copilotkit/react-core';
5
+ import '@copilotkit/runtime-client-gql';
5
6
  import '../../types/autosuggestions-config/subtypes/make-system-prompt.js';
6
- import '../../types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js';
7
7
 
8
8
  /**
9
9
  * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -19,7 +17,6 @@ var __spreadValues = (a, b) => {
19
17
  }
20
18
  return a;
21
19
  };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
20
  var __export = (target, all) => {
24
21
  for (var name in all)
25
22
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -63,6 +60,7 @@ module.exports = __toCommonJS(use_make_standard_insertion_function_exports);
63
60
  var import_shared = require("@copilotkit/shared");
64
61
  var import_react_core = require("@copilotkit/react-core");
65
62
  var import_react = require("react");
63
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
66
64
 
67
65
  // src/lib/retry.tsx
68
66
  function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
@@ -80,46 +78,83 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
80
78
  }
81
79
 
82
80
  // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
83
- var import_react_core2 = require("@copilotkit/react-core");
84
81
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
85
82
  const { getContextString, copilotApiConfig } = (0, import_react.useContext)(import_react_core.CopilotContext);
86
83
  const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
84
+ const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
85
+ url: copilotApiConfig.chatApiEndpoint,
86
+ publicApiKey: copilotApiConfig.publicApiKey,
87
+ headers
88
+ });
89
+ function runtimeClientResponseToStringStream(responsePromise) {
90
+ return __async(this, null, function* () {
91
+ const messagesStream = yield import_runtime_client_gql.CopilotRuntimeClient.asStream(responsePromise);
92
+ return new ReadableStream({
93
+ start(controller) {
94
+ return __async(this, null, function* () {
95
+ const reader = messagesStream.getReader();
96
+ let sentContent = "";
97
+ while (true) {
98
+ const { done, value } = yield reader.read();
99
+ if (done) {
100
+ break;
101
+ }
102
+ const messages = (0, import_runtime_client_gql.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
103
+ let newContent = "";
104
+ for (const message of messages) {
105
+ if (message instanceof import_runtime_client_gql.TextMessage) {
106
+ newContent += message.content;
107
+ }
108
+ }
109
+ if (newContent) {
110
+ const contentToSend = newContent.slice(sentContent.length);
111
+ controller.enqueue(contentToSend);
112
+ sentContent += contentToSend;
113
+ }
114
+ }
115
+ controller.close();
116
+ });
117
+ }
118
+ });
119
+ });
120
+ }
87
121
  const insertionFunction = (0, import_react.useCallback)(
88
122
  (editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
89
123
  const res = yield retry(() => __async(this, null, function* () {
90
124
  const messages = [
91
- {
92
- role: "system",
125
+ new import_runtime_client_gql.TextMessage({
126
+ role: import_runtime_client_gql.Role.System,
93
127
  content: insertionApiConfig.makeSystemPrompt(
94
128
  textareaPurpose,
95
129
  getContextString(documents, contextCategories)
96
130
  )
97
- },
131
+ }),
98
132
  ...insertionApiConfig.fewShotMessages,
99
- {
100
- role: "user",
101
- name: "TextAfterCursor",
102
- content: editorState.textAfterCursor
103
- },
104
- {
105
- role: "user",
106
- name: "TextBeforeCursor",
107
- content: editorState.textBeforeCursor
108
- },
109
- {
110
- role: "user",
111
- name: "InsertionPrompt",
112
- content: insertionPrompt
113
- }
133
+ new import_runtime_client_gql.TextMessage({
134
+ role: import_runtime_client_gql.Role.User,
135
+ content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
136
+ }),
137
+ new import_runtime_client_gql.TextMessage({
138
+ role: import_runtime_client_gql.Role.User,
139
+ content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
140
+ }),
141
+ new import_runtime_client_gql.TextMessage({
142
+ role: import_runtime_client_gql.Role.User,
143
+ content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
144
+ })
114
145
  ];
115
- const stream = yield (0, import_react_core2.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
116
- messages
117
- }, insertionApiConfig.forwardedParams), {
118
- copilotConfig: copilotApiConfig,
119
- signal: abortSignal,
120
- headers
121
- }));
122
- return stream.events;
146
+ return runtimeClientResponseToStringStream(
147
+ runtimeClient.generateCopilotResponse(
148
+ {
149
+ frontend: {
150
+ actions: []
151
+ },
152
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
153
+ },
154
+ copilotApiConfig.properties,
155
+ abortSignal
156
+ )
157
+ );
123
158
  }));
124
159
  return res;
125
160
  }),
@@ -129,43 +164,48 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
129
164
  (editorState, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
130
165
  const res = yield retry(() => __async(this, null, function* () {
131
166
  const messages = [
132
- {
133
- role: "system",
167
+ new import_runtime_client_gql.TextMessage({
168
+ role: import_runtime_client_gql.Role.System,
134
169
  content: editingApiConfig.makeSystemPrompt(
135
170
  textareaPurpose,
136
171
  getContextString(documents, contextCategories)
137
172
  )
138
- },
173
+ }),
139
174
  ...editingApiConfig.fewShotMessages,
140
- {
141
- role: "user",
142
- name: "TextBeforeCursor",
143
- content: editorState.textBeforeCursor
144
- },
145
- {
146
- role: "user",
147
- name: "TextToEdit",
148
- content: editorState.selectedText
149
- },
150
- {
151
- role: "user",
152
- name: "TextAfterCursor",
153
- content: editorState.textAfterCursor
154
- },
155
- {
156
- role: "user",
157
- name: "EditingPrompt",
158
- content: editingPrompt
159
- }
175
+ new import_runtime_client_gql.TextMessage({
176
+ role: import_runtime_client_gql.Role.User,
177
+ content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
178
+ }),
179
+ new import_runtime_client_gql.TextMessage({
180
+ role: import_runtime_client_gql.Role.User,
181
+ content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`
182
+ }),
183
+ new import_runtime_client_gql.TextMessage({
184
+ role: import_runtime_client_gql.Role.User,
185
+ content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
186
+ }),
187
+ new import_runtime_client_gql.TextMessage({
188
+ role: import_runtime_client_gql.Role.User,
189
+ content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
190
+ })
160
191
  ];
161
- const stream = yield (0, import_react_core2.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
162
- messages
163
- }, editingApiConfig.forwardedParams), {
164
- copilotConfig: copilotApiConfig,
165
- signal: abortSignal,
192
+ const runtimeClient2 = new import_runtime_client_gql.CopilotRuntimeClient({
193
+ url: copilotApiConfig.chatApiEndpoint,
194
+ publicApiKey: copilotApiConfig.publicApiKey,
166
195
  headers
167
- }));
168
- return stream.events;
196
+ });
197
+ return runtimeClientResponseToStringStream(
198
+ runtimeClient2.generateCopilotResponse(
199
+ {
200
+ frontend: {
201
+ actions: []
202
+ },
203
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
204
+ },
205
+ copilotApiConfig.properties,
206
+ abortSignal
207
+ )
208
+ );
169
209
  }));
170
210
  return res;
171
211
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx","../../../src/lib/retry.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n InsertionEditorApiConfig,\n InsertionEditorState,\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 { fetchAndDecodeChatCompletionAsText } 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 } = useContext(CopilotContext);\n const headers = {\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\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: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...insertionApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: insertionPrompt,\n },\n ];\n\n const stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...insertionApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n headers,\n });\n return stream.events!;\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: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...editingApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: editorState.selectedText,\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: editingPrompt,\n },\n ];\n\n const stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...editingApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n headers,\n });\n return stream.events!;\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","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,oBAA6D;AAC7D,wBAA+B;AAC/B,mBAAwC;;;ACFjC,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,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADRA,IAAAA,qBAAmD;AAe5C,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,QAAI,yBAAW,gCAAc;AACxE,QAAM,UAAU,mBACV,iBAAiB,eACjB,EAAE,CAAC,iDAAmC,GAAG,iBAAiB,aAAa,IACvE,CAAC;AAGP,QAAM,wBAAoB;AAAA,IACxB,CACE,aACA,iBACA,WACA,gBACG;AACH,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,mBAAmB;AAAA,cAC1B;AAAA,cACA,iBAAiB,WAAW,iBAAiB;AAAA,YAC/C;AAAA,UACF;AAAA,UACA,GAAG,mBAAmB;AAAA,UACtB;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAA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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":["import_react_core"]}
1
+ {"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx","../../../src/lib/retry.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} 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 {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n 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 {\n frontend: {\n actions: [],\n },\n messages: convertMessagesToGqlInput(messages),\n },\n copilotApiConfig.properties,\n 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","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,wBAA+B;AAC/B,mBAAwC;AACxC,gCAOO;;;ACVA,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,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADYO,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,QAAI,yBAAW,gCAAc;AACxE,QAAM,UAAU,mBACV,iBAAiB,eACjB,EAAE,CAAC,iDAAmC,GAAG,iBAAiB,aAAa,IACvE,CAAC;AAGP,QAAM,gBAAgB,IAAI,+CAAqB;AAAA,IAC7C,KAAK,iBAAiB;AAAA,IACtB,cAAc,iBAAiB;AAAA,IAC/B;AAAA,EACF,CAAC;AAED,WAAe,o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A,YAC9C;AAAA,YACA,iBAAiB;AAAA,YACjB;AAAA,UACF;AAAA,QACF;AAAA,MACF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,iCAA6B;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"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useMakeStandardInsertionOrEditingFunction
3
- } from "../../chunk-HE4GMS2P.mjs";
3
+ } from "../../chunk-3SVQJA5A.mjs";
4
4
  import "../../chunk-KNQIEOFP.mjs";
5
5
  import "../../chunk-MRXNTQOX.mjs";
6
6
  export {
package/dist/index.d.ts CHANGED
@@ -5,11 +5,11 @@ export { AutosuggestionsBareFunction } from './types/base/autosuggestions-bare-f
5
5
  export { BaseCopilotTextareaProps } from './types/base/base-copilot-textarea-props.js';
6
6
  export { HTMLCopilotTextAreaElement } from './types/html-copilot-textarea-element.js';
7
7
  export { AutosuggestionsConfig, defaultAutosuggestionsConfig } from './types/autosuggestions-config/autosuggestions-config.js';
8
- export { MinimalChatGPTMessage } from './types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js';
9
8
  export { MakeSystemPrompt } from './types/autosuggestions-config/subtypes/make-system-prompt.js';
10
9
  export { AutosuggestionsConfigUserSpecified, InsertionsApiConfigUserSpecified, SuggestionsApiConfigUserSpecified } from './types/autosuggestions-config/autosuggestions-config-user-specified.js';
11
10
  import 'react';
12
11
  import '@copilotkit/react-core';
13
12
  import './types/autosuggestions-config/suggestions-api-config.js';
13
+ import '@copilotkit/runtime-client-gql';
14
14
  import './types/autosuggestions-config/insertions-api-config.js';
15
15
  import './types/autosuggestions-config/editing-api-config.js';