@copilotkit/react-textarea 1.10.7-next.0 → 1.50.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 (95) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/dist/{chunk-HDBI2WN5.mjs → chunk-2IWVZ4PP.mjs} +17 -27
  3. package/dist/chunk-2IWVZ4PP.mjs.map +1 -0
  4. package/dist/{chunk-XW3ICO4S.mjs → chunk-3QJOFG3V.mjs} +1 -1
  5. package/dist/chunk-3QJOFG3V.mjs.map +1 -0
  6. package/dist/{chunk-HBWBHJ64.mjs → chunk-4VCJHANC.mjs} +9 -9
  7. package/dist/{chunk-7WVURIB7.mjs → chunk-5NZNJCP2.mjs} +21 -21
  8. package/dist/{chunk-2DF2AVDU.mjs → chunk-66KFI242.mjs} +2 -2
  9. package/dist/{chunk-C3PMJNQA.mjs → chunk-7VADGLV2.mjs} +6 -6
  10. package/dist/{chunk-RXV67GJN.mjs → chunk-DL3JWL2E.mjs} +4 -2
  11. package/dist/chunk-DL3JWL2E.mjs.map +1 -0
  12. package/dist/{chunk-7L6GIHDM.mjs → chunk-F2ULK22F.mjs} +1 -1
  13. package/dist/chunk-F2ULK22F.mjs.map +1 -0
  14. package/dist/{chunk-6SGWO63I.mjs → chunk-ISKK3RIW.mjs} +4 -4
  15. package/dist/chunk-JD7BAH7U.mjs +1 -0
  16. package/dist/{chunk-LQ2OWQU7.mjs → chunk-JLOABKLH.mjs} +2 -2
  17. package/dist/{chunk-LQ2OWQU7.mjs.map → chunk-JLOABKLH.mjs.map} +1 -1
  18. package/dist/{chunk-3PQ7GSFE.mjs → chunk-NAFNY4FL.mjs} +1 -1
  19. package/dist/chunk-NAFNY4FL.mjs.map +1 -0
  20. package/dist/{chunk-F6GMWOLE.mjs → chunk-ZQSEYPNN.mjs} +6 -25
  21. package/dist/chunk-ZQSEYPNN.mjs.map +1 -0
  22. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +17 -27
  23. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  24. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +21 -21
  25. package/dist/components/base-copilot-textarea/render-element.d.ts +3 -2
  26. package/dist/components/base-copilot-textarea/render-element.js.map +1 -1
  27. package/dist/components/base-copilot-textarea/render-element.mjs +1 -1
  28. package/dist/components/base-copilot-textarea/render-placeholder.d.ts +3 -2
  29. package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -1
  30. package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
  31. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +1 -1
  32. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -1
  33. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +1 -1
  34. package/dist/components/copilot-textarea/copilot-textarea.js +24 -48
  35. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  36. package/dist/components/copilot-textarea/copilot-textarea.mjs +75 -28
  37. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  38. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +1 -1
  39. package/dist/components/hovering-toolbar/hovering-toolbar-components.js +16 -26
  40. package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -1
  41. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +1 -1
  42. package/dist/components/hovering-toolbar/hovering-toolbar.js +16 -26
  43. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  44. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +8 -8
  45. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
  46. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +5 -5
  47. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
  48. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +6 -6
  49. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
  50. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +6 -6
  51. package/dist/components/index.d.ts +2 -11
  52. package/dist/components/index.js +25 -531
  53. package/dist/components/index.js.map +1 -1
  54. package/dist/components/index.mjs +23 -35
  55. package/dist/components/ui/command.d.ts +1 -1
  56. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +4 -20
  57. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  58. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  59. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +3 -1
  60. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  61. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  62. package/dist/hooks/misc/use-autosize-textarea.d.ts +1 -1
  63. package/dist/hooks/misc/use-autosize-textarea.js.map +1 -1
  64. package/dist/hooks/misc/use-autosize-textarea.mjs +1 -1
  65. package/dist/index.d.ts +0 -1
  66. package/dist/index.js +76 -368
  67. package/dist/index.js.map +1 -1
  68. package/dist/index.mjs +27 -34
  69. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
  70. package/dist/types/autosuggestions-config/index.mjs +2 -2
  71. package/dist/types/index.mjs +3 -3
  72. package/package.json +22 -22
  73. package/src/components/base-copilot-textarea/render-element.tsx +2 -1
  74. package/src/components/base-copilot-textarea/render-placeholder.tsx +2 -1
  75. package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +1 -1
  76. package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +28 -40
  77. package/src/components/index.ts +0 -3
  78. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +24 -22
  79. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +2 -1
  80. package/src/hooks/misc/use-autosize-textarea.tsx +1 -1
  81. package/dist/chunk-3PQ7GSFE.mjs.map +0 -1
  82. package/dist/chunk-7L6GIHDM.mjs.map +0 -1
  83. package/dist/chunk-F6GMWOLE.mjs.map +0 -1
  84. package/dist/chunk-HDBI2WN5.mjs.map +0 -1
  85. package/dist/chunk-MMVDU6DF.mjs +0 -1
  86. package/dist/chunk-NZIHZWRU.mjs +0 -60
  87. package/dist/chunk-NZIHZWRU.mjs.map +0 -1
  88. package/dist/chunk-RXV67GJN.mjs.map +0 -1
  89. package/dist/chunk-XW3ICO4S.mjs.map +0 -1
  90. /package/dist/{chunk-HBWBHJ64.mjs.map → chunk-4VCJHANC.mjs.map} +0 -0
  91. /package/dist/{chunk-7WVURIB7.mjs.map → chunk-5NZNJCP2.mjs.map} +0 -0
  92. /package/dist/{chunk-2DF2AVDU.mjs.map → chunk-66KFI242.mjs.map} +0 -0
  93. /package/dist/{chunk-C3PMJNQA.mjs.map → chunk-7VADGLV2.mjs.map} +0 -0
  94. /package/dist/{chunk-6SGWO63I.mjs.map → chunk-ISKK3RIW.mjs.map} +0 -0
  95. /package/dist/{chunk-MMVDU6DF.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
@@ -79,8 +79,7 @@ var __async = (__this, __arguments, generator) => {
79
79
  // src/components/index.ts
80
80
  var components_exports = {};
81
81
  __export(components_exports, {
82
- BaseCopilotTextarea: () => BaseCopilotTextarea,
83
- CopilotTextarea: () => CopilotTextarea
82
+ BaseCopilotTextarea: () => BaseCopilotTextarea
84
83
  });
85
84
  module.exports = __toCommonJS(components_exports);
86
85
 
@@ -282,21 +281,21 @@ var withPartialHistory = (editor, shouldSave2) => {
282
281
  const lastBatch = undos[undos.length - 1];
283
282
  const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
284
283
  let save = import_slate_history.HistoryEditor.isSaving(e);
285
- let merge2 = import_slate_history.HistoryEditor.isMerging(e);
284
+ let merge = import_slate_history.HistoryEditor.isMerging(e);
286
285
  if (save == null) {
287
286
  save = shouldSave2(op, lastOp);
288
287
  }
289
288
  if (save) {
290
- if (merge2 == null) {
289
+ if (merge == null) {
291
290
  if (lastBatch == null) {
292
- merge2 = false;
291
+ merge = false;
293
292
  } else if (operations.length !== 0) {
294
- merge2 = true;
293
+ merge = true;
295
294
  } else {
296
- merge2 = shouldMerge(op, lastOp);
295
+ merge = shouldMerge(op, lastOp);
297
296
  }
298
297
  }
299
- if (lastBatch && merge2) {
298
+ if (lastBatch && merge) {
300
299
  lastBatch.operations.push(op);
301
300
  } else {
302
301
  const batch = {
@@ -680,32 +679,22 @@ var import_css = require("@emotion/css");
680
679
  var import_react5 = __toESM(require("react"));
681
680
  var import_react_dom = __toESM(require("react-dom"));
682
681
  var import_jsx_runtime2 = require("react/jsx-runtime");
683
- var Button = import_react5.default.forwardRef(
684
- (_a, ref) => {
685
- var _b = _a, {
686
- className,
687
- active,
688
- reversed
689
- } = _b, props = __objRest(_b, [
690
- "className",
691
- "active",
692
- "reversed"
693
- ]);
694
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
695
- "span",
696
- __spreadProps(__spreadValues({}, props), {
697
- ref,
698
- className: (0, import_css.cx)(
699
- className,
700
- import_css.css`
701
- cursor: pointer;
702
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
703
- `
704
- )
705
- })
706
- );
707
- }
708
- );
682
+ var Button = import_react5.default.forwardRef((_a, ref) => {
683
+ var _b = _a, { className, active, reversed } = _b, props = __objRest(_b, ["className", "active", "reversed"]);
684
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
685
+ "span",
686
+ __spreadProps(__spreadValues({}, props), {
687
+ ref,
688
+ className: (0, import_css.cx)(
689
+ className,
690
+ import_css.css`
691
+ cursor: pointer;
692
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
693
+ `
694
+ )
695
+ })
696
+ );
697
+ });
709
698
  var Icon = import_react5.default.forwardRef(
710
699
  (_a, ref) => {
711
700
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
@@ -1570,7 +1559,7 @@ var isSelectionEqual = (a, b) => {
1570
1559
  return import_slate9.Range.equals(a, b);
1571
1560
  };
1572
1561
  function usePrevious(value) {
1573
- const ref = (0, import_react11.useRef)();
1562
+ const ref = (0, import_react11.useRef)(void 0);
1574
1563
  (0, import_react11.useEffect)(() => {
1575
1564
  ref.current = value;
1576
1565
  });
@@ -1787,503 +1776,8 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
1787
1776
  }
1788
1777
  };
1789
1778
  }
1790
-
1791
- // src/components/copilot-textarea/copilot-textarea.tsx
1792
- var import_react15 = __toESM(require("react"));
1793
-
1794
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1795
- var import_shared2 = require("@copilotkit/shared");
1796
- var import_react_core3 = require("@copilotkit/react-core");
1797
- var import_react13 = require("react");
1798
-
1799
- // src/lib/retry.tsx
1800
- function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
1801
- return new Promise((resolve, reject) => {
1802
- fn().then(resolve).catch((error) => {
1803
- if (retriesLeft === 1) {
1804
- reject(error);
1805
- return;
1806
- }
1807
- setTimeout(() => {
1808
- retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
1809
- }, interval);
1810
- });
1811
- });
1812
- }
1813
-
1814
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1815
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1816
- function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
1817
- const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core3.useCopilotContext)();
1818
- const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
1819
- const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1820
- const { maxTokens, stop, temperature = 0 } = apiConfig;
1821
- return (0, import_react13.useCallback)(
1822
- (editorState2, abortSignal) => __async(this, null, function* () {
1823
- const res = yield retry(() => __async(this, null, function* () {
1824
- var _a, _b, _c;
1825
- const messages = [
1826
- new import_runtime_client_gql.TextMessage({
1827
- role: import_runtime_client_gql.Role.System,
1828
- content: apiConfig.makeSystemPrompt(
1829
- textareaPurpose,
1830
- getContextString([], contextCategories)
1831
- )
1832
- }),
1833
- ...apiConfig.fewShotMessages,
1834
- editorState2.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
1835
- role: import_runtime_client_gql.Role.User,
1836
- content: editorState2.textAfterCursor
1837
- }) : null,
1838
- new import_runtime_client_gql.TextMessage({
1839
- role: import_runtime_client_gql.Role.User,
1840
- content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
1841
- }),
1842
- new import_runtime_client_gql.TextMessage({
1843
- role: import_runtime_client_gql.Role.User,
1844
- content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
1845
- })
1846
- ].filter(Boolean);
1847
- const response = yield runtimeClient.generateCopilotResponse({
1848
- data: {
1849
- frontend: {
1850
- actions: [],
1851
- url: window.location.href
1852
- },
1853
- messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)((0, import_runtime_client_gql.filterAgentStateMessages)(messages)),
1854
- metadata: {
1855
- requestType: import_runtime_client_gql.CopilotRequestType.TextareaCompletion
1856
- },
1857
- forwardedParameters: {
1858
- maxTokens,
1859
- stop,
1860
- temperature
1861
- }
1862
- },
1863
- properties,
1864
- signal: abortSignal
1865
- }).toPromise();
1866
- let result = "";
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) {
1871
- break;
1872
- }
1873
- if (message.isTextMessage()) {
1874
- result += message.content;
1875
- }
1876
- }
1877
- return result;
1878
- }));
1879
- return res;
1880
- }),
1881
- [apiConfig, getContextString, contextCategories, textareaPurpose]
1882
- );
1883
- }
1884
-
1885
- // src/types/autosuggestions-config/suggestions-api-config.tsx
1886
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1887
- var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1888
- return `You are a versatile writing assistant.
1889
-
1890
- The user is writing some text.
1891
- The purpose is: "${textareaPurpose}"
1892
-
1893
- Your job is to guess what the user will write next AS BEST YOU CAN.
1894
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
1895
-
1896
- Adjust yourself to the user's style and implied intent.
1897
-
1898
- The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
1899
- <TextAfterCursor>
1900
- <TextBeforeCursor>
1901
- <YourSuggestion>
1902
-
1903
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
1904
- Refrain from adding <YourSuggestion> tags when responding
1905
-
1906
- The following external context is also provided. Use it to help you make better suggestions!!!
1907
- \`\`\`
1908
- ${contextString}
1909
- \`\`\`
1910
- `;
1911
- };
1912
- var defaultSuggestionsFewShotMessages = [
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,
1919
- content: "This morning I woke up and went straight to the grocery store."
1920
- }),
1921
- new import_runtime_client_gql2.TextMessage({
1922
- role: import_runtime_client_gql2.Role.Assistant,
1923
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
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,
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"; `
1936
- })
1937
- ];
1938
- var defaultSuggestionsApiConfig = {
1939
- makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
1940
- fewShotMessages: defaultSuggestionsFewShotMessages
1941
- };
1942
-
1943
- // src/types/autosuggestions-config/insertions-api-config.tsx
1944
- var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1945
- var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1946
- return `You are a versatile writing assistant helping the user insert new text into their existing work.
1947
-
1948
- The user is writing some text.
1949
- The purpose is: "${textareaPurpose}"
1950
-
1951
- The following external context is also provided. Use it to inform your suggestions when relevant!!!
1952
- \`\`\`
1953
- ${contextString}
1954
- \`\`\`
1955
-
1956
- The user will provide you with a prompt for an INSERTION into the text they are writing.
1957
- Your job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.
1958
- Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
1959
-
1960
- Adjust yourself to the user's style and implied intent.
1961
-
1962
-
1963
- The user will provide the text before and after the cursor, as well as the INSERTION prompt. You should use this to infer the best relevant insertion.
1964
- The conversation will be structured as follows:
1965
- <TextAfterCursor>
1966
- <TextBeforeCursor>
1967
- <InsertionPrompt>
1968
-
1969
- <YourInsertionSuggestion>
1970
- `;
1971
- };
1972
- var defaultInsertionsFewShotMessages = [
1973
- new import_runtime_client_gql3.TextMessage({
1974
- role: import_runtime_client_gql3.Role.User,
1975
- content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
1976
- }),
1977
- new import_runtime_client_gql3.TextMessage({
1978
- role: import_runtime_client_gql3.Role.User,
1979
- content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
1980
- }),
1981
- new import_runtime_client_gql3.TextMessage({
1982
- role: import_runtime_client_gql3.Role.User,
1983
- content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
1984
- }),
1985
- new import_runtime_client_gql3.TextMessage({
1986
- role: import_runtime_client_gql3.Role.Assistant,
1987
- content: "When I arrived I went straight to the produce section and picked out a big watermelon."
1988
- }),
1989
- new import_runtime_client_gql3.TextMessage({
1990
- role: import_runtime_client_gql3.Role.User,
1991
- 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>"
1992
- }),
1993
- new import_runtime_client_gql3.TextMessage({
1994
- role: import_runtime_client_gql3.Role.User,
1995
- 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>`
1996
- }),
1997
- new import_runtime_client_gql3.TextMessage({
1998
- role: import_runtime_client_gql3.Role.User,
1999
- content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
2000
- }),
2001
- new import_runtime_client_gql3.TextMessage({
2002
- role: import_runtime_client_gql3.Role.Assistant,
2003
- 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"; `
2004
- })
2005
- ];
2006
- var defaultInsertionsApiConfig = {
2007
- makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
2008
- fewShotMessages: defaultInsertionsFewShotMessages,
2009
- forwardedParams: void 0
2010
- };
2011
-
2012
- // src/types/autosuggestions-config/editing-api-config.tsx
2013
- var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
2014
- var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
2015
- return `You are a versatile writing assistant helping the user edit a portion of their text.
2016
-
2017
- The user is writing some text.
2018
- The purpose is: "${textareaPurpose}"
2019
-
2020
- The following external context is also provided. Use it when relevant.
2021
- \`\`\`
2022
- ${contextString}
2023
- \`\`\`
2024
-
2025
- The user has provided you with a PROMPT for EDITING a PORTION of the text.
2026
- Your job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.
2027
- Only rewrite the portion of the text that the user has marked as "TextToEdit"!!!
2028
-
2029
- Adjust yourself to the user's style and implied intent.
2030
-
2031
- The conversation will be structured as follows:
2032
- <TextBeforeCursor>
2033
- <TextToEdit>
2034
- <TextAfterCursor>
2035
- <EditingPrompt>
2036
-
2037
- <YourEditSuggestion>
2038
- `;
2039
- };
2040
- var defaultEditingFewShotMessages = [
2041
- new import_runtime_client_gql4.TextMessage({
2042
- role: import_runtime_client_gql4.Role.User,
2043
- content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
2044
- }),
2045
- new import_runtime_client_gql4.TextMessage({
2046
- role: import_runtime_client_gql4.Role.User,
2047
- content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
2048
- }),
2049
- new import_runtime_client_gql4.TextMessage({
2050
- role: import_runtime_client_gql4.Role.User,
2051
- content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
2052
- }),
2053
- new import_runtime_client_gql4.TextMessage({
2054
- role: import_runtime_client_gql4.Role.User,
2055
- content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
2056
- }),
2057
- new import_runtime_client_gql4.TextMessage({
2058
- role: import_runtime_client_gql4.Role.Assistant,
2059
- content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
2060
- }),
2061
- new import_runtime_client_gql4.TextMessage({
2062
- role: import_runtime_client_gql4.Role.User,
2063
- content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
2064
- }),
2065
- new import_runtime_client_gql4.TextMessage({
2066
- role: import_runtime_client_gql4.Role.User,
2067
- content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
2068
- }),
2069
- new import_runtime_client_gql4.TextMessage({
2070
- role: import_runtime_client_gql4.Role.User,
2071
- content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
2072
- }),
2073
- new import_runtime_client_gql4.TextMessage({
2074
- role: import_runtime_client_gql4.Role.User,
2075
- content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
2076
- }),
2077
- new import_runtime_client_gql4.TextMessage({
2078
- role: import_runtime_client_gql4.Role.Assistant,
2079
- content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
2080
- })
2081
- ];
2082
- var defaultEditingApiConfig = {
2083
- makeSystemPrompt: defaultEditingMakeSystemPrompt,
2084
- fewShotMessages: defaultEditingFewShotMessages,
2085
- forwardedParams: void 0
2086
- };
2087
-
2088
- // src/types/autosuggestions-config/autosuggestions-config.tsx
2089
- var import_react_core4 = require("@copilotkit/react-core");
2090
- var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
2091
- contextCategories: import_react_core4.defaultCopilotContextCategories,
2092
- chatApiConfigs: {
2093
- suggestionsApiConfig: defaultSuggestionsApiConfig,
2094
- insertionApiConfig: defaultInsertionsApiConfig,
2095
- editingApiConfig: defaultEditingApiConfig
2096
- }
2097
- });
2098
-
2099
- // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2100
- var import_shared3 = require("@copilotkit/shared");
2101
- var import_react_core5 = require("@copilotkit/react-core");
2102
- var import_react14 = require("react");
2103
- var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
2104
- function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2105
- const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core5.useCopilotContext)();
2106
- const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2107
- function runtimeClientResponseToStringStream(responsePromise) {
2108
- return __async(this, null, function* () {
2109
- const messagesStream = runtimeClient.asStream(responsePromise);
2110
- return new ReadableStream({
2111
- start(controller) {
2112
- return __async(this, null, function* () {
2113
- const reader = messagesStream.getReader();
2114
- let sentContent = "";
2115
- while (true) {
2116
- const { done, value } = yield reader.read();
2117
- if (done) {
2118
- break;
2119
- }
2120
- const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
2121
- let newContent = "";
2122
- for (const message of messages) {
2123
- if (message.isTextMessage()) {
2124
- newContent += message.content;
2125
- }
2126
- }
2127
- if (newContent) {
2128
- const contentToSend = newContent.slice(sentContent.length);
2129
- controller.enqueue(contentToSend);
2130
- sentContent += contentToSend;
2131
- }
2132
- }
2133
- controller.close();
2134
- });
2135
- }
2136
- });
2137
- });
2138
- }
2139
- const insertionFunction = (0, import_react14.useCallback)(
2140
- (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2141
- const res = yield retry(() => __async(this, null, function* () {
2142
- const messages = [
2143
- new import_runtime_client_gql5.TextMessage({
2144
- role: import_runtime_client_gql5.Role.System,
2145
- content: insertionApiConfig.makeSystemPrompt(
2146
- textareaPurpose,
2147
- getContextString(documents, contextCategories)
2148
- )
2149
- }),
2150
- ...insertionApiConfig.fewShotMessages,
2151
- new import_runtime_client_gql5.TextMessage({
2152
- role: import_runtime_client_gql5.Role.User,
2153
- content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2154
- }),
2155
- new import_runtime_client_gql5.TextMessage({
2156
- role: import_runtime_client_gql5.Role.User,
2157
- content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2158
- }),
2159
- new import_runtime_client_gql5.TextMessage({
2160
- role: import_runtime_client_gql5.Role.User,
2161
- content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
2162
- })
2163
- ];
2164
- return runtimeClientResponseToStringStream(
2165
- runtimeClient.generateCopilotResponse({
2166
- data: {
2167
- frontend: {
2168
- actions: [],
2169
- url: window.location.href
2170
- },
2171
- messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
2172
- metadata: {
2173
- requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
2174
- }
2175
- },
2176
- properties: copilotApiConfig.properties,
2177
- signal: abortSignal
2178
- })
2179
- );
2180
- }));
2181
- return res;
2182
- }),
2183
- [insertionApiConfig, getContextString, contextCategories, textareaPurpose]
2184
- );
2185
- const editingFunction = (0, import_react14.useCallback)(
2186
- (editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
2187
- const res = yield retry(() => __async(this, null, function* () {
2188
- const messages = [
2189
- new import_runtime_client_gql5.TextMessage({
2190
- role: import_runtime_client_gql5.Role.System,
2191
- content: editingApiConfig.makeSystemPrompt(
2192
- textareaPurpose,
2193
- getContextString(documents, contextCategories)
2194
- )
2195
- }),
2196
- ...editingApiConfig.fewShotMessages,
2197
- new import_runtime_client_gql5.TextMessage({
2198
- role: import_runtime_client_gql5.Role.User,
2199
- content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2200
- }),
2201
- new import_runtime_client_gql5.TextMessage({
2202
- role: import_runtime_client_gql5.Role.User,
2203
- content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
2204
- }),
2205
- new import_runtime_client_gql5.TextMessage({
2206
- role: import_runtime_client_gql5.Role.User,
2207
- content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2208
- }),
2209
- new import_runtime_client_gql5.TextMessage({
2210
- role: import_runtime_client_gql5.Role.User,
2211
- content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
2212
- })
2213
- ];
2214
- return runtimeClientResponseToStringStream(
2215
- runtimeClient.generateCopilotResponse({
2216
- data: {
2217
- frontend: {
2218
- actions: [],
2219
- url: window.location.href
2220
- },
2221
- messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
2222
- metadata: {
2223
- requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
2224
- }
2225
- },
2226
- properties: copilotApiConfig.properties,
2227
- signal: abortSignal
2228
- })
2229
- );
2230
- }));
2231
- return res;
2232
- }),
2233
- [editingApiConfig, getContextString, contextCategories, textareaPurpose]
2234
- );
2235
- const insertionOrEditingFunction = (0, import_react14.useCallback)(
2236
- (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2237
- if (editorState2.selectedText === "") {
2238
- return yield insertionFunction(editorState2, insertionPrompt, documents, abortSignal);
2239
- } else {
2240
- return yield editingFunction(editorState2, insertionPrompt, documents, abortSignal);
2241
- }
2242
- }),
2243
- [insertionFunction, editingFunction]
2244
- );
2245
- return insertionOrEditingFunction;
2246
- }
2247
-
2248
- // src/components/copilot-textarea/copilot-textarea.tsx
2249
- var import_lodash = __toESM(require("lodash.merge"));
2250
- var import_jsx_runtime15 = require("react/jsx-runtime");
2251
- var CopilotTextarea = import_react15.default.forwardRef(
2252
- (props, ref) => {
2253
- const _a = props, { autosuggestionsConfig: autosuggestionsConfigUserSpecified } = _a, forwardedProps = __objRest(_a, ["autosuggestionsConfig"]);
2254
- const autosuggestionsConfig = (0, import_lodash.default)(
2255
- defaultAutosuggestionsConfig,
2256
- autosuggestionsConfigUserSpecified
2257
- );
2258
- const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
2259
- autosuggestionsConfig.textareaPurpose,
2260
- autosuggestionsConfig.contextCategories,
2261
- autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
2262
- );
2263
- const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
2264
- autosuggestionsConfig.textareaPurpose,
2265
- autosuggestionsConfig.contextCategories,
2266
- autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
2267
- autosuggestionsConfig.chatApiConfigs.editingApiConfig
2268
- );
2269
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2270
- BaseCopilotTextarea,
2271
- __spreadProps(__spreadValues({
2272
- ref
2273
- }, forwardedProps), {
2274
- baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
2275
- apiConfig: {
2276
- insertionOrEditingFunction,
2277
- autosuggestionsFunction
2278
- }
2279
- })
2280
- })
2281
- ) });
2282
- }
2283
- );
2284
1779
  // Annotate the CommonJS export names for ESM import in node:
2285
1780
  0 && (module.exports = {
2286
- BaseCopilotTextarea,
2287
- CopilotTextarea
1781
+ BaseCopilotTextarea
2288
1782
  });
2289
1783
  //# sourceMappingURL=index.js.map