@copilotkit/react-textarea 1.50.0-beta.1 → 1.50.0-beta.11

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 (37) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/{chunk-ISKK3RIW.mjs → chunk-4ECCCOFV.mjs} +4 -4
  3. package/dist/{chunk-5NZNJCP2.mjs → chunk-AT3INWD6.mjs} +25 -25
  4. package/dist/{chunk-4VCJHANC.mjs → chunk-JVCLCI7G.mjs} +4 -4
  5. package/dist/chunk-KAU7LAEQ.mjs +60 -0
  6. package/dist/chunk-KAU7LAEQ.mjs.map +1 -0
  7. package/dist/{chunk-66KFI242.mjs → chunk-L6JBC3MS.mjs} +2 -2
  8. package/dist/chunk-MMVDU6DF.mjs +1 -0
  9. package/dist/{chunk-7VADGLV2.mjs → chunk-PIMJDHZM.mjs} +5 -5
  10. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +19 -19
  11. package/dist/components/copilot-textarea/copilot-textarea.mjs +30 -77
  12. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  13. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +8 -8
  14. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +4 -4
  15. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +5 -5
  16. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +5 -5
  17. package/dist/components/index.d.ts +11 -2
  18. package/dist/components/index.js +490 -8
  19. package/dist/components/index.js.map +1 -1
  20. package/dist/components/index.mjs +33 -21
  21. package/dist/components/ui/command.d.ts +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +327 -59
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +37 -30
  26. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
  27. package/dist/types/autosuggestions-config/index.mjs +2 -2
  28. package/dist/types/index.mjs +3 -3
  29. package/package.json +6 -6
  30. package/src/components/index.ts +3 -0
  31. package/dist/chunk-JD7BAH7U.mjs +0 -1
  32. /package/dist/{chunk-ISKK3RIW.mjs.map → chunk-4ECCCOFV.mjs.map} +0 -0
  33. /package/dist/{chunk-5NZNJCP2.mjs.map → chunk-AT3INWD6.mjs.map} +0 -0
  34. /package/dist/{chunk-4VCJHANC.mjs.map → chunk-JVCLCI7G.mjs.map} +0 -0
  35. /package/dist/{chunk-66KFI242.mjs.map → chunk-L6JBC3MS.mjs.map} +0 -0
  36. /package/dist/{chunk-JD7BAH7U.mjs.map → chunk-MMVDU6DF.mjs.map} +0 -0
  37. /package/dist/{chunk-7VADGLV2.mjs.map → chunk-PIMJDHZM.mjs.map} +0 -0
@@ -1,41 +1,53 @@
1
- import "../chunk-JD7BAH7U.mjs";
1
+ import "../chunk-MMVDU6DF.mjs";
2
+ import {
3
+ CopilotTextarea
4
+ } from "../chunk-KAU7LAEQ.mjs";
5
+ import "../chunk-ZQSEYPNN.mjs";
6
+ import "../chunk-DL3JWL2E.mjs";
7
+ import "../chunk-KNQIEOFP.mjs";
2
8
  import {
3
9
  BaseCopilotTextarea
4
- } from "../chunk-5NZNJCP2.mjs";
10
+ } from "../chunk-AT3INWD6.mjs";
11
+ import "../chunk-2C7O2EVM.mjs";
5
12
  import "../chunk-GQN2HYFJ.mjs";
6
- import "../chunk-7VADGLV2.mjs";
13
+ import "../chunk-23Q6A46J.mjs";
14
+ import "../chunk-AJ5OMEXM.mjs";
15
+ import "../chunk-DRV2FOHZ.mjs";
16
+ import "../chunk-4NHVQZ67.mjs";
17
+ import "../chunk-QJNFNPWH.mjs";
18
+ import "../chunk-5UNJXFUO.mjs";
19
+ import "../chunk-7LSRNPNI.mjs";
20
+ import "../chunk-PIMJDHZM.mjs";
7
21
  import "../chunk-L7VVZH4Q.mjs";
8
- import "../chunk-66KFI242.mjs";
9
- import "../chunk-4VCJHANC.mjs";
22
+ import "../chunk-L6JBC3MS.mjs";
23
+ import "../chunk-JVCLCI7G.mjs";
10
24
  import "../chunk-KMVGEY7Q.mjs";
11
- import "../chunk-2IWVZ4PP.mjs";
12
25
  import "../chunk-WGWQRALG.mjs";
26
+ import "../chunk-D47EKHIF.mjs";
27
+ import "../chunk-NAFNY4FL.mjs";
28
+ import "../chunk-LYB4B6MK.mjs";
29
+ import "../chunk-2IWVZ4PP.mjs";
13
30
  import "../chunk-4PDYALMP.mjs";
14
31
  import "../chunk-VSVQZUPW.mjs";
15
32
  import "../chunk-I72DKFHD.mjs";
16
- import "../chunk-D47EKHIF.mjs";
17
- import "../chunk-2C7O2EVM.mjs";
18
- import "../chunk-NAFNY4FL.mjs";
33
+ import "../chunk-ECR45NSD.mjs";
34
+ import "../chunk-2QDCE7PD.mjs";
35
+ import "../chunk-YLFAIYRY.mjs";
19
36
  import "../chunk-F2ULK22F.mjs";
20
37
  import "../chunk-3QJOFG3V.mjs";
21
38
  import "../chunk-JLOABKLH.mjs";
22
- import "../chunk-7LSRNPNI.mjs";
23
- import "../chunk-LYB4B6MK.mjs";
24
- import "../chunk-2QDCE7PD.mjs";
39
+ import "../chunk-RUV6NBIF.mjs";
40
+ import "../chunk-4ECCCOFV.mjs";
41
+ import "../chunk-EJGGLWWR.mjs";
42
+ import "../chunk-MCNXIA4Q.mjs";
43
+ import "../chunk-QFXR6DOA.mjs";
25
44
  import "../chunk-WJHSY5T6.mjs";
26
45
  import "../chunk-F6RLSVG3.mjs";
27
- import "../chunk-23Q6A46J.mjs";
28
- import "../chunk-AJ5OMEXM.mjs";
29
- import "../chunk-YLFAIYRY.mjs";
30
- import "../chunk-DRV2FOHZ.mjs";
31
- import "../chunk-4NHVQZ67.mjs";
32
- import "../chunk-QJNFNPWH.mjs";
33
- import "../chunk-5UNJXFUO.mjs";
34
46
  import "../chunk-DFTV4TST.mjs";
35
47
  import "../chunk-T6MTDQZ7.mjs";
36
- import "../chunk-ECR45NSD.mjs";
37
48
  import "../chunk-MRXNTQOX.mjs";
38
49
  export {
39
- BaseCopilotTextarea
50
+ BaseCopilotTextarea,
51
+ CopilotTextarea
40
52
  };
41
53
  //# sourceMappingURL=index.mjs.map
@@ -17,7 +17,7 @@ declare const Command: React.ForwardRefExoticComponent<Omit<{
17
17
  interface CommandDialogProps extends DialogProps {
18
18
  }
19
19
  declare const CommandDialog: ({ children, ...props }: CommandDialogProps) => react_jsx_runtime.JSX.Element;
20
- declare const CommandInput: React.ForwardRefExoticComponent<Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "onChange" | "value"> & {
20
+ declare const CommandInput: React.ForwardRefExoticComponent<Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "type"> & {
21
21
  value?: string;
22
22
  onValueChange?: (search: string) => void;
23
23
  } & React.RefAttributes<HTMLInputElement>, "ref"> & React.RefAttributes<HTMLInputElement>>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { BaseCopilotTextarea } from './components/base-copilot-textarea/base-copilot-textarea.js';
2
+ export { CopilotTextarea, CopilotTextareaProps } from './components/copilot-textarea/copilot-textarea.js';
2
3
  export { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from './types/base/base-autosuggestions-config.js';
3
4
  export { AutosuggestionsBareFunction } from './types/base/autosuggestions-bare-function.js';
4
5
  export { BaseCopilotTextareaProps } from './types/base/index.js';
package/dist/index.js CHANGED
@@ -81,6 +81,7 @@ var __async = (__this, __arguments, generator) => {
81
81
  var src_exports = {};
82
82
  __export(src_exports, {
83
83
  BaseCopilotTextarea: () => BaseCopilotTextarea,
84
+ CopilotTextarea: () => CopilotTextarea,
84
85
  defaultAutosuggestionsConfig: () => defaultAutosuggestionsConfig,
85
86
  defaultBaseAutosuggestionsConfig: () => defaultBaseAutosuggestionsConfig
86
87
  });
@@ -284,21 +285,21 @@ var withPartialHistory = (editor, shouldSave2) => {
284
285
  const lastBatch = undos[undos.length - 1];
285
286
  const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
286
287
  let save = import_slate_history.HistoryEditor.isSaving(e);
287
- let merge = import_slate_history.HistoryEditor.isMerging(e);
288
+ let merge2 = import_slate_history.HistoryEditor.isMerging(e);
288
289
  if (save == null) {
289
290
  save = shouldSave2(op, lastOp);
290
291
  }
291
292
  if (save) {
292
- if (merge == null) {
293
+ if (merge2 == null) {
293
294
  if (lastBatch == null) {
294
- merge = false;
295
+ merge2 = false;
295
296
  } else if (operations.length !== 0) {
296
- merge = true;
297
+ merge2 = true;
297
298
  } else {
298
- merge = shouldMerge(op, lastOp);
299
+ merge2 = shouldMerge(op, lastOp);
299
300
  }
300
301
  }
301
- if (lastBatch && merge) {
302
+ if (lastBatch && merge2) {
302
303
  lastBatch.operations.push(op);
303
304
  } else {
304
305
  const batch = {
@@ -1780,8 +1781,86 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
1780
1781
  };
1781
1782
  }
1782
1783
 
1783
- // src/types/autosuggestions-config/suggestions-api-config.tsx
1784
+ // src/components/copilot-textarea/copilot-textarea.tsx
1785
+ var import_react15 = __toESM(require("react"));
1786
+
1787
+ // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1788
+ var import_shared2 = require("@copilotkit/shared");
1789
+ var import_react_core3 = require("@copilotkit/react-core");
1790
+ var import_react13 = require("react");
1791
+
1792
+ // src/lib/retry.tsx
1793
+ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
1794
+ return new Promise((resolve, reject) => {
1795
+ fn().then(resolve).catch((error) => {
1796
+ if (retriesLeft === 1) {
1797
+ reject(error);
1798
+ return;
1799
+ }
1800
+ setTimeout(() => {
1801
+ retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
1802
+ }, interval);
1803
+ });
1804
+ });
1805
+ }
1806
+
1807
+ // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1784
1808
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1809
+ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
1810
+ const runtimeClient = { generateCopilotResponse: (...args) => {
1811
+ } };
1812
+ const { getContextString, copilotApiConfig } = (0, import_react_core3.useCopilotContext)();
1813
+ const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
1814
+ const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1815
+ const { maxTokens, stop, temperature = 0 } = apiConfig;
1816
+ return (0, import_react13.useCallback)(
1817
+ (editorState2, abortSignal) => __async(this, null, function* () {
1818
+ const res = yield retry(() => __async(this, null, function* () {
1819
+ var _a, _b, _c;
1820
+ const messages = [
1821
+ new import_runtime_client_gql.TextMessage({
1822
+ role: import_runtime_client_gql.Role.System,
1823
+ content: apiConfig.makeSystemPrompt(
1824
+ textareaPurpose,
1825
+ getContextString([], contextCategories)
1826
+ )
1827
+ }),
1828
+ ...apiConfig.fewShotMessages,
1829
+ editorState2.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
1830
+ role: import_runtime_client_gql.Role.User,
1831
+ content: editorState2.textAfterCursor
1832
+ }) : null,
1833
+ new import_runtime_client_gql.TextMessage({
1834
+ role: import_runtime_client_gql.Role.User,
1835
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
1836
+ }),
1837
+ new import_runtime_client_gql.TextMessage({
1838
+ role: import_runtime_client_gql.Role.User,
1839
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
1840
+ })
1841
+ ].filter(Boolean);
1842
+ const response = {};
1843
+ let result = "";
1844
+ for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
1845
+ (_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
1846
+ )) {
1847
+ if (abortSignal.aborted) {
1848
+ break;
1849
+ }
1850
+ if (message.isTextMessage()) {
1851
+ result += message.content;
1852
+ }
1853
+ }
1854
+ return result;
1855
+ }));
1856
+ return res;
1857
+ }),
1858
+ [apiConfig, getContextString, contextCategories, textareaPurpose]
1859
+ );
1860
+ }
1861
+
1862
+ // src/types/autosuggestions-config/suggestions-api-config.tsx
1863
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1785
1864
  var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1786
1865
  return `You are a versatile writing assistant.
1787
1866
 
@@ -1808,28 +1887,28 @@ ${contextString}
1808
1887
  `;
1809
1888
  };
1810
1889
  var defaultSuggestionsFewShotMessages = [
1811
- new import_runtime_client_gql.TextMessage({
1812
- role: import_runtime_client_gql.Role.User,
1890
+ new import_runtime_client_gql2.TextMessage({
1891
+ role: import_runtime_client_gql2.Role.User,
1813
1892
  content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
1814
1893
  }),
1815
- new import_runtime_client_gql.TextMessage({
1816
- role: import_runtime_client_gql.Role.User,
1894
+ new import_runtime_client_gql2.TextMessage({
1895
+ role: import_runtime_client_gql2.Role.User,
1817
1896
  content: "This morning I woke up and went straight to the grocery store."
1818
1897
  }),
1819
- new import_runtime_client_gql.TextMessage({
1820
- role: import_runtime_client_gql.Role.Assistant,
1898
+ new import_runtime_client_gql2.TextMessage({
1899
+ role: import_runtime_client_gql2.Role.Assistant,
1821
1900
  content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
1822
1901
  }),
1823
- new import_runtime_client_gql.TextMessage({
1824
- role: import_runtime_client_gql.Role.User,
1902
+ new import_runtime_client_gql2.TextMessage({
1903
+ role: import_runtime_client_gql2.Role.User,
1825
1904
  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>"
1826
1905
  }),
1827
- new import_runtime_client_gql.TextMessage({
1828
- role: import_runtime_client_gql.Role.User,
1906
+ new import_runtime_client_gql2.TextMessage({
1907
+ role: import_runtime_client_gql2.Role.User,
1829
1908
  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>`
1830
1909
  }),
1831
- new import_runtime_client_gql.TextMessage({
1832
- role: import_runtime_client_gql.Role.Assistant,
1910
+ new import_runtime_client_gql2.TextMessage({
1911
+ role: import_runtime_client_gql2.Role.Assistant,
1833
1912
  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"; `
1834
1913
  })
1835
1914
  ];
@@ -1839,7 +1918,7 @@ var defaultSuggestionsApiConfig = {
1839
1918
  };
1840
1919
 
1841
1920
  // src/types/autosuggestions-config/insertions-api-config.tsx
1842
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1921
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1843
1922
  var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1844
1923
  return `You are a versatile writing assistant helping the user insert new text into their existing work.
1845
1924
 
@@ -1868,36 +1947,36 @@ The conversation will be structured as follows:
1868
1947
  `;
1869
1948
  };
1870
1949
  var defaultInsertionsFewShotMessages = [
1871
- new import_runtime_client_gql2.TextMessage({
1872
- role: import_runtime_client_gql2.Role.User,
1950
+ new import_runtime_client_gql3.TextMessage({
1951
+ role: import_runtime_client_gql3.Role.User,
1873
1952
  content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
1874
1953
  }),
1875
- new import_runtime_client_gql2.TextMessage({
1876
- role: import_runtime_client_gql2.Role.User,
1954
+ new import_runtime_client_gql3.TextMessage({
1955
+ role: import_runtime_client_gql3.Role.User,
1877
1956
  content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
1878
1957
  }),
1879
- new import_runtime_client_gql2.TextMessage({
1880
- role: import_runtime_client_gql2.Role.User,
1958
+ new import_runtime_client_gql3.TextMessage({
1959
+ role: import_runtime_client_gql3.Role.User,
1881
1960
  content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
1882
1961
  }),
1883
- new import_runtime_client_gql2.TextMessage({
1884
- role: import_runtime_client_gql2.Role.Assistant,
1962
+ new import_runtime_client_gql3.TextMessage({
1963
+ role: import_runtime_client_gql3.Role.Assistant,
1885
1964
  content: "When I arrived I went straight to the produce section and picked out a big watermelon."
1886
1965
  }),
1887
- new import_runtime_client_gql2.TextMessage({
1888
- role: import_runtime_client_gql2.Role.User,
1966
+ new import_runtime_client_gql3.TextMessage({
1967
+ role: import_runtime_client_gql3.Role.User,
1889
1968
  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>"
1890
1969
  }),
1891
- new import_runtime_client_gql2.TextMessage({
1892
- role: import_runtime_client_gql2.Role.User,
1970
+ new import_runtime_client_gql3.TextMessage({
1971
+ role: import_runtime_client_gql3.Role.User,
1893
1972
  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>`
1894
1973
  }),
1895
- new import_runtime_client_gql2.TextMessage({
1896
- role: import_runtime_client_gql2.Role.User,
1974
+ new import_runtime_client_gql3.TextMessage({
1975
+ role: import_runtime_client_gql3.Role.User,
1897
1976
  content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
1898
1977
  }),
1899
- new import_runtime_client_gql2.TextMessage({
1900
- role: import_runtime_client_gql2.Role.Assistant,
1978
+ new import_runtime_client_gql3.TextMessage({
1979
+ role: import_runtime_client_gql3.Role.Assistant,
1901
1980
  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"; `
1902
1981
  })
1903
1982
  ];
@@ -1908,7 +1987,7 @@ var defaultInsertionsApiConfig = {
1908
1987
  };
1909
1988
 
1910
1989
  // src/types/autosuggestions-config/editing-api-config.tsx
1911
- var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1990
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
1912
1991
  var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
1913
1992
  return `You are a versatile writing assistant helping the user edit a portion of their text.
1914
1993
 
@@ -1936,44 +2015,44 @@ The conversation will be structured as follows:
1936
2015
  `;
1937
2016
  };
1938
2017
  var defaultEditingFewShotMessages = [
1939
- new import_runtime_client_gql3.TextMessage({
1940
- role: import_runtime_client_gql3.Role.User,
2018
+ new import_runtime_client_gql4.TextMessage({
2019
+ role: import_runtime_client_gql4.Role.User,
1941
2020
  content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
1942
2021
  }),
1943
- new import_runtime_client_gql3.TextMessage({
1944
- role: import_runtime_client_gql3.Role.User,
2022
+ new import_runtime_client_gql4.TextMessage({
2023
+ role: import_runtime_client_gql4.Role.User,
1945
2024
  content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
1946
2025
  }),
1947
- new import_runtime_client_gql3.TextMessage({
1948
- role: import_runtime_client_gql3.Role.User,
2026
+ new import_runtime_client_gql4.TextMessage({
2027
+ role: import_runtime_client_gql4.Role.User,
1949
2028
  content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
1950
2029
  }),
1951
- new import_runtime_client_gql3.TextMessage({
1952
- role: import_runtime_client_gql3.Role.User,
2030
+ new import_runtime_client_gql4.TextMessage({
2031
+ role: import_runtime_client_gql4.Role.User,
1953
2032
  content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
1954
2033
  }),
1955
- new import_runtime_client_gql3.TextMessage({
1956
- role: import_runtime_client_gql3.Role.Assistant,
2034
+ new import_runtime_client_gql4.TextMessage({
2035
+ role: import_runtime_client_gql4.Role.Assistant,
1957
2036
  content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
1958
2037
  }),
1959
- new import_runtime_client_gql3.TextMessage({
1960
- role: import_runtime_client_gql3.Role.User,
2038
+ new import_runtime_client_gql4.TextMessage({
2039
+ role: import_runtime_client_gql4.Role.User,
1961
2040
  content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
1962
2041
  }),
1963
- new import_runtime_client_gql3.TextMessage({
1964
- role: import_runtime_client_gql3.Role.User,
2042
+ new import_runtime_client_gql4.TextMessage({
2043
+ role: import_runtime_client_gql4.Role.User,
1965
2044
  content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
1966
2045
  }),
1967
- new import_runtime_client_gql3.TextMessage({
1968
- role: import_runtime_client_gql3.Role.User,
2046
+ new import_runtime_client_gql4.TextMessage({
2047
+ role: import_runtime_client_gql4.Role.User,
1969
2048
  content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
1970
2049
  }),
1971
- new import_runtime_client_gql3.TextMessage({
1972
- role: import_runtime_client_gql3.Role.User,
2050
+ new import_runtime_client_gql4.TextMessage({
2051
+ role: import_runtime_client_gql4.Role.User,
1973
2052
  content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
1974
2053
  }),
1975
- new import_runtime_client_gql3.TextMessage({
1976
- role: import_runtime_client_gql3.Role.Assistant,
2054
+ new import_runtime_client_gql4.TextMessage({
2055
+ role: import_runtime_client_gql4.Role.Assistant,
1977
2056
  content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
1978
2057
  })
1979
2058
  ];
@@ -1984,18 +2063,207 @@ var defaultEditingApiConfig = {
1984
2063
  };
1985
2064
 
1986
2065
  // src/types/autosuggestions-config/autosuggestions-config.tsx
1987
- var import_react_core3 = require("@copilotkit/react-core");
2066
+ var import_react_core4 = require("@copilotkit/react-core");
1988
2067
  var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
1989
- contextCategories: import_react_core3.defaultCopilotContextCategories,
2068
+ contextCategories: import_react_core4.defaultCopilotContextCategories,
1990
2069
  chatApiConfigs: {
1991
2070
  suggestionsApiConfig: defaultSuggestionsApiConfig,
1992
2071
  insertionApiConfig: defaultInsertionsApiConfig,
1993
2072
  editingApiConfig: defaultEditingApiConfig
1994
2073
  }
1995
2074
  });
2075
+
2076
+ // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2077
+ var import_shared3 = require("@copilotkit/shared");
2078
+ var import_react_core5 = require("@copilotkit/react-core");
2079
+ var import_react14 = require("react");
2080
+ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
2081
+ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2082
+ const runtimeClient = { generateCopilotResponse: (...args) => {
2083
+ } };
2084
+ const { getContextString, copilotApiConfig } = (0, import_react_core5.useCopilotContext)();
2085
+ const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2086
+ function runtimeClientResponseToStringStream(responsePromise) {
2087
+ return __async(this, null, function* () {
2088
+ const messagesStream = runtimeClient.asStream(responsePromise);
2089
+ return new ReadableStream({
2090
+ start(controller) {
2091
+ return __async(this, null, function* () {
2092
+ const reader = messagesStream.getReader();
2093
+ let sentContent = "";
2094
+ while (true) {
2095
+ const { done, value } = yield reader.read();
2096
+ if (done) {
2097
+ break;
2098
+ }
2099
+ const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
2100
+ let newContent = "";
2101
+ for (const message of messages) {
2102
+ if (message.isTextMessage()) {
2103
+ newContent += message.content;
2104
+ }
2105
+ }
2106
+ if (newContent) {
2107
+ const contentToSend = newContent.slice(sentContent.length);
2108
+ controller.enqueue(contentToSend);
2109
+ sentContent += contentToSend;
2110
+ }
2111
+ }
2112
+ controller.close();
2113
+ });
2114
+ }
2115
+ });
2116
+ });
2117
+ }
2118
+ const insertionFunction = (0, import_react14.useCallback)(
2119
+ (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2120
+ const res = yield retry(() => __async(this, null, function* () {
2121
+ const messages = [
2122
+ new import_runtime_client_gql5.TextMessage({
2123
+ role: import_runtime_client_gql5.Role.System,
2124
+ content: insertionApiConfig.makeSystemPrompt(
2125
+ textareaPurpose,
2126
+ getContextString(documents, contextCategories)
2127
+ )
2128
+ }),
2129
+ ...insertionApiConfig.fewShotMessages,
2130
+ new import_runtime_client_gql5.TextMessage({
2131
+ role: import_runtime_client_gql5.Role.User,
2132
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2133
+ }),
2134
+ new import_runtime_client_gql5.TextMessage({
2135
+ role: import_runtime_client_gql5.Role.User,
2136
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2137
+ }),
2138
+ new import_runtime_client_gql5.TextMessage({
2139
+ role: import_runtime_client_gql5.Role.User,
2140
+ content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
2141
+ })
2142
+ ];
2143
+ return runtimeClientResponseToStringStream(
2144
+ runtimeClient.generateCopilotResponse({
2145
+ data: {
2146
+ frontend: {
2147
+ actions: [],
2148
+ url: window.location.href
2149
+ },
2150
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
2151
+ metadata: {
2152
+ requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
2153
+ }
2154
+ },
2155
+ properties: copilotApiConfig.properties,
2156
+ signal: abortSignal
2157
+ })
2158
+ );
2159
+ }));
2160
+ return res;
2161
+ }),
2162
+ [insertionApiConfig, getContextString, contextCategories, textareaPurpose]
2163
+ );
2164
+ const editingFunction = (0, import_react14.useCallback)(
2165
+ (editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
2166
+ const res = yield retry(() => __async(this, null, function* () {
2167
+ const messages = [
2168
+ new import_runtime_client_gql5.TextMessage({
2169
+ role: import_runtime_client_gql5.Role.System,
2170
+ content: editingApiConfig.makeSystemPrompt(
2171
+ textareaPurpose,
2172
+ getContextString(documents, contextCategories)
2173
+ )
2174
+ }),
2175
+ ...editingApiConfig.fewShotMessages,
2176
+ new import_runtime_client_gql5.TextMessage({
2177
+ role: import_runtime_client_gql5.Role.User,
2178
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2179
+ }),
2180
+ new import_runtime_client_gql5.TextMessage({
2181
+ role: import_runtime_client_gql5.Role.User,
2182
+ content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
2183
+ }),
2184
+ new import_runtime_client_gql5.TextMessage({
2185
+ role: import_runtime_client_gql5.Role.User,
2186
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2187
+ }),
2188
+ new import_runtime_client_gql5.TextMessage({
2189
+ role: import_runtime_client_gql5.Role.User,
2190
+ content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
2191
+ })
2192
+ ];
2193
+ return runtimeClientResponseToStringStream(
2194
+ runtimeClient.generateCopilotResponse({
2195
+ data: {
2196
+ frontend: {
2197
+ actions: [],
2198
+ url: window.location.href
2199
+ },
2200
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
2201
+ metadata: {
2202
+ requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
2203
+ }
2204
+ },
2205
+ properties: copilotApiConfig.properties,
2206
+ signal: abortSignal
2207
+ })
2208
+ );
2209
+ }));
2210
+ return res;
2211
+ }),
2212
+ [editingApiConfig, getContextString, contextCategories, textareaPurpose]
2213
+ );
2214
+ const insertionOrEditingFunction = (0, import_react14.useCallback)(
2215
+ (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2216
+ if (editorState2.selectedText === "") {
2217
+ return yield insertionFunction(editorState2, insertionPrompt, documents, abortSignal);
2218
+ } else {
2219
+ return yield editingFunction(editorState2, insertionPrompt, documents, abortSignal);
2220
+ }
2221
+ }),
2222
+ [insertionFunction, editingFunction]
2223
+ );
2224
+ return insertionOrEditingFunction;
2225
+ }
2226
+
2227
+ // src/components/copilot-textarea/copilot-textarea.tsx
2228
+ var import_lodash = __toESM(require("lodash.merge"));
2229
+ var import_jsx_runtime15 = require("react/jsx-runtime");
2230
+ var CopilotTextarea = import_react15.default.forwardRef(
2231
+ (props, ref) => {
2232
+ const _a = props, { autosuggestionsConfig: autosuggestionsConfigUserSpecified } = _a, forwardedProps = __objRest(_a, ["autosuggestionsConfig"]);
2233
+ const autosuggestionsConfig = (0, import_lodash.default)(
2234
+ defaultAutosuggestionsConfig,
2235
+ autosuggestionsConfigUserSpecified
2236
+ );
2237
+ const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
2238
+ autosuggestionsConfig.textareaPurpose,
2239
+ autosuggestionsConfig.contextCategories,
2240
+ autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
2241
+ );
2242
+ const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
2243
+ autosuggestionsConfig.textareaPurpose,
2244
+ autosuggestionsConfig.contextCategories,
2245
+ autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
2246
+ autosuggestionsConfig.chatApiConfigs.editingApiConfig
2247
+ );
2248
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2249
+ BaseCopilotTextarea,
2250
+ __spreadProps(__spreadValues({
2251
+ ref
2252
+ }, forwardedProps), {
2253
+ baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
2254
+ apiConfig: {
2255
+ insertionOrEditingFunction,
2256
+ autosuggestionsFunction
2257
+ }
2258
+ })
2259
+ })
2260
+ ) });
2261
+ }
2262
+ );
1996
2263
  // Annotate the CommonJS export names for ESM import in node:
1997
2264
  0 && (module.exports = {
1998
2265
  BaseCopilotTextarea,
2266
+ CopilotTextarea,
1999
2267
  defaultAutosuggestionsConfig,
2000
2268
  defaultBaseAutosuggestionsConfig
2001
2269
  });