@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
@@ -146,7 +146,7 @@ function areEqual_autocompleteState(prev, next) {
146
146
  }
147
147
 
148
148
  // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
149
- function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
149
+ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
150
150
  const [previousAutocompleteState, setPreviousAutocompleteState] = (0, import_react.useState)(null);
151
151
  const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = (0, import_react.useState)(null);
152
152
  const awaitForAndAppendSuggestion = (0, import_react.useCallback)(
@@ -204,10 +204,11 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
204
204
  setCurrentAutocompleteSuggestion
205
205
  ]
206
206
  );
207
- const keyDownHandler = (0, import_react.useCallback)(
207
+ const keyDownOrTouchHandler = (0, import_react.useCallback)(
208
208
  (event) => {
209
209
  if (currentAutocompleteSuggestion) {
210
- if (shouldAcceptAutosuggestionOnKeyPress(event)) {
210
+ const shouldAcceptSuggestion = event instanceof KeyboardEvent ? shouldAcceptAutosuggestionOnKeyPress(event) : shouldAcceptAutosuggestionOnTouch(event);
211
+ if (shouldAcceptSuggestion) {
211
212
  event.preventDefault();
212
213
  insertAutocompleteSuggestion(currentAutocompleteSuggestion);
213
214
  setCurrentAutocompleteSuggestion(null);
@@ -224,7 +225,8 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
224
225
  return {
225
226
  currentAutocompleteSuggestion,
226
227
  onChangeHandler: onChange,
227
- onKeyDownHandler: keyDownHandler
228
+ onKeyDownHandler: keyDownOrTouchHandler,
229
+ onTouchStartHandler: keyDownOrTouchHandler
228
230
  };
229
231
  }
230
232
 
@@ -651,6 +653,7 @@ var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
651
653
  }
652
654
  return false;
653
655
  };
656
+ var defaultShouldAcceptAutosuggestionOnTouch = () => true;
654
657
  var defaultBaseAutosuggestionsConfig = {
655
658
  debounceTime: 250,
656
659
  contextCategories: import_react_core.defaultCopilotContextCategories,
@@ -658,7 +661,8 @@ var defaultBaseAutosuggestionsConfig = {
658
661
  disabled: false,
659
662
  temporarilyDisableWhenMovingCursorWithoutChangingText: true,
660
663
  shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
661
- shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress
664
+ shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
665
+ shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch
662
666
  };
663
667
 
664
668
  // src/components/hovering-toolbar/hovering-toolbar.tsx
@@ -1376,7 +1380,6 @@ var HoveringToolbar = (props) => {
1376
1380
  setIsDisplayed(false);
1377
1381
  },
1378
1382
  performInsertion: (insertedText) => {
1379
- console.log("inserted text", insertedText);
1380
1383
  import_slate7.Transforms.delete(editor, { at: selection });
1381
1384
  import_slate7.Transforms.insertText(editor, insertedText, {
1382
1385
  at: selection
@@ -1627,10 +1630,12 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1627
1630
  const {
1628
1631
  currentAutocompleteSuggestion,
1629
1632
  onChangeHandler: onChangeHandlerForAutocomplete,
1630
- onKeyDownHandler: onKeyDownHandlerForAutocomplete
1633
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete,
1634
+ onTouchStartHandler: onTouchStartHandlerForAutocomplete
1631
1635
  } = useAutosuggestions(
1632
1636
  autosuggestionsConfig.debounceTime,
1633
1637
  autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
1638
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,
1634
1639
  autosuggestionsConfig.apiConfig.autosuggestionsFunction,
1635
1640
  insertText,
1636
1641
  autosuggestionsConfig.disableWhenEmpty,
@@ -1759,6 +1764,9 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1759
1764
  onKeyDownHandlerForAutocomplete(event);
1760
1765
  (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
1761
1766
  },
1767
+ onTouchStart: (event) => {
1768
+ onTouchStartHandlerForAutocomplete(event);
1769
+ },
1762
1770
  className: moddedClassName,
1763
1771
  onBlur: (ev) => {
1764
1772
  var _a2;
@@ -1809,7 +1817,7 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
1809
1817
  }
1810
1818
 
1811
1819
  // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1812
- var import_react_core4 = require("@copilotkit/react-core");
1820
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1813
1821
  function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
1814
1822
  const { getContextString, copilotApiConfig } = (0, import_react13.useContext)(import_react_core3.CopilotContext);
1815
1823
  const publicApiKey = copilotApiConfig.publicApiKey;
@@ -1817,44 +1825,55 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
1817
1825
  return (0, import_react13.useCallback)(
1818
1826
  (editorState2, abortSignal) => __async(this, null, function* () {
1819
1827
  const res = yield retry(() => __async(this, null, function* () {
1828
+ var _a, _b, _c;
1820
1829
  const messages = [
1821
- {
1822
- role: "system",
1830
+ new import_runtime_client_gql.TextMessage({
1831
+ role: import_runtime_client_gql.Role.System,
1823
1832
  content: apiConfig.makeSystemPrompt(
1824
1833
  textareaPurpose,
1825
1834
  getContextString([], contextCategories)
1826
1835
  )
1827
- },
1836
+ }),
1828
1837
  ...apiConfig.fewShotMessages,
1829
- {
1830
- role: "user",
1831
- name: "TextAfterCursor",
1838
+ new import_runtime_client_gql.TextMessage({
1839
+ role: import_runtime_client_gql.Role.User,
1832
1840
  content: editorState2.textAfterCursor
1833
- },
1834
- {
1835
- role: "user",
1836
- name: "TextBeforeCursor",
1837
- content: editorState2.textBeforeCursor
1838
- }
1841
+ }),
1842
+ new import_runtime_client_gql.TextMessage({
1843
+ role: import_runtime_client_gql.Role.User,
1844
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
1845
+ }),
1846
+ new import_runtime_client_gql.TextMessage({
1847
+ role: import_runtime_client_gql.Role.User,
1848
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
1849
+ })
1839
1850
  ];
1840
- const response = yield (0, import_react_core4.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
1841
- messages
1842
- }, apiConfig.forwardedParams), {
1843
- copilotConfig: copilotApiConfig,
1844
- signal: abortSignal,
1845
- headers
1846
- }));
1847
- if (!response.events) {
1848
- throw new Error("Failed to fetch chat completion");
1849
- }
1850
- const reader = response.events.getReader();
1851
+ const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
1852
+ url: copilotApiConfig.chatApiEndpoint,
1853
+ publicApiKey: copilotApiConfig.publicApiKey,
1854
+ headers: copilotApiConfig.headers
1855
+ });
1856
+ const response = yield runtimeClient.generateCopilotResponse(
1857
+ {
1858
+ frontend: {
1859
+ actions: []
1860
+ },
1861
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
1862
+ },
1863
+ copilotApiConfig.properties,
1864
+ abortSignal
1865
+ ).toPromise();
1851
1866
  let result = "";
1852
- while (!abortSignal.aborted) {
1853
- const { done, value } = yield reader.read();
1854
- if (done) {
1867
+ for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
1868
+ (_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
1869
+ )) {
1870
+ if (abortSignal.aborted) {
1855
1871
  break;
1856
1872
  }
1857
- result += value;
1873
+ if (message instanceof import_runtime_client_gql.TextMessage) {
1874
+ result += message.content;
1875
+ console.log(message.content);
1876
+ }
1858
1877
  }
1859
1878
  return result;
1860
1879
  }));
@@ -1865,6 +1884,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
1865
1884
  }
1866
1885
 
1867
1886
  // src/types/autosuggestions-config/suggestions-api-config.tsx
1887
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1868
1888
  var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1869
1889
  return `You are a versatile writing assistant.
1870
1890
 
@@ -1890,33 +1910,30 @@ ${contextString}
1890
1910
  `;
1891
1911
  };
1892
1912
  var defaultSuggestionsFewShotMessages = [
1893
- {
1894
- role: "user",
1895
- name: "TextAfterCursor",
1896
- content: "While I was there I also picked up some apples, oranges, and bananas."
1897
- },
1898
- {
1899
- role: "user",
1913
+ new import_runtime_client_gql2.TextMessage({
1914
+ role: import_runtime_client_gql2.Role.User,
1915
+ content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
1916
+ }),
1917
+ new import_runtime_client_gql2.TextMessage({
1918
+ role: import_runtime_client_gql2.Role.User,
1900
1919
  content: "This morning I woke up and went straight to the grocery store."
1901
- },
1902
- {
1903
- role: "assistant",
1920
+ }),
1921
+ new import_runtime_client_gql2.TextMessage({
1922
+ role: import_runtime_client_gql2.Role.Assistant,
1904
1923
  content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
1905
- },
1906
- {
1907
- role: "user",
1908
- name: "TextAfterCursor",
1909
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
1910
- },
1911
- {
1912
- role: "user",
1913
- name: "TextBeforeCursor",
1914
- content: `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;`
1915
- },
1916
- {
1917
- role: "assistant",
1924
+ }),
1925
+ new import_runtime_client_gql2.TextMessage({
1926
+ role: import_runtime_client_gql2.Role.User,
1927
+ content: "<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>"
1928
+ }),
1929
+ new import_runtime_client_gql2.TextMessage({
1930
+ role: import_runtime_client_gql2.Role.User,
1931
+ content: `<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>`
1932
+ }),
1933
+ new import_runtime_client_gql2.TextMessage({
1934
+ role: import_runtime_client_gql2.Role.Assistant,
1918
1935
  content: ` (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"; `
1919
- }
1936
+ })
1920
1937
  ];
1921
1938
  var defaultSuggestionsApiConfig = {
1922
1939
  makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
@@ -1925,6 +1942,7 @@ var defaultSuggestionsApiConfig = {
1925
1942
  };
1926
1943
 
1927
1944
  // src/types/autosuggestions-config/insertions-api-config.tsx
1945
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1928
1946
  var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1929
1947
  return `You are a versatile writing assistant helping the user insert new text into their existing work.
1930
1948
 
@@ -1953,44 +1971,38 @@ The conversation will be structured as follows:
1953
1971
  `;
1954
1972
  };
1955
1973
  var defaultInsertionsFewShotMessages = [
1956
- {
1957
- role: "user",
1958
- name: "TextAfterCursor",
1959
- content: "While I was there I also picked up some apples, oranges, and bananas."
1960
- },
1961
- {
1962
- role: "user",
1963
- name: "TextBeforeCursor",
1964
- content: "This morning I woke up and went straight to the grocery store."
1965
- },
1966
- {
1967
- role: "user",
1968
- name: "InsertionPrompt",
1969
- content: "I bought a big watermelon"
1970
- },
1971
- {
1972
- role: "assistant",
1973
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
1974
- },
1975
- {
1976
- role: "user",
1977
- name: "TextAfterCursor",
1978
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
1979
- },
1980
- {
1981
- role: "user",
1982
- name: "TextBeforeCursor",
1983
- content: `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;`
1984
- },
1985
- {
1986
- role: "user",
1987
- name: "InsertionPrompt",
1988
- content: "add section about the optionholder's pro rata share"
1989
- },
1990
- {
1991
- role: "assistant",
1974
+ new import_runtime_client_gql3.TextMessage({
1975
+ role: import_runtime_client_gql3.Role.User,
1976
+ content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
1977
+ }),
1978
+ new import_runtime_client_gql3.TextMessage({
1979
+ role: import_runtime_client_gql3.Role.User,
1980
+ content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
1981
+ }),
1982
+ new import_runtime_client_gql3.TextMessage({
1983
+ role: import_runtime_client_gql3.Role.User,
1984
+ content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
1985
+ }),
1986
+ new import_runtime_client_gql3.TextMessage({
1987
+ role: import_runtime_client_gql3.Role.Assistant,
1988
+ content: "When I arrived I went straight to the produce section and picked out a big watermelon."
1989
+ }),
1990
+ new import_runtime_client_gql3.TextMessage({
1991
+ role: import_runtime_client_gql3.Role.User,
1992
+ content: "<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>"
1993
+ }),
1994
+ new import_runtime_client_gql3.TextMessage({
1995
+ role: import_runtime_client_gql3.Role.User,
1996
+ content: `<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>`
1997
+ }),
1998
+ new import_runtime_client_gql3.TextMessage({
1999
+ role: import_runtime_client_gql3.Role.User,
2000
+ content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
2001
+ }),
2002
+ new import_runtime_client_gql3.TextMessage({
2003
+ role: import_runtime_client_gql3.Role.Assistant,
1992
2004
  content: ` (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"; `
1993
- }
2005
+ })
1994
2006
  ];
1995
2007
  var defaultInsertionsApiConfig = {
1996
2008
  makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
@@ -1999,6 +2011,7 @@ var defaultInsertionsApiConfig = {
1999
2011
  };
2000
2012
 
2001
2013
  // src/types/autosuggestions-config/editing-api-config.tsx
2014
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
2002
2015
  var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
2003
2016
  return `You are a versatile writing assistant helping the user edit a portion of their text.
2004
2017
 
@@ -2026,54 +2039,46 @@ The conversation will be structured as follows:
2026
2039
  `;
2027
2040
  };
2028
2041
  var defaultEditingFewShotMessages = [
2029
- {
2030
- role: "user",
2031
- name: "TextBeforeCursor",
2032
- content: "This morning I woke up and went straight to the grocery store. "
2033
- },
2034
- {
2035
- role: "user",
2036
- name: "TextToEdit",
2037
- content: "While I was there I picked up some apples, oranges, and bananas. "
2038
- },
2039
- {
2040
- role: "user",
2041
- name: "TextAfterCursor",
2042
- content: "The grocery store was having a sale on fruit, so I decided to stock up."
2043
- },
2044
- {
2045
- role: "user",
2046
- name: "EditingPrompt",
2047
- content: "I also bought a big watermelon"
2048
- },
2049
- {
2050
- role: "assistant",
2042
+ new import_runtime_client_gql4.TextMessage({
2043
+ role: import_runtime_client_gql4.Role.User,
2044
+ content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
2045
+ }),
2046
+ new import_runtime_client_gql4.TextMessage({
2047
+ role: import_runtime_client_gql4.Role.User,
2048
+ content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
2049
+ }),
2050
+ new import_runtime_client_gql4.TextMessage({
2051
+ role: import_runtime_client_gql4.Role.User,
2052
+ content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
2053
+ }),
2054
+ new import_runtime_client_gql4.TextMessage({
2055
+ role: import_runtime_client_gql4.Role.User,
2056
+ content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
2057
+ }),
2058
+ new import_runtime_client_gql4.TextMessage({
2059
+ role: import_runtime_client_gql4.Role.Assistant,
2051
2060
  content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
2052
- },
2053
- {
2054
- role: "user",
2055
- name: "TextBeforeCursor",
2056
- content: "Yesterday, I spent the afternoon working on my new project. "
2057
- },
2058
- {
2059
- role: "user",
2060
- name: "TextToEdit",
2061
- content: "It's quite challenging and requires a lot of focus. "
2062
- },
2063
- {
2064
- role: "user",
2065
- name: "TextAfterCursor",
2066
- content: "I'm really excited about the potential outcomes of this project."
2067
- },
2068
- {
2069
- role: "user",
2070
- name: "EditingPrompt",
2071
- content: "emphasize the complexity and my enthusiasm for the project"
2072
- },
2073
- {
2074
- role: "assistant",
2061
+ }),
2062
+ new import_runtime_client_gql4.TextMessage({
2063
+ role: import_runtime_client_gql4.Role.User,
2064
+ content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
2065
+ }),
2066
+ new import_runtime_client_gql4.TextMessage({
2067
+ role: import_runtime_client_gql4.Role.User,
2068
+ content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
2069
+ }),
2070
+ new import_runtime_client_gql4.TextMessage({
2071
+ role: import_runtime_client_gql4.Role.User,
2072
+ content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
2073
+ }),
2074
+ new import_runtime_client_gql4.TextMessage({
2075
+ role: import_runtime_client_gql4.Role.User,
2076
+ content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
2077
+ }),
2078
+ new import_runtime_client_gql4.TextMessage({
2079
+ role: import_runtime_client_gql4.Role.Assistant,
2075
2080
  content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
2076
- }
2081
+ })
2077
2082
  ];
2078
2083
  var defaultEditingApiConfig = {
2079
2084
  makeSystemPrompt: defaultEditingMakeSystemPrompt,
@@ -2082,9 +2087,9 @@ var defaultEditingApiConfig = {
2082
2087
  };
2083
2088
 
2084
2089
  // src/types/autosuggestions-config/autosuggestions-config.tsx
2085
- var import_react_core5 = require("@copilotkit/react-core");
2090
+ var import_react_core4 = require("@copilotkit/react-core");
2086
2091
  var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
2087
- contextCategories: import_react_core5.defaultCopilotContextCategories,
2092
+ contextCategories: import_react_core4.defaultCopilotContextCategories,
2088
2093
  chatApiConfigs: {
2089
2094
  suggestionsApiConfig: defaultSuggestionsApiConfig,
2090
2095
  insertionApiConfig: defaultInsertionsApiConfig,
@@ -2094,48 +2099,86 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
2094
2099
 
2095
2100
  // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2096
2101
  var import_shared2 = require("@copilotkit/shared");
2097
- var import_react_core6 = require("@copilotkit/react-core");
2102
+ var import_react_core5 = require("@copilotkit/react-core");
2098
2103
  var import_react14 = require("react");
2099
- var import_react_core7 = require("@copilotkit/react-core");
2104
+ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
2100
2105
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2101
- const { getContextString, copilotApiConfig } = (0, import_react14.useContext)(import_react_core6.CopilotContext);
2106
+ const { getContextString, copilotApiConfig } = (0, import_react14.useContext)(import_react_core5.CopilotContext);
2102
2107
  const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2108
+ const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
2109
+ url: copilotApiConfig.chatApiEndpoint,
2110
+ publicApiKey: copilotApiConfig.publicApiKey,
2111
+ headers
2112
+ });
2113
+ function runtimeClientResponseToStringStream(responsePromise) {
2114
+ return __async(this, null, function* () {
2115
+ const messagesStream = yield import_runtime_client_gql5.CopilotRuntimeClient.asStream(responsePromise);
2116
+ return new ReadableStream({
2117
+ start(controller) {
2118
+ return __async(this, null, function* () {
2119
+ const reader = messagesStream.getReader();
2120
+ let sentContent = "";
2121
+ while (true) {
2122
+ const { done, value } = yield reader.read();
2123
+ if (done) {
2124
+ break;
2125
+ }
2126
+ const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
2127
+ let newContent = "";
2128
+ for (const message of messages) {
2129
+ if (message instanceof import_runtime_client_gql5.TextMessage) {
2130
+ newContent += message.content;
2131
+ }
2132
+ }
2133
+ if (newContent) {
2134
+ const contentToSend = newContent.slice(sentContent.length);
2135
+ controller.enqueue(contentToSend);
2136
+ sentContent += contentToSend;
2137
+ }
2138
+ }
2139
+ controller.close();
2140
+ });
2141
+ }
2142
+ });
2143
+ });
2144
+ }
2103
2145
  const insertionFunction = (0, import_react14.useCallback)(
2104
2146
  (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2105
2147
  const res = yield retry(() => __async(this, null, function* () {
2106
2148
  const messages = [
2107
- {
2108
- role: "system",
2149
+ new import_runtime_client_gql5.TextMessage({
2150
+ role: import_runtime_client_gql5.Role.System,
2109
2151
  content: insertionApiConfig.makeSystemPrompt(
2110
2152
  textareaPurpose,
2111
2153
  getContextString(documents, contextCategories)
2112
2154
  )
2113
- },
2155
+ }),
2114
2156
  ...insertionApiConfig.fewShotMessages,
2115
- {
2116
- role: "user",
2117
- name: "TextAfterCursor",
2118
- content: editorState2.textAfterCursor
2119
- },
2120
- {
2121
- role: "user",
2122
- name: "TextBeforeCursor",
2123
- content: editorState2.textBeforeCursor
2124
- },
2125
- {
2126
- role: "user",
2127
- name: "InsertionPrompt",
2128
- content: insertionPrompt
2129
- }
2157
+ new import_runtime_client_gql5.TextMessage({
2158
+ role: import_runtime_client_gql5.Role.User,
2159
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2160
+ }),
2161
+ new import_runtime_client_gql5.TextMessage({
2162
+ role: import_runtime_client_gql5.Role.User,
2163
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2164
+ }),
2165
+ new import_runtime_client_gql5.TextMessage({
2166
+ role: import_runtime_client_gql5.Role.User,
2167
+ content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
2168
+ })
2130
2169
  ];
2131
- const stream = yield (0, import_react_core7.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
2132
- messages
2133
- }, insertionApiConfig.forwardedParams), {
2134
- copilotConfig: copilotApiConfig,
2135
- signal: abortSignal,
2136
- headers
2137
- }));
2138
- return stream.events;
2170
+ return runtimeClientResponseToStringStream(
2171
+ runtimeClient.generateCopilotResponse(
2172
+ {
2173
+ frontend: {
2174
+ actions: []
2175
+ },
2176
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
2177
+ },
2178
+ copilotApiConfig.properties,
2179
+ abortSignal
2180
+ )
2181
+ );
2139
2182
  }));
2140
2183
  return res;
2141
2184
  }),
@@ -2145,43 +2188,48 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
2145
2188
  (editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
2146
2189
  const res = yield retry(() => __async(this, null, function* () {
2147
2190
  const messages = [
2148
- {
2149
- role: "system",
2191
+ new import_runtime_client_gql5.TextMessage({
2192
+ role: import_runtime_client_gql5.Role.System,
2150
2193
  content: editingApiConfig.makeSystemPrompt(
2151
2194
  textareaPurpose,
2152
2195
  getContextString(documents, contextCategories)
2153
2196
  )
2154
- },
2197
+ }),
2155
2198
  ...editingApiConfig.fewShotMessages,
2156
- {
2157
- role: "user",
2158
- name: "TextBeforeCursor",
2159
- content: editorState2.textBeforeCursor
2160
- },
2161
- {
2162
- role: "user",
2163
- name: "TextToEdit",
2164
- content: editorState2.selectedText
2165
- },
2166
- {
2167
- role: "user",
2168
- name: "TextAfterCursor",
2169
- content: editorState2.textAfterCursor
2170
- },
2171
- {
2172
- role: "user",
2173
- name: "EditingPrompt",
2174
- content: editingPrompt
2175
- }
2199
+ new import_runtime_client_gql5.TextMessage({
2200
+ role: import_runtime_client_gql5.Role.User,
2201
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2202
+ }),
2203
+ new import_runtime_client_gql5.TextMessage({
2204
+ role: import_runtime_client_gql5.Role.User,
2205
+ content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
2206
+ }),
2207
+ new import_runtime_client_gql5.TextMessage({
2208
+ role: import_runtime_client_gql5.Role.User,
2209
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2210
+ }),
2211
+ new import_runtime_client_gql5.TextMessage({
2212
+ role: import_runtime_client_gql5.Role.User,
2213
+ content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
2214
+ })
2176
2215
  ];
2177
- const stream = yield (0, import_react_core7.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
2178
- messages
2179
- }, editingApiConfig.forwardedParams), {
2180
- copilotConfig: copilotApiConfig,
2181
- signal: abortSignal,
2216
+ const runtimeClient2 = new import_runtime_client_gql5.CopilotRuntimeClient({
2217
+ url: copilotApiConfig.chatApiEndpoint,
2218
+ publicApiKey: copilotApiConfig.publicApiKey,
2182
2219
  headers
2183
- }));
2184
- return stream.events;
2220
+ });
2221
+ return runtimeClientResponseToStringStream(
2222
+ runtimeClient2.generateCopilotResponse(
2223
+ {
2224
+ frontend: {
2225
+ actions: []
2226
+ },
2227
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
2228
+ },
2229
+ copilotApiConfig.properties,
2230
+ abortSignal
2231
+ )
2232
+ );
2185
2233
  }));
2186
2234
  return res;
2187
2235
  }),