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