@copilotkit/react-textarea 0.26.0-alpha.2 → 0.26.0-alpha.4

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 (223) hide show
  1. package/.turbo/turbo-build.log +189 -185
  2. package/CHANGELOG.md +22 -0
  3. package/dist/chunk-224UKA7C.mjs +33 -0
  4. package/dist/chunk-224UKA7C.mjs.map +1 -0
  5. package/dist/chunk-2C7O2EVM.mjs +27 -0
  6. package/dist/chunk-2C7O2EVM.mjs.map +1 -0
  7. package/dist/chunk-2QDCE7PD.mjs +29 -0
  8. package/dist/chunk-2QDCE7PD.mjs.map +1 -0
  9. package/dist/chunk-3PQ7GSFE.mjs +17 -0
  10. package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
  11. package/dist/chunk-47L4PLG4.mjs +45 -0
  12. package/dist/chunk-47L4PLG4.mjs.map +1 -0
  13. package/dist/chunk-4NHVQZ67.mjs +107 -0
  14. package/dist/chunk-4NHVQZ67.mjs.map +1 -0
  15. package/dist/chunk-5FO6ISW4.mjs +3 -0
  16. package/dist/chunk-5FO6ISW4.mjs.map +1 -0
  17. package/dist/chunk-5UNJXFUO.mjs +29 -0
  18. package/dist/chunk-5UNJXFUO.mjs.map +1 -0
  19. package/dist/chunk-72P3KOHZ.mjs +91 -0
  20. package/dist/chunk-72P3KOHZ.mjs.map +1 -0
  21. package/dist/chunk-7LSRNPNI.mjs +59 -0
  22. package/dist/chunk-7LSRNPNI.mjs.map +1 -0
  23. package/dist/chunk-7SUZ6CXM.mjs +47 -0
  24. package/dist/chunk-7SUZ6CXM.mjs.map +1 -0
  25. package/dist/chunk-DE5K76I2.mjs +3 -0
  26. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  27. package/dist/chunk-DRV2FOHZ.mjs +65 -0
  28. package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
  29. package/dist/chunk-ECR45NSD.mjs +101 -0
  30. package/dist/chunk-ECR45NSD.mjs.map +1 -0
  31. package/dist/chunk-ELEY7HWW.mjs +202 -0
  32. package/dist/chunk-ELEY7HWW.mjs.map +1 -0
  33. package/dist/chunk-EPBVNDKE.mjs +46 -0
  34. package/dist/chunk-EPBVNDKE.mjs.map +1 -0
  35. package/dist/chunk-FJNUPSQK.mjs +72 -0
  36. package/dist/chunk-FJNUPSQK.mjs.map +1 -0
  37. package/dist/chunk-FP2EKU3L.mjs +28 -0
  38. package/dist/chunk-FP2EKU3L.mjs.map +1 -0
  39. package/dist/chunk-FRIYJQCI.mjs +99 -0
  40. package/dist/chunk-FRIYJQCI.mjs.map +1 -0
  41. package/dist/chunk-GQN2HYFJ.mjs +22 -0
  42. package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
  43. package/dist/chunk-H4VKQGVU.mjs +3 -0
  44. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  45. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  46. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  47. package/dist/chunk-JJLQVT7S.mjs +10 -0
  48. package/dist/chunk-JJLQVT7S.mjs.map +1 -0
  49. package/dist/chunk-K5LNB36H.mjs +80 -0
  50. package/dist/chunk-K5LNB36H.mjs.map +1 -0
  51. package/dist/chunk-KDVMG3XF.mjs +63 -0
  52. package/dist/chunk-KDVMG3XF.mjs.map +1 -0
  53. package/dist/chunk-KFQZHRPJ.mjs +19 -0
  54. package/dist/chunk-KFQZHRPJ.mjs.map +1 -0
  55. package/dist/chunk-KNBNKEXR.mjs +27 -0
  56. package/dist/chunk-KNBNKEXR.mjs.map +1 -0
  57. package/dist/chunk-KNQIEOFP.mjs +18 -0
  58. package/dist/chunk-KNQIEOFP.mjs.map +1 -0
  59. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  60. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  61. package/dist/chunk-LP2REBM5.mjs +217 -0
  62. package/dist/chunk-LP2REBM5.mjs.map +1 -0
  63. package/dist/chunk-M2DR4KVB.mjs +33 -0
  64. package/dist/chunk-M2DR4KVB.mjs.map +1 -0
  65. package/dist/chunk-MMVDU6DF.mjs +3 -0
  66. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  67. package/dist/chunk-MRXNTQOX.mjs +55 -0
  68. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  69. package/dist/chunk-MTDBPK5D.mjs +53 -0
  70. package/dist/chunk-MTDBPK5D.mjs.map +1 -0
  71. package/dist/chunk-NRTYAQJE.mjs +46 -0
  72. package/dist/chunk-NRTYAQJE.mjs.map +1 -0
  73. package/dist/chunk-NTLVQENP.mjs +19 -0
  74. package/dist/chunk-NTLVQENP.mjs.map +1 -0
  75. package/dist/chunk-OHO4G6DR.mjs +19 -0
  76. package/dist/chunk-OHO4G6DR.mjs.map +1 -0
  77. package/dist/chunk-P4QVFRLY.mjs +103 -0
  78. package/dist/chunk-P4QVFRLY.mjs.map +1 -0
  79. package/dist/chunk-PTZVE6NC.mjs +94 -0
  80. package/dist/chunk-PTZVE6NC.mjs.map +1 -0
  81. package/dist/chunk-QDFAIRQF.mjs +45 -0
  82. package/dist/chunk-QDFAIRQF.mjs.map +1 -0
  83. package/dist/chunk-RBR32FWA.mjs +74 -0
  84. package/dist/chunk-RBR32FWA.mjs.map +1 -0
  85. package/dist/chunk-T6MTDQZ7.mjs +45 -0
  86. package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
  87. package/dist/chunk-VPEH6V7T.mjs +83 -0
  88. package/dist/chunk-VPEH6V7T.mjs.map +1 -0
  89. package/dist/chunk-WADHCMPK.mjs +3 -0
  90. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  91. package/dist/chunk-WFTAAA7R.mjs +44 -0
  92. package/dist/chunk-WFTAAA7R.mjs.map +1 -0
  93. package/dist/chunk-WJHSY5T6.mjs +3 -0
  94. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  95. package/dist/chunk-WTASPE2W.mjs +105 -0
  96. package/dist/chunk-WTASPE2W.mjs.map +1 -0
  97. package/dist/chunk-XV7MLLXQ.mjs +18 -0
  98. package/dist/chunk-XV7MLLXQ.mjs.map +1 -0
  99. package/dist/chunk-Y473E2ZQ.mjs +112 -0
  100. package/dist/chunk-Y473E2ZQ.mjs.map +1 -0
  101. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +35 -1745
  102. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  103. package/dist/components/base-copilot-textarea/render-element.mjs +3 -51
  104. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -49
  106. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  107. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  108. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  109. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  110. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  111. package/dist/components/copilot-textarea/copilot-textarea.mjs +47 -2202
  112. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  113. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -17
  114. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  115. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -137
  116. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +18 -875
  118. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  119. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +12 -558
  120. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  121. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +13 -581
  122. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  123. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +5 -102
  124. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
  125. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +14 -581
  126. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  127. package/dist/components/index.mjs +48 -2203
  128. package/dist/components/index.mjs.map +1 -1
  129. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  130. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  131. package/dist/components/source-search-box/source-search-box.mjs +6 -211
  132. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  133. package/dist/components/ui/button.mjs +4 -85
  134. package/dist/components/ui/button.mjs.map +1 -1
  135. package/dist/components/ui/card.mjs +7 -53
  136. package/dist/components/ui/card.mjs.map +1 -1
  137. package/dist/components/ui/command.mjs +5 -244
  138. package/dist/components/ui/command.mjs.map +1 -1
  139. package/dist/components/ui/dialog.mjs +4 -144
  140. package/dist/components/ui/dialog.mjs.map +1 -1
  141. package/dist/components/ui/label.mjs +4 -60
  142. package/dist/components/ui/label.mjs.map +1 -1
  143. package/dist/components/ui/separator.mjs +8 -50
  144. package/dist/components/ui/separator.mjs.map +1 -1
  145. package/dist/components/ui/textarea.mjs +7 -48
  146. package/dist/components/ui/textarea.mjs.map +1 -1
  147. package/dist/context/index.mjs +2 -0
  148. package/dist/context/index.mjs.map +1 -1
  149. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -158
  150. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  151. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  152. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  153. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -148
  154. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  155. package/dist/hooks/index.mjs +2 -0
  156. package/dist/hooks/index.mjs.map +1 -1
  157. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -147
  158. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  159. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -193
  160. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  161. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  162. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  163. package/dist/index.mjs +50 -2206
  164. package/dist/index.mjs.map +1 -1
  165. package/dist/lib/debouncer.mjs +3 -51
  166. package/dist/lib/debouncer.mjs.map +1 -1
  167. package/dist/lib/editor-to-text.mjs +3 -43
  168. package/dist/lib/editor-to-text.mjs.map +1 -1
  169. package/dist/lib/get-text-around-cursor.mjs +3 -102
  170. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  171. package/dist/lib/retry.mjs +3 -17
  172. package/dist/lib/retry.mjs.map +1 -1
  173. package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
  174. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  175. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -20
  176. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  177. package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
  178. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  179. package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
  180. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  181. package/dist/lib/stream-promise-flatten.mjs +3 -47
  182. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  183. package/dist/lib/utils.mjs +3 -71
  184. package/dist/lib/utils.mjs.map +1 -1
  185. package/dist/lib/utils.test.mjs +1 -0
  186. package/dist/lib/utils.test.mjs.map +1 -1
  187. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
  188. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  189. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -265
  190. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  191. package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -81
  192. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  193. package/dist/types/autosuggestions-config/index.mjs +10 -327
  194. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  195. package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -75
  196. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  197. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -83
  198. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  199. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
  200. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  201. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
  202. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  203. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
  204. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  205. package/dist/types/base/autosuggestion-state.mjs +2 -0
  206. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  207. package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
  208. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  209. package/dist/types/base/base-autosuggestions-config.mjs +3 -26
  210. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  211. package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
  212. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  213. package/dist/types/base/custom-editor.mjs +2 -0
  214. package/dist/types/base/custom-editor.mjs.map +1 -1
  215. package/dist/types/base/editor-autocomplete-state.mjs +4 -17
  216. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  217. package/dist/types/base/index.mjs +4 -26
  218. package/dist/types/base/index.mjs.map +1 -1
  219. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  220. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  221. package/dist/types/index.mjs +12 -328
  222. package/dist/types/index.mjs.map +1 -1
  223. package/package.json +3 -3
@@ -1,2203 +1,48 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
-
53
- // src/components/copilot-textarea/copilot-textarea.tsx
54
- import React10 from "react";
55
-
56
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
57
- import { CopilotContext } from "@copilotkit/react-core";
58
- import { useCallback, useContext } from "react";
59
-
60
- // src/types/base/base-autosuggestions-config.tsx
61
- import { defaultCopilotContextCategories } from "@copilotkit/react-core";
62
- var defaultShouldToggleHoveringEditorOnKeyPress = (event) => {
63
- if (event.key === "k" && event.metaKey) {
64
- return true;
65
- }
66
- return false;
67
- };
68
- var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
69
- if (event.key === "Tab") {
70
- return true;
71
- }
72
- return false;
73
- };
74
- var defaultBaseAutosuggestionsConfig = {
75
- debounceTime: 250,
76
- contextCategories: defaultCopilotContextCategories,
77
- disableWhenEmpty: true,
78
- disabled: false,
79
- temporarilyDisableWhenMovingCursorWithoutChangingText: true,
80
- shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
81
- shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress
82
- };
83
-
84
- // src/types/autosuggestions-config/suggestions-api-config.tsx
85
- var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
86
- return `You are a versatile writing assistant.
87
-
88
- The user is writing some text.
89
- The purpose is: "${textareaPurpose}"
90
-
91
- Your job is to guess what the user will write next AS BEST YOU CAN.
92
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
93
-
94
- Adjust yourself to the user's style and implied intent.
95
-
96
- 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.
97
- <TextAfterCursor>
98
- <TextBeforeCursor>
99
- <YourSuggestion>
100
-
101
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
102
-
103
- The following external context is also provided. Use it to help you make better suggestions!!!
104
- \`\`\`
105
- ${contextString}
106
- \`\`\`
107
- `;
108
- };
109
- var defaultSuggestionsFewShotMessages = [
110
- {
111
- role: "user",
112
- name: "TextAfterCursor",
113
- content: "While I was there I also picked up some apples, oranges, and bananas."
114
- },
115
- {
116
- role: "user",
117
- content: "This morning I woke up and went straight to the grocery store."
118
- },
119
- {
120
- role: "assistant",
121
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
122
- },
123
- {
124
- role: "user",
125
- name: "TextAfterCursor",
126
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
127
- },
128
- {
129
- role: "user",
130
- name: "TextBeforeCursor",
131
- 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;`
132
- },
133
- {
134
- role: "assistant",
135
- 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"; `
136
- }
137
- ];
138
- var defaultSuggestionsApiConfig = {
139
- makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
140
- fewShotMessages: defaultSuggestionsFewShotMessages,
141
- forwardedParams: void 0
142
- };
143
-
144
- // src/types/autosuggestions-config/insertions-api-config.tsx
145
- var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
146
- return `You are a versatile writing assistant.
147
-
148
- The user is writing some text.
149
- The purpose is: "${textareaPurpose}"
150
-
151
- The following external context is also provided. Use it to help you make better suggestions!!!
152
- \`\`\`
153
- ${contextString}
154
- \`\`\`
155
-
156
- The user also provides you with a prompt for INSERTIONS into the text they are writing.
157
- Your job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.
158
- Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
159
-
160
- Adjust yourself to the user's style and implied intent.
161
-
162
- 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.
163
- <TextAfterCursor>
164
- <TextBeforeCursor>
165
- <InsertionPrompt>
166
- <YourSuggestion>
167
- `;
168
- };
169
- var defaultInsertionsFewShotMessages = [
170
- {
171
- role: "user",
172
- name: "TextAfterCursor",
173
- content: "While I was there I also picked up some apples, oranges, and bananas."
174
- },
175
- {
176
- role: "user",
177
- name: "TextBeforeCursor",
178
- content: "This morning I woke up and went straight to the grocery store."
179
- },
180
- {
181
- role: "user",
182
- name: "InsertionPrompt",
183
- content: "I bought a big watermelon"
184
- },
185
- {
186
- role: "assistant",
187
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
188
- },
189
- {
190
- role: "user",
191
- name: "TextAfterCursor",
192
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
193
- },
194
- {
195
- role: "user",
196
- name: "TextBeforeCursor",
197
- 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;`
198
- },
199
- {
200
- role: "user",
201
- name: "InsertionPrompt",
202
- content: "add section about the optionholder's pro rata share"
203
- },
204
- {
205
- role: "assistant",
206
- 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"; `
207
- }
208
- ];
209
- var defaultInsertionsApiConfig = {
210
- makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
211
- fewShotMessages: defaultInsertionsFewShotMessages,
212
- forwardedParams: void 0
213
- };
214
-
215
- // src/types/autosuggestions-config/editing-api-config.tsx
216
- var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
217
- return `You are a versatile writing assistant.
218
-
219
- The user is writing some text.
220
- The purpose is: "${textareaPurpose}"
221
-
222
- The following external context is also provided. Use it to help you make better suggestions!!!
223
- \`\`\`
224
- ${contextString}
225
- \`\`\`
226
-
227
- The user also provides you with a prompt for EDITING some text they are writing.
228
- Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
229
-
230
- Adjust yourself to the user's style and implied intent.
231
-
232
- The user will provide the following information; use this to infer the best relevant EDIT:
233
- <TextBeforeCursor>
234
- <TextToEdit>
235
- <TextAfterCursor>
236
- <EditingPrompt>
237
-
238
- <YourEditSuggestion>
239
- `;
240
- };
241
- var defaultEditingFewShotMessages = [
242
- {
243
- role: "user",
244
- name: "TextBeforeCursor",
245
- content: "This morning I woke up and went straight to the grocery store. "
246
- },
247
- {
248
- role: "user",
249
- name: "TextToEdit",
250
- content: "While I was there I also picked up some apples, oranges, and bananas. "
251
- },
252
- {
253
- role: "user",
254
- name: "TextAfterCursor",
255
- content: "The grocery store was having a sale on fruit, so I decided to stock up."
256
- },
257
- {
258
- role: "user",
259
- name: "EditingPrompt",
260
- content: "I bought a big watermelon"
261
- },
262
- {
263
- role: "assistant",
264
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
265
- },
266
- {
267
- role: "user",
268
- name: "TextAfterCursor",
269
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
270
- },
271
- {
272
- role: "user",
273
- name: "TextBeforeCursor",
274
- 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;`
275
- },
276
- {
277
- role: "user",
278
- name: "InsertionPrompt",
279
- content: "add section about the optionholder's pro rata share"
280
- },
281
- {
282
- role: "assistant",
283
- 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"; `
284
- }
285
- ];
286
- var defaultEditingApiConfig = {
287
- makeSystemPrompt: defaultEditingMakeSystemPrompt,
288
- fewShotMessages: defaultEditingFewShotMessages,
289
- forwardedParams: void 0
290
- };
291
-
292
- // src/types/autosuggestions-config/autosuggestions-config.tsx
293
- import { defaultCopilotContextCategories as defaultCopilotContextCategories2 } from "@copilotkit/react-core";
294
- var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
295
- contextCategories: defaultCopilotContextCategories2,
296
- chatApiConfigs: {
297
- suggestionsApiConfig: defaultSuggestionsApiConfig,
298
- insertionApiConfig: defaultInsertionsApiConfig,
299
- editingApiConfig: defaultEditingApiConfig
300
- }
301
- });
302
-
303
- // src/types/autosuggestions-config/subtypes/chatlike-api-endpoint.tsx
304
- import { copilotApiConfigExtrapolator } from "@copilotkit/react-core";
305
- var ChatlikeApiEndpoint = class {
306
- constructor(run) {
307
- this.run = run;
308
- }
309
- /**
310
- * Creates a new instance of ChatlikeApiEndpoint with the provided API endpoint.
311
- * @param apiEndpoint The URL of the OpenAI-compatible API endpoint.
312
- * @returns A new instance of ChatlikeApiEndpoint.
313
- */
314
- static fromCopilotApiConfig(copilotApiConfig) {
315
- return new ChatlikeApiEndpoint(
316
- (abortSignal, messages, forwardedProps) => __async(this, null, function* () {
317
- const res = yield fetch(copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint, {
318
- method: "POST",
319
- headers: __spreadValues({}, copilotApiConfig.headers),
320
- body: JSON.stringify(__spreadProps(__spreadValues(__spreadValues({}, forwardedProps), copilotApiConfig.body), {
321
- messages
322
- })),
323
- signal: abortSignal
324
- });
325
- const bodySteram = res.body;
326
- if (!bodySteram) {
327
- throw new Error("The response body is empty.");
328
- }
329
- const stringStream = bodySteram.pipeThrough(new TextDecoderStream());
330
- return stringStream;
331
- })
332
- );
333
- }
334
- /**
335
- * Creates a fully customized instance of ChatlikeApiEndpoint.
336
- * @param run - The implementation of the ChatlikeApiEndpointImpl interface.
337
- * @returns A new instance of ChatlikeApiEndpoint .
338
- */
339
- static custom(run) {
340
- return new ChatlikeApiEndpoint(run);
341
- }
342
- };
343
-
344
- // src/lib/retry.tsx
345
- function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
346
- return new Promise((resolve, reject) => {
347
- fn().then(resolve).catch((error) => {
348
- if (retriesLeft === 1) {
349
- reject(error);
350
- return;
351
- }
352
- setTimeout(() => {
353
- retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
354
- }, interval);
355
- });
356
- });
357
- }
358
-
359
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
360
- function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
361
- const { getContextString, copilotApiConfig } = useContext(CopilotContext);
362
- return useCallback(
363
- (editorState2, abortSignal) => __async(this, null, function* () {
364
- const res = yield retry(() => __async(this, null, function* () {
365
- const messages = [
366
- {
367
- role: "system",
368
- content: apiConfig.makeSystemPrompt(
369
- textareaPurpose,
370
- getContextString([], contextCategories)
371
- )
372
- },
373
- ...apiConfig.fewShotMessages,
374
- {
375
- role: "user",
376
- name: "TextAfterCursor",
377
- content: editorState2.textAfterCursor
378
- },
379
- {
380
- role: "user",
381
- name: "TextBeforeCursor",
382
- content: editorState2.textBeforeCursor
383
- }
384
- ];
385
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
386
- const stream = yield apiEndpoint.run(abortSignal, messages, apiConfig.forwardedParams);
387
- const reader = stream.getReader();
388
- let result = "";
389
- while (true) {
390
- const { done, value } = yield reader.read();
391
- if (done) {
392
- break;
393
- }
394
- result += value;
395
- }
396
- return result;
397
- }));
398
- return res;
399
- }),
400
- [apiConfig, getContextString, contextCategories, textareaPurpose]
401
- );
402
- }
403
-
404
- // src/components/base-copilot-textarea/base-copilot-textarea.tsx
405
- import React9, { useCallback as useCallback4, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
406
- import { Editor as Editor5 } from "slate";
407
- import { Editable, Slate } from "slate-react";
408
- import { twMerge as twMerge2 } from "tailwind-merge";
409
-
410
- // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
411
- import { useCallback as useCallback2, useEffect, useMemo, useState } from "react";
412
-
413
- // src/lib/debouncer.ts
414
- var Debouncer = class {
415
- constructor(wait) {
416
- this.wait = wait;
417
- this.debounce = (func, ...args) => __async(this, null, function* () {
418
- this.cancel();
419
- this.timeoutId = setTimeout(() => __async(this, null, function* () {
420
- try {
421
- this.activeAbortController = new AbortController();
422
- yield func(...args, this.activeAbortController.signal);
423
- this.activeAbortController = void 0;
424
- } catch (error) {
425
- }
426
- }), this.wait);
427
- });
428
- this.cancel = () => {
429
- if (this.activeAbortController) {
430
- this.activeAbortController.abort();
431
- this.activeAbortController = void 0;
432
- }
433
- if (this.timeoutId !== void 0) {
434
- clearTimeout(this.timeoutId);
435
- this.timeoutId = void 0;
436
- }
437
- };
438
- }
439
- };
440
-
441
- // src/lib/utils.ts
442
- import { clsx } from "clsx";
443
- import { customAlphabet } from "nanoid";
444
- import { twMerge } from "tailwind-merge";
445
- function cn(...inputs) {
446
- return twMerge(clsx(inputs));
447
- }
448
- var nanoid = customAlphabet(
449
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
450
- 7
451
- );
452
- var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
453
- function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
454
- if (a === null || a === void 0 || b === null || b === void 0) {
455
- return a === b;
456
- }
457
- return naiveEqualityCheck(a, b);
458
- }
459
-
460
- // src/types/base/editor-autocomplete-state.ts
461
- function areEqual_autocompleteState(prev, next) {
462
- return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
463
- }
464
-
465
- // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
466
- function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
467
- const [previousAutocompleteState, setPreviousAutocompleteState] = useState(null);
468
- const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = useState(null);
469
- const awaitForAndAppendSuggestion = useCallback2(
470
- (editorAutocompleteState, abortSignal) => __async(this, null, function* () {
471
- if (disabled) {
472
- return;
473
- }
474
- if (disableWhenEmpty && editorAutocompleteState.textBeforeCursor === "" && editorAutocompleteState.textAfterCursor === "") {
475
- return;
476
- }
477
- const suggestion = yield autosuggestionFunction(editorAutocompleteState, abortSignal);
478
- if (!suggestion || abortSignal.aborted) {
479
- throw new DOMException("Aborted", "AbortError");
480
- }
481
- setCurrentAutocompleteSuggestion({
482
- text: suggestion,
483
- point: editorAutocompleteState.cursorPoint
484
- });
485
- }),
486
- [autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled]
487
- );
488
- const debouncedFunction = useMemo(
489
- () => new Debouncer(debounceTime),
490
- [debounceTime]
491
- );
492
- useEffect(() => {
493
- return () => {
494
- debouncedFunction.cancel();
495
- setCurrentAutocompleteSuggestion(null);
496
- };
497
- }, [debouncedFunction, disabled]);
498
- const onChange = useCallback2(
499
- (newEditorState) => {
500
- const editorStateHasChanged = !nullableCompatibleEqualityCheck(
501
- areEqual_autocompleteState,
502
- previousAutocompleteState,
503
- newEditorState
504
- );
505
- setPreviousAutocompleteState(newEditorState);
506
- if (!editorStateHasChanged) {
507
- return;
508
- }
509
- setCurrentAutocompleteSuggestion(null);
510
- if (newEditorState) {
511
- debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);
512
- } else {
513
- debouncedFunction.cancel();
514
- }
515
- },
516
- [
517
- previousAutocompleteState,
518
- setPreviousAutocompleteState,
519
- debouncedFunction,
520
- awaitForAndAppendSuggestion,
521
- setCurrentAutocompleteSuggestion
522
- ]
523
- );
524
- const keyDownHandler = useCallback2(
525
- (event) => {
526
- if (currentAutocompleteSuggestion) {
527
- if (shouldAcceptAutosuggestionOnKeyPress(event)) {
528
- event.preventDefault();
529
- insertAutocompleteSuggestion(currentAutocompleteSuggestion);
530
- setCurrentAutocompleteSuggestion(null);
531
- }
532
- }
533
- },
534
- [
535
- currentAutocompleteSuggestion,
536
- setCurrentAutocompleteSuggestion,
537
- insertAutocompleteSuggestion,
538
- shouldAcceptAutosuggestionOnKeyPress
539
- ]
540
- );
541
- return {
542
- currentAutocompleteSuggestion,
543
- onChangeHandler: onChange,
544
- onKeyDownHandler: keyDownHandler
545
- };
546
- }
547
-
548
- // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
549
- import { useMemo as useMemo2 } from "react";
550
- import { createEditor, Element } from "slate";
551
- import { withReact } from "slate-react";
552
-
553
- // src/lib/slatejs-edits/with-partial-history.ts
554
- import { Editor, Operation, Path, Transforms } from "slate";
555
- import { HistoryEditor } from "slate-history";
556
- var withPartialHistory = (editor, shouldSave2) => {
557
- const e = editor;
558
- const { apply } = e;
559
- e.history = { undos: [], redos: [] };
560
- e.redo = () => {
561
- const { history } = e;
562
- const { redos } = history;
563
- if (redos.length > 0) {
564
- const batch = redos[redos.length - 1];
565
- if (batch.selectionBefore) {
566
- Transforms.setSelection(e, batch.selectionBefore);
567
- }
568
- HistoryEditor.withoutSaving(e, () => {
569
- Editor.withoutNormalizing(e, () => {
570
- for (const op of batch.operations) {
571
- e.apply(op);
572
- }
573
- });
574
- });
575
- history.redos.pop();
576
- e.writeHistory("undos", batch);
577
- }
578
- };
579
- e.undo = () => {
580
- const { history } = e;
581
- const { undos } = history;
582
- if (undos.length > 0) {
583
- const batch = undos[undos.length - 1];
584
- HistoryEditor.withoutSaving(e, () => {
585
- Editor.withoutNormalizing(e, () => {
586
- const inverseOps = batch.operations.map(Operation.inverse).reverse();
587
- for (const op of inverseOps) {
588
- e.apply(op);
589
- }
590
- if (batch.selectionBefore) {
591
- Transforms.setSelection(e, batch.selectionBefore);
592
- }
593
- });
594
- });
595
- e.writeHistory("redos", batch);
596
- history.undos.pop();
597
- }
598
- };
599
- e.apply = (op) => {
600
- const { operations, history } = e;
601
- const { undos } = history;
602
- const lastBatch = undos[undos.length - 1];
603
- const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
604
- let save = HistoryEditor.isSaving(e);
605
- let merge2 = HistoryEditor.isMerging(e);
606
- if (save == null) {
607
- save = shouldSave2(op, lastOp);
608
- }
609
- if (save) {
610
- if (merge2 == null) {
611
- if (lastBatch == null) {
612
- merge2 = false;
613
- } else if (operations.length !== 0) {
614
- merge2 = true;
615
- } else {
616
- merge2 = shouldMerge(op, lastOp);
617
- }
618
- }
619
- if (lastBatch && merge2) {
620
- lastBatch.operations.push(op);
621
- } else {
622
- const batch = {
623
- operations: [op],
624
- selectionBefore: e.selection
625
- };
626
- e.writeHistory("undos", batch);
627
- }
628
- while (undos.length > 100) {
629
- undos.shift();
630
- }
631
- history.redos = [];
632
- }
633
- apply(op);
634
- };
635
- e.writeHistory = (stack, batch) => {
636
- e.history[stack].push(batch);
637
- };
638
- return e;
639
- };
640
- var shouldMerge = (op, prev) => {
641
- if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
642
- return true;
643
- }
644
- if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
645
- return true;
646
- }
647
- return false;
648
- };
649
- var defaultShouldSave = (op, prev) => {
650
- if (op.type === "set_selection") {
651
- return false;
652
- }
653
- return true;
654
- };
655
-
656
- // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
657
- var shouldSave = (op, prev) => {
658
- const excludedNodeType = "suggestion";
659
- if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
660
- return false;
661
- }
662
- if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
663
- return false;
664
- }
665
- if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
666
- return false;
667
- }
668
- if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
669
- return false;
670
- }
671
- if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
672
- return false;
673
- }
674
- if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
675
- return false;
676
- }
677
- return defaultShouldSave(op, prev);
678
- };
679
- function useCopilotTextareaEditor() {
680
- const editor = useMemo2(() => {
681
- const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
682
- const { isVoid } = editor2;
683
- editor2.isVoid = (element) => {
684
- switch (element.type) {
685
- case "suggestion":
686
- return true;
687
- default:
688
- return isVoid(element);
689
- }
690
- };
691
- const { markableVoid } = editor2;
692
- editor2.markableVoid = (element) => {
693
- switch (element.type) {
694
- case "suggestion":
695
- return true;
696
- default:
697
- return markableVoid(element);
698
- }
699
- };
700
- const { isInline } = editor2;
701
- editor2.isInline = (element) => {
702
- switch (element.type) {
703
- case "suggestion":
704
- return element.inline;
705
- default:
706
- return isInline(element);
707
- }
708
- };
709
- return editor2;
710
- }, []);
711
- return editor;
712
- }
713
-
714
- // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
715
- import React from "react";
716
- import { ReactEditor } from "slate-react";
717
-
718
- // src/lib/get-text-around-cursor.ts
719
- import { Editor as Editor2, Path as Path2, Range as Range2, Text, Element as Element2, Point } from "slate";
720
- function getTextAroundCollapsedCursor(editor) {
721
- const { selection } = editor;
722
- if (!selection || !Range2.isCollapsed(selection)) {
723
- return null;
724
- }
725
- const cursorPoint = selection.anchor;
726
- const beforeRange = {
727
- anchor: Editor2.start(editor, []),
728
- focus: cursorPoint
729
- };
730
- const afterRange = {
731
- anchor: cursorPoint,
732
- focus: Editor2.end(editor, [])
733
- };
734
- const before = extractTextWithNewlines(editor, beforeRange);
735
- const after = extractTextWithNewlines(editor, afterRange);
736
- return {
737
- cursorPoint,
738
- textBeforeCursor: before,
739
- textAfterCursor: after
740
- };
741
- }
742
- function getTextAroundSelection(editor) {
743
- const { selection } = editor;
744
- if (!selection) {
745
- return null;
746
- }
747
- const wellOrderedSelection = wellOrderedRange(selection);
748
- const beforeRange = {
749
- anchor: Editor2.start(editor, []),
750
- focus: wellOrderedSelection.anchor
751
- };
752
- const afterRange = {
753
- anchor: wellOrderedSelection.focus,
754
- focus: Editor2.end(editor, [])
755
- };
756
- const before = extractTextWithNewlines(editor, beforeRange);
757
- const after = extractTextWithNewlines(editor, afterRange);
758
- const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
759
- return {
760
- selection: wellOrderedSelection,
761
- textBeforeCursor: before,
762
- selectedText,
763
- textAfterCursor: after
764
- };
765
- }
766
- function getFullEditorTextWithNewlines(editor) {
767
- const fullDocumentRange = {
768
- anchor: Editor2.start(editor, []),
769
- focus: Editor2.end(editor, [])
770
- };
771
- return extractTextWithNewlines(editor, fullDocumentRange);
772
- }
773
- function extractTextWithNewlines(editor, range) {
774
- const voids = false;
775
- const [start, end] = Range2.edges(range);
776
- let text = "";
777
- let lastBlock = null;
778
- for (const [node, path] of Editor2.nodes(editor, {
779
- at: range,
780
- match: Text.isText,
781
- voids
782
- })) {
783
- let t = node.text;
784
- const [block] = Editor2.above(editor, {
785
- at: path,
786
- match: (n) => Element2.isElement(n) && n.type === "paragraph"
787
- }) || [null];
788
- if (lastBlock !== block && block) {
789
- if (lastBlock) {
790
- text += "\n";
791
- }
792
- lastBlock = block;
793
- }
794
- if (Path2.equals(path, end.path)) {
795
- t = t.slice(0, end.offset);
796
- }
797
- if (Path2.equals(path, start.path)) {
798
- t = t.slice(start.offset);
799
- }
800
- text += t;
801
- }
802
- return text;
803
- }
804
- function wellOrderedRange(range) {
805
- const { anchor, focus } = range;
806
- if (Point.isBefore(anchor, focus)) {
807
- return range;
808
- }
809
- return {
810
- anchor: focus,
811
- focus: anchor
812
- };
813
- }
814
-
815
- // src/lib/slatejs-edits/replace-text.ts
816
- import { Editor as Editor3, Transforms as Transforms2 } from "slate";
817
- function replaceEditorText(editor, newText) {
818
- Transforms2.delete(editor, {
819
- at: {
820
- anchor: Editor3.start(editor, []),
821
- focus: Editor3.end(editor, [])
822
- }
823
- });
824
- if (newText && newText !== "") {
825
- Transforms2.insertNodes(
826
- editor,
827
- [
828
- {
829
- type: "paragraph",
830
- children: [{ text: newText }]
831
- }
832
- ],
833
- {
834
- at: [0]
835
- }
836
- );
837
- }
838
- }
839
-
840
- // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
841
- function usePopulateCopilotTextareaRef(editor, ref) {
842
- React.useImperativeHandle(
843
- ref,
844
- () => {
845
- class Combined {
846
- constructor(customMethods2, editorHtmlElement2) {
847
- this.customMethods = customMethods2;
848
- this.editorHtmlElement = editorHtmlElement2;
849
- }
850
- get(target, propKey) {
851
- if (this.isKeyOfCustomMethods(propKey)) {
852
- const value = this.customMethods[propKey];
853
- if (typeof value === "function") {
854
- return value.bind(this.customMethods);
855
- }
856
- return value;
857
- } else if (this.isKeyOfHTMLElement(propKey)) {
858
- const value = this.editorHtmlElement[propKey];
859
- if (typeof value === "function") {
860
- return value.bind(this.editorHtmlElement);
861
- }
862
- return value;
863
- }
864
- }
865
- set(target, propKey, value) {
866
- if (this.isKeyOfCustomMethods(propKey)) {
867
- this.customMethods[propKey] = value;
868
- } else if (this.isKeyOfHTMLElement(propKey)) {
869
- this.editorHtmlElement[propKey] = value;
870
- } else {
871
- target[propKey] = value;
872
- }
873
- return true;
874
- }
875
- isKeyOfCustomMethods(key) {
876
- return key in this.customMethods;
877
- }
878
- isKeyOfHTMLElement(key) {
879
- return key in this.editorHtmlElement;
880
- }
881
- }
882
- const handler = {
883
- get(target, propKey) {
884
- return target.get(target, propKey);
885
- },
886
- set(target, propKey, value) {
887
- return target.set(target, propKey, value);
888
- }
889
- };
890
- class CustomMethods {
891
- constructor(editor2) {
892
- this.editor = editor2;
893
- }
894
- focus() {
895
- ReactEditor.focus(this.editor);
896
- }
897
- blur() {
898
- ReactEditor.blur(this.editor);
899
- }
900
- get value() {
901
- return getFullEditorTextWithNewlines(this.editor);
902
- }
903
- set value(value) {
904
- replaceEditorText(this.editor, value);
905
- }
906
- }
907
- const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
908
- const customMethods = new CustomMethods(editor);
909
- const combined = new Combined(customMethods, editorHtmlElement);
910
- return new Proxy(combined, handler);
911
- },
912
- [editor]
913
- );
914
- }
915
-
916
- // src/lib/slatejs-edits/add-autocompletions.ts
917
- import { Transforms as Transforms3 } from "slate";
918
- function addAutocompletionsToEditor(editor, newSuggestion, point) {
919
- const editorPosition = editor.selection;
920
- Transforms3.insertNodes(
921
- editor,
922
- [
923
- {
924
- type: "suggestion",
925
- inline: true,
926
- content: newSuggestion,
927
- children: [{ text: "" }]
928
- }
929
- ],
930
- {
931
- at: point
932
- }
933
- );
934
- if (editorPosition) {
935
- editor.selection = editorPosition;
936
- }
937
- }
938
-
939
- // src/lib/slatejs-edits/clear-autocompletions.ts
940
- import { Element as Element3, Node as Node2, Transforms as Transforms4 } from "slate";
941
- function clearAutocompletionsFromEditor(editor) {
942
- const paths = [];
943
- for (const [node, path] of Node2.nodes(editor)) {
944
- if (Element3.isElement(node) && node.type === "suggestion") {
945
- paths.push(path);
946
- }
947
- }
948
- for (const path of paths) {
949
- try {
950
- Transforms4.removeNodes(editor, { at: path });
951
- } catch (e) {
952
- console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
953
- }
954
- }
955
- }
956
-
957
- // src/components/hovering-toolbar/hovering-toolbar.tsx
958
- import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
959
- import { Transforms as Transforms5 } from "slate";
960
- import { useSlate, useSlateSelection } from "slate-react";
961
-
962
- // src/hooks/misc/use-autosize-textarea.tsx
963
- import { useEffect as useEffect2 } from "react";
964
- var useAutosizeTextArea = (textAreaRef, value) => {
965
- useEffect2(() => {
966
- if (textAreaRef.current !== null) {
967
- textAreaRef.current.style.height = "0px";
968
- const scrollHeight = textAreaRef.current.scrollHeight;
969
- textAreaRef.current.style.height = scrollHeight + "px";
970
- }
971
- }, [textAreaRef, value]);
972
- };
973
- var use_autosize_textarea_default = useAutosizeTextArea;
974
-
975
- // src/components/source-search-box/source-search-box.tsx
976
- import { useState as useState2 } from "react";
977
-
978
- // src/components/ui/command.tsx
979
- import * as React2 from "react";
980
- import { Command as CommandPrimitive } from "cmdk";
981
- import { jsx } from "react/jsx-runtime";
982
- var Command = React2.forwardRef((_a, ref) => {
983
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
984
- return /* @__PURE__ */ jsx(
985
- CommandPrimitive,
986
- __spreadValues({
987
- ref,
988
- className: cn(
989
- "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
990
- className
991
- )
992
- }, props)
993
- );
994
- });
995
- Command.displayName = CommandPrimitive.displayName;
996
- var CommandInput = React2.forwardRef((_a, ref) => {
997
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
998
- return /* @__PURE__ */ jsx("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ jsx(
999
- CommandPrimitive.Input,
1000
- __spreadValues({
1001
- ref,
1002
- className: cn(
1003
- "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
1004
- className
1005
- )
1006
- }, props)
1007
- ) });
1008
- });
1009
- CommandInput.displayName = CommandPrimitive.Input.displayName;
1010
- var CommandList = React2.forwardRef((_a, ref) => {
1011
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1012
- return /* @__PURE__ */ jsx(
1013
- CommandPrimitive.List,
1014
- __spreadValues({
1015
- ref,
1016
- className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden pb-2", className)
1017
- }, props)
1018
- );
1019
- });
1020
- CommandList.displayName = CommandPrimitive.List.displayName;
1021
- var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
1022
- CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
1023
- var CommandGroup = React2.forwardRef((_a, ref) => {
1024
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1025
- return /* @__PURE__ */ jsx(
1026
- CommandPrimitive.Group,
1027
- __spreadValues({
1028
- ref,
1029
- className: cn(
1030
- "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
1031
- className
1032
- )
1033
- }, props)
1034
- );
1035
- });
1036
- CommandGroup.displayName = CommandPrimitive.Group.displayName;
1037
- var CommandSeparator = React2.forwardRef((_a, ref) => {
1038
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1039
- return /* @__PURE__ */ jsx(
1040
- CommandPrimitive.Separator,
1041
- __spreadValues({
1042
- ref,
1043
- className: cn("-mx-1 h-px bg-border", className)
1044
- }, props)
1045
- );
1046
- });
1047
- CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
1048
- var CommandItem = React2.forwardRef((_a, ref) => {
1049
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1050
- return /* @__PURE__ */ jsx(
1051
- CommandPrimitive.Item,
1052
- __spreadValues({
1053
- ref,
1054
- className: cn(
1055
- "relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
1056
- className
1057
- )
1058
- }, props)
1059
- );
1060
- });
1061
- CommandItem.displayName = CommandPrimitive.Item.displayName;
1062
- var CommandShortcut = (_a) => {
1063
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1064
- return /* @__PURE__ */ jsx(
1065
- "span",
1066
- __spreadValues({
1067
- className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
1068
- }, props)
1069
- );
1070
- };
1071
- CommandShortcut.displayName = "CommandShortcut";
1072
-
1073
- // src/components/source-search-box/source-search-box.tsx
1074
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1075
- function SourceSearchBox(props) {
1076
- const [selectedValue, setSelectedValue] = useState2("");
1077
- return /* @__PURE__ */ jsxs(
1078
- Command,
1079
- {
1080
- className: "rounded-lg border shadow-md",
1081
- value: selectedValue,
1082
- onValueChange: (value) => {
1083
- setSelectedValue(value);
1084
- },
1085
- filter: (value, search) => {
1086
- if (props.searchTerm === "")
1087
- return 1;
1088
- if (value.startsWith(props.searchTerm))
1089
- return 1;
1090
- return 0;
1091
- },
1092
- children: [
1093
- /* @__PURE__ */ jsx2(
1094
- CommandInput,
1095
- {
1096
- value: props.searchTerm,
1097
- className: "rounded-t-lg hidden",
1098
- placeholder: "Search for a command..."
1099
- }
1100
- ),
1101
- /* @__PURE__ */ jsxs(CommandList, { children: [
1102
- /* @__PURE__ */ jsx2(CommandEmpty, { children: "No results found." }),
1103
- /* @__PURE__ */ jsx2(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
1104
- return /* @__PURE__ */ jsx2(
1105
- CommandItem,
1106
- {
1107
- value: filePointer.name,
1108
- onSelect: (value) => {
1109
- props.onSelectedFile(filePointer);
1110
- },
1111
- children: /* @__PURE__ */ jsxs("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
1112
- /* @__PURE__ */ jsx2(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ jsx2(
1113
- "img",
1114
- {
1115
- src: filePointer.iconImageUri,
1116
- alt: filePointer.sourceApplication,
1117
- className: "w-full h-full"
1118
- }
1119
- ) }),
1120
- filePointer.name
1121
- ] })
1122
- },
1123
- `word-${filePointer.sourceApplication}.${filePointer.name}`
1124
- );
1125
- }) }),
1126
- /* @__PURE__ */ jsx2(CommandSeparator, {})
1127
- ] })
1128
- ]
1129
- }
1130
- );
1131
- }
1132
- function Logo({
1133
- children,
1134
- width,
1135
- height
1136
- }) {
1137
- return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center", style: { width, height }, children });
1138
- }
1139
-
1140
- // src/components/ui/button.tsx
1141
- import * as React3 from "react";
1142
- import { Slot } from "@radix-ui/react-slot";
1143
- import { cva } from "class-variance-authority";
1144
- import { jsx as jsx3 } from "react/jsx-runtime";
1145
- var buttonVariants = cva(
1146
- "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
1147
- {
1148
- variants: {
1149
- variant: {
1150
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
1151
- destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
1152
- outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
1153
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
1154
- ghost: "hover:bg-accent hover:text-accent-foreground",
1155
- link: "text-primary underline-offset-4 hover:underline"
1156
- },
1157
- size: {
1158
- default: "h-10 px-4 py-2",
1159
- sm: "h-9 rounded-md px-3",
1160
- lg: "h-11 rounded-md px-8",
1161
- icon: "h-10 w-10"
1162
- }
1163
- },
1164
- defaultVariants: {
1165
- variant: "default",
1166
- size: "default"
1167
- }
1168
- }
1169
- );
1170
- var Button = React3.forwardRef(
1171
- (_a, ref) => {
1172
- var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
1173
- const Comp = asChild ? Slot : "button";
1174
- return /* @__PURE__ */ jsx3(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
1175
- }
1176
- );
1177
- Button.displayName = "Button";
1178
-
1179
- // src/components/ui/label.tsx
1180
- import * as React4 from "react";
1181
- import * as LabelPrimitive from "@radix-ui/react-label";
1182
- import { cva as cva2 } from "class-variance-authority";
1183
- import { jsx as jsx4 } from "react/jsx-runtime";
1184
- var labelVariants = cva2(
1185
- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
1186
- );
1187
- var Label = React4.forwardRef((_a, ref) => {
1188
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1189
- return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
1190
- });
1191
- Label.displayName = LabelPrimitive.Root.displayName;
1192
-
1193
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
1194
- import { useCallback as useCallback3, useContext as useContext2, useEffect as useEffect3, useRef, useState as useState3 } from "react";
1195
-
1196
- // src/lib/stream-promise-flatten.ts
1197
- function streamPromiseFlatten(promise) {
1198
- return new ReadableStream({
1199
- start(controller) {
1200
- return __async(this, null, function* () {
1201
- try {
1202
- const stream = yield promise;
1203
- const reader = stream.getReader();
1204
- while (true) {
1205
- const { done, value } = yield reader.read();
1206
- if (done) {
1207
- controller.close();
1208
- return;
1209
- }
1210
- controller.enqueue(value);
1211
- }
1212
- } catch (error) {
1213
- controller.error(error);
1214
- }
1215
- });
1216
- }
1217
- });
1218
- }
1219
-
1220
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
1221
- import { CopilotContext as CopilotContext2 } from "@copilotkit/react-core";
1222
-
1223
- // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
1224
- import Chip from "@mui/material/Chip/Chip.js";
1225
- import Avatar from "@mui/material/Avatar/Avatar.js";
1226
- import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1227
- var IncludedFilesPreview = ({
1228
- includedFiles,
1229
- setIncludedFiles
1230
- }) => {
1231
- return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-2 mt-2", children: [
1232
- /* @__PURE__ */ jsx5(Label, { className: "", children: "Included context:" }),
1233
- /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
1234
- return /* @__PURE__ */ jsx5(
1235
- FileChipPreview,
1236
- {
1237
- filePointer,
1238
- onDelete: () => {
1239
- setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
1240
- }
1241
- },
1242
- `file-${filePointer.sourceApplication}.${filePointer.name}`
1243
- );
1244
- }) })
1245
- ] });
1246
- };
1247
- var FileChipPreview = ({ filePointer, onDelete }) => {
1248
- return /* @__PURE__ */ jsx5(
1249
- Chip,
1250
- {
1251
- label: filePointer.name,
1252
- onDelete,
1253
- avatar: /* @__PURE__ */ jsx5(
1254
- Avatar,
1255
- {
1256
- src: filePointer.iconImageUri,
1257
- alt: filePointer.sourceApplication,
1258
- sx: { backgroundColor: "transparent" }
1259
- }
1260
- )
1261
- }
1262
- );
1263
- };
1264
-
1265
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
1266
- import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
1267
- var HoveringInsertionPromptBoxCore = ({
1268
- performInsertion,
1269
- state,
1270
- insertionOrEditingFunction,
1271
- contextCategories
1272
- }) => {
1273
- const { getDocumentsContext } = useContext2(CopilotContext2);
1274
- const [editSuggestion, setEditSuggestion] = useState3("");
1275
- const [suggestionIsLoading, setSuggestionIsLoading] = useState3(false);
1276
- const [adjustmentPrompt, setAdjustmentPrompt] = useState3("");
1277
- const [generatingSuggestion, setGeneratingSuggestion] = useState3(
1278
- null
1279
- );
1280
- const adjustmentTextAreaRef = useRef(null);
1281
- const suggestionTextAreaRef = useRef(null);
1282
- const [filePointers, setFilePointers] = useState3([]);
1283
- const [suggestedFiles, setSuggestedFiles] = useState3([]);
1284
- useEffect3(() => {
1285
- setSuggestedFiles(getDocumentsContext(contextCategories));
1286
- }, [contextCategories, getDocumentsContext]);
1287
- use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
1288
- use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
1289
- useEffect3(() => {
1290
- var _a;
1291
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1292
- }, []);
1293
- useEffect3(() => {
1294
- if (!generatingSuggestion) {
1295
- return;
1296
- }
1297
- if (generatingSuggestion.locked) {
1298
- return;
1299
- }
1300
- setEditSuggestion("");
1301
- const reader = generatingSuggestion.getReader();
1302
- const read = () => __async(void 0, null, function* () {
1303
- setSuggestionIsLoading(true);
1304
- while (true) {
1305
- const { done, value } = yield reader.read();
1306
- if (done) {
1307
- break;
1308
- }
1309
- setEditSuggestion((prev) => {
1310
- const newSuggestion = prev + value;
1311
- if (suggestionTextAreaRef.current) {
1312
- suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
1313
- }
1314
- return newSuggestion;
1315
- });
1316
- }
1317
- setSuggestionIsLoading(false);
1318
- });
1319
- read();
1320
- return () => {
1321
- const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
1322
- try {
1323
- yield reader.closed;
1324
- } catch (e) {
1325
- reader.releaseLock();
1326
- }
1327
- });
1328
- releaseLockIfNotClosed();
1329
- };
1330
- }, [generatingSuggestion]);
1331
- const beginGeneratingAdjustment = useCallback3(() => __async(void 0, null, function* () {
1332
- if (!adjustmentPrompt.trim()) {
1333
- return;
1334
- }
1335
- let modificationState = state.editorState;
1336
- if (editSuggestion !== "") {
1337
- modificationState.selectedText = editSuggestion;
1338
- }
1339
- const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
1340
- modificationState,
1341
- adjustmentPrompt,
1342
- filePointers,
1343
- new AbortController().signal
1344
- );
1345
- const adjustmentSuggestionTextStream = streamPromiseFlatten(
1346
- adjustmentSuggestionTextStreamPromise
1347
- );
1348
- setGeneratingSuggestion(adjustmentSuggestionTextStream);
1349
- }), [
1350
- adjustmentPrompt,
1351
- editSuggestion,
1352
- state.editorState,
1353
- insertionOrEditingFunction,
1354
- filePointers
1355
- ]);
1356
- const isLoading = suggestionIsLoading;
1357
- const textToEdit = editSuggestion || state.editorState.selectedText;
1358
- const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
1359
- const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
1360
- const AdjustmentPromptComponent = /* @__PURE__ */ jsxs3(Fragment, { children: [
1361
- /* @__PURE__ */ jsx6(Label, { className: "", children: adjustmentLabel }),
1362
- /* @__PURE__ */ jsxs3("div", { className: "relative w-full flex items-center", children: [
1363
- /* @__PURE__ */ jsx6(
1364
- "textarea",
1365
- {
1366
- disabled: suggestionIsLoading,
1367
- ref: adjustmentTextAreaRef,
1368
- value: adjustmentPrompt,
1369
- onChange: (e) => setAdjustmentPrompt(e.target.value),
1370
- onKeyDown: (e) => {
1371
- if (e.key === "Enter" && e.shiftKey) {
1372
- e.preventDefault();
1373
- setAdjustmentPrompt(adjustmentPrompt + "\n");
1374
- } else if (e.key === "Enter") {
1375
- e.preventDefault();
1376
- beginGeneratingAdjustment();
1377
- }
1378
- },
1379
- placeholder,
1380
- style: { minHeight: "3rem" },
1381
- className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
1382
- rows: 1
1383
- }
1384
- ),
1385
- /* @__PURE__ */ jsx6(
1386
- "button",
1387
- {
1388
- onClick: beginGeneratingAdjustment,
1389
- className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
1390
- children: /* @__PURE__ */ jsx6("i", { className: "material-icons", children: "arrow_forward" })
1391
- }
1392
- )
1393
- ] })
1394
- ] });
1395
- const SuggestionComponent = /* @__PURE__ */ jsxs3(Fragment, { children: [
1396
- /* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-end w-full", children: [
1397
- /* @__PURE__ */ jsx6(Label, { className: "mt-4", children: "Suggested:" }),
1398
- /* @__PURE__ */ jsx6("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ jsx6("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ jsx6(
1399
- "div",
1400
- {
1401
- className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
1402
- role: "status",
1403
- children: /* @__PURE__ */ jsx6("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
1404
- }
1405
- ) }) })
1406
- ] }),
1407
- /* @__PURE__ */ jsx6(
1408
- "textarea",
1409
- {
1410
- ref: suggestionTextAreaRef,
1411
- value: editSuggestion,
1412
- disabled: suggestionIsLoading,
1413
- onChange: (e) => setEditSuggestion(e.target.value),
1414
- className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
1415
- style: { overflow: "auto", maxHeight: "10em" }
1416
- }
1417
- )
1418
- ] });
1419
- const SubmitComponent = /* @__PURE__ */ jsx6("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ jsxs3(
1420
- Button,
1421
- {
1422
- className: " bg-green-700 text-white",
1423
- onClick: () => {
1424
- performInsertion(editSuggestion);
1425
- },
1426
- children: [
1427
- "Insert ",
1428
- /* @__PURE__ */ jsx6("i", { className: "material-icons", children: "check" })
1429
- ]
1430
- }
1431
- ) });
1432
- const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
1433
- const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
1434
- return /* @__PURE__ */ jsxs3("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
1435
- AdjustmentPromptComponent,
1436
- filePointers.length > 0 && /* @__PURE__ */ jsx6(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
1437
- sourceSearchWord !== void 0 && /* @__PURE__ */ jsx6(
1438
- SourceSearchBox,
1439
- {
1440
- searchTerm: sourceSearchWord,
1441
- suggestedFiles,
1442
- onSelectedFile: (filePointer) => {
1443
- var _a;
1444
- setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
1445
- setFilePointers((prev) => [...prev, filePointer]);
1446
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1447
- }
1448
- }
1449
- ),
1450
- generatingSuggestion ? SuggestionComponent : null,
1451
- generatingSuggestion ? SubmitComponent : null
1452
- ] });
1453
- };
1454
-
1455
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
1456
- import { jsx as jsx7 } from "react/jsx-runtime";
1457
- var HoveringInsertionPromptBox = (props) => {
1458
- return /* @__PURE__ */ jsx7(
1459
- "div",
1460
- {
1461
- className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
1462
- style: { width: "35rem" },
1463
- children: /* @__PURE__ */ jsx7(
1464
- HoveringInsertionPromptBoxCore,
1465
- {
1466
- state: {
1467
- editorState: props.editorState
1468
- },
1469
- insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
1470
- performInsertion: props.performInsertion,
1471
- contextCategories: props.contextCategories
1472
- }
1473
- )
1474
- }
1475
- );
1476
- };
1477
-
1478
- // src/components/hovering-toolbar/hovering-toolbar-components.tsx
1479
- import { css, cx } from "@emotion/css";
1480
- import React6 from "react";
1481
- import ReactDOM from "react-dom";
1482
- import { jsx as jsx8 } from "react/jsx-runtime";
1483
- var Button2 = React6.forwardRef(
1484
- (_a, ref) => {
1485
- var _b = _a, {
1486
- className,
1487
- active,
1488
- reversed
1489
- } = _b, props = __objRest(_b, [
1490
- "className",
1491
- "active",
1492
- "reversed"
1493
- ]);
1494
- return /* @__PURE__ */ jsx8(
1495
- "span",
1496
- __spreadProps(__spreadValues({}, props), {
1497
- ref,
1498
- className: cx(
1499
- className,
1500
- css`
1501
- cursor: pointer;
1502
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
1503
- `
1504
- )
1505
- })
1506
- );
1507
- }
1508
- );
1509
- var Icon = React6.forwardRef(
1510
- (_a, ref) => {
1511
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1512
- return /* @__PURE__ */ jsx8(
1513
- "span",
1514
- __spreadProps(__spreadValues({}, props), {
1515
- ref,
1516
- className: cx(
1517
- "material-icons",
1518
- className,
1519
- css`
1520
- font-size: 18px;
1521
- vertical-align: text-bottom;
1522
- `
1523
- )
1524
- })
1525
- );
1526
- }
1527
- );
1528
- var Menu = React6.forwardRef(
1529
- (_a, ref) => {
1530
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1531
- return /* @__PURE__ */ jsx8(
1532
- "div",
1533
- __spreadProps(__spreadValues({}, props), {
1534
- "data-test-id": "menu",
1535
- ref,
1536
- className: cx(
1537
- className,
1538
- css`
1539
- & > * {
1540
- display: inline-block;
1541
- }
1542
-
1543
- & > * + * {
1544
- margin-left: 15px;
1545
- }
1546
- `
1547
- )
1548
- })
1549
- );
1550
- }
1551
- );
1552
- var Portal = ({ children }) => {
1553
- return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
1554
- };
1555
- var Toolbar = React6.forwardRef(
1556
- (_a, ref) => {
1557
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1558
- return /* @__PURE__ */ jsx8(
1559
- Menu,
1560
- __spreadProps(__spreadValues({}, props), {
1561
- ref,
1562
- className: cx(
1563
- className,
1564
- css`
1565
- position: relative;
1566
- padding: 1px 18px 17px;
1567
- margin: 0 -20px;
1568
- border-bottom: 2px solid #eee;
1569
- margin-bottom: 20px;
1570
- `
1571
- )
1572
- })
1573
- );
1574
- }
1575
- );
1576
-
1577
- // src/components/hovering-toolbar/hovering-editor-provider.tsx
1578
- import { createContext, useState as useState4, useContext as useContext3 } from "react";
1579
- import { jsx as jsx9 } from "react/jsx-runtime";
1580
- var HoveringEditorContext = createContext({
1581
- isDisplayed: false,
1582
- setIsDisplayed: () => {
1583
- }
1584
- });
1585
- var HoveringEditorProvider = ({ children }) => {
1586
- const [isDisplayed, setIsDisplayed] = useState4(false);
1587
- return /* @__PURE__ */ jsx9(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
1588
- };
1589
- var useHoveringEditorContext = () => useContext3(HoveringEditorContext);
1590
-
1591
- // src/components/hovering-toolbar/hovering-toolbar.tsx
1592
- import { jsx as jsx10 } from "react/jsx-runtime";
1593
- var HoveringToolbar = (props) => {
1594
- const ref = useRef2(null);
1595
- const editor = useSlate();
1596
- const selection = useSlateSelection();
1597
- const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
1598
- const [isClient, setIsClient] = useState5(false);
1599
- useEffect4(() => {
1600
- setIsClient(true);
1601
- }, []);
1602
- useEffect4(() => {
1603
- const el = ref.current;
1604
- const { selection: selection2 } = editor;
1605
- if (!el) {
1606
- return;
1607
- }
1608
- if (!selection2) {
1609
- el.removeAttribute("style");
1610
- return;
1611
- }
1612
- const domSelection = window.getSelection();
1613
- if (!domSelection) {
1614
- return;
1615
- }
1616
- const domRange = domSelection.getRangeAt(0);
1617
- const rect = domRange.getBoundingClientRect();
1618
- if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
1619
- return;
1620
- }
1621
- const minGapFromEdge = 60;
1622
- const verticalOffsetFromCorner = 35;
1623
- const horizontalOffsetFromCorner = 15;
1624
- let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
1625
- if (top < minGapFromEdge) {
1626
- top = rect.bottom + window.scrollY + minGapFromEdge;
1627
- } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
1628
- top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
1629
- }
1630
- let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
1631
- if (left < minGapFromEdge) {
1632
- left = minGapFromEdge;
1633
- } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
1634
- left = window.innerWidth - el.offsetWidth - minGapFromEdge;
1635
- }
1636
- el.style.opacity = "1";
1637
- el.style.top = `${top}px`;
1638
- el.style.left = `${left}px`;
1639
- });
1640
- useEffect4(() => {
1641
- const handleClickOutside = (event) => {
1642
- if (ref.current && !ref.current.contains(event.target)) {
1643
- setIsDisplayed(false);
1644
- }
1645
- };
1646
- document.addEventListener("mousedown", handleClickOutside);
1647
- return () => {
1648
- document.removeEventListener("mousedown", handleClickOutside);
1649
- };
1650
- }, [ref, setIsDisplayed]);
1651
- if (!isClient) {
1652
- return null;
1653
- }
1654
- return /* @__PURE__ */ jsx10(Portal, { children: /* @__PURE__ */ jsx10(
1655
- Menu,
1656
- {
1657
- ref,
1658
- className: props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
1659
- children: isDisplayed && selection && /* @__PURE__ */ jsx10(
1660
- HoveringInsertionPromptBox,
1661
- {
1662
- editorState: editorState(editor, selection),
1663
- apiConfig: props.apiConfig,
1664
- closeWindow: () => {
1665
- setIsDisplayed(false);
1666
- },
1667
- performInsertion: (insertedText) => {
1668
- console.log("inserted text", insertedText);
1669
- Transforms5.delete(editor, { at: selection });
1670
- Transforms5.insertText(editor, insertedText, {
1671
- at: selection
1672
- });
1673
- setIsDisplayed(false);
1674
- },
1675
- contextCategories: props.contextCategories
1676
- }
1677
- )
1678
- }
1679
- ) });
1680
- };
1681
- function editorState(editor, selection) {
1682
- const textAroundCursor = getTextAroundSelection(editor);
1683
- if (textAroundCursor) {
1684
- return textAroundCursor;
1685
- }
1686
- return {
1687
- textBeforeCursor: getFullEditorTextWithNewlines(editor),
1688
- textAfterCursor: "",
1689
- selectedText: ""
1690
- };
1691
- }
1692
-
1693
- // src/components/base-copilot-textarea/render-element.tsx
1694
- import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
1695
- function makeRenderElementFunction(suggestionsStyle) {
1696
- return (props) => {
1697
- switch (props.element.type) {
1698
- case "paragraph":
1699
- return /* @__PURE__ */ jsx11(DefaultElement, __spreadValues({}, props));
1700
- case "suggestion":
1701
- return /* @__PURE__ */ jsx11(SuggestionElement, __spreadProps(__spreadValues({}, props), { suggestionsStyle }));
1702
- }
1703
- };
1704
- }
1705
- var DefaultElement = (props) => {
1706
- return /* @__PURE__ */ jsx11("div", __spreadProps(__spreadValues({}, props.attributes), { children: props.children }));
1707
- };
1708
- var SuggestionElement = (props) => {
1709
- return /* @__PURE__ */ jsxs4(
1710
- "span",
1711
- __spreadProps(__spreadValues({}, props.attributes), {
1712
- style: __spreadValues({}, props.suggestionsStyle),
1713
- contentEditable: false,
1714
- children: [
1715
- props.children,
1716
- props.element.type === "suggestion" && props.element.content
1717
- ]
1718
- })
1719
- );
1720
- };
1721
-
1722
- // src/components/base-copilot-textarea/render-placeholder.tsx
1723
- import { jsx as jsx12 } from "react/jsx-runtime";
1724
- function makeRenderPlaceholderFunction(placeholderStyle) {
1725
- return (props) => {
1726
- const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
1727
- return /* @__PURE__ */ jsx12(
1728
- "div",
1729
- __spreadProps(__spreadValues({}, restAttributes), {
1730
- style: __spreadValues(__spreadValues({}, style), placeholderStyle),
1731
- children: props.children
1732
- })
1733
- );
1734
- };
1735
- }
1736
-
1737
- // src/components/base-copilot-textarea/use-add-branding-css.tsx
1738
- import { useEffect as useEffect5 } from "react";
1739
- function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
1740
- const cssSelector = ".copilot-textarea.with-branding";
1741
- useEffect5(() => {
1742
- if (disableBranding) {
1743
- return;
1744
- }
1745
- const styleEl = document.createElement("style");
1746
- styleEl.id = "dynamic-styles";
1747
- let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
1748
- const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
1749
- return `${kebabCaseKey}: ${value};`;
1750
- }).join(" ");
1751
- dynamicStyles += `font-style: normal; font-size: x-small;`;
1752
- dynamicStyles += `content: "CopilotKit";`;
1753
- dynamicStyles += `bottom: 6px;`;
1754
- dynamicStyles += `right: 6px;`;
1755
- dynamicStyles += `pointer-events: none;`;
1756
- dynamicStyles += `font-weight: 200;`;
1757
- dynamicStyles += `padding: 0;`;
1758
- dynamicStyles += `margin: 0;`;
1759
- dynamicStyles += `border: 0;`;
1760
- dynamicStyles += `line-height: 1;`;
1761
- dynamicStyles += `position: absolute;`;
1762
- styleEl.innerHTML = `
1763
- ${cssSelector}::after {
1764
- ${dynamicStyles}
1765
- }
1766
- `;
1767
- document.head.appendChild(styleEl);
1768
- const textarea = document.querySelector(cssSelector);
1769
- const handleScroll = () => {
1770
- const styleEl2 = document.getElementById("dynamic-styles");
1771
- if (styleEl2 && textarea) {
1772
- const offsetFromBottom = -textarea.scrollTop + 6;
1773
- const offsetFromRight = -textarea.scrollLeft + 6;
1774
- styleEl2.innerHTML = `
1775
- ${cssSelector}::after {
1776
- ${dynamicStyles}
1777
- bottom: ${offsetFromBottom}px;
1778
- right: ${offsetFromRight}px;
1779
- }
1780
- `;
1781
- }
1782
- };
1783
- textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
1784
- return () => {
1785
- var _a;
1786
- (_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
1787
- textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
1788
- };
1789
- }, [disableBranding, suggestionStyleAugmented]);
1790
- }
1791
-
1792
- // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1793
- import { useEffect as useEffect6, useRef as useRef3 } from "react";
1794
- import { useSlateSelector } from "slate-react";
1795
- import { Range as Range4 } from "slate";
1796
-
1797
- // src/lib/editor-to-text.ts
1798
- import { Element as Element4 } from "slate";
1799
- function nodeChildrenToTextComponents(editor, nodes) {
1800
- const indeciesOfInlineElements = new Set(
1801
- nodes.map((node, index) => {
1802
- if (Element4.isElement(node) && editor.isInline(node)) {
1803
- return index;
1804
- }
1805
- return -1;
1806
- }).filter((index) => index !== -1)
1807
- );
1808
- const nonIgnorableItems = nodes.filter((node, index) => {
1809
- const isInline = indeciesOfInlineElements.has(index);
1810
- if (isInline) {
1811
- return false;
1812
- }
1813
- const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
1814
- if (isNeighbourOfInline) {
1815
- return node.text !== "";
1816
- }
1817
- return true;
1818
- });
1819
- return nonIgnorableItems.map((node) => {
1820
- if (Element4.isElement(node)) {
1821
- switch (node.type) {
1822
- case "paragraph":
1823
- return nodeChildrenToTextComponents(editor, node.children);
1824
- case "suggestion":
1825
- return [];
1826
- }
1827
- } else {
1828
- return [node];
1829
- }
1830
- }).reduce((acc, val) => acc.concat(val), []);
1831
- }
1832
- var editorToText = (editor) => {
1833
- const flattened = nodeChildrenToTextComponents(editor, editor.children);
1834
- const text = flattened.map((textComponent) => textComponent.text).join("\n");
1835
- return text;
1836
- };
1837
-
1838
- // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1839
- import { Fragment as Fragment2, jsx as jsx13 } from "react/jsx-runtime";
1840
- function TrackerTextEditedSinceLastCursorMovement(props) {
1841
- const cursorState = useSlateSelector((state) => ({
1842
- selection: state.selection,
1843
- text: editorToText(state)
1844
- }));
1845
- const previousState = usePrevious(cursorState);
1846
- useEffect6(() => {
1847
- if (!previousState) {
1848
- return;
1849
- }
1850
- if (cursorChangedWithoutTextChanged(previousState, cursorState)) {
1851
- props.setCursorMovedSinceLastTextChange(true);
1852
- }
1853
- }, [props.setCursorMovedSinceLastTextChange, cursorState]);
1854
- return /* @__PURE__ */ jsx13(Fragment2, {});
1855
- }
1856
- var cursorChangedWithoutTextChanged = (prev, next) => {
1857
- const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
1858
- const isTextSame = prev.text === next.text;
1859
- return isSelectionChanged && isTextSame;
1860
- };
1861
- var isSelectionEqual = (a, b) => {
1862
- if (!a && !b)
1863
- return true;
1864
- if (!a || !b)
1865
- return false;
1866
- return Range4.equals(a, b);
1867
- };
1868
- function usePrevious(value) {
1869
- const ref = useRef3();
1870
- useEffect6(() => {
1871
- ref.current = value;
1872
- });
1873
- return ref.current;
1874
- }
1875
-
1876
- // src/components/base-copilot-textarea/base-copilot-textarea.tsx
1877
- import { jsx as jsx14, jsxs as jsxs5 } from "react/jsx-runtime";
1878
- var BaseCopilotTextarea = React9.forwardRef(
1879
- (props, ref) => {
1880
- return /* @__PURE__ */ jsx14(HoveringEditorProvider, { children: /* @__PURE__ */ jsx14(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), { ref })) });
1881
- }
1882
- );
1883
- var BaseCopilotTextareaWithHoveringContext = React9.forwardRef(
1884
- (props, ref) => {
1885
- const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
1886
- const valueOnInitialRender = useMemo4(() => {
1887
- var _a2;
1888
- return (_a2 = props.value) != null ? _a2 : "";
1889
- }, []);
1890
- const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState6(valueOnInitialRender);
1891
- const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState6(false);
1892
- const initialValue = useMemo4(() => {
1893
- return [
1894
- {
1895
- type: "paragraph",
1896
- children: [{ text: valueOnInitialRender }]
1897
- }
1898
- ];
1899
- }, [valueOnInitialRender]);
1900
- const editor = useCopilotTextareaEditor();
1901
- const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
1902
- const insertText = useCallback4(
1903
- (autosuggestion) => {
1904
- Editor5.insertText(editor, autosuggestion.text, {
1905
- at: autosuggestion.point
1906
- });
1907
- },
1908
- [editor]
1909
- );
1910
- const shouldDisableAutosuggestions = (
1911
- // textarea is manually disabled:
1912
- autosuggestionsConfig.disabled || // hovering editor is displayed:
1913
- hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
1914
- cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
1915
- );
1916
- const {
1917
- currentAutocompleteSuggestion,
1918
- onChangeHandler: onChangeHandlerForAutocomplete,
1919
- onKeyDownHandler: onKeyDownHandlerForAutocomplete
1920
- } = useAutosuggestions(
1921
- autosuggestionsConfig.debounceTime,
1922
- autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
1923
- autosuggestionsConfig.apiConfig.autosuggestionsFunction,
1924
- insertText,
1925
- autosuggestionsConfig.disableWhenEmpty,
1926
- shouldDisableAutosuggestions
1927
- );
1928
- const onKeyDownHandlerForHoveringEditor = useCallback4(
1929
- (event) => {
1930
- if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event)) {
1931
- event.preventDefault();
1932
- setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
1933
- }
1934
- },
1935
- [
1936
- hoveringEditorIsDisplayed,
1937
- setHoveringEditorIsDisplayed,
1938
- autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress
1939
- ]
1940
- );
1941
- useEffect7(() => {
1942
- clearAutocompletionsFromEditor(editor);
1943
- if (currentAutocompleteSuggestion) {
1944
- addAutocompletionsToEditor(
1945
- editor,
1946
- currentAutocompleteSuggestion.text,
1947
- currentAutocompleteSuggestion.point
1948
- );
1949
- }
1950
- }, [currentAutocompleteSuggestion]);
1951
- const suggestionStyleAugmented = useMemo4(() => {
1952
- return __spreadValues({
1953
- fontStyle: "italic",
1954
- color: "gray"
1955
- }, props.suggestionsStyle);
1956
- }, [props.suggestionsStyle]);
1957
- const renderElementMemoized = useMemo4(() => {
1958
- return makeRenderElementFunction(suggestionStyleAugmented);
1959
- }, [suggestionStyleAugmented]);
1960
- const renderPlaceholderMemoized = useMemo4(() => {
1961
- const placeholderStyleSlatejsOverrides = {
1962
- top: void 0
1963
- };
1964
- const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
1965
- return makeRenderPlaceholderFunction(placeholderStyleAugmented);
1966
- }, [props.placeholderStyle]);
1967
- useEffect7(() => {
1968
- var _a2, _b;
1969
- if (props.value === lastKnownFullEditorText) {
1970
- return;
1971
- }
1972
- setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
1973
- replaceEditorText(editor, (_b = props.value) != null ? _b : "");
1974
- }, [props.value]);
1975
- const _a = props, {
1976
- placeholderStyle,
1977
- value,
1978
- hoverMenuClassname,
1979
- onValueChange,
1980
- baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
1981
- className,
1982
- onChange,
1983
- onKeyDown,
1984
- disableBranding
1985
- } = _a, propsToForward = __objRest(_a, [
1986
- "placeholderStyle",
1987
- "value",
1988
- "hoverMenuClassname",
1989
- "onValueChange",
1990
- "baseAutosuggestionsConfig",
1991
- "className",
1992
- "onChange",
1993
- "onKeyDown",
1994
- "disableBranding"
1995
- ]);
1996
- useAddBrandingCss(suggestionStyleAugmented, disableBranding);
1997
- usePopulateCopilotTextareaRef(editor, ref);
1998
- const moddedClassName = (() => {
1999
- const baseClassName = "copilot-textarea";
2000
- const brandingClass = disableBranding ? "no-branding" : "with-branding";
2001
- const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
2002
- const mergedClassName = twMerge2(defaultTailwindClassName, className != null ? className : "");
2003
- return `${baseClassName} ${brandingClass} ${mergedClassName}`;
2004
- })();
2005
- return /* @__PURE__ */ jsxs5(
2006
- Slate,
2007
- {
2008
- editor,
2009
- initialValue,
2010
- onChange: (value2) => {
2011
- var _a2, _b;
2012
- const newEditorState = getTextAroundCollapsedCursor(editor);
2013
- const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
2014
- setLastKnownFullEditorText((prev) => {
2015
- if (prev !== fullEditorText) {
2016
- setCursorMovedSinceLastTextChange(false);
2017
- }
2018
- return fullEditorText;
2019
- });
2020
- onChangeHandlerForAutocomplete(newEditorState);
2021
- (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
2022
- (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
2023
- },
2024
- children: [
2025
- /* @__PURE__ */ jsx14(
2026
- TrackerTextEditedSinceLastCursorMovement,
2027
- {
2028
- setCursorMovedSinceLastTextChange
2029
- }
2030
- ),
2031
- /* @__PURE__ */ jsx14(
2032
- HoveringToolbar,
2033
- {
2034
- apiConfig: autosuggestionsConfig.apiConfig,
2035
- contextCategories: autosuggestionsConfig.contextCategories,
2036
- hoverMenuClassname
2037
- }
2038
- ),
2039
- /* @__PURE__ */ jsx14(
2040
- Editable,
2041
- __spreadValues({
2042
- renderElement: renderElementMemoized,
2043
- renderPlaceholder: renderPlaceholderMemoized,
2044
- onKeyDown: (event) => {
2045
- var _a2;
2046
- onKeyDownHandlerForHoveringEditor(event);
2047
- onKeyDownHandlerForAutocomplete(event);
2048
- (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
2049
- },
2050
- className: moddedClassName
2051
- }, propsToForward)
2052
- )
2053
- ]
2054
- }
2055
- );
2056
- }
2057
- );
2058
- function makeSemiFakeReactTextAreaEvent(currentText) {
2059
- return {
2060
- target: {
2061
- value: currentText,
2062
- type: "copilot-textarea"
2063
- },
2064
- currentTarget: {
2065
- value: currentText,
2066
- type: "copilot-textarea"
2067
- }
2068
- };
2069
- }
2070
-
2071
- // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2072
- import { CopilotContext as CopilotContext3 } from "@copilotkit/react-core";
2073
- import { useCallback as useCallback5, useContext as useContext4 } from "react";
2074
- function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2075
- const { getContextString, copilotApiConfig } = useContext4(CopilotContext3);
2076
- const insertionFunction = useCallback5(
2077
- (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2078
- const res = yield retry(() => __async(this, null, function* () {
2079
- const messages = [
2080
- {
2081
- role: "system",
2082
- content: insertionApiConfig.makeSystemPrompt(
2083
- textareaPurpose,
2084
- getContextString(documents, contextCategories)
2085
- )
2086
- },
2087
- ...insertionApiConfig.fewShotMessages,
2088
- {
2089
- role: "user",
2090
- name: "TextAfterCursor",
2091
- content: editorState2.textAfterCursor
2092
- },
2093
- {
2094
- role: "user",
2095
- name: "TextBeforeCursor",
2096
- content: editorState2.textBeforeCursor
2097
- },
2098
- {
2099
- role: "user",
2100
- name: "InsertionPrompt",
2101
- content: insertionPrompt
2102
- }
2103
- ];
2104
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
2105
- return yield apiEndpoint.run(abortSignal, messages, insertionApiConfig.forwardedParams);
2106
- }));
2107
- return res;
2108
- }),
2109
- [insertionApiConfig, getContextString, contextCategories, textareaPurpose]
2110
- );
2111
- const editingFunction = useCallback5(
2112
- (editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
2113
- const res = yield retry(() => __async(this, null, function* () {
2114
- const messages = [
2115
- {
2116
- role: "system",
2117
- content: editingApiConfig.makeSystemPrompt(
2118
- textareaPurpose,
2119
- getContextString(documents, contextCategories)
2120
- )
2121
- },
2122
- ...editingApiConfig.fewShotMessages,
2123
- {
2124
- role: "user",
2125
- name: "TextBeforeCursor",
2126
- content: editorState2.textBeforeCursor
2127
- },
2128
- {
2129
- role: "user",
2130
- name: "TextToEdit",
2131
- content: editorState2.selectedText
2132
- },
2133
- {
2134
- role: "user",
2135
- name: "TextAfterCursor",
2136
- content: editorState2.textAfterCursor
2137
- },
2138
- {
2139
- role: "user",
2140
- name: "EditingPrompt",
2141
- content: editingPrompt
2142
- }
2143
- ];
2144
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
2145
- return yield apiEndpoint.run(abortSignal, messages, editingApiConfig.forwardedParams);
2146
- }));
2147
- return res;
2148
- }),
2149
- [editingApiConfig, getContextString, contextCategories, textareaPurpose]
2150
- );
2151
- const insertionOrEditingFunction = useCallback5(
2152
- (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2153
- if (editorState2.selectedText === "") {
2154
- return yield insertionFunction(editorState2, insertionPrompt, documents, abortSignal);
2155
- } else {
2156
- return yield editingFunction(editorState2, insertionPrompt, documents, abortSignal);
2157
- }
2158
- }),
2159
- [insertionFunction, editingFunction]
2160
- );
2161
- return insertionOrEditingFunction;
2162
- }
2163
-
2164
- // src/components/copilot-textarea/copilot-textarea.tsx
2165
- import merge from "lodash.merge";
2166
- import { Fragment as Fragment3, jsx as jsx15 } from "react/jsx-runtime";
2167
- var CopilotTextarea = React10.forwardRef(
2168
- (props, ref) => {
2169
- const _a = props, { autosuggestionsConfig: autosuggestionsConfigUserSpecified } = _a, forwardedProps = __objRest(_a, ["autosuggestionsConfig"]);
2170
- const autosuggestionsConfig = merge(
2171
- defaultAutosuggestionsConfig,
2172
- autosuggestionsConfigUserSpecified
2173
- );
2174
- const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
2175
- autosuggestionsConfig.textareaPurpose,
2176
- autosuggestionsConfig.contextCategories,
2177
- autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
2178
- );
2179
- const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
2180
- autosuggestionsConfig.textareaPurpose,
2181
- autosuggestionsConfig.contextCategories,
2182
- autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
2183
- autosuggestionsConfig.chatApiConfigs.editingApiConfig
2184
- );
2185
- return /* @__PURE__ */ jsx15(Fragment3, { children: /* @__PURE__ */ jsx15(
2186
- BaseCopilotTextarea,
2187
- __spreadProps(__spreadValues({
2188
- ref
2189
- }, forwardedProps), {
2190
- baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
2191
- apiConfig: {
2192
- insertionOrEditingFunction,
2193
- autosuggestionsFunction
2194
- }
2195
- })
2196
- })
2197
- ) });
2198
- }
2199
- );
2200
- export {
2201
- CopilotTextarea
2202
- };
1
+ export { CopilotTextarea } from '../../chunk-NRTYAQJE.mjs';
2
+ import '../../chunk-MTDBPK5D.mjs';
3
+ import '../../chunk-FRIYJQCI.mjs';
4
+ import '../../chunk-LP2REBM5.mjs';
5
+ import '../../chunk-2C7O2EVM.mjs';
6
+ import '../../chunk-GQN2HYFJ.mjs';
7
+ import '../../chunk-Y473E2ZQ.mjs';
8
+ import '../../chunk-L7VVZH4Q.mjs';
9
+ import '../../chunk-KNBNKEXR.mjs';
10
+ import '../../chunk-ELEY7HWW.mjs';
11
+ import '../../chunk-EPBVNDKE.mjs';
12
+ import '../../chunk-KFQZHRPJ.mjs';
13
+ import '../../chunk-XV7MLLXQ.mjs';
14
+ import '../../chunk-P4QVFRLY.mjs';
15
+ import '../../chunk-FJNUPSQK.mjs';
16
+ import '../../chunk-WTASPE2W.mjs';
17
+ import '../../chunk-PTZVE6NC.mjs';
18
+ import '../../chunk-WFTAAA7R.mjs';
19
+ import '../../chunk-3PQ7GSFE.mjs';
20
+ import '../../chunk-224UKA7C.mjs';
21
+ import '../../chunk-OHO4G6DR.mjs';
22
+ import '../../chunk-47L4PLG4.mjs';
23
+ import '../../chunk-7LSRNPNI.mjs';
24
+ import '../../chunk-2QDCE7PD.mjs';
25
+ import '../../chunk-DE5K76I2.mjs';
26
+ import '../../chunk-5FO6ISW4.mjs';
27
+ import '../../chunk-QDFAIRQF.mjs';
28
+ import '../../chunk-NTLVQENP.mjs';
29
+ import '../../chunk-K5LNB36H.mjs';
30
+ import '../../chunk-RBR32FWA.mjs';
31
+ import '../../chunk-KDVMG3XF.mjs';
32
+ import '../../chunk-WJHSY5T6.mjs';
33
+ import '../../chunk-FP2EKU3L.mjs';
34
+ import '../../chunk-WADHCMPK.mjs';
35
+ import '../../chunk-72P3KOHZ.mjs';
36
+ import '../../chunk-JJLQVT7S.mjs';
37
+ import '../../chunk-7SUZ6CXM.mjs';
38
+ import '../../chunk-DRV2FOHZ.mjs';
39
+ import '../../chunk-4NHVQZ67.mjs';
40
+ import '../../chunk-VPEH6V7T.mjs';
41
+ import '../../chunk-5UNJXFUO.mjs';
42
+ import '../../chunk-M2DR4KVB.mjs';
43
+ import '../../chunk-T6MTDQZ7.mjs';
44
+ import '../../chunk-ECR45NSD.mjs';
45
+ import '../../chunk-KNQIEOFP.mjs';
46
+ import '../../chunk-MRXNTQOX.mjs';
47
+ //# sourceMappingURL=out.js.map
2203
48
  //# sourceMappingURL=copilot-textarea.mjs.map