@copilotkit/react-textarea 0.27.2-alpha.0 → 0.28.0-alpha.2

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 (189) hide show
  1. package/.turbo/turbo-build.log +293 -144
  2. package/CHANGELOG.md +26 -0
  3. package/dist/{chunk-LQZBI6XD.mjs → chunk-5J3UZV77.mjs} +3 -3
  4. package/dist/chunk-5J3UZV77.mjs.map +1 -0
  5. package/dist/{chunk-YLXEQDMS.mjs → chunk-B6TKVDDY.mjs} +5 -5
  6. package/dist/chunk-B6TKVDDY.mjs.map +1 -0
  7. package/dist/{chunk-HSCZA5TS.mjs → chunk-BBZ7AWOB.mjs} +2 -2
  8. package/dist/chunk-BBZ7AWOB.mjs.map +1 -0
  9. package/dist/{chunk-47L4PLG4.mjs → chunk-LQ2OWQU7.mjs} +1 -1
  10. package/dist/chunk-LQ2OWQU7.mjs.map +1 -0
  11. package/dist/{chunk-XV7MLLXQ.mjs → chunk-LYB4B6MK.mjs} +1 -1
  12. package/dist/chunk-LYB4B6MK.mjs.map +1 -0
  13. package/dist/{chunk-KJNSWCJC.mjs → chunk-QCPS6IYI.mjs} +6 -10
  14. package/dist/chunk-QCPS6IYI.mjs.map +1 -0
  15. package/dist/{chunk-NT3GWKWK.mjs → chunk-RT4UTBH3.mjs} +7 -7
  16. package/dist/chunk-RT4UTBH3.mjs.map +1 -0
  17. package/dist/{chunk-JYWINDWZ.mjs → chunk-SNQEBH5I.mjs} +4 -4
  18. package/dist/{chunk-JYWINDWZ.mjs.map → chunk-SNQEBH5I.mjs.map} +1 -1
  19. package/dist/{chunk-EPBVNDKE.mjs → chunk-SX6NY5FW.mjs} +1 -1
  20. package/dist/chunk-SX6NY5FW.mjs.map +1 -0
  21. package/dist/{chunk-KTTN5H7S.mjs → chunk-VB4VNCIQ.mjs} +6 -4
  22. package/dist/chunk-VB4VNCIQ.mjs.map +1 -0
  23. package/dist/{chunk-OHO4G6DR.mjs → chunk-XW3ICO4S.mjs} +1 -1
  24. package/dist/chunk-XW3ICO4S.mjs.map +1 -0
  25. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1658 -0
  26. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
  27. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -8
  28. package/dist/components/base-copilot-textarea/render-element.js +53 -0
  29. package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
  30. package/dist/components/base-copilot-textarea/render-placeholder.js +51 -0
  31. package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
  32. package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
  33. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +85 -0
  34. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
  35. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +1 -1
  36. package/dist/components/base-copilot-textarea/use-add-branding-css.js +61 -0
  37. package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
  38. package/dist/components/copilot-textarea/copilot-textarea.js +2082 -0
  39. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
  40. package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
  41. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +2 -2
  42. package/dist/components/hovering-toolbar/hovering-editor-provider.js +21 -0
  43. package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
  44. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +1 -1
  45. package/dist/components/hovering-toolbar/hovering-toolbar-components.js +144 -0
  46. package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
  47. package/dist/components/hovering-toolbar/hovering-toolbar.js +842 -0
  48. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
  49. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +5 -5
  50. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +1 -2
  51. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +544 -0
  52. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
  53. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +2 -2
  54. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +1 -2
  55. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +564 -0
  56. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
  57. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +3 -3
  58. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +4 -4
  59. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +122 -0
  60. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
  61. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +1 -1
  62. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +0 -1
  63. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +564 -0
  64. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
  65. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +3 -3
  66. package/dist/components/index.js +2083 -0
  67. package/dist/components/index.js.map +1 -0
  68. package/dist/components/index.mjs +11 -11
  69. package/dist/components/manual-ui/chip-with-icon.d.ts +1 -3
  70. package/dist/components/manual-ui/chip-with-icon.js +16 -0
  71. package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
  72. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  73. package/dist/components/source-search-box/source-search-box.js +213 -0
  74. package/dist/components/source-search-box/source-search-box.js.map +1 -0
  75. package/dist/components/ui/button.js +103 -0
  76. package/dist/components/ui/button.js.map +1 -0
  77. package/dist/components/ui/card.js +124 -0
  78. package/dist/components/ui/card.js.map +1 -0
  79. package/dist/components/ui/command.js +243 -0
  80. package/dist/components/ui/command.js.map +1 -0
  81. package/dist/components/ui/dialog.js +162 -0
  82. package/dist/components/ui/dialog.js.map +1 -0
  83. package/dist/components/ui/label.js +78 -0
  84. package/dist/components/ui/label.js.map +1 -0
  85. package/dist/components/ui/separator.js +86 -0
  86. package/dist/components/ui/separator.js.map +1 -0
  87. package/dist/components/ui/textarea.js +83 -0
  88. package/dist/components/ui/textarea.js.map +1 -0
  89. package/dist/context/index.js +4 -0
  90. package/dist/context/index.js.map +1 -0
  91. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +158 -0
  92. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
  93. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +169 -0
  94. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
  95. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +151 -0
  96. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
  97. package/dist/hooks/index.js +4 -0
  98. package/dist/hooks/index.js.map +1 -0
  99. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +113 -0
  100. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
  101. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  102. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +162 -0
  103. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
  104. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  105. package/dist/hooks/misc/use-autosize-textarea.js +19 -0
  106. package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
  107. package/dist/index.js +2085 -0
  108. package/dist/index.js.map +1 -0
  109. package/dist/index.mjs +11 -11
  110. package/dist/lib/debouncer.js +54 -0
  111. package/dist/lib/debouncer.js.map +1 -0
  112. package/dist/lib/editor-to-text.js +47 -0
  113. package/dist/lib/editor-to-text.js.map +1 -0
  114. package/dist/lib/get-text-around-cursor.js +106 -0
  115. package/dist/lib/get-text-around-cursor.js.map +1 -0
  116. package/dist/lib/retry.js +20 -0
  117. package/dist/lib/retry.js.map +1 -0
  118. package/dist/lib/slatejs-edits/add-autocompletions.js +29 -0
  119. package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
  120. package/dist/lib/slatejs-edits/clear-autocompletions.js +24 -0
  121. package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
  122. package/dist/lib/slatejs-edits/replace-text.js +31 -0
  123. package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
  124. package/dist/lib/slatejs-edits/with-partial-history.js +110 -0
  125. package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
  126. package/dist/lib/stream-promise-flatten.js +50 -0
  127. package/dist/lib/stream-promise-flatten.js.map +1 -0
  128. package/dist/lib/utils.js +73 -0
  129. package/dist/lib/utils.js.map +1 -0
  130. package/dist/lib/utils.test.js +10 -0
  131. package/dist/lib/utils.test.js.map +1 -0
  132. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +4 -0
  133. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
  134. package/dist/types/autosuggestions-config/autosuggestions-config.js +273 -0
  135. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
  136. package/dist/types/autosuggestions-config/editing-api-config.js +90 -0
  137. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
  138. package/dist/types/autosuggestions-config/index.js +273 -0
  139. package/dist/types/autosuggestions-config/index.js.map +1 -0
  140. package/dist/types/autosuggestions-config/insertions-api-config.js +81 -0
  141. package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
  142. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +4 -0
  143. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
  144. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +4 -0
  145. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +1 -0
  146. package/dist/types/autosuggestions-config/suggestions-api-config.js +67 -0
  147. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
  148. package/dist/types/base/autosuggestion-state.js +4 -0
  149. package/dist/types/base/autosuggestion-state.js.map +1 -0
  150. package/dist/types/base/autosuggestions-bare-function.js +4 -0
  151. package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
  152. package/dist/types/base/base-autosuggestions-config.js +30 -0
  153. package/dist/types/base/base-autosuggestions-config.js.map +1 -0
  154. package/dist/types/base/base-copilot-textarea-props.js +4 -0
  155. package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
  156. package/dist/types/base/custom-editor.js +4 -0
  157. package/dist/types/base/custom-editor.js.map +1 -0
  158. package/dist/types/base/editor-autocomplete-state.js +21 -0
  159. package/dist/types/base/editor-autocomplete-state.js.map +1 -0
  160. package/dist/types/base/index.js +30 -0
  161. package/dist/types/base/index.js.map +1 -0
  162. package/dist/types/html-copilot-textarea-element.js +4 -0
  163. package/dist/types/html-copilot-textarea-element.js.map +1 -0
  164. package/dist/types/index.js +274 -0
  165. package/dist/types/index.js.map +1 -0
  166. package/package.json +8 -7
  167. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +2 -3
  168. package/src/components/base-copilot-textarea/render-placeholder.tsx +1 -1
  169. package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +2 -2
  170. package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
  171. package/src/components/hovering-toolbar/hovering-editor-provider.tsx +2 -2
  172. package/src/components/hovering-toolbar/hovering-toolbar.tsx +4 -5
  173. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +10 -5
  174. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +1 -2
  175. package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +4 -4
  176. package/src/components/manual-ui/chip-with-icon.tsx +1 -3
  177. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +10 -11
  178. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +7 -11
  179. package/tsup.config.ts +1 -2
  180. package/dist/chunk-47L4PLG4.mjs.map +0 -1
  181. package/dist/chunk-EPBVNDKE.mjs.map +0 -1
  182. package/dist/chunk-HSCZA5TS.mjs.map +0 -1
  183. package/dist/chunk-KJNSWCJC.mjs.map +0 -1
  184. package/dist/chunk-KTTN5H7S.mjs.map +0 -1
  185. package/dist/chunk-LQZBI6XD.mjs.map +0 -1
  186. package/dist/chunk-NT3GWKWK.mjs.map +0 -1
  187. package/dist/chunk-OHO4G6DR.mjs.map +0 -1
  188. package/dist/chunk-XV7MLLXQ.mjs.map +0 -1
  189. package/dist/chunk-YLXEQDMS.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/base/base-autosuggestions-config.tsx"],"names":[],"mappings":";AACA,SAAS,uCAAuC;AAyDhD,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO,MAAM,SAAS;AACtC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAcO,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,sCAAsC;AAAA,EACtC,sCAAsC;AACxC","sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === \"k\" && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n};\n"]}
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=html-copilot-textarea-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,274 @@
1
+ 'use strict';
2
+
3
+ var reactCore = require('@copilotkit/react-core');
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var defaultShouldToggleHoveringEditorOnKeyPress = (event) => {
25
+ if (event.key === "k" && event.metaKey) {
26
+ return true;
27
+ }
28
+ return false;
29
+ };
30
+ var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
31
+ if (event.key === "Tab") {
32
+ return true;
33
+ }
34
+ return false;
35
+ };
36
+ var defaultBaseAutosuggestionsConfig = {
37
+ debounceTime: 250,
38
+ contextCategories: reactCore.defaultCopilotContextCategories,
39
+ disableWhenEmpty: true,
40
+ disabled: false,
41
+ temporarilyDisableWhenMovingCursorWithoutChangingText: true,
42
+ shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
43
+ shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress
44
+ };
45
+
46
+ // src/types/autosuggestions-config/suggestions-api-config.tsx
47
+ var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
48
+ return `You are a versatile writing assistant.
49
+
50
+ The user is writing some text.
51
+ The purpose is: "${textareaPurpose}"
52
+
53
+ Your job is to guess what the user will write next AS BEST YOU CAN.
54
+ Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
55
+
56
+ Adjust yourself to the user's style and implied intent.
57
+
58
+ 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.
59
+ <TextAfterCursor>
60
+ <TextBeforeCursor>
61
+ <YourSuggestion>
62
+
63
+ If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
64
+
65
+ The following external context is also provided. Use it to help you make better suggestions!!!
66
+ \`\`\`
67
+ ${contextString}
68
+ \`\`\`
69
+ `;
70
+ };
71
+ var defaultSuggestionsFewShotMessages = [
72
+ {
73
+ role: "user",
74
+ name: "TextAfterCursor",
75
+ content: "While I was there I also picked up some apples, oranges, and bananas."
76
+ },
77
+ {
78
+ role: "user",
79
+ content: "This morning I woke up and went straight to the grocery store."
80
+ },
81
+ {
82
+ role: "assistant",
83
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
84
+ },
85
+ {
86
+ role: "user",
87
+ name: "TextAfterCursor",
88
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
89
+ },
90
+ {
91
+ role: "user",
92
+ name: "TextBeforeCursor",
93
+ 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;`
94
+ },
95
+ {
96
+ role: "assistant",
97
+ 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"; `
98
+ }
99
+ ];
100
+ var defaultSuggestionsApiConfig = {
101
+ makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
102
+ fewShotMessages: defaultSuggestionsFewShotMessages,
103
+ forwardedParams: void 0
104
+ };
105
+
106
+ // src/types/autosuggestions-config/insertions-api-config.tsx
107
+ var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
108
+ return `You are a versatile writing assistant helping the user insert new text into their existing work.
109
+
110
+ The user is writing some text.
111
+ The purpose is: "${textareaPurpose}"
112
+
113
+ The following external context is also provided. Use it to inform your suggestions when relevant!!!
114
+ \`\`\`
115
+ ${contextString}
116
+ \`\`\`
117
+
118
+ The user will provide you with a prompt for an INSERTION into the text they are writing.
119
+ Your job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.
120
+ Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
121
+
122
+ Adjust yourself to the user's style and implied intent.
123
+
124
+
125
+ 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.
126
+ The conversation will be structured as follows:
127
+ <TextAfterCursor>
128
+ <TextBeforeCursor>
129
+ <InsertionPrompt>
130
+
131
+ <YourInsertionSuggestion>
132
+ `;
133
+ };
134
+ var defaultInsertionsFewShotMessages = [
135
+ {
136
+ role: "user",
137
+ name: "TextAfterCursor",
138
+ content: "While I was there I also picked up some apples, oranges, and bananas."
139
+ },
140
+ {
141
+ role: "user",
142
+ name: "TextBeforeCursor",
143
+ content: "This morning I woke up and went straight to the grocery store."
144
+ },
145
+ {
146
+ role: "user",
147
+ name: "InsertionPrompt",
148
+ content: "I bought a big watermelon"
149
+ },
150
+ {
151
+ role: "assistant",
152
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
153
+ },
154
+ {
155
+ role: "user",
156
+ name: "TextAfterCursor",
157
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
158
+ },
159
+ {
160
+ role: "user",
161
+ name: "TextBeforeCursor",
162
+ 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;`
163
+ },
164
+ {
165
+ role: "user",
166
+ name: "InsertionPrompt",
167
+ content: "add section about the optionholder's pro rata share"
168
+ },
169
+ {
170
+ role: "assistant",
171
+ 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"; `
172
+ }
173
+ ];
174
+ var defaultInsertionsApiConfig = {
175
+ makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
176
+ fewShotMessages: defaultInsertionsFewShotMessages,
177
+ forwardedParams: void 0
178
+ };
179
+
180
+ // src/types/autosuggestions-config/editing-api-config.tsx
181
+ var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
182
+ return `You are a versatile writing assistant helping the user edit a portion of their text.
183
+
184
+ The user is writing some text.
185
+ The purpose is: "${textareaPurpose}"
186
+
187
+ The following external context is also provided. Use it when relevant.
188
+ \`\`\`
189
+ ${contextString}
190
+ \`\`\`
191
+
192
+ The user has provided you with a PROMPT for EDITING a PORTION of the text.
193
+ Your job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.
194
+ Only rewrite the portion of the text that the user has marked as "TextToEdit"!!!
195
+
196
+ Adjust yourself to the user's style and implied intent.
197
+
198
+ The conversation will be structured as follows:
199
+ <TextBeforeCursor>
200
+ <TextToEdit>
201
+ <TextAfterCursor>
202
+ <EditingPrompt>
203
+
204
+ <YourEditSuggestion>
205
+ `;
206
+ };
207
+ var defaultEditingFewShotMessages = [
208
+ {
209
+ role: "user",
210
+ name: "TextBeforeCursor",
211
+ content: "This morning I woke up and went straight to the grocery store. "
212
+ },
213
+ {
214
+ role: "user",
215
+ name: "TextToEdit",
216
+ content: "While I was there I picked up some apples, oranges, and bananas. "
217
+ },
218
+ {
219
+ role: "user",
220
+ name: "TextAfterCursor",
221
+ content: "The grocery store was having a sale on fruit, so I decided to stock up."
222
+ },
223
+ {
224
+ role: "user",
225
+ name: "EditingPrompt",
226
+ content: "I also bought a big watermelon"
227
+ },
228
+ {
229
+ role: "assistant",
230
+ content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
231
+ },
232
+ {
233
+ role: "user",
234
+ name: "TextBeforeCursor",
235
+ content: "Yesterday, I spent the afternoon working on my new project. "
236
+ },
237
+ {
238
+ role: "user",
239
+ name: "TextToEdit",
240
+ content: "It's quite challenging and requires a lot of focus. "
241
+ },
242
+ {
243
+ role: "user",
244
+ name: "TextAfterCursor",
245
+ content: "I'm really excited about the potential outcomes of this project."
246
+ },
247
+ {
248
+ role: "user",
249
+ name: "EditingPrompt",
250
+ content: "emphasize the complexity and my enthusiasm for the project"
251
+ },
252
+ {
253
+ role: "assistant",
254
+ content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
255
+ }
256
+ ];
257
+ var defaultEditingApiConfig = {
258
+ makeSystemPrompt: defaultEditingMakeSystemPrompt,
259
+ fewShotMessages: defaultEditingFewShotMessages,
260
+ forwardedParams: void 0
261
+ };
262
+ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
263
+ contextCategories: reactCore.defaultCopilotContextCategories,
264
+ chatApiConfigs: {
265
+ suggestionsApiConfig: defaultSuggestionsApiConfig,
266
+ insertionApiConfig: defaultInsertionsApiConfig,
267
+ editingApiConfig: defaultEditingApiConfig
268
+ }
269
+ });
270
+
271
+ exports.defaultAutosuggestionsConfig = defaultAutosuggestionsConfig;
272
+ exports.defaultBaseAutosuggestionsConfig = defaultBaseAutosuggestionsConfig;
273
+ //# sourceMappingURL=out.js.map
274
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/base/base-autosuggestions-config.tsx","../../src/types/autosuggestions-config/suggestions-api-config.tsx","../../src/types/autosuggestions-config/insertions-api-config.tsx","../../src/types/autosuggestions-config/editing-api-config.tsx","../../src/types/autosuggestions-config/autosuggestions-config.tsx"],"names":["defaultCopilotContextCategories"],"mappings":"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","sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === \"k\" && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n};\n","import { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe 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.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n '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;',\n },\n {\n role: \"assistant\",\n content:\n ' (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\"; ',\n },\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user insert new text into their existing work.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to inform your suggestions when relevant!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user will provide you with a prompt for an INSERTION into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.\nOnly insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\n\nThe 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.\nThe conversation will be structured as follows:\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\n\n<YourInsertionSuggestion>\n`;\n};\n\nexport const defaultInsertionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n '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;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (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\"; ',\n },\n];\n\nexport const defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant helping the user edit a portion of their text.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it when relevant.\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user has provided you with a PROMPT for EDITING a PORTION of the text. \nYour job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.\nOnly rewrite the portion of the text that the user has marked as \"TextToEdit\"!!!\n\nAdjust yourself to the user's style and implied intent.\n\nThe conversation will be structured as follows:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store. \",\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: \"While I was there I picked up some apples, oranges, and bananas. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"The grocery store was having a sale on fruit, so I decided to stock up.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"I also bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \"While I was there I picked up some apples, oranges, and bananas, and a big watermelon.\",\n },\n\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"Yesterday, I spent the afternoon working on my new project. \",\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: \"It's quite challenging and requires a lot of focus. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"I'm really excited about the potential outcomes of this project.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"emphasize the complexity and my enthusiasm for the project\",\n },\n {\n role: \"assistant\",\n content:\n \"It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project.\",\n },\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n","import { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../base\";\nimport { SuggestionsApiConfig, defaultSuggestionsApiConfig } from \"./suggestions-api-config\";\nimport { InsertionsApiConfig, defaultInsertionsApiConfig } from \"./insertions-api-config\";\nimport { EditingApiConfig, defaultEditingApiConfig } from \"./editing-api-config\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n// Like the base autosuggestions config, with 2 additional fields:\n// 1. contextCategories: string[] | undefined;\n// 2. instead of apiConfigs, we have chatApiConfigs: a higher-level abstraction that uses a ChatGPT-like API endpoint.\nexport interface AutosuggestionsConfig extends Omit<BaseAutosuggestionsConfig, \"apiConfig\"> {\n contextCategories: string[];\n chatApiConfigs: {\n suggestionsApiConfig: SuggestionsApiConfig;\n insertionApiConfig: InsertionsApiConfig;\n editingApiConfig: EditingApiConfig;\n };\n}\n\nexport const defaultAutosuggestionsConfig: Omit<\n AutosuggestionsConfig,\n \"textareaPurpose\" | \"apiEndpoint\"\n> = {\n ...defaultBaseAutosuggestionsConfig,\n contextCategories: defaultCopilotContextCategories,\n chatApiConfigs: {\n suggestionsApiConfig: defaultSuggestionsApiConfig,\n insertionApiConfig: defaultInsertionsApiConfig,\n editingApiConfig: defaultEditingApiConfig,\n },\n};\n"]}
package/package.json CHANGED
@@ -4,14 +4,14 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.27.2-alpha.0",
7
+ "version": "0.28.0-alpha.2",
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
11
11
  "main": "./dist/index.js",
12
12
  "module": "./dist/index.mjs",
13
13
  "exports": {
14
- ".": "./dist/index.mjs",
14
+ ".": "./dist/index.js",
15
15
  "./styles.css": "./dist/index.css"
16
16
  },
17
17
  "types": "./dist/index.d.ts",
@@ -33,9 +33,9 @@
33
33
  "ts-jest": "^29.1.1",
34
34
  "tsup": "^6.7.0",
35
35
  "typescript": "^5.1.3",
36
- "eslint-config-custom": "0.2.0",
37
- "tsconfig": "0.6.0",
38
- "tailwind-config": "0.1.0"
36
+ "tailwind-config": "0.2.0-alpha.1",
37
+ "tsconfig": "0.7.0-alpha.1",
38
+ "eslint-config-custom": "0.3.0-alpha.1"
39
39
  },
40
40
  "dependencies": {
41
41
  "@emotion/css": "^11.11.2",
@@ -58,10 +58,11 @@
58
58
  "slate-history": "^0.93.0",
59
59
  "slate-react": "^0.98.1",
60
60
  "tailwind-merge": "^1.13.2",
61
- "@copilotkit/react-core": "0.18.0-alpha.0"
61
+ "@copilotkit/react-core": "0.18.0-alpha.2",
62
+ "@copilotkit/shared": "0.2.0-alpha.1"
62
63
  },
63
64
  "scripts": {
64
- "build": "tsup --treeshake",
65
+ "build": "tsup --treeshake --clean",
65
66
  "dev": "tsup --watch --no-splitting",
66
67
  "test": "jest",
67
68
  "check-types": "tsc --noEmit",
@@ -24,7 +24,6 @@ import {
24
24
  HoveringEditorProvider,
25
25
  useHoveringEditorContext,
26
26
  } from "../hovering-toolbar/hovering-editor-provider";
27
- import { EditorAutocompleteState } from "../../types/base/editor-autocomplete-state";
28
27
  import { TrackerTextEditedSinceLastCursorMovement } from "./track-cursor-moved-since-last-text-change";
29
28
 
30
29
  /**
@@ -65,7 +64,7 @@ export interface HTMLCopilotTextAreaElement extends HTMLElement {
65
64
  * for figuring out which contnet to fill in.
66
65
  */
67
66
  export const BaseCopilotTextarea = React.forwardRef(
68
- (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
67
+ (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {
69
68
  return (
70
69
  <HoveringEditorProvider>
71
70
  <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />
@@ -84,7 +83,7 @@ export const BaseCopilotTextarea = React.forwardRef(
84
83
  * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.
85
84
  */
86
85
  const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
87
- (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
86
+ (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {
88
87
  const autosuggestionsConfig: BaseAutosuggestionsConfig = {
89
88
  ...defaultBaseAutosuggestionsConfig,
90
89
  ...props.baseAutosuggestionsConfig,
@@ -1,4 +1,4 @@
1
- import { RenderElementProps, RenderPlaceholderProps } from "slate-react";
1
+ import { RenderPlaceholderProps } from "slate-react";
2
2
 
3
3
  export type RenderPlaceholderFunction = (props: RenderPlaceholderProps) => JSX.Element;
4
4
 
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef } from "react";
1
+ import { useEffect, useRef } from "react";
2
2
  import { BaseSelection } from "slate";
3
3
  import { useSlateSelector } from "slate-react";
4
4
  import { Range } from "slate";
@@ -9,7 +9,7 @@ interface TrackerTextEditedSinceLastCursorMovementProps {
9
9
  }
10
10
  export function TrackerTextEditedSinceLastCursorMovement(
11
11
  props: TrackerTextEditedSinceLastCursorMovementProps,
12
- ): JSX.Element {
12
+ ) {
13
13
  const cursorState: RelevantEditorState = useSlateSelector((state) => ({
14
14
  selection: state.selection,
15
15
  text: editorToText(state),
@@ -23,7 +23,7 @@ export interface CopilotTextareaProps
23
23
  * A copilot textarea that uses the standard autosuggestions function.
24
24
  */
25
25
  export const CopilotTextarea = React.forwardRef(
26
- (props: CopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
26
+ (props: CopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {
27
27
  // separate the AutosuggestionsConfigUserSpecified from the rest of the props
28
28
  const { autosuggestionsConfig: autosuggestionsConfigUserSpecified, ...forwardedProps } = props;
29
29
 
@@ -1,4 +1,4 @@
1
- import React, { createContext, useState, useContext, ReactNode } from "react";
1
+ import { createContext, useState, useContext, ReactNode } from "react";
2
2
 
3
3
  interface HoveringEditorContextProps {
4
4
  isDisplayed: boolean;
@@ -18,7 +18,7 @@ export interface HoveringEditorProviderProps {
18
18
  * A context provider for the hovering editor over the `CopilotTextarea`
19
19
  * (used to edit and insert text into the `CopilotTextarea`).
20
20
  */
21
- export const HoveringEditorProvider: React.FC<HoveringEditorProviderProps> = ({ children }) => {
21
+ export const HoveringEditorProvider = ({ children }: HoveringEditorProviderProps) => {
22
22
  const [isDisplayed, setIsDisplayed] = useState<boolean>(false);
23
23
 
24
24
  return (
@@ -1,9 +1,8 @@
1
- import { css } from "@emotion/css";
2
- import { useEffect, useMemo, useRef, useState } from "react";
3
- import { BaseSelection, Editor, Range, Location, Transforms } from "slate";
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Editor, Location, Transforms } from "slate";
4
3
  import { useSlate, useSlateSelection } from "slate-react";
5
4
  import { HoveringInsertionPromptBox } from "./text-insertion-prompt-box";
6
- import { Button, Icon, Menu, Portal } from "./hovering-toolbar-components";
5
+ import { Menu, Portal } from "./hovering-toolbar-components";
7
6
  import { useHoveringEditorContext } from "./hovering-editor-provider";
8
7
  import {
9
8
  getFullEditorTextWithNewlines,
@@ -20,7 +19,7 @@ export interface HoveringToolbarProps {
20
19
  hoverMenuClassname: string | undefined;
21
20
  }
22
21
 
23
- export const HoveringToolbar: (props: HoveringToolbarProps) => JSX.Element | null = (props) => {
22
+ export const HoveringToolbar = (props: HoveringToolbarProps) => {
24
23
  const ref = useRef<HTMLDivElement>(null);
25
24
  const editor = useSlate();
26
25
  const selection = useSlateSelection();
@@ -1,5 +1,4 @@
1
1
  import useAutosizeTextArea from "../../../hooks/misc/use-autosize-textarea";
2
- import { MinimalChatGPTMessage } from "../../../types";
3
2
  import {
4
3
  EditingEditorState,
5
4
  Generator_InsertionOrEditingSuggestion,
@@ -8,7 +7,7 @@ import { SourceSearchBox } from "../../source-search-box/source-search-box";
8
7
  import { DocumentPointer } from "@copilotkit/react-core";
9
8
  import { Button } from "../../ui/button";
10
9
  import { Label } from "../../ui/label";
11
- import React, { useCallback, useContext, useEffect, useRef, useState } from "react";
10
+ import { useCallback, useContext, useEffect, useRef, useState } from "react";
12
11
 
13
12
  import { streamPromiseFlatten } from "../../../lib/stream-promise-flatten";
14
13
  import { CopilotContext } from "@copilotkit/react-core";
@@ -25,12 +24,12 @@ export interface HoveringInsertionPromptBoxCoreProps {
25
24
  contextCategories: string[];
26
25
  }
27
26
 
28
- export const HoveringInsertionPromptBoxCore: React.FC<HoveringInsertionPromptBoxCoreProps> = ({
27
+ export const HoveringInsertionPromptBoxCore = ({
29
28
  performInsertion,
30
29
  state,
31
30
  insertionOrEditingFunction,
32
31
  contextCategories,
33
- }) => {
32
+ }: HoveringInsertionPromptBoxCoreProps) => {
34
33
  const { getDocumentsContext } = useContext(CopilotContext);
35
34
 
36
35
  const [editSuggestion, setEditSuggestion] = useState<string>("");
@@ -57,7 +56,13 @@ export const HoveringInsertionPromptBoxCore: React.FC<HoveringInsertionPromptBox
57
56
 
58
57
  // initially focus on the adjustment prompt text area
59
58
  useEffect(() => {
60
- adjustmentTextAreaRef.current?.focus();
59
+ // Focus in the next tick, making sure the adjustment prompt text area is rendered
60
+ // TODO: This happens in Safari, but not in Chrome. Need to look further into this,
61
+ // because focus() should not throw IndexSizeError.
62
+ // this fixes https://github.com/CopilotKit/CopilotKit/issues/171
63
+ setTimeout(() => {
64
+ adjustmentTextAreaRef.current?.focus();
65
+ }, 0);
61
66
  }, []);
62
67
 
63
68
  // continuously read the generating suggestion stream and update the edit suggestion
@@ -1,4 +1,3 @@
1
- import React, { useCallback, useState } from "react";
2
1
  import { HoveringInsertionPromptBoxCore } from "./hovering-insertion-prompt-box-core";
3
2
  import {
4
3
  EditingEditorState,
@@ -13,7 +12,7 @@ export interface Props {
13
12
  contextCategories: string[];
14
13
  }
15
14
 
16
- export const HoveringInsertionPromptBox: React.FC<Props> = (props) => {
15
+ export const HoveringInsertionPromptBox = (props: Props) => {
17
16
  return (
18
17
  <div
19
18
  className="flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white"
@@ -9,10 +9,10 @@ export interface IncludedFilesPreviewProps {
9
9
  setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;
10
10
  }
11
11
 
12
- export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({
12
+ export const IncludedFilesPreview = ({
13
13
  includedFiles,
14
14
  setIncludedFiles,
15
- }) => {
15
+ }: IncludedFilesPreviewProps) => {
16
16
  return (
17
17
  <div className="flex flex-col gap-2 mt-2">
18
18
  <Label className="">Included context:</Label>
@@ -33,12 +33,12 @@ export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({
33
33
  );
34
34
  };
35
35
 
36
- export interface FileChipPreviewProp {
36
+ export interface FileChipPreviewProps {
37
37
  filePointer: DocumentPointer;
38
38
  onDelete: () => void;
39
39
  }
40
40
 
41
- export const FileChipPreview: React.FC<FileChipPreviewProp> = ({ filePointer, onDelete }) => {
41
+ export const FileChipPreview = ({ filePointer, onDelete }: FileChipPreviewProps) => {
42
42
  return (
43
43
  <Chip
44
44
  label={filePointer.name}
@@ -1,12 +1,10 @@
1
- import React from "react";
2
-
3
1
  export interface ChipWithIconProps {
4
2
  label: string;
5
3
  onDelete: () => void;
6
4
  iconUrl: string;
7
5
  }
8
6
 
9
- export const ChipWithIcon: React.FC<ChipWithIconProps> = ({ label, onDelete, iconUrl }) => {
7
+ export const ChipWithIcon = ({ label, onDelete, iconUrl }: ChipWithIconProps) => {
10
8
  return (
11
9
  <span className="inline-flex items-center px-3 py-1 rounded-full bg-slate-200 text-sm font-medium text-white">
12
10
  {iconUrl && <img src={iconUrl} alt="icon" className="w-4 h-4 rounded-full mr-2" />}
@@ -1,10 +1,11 @@
1
- import { CopilotContext, Message } from "@copilotkit/react-core";
1
+ import { Message } from "@copilotkit/shared";
2
+ import { CopilotContext } from "@copilotkit/react-core";
2
3
  import { useCallback, useContext } from "react";
3
4
  import { AutosuggestionsBareFunction, MinimalChatGPTMessage } from "../../types";
4
5
  import { retry } from "../../lib/retry";
5
6
  import { InsertionEditorState } from "../../types/base/autosuggestions-bare-function";
6
7
  import { SuggestionsApiConfig } from "../../types/autosuggestions-config/suggestions-api-config";
7
- import { ChatCompletionStream } from "@copilotkit/react-core";
8
+ import { fetchAndDecodeChatCompletionAsText } from "@copilotkit/react-core";
8
9
 
9
10
  /**
10
11
  * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
@@ -50,21 +51,20 @@ export function useMakeStandardAutosuggestionFunction(
50
51
  },
51
52
  ];
52
53
 
53
- const chatCompletionStream = new ChatCompletionStream({
54
- url: copilotApiConfig.chatApiEndpoint,
55
- });
56
-
57
- const stream = await chatCompletionStream.fetch({
54
+ const response = await fetchAndDecodeChatCompletionAsText({
58
55
  messages: messages as Message[],
59
56
  ...apiConfig.forwardedParams,
60
57
  copilotConfig: copilotApiConfig,
61
58
  signal: abortSignal,
62
59
  });
63
60
 
64
- // read the stream:
65
- const reader = stream.getReader();
66
- let result = "";
61
+ if (!response.events) {
62
+ throw new Error("Failed to fetch chat completion");
63
+ }
67
64
 
65
+ const reader = response.events.getReader();
66
+
67
+ let result = "";
68
68
  while (!abortSignal.aborted) {
69
69
  const { done, value } = await reader.read();
70
70
  if (done) {
@@ -72,7 +72,6 @@ export function useMakeStandardAutosuggestionFunction(
72
72
  }
73
73
  result += value;
74
74
  }
75
-
76
75
  return result;
77
76
  });
78
77