@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
@@ -0,0 +1,99 @@
1
+ import { ChatlikeApiEndpoint } from './chunk-QDFAIRQF.mjs';
2
+ import { retry } from './chunk-KNQIEOFP.mjs';
3
+ import { __async } from './chunk-MRXNTQOX.mjs';
4
+ import { CopilotContext } from '@copilotkit/react-core';
5
+ import { useContext, useCallback } from 'react';
6
+
7
+ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
8
+ const { getContextString, copilotApiConfig } = useContext(CopilotContext);
9
+ const insertionFunction = useCallback(
10
+ (editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
11
+ const res = yield retry(() => __async(this, null, function* () {
12
+ const messages = [
13
+ {
14
+ role: "system",
15
+ content: insertionApiConfig.makeSystemPrompt(
16
+ textareaPurpose,
17
+ getContextString(documents, contextCategories)
18
+ )
19
+ },
20
+ ...insertionApiConfig.fewShotMessages,
21
+ {
22
+ role: "user",
23
+ name: "TextAfterCursor",
24
+ content: editorState.textAfterCursor
25
+ },
26
+ {
27
+ role: "user",
28
+ name: "TextBeforeCursor",
29
+ content: editorState.textBeforeCursor
30
+ },
31
+ {
32
+ role: "user",
33
+ name: "InsertionPrompt",
34
+ content: insertionPrompt
35
+ }
36
+ ];
37
+ const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
38
+ return yield apiEndpoint.run(abortSignal, messages, insertionApiConfig.forwardedParams);
39
+ }));
40
+ return res;
41
+ }),
42
+ [insertionApiConfig, getContextString, contextCategories, textareaPurpose]
43
+ );
44
+ const editingFunction = useCallback(
45
+ (editorState, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
46
+ const res = yield retry(() => __async(this, null, function* () {
47
+ const messages = [
48
+ {
49
+ role: "system",
50
+ content: editingApiConfig.makeSystemPrompt(
51
+ textareaPurpose,
52
+ getContextString(documents, contextCategories)
53
+ )
54
+ },
55
+ ...editingApiConfig.fewShotMessages,
56
+ {
57
+ role: "user",
58
+ name: "TextBeforeCursor",
59
+ content: editorState.textBeforeCursor
60
+ },
61
+ {
62
+ role: "user",
63
+ name: "TextToEdit",
64
+ content: editorState.selectedText
65
+ },
66
+ {
67
+ role: "user",
68
+ name: "TextAfterCursor",
69
+ content: editorState.textAfterCursor
70
+ },
71
+ {
72
+ role: "user",
73
+ name: "EditingPrompt",
74
+ content: editingPrompt
75
+ }
76
+ ];
77
+ const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
78
+ return yield apiEndpoint.run(abortSignal, messages, editingApiConfig.forwardedParams);
79
+ }));
80
+ return res;
81
+ }),
82
+ [editingApiConfig, getContextString, contextCategories, textareaPurpose]
83
+ );
84
+ const insertionOrEditingFunction = useCallback(
85
+ (editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
86
+ if (editorState.selectedText === "") {
87
+ return yield insertionFunction(editorState, insertionPrompt, documents, abortSignal);
88
+ } else {
89
+ return yield editingFunction(editorState, insertionPrompt, documents, abortSignal);
90
+ }
91
+ }),
92
+ [insertionFunction, editingFunction]
93
+ );
94
+ return insertionOrEditingFunction;
95
+ }
96
+
97
+ export { useMakeStandardInsertionOrEditingFunction };
98
+ //# sourceMappingURL=out.js.map
99
+ //# sourceMappingURL=chunk-FRIYJQCI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AA0BjC,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AAExE,QAAM,oBAAoB;AAAA,IACxB,CACE,aACA,iBACA,WACA,gBACG;AACH,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,mBAAmB;AAAA,cAC1B;AAAA,cACA,iBAAiB,WAAW,iBAAiB;AAAA,YAC/C;AAAA,UACF;AAAA,UACA,GAAG,mBAAmB;AAAA,UACtB;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAEA,cAAM,cAAc,oBAAoB,qBAAqB,gBAAgB;AAC7E,eAAO,MAAM,YAAY,IAAI,aAAa,UAAU,mBAAmB,eAAe;AAAA,MACxF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,oBAAoB,kBAAkB,mBAAmB,eAAe;AAAA,EAC3E;AAEA,QAAM,kBAAkB;AAAA,IACtB,CACE,aACA,eACA,WACA,gBACG;AACH,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,iBAAiB;AAAA,cACxB;AAAA,cACA,iBAAiB,WAAW,iBAAiB;AAAA,YAC/C;AAAA,UACF;AAAA,UACA,GAAG,iBAAiB;AAAA,UACpB;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAEA,cAAM,cAAc,oBAAoB,qBAAqB,gBAAgB;AAC7E,eAAO,MAAM,YAAY,IAAI,aAAa,UAAU,iBAAiB,eAAe;AAAA,MACtF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,6BAA6B;AAAA,IACjC,CACE,aACA,iBACA,WACA,gBACG;AACH,UAAI,YAAY,iBAAiB,IAAI;AACnC,eAAO,MAAM,kBAAkB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACrF,OAAO;AACL,eAAO,MAAM,gBAAgB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACnF;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,eAAe;AAAA,EACrC;AAEA,SAAO;AACT","sourcesContent":["import { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { ChatlikeApiEndpoint, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n InsertionEditorApiConfig,\n InsertionEditorState,\n} from \"../../types/base/autosuggestions-bare-function\";\nimport { InsertionsApiConfig } from \"../../types/autosuggestions-config/insertions-api-config\";\nimport { EditingApiConfig } from \"../../types/autosuggestions-config/editing-api-config\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardInsertionOrEditingFunction(\n textareaPurpose: string,\n contextCategories: string[],\n insertionApiConfig: InsertionsApiConfig,\n editingApiConfig: EditingApiConfig,\n): Generator_InsertionOrEditingSuggestion {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n\n const insertionFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...insertionApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: insertionPrompt,\n },\n ];\n\n const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);\n return await apiEndpoint.run(abortSignal, messages, insertionApiConfig.forwardedParams);\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...editingApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: editorState.selectedText,\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: editingPrompt,\n },\n ];\n\n const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);\n return await apiEndpoint.run(abortSignal, messages, editingApiConfig.forwardedParams);\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);\n } else {\n return await editingFunction(editorState, insertionPrompt, documents, abortSignal);\n }\n },\n [insertionFunction, editingFunction],\n );\n\n return insertionOrEditingFunction;\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { Node, Element, Transforms } from 'slate';
2
+
3
+ // src/lib/slatejs-edits/clear-autocompletions.ts
4
+ function clearAutocompletionsFromEditor(editor) {
5
+ const paths = [];
6
+ for (const [node, path] of Node.nodes(editor)) {
7
+ if (Element.isElement(node) && node.type === "suggestion") {
8
+ paths.push(path);
9
+ }
10
+ }
11
+ for (const path of paths) {
12
+ try {
13
+ Transforms.removeNodes(editor, { at: path });
14
+ } catch (e) {
15
+ console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
16
+ }
17
+ }
18
+ }
19
+
20
+ export { clearAutocompletionsFromEditor };
21
+ //# sourceMappingURL=out.js.map
22
+ //# sourceMappingURL=chunk-GQN2HYFJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/slatejs-edits/clear-autocompletions.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS,MAAY,kBAAkB;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,QAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,iBAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ,IAAI,uEAAuE,CAAC;AAAA,IACtF;AAAA,EACF;AACF","sourcesContent":["import { Element, Node, Path, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function clearAutocompletionsFromEditor(editor: CustomEditor) {\n // clear previous suggestion\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (Element.isElement(node) && node.type === \"suggestion\") {\n paths.push(path);\n }\n }\n for (const path of paths) {\n try {\n Transforms.removeNodes(editor, { at: path });\n } catch (e) {\n console.log(\"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\", e);\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-H4VKQGVU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-IU3WTXLQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { arraysAreEqual } from './chunk-7SUZ6CXM.mjs';
2
+
3
+ // src/types/base/editor-autocomplete-state.ts
4
+ function areEqual_autocompleteState(prev, next) {
5
+ return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
6
+ }
7
+
8
+ export { areEqual_autocompleteState };
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=chunk-JJLQVT7S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/base/editor-autocomplete-state.ts"],"names":[],"mappings":";;;;;AASO,SAAS,2BACd,MACA,MACA;AACA,SACE,KAAK,YAAY,WAAW,KAAK,YAAY,UAC7C,eAAe,KAAK,YAAY,MAAM,KAAK,YAAY,IAAI,KAC3D,KAAK,qBAAqB,KAAK,oBAC/B,KAAK,oBAAoB,KAAK;AAElC","sourcesContent":["import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState,\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) &&\n prev.textBeforeCursor === next.textBeforeCursor &&\n prev.textAfterCursor === next.textAfterCursor\n );\n}\n"]}
@@ -0,0 +1,80 @@
1
+ // src/types/autosuggestions-config/editing-api-config.tsx
2
+ var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
3
+ return `You are a versatile writing assistant.
4
+
5
+ The user is writing some text.
6
+ The purpose is: "${textareaPurpose}"
7
+
8
+ The following external context is also provided. Use it to help you make better suggestions!!!
9
+ \`\`\`
10
+ ${contextString}
11
+ \`\`\`
12
+
13
+ The user also provides you with a prompt for EDITING some text they are writing.
14
+ Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
15
+
16
+ Adjust yourself to the user's style and implied intent.
17
+
18
+ The user will provide the following information; use this to infer the best relevant EDIT:
19
+ <TextBeforeCursor>
20
+ <TextToEdit>
21
+ <TextAfterCursor>
22
+ <EditingPrompt>
23
+
24
+ <YourEditSuggestion>
25
+ `;
26
+ };
27
+ var defaultEditingFewShotMessages = [
28
+ {
29
+ role: "user",
30
+ name: "TextBeforeCursor",
31
+ content: "This morning I woke up and went straight to the grocery store. "
32
+ },
33
+ {
34
+ role: "user",
35
+ name: "TextToEdit",
36
+ content: "While I was there I also picked up some apples, oranges, and bananas. "
37
+ },
38
+ {
39
+ role: "user",
40
+ name: "TextAfterCursor",
41
+ content: "The grocery store was having a sale on fruit, so I decided to stock up."
42
+ },
43
+ {
44
+ role: "user",
45
+ name: "EditingPrompt",
46
+ content: "I bought a big watermelon"
47
+ },
48
+ {
49
+ role: "assistant",
50
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
51
+ },
52
+ {
53
+ role: "user",
54
+ name: "TextAfterCursor",
55
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
56
+ },
57
+ {
58
+ role: "user",
59
+ name: "TextBeforeCursor",
60
+ 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;`
61
+ },
62
+ {
63
+ role: "user",
64
+ name: "InsertionPrompt",
65
+ content: "add section about the optionholder's pro rata share"
66
+ },
67
+ {
68
+ role: "assistant",
69
+ 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"; `
70
+ }
71
+ ];
72
+ var defaultEditingApiConfig = {
73
+ makeSystemPrompt: defaultEditingMakeSystemPrompt,
74
+ fewShotMessages: defaultEditingFewShotMessages,
75
+ forwardedParams: void 0
76
+ };
77
+
78
+ export { defaultEditingApiConfig, defaultEditingFewShotMessages, defaultEditingMakeSystemPrompt };
79
+ //# sourceMappingURL=out.js.map
80
+ //# sourceMappingURL=chunk-K5LNB36H.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/editing-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,iCAAmD,CAC9D,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA,EAIlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBF;AAEO,IAAM,gCAAyD;AAAA,EACpE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user also provides you with a prompt for EDITING some text they are writing. \nYour job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the following information; use this to infer the best relevant EDIT:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store. \",\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: \"While I was there I also picked up some apples, oranges, and bananas. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"The grocery store was having a sale on fruit, so I decided to stock up.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -0,0 +1,63 @@
1
+ // src/types/autosuggestions-config/suggestions-api-config.tsx
2
+ var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
3
+ return `You are a versatile writing assistant.
4
+
5
+ The user is writing some text.
6
+ The purpose is: "${textareaPurpose}"
7
+
8
+ Your job is to guess what the user will write next AS BEST YOU CAN.
9
+ Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
10
+
11
+ Adjust yourself to the user's style and implied intent.
12
+
13
+ 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.
14
+ <TextAfterCursor>
15
+ <TextBeforeCursor>
16
+ <YourSuggestion>
17
+
18
+ If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
19
+
20
+ The following external context is also provided. Use it to help you make better suggestions!!!
21
+ \`\`\`
22
+ ${contextString}
23
+ \`\`\`
24
+ `;
25
+ };
26
+ var defaultSuggestionsFewShotMessages = [
27
+ {
28
+ role: "user",
29
+ name: "TextAfterCursor",
30
+ content: "While I was there I also picked up some apples, oranges, and bananas."
31
+ },
32
+ {
33
+ role: "user",
34
+ content: "This morning I woke up and went straight to the grocery store."
35
+ },
36
+ {
37
+ role: "assistant",
38
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
39
+ },
40
+ {
41
+ role: "user",
42
+ name: "TextAfterCursor",
43
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
44
+ },
45
+ {
46
+ role: "user",
47
+ name: "TextBeforeCursor",
48
+ 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;`
49
+ },
50
+ {
51
+ role: "assistant",
52
+ 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"; `
53
+ }
54
+ ];
55
+ var defaultSuggestionsApiConfig = {
56
+ makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
57
+ fewShotMessages: defaultSuggestionsFewShotMessages,
58
+ forwardedParams: void 0
59
+ };
60
+
61
+ export { defaultSuggestionsApiConfig, defaultSuggestionsFewShotMessages, defaultSuggestionsMakeSystemPrompt };
62
+ //# sourceMappingURL=out.js.map
63
+ //# sourceMappingURL=chunk-KDVMG3XF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/suggestions-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,qCAAuD,CAClE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBlB;AAAA;AAAA;AAGF;AAEO,IAAM,oCAA6D;AAAA,EACxE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,8BAAoD;AAAA,EAC/D,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -0,0 +1,19 @@
1
+ import { cn } from './chunk-7SUZ6CXM.mjs';
2
+ import { __objRest, __spreadValues } from './chunk-MRXNTQOX.mjs';
3
+ import * as React from 'react';
4
+ import * as LabelPrimitive from '@radix-ui/react-label';
5
+ import { cva } from 'class-variance-authority';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ var labelVariants = cva(
9
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
10
+ );
11
+ var Label = React.forwardRef((_a, ref) => {
12
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
13
+ return /* @__PURE__ */ jsx(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
14
+ });
15
+ Label.displayName = LabelPrimitive.Root.displayName;
16
+
17
+ export { Label };
18
+ //# sourceMappingURL=out.js.map
19
+ //# sourceMappingURL=chunk-KFQZHRPJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/ui/label.tsx"],"names":[],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AACvB,YAAY,oBAAoB;AAChC,SAAS,WAA8B;AAYrC;AARF,IAAM,gBAAgB;AAAA,EACpB;AACF;AAEA,IAAM,QAAc,iBAGlB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAfL,IAeG,IAAgB,kBAAhB,IAAgB,CAAd;AACH,6BAAgB,qBAAf,iBAAoB,KAAU,WAAW,GAAG,cAAc,GAAG,SAAS,KAAO,MAAO;AAAA,CACtF;AACD,MAAM,cAA6B,oBAAK","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n);\n\nconst Label = React.forwardRef<\n React.ElementRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>\n>(({ className, ...props }, ref) => (\n <LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />\n));\nLabel.displayName = LabelPrimitive.Root.displayName;\n\nexport { Label };\n"]}
@@ -0,0 +1,27 @@
1
+ import { HoveringInsertionPromptBoxCore } from './chunk-ELEY7HWW.mjs';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ var HoveringInsertionPromptBox = (props) => {
5
+ return /* @__PURE__ */ jsx(
6
+ "div",
7
+ {
8
+ className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
9
+ style: { width: "35rem" },
10
+ children: /* @__PURE__ */ jsx(
11
+ HoveringInsertionPromptBoxCore,
12
+ {
13
+ state: {
14
+ editorState: props.editorState
15
+ },
16
+ insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
17
+ performInsertion: props.performInsertion,
18
+ contextCategories: props.contextCategories
19
+ }
20
+ )
21
+ }
22
+ );
23
+ };
24
+
25
+ export { HoveringInsertionPromptBox };
26
+ //# sourceMappingURL=out.js.map
27
+ //# sourceMappingURL=chunk-KNBNKEXR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx"],"names":[],"mappings":";;;;;AAqBM;AANC,IAAM,6BAA8C,CAAC,UAAU;AACpE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,OAAO,QAAQ;AAAA,MAExB;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,aAAa,MAAM;AAAA,UACrB;AAAA,UACA,4BAA4B,MAAM,UAAU;AAAA,UAC5C,kBAAkB,MAAM;AAAA,UACxB,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EACF;AAEJ","sourcesContent":["import React, { useCallback, useState } from \"react\";\nimport { HoveringInsertionPromptBoxCore } from \"./hovering-insertion-prompt-box-core\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../../types/base/autosuggestions-bare-function\";\n\nexport interface Props {\n editorState: EditingEditorState;\n apiConfig: InsertionEditorApiConfig;\n performInsertion: (insertedText: string) => void;\n closeWindow: () => void;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBox: React.FC<Props> = (props) => {\n return (\n <div\n className=\"flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white\"\n style={{ width: \"35rem\" }}\n >\n <HoveringInsertionPromptBoxCore\n state={{\n editorState: props.editorState,\n }}\n insertionOrEditingFunction={props.apiConfig.insertionOrEditingFunction}\n performInsertion={props.performInsertion}\n contextCategories={props.contextCategories}\n />\n </div>\n );\n};\n"]}
@@ -0,0 +1,18 @@
1
+ // src/lib/retry.tsx
2
+ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
3
+ return new Promise((resolve, reject) => {
4
+ fn().then(resolve).catch((error) => {
5
+ if (retriesLeft === 1) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ setTimeout(() => {
10
+ retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
11
+ }, interval);
12
+ });
13
+ });
14
+ }
15
+
16
+ export { retry };
17
+ //# sourceMappingURL=out.js.map
18
+ //# sourceMappingURL=chunk-KNQIEOFP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/retry.tsx"],"names":[],"mappings":";AAAO,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH","sourcesContent":["export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-L7VVZH4Q.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,217 @@
1
+ import { addAutocompletionsToEditor } from './chunk-2C7O2EVM.mjs';
2
+ import { clearAutocompletionsFromEditor } from './chunk-GQN2HYFJ.mjs';
3
+ import { HoveringToolbar } from './chunk-Y473E2ZQ.mjs';
4
+ import { HoveringEditorProvider, useHoveringEditorContext } from './chunk-XV7MLLXQ.mjs';
5
+ import { makeRenderElementFunction } from './chunk-224UKA7C.mjs';
6
+ import { makeRenderPlaceholderFunction } from './chunk-OHO4G6DR.mjs';
7
+ import { TrackerTextEditedSinceLastCursorMovement } from './chunk-47L4PLG4.mjs';
8
+ import { useAddBrandingCss } from './chunk-7LSRNPNI.mjs';
9
+ import { defaultBaseAutosuggestionsConfig } from './chunk-FP2EKU3L.mjs';
10
+ import { useAutosuggestions } from './chunk-72P3KOHZ.mjs';
11
+ import { useCopilotTextareaEditor } from './chunk-DRV2FOHZ.mjs';
12
+ import { usePopulateCopilotTextareaRef } from './chunk-VPEH6V7T.mjs';
13
+ import { replaceEditorText } from './chunk-5UNJXFUO.mjs';
14
+ import { getTextAroundCollapsedCursor, getFullEditorTextWithNewlines } from './chunk-ECR45NSD.mjs';
15
+ import { __spreadProps, __spreadValues, __objRest } from './chunk-MRXNTQOX.mjs';
16
+ import React, { useMemo, useState, useCallback, useEffect } from 'react';
17
+ import { Editor } from 'slate';
18
+ import { Slate, Editable } from 'slate-react';
19
+ import { twMerge } from 'tailwind-merge';
20
+ import { jsx, jsxs } from 'react/jsx-runtime';
21
+
22
+ var BaseCopilotTextarea = React.forwardRef(
23
+ (props, ref) => {
24
+ return /* @__PURE__ */ jsx(HoveringEditorProvider, { children: /* @__PURE__ */ jsx(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), { ref })) });
25
+ }
26
+ );
27
+ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
28
+ (props, ref) => {
29
+ const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
30
+ const valueOnInitialRender = useMemo(() => {
31
+ var _a2;
32
+ return (_a2 = props.value) != null ? _a2 : "";
33
+ }, []);
34
+ const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);
35
+ const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);
36
+ const initialValue = useMemo(() => {
37
+ return [
38
+ {
39
+ type: "paragraph",
40
+ children: [{ text: valueOnInitialRender }]
41
+ }
42
+ ];
43
+ }, [valueOnInitialRender]);
44
+ const editor = useCopilotTextareaEditor();
45
+ const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
46
+ const insertText = useCallback(
47
+ (autosuggestion) => {
48
+ Editor.insertText(editor, autosuggestion.text, {
49
+ at: autosuggestion.point
50
+ });
51
+ },
52
+ [editor]
53
+ );
54
+ const shouldDisableAutosuggestions = (
55
+ // textarea is manually disabled:
56
+ autosuggestionsConfig.disabled || // hovering editor is displayed:
57
+ hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
58
+ cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
59
+ );
60
+ const {
61
+ currentAutocompleteSuggestion,
62
+ onChangeHandler: onChangeHandlerForAutocomplete,
63
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete
64
+ } = useAutosuggestions(
65
+ autosuggestionsConfig.debounceTime,
66
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
67
+ autosuggestionsConfig.apiConfig.autosuggestionsFunction,
68
+ insertText,
69
+ autosuggestionsConfig.disableWhenEmpty,
70
+ shouldDisableAutosuggestions
71
+ );
72
+ const onKeyDownHandlerForHoveringEditor = useCallback(
73
+ (event) => {
74
+ if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event)) {
75
+ event.preventDefault();
76
+ setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
77
+ }
78
+ },
79
+ [
80
+ hoveringEditorIsDisplayed,
81
+ setHoveringEditorIsDisplayed,
82
+ autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress
83
+ ]
84
+ );
85
+ useEffect(() => {
86
+ clearAutocompletionsFromEditor(editor);
87
+ if (currentAutocompleteSuggestion) {
88
+ addAutocompletionsToEditor(
89
+ editor,
90
+ currentAutocompleteSuggestion.text,
91
+ currentAutocompleteSuggestion.point
92
+ );
93
+ }
94
+ }, [currentAutocompleteSuggestion]);
95
+ const suggestionStyleAugmented = useMemo(() => {
96
+ return __spreadValues({
97
+ fontStyle: "italic",
98
+ color: "gray"
99
+ }, props.suggestionsStyle);
100
+ }, [props.suggestionsStyle]);
101
+ const renderElementMemoized = useMemo(() => {
102
+ return makeRenderElementFunction(suggestionStyleAugmented);
103
+ }, [suggestionStyleAugmented]);
104
+ const renderPlaceholderMemoized = useMemo(() => {
105
+ const placeholderStyleSlatejsOverrides = {
106
+ top: void 0
107
+ };
108
+ const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
109
+ return makeRenderPlaceholderFunction(placeholderStyleAugmented);
110
+ }, [props.placeholderStyle]);
111
+ useEffect(() => {
112
+ var _a2, _b;
113
+ if (props.value === lastKnownFullEditorText) {
114
+ return;
115
+ }
116
+ setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
117
+ replaceEditorText(editor, (_b = props.value) != null ? _b : "");
118
+ }, [props.value]);
119
+ const _a = props, {
120
+ placeholderStyle,
121
+ value,
122
+ hoverMenuClassname,
123
+ onValueChange,
124
+ baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
125
+ className,
126
+ onChange,
127
+ onKeyDown,
128
+ disableBranding
129
+ } = _a, propsToForward = __objRest(_a, [
130
+ "placeholderStyle",
131
+ "value",
132
+ "hoverMenuClassname",
133
+ "onValueChange",
134
+ "baseAutosuggestionsConfig",
135
+ "className",
136
+ "onChange",
137
+ "onKeyDown",
138
+ "disableBranding"
139
+ ]);
140
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
141
+ usePopulateCopilotTextareaRef(editor, ref);
142
+ const moddedClassName = (() => {
143
+ const baseClassName = "copilot-textarea";
144
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
145
+ const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
146
+ const mergedClassName = twMerge(defaultTailwindClassName, className != null ? className : "");
147
+ return `${baseClassName} ${brandingClass} ${mergedClassName}`;
148
+ })();
149
+ return /* @__PURE__ */ jsxs(
150
+ Slate,
151
+ {
152
+ editor,
153
+ initialValue,
154
+ onChange: (value2) => {
155
+ var _a2, _b;
156
+ const newEditorState = getTextAroundCollapsedCursor(editor);
157
+ const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
158
+ setLastKnownFullEditorText((prev) => {
159
+ if (prev !== fullEditorText) {
160
+ setCursorMovedSinceLastTextChange(false);
161
+ }
162
+ return fullEditorText;
163
+ });
164
+ onChangeHandlerForAutocomplete(newEditorState);
165
+ (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
166
+ (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
167
+ },
168
+ children: [
169
+ /* @__PURE__ */ jsx(
170
+ TrackerTextEditedSinceLastCursorMovement,
171
+ {
172
+ setCursorMovedSinceLastTextChange
173
+ }
174
+ ),
175
+ /* @__PURE__ */ jsx(
176
+ HoveringToolbar,
177
+ {
178
+ apiConfig: autosuggestionsConfig.apiConfig,
179
+ contextCategories: autosuggestionsConfig.contextCategories,
180
+ hoverMenuClassname
181
+ }
182
+ ),
183
+ /* @__PURE__ */ jsx(
184
+ Editable,
185
+ __spreadValues({
186
+ renderElement: renderElementMemoized,
187
+ renderPlaceholder: renderPlaceholderMemoized,
188
+ onKeyDown: (event) => {
189
+ var _a2;
190
+ onKeyDownHandlerForHoveringEditor(event);
191
+ onKeyDownHandlerForAutocomplete(event);
192
+ (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
193
+ },
194
+ className: moddedClassName
195
+ }, propsToForward)
196
+ )
197
+ ]
198
+ }
199
+ );
200
+ }
201
+ );
202
+ function makeSemiFakeReactTextAreaEvent(currentText) {
203
+ return {
204
+ target: {
205
+ value: currentText,
206
+ type: "copilot-textarea"
207
+ },
208
+ currentTarget: {
209
+ value: currentText,
210
+ type: "copilot-textarea"
211
+ }
212
+ };
213
+ }
214
+
215
+ export { BaseCopilotTextarea };
216
+ //# sourceMappingURL=out.js.map
217
+ //# sourceMappingURL=chunk-LP2REBM5.mjs.map