@copilotkit/react-textarea 0.19.0-alpha.8 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/.turbo/turbo-build.log +298 -299
  2. package/CHANGELOG.md +39 -0
  3. package/dist/chunk-2NURR2DX.mjs +47 -0
  4. package/dist/chunk-2NURR2DX.mjs.map +1 -0
  5. package/dist/chunk-3TK2VELX.mjs +202 -0
  6. package/dist/chunk-3TK2VELX.mjs.map +1 -0
  7. package/dist/chunk-47JRPWI3.mjs +257 -0
  8. package/dist/chunk-47JRPWI3.mjs.map +1 -0
  9. package/dist/chunk-4S5ZJH3I.mjs +18 -0
  10. package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
  11. package/dist/chunk-5EJ5XOGP.mjs +22 -0
  12. package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
  13. package/dist/chunk-5FO6ISW4.mjs +3 -0
  14. package/dist/chunk-5FO6ISW4.mjs.map +1 -0
  15. package/dist/chunk-66BDXIX4.mjs +76 -0
  16. package/dist/chunk-66BDXIX4.mjs.map +1 -0
  17. package/dist/chunk-7QWJ3OV7.mjs +108 -0
  18. package/dist/chunk-7QWJ3OV7.mjs.map +1 -0
  19. package/dist/chunk-BBKDE7YT.mjs +19 -0
  20. package/dist/chunk-BBKDE7YT.mjs.map +1 -0
  21. package/dist/chunk-CSGFJU3L.mjs +65 -0
  22. package/dist/chunk-CSGFJU3L.mjs.map +1 -0
  23. package/dist/chunk-DE5K76I2.mjs +3 -0
  24. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  25. package/dist/chunk-F3MHL6ZY.mjs +25 -0
  26. package/dist/chunk-F3MHL6ZY.mjs.map +1 -0
  27. package/dist/chunk-FN7GDKKG.mjs +29 -0
  28. package/dist/chunk-FN7GDKKG.mjs.map +1 -0
  29. package/dist/chunk-H4VKQGVU.mjs +3 -0
  30. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  31. package/dist/chunk-HRTFMM7P.mjs +82 -0
  32. package/dist/chunk-HRTFMM7P.mjs.map +1 -0
  33. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  34. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  35. package/dist/chunk-IXJ2HCOA.mjs +101 -0
  36. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  37. package/dist/chunk-JAFCXEPU.mjs +10 -0
  38. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  39. package/dist/chunk-JHTAOLEW.mjs +63 -0
  40. package/dist/chunk-JHTAOLEW.mjs.map +1 -0
  41. package/dist/chunk-K2AVA67P.mjs +57 -0
  42. package/dist/chunk-K2AVA67P.mjs.map +1 -0
  43. package/dist/chunk-KCHYD3EB.mjs +107 -0
  44. package/dist/chunk-KCHYD3EB.mjs.map +1 -0
  45. package/dist/chunk-KGKLUWKW.mjs +47 -0
  46. package/dist/chunk-KGKLUWKW.mjs.map +1 -0
  47. package/dist/chunk-KIRROE2K.mjs +37 -0
  48. package/dist/chunk-KIRROE2K.mjs.map +1 -0
  49. package/dist/chunk-L6DZHWEL.mjs +76 -0
  50. package/dist/chunk-L6DZHWEL.mjs.map +1 -0
  51. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  52. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  53. package/dist/chunk-LNAIMEB2.mjs +34 -0
  54. package/dist/chunk-LNAIMEB2.mjs.map +1 -0
  55. package/dist/chunk-MMVDU6DF.mjs +3 -0
  56. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  57. package/dist/chunk-MPME5BW2.mjs +59 -0
  58. package/dist/chunk-MPME5BW2.mjs.map +1 -0
  59. package/dist/chunk-MRXNTQOX.mjs +55 -0
  60. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  61. package/dist/chunk-ND5PXTAW.mjs +17 -0
  62. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  63. package/dist/chunk-NKW5OU2S.mjs +33 -0
  64. package/dist/chunk-NKW5OU2S.mjs.map +1 -0
  65. package/dist/chunk-O5OWT5GE.mjs +114 -0
  66. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  67. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  68. package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
  69. package/dist/chunk-OELUUJZY.mjs +16 -0
  70. package/dist/chunk-OELUUJZY.mjs.map +1 -0
  71. package/dist/chunk-OXPXFYUG.mjs +111 -0
  72. package/dist/chunk-OXPXFYUG.mjs.map +1 -0
  73. package/dist/chunk-QNJ6MXJ2.mjs +21 -0
  74. package/dist/chunk-QNJ6MXJ2.mjs.map +1 -0
  75. package/dist/chunk-RDHPSSHJ.mjs +44 -0
  76. package/dist/chunk-RDHPSSHJ.mjs.map +1 -0
  77. package/dist/chunk-RQHOUUXQ.mjs +29 -0
  78. package/dist/chunk-RQHOUUXQ.mjs.map +1 -0
  79. package/dist/chunk-S6JUGJK2.mjs +13 -0
  80. package/dist/chunk-S6JUGJK2.mjs.map +1 -0
  81. package/dist/chunk-UHD44NC5.mjs +101 -0
  82. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  83. package/dist/chunk-WADHCMPK.mjs +3 -0
  84. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  85. package/dist/chunk-WJHSY5T6.mjs +3 -0
  86. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  87. package/dist/chunk-WJYQWL4I.mjs +27 -0
  88. package/dist/chunk-WJYQWL4I.mjs.map +1 -0
  89. package/dist/chunk-XA7M72ZO.mjs +106 -0
  90. package/dist/chunk-XA7M72ZO.mjs.map +1 -0
  91. package/dist/chunk-XHUMROEY.mjs +91 -0
  92. package/dist/chunk-XHUMROEY.mjs.map +1 -0
  93. package/dist/chunk-YQU7WG7T.mjs +83 -0
  94. package/dist/chunk-YQU7WG7T.mjs.map +1 -0
  95. package/dist/chunk-YTOPHPSG.mjs +45 -0
  96. package/dist/chunk-YTOPHPSG.mjs.map +1 -0
  97. package/dist/chunk-YW3REYX6.mjs +23 -0
  98. package/dist/chunk-YW3REYX6.mjs.map +1 -0
  99. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +13 -0
  100. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +34 -1910
  101. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  102. package/dist/components/base-copilot-textarea/render-element.d.ts +6 -0
  103. package/dist/components/base-copilot-textarea/render-element.mjs +3 -52
  104. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/render-placeholder.d.ts +6 -0
  106. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -46
  107. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  108. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +6 -0
  109. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  110. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  111. package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +3 -0
  112. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  113. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  114. package/dist/components/copilot-textarea/copilot-textarea.d.ts +19 -0
  115. package/dist/components/copilot-textarea/copilot-textarea.mjs +46 -2378
  116. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +13 -0
  118. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -22
  119. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  120. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
  121. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -125
  122. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  123. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +9 -0
  124. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +17 -1055
  125. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  126. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +26 -0
  127. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +11 -761
  128. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  129. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +13 -0
  130. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +12 -774
  131. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  132. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +3 -0
  133. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +13 -774
  134. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  135. package/dist/components/index.d.ts +14 -0
  136. package/dist/components/index.mjs +47 -2379
  137. package/dist/components/index.mjs.map +1 -1
  138. package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
  139. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  140. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  141. package/dist/components/source-search-box/source-search-box.d.ts +14 -0
  142. package/dist/components/source-search-box/source-search-box.mjs +6 -356
  143. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  144. package/dist/components/ui/button.d.ts +14 -0
  145. package/dist/components/ui/button.mjs +4 -88
  146. package/dist/components/ui/button.mjs.map +1 -1
  147. package/dist/components/ui/card.d.ts +10 -0
  148. package/dist/components/ui/card.mjs +7 -53
  149. package/dist/components/ui/card.mjs.map +1 -1
  150. package/dist/components/ui/command.d.ts +48 -0
  151. package/dist/components/ui/command.mjs +5 -266
  152. package/dist/components/ui/command.mjs.map +1 -1
  153. package/dist/components/ui/dialog.d.ts +18 -0
  154. package/dist/components/ui/dialog.mjs +4 -164
  155. package/dist/components/ui/dialog.mjs.map +1 -1
  156. package/dist/components/ui/label.d.ts +8 -0
  157. package/dist/components/ui/label.mjs +4 -63
  158. package/dist/components/ui/label.mjs.map +1 -1
  159. package/dist/components/ui/separator.d.ts +6 -0
  160. package/dist/components/ui/separator.mjs +8 -50
  161. package/dist/components/ui/separator.mjs.map +1 -1
  162. package/dist/components/ui/textarea.d.ts +7 -0
  163. package/dist/components/ui/textarea.mjs +7 -48
  164. package/dist/components/ui/textarea.mjs.map +1 -1
  165. package/dist/context/index.d.ts +1 -0
  166. package/dist/context/index.mjs +2 -0
  167. package/dist/context/index.mjs.map +1 -1
  168. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +13 -0
  169. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -168
  170. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  171. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +8 -0
  172. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  173. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  174. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +7 -0
  175. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -155
  176. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  177. package/dist/hooks/index.d.ts +1 -0
  178. package/dist/hooks/index.mjs +2 -0
  179. package/dist/hooks/index.mjs.map +1 -1
  180. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +21 -0
  181. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -145
  182. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  183. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +22 -0
  184. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -199
  185. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  186. package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
  187. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  188. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  189. package/dist/index.css +4 -18
  190. package/dist/index.css.map +1 -1
  191. package/dist/index.d.ts +16 -0
  192. package/dist/index.mjs +49 -2382
  193. package/dist/index.mjs.map +1 -1
  194. package/dist/lib/debouncer.d.ts +11 -0
  195. package/dist/lib/debouncer.mjs +3 -51
  196. package/dist/lib/debouncer.mjs.map +1 -1
  197. package/dist/lib/editor-to-text.d.ts +7 -0
  198. package/dist/lib/editor-to-text.mjs +3 -43
  199. package/dist/lib/editor-to-text.mjs.map +1 -1
  200. package/dist/lib/get-text-around-cursor.d.ts +15 -0
  201. package/dist/lib/get-text-around-cursor.mjs +3 -109
  202. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  203. package/dist/lib/retry.d.ts +3 -0
  204. package/dist/lib/retry.mjs +3 -17
  205. package/dist/lib/retry.mjs.map +1 -1
  206. package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
  207. package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
  208. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  209. package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
  210. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -23
  211. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  212. package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
  213. package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
  214. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  215. package/dist/lib/slatejs-edits/with-partial-history.d.ts +10 -0
  216. package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
  217. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  218. package/dist/lib/stream-promise-flatten.d.ts +3 -0
  219. package/dist/lib/stream-promise-flatten.mjs +3 -47
  220. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  221. package/dist/lib/utils.d.ts +10 -0
  222. package/dist/lib/utils.mjs +3 -71
  223. package/dist/lib/utils.mjs.map +1 -1
  224. package/dist/lib/utils.test.d.ts +1 -0
  225. package/dist/lib/utils.test.mjs +1 -0
  226. package/dist/lib/utils.test.mjs.map +1 -1
  227. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +22 -0
  228. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
  229. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  230. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +19 -0
  231. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -253
  232. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  233. package/dist/types/autosuggestions-config/editing-api-config.d.ts +15 -0
  234. package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -83
  235. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  236. package/dist/types/autosuggestions-config/index.d.ts +11 -0
  237. package/dist/types/autosuggestions-config/index.mjs +10 -309
  238. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  239. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +15 -0
  240. package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -77
  241. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  242. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.d.ts +27 -0
  243. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -77
  244. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  245. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
  246. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
  247. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  248. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +7 -0
  249. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
  250. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  251. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +15 -0
  252. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
  253. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  254. package/dist/types/base/autosuggestion-state.d.ts +8 -0
  255. package/dist/types/base/autosuggestion-state.mjs +2 -0
  256. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  257. package/dist/types/base/autosuggestions-bare-function.d.ts +17 -0
  258. package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
  259. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  260. package/dist/types/base/base-autosuggestions-config.d.ts +15 -0
  261. package/dist/types/base/base-autosuggestions-config.mjs +3 -11
  262. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  263. package/dist/types/base/base-copilot-textarea-props.d.ts +40 -0
  264. package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
  265. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  266. package/dist/types/base/custom-editor.d.ts +29 -0
  267. package/dist/types/base/custom-editor.mjs +2 -0
  268. package/dist/types/base/custom-editor.mjs.map +1 -1
  269. package/dist/types/base/editor-autocomplete-state.d.ts +10 -0
  270. package/dist/types/base/editor-autocomplete-state.mjs +4 -17
  271. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  272. package/dist/types/base/index.d.ts +4 -0
  273. package/dist/types/base/index.mjs +4 -11
  274. package/dist/types/base/index.mjs.map +1 -1
  275. package/dist/types/html-copilot-textarea-element.d.ts +7 -0
  276. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  277. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  278. package/dist/types/index.d.ts +14 -0
  279. package/dist/types/index.mjs +12 -310
  280. package/dist/types/index.mjs.map +1 -1
  281. package/package.json +4 -4
  282. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +4 -1
  283. package/src/components/hovering-toolbar/hovering-toolbar.tsx +2 -0
  284. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +26 -152
  285. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +2 -0
  286. package/src/components/source-search-box/source-search-box.tsx +13 -17
  287. package/src/types/base/base-autosuggestions-config.tsx +2 -0
package/dist/index.mjs CHANGED
@@ -1,2383 +1,50 @@
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/base-copilot-textarea/base-copilot-textarea.tsx
54
- import React9, { useCallback as useCallback2, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
55
- import { Editor as Editor5 } from "slate";
56
- import { Editable, Slate } from "slate-react";
57
- import { twMerge as twMerge2 } from "tailwind-merge";
58
-
59
- // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
60
- import { useCallback, useEffect, useMemo, useState } from "react";
61
-
62
- // src/lib/debouncer.ts
63
- var Debouncer = class {
64
- constructor(wait) {
65
- this.wait = wait;
66
- this.debounce = (func, ...args) => __async(this, null, function* () {
67
- this.cancel();
68
- this.timeoutId = setTimeout(() => __async(this, null, function* () {
69
- try {
70
- this.activeAbortController = new AbortController();
71
- yield func(...args, this.activeAbortController.signal);
72
- this.activeAbortController = void 0;
73
- } catch (error) {
74
- }
75
- }), this.wait);
76
- });
77
- this.cancel = () => {
78
- if (this.activeAbortController) {
79
- this.activeAbortController.abort();
80
- this.activeAbortController = void 0;
81
- }
82
- if (this.timeoutId !== void 0) {
83
- clearTimeout(this.timeoutId);
84
- this.timeoutId = void 0;
85
- }
86
- };
87
- }
88
- };
89
-
90
- // src/lib/utils.ts
91
- import { clsx } from "clsx";
92
- import { customAlphabet } from "nanoid";
93
- import { twMerge } from "tailwind-merge";
94
- function cn(...inputs) {
95
- return twMerge(clsx(inputs));
96
- }
97
- var nanoid = customAlphabet(
98
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
99
- 7
100
- );
101
- var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
102
- function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
103
- if (a === null || a === void 0 || b === null || b === void 0) {
104
- return a === b;
105
- }
106
- return naiveEqualityCheck(a, b);
107
- }
108
-
109
- // src/types/base/editor-autocomplete-state.ts
110
- function areEqual_autocompleteState(prev, next) {
111
- return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
112
- }
113
-
114
- // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
115
- function useAutosuggestions(debounceTime, acceptAutosuggestionKey, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
116
- const [previousAutocompleteState, setPreviousAutocompleteState] = useState(null);
117
- const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = useState(null);
118
- const awaitForAndAppendSuggestion = useCallback(
119
- (editorAutocompleteState, abortSignal) => __async(this, null, function* () {
120
- if (disabled) {
121
- return;
122
- }
123
- if (disableWhenEmpty && editorAutocompleteState.textBeforeCursor === "" && editorAutocompleteState.textAfterCursor === "") {
124
- return;
125
- }
126
- const suggestion = yield autosuggestionFunction(
127
- editorAutocompleteState,
128
- abortSignal
129
- );
130
- if (!suggestion || abortSignal.aborted) {
131
- throw new DOMException("Aborted", "AbortError");
132
- }
133
- setCurrentAutocompleteSuggestion({
134
- text: suggestion,
135
- point: editorAutocompleteState.cursorPoint
136
- });
137
- }),
138
- [
139
- autosuggestionFunction,
140
- setCurrentAutocompleteSuggestion,
141
- disableWhenEmpty,
142
- disabled
143
- ]
144
- );
145
- const debouncedFunction = useMemo(
146
- () => new Debouncer(
147
- debounceTime
148
- ),
149
- [debounceTime]
150
- );
151
- useEffect(() => {
152
- return () => {
153
- debouncedFunction.cancel();
154
- setCurrentAutocompleteSuggestion(null);
155
- };
156
- }, [debouncedFunction, disabled]);
157
- const onChange = useCallback(
158
- (newEditorState) => {
159
- const editorStateHasChanged = !nullableCompatibleEqualityCheck(
160
- areEqual_autocompleteState,
161
- previousAutocompleteState,
162
- newEditorState
163
- );
164
- setPreviousAutocompleteState(newEditorState);
165
- if (!editorStateHasChanged) {
166
- return;
167
- }
168
- setCurrentAutocompleteSuggestion(null);
169
- if (newEditorState) {
170
- debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);
171
- } else {
172
- debouncedFunction.cancel();
173
- }
174
- },
175
- [
176
- previousAutocompleteState,
177
- setPreviousAutocompleteState,
178
- debouncedFunction,
179
- awaitForAndAppendSuggestion,
180
- setCurrentAutocompleteSuggestion
181
- ]
182
- );
183
- const keyDownHandler = useCallback(
184
- (event) => {
185
- if (currentAutocompleteSuggestion) {
186
- if (event.key === acceptAutosuggestionKey) {
187
- event.preventDefault();
188
- insertAutocompleteSuggestion(currentAutocompleteSuggestion);
189
- setCurrentAutocompleteSuggestion(null);
190
- }
191
- }
192
- },
193
- [
194
- currentAutocompleteSuggestion,
195
- setCurrentAutocompleteSuggestion,
196
- insertAutocompleteSuggestion,
197
- acceptAutosuggestionKey
198
- ]
199
- );
200
- return {
201
- currentAutocompleteSuggestion,
202
- onChangeHandler: onChange,
203
- onKeyDownHandler: keyDownHandler
204
- };
205
- }
206
-
207
- // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
208
- import { useMemo as useMemo2 } from "react";
209
- import { createEditor, Element } from "slate";
210
- import { withReact } from "slate-react";
211
-
212
- // src/lib/slatejs-edits/with-partial-history.ts
213
- import { Editor, Operation, Path, Transforms } from "slate";
214
- import { HistoryEditor } from "slate-history";
215
- var withPartialHistory = (editor, shouldSave2) => {
216
- const e = editor;
217
- const { apply } = e;
218
- e.history = { undos: [], redos: [] };
219
- e.redo = () => {
220
- const { history } = e;
221
- const { redos } = history;
222
- if (redos.length > 0) {
223
- const batch = redos[redos.length - 1];
224
- if (batch.selectionBefore) {
225
- Transforms.setSelection(e, batch.selectionBefore);
226
- }
227
- HistoryEditor.withoutSaving(e, () => {
228
- Editor.withoutNormalizing(e, () => {
229
- for (const op of batch.operations) {
230
- e.apply(op);
231
- }
232
- });
233
- });
234
- history.redos.pop();
235
- e.writeHistory("undos", batch);
236
- }
237
- };
238
- e.undo = () => {
239
- const { history } = e;
240
- const { undos } = history;
241
- if (undos.length > 0) {
242
- const batch = undos[undos.length - 1];
243
- HistoryEditor.withoutSaving(e, () => {
244
- Editor.withoutNormalizing(e, () => {
245
- const inverseOps = batch.operations.map(Operation.inverse).reverse();
246
- for (const op of inverseOps) {
247
- e.apply(op);
248
- }
249
- if (batch.selectionBefore) {
250
- Transforms.setSelection(e, batch.selectionBefore);
251
- }
252
- });
253
- });
254
- e.writeHistory("redos", batch);
255
- history.undos.pop();
256
- }
257
- };
258
- e.apply = (op) => {
259
- const { operations, history } = e;
260
- const { undos } = history;
261
- const lastBatch = undos[undos.length - 1];
262
- const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
263
- let save = HistoryEditor.isSaving(e);
264
- let merge2 = HistoryEditor.isMerging(e);
265
- if (save == null) {
266
- save = shouldSave2(op, lastOp);
267
- }
268
- if (save) {
269
- if (merge2 == null) {
270
- if (lastBatch == null) {
271
- merge2 = false;
272
- } else if (operations.length !== 0) {
273
- merge2 = true;
274
- } else {
275
- merge2 = shouldMerge(op, lastOp);
276
- }
277
- }
278
- if (lastBatch && merge2) {
279
- lastBatch.operations.push(op);
280
- } else {
281
- const batch = {
282
- operations: [op],
283
- selectionBefore: e.selection
284
- };
285
- e.writeHistory("undos", batch);
286
- }
287
- while (undos.length > 100) {
288
- undos.shift();
289
- }
290
- history.redos = [];
291
- }
292
- apply(op);
293
- };
294
- e.writeHistory = (stack, batch) => {
295
- e.history[stack].push(batch);
296
- };
297
- return e;
298
- };
299
- var shouldMerge = (op, prev) => {
300
- if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
301
- return true;
302
- }
303
- if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
304
- return true;
305
- }
306
- return false;
307
- };
308
- var defaultShouldSave = (op, prev) => {
309
- if (op.type === "set_selection") {
310
- return false;
311
- }
312
- return true;
313
- };
314
-
315
- // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
316
- var shouldSave = (op, prev) => {
317
- const excludedNodeType = "suggestion";
318
- if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
319
- return false;
320
- }
321
- if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
322
- return false;
323
- }
324
- if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
325
- return false;
326
- }
327
- if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
328
- return false;
329
- }
330
- if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
331
- return false;
332
- }
333
- if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
334
- return false;
335
- }
336
- return defaultShouldSave(op, prev);
337
- };
338
- function useCopilotTextareaEditor() {
339
- const editor = useMemo2(() => {
340
- const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
341
- const { isVoid } = editor2;
342
- editor2.isVoid = (element) => {
343
- switch (element.type) {
344
- case "suggestion":
345
- return true;
346
- default:
347
- return isVoid(element);
348
- }
349
- };
350
- const { markableVoid } = editor2;
351
- editor2.markableVoid = (element) => {
352
- switch (element.type) {
353
- case "suggestion":
354
- return true;
355
- default:
356
- return markableVoid(element);
357
- }
358
- };
359
- const { isInline } = editor2;
360
- editor2.isInline = (element) => {
361
- switch (element.type) {
362
- case "suggestion":
363
- return element.inline;
364
- default:
365
- return isInline(element);
366
- }
367
- };
368
- return editor2;
369
- }, []);
370
- return editor;
371
- }
372
-
373
- // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
374
- import React from "react";
375
- import { ReactEditor } from "slate-react";
376
-
377
- // src/lib/get-text-around-cursor.ts
378
- import {
379
- Editor as Editor2,
380
- Path as Path2,
381
- Range as Range2,
382
- Text,
383
- Element as Element2,
384
- Point
385
- } from "slate";
386
- function getTextAroundCollapsedCursor(editor) {
387
- const { selection } = editor;
388
- if (!selection || !Range2.isCollapsed(selection)) {
389
- return null;
390
- }
391
- const cursorPoint = selection.anchor;
392
- const beforeRange = {
393
- anchor: Editor2.start(editor, []),
394
- focus: cursorPoint
395
- };
396
- const afterRange = {
397
- anchor: cursorPoint,
398
- focus: Editor2.end(editor, [])
399
- };
400
- const before = extractTextWithNewlines(editor, beforeRange);
401
- const after = extractTextWithNewlines(editor, afterRange);
402
- return {
403
- cursorPoint,
404
- textBeforeCursor: before,
405
- textAfterCursor: after
406
- };
407
- }
408
- function getTextAroundSelection(editor) {
409
- const { selection } = editor;
410
- if (!selection) {
411
- return null;
412
- }
413
- const wellOrderedSelection = wellOrderedRange(selection);
414
- const beforeRange = {
415
- anchor: Editor2.start(editor, []),
416
- focus: wellOrderedSelection.anchor
417
- };
418
- const afterRange = {
419
- anchor: wellOrderedSelection.focus,
420
- focus: Editor2.end(editor, [])
421
- };
422
- const before = extractTextWithNewlines(editor, beforeRange);
423
- const after = extractTextWithNewlines(editor, afterRange);
424
- const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
425
- return {
426
- selection: wellOrderedSelection,
427
- textBeforeCursor: before,
428
- selectedText,
429
- textAfterCursor: after
430
- };
431
- }
432
- function getFullEditorTextWithNewlines(editor) {
433
- const fullDocumentRange = {
434
- anchor: Editor2.start(editor, []),
435
- focus: Editor2.end(editor, [])
436
- };
437
- return extractTextWithNewlines(editor, fullDocumentRange);
438
- }
439
- function extractTextWithNewlines(editor, range) {
440
- const voids = false;
441
- const [start, end] = Range2.edges(range);
442
- let text = "";
443
- let lastBlock = null;
444
- for (const [node, path] of Editor2.nodes(editor, {
445
- at: range,
446
- match: Text.isText,
447
- voids
448
- })) {
449
- let t = node.text;
450
- const [block] = Editor2.above(editor, {
451
- at: path,
452
- match: (n) => Element2.isElement(n) && n.type === "paragraph"
453
- }) || [null];
454
- if (lastBlock !== block && block) {
455
- if (lastBlock) {
456
- text += "\n";
457
- }
458
- lastBlock = block;
459
- }
460
- if (Path2.equals(path, end.path)) {
461
- t = t.slice(0, end.offset);
462
- }
463
- if (Path2.equals(path, start.path)) {
464
- t = t.slice(start.offset);
465
- }
466
- text += t;
467
- }
468
- return text;
469
- }
470
- function wellOrderedRange(range) {
471
- const { anchor, focus } = range;
472
- if (Point.isBefore(anchor, focus)) {
473
- return range;
474
- }
475
- return {
476
- anchor: focus,
477
- focus: anchor
478
- };
479
- }
480
-
481
- // src/lib/slatejs-edits/replace-text.ts
482
- import { Editor as Editor3, Transforms as Transforms2 } from "slate";
483
- function replaceEditorText(editor, newText) {
484
- Transforms2.delete(editor, {
485
- at: {
486
- anchor: Editor3.start(editor, []),
487
- focus: Editor3.end(editor, [])
488
- }
489
- });
490
- if (newText && newText !== "") {
491
- Transforms2.insertNodes(
492
- editor,
493
- [
494
- {
495
- type: "paragraph",
496
- children: [{ text: newText }]
497
- }
498
- ],
499
- {
500
- at: [0]
501
- }
502
- );
503
- }
504
- }
505
-
506
- // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
507
- function usePopulateCopilotTextareaRef(editor, ref) {
508
- React.useImperativeHandle(
509
- ref,
510
- () => {
511
- class Combined {
512
- constructor(customMethods2, editorHtmlElement2) {
513
- this.customMethods = customMethods2;
514
- this.editorHtmlElement = editorHtmlElement2;
515
- }
516
- get(target, propKey) {
517
- if (this.isKeyOfCustomMethods(propKey)) {
518
- const value = this.customMethods[propKey];
519
- if (typeof value === "function") {
520
- return value.bind(this.customMethods);
521
- }
522
- return value;
523
- } else if (this.isKeyOfHTMLElement(propKey)) {
524
- const value = this.editorHtmlElement[propKey];
525
- if (typeof value === "function") {
526
- return value.bind(this.editorHtmlElement);
527
- }
528
- return value;
529
- }
530
- }
531
- set(target, propKey, value) {
532
- if (this.isKeyOfCustomMethods(propKey)) {
533
- this.customMethods[propKey] = value;
534
- } else if (this.isKeyOfHTMLElement(propKey)) {
535
- this.editorHtmlElement[propKey] = value;
536
- } else {
537
- target[propKey] = value;
538
- }
539
- return true;
540
- }
541
- isKeyOfCustomMethods(key) {
542
- return key in this.customMethods;
543
- }
544
- isKeyOfHTMLElement(key) {
545
- return key in this.editorHtmlElement;
546
- }
547
- }
548
- const handler = {
549
- get(target, propKey) {
550
- return target.get(target, propKey);
551
- },
552
- set(target, propKey, value) {
553
- return target.set(target, propKey, value);
554
- }
555
- };
556
- class CustomMethods {
557
- constructor(editor2) {
558
- this.editor = editor2;
559
- }
560
- focus() {
561
- ReactEditor.focus(this.editor);
562
- }
563
- blur() {
564
- ReactEditor.blur(this.editor);
565
- }
566
- get value() {
567
- return getFullEditorTextWithNewlines(this.editor);
568
- }
569
- set value(value) {
570
- replaceEditorText(this.editor, value);
571
- }
572
- }
573
- const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
574
- const customMethods = new CustomMethods(editor);
575
- const combined = new Combined(customMethods, editorHtmlElement);
576
- return new Proxy(combined, handler);
577
- },
578
- [editor]
579
- );
580
- }
581
-
582
- // src/lib/slatejs-edits/add-autocompletions.ts
583
- import { Transforms as Transforms3 } from "slate";
584
- function addAutocompletionsToEditor(editor, newSuggestion, point) {
585
- const editorPosition = editor.selection;
586
- Transforms3.insertNodes(
587
- editor,
588
- [
589
- {
590
- type: "suggestion",
591
- inline: true,
592
- content: newSuggestion,
593
- children: [{ text: "" }]
594
- }
595
- ],
596
- {
597
- at: point
598
- }
599
- );
600
- if (editorPosition) {
601
- editor.selection = editorPosition;
602
- }
603
- }
604
-
605
- // src/lib/slatejs-edits/clear-autocompletions.ts
606
- import { Element as Element3, Node as Node2, Transforms as Transforms4 } from "slate";
607
- function clearAutocompletionsFromEditor(editor) {
608
- const paths = [];
609
- for (const [node, path] of Node2.nodes(editor)) {
610
- if (Element3.isElement(node) && node.type === "suggestion") {
611
- paths.push(path);
612
- }
613
- }
614
- for (const path of paths) {
615
- try {
616
- Transforms4.removeNodes(editor, { at: path });
617
- } catch (e) {
618
- console.log(
619
- "CopilotTextarea.clearAutocompletionsFromEditor: error removing node",
620
- e
621
- );
622
- }
623
- }
624
- }
625
-
626
- // src/types/base/base-autosuggestions-config.tsx
627
- var defaultBaseAutosuggestionsConfig = {
628
- debounceTime: 250,
629
- acceptAutosuggestionKey: "Tab",
630
- disableWhenEmpty: true,
631
- disabled: false,
632
- temporarilyDisableWhenMovingCursorWithoutChangingText: true
633
- };
634
-
635
- // src/components/hovering-toolbar/hovering-toolbar.tsx
636
- import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
637
- import { Transforms as Transforms5 } from "slate";
638
- import { useSlate, useSlateSelection } from "slate-react";
639
-
640
- // src/hooks/misc/use-autosize-textarea.tsx
641
- import { useEffect as useEffect2 } from "react";
642
- var useAutosizeTextArea = (textAreaRef, value) => {
643
- useEffect2(() => {
644
- if (textAreaRef.current !== null) {
645
- textAreaRef.current.style.height = "0px";
646
- const scrollHeight = textAreaRef.current.scrollHeight;
647
- textAreaRef.current.style.height = scrollHeight + "px";
648
- }
649
- }, [textAreaRef, value]);
650
- };
651
- var use_autosize_textarea_default = useAutosizeTextArea;
652
-
653
- // src/components/source-search-box/source-search-box.tsx
654
- import { useState as useState2 } from "react";
655
-
656
- // src/components/ui/command.tsx
657
- import * as React2 from "react";
658
- import { Command as CommandPrimitive } from "cmdk";
659
- import { jsx } from "react/jsx-runtime";
660
- "use client";
661
- var Command = React2.forwardRef((_a, ref) => {
662
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
663
- return /* @__PURE__ */ jsx(CommandPrimitive, __spreadValues({
664
- ref,
665
- className: cn(
666
- "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
667
- className
668
- )
669
- }, props));
670
- });
671
- Command.displayName = CommandPrimitive.displayName;
672
- var CommandInput = React2.forwardRef((_a, ref) => {
673
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
674
- return /* @__PURE__ */ jsx("div", {
675
- className: "flex items-center border-b px-3",
676
- "cmdk-input-wrapper": "",
677
- children: /* @__PURE__ */ jsx(CommandPrimitive.Input, __spreadValues({
678
- ref,
679
- className: cn(
680
- "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",
681
- className
682
- )
683
- }, props))
684
- });
685
- });
686
- CommandInput.displayName = CommandPrimitive.Input.displayName;
687
- var CommandList = React2.forwardRef((_a, ref) => {
688
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
689
- return /* @__PURE__ */ jsx(CommandPrimitive.List, __spreadValues({
690
- ref,
691
- className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)
692
- }, props));
693
- });
694
- CommandList.displayName = CommandPrimitive.List.displayName;
695
- var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({
696
- ref,
697
- className: "py-6 text-center text-sm"
698
- }, props)));
699
- CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
700
- var CommandGroup = React2.forwardRef((_a, ref) => {
701
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
702
- return /* @__PURE__ */ jsx(CommandPrimitive.Group, __spreadValues({
703
- ref,
704
- className: cn(
705
- "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",
706
- className
707
- )
708
- }, props));
709
- });
710
- CommandGroup.displayName = CommandPrimitive.Group.displayName;
711
- var CommandSeparator = React2.forwardRef((_a, ref) => {
712
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
713
- return /* @__PURE__ */ jsx(CommandPrimitive.Separator, __spreadValues({
714
- ref,
715
- className: cn("-mx-1 h-px bg-border", className)
716
- }, props));
717
- });
718
- CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
719
- var CommandItem = React2.forwardRef((_a, ref) => {
720
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
721
- return /* @__PURE__ */ jsx(CommandPrimitive.Item, __spreadValues({
722
- ref,
723
- className: cn(
724
- "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",
725
- className
726
- )
727
- }, props));
728
- });
729
- CommandItem.displayName = CommandPrimitive.Item.displayName;
730
- var CommandShortcut = (_a) => {
731
- var _b = _a, {
732
- className
733
- } = _b, props = __objRest(_b, [
734
- "className"
735
- ]);
736
- return /* @__PURE__ */ jsx("span", __spreadValues({
737
- className: cn(
738
- "ml-auto text-xs tracking-widest text-muted-foreground",
739
- className
740
- )
741
- }, props));
742
- };
743
- CommandShortcut.displayName = "CommandShortcut";
744
-
745
- // src/components/source-search-box/source-search-box.tsx
746
- import {
747
- Calculator,
748
- Calendar,
749
- Smile
750
- } from "lucide-react";
751
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
752
- function SourceSearchBox(props) {
753
- const [selectedValue, setSelectedValue] = useState2("");
754
- return /* @__PURE__ */ jsxs(Command, {
755
- className: "rounded-lg border shadow-md",
756
- value: selectedValue,
757
- onValueChange: (value) => {
758
- setSelectedValue(value);
759
- },
760
- filter: (value, search) => {
761
- if (props.searchTerm === "")
762
- return 1;
763
- if (value.startsWith(props.searchTerm))
764
- return 1;
765
- return 0;
766
- },
767
- children: [
768
- /* @__PURE__ */ jsx2(CommandInput, {
769
- value: props.searchTerm,
770
- className: "rounded-t-lg hidden",
771
- placeholder: "Search for a command..."
772
- }),
773
- /* @__PURE__ */ jsxs(CommandList, {
774
- children: [
775
- /* @__PURE__ */ jsx2(CommandEmpty, {
776
- children: "No results found."
777
- }),
778
- /* @__PURE__ */ jsx2(CommandGroup, {
779
- heading: "Recents",
780
- children: props.recentFiles.map((filePointer) => {
781
- return /* @__PURE__ */ jsx2(CommandItem, {
782
- value: filePointer.name,
783
- onSelect: (value) => {
784
- console.log(filePointer.name);
785
- props.onSelectedFile(filePointer);
786
- },
787
- children: /* @__PURE__ */ jsxs("div", {
788
- className: "flex flex-row gap-3 items-center",
789
- children: [
790
- /* @__PURE__ */ jsx2(Logo, {
791
- size: "30px",
792
- children: /* @__PURE__ */ jsx2(IconForFilePointer, {
793
- filePointer,
794
- className: "mx-auto my-auto"
795
- })
796
- }),
797
- filePointer.name
798
- ]
799
- })
800
- }, `word-${filePointer.sourceApplication}.${filePointer.name}`);
801
- })
802
- }),
803
- /* @__PURE__ */ jsxs(CommandGroup, {
804
- heading: "Suggestions",
805
- children: [
806
- /* @__PURE__ */ jsxs(CommandItem, {
807
- onSelect: (value) => {
808
- console.log(value);
809
- console.log(value);
810
- },
811
- children: [
812
- /* @__PURE__ */ jsx2(Calendar, {
813
- className: "mr-2 h-4 w-4"
814
- }),
815
- /* @__PURE__ */ jsx2("span", {
816
- children: "Calendar"
817
- })
818
- ]
819
- }),
820
- /* @__PURE__ */ jsxs(CommandItem, {
821
- children: [
822
- /* @__PURE__ */ jsx2(Smile, {
823
- className: "mr-2 h-4 w-4"
824
- }),
825
- /* @__PURE__ */ jsx2("span", {
826
- children: "Search Emoji"
827
- })
828
- ]
829
- }),
830
- /* @__PURE__ */ jsxs(CommandItem, {
831
- children: [
832
- /* @__PURE__ */ jsx2(Calculator, {
833
- className: "mr-2 h-4 w-4"
834
- }),
835
- /* @__PURE__ */ jsx2("span", {
836
- children: "Calculator"
837
- })
838
- ]
839
- })
840
- ]
841
- }),
842
- /* @__PURE__ */ jsx2(CommandSeparator, {})
843
- ]
844
- })
845
- ]
846
- });
847
- }
848
- function Logo({
849
- children,
850
- size = "30px"
851
- }) {
852
- return /* @__PURE__ */ jsx2("div", {
853
- className: "flex items-center justify-center",
854
- style: { width: size, height: size },
855
- children
856
- });
857
- }
858
-
859
- // src/components/ui/button.tsx
860
- import * as React3 from "react";
861
- import { Slot } from "@radix-ui/react-slot";
862
- import { cva } from "class-variance-authority";
863
- import { jsx as jsx3 } from "react/jsx-runtime";
864
- var buttonVariants = cva(
865
- "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",
866
- {
867
- variants: {
868
- variant: {
869
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
870
- destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
871
- outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
872
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
873
- ghost: "hover:bg-accent hover:text-accent-foreground",
874
- link: "text-primary underline-offset-4 hover:underline"
875
- },
876
- size: {
877
- default: "h-10 px-4 py-2",
878
- sm: "h-9 rounded-md px-3",
879
- lg: "h-11 rounded-md px-8",
880
- icon: "h-10 w-10"
881
- }
882
- },
883
- defaultVariants: {
884
- variant: "default",
885
- size: "default"
886
- }
887
- }
888
- );
889
- var Button = React3.forwardRef(
890
- (_a, ref) => {
891
- var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
892
- const Comp = asChild ? Slot : "button";
893
- return /* @__PURE__ */ jsx3(Comp, __spreadValues({
894
- className: cn(buttonVariants({ variant, size, className })),
895
- ref
896
- }, props));
897
- }
898
- );
899
- Button.displayName = "Button";
900
-
901
- // src/components/ui/label.tsx
902
- import * as React4 from "react";
903
- import * as LabelPrimitive from "@radix-ui/react-label";
904
- import { cva as cva2 } from "class-variance-authority";
905
- import { jsx as jsx4 } from "react/jsx-runtime";
906
- "use client";
907
- var labelVariants = cva2(
908
- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
909
- );
910
- var Label = React4.forwardRef((_a, ref) => {
911
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
912
- return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({
913
- ref,
914
- className: cn(labelVariants(), className)
915
- }, props));
916
- });
917
- Label.displayName = LabelPrimitive.Root.displayName;
918
-
919
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
920
- import { useEffect as useEffect3, useRef, useState as useState3 } from "react";
921
- import Chip from "@mui/material/Chip";
922
- import Avatar from "@mui/material/Avatar";
923
-
924
- // src/lib/stream-promise-flatten.ts
925
- function streamPromiseFlatten(promise) {
926
- return new ReadableStream({
927
- start(controller) {
928
- return __async(this, null, function* () {
929
- try {
930
- const stream = yield promise;
931
- const reader = stream.getReader();
932
- while (true) {
933
- const { done, value } = yield reader.read();
934
- if (done) {
935
- controller.close();
936
- return;
937
- }
938
- controller.enqueue(value);
939
- }
940
- } catch (error) {
941
- controller.error(error);
942
- }
943
- });
944
- }
945
- });
946
- }
947
-
948
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
949
- import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
950
- var HoveringInsertionPromptBoxCore = ({ performInsertion, state, insertionOrEditingFunction }) => {
951
- const [editSuggestion, setEditSuggestion] = useState3("");
952
- const [suggestionIsLoading, setSuggestionIsLoading] = useState3(false);
953
- const [adjustmentPrompt, setAdjustmentPrompt] = useState3("");
954
- const [generatingSuggestion, setGeneratingSuggestion] = useState3(null);
955
- const adjustmentTextAreaRef = useRef(null);
956
- const suggestionTextAreaRef = useRef(null);
957
- const [filePointers, setFilePointers] = useState3([]);
958
- use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
959
- use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
960
- useEffect3(() => {
961
- var _a;
962
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
963
- }, []);
964
- useEffect3(() => {
965
- if (!generatingSuggestion) {
966
- return;
967
- }
968
- if (generatingSuggestion.locked) {
969
- return;
970
- }
971
- setEditSuggestion("");
972
- const reader = generatingSuggestion.getReader();
973
- const read = () => __async(void 0, null, function* () {
974
- setSuggestionIsLoading(true);
975
- while (true) {
976
- const { done, value } = yield reader.read();
977
- if (done) {
978
- break;
979
- }
980
- setEditSuggestion((prev) => {
981
- const newSuggestion = prev + value;
982
- if (suggestionTextAreaRef.current) {
983
- suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
984
- }
985
- return newSuggestion;
986
- });
987
- }
988
- setSuggestionIsLoading(false);
989
- });
990
- read();
991
- return () => {
992
- const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
993
- try {
994
- yield reader.closed;
995
- } catch (e) {
996
- reader.releaseLock();
997
- }
998
- });
999
- releaseLockIfNotClosed();
1000
- };
1001
- }, [generatingSuggestion]);
1002
- const begingGeneratingAdjustment = () => __async(void 0, null, function* () {
1003
- if (!adjustmentPrompt.trim()) {
1004
- return;
1005
- }
1006
- let editorState2 = state.editorState;
1007
- if (editSuggestion !== "") {
1008
- editorState2.selectedText = editSuggestion;
1009
- }
1010
- const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
1011
- editorState2,
1012
- adjustmentPrompt,
1013
- new AbortController().signal
1014
- );
1015
- const adjustmentSuggestionTextStream = streamPromiseFlatten(
1016
- adjustmentSuggestionTextStreamPromise
1017
- );
1018
- setGeneratingSuggestion(adjustmentSuggestionTextStream);
1019
- });
1020
- const isLoading = suggestionIsLoading;
1021
- const textToEdit = editSuggestion || state.editorState.selectedText;
1022
- const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
1023
- const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
1024
- const AdjustmentPromptComponent = /* @__PURE__ */ jsxs2(Fragment, {
1025
- children: [
1026
- /* @__PURE__ */ jsx5(Label, {
1027
- className: "",
1028
- children: adjustmentLabel
1029
- }),
1030
- /* @__PURE__ */ jsxs2("div", {
1031
- className: "relative w-full flex items-center",
1032
- children: [
1033
- /* @__PURE__ */ jsx5("textarea", {
1034
- disabled: suggestionIsLoading,
1035
- ref: adjustmentTextAreaRef,
1036
- value: adjustmentPrompt,
1037
- onChange: (e) => setAdjustmentPrompt(e.target.value),
1038
- onKeyDown: (e) => {
1039
- if (e.key === "Enter" && e.shiftKey) {
1040
- e.preventDefault();
1041
- setAdjustmentPrompt(adjustmentPrompt + "\n");
1042
- } else if (e.key === "Enter") {
1043
- e.preventDefault();
1044
- begingGeneratingAdjustment();
1045
- }
1046
- },
1047
- placeholder,
1048
- style: { minHeight: "3rem" },
1049
- 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]",
1050
- rows: 1
1051
- }),
1052
- /* @__PURE__ */ jsx5("button", {
1053
- onClick: begingGeneratingAdjustment,
1054
- className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
1055
- children: /* @__PURE__ */ jsx5("i", {
1056
- className: "material-icons",
1057
- children: "arrow_forward"
1058
- })
1059
- })
1060
- ]
1061
- })
1062
- ]
1063
- });
1064
- const SuggestionComponent = /* @__PURE__ */ jsxs2(Fragment, {
1065
- children: [
1066
- /* @__PURE__ */ jsxs2("div", {
1067
- className: "flex justify-between items-end w-full",
1068
- children: [
1069
- /* @__PURE__ */ jsx5(Label, {
1070
- className: "mt-4",
1071
- children: "Suggested:"
1072
- }),
1073
- /* @__PURE__ */ jsx5("div", {
1074
- className: "ml-auto",
1075
- children: isLoading && /* @__PURE__ */ jsx5("div", {
1076
- className: "flex justify-center items-center",
1077
- children: /* @__PURE__ */ jsx5("div", {
1078
- 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]",
1079
- role: "status",
1080
- children: /* @__PURE__ */ jsx5("span", {
1081
- className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]",
1082
- children: "Loading..."
1083
- })
1084
- })
1085
- })
1086
- })
1087
- ]
1088
- }),
1089
- /* @__PURE__ */ jsx5("textarea", {
1090
- ref: suggestionTextAreaRef,
1091
- value: editSuggestion,
1092
- disabled: suggestionIsLoading,
1093
- onChange: (e) => setEditSuggestion(e.target.value),
1094
- className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
1095
- style: { overflow: "auto", maxHeight: "10em" }
1096
- })
1097
- ]
1098
- });
1099
- const SubmitComponent = /* @__PURE__ */ jsx5("div", {
1100
- className: "flex w-full gap-4 justify-start",
1101
- children: /* @__PURE__ */ jsxs2(Button, {
1102
- className: " bg-green-700 text-white",
1103
- onClick: () => {
1104
- performInsertion(editSuggestion);
1105
- },
1106
- children: [
1107
- "Insert ",
1108
- /* @__PURE__ */ jsx5("i", {
1109
- className: "material-icons",
1110
- children: "check"
1111
- })
1112
- ]
1113
- })
1114
- });
1115
- const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
1116
- const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
1117
- return /* @__PURE__ */ jsxs2("div", {
1118
- className: "w-full flex flex-col items-start relative gap-2",
1119
- children: [
1120
- AdjustmentPromptComponent,
1121
- filePointers.length > 0 && /* @__PURE__ */ jsx5(IncludedFilesPreview, {
1122
- includedFiles: filePointers,
1123
- setIncludedFiles: setFilePointers
1124
- }),
1125
- sourceSearchWord !== void 0 && /* @__PURE__ */ jsx5(SourceSearchBox, {
1126
- searchTerm: sourceSearchWord,
1127
- recentFiles: mockFiles,
1128
- onSelectedFile: (filePointer) => {
1129
- var _a;
1130
- setAdjustmentPrompt(
1131
- adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), "")
1132
- );
1133
- setFilePointers((prev) => [...prev, filePointer]);
1134
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1135
- }
1136
- }),
1137
- generatingSuggestion ? SuggestionComponent : null,
1138
- generatingSuggestion ? SubmitComponent : null
1139
- ]
1140
- });
1141
- };
1142
- var IncludedFilesPreview = ({
1143
- includedFiles,
1144
- setIncludedFiles
1145
- }) => {
1146
- return /* @__PURE__ */ jsxs2("div", {
1147
- className: "flex flex-col gap-2 mt-2",
1148
- children: [
1149
- /* @__PURE__ */ jsx5(Label, {
1150
- className: "",
1151
- children: "Included context:"
1152
- }),
1153
- /* @__PURE__ */ jsx5("div", {
1154
- className: "flex flex-wrap gap-2",
1155
- children: includedFiles.map((filePointer, index) => {
1156
- return /* @__PURE__ */ jsx5(FileChipPreview, {
1157
- filePointer,
1158
- onDelete: () => {
1159
- setIncludedFiles(
1160
- (prev) => prev.filter((fp) => fp !== filePointer)
1161
- );
1162
- }
1163
- }, `file-${filePointer.sourceApplication}.${filePointer.name}`);
1164
- })
1165
- })
1166
- ]
1167
- });
1168
- };
1169
- var FileChipPreview = ({
1170
- filePointer,
1171
- onDelete
1172
- }) => {
1173
- return /* @__PURE__ */ jsx5(Chip, {
1174
- label: filePointer.name,
1175
- onDelete,
1176
- avatar: /* @__PURE__ */ jsx5(Avatar, {
1177
- sx: { backgroundColor: "transparent" },
1178
- children: /* @__PURE__ */ jsx5(IconForFilePointer, {
1179
- filePointer,
1180
- className: "w-4 h-1 object-contain"
1181
- })
1182
- })
1183
- });
1184
- };
1185
- function IconForFilePointer({
1186
- filePointer,
1187
- className
1188
- }) {
1189
- if (filePointer.sourceApplication === "Salesforce") {
1190
- return /* @__PURE__ */ jsx5(IconSalesforce, {
1191
- className
1192
- });
1193
- } else if (filePointer.sourceApplication === "GoogleDocs") {
1194
- return /* @__PURE__ */ jsx5(IconGoogleDocs, {
1195
- className
1196
- });
1197
- } else {
1198
- return /* @__PURE__ */ jsx5(IconSalesforce, {
1199
- className
1200
- });
1201
- }
1202
- }
1203
- function IconSalesforce(_a) {
1204
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1205
- return /* @__PURE__ */ jsxs2("svg", __spreadProps(__spreadValues({
1206
- xmlns: "http://www.w3.org/2000/svg",
1207
- xmlnsXlink: "http://www.w3.org/1999/xlink",
1208
- preserveAspectRatio: "xMidYMid meet",
1209
- viewBox: "0 0 273 191"
1210
- }, props), {
1211
- children: [
1212
- /* @__PURE__ */ jsx5("title", {
1213
- children: "Salesforce.com logo"
1214
- }),
1215
- /* @__PURE__ */ jsx5("defs", {
1216
- children: /* @__PURE__ */ jsx5("path", {
1217
- id: "a",
1218
- d: "M.06.5h272v190H.06z"
1219
- })
1220
- }),
1221
- /* @__PURE__ */ jsxs2("g", {
1222
- fillRule: "evenodd",
1223
- children: [
1224
- /* @__PURE__ */ jsx5("mask", {
1225
- id: "b",
1226
- fill: "#fff",
1227
- children: /* @__PURE__ */ jsx5("use", {
1228
- xlinkHref: "#a"
1229
- })
1230
- }),
1231
- /* @__PURE__ */ jsx5("path", {
1232
- fill: "#00A1E0",
1233
- d: "M113 21.3c8.78-9.14 21-14.8 34.5-14.8 18 0 33.6 10 42 24.9a58 58 0 0 1 23.7-5.05c32.4 0 58.7 26.5 58.7 59.2s-26.3 59.2-58.7 59.2c-3.96 0-7.82-.398-11.6-1.15-7.35 13.1-21.4 22-37.4 22a42.7 42.7 0 0 1-18.8-4.32c-7.45 17.5-24.8 29.8-45 29.8-21.1 0-39-13.3-45.9-32a45.1 45.1 0 0 1-9.34.972c-25.1 0-45.4-20.6-45.4-45.9 0-17 9.14-31.8 22.7-39.8a52.6 52.6 0 0 1-4.35-21c0-29.2 23.7-52.8 52.9-52.8 17.1 0 32.4 8.15 42 20.8",
1234
- mask: "url(#b)"
1235
- }),
1236
- /* @__PURE__ */ jsx5("path", {
1237
- fill: "#FFFFFE",
1238
- d: "M39.4 99.3c-.171.446.061.539.116.618.511.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.92-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.26.799 7.09 1.81 0 0 .542.35.739-.173.107-.283 1.04-2.78 1.14-3.06.106-.293-.08-.514-.271-.628-2.1-1.28-5-2.15-8-2.15l-.557.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.592.184c2.68.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.941 0-3.94-.016-7.19-2.07-.393-.229-.617-.394-.92-.579-.16-.097-.56-.272-.734.252l-1.1 3.06m81.7 0c-.171.446.061.539.118.618.509.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.91-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.25.799 7.09 1.81 0 0 .542.35.74-.173.106-.283 1.04-2.78 1.13-3.06.107-.293-.08-.514-.27-.628-2.1-1.28-5-2.15-8-2.15l-.558.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.591.184c2.69.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.943 0-3.95-.016-7.19-2.07-.393-.229-.623-.387-.921-.579-.101-.064-.572-.248-.733.252l-1.1 3.06m55.8-9.36c0 2.7-.504 4.83-1.49 6.34-.984 1.49-2.47 2.22-4.54 2.22s-3.55-.724-4.52-2.21c-.977-1.5-1.47-3.64-1.47-6.34 0-2.7.496-4.82 1.47-6.31.968-1.48 2.44-2.19 4.52-2.19s3.56.717 4.54 2.19c.992 1.49 1.49 3.61 1.49 6.31m4.66-5.01c-.459-1.55-1.17-2.91-2.12-4.05a10.151 10.151 0 0 0-3.58-2.72c-1.42-.665-3.1-1-5-1s-3.57.337-5 1c-1.42.664-2.63 1.58-3.58 2.72-.948 1.14-1.66 2.5-2.12 4.05-.455 1.54-.686 3.22-.686 5.01 0 1.79.231 3.47.686 5.01.457 1.55 1.17 2.91 2.12 4.05.951 1.14 2.16 2.05 3.58 2.7 1.43.648 3.11.978 5 .978 1.89 0 3.57-.33 4.99-.978 1.42-.648 2.63-1.56 3.58-2.7.949-1.14 1.66-2.5 2.12-4.05.454-1.54.685-3.22.685-5.01 0-1.78-.231-3.47-.685-5.01m38.3 12.8c-.153-.453-.595-.282-.595-.282-.677.259-1.4.499-2.17.619-.776.122-1.64.183-2.55.183-2.25 0-4.05-.671-5.33-2-1.29-1.33-2.01-3.47-2-6.37.007-2.64.645-4.62 1.79-6.14 1.13-1.5 2.87-2.28 5.17-2.28 1.92 0 3.39.223 4.93.705 0 0 .365.159.54-.322.409-1.13.711-1.94 1.15-3.18.124-.355-.18-.505-.291-.548-.604-.236-2.03-.623-3.11-.786-1.01-.154-2.18-.234-3.5-.234-1.96 0-3.7.335-5.19.999-1.49.663-2.75 1.58-3.75 2.72-1 1.14-1.76 2.5-2.27 4.05-.505 1.54-.76 3.23-.76 5.02 0 3.86 1.04 6.99 3.1 9.28 2.06 2.3 5.16 3.46 9.2 3.46 2.39 0 4.84-.483 6.6-1.18 0 0 .336-.162.19-.554l-1.15-3.16m8.15-10.4c.223-1.5.634-2.75 1.28-3.72.967-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.65.975.934 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.397-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.959 1.16-1.68 2.53-2.14 4.1-.46 1.55-.692 3.25-.692 5.03 0 1.82.241 3.51.715 5.04.479 1.54 1.25 2.89 2.29 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.52.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.175-.098.34-.267.134-.754l-1.03-2.89c-.158-.431-.594-.275-.594-.275-1.13.422-2.73 1.18-6.48 1.17-2.45-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.471-6.79zm-142 3.3c.223-1.5.635-2.75 1.28-3.72.968-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.649.975.933 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.396-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.957 1.16-1.68 2.53-2.14 4.1-.459 1.55-.69 3.25-.69 5.03 0 1.82.239 3.51.716 5.04.478 1.54 1.25 2.89 2.28 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.51.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.174-.098.34-.267.133-.754l-1.03-2.89c-.159-.431-.595-.275-.595-.275-1.13.422-2.73 1.18-6.48 1.17-2.44-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.472-6.79zm-49.8 13.6c-.619-.494-.705-.615-.91-.936-.313-.483-.473-1.17-.473-2.05 0-1.38.46-2.38 1.41-3.05-.01.002 1.36-1.18 4.58-1.14a32 32 0 0 1 4.28.365v7.17h.002s-2 .431-4.26.567c-3.21.193-4.63-.924-4.62-.921zm6.28-11.1c-.64-.047-1.47-.07-2.46-.07-1.35 0-2.66.168-3.88.498-1.23.332-2.34.846-3.29 1.53a7.63 7.63 0 0 0-2.29 2.6c-.559 1.04-.844 2.26-.844 3.64 0 1.4.243 2.61.723 3.6a6.54 6.54 0 0 0 2.06 2.47c.877.638 1.96 1.11 3.21 1.39 1.24.283 2.64.426 4.18.426 1.62 0 3.23-.136 4.79-.399a95.1 95.1 0 0 0 3.97-.772c.526-.121 1.11-.28 1.11-.28.39-.099.36-.516.36-.516l-.009-14.4c0-3.16-.844-5.51-2.51-6.96-1.66-1.45-4.09-2.18-7.24-2.18-1.18 0-3.09.16-4.23.389 0 0-3.44.668-4.86 1.78 0 0-.312.192-.142.627l1.12 3c.139.389.518.256.518.256s.119-.047.259-.13c3.03-1.65 6.87-1.6 6.87-1.6 1.7 0 3.02.345 3.9 1.02.861.661 1.3 1.66 1.3 3.76v.667c-1.35-.196-2.6-.309-2.6-.309zm127-8.13a.428.428 0 0 0-.237-.568c-.269-.102-1.61-.385-2.64-.449-1.98-.124-3.08.21-4.07.654-.978.441-2.06 1.15-2.66 1.97l-.002-1.92c0-.264-.187-.477-.453-.477h-4.04c-.262 0-.452.213-.452.477v23.5a.48.48 0 0 0 .479.479h4.14a.479.479 0 0 0 .478-.479v-11.8c0-1.58.174-3.15.521-4.14.342-.979.807-1.76 1.38-2.32a4.79 4.79 0 0 1 1.95-1.17 7.68 7.68 0 0 1 2.12-.298c.825 0 1.73.212 1.73.212.304.034.473-.152.576-.426.271-.721 1.04-2.88 1.19-3.31"
1239
- }),
1240
- /* @__PURE__ */ jsx5("path", {
1241
- fill: "#FFFFFE",
1242
- d: "M162.201 67.548a13.258 13.258 0 0 0-1.559-.37 12.217 12.217 0 0 0-2.144-.166c-2.853 0-5.102.806-6.681 2.398-1.568 1.58-2.635 3.987-3.17 7.154l-.193 1.069h-3.581s-.437-.018-.529.459l-.588 3.28c-.041.314.094.51.514.508h3.486l-3.537 19.743c-.277 1.59-.594 2.898-.945 3.889-.346.978-.684 1.711-1.1 2.243-.403.515-.785.894-1.444 1.115-.544.183-1.17.267-1.856.267-.382 0-.89-.064-1.265-.139-.375-.074-.57-.158-.851-.276 0 0-.409-.156-.57.254-.131.335-1.06 2.89-1.17 3.206-.112.312.045.558.243.629.464.166.809.272 1.441.421.878.207 1.618.22 2.311.22 1.452 0 2.775-.204 3.872-.6 1.104-.399 2.065-1.094 2.915-2.035.919-1.015 1.497-2.078 2.05-3.528.547-1.437 1.013-3.221 1.386-5.3l3.554-20.109h5.196s.438.016.529-.459l.588-3.28c.041-.314-.093-.51-.515-.508h-5.043c.025-.114.254-1.888.833-3.558.247-.713.712-1.288 1.106-1.683a3.273 3.273 0 0 1 1.321-.822 5.48 5.48 0 0 1 1.693-.244c.475 0 .941.057 1.296.131.489.104.679.159.807.197.514.157.583.005.684-.244l1.206-3.312c.124-.356-.178-.506-.29-.55m-70.474 34.117c0 .264-.188.479-.452.479h-4.183c-.265 0-.453-.215-.453-.479V67.997c0-.263.188-.476.453-.476h4.183c.264 0 .452.213.452.476v33.668"
1243
- })
1244
- ]
1245
- })
1246
- ]
1247
- }));
1248
- }
1249
- function IconGoogleDocs(_a) {
1250
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1251
- return /* @__PURE__ */ jsxs2("svg", __spreadProps(__spreadValues({
1252
- xmlns: "http://www.w3.org/2000/svg",
1253
- xmlSpace: "preserve",
1254
- viewBox: "0 0 64 88"
1255
- }, props), {
1256
- children: [
1257
- /* @__PURE__ */ jsx5("path", {
1258
- d: "M58 88H6c-3.3 0-6-2.7-6-6V6c0-3.3 2.7-6 6-6h36l22 22v60c0 3.3-2.7 6-6 6z",
1259
- style: {
1260
- fill: "#3086f6"
1261
- }
1262
- }),
1263
- /* @__PURE__ */ jsx5("path", {
1264
- d: "m42 0 22 22H42V0z",
1265
- style: {
1266
- fill: "#0c67d6"
1267
- }
1268
- }),
1269
- /* @__PURE__ */ jsx5("path", {
1270
- d: "M50 39H14v-5h36v5zm0 7H14v5h36v-5zM40 58H14v5h26v-5z",
1271
- style: {
1272
- fill: "#fdffff"
1273
- }
1274
- })
1275
- ]
1276
- }));
1277
- }
1278
- var mockFiles = [
1279
- {
1280
- name: "CopilotTextarea README",
1281
- sourceApplication: "GoogleDocs",
1282
- getContents: () => __async(void 0, null, function* () {
1283
- return "some contents";
1284
- })
1285
- },
1286
- {
1287
- name: "prospecting call transcript",
1288
- sourceApplication: "Salesforce",
1289
- getContents: () => __async(void 0, null, function* () {
1290
- return "some contents";
1291
- })
1292
- },
1293
- {
1294
- name: "customer feedback",
1295
- sourceApplication: "Zendesk",
1296
- getContents: () => __async(void 0, null, function* () {
1297
- return "some contents";
1298
- })
1299
- },
1300
- {
1301
- name: "product specifications",
1302
- sourceApplication: "Google Docs",
1303
- getContents: () => __async(void 0, null, function* () {
1304
- return "some contents";
1305
- })
1306
- },
1307
- {
1308
- name: "meeting minutes",
1309
- sourceApplication: "Microsoft Teams",
1310
- getContents: () => __async(void 0, null, function* () {
1311
- return "some contents";
1312
- })
1313
- },
1314
- {
1315
- name: "project plan",
1316
- sourceApplication: "Trello",
1317
- getContents: () => __async(void 0, null, function* () {
1318
- return "some contents";
1319
- })
1320
- },
1321
- {
1322
- name: "code review comments",
1323
- sourceApplication: "Github",
1324
- getContents: () => __async(void 0, null, function* () {
1325
- return "some contents";
1326
- })
1327
- }
1328
- ];
1329
-
1330
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
1331
- import { jsx as jsx6 } from "react/jsx-runtime";
1332
- var HoveringInsertionPromptBox = (props) => {
1333
- return /* @__PURE__ */ jsx6("div", {
1334
- className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
1335
- style: { width: "35rem" },
1336
- children: /* @__PURE__ */ jsx6(HoveringInsertionPromptBoxCore, {
1337
- state: {
1338
- editorState: props.editorState
1339
- },
1340
- performInsertion: props.performInsertion,
1341
- insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction
1342
- })
1343
- });
1344
- };
1345
-
1346
- // src/components/hovering-toolbar/hovering-toolbar-components.tsx
1347
- import { css, cx } from "@emotion/css";
1348
- import React6 from "react";
1349
- import ReactDOM from "react-dom";
1350
- import { jsx as jsx7 } from "react/jsx-runtime";
1351
- var Button2 = React6.forwardRef(
1352
- (_a, ref) => {
1353
- var _b = _a, {
1354
- className,
1355
- active,
1356
- reversed
1357
- } = _b, props = __objRest(_b, [
1358
- "className",
1359
- "active",
1360
- "reversed"
1361
- ]);
1362
- return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
1363
- ref,
1364
- className: cx(
1365
- className,
1366
- css`
1367
- cursor: pointer;
1368
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
1369
- `
1370
- )
1371
- }));
1372
- }
1373
- );
1374
- var Icon = React6.forwardRef(
1375
- (_a, ref) => {
1376
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1377
- return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
1378
- ref,
1379
- className: cx(
1380
- "material-icons",
1381
- className,
1382
- css`
1383
- font-size: 18px;
1384
- vertical-align: text-bottom;
1385
- `
1386
- )
1387
- }));
1388
- }
1389
- );
1390
- var Menu = React6.forwardRef(
1391
- (_a, ref) => {
1392
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1393
- return /* @__PURE__ */ jsx7("div", __spreadProps(__spreadValues({}, props), {
1394
- "data-test-id": "menu",
1395
- ref,
1396
- className: cx(
1397
- className,
1398
- css`
1399
- & > * {
1400
- display: inline-block;
1401
- }
1402
-
1403
- & > * + * {
1404
- margin-left: 15px;
1405
- }
1406
- `
1407
- )
1408
- }));
1409
- }
1410
- );
1411
- var Portal = ({ children }) => {
1412
- return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
1413
- };
1414
- var Toolbar = React6.forwardRef(
1415
- (_a, ref) => {
1416
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1417
- return /* @__PURE__ */ jsx7(Menu, __spreadProps(__spreadValues({}, props), {
1418
- ref,
1419
- className: cx(
1420
- className,
1421
- css`
1422
- position: relative;
1423
- padding: 1px 18px 17px;
1424
- margin: 0 -20px;
1425
- border-bottom: 2px solid #eee;
1426
- margin-bottom: 20px;
1427
- `
1428
- )
1429
- }));
1430
- }
1431
- );
1432
-
1433
- // src/components/hovering-toolbar/hovering-editor-provider.tsx
1434
- import { createContext, useState as useState4, useContext } from "react";
1435
- import { jsx as jsx8 } from "react/jsx-runtime";
1436
- var HoveringEditorContext = createContext({
1437
- isDisplayed: false,
1438
- setIsDisplayed: () => {
1439
- }
1440
- });
1441
- var HoveringEditorProvider = ({
1442
- children
1443
- }) => {
1444
- const [isDisplayed, setIsDisplayed] = useState4(false);
1445
- return /* @__PURE__ */ jsx8(HoveringEditorContext.Provider, {
1446
- value: { isDisplayed, setIsDisplayed },
1447
- children
1448
- });
1449
- };
1450
- var useHoveringEditorContext = () => useContext(HoveringEditorContext);
1451
-
1452
- // src/components/hovering-toolbar/hovering-toolbar.tsx
1453
- import { jsx as jsx9 } from "react/jsx-runtime";
1454
- var HoveringToolbar = (props) => {
1455
- const ref = useRef2(null);
1456
- const editor = useSlate();
1457
- const selection = useSlateSelection();
1458
- const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
1459
- const [isClient, setIsClient] = useState5(false);
1460
- useEffect4(() => {
1461
- setIsClient(true);
1462
- }, []);
1463
- useEffect4(() => {
1464
- const el = ref.current;
1465
- const { selection: selection2 } = editor;
1466
- if (!el) {
1467
- return;
1468
- }
1469
- if (!selection2) {
1470
- el.removeAttribute("style");
1471
- return;
1472
- }
1473
- const domSelection = window.getSelection();
1474
- if (!domSelection) {
1475
- return;
1476
- }
1477
- const domRange = domSelection.getRangeAt(0);
1478
- const rect = domRange.getBoundingClientRect();
1479
- if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
1480
- return;
1481
- }
1482
- const minGapFromEdge = 60;
1483
- const verticalOffsetFromCorner = 35;
1484
- const horizontalOffsetFromCorner = 15;
1485
- let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
1486
- if (top < minGapFromEdge) {
1487
- top = rect.bottom + window.scrollY + minGapFromEdge;
1488
- } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
1489
- top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
1490
- }
1491
- let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
1492
- if (left < minGapFromEdge) {
1493
- left = minGapFromEdge;
1494
- } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
1495
- left = window.innerWidth - el.offsetWidth - minGapFromEdge;
1496
- }
1497
- el.style.opacity = "1";
1498
- el.style.top = `${top}px`;
1499
- el.style.left = `${left}px`;
1500
- });
1501
- useEffect4(() => {
1502
- const handleClickOutside = (event) => {
1503
- if (ref.current && !ref.current.contains(event.target)) {
1504
- setIsDisplayed(false);
1505
- }
1506
- };
1507
- document.addEventListener("mousedown", handleClickOutside);
1508
- return () => {
1509
- document.removeEventListener("mousedown", handleClickOutside);
1510
- };
1511
- }, [ref, setIsDisplayed]);
1512
- if (!isClient) {
1513
- return null;
1514
- }
1515
- return /* @__PURE__ */ jsx9(Portal, {
1516
- children: /* @__PURE__ */ jsx9(Menu, {
1517
- ref,
1518
- className: "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
1519
- children: isDisplayed && selection && /* @__PURE__ */ jsx9(HoveringInsertionPromptBox, {
1520
- editorState: editorState(editor, selection),
1521
- apiConfig: props.apiConfig,
1522
- closeWindow: () => {
1523
- setIsDisplayed(false);
1524
- },
1525
- performInsertion: (insertedText) => {
1526
- console.log("inserted text", insertedText);
1527
- Transforms5.delete(editor, { at: selection });
1528
- Transforms5.insertText(editor, insertedText, {
1529
- at: selection
1530
- });
1531
- setIsDisplayed(false);
1532
- }
1533
- })
1534
- })
1535
- });
1536
- };
1537
- function editorState(editor, selection) {
1538
- const textAroundCursor = getTextAroundSelection(editor);
1539
- if (textAroundCursor) {
1540
- return textAroundCursor;
1541
- }
1542
- return {
1543
- textBeforeCursor: getFullEditorTextWithNewlines(editor),
1544
- textAfterCursor: "",
1545
- selectedText: ""
1546
- };
1547
- }
1548
-
1549
- // src/components/base-copilot-textarea/render-element.tsx
1550
- import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
1551
- function makeRenderElementFunction(suggestionsStyle) {
1552
- return (props) => {
1553
- switch (props.element.type) {
1554
- case "paragraph":
1555
- return /* @__PURE__ */ jsx10(DefaultElement, __spreadValues({}, props));
1556
- case "suggestion":
1557
- return /* @__PURE__ */ jsx10(SuggestionElement, __spreadProps(__spreadValues({}, props), {
1558
- suggestionsStyle
1559
- }));
1560
- }
1561
- };
1562
- }
1563
- var DefaultElement = (props) => {
1564
- return /* @__PURE__ */ jsx10("div", __spreadProps(__spreadValues({}, props.attributes), {
1565
- children: props.children
1566
- }));
1567
- };
1568
- var SuggestionElement = (props) => {
1569
- return /* @__PURE__ */ jsxs3("span", __spreadProps(__spreadValues({}, props.attributes), {
1570
- style: __spreadValues({}, props.suggestionsStyle),
1571
- contentEditable: false,
1572
- children: [
1573
- props.children,
1574
- props.element.type === "suggestion" && props.element.content
1575
- ]
1576
- }));
1577
- };
1578
-
1579
- // src/components/base-copilot-textarea/render-placeholder.tsx
1580
- import { jsx as jsx11 } from "react/jsx-runtime";
1581
- function makeRenderPlaceholderFunction(placeholderStyle) {
1582
- return (props) => {
1583
- const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
1584
- return /* @__PURE__ */ jsx11("div", __spreadProps(__spreadValues({}, restAttributes), {
1585
- style: __spreadValues(__spreadValues({}, style), placeholderStyle),
1586
- children: props.children
1587
- }));
1588
- };
1589
- }
1590
-
1591
- // src/components/base-copilot-textarea/use-add-branding-css.tsx
1592
- import { useEffect as useEffect5 } from "react";
1593
- function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
1594
- const cssSelector = ".copilot-textarea.with-branding";
1595
- useEffect5(() => {
1596
- if (disableBranding) {
1597
- return;
1598
- }
1599
- const styleEl = document.createElement("style");
1600
- styleEl.id = "dynamic-styles";
1601
- let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
1602
- const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
1603
- return `${kebabCaseKey}: ${value};`;
1604
- }).join(" ");
1605
- dynamicStyles += `font-style: normal; font-size: x-small;`;
1606
- dynamicStyles += `content: "CopilotKit";`;
1607
- dynamicStyles += `bottom: 6px;`;
1608
- dynamicStyles += `right: 6px;`;
1609
- dynamicStyles += `pointer-events: none;`;
1610
- dynamicStyles += `font-weight: 200;`;
1611
- dynamicStyles += `padding: 0;`;
1612
- dynamicStyles += `margin: 0;`;
1613
- dynamicStyles += `border: 0;`;
1614
- dynamicStyles += `line-height: 1;`;
1615
- dynamicStyles += `position: absolute;`;
1616
- styleEl.innerHTML = `
1617
- ${cssSelector}::after {
1618
- ${dynamicStyles}
1619
- }
1620
- `;
1621
- document.head.appendChild(styleEl);
1622
- const textarea = document.querySelector(cssSelector);
1623
- const handleScroll = () => {
1624
- const styleEl2 = document.getElementById("dynamic-styles");
1625
- if (styleEl2 && textarea) {
1626
- const offsetFromBottom = -textarea.scrollTop + 6;
1627
- const offsetFromRight = -textarea.scrollLeft + 6;
1628
- styleEl2.innerHTML = `
1629
- ${cssSelector}::after {
1630
- ${dynamicStyles}
1631
- bottom: ${offsetFromBottom}px;
1632
- right: ${offsetFromRight}px;
1633
- }
1634
- `;
1635
- }
1636
- };
1637
- textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
1638
- return () => {
1639
- var _a;
1640
- (_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
1641
- textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
1642
- };
1643
- }, [disableBranding, suggestionStyleAugmented]);
1644
- }
1645
-
1646
- // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1647
- import { useEffect as useEffect6, useRef as useRef3 } from "react";
1648
- import { useSlateSelector } from "slate-react";
1649
- import { Range as Range4 } from "slate";
1650
-
1651
- // src/lib/editor-to-text.ts
1652
- import { Element as Element4 } from "slate";
1653
- function nodeChildrenToTextComponents(editor, nodes) {
1654
- const indeciesOfInlineElements = new Set(
1655
- nodes.map((node, index) => {
1656
- if (Element4.isElement(node) && editor.isInline(node)) {
1657
- return index;
1658
- }
1659
- return -1;
1660
- }).filter((index) => index !== -1)
1661
- );
1662
- const nonIgnorableItems = nodes.filter((node, index) => {
1663
- const isInline = indeciesOfInlineElements.has(index);
1664
- if (isInline) {
1665
- return false;
1666
- }
1667
- const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
1668
- if (isNeighbourOfInline) {
1669
- return node.text !== "";
1670
- }
1671
- return true;
1672
- });
1673
- return nonIgnorableItems.map((node) => {
1674
- if (Element4.isElement(node)) {
1675
- switch (node.type) {
1676
- case "paragraph":
1677
- return nodeChildrenToTextComponents(editor, node.children);
1678
- case "suggestion":
1679
- return [];
1680
- }
1681
- } else {
1682
- return [node];
1683
- }
1684
- }).reduce((acc, val) => acc.concat(val), []);
1685
- }
1686
- var editorToText = (editor) => {
1687
- const flattened = nodeChildrenToTextComponents(editor, editor.children);
1688
- const text = flattened.map((textComponent) => textComponent.text).join("\n");
1689
- return text;
1690
- };
1691
-
1692
- // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1693
- import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
1694
- function TrackerTextEditedSinceLastCursorMovement(props) {
1695
- const cursorState = useSlateSelector((state) => ({
1696
- selection: state.selection,
1697
- text: editorToText(state)
1698
- }));
1699
- const previousState = usePrevious(cursorState);
1700
- useEffect6(() => {
1701
- if (!previousState) {
1702
- return;
1703
- }
1704
- if (cursorChangedWithoutTextChanged(previousState, cursorState)) {
1705
- props.setCursorMovedSinceLastTextChange(true);
1706
- }
1707
- }, [props.setCursorMovedSinceLastTextChange, cursorState]);
1708
- return /* @__PURE__ */ jsx12(Fragment2, {});
1709
- }
1710
- var cursorChangedWithoutTextChanged = (prev, next) => {
1711
- const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
1712
- const isTextSame = prev.text === next.text;
1713
- return isSelectionChanged && isTextSame;
1714
- };
1715
- var isSelectionEqual = (a, b) => {
1716
- if (!a && !b)
1717
- return true;
1718
- if (!a || !b)
1719
- return false;
1720
- return Range4.equals(a, b);
1721
- };
1722
- function usePrevious(value) {
1723
- const ref = useRef3();
1724
- useEffect6(() => {
1725
- ref.current = value;
1726
- });
1727
- return ref.current;
1728
- }
1729
-
1730
- // src/components/base-copilot-textarea/base-copilot-textarea.tsx
1731
- import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
1732
- var BaseCopilotTextareaWithHoveringContext = React9.forwardRef(
1733
- (props, ref) => {
1734
- const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
1735
- const valueOnInitialRender = useMemo4(() => {
1736
- var _a2;
1737
- return (_a2 = props.value) != null ? _a2 : "";
1738
- }, []);
1739
- const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState6(valueOnInitialRender);
1740
- const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState6(false);
1741
- const initialValue = useMemo4(() => {
1742
- return [
1743
- {
1744
- type: "paragraph",
1745
- children: [{ text: valueOnInitialRender }]
1746
- }
1747
- ];
1748
- }, [valueOnInitialRender]);
1749
- const editor = useCopilotTextareaEditor();
1750
- const {
1751
- isDisplayed: hoveringEditorIsDisplayed,
1752
- setIsDisplayed: setHoveringEditorIsDisplayed
1753
- } = useHoveringEditorContext();
1754
- const insertText = useCallback2(
1755
- (autosuggestion) => {
1756
- Editor5.insertText(editor, autosuggestion.text, {
1757
- at: autosuggestion.point
1758
- });
1759
- },
1760
- [editor]
1761
- );
1762
- const {
1763
- currentAutocompleteSuggestion,
1764
- onChangeHandler: onChangeHandlerForAutocomplete,
1765
- onKeyDownHandler: onKeyDownHandlerForAutocomplete
1766
- } = useAutosuggestions(
1767
- autosuggestionsConfig.debounceTime,
1768
- autosuggestionsConfig.acceptAutosuggestionKey,
1769
- autosuggestionsConfig.apiConfig.autosuggestionsFunction,
1770
- insertText,
1771
- autosuggestionsConfig.disableWhenEmpty,
1772
- autosuggestionsConfig.disabled || hoveringEditorIsDisplayed || cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
1773
- );
1774
- const onKeyDownHandlerForHoveringEditor = useCallback2(
1775
- (event) => {
1776
- if (event.key === "k" && event.metaKey) {
1777
- event.preventDefault();
1778
- setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
1779
- }
1780
- },
1781
- [hoveringEditorIsDisplayed, setHoveringEditorIsDisplayed]
1782
- );
1783
- useEffect7(() => {
1784
- clearAutocompletionsFromEditor(editor);
1785
- if (currentAutocompleteSuggestion) {
1786
- addAutocompletionsToEditor(
1787
- editor,
1788
- currentAutocompleteSuggestion.text,
1789
- currentAutocompleteSuggestion.point
1790
- );
1791
- }
1792
- }, [currentAutocompleteSuggestion]);
1793
- const suggestionStyleAugmented = useMemo4(() => {
1794
- return __spreadValues({
1795
- fontStyle: "italic",
1796
- color: "gray"
1797
- }, props.suggestionsStyle);
1798
- }, [props.suggestionsStyle]);
1799
- const renderElementMemoized = useMemo4(() => {
1800
- return makeRenderElementFunction(suggestionStyleAugmented);
1801
- }, [suggestionStyleAugmented]);
1802
- const renderPlaceholderMemoized = useMemo4(() => {
1803
- const placeholderStyleSlatejsOverrides = {
1804
- top: void 0
1805
- };
1806
- const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
1807
- return makeRenderPlaceholderFunction(placeholderStyleAugmented);
1808
- }, [props.placeholderStyle]);
1809
- useEffect7(() => {
1810
- var _a2, _b;
1811
- if (props.value === lastKnownFullEditorText) {
1812
- return;
1813
- }
1814
- setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
1815
- replaceEditorText(editor, (_b = props.value) != null ? _b : "");
1816
- }, [props.value]);
1817
- const _a = props, {
1818
- placeholderStyle,
1819
- value,
1820
- onValueChange,
1821
- baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
1822
- className,
1823
- onChange,
1824
- onKeyDown,
1825
- disableBranding
1826
- } = _a, propsToForward = __objRest(_a, [
1827
- "placeholderStyle",
1828
- "value",
1829
- "onValueChange",
1830
- "baseAutosuggestionsConfig",
1831
- "className",
1832
- "onChange",
1833
- "onKeyDown",
1834
- "disableBranding"
1835
- ]);
1836
- useAddBrandingCss(suggestionStyleAugmented, disableBranding);
1837
- usePopulateCopilotTextareaRef(editor, ref);
1838
- const moddedClassName = (() => {
1839
- const baseClassName = "copilot-textarea";
1840
- const brandingClass = disableBranding ? "no-branding" : "with-branding";
1841
- const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
1842
- const mergedClassName = twMerge2(
1843
- defaultTailwindClassName,
1844
- className != null ? className : ""
1845
- );
1846
- return `${baseClassName} ${brandingClass} ${mergedClassName}`;
1847
- })();
1848
- return /* @__PURE__ */ jsxs4(Slate, {
1849
- editor,
1850
- initialValue,
1851
- onChange: (value2) => {
1852
- var _a2, _b;
1853
- const newEditorState = getTextAroundCollapsedCursor(editor);
1854
- const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
1855
- setLastKnownFullEditorText((prev) => {
1856
- if (prev !== fullEditorText) {
1857
- setCursorMovedSinceLastTextChange(false);
1858
- }
1859
- return fullEditorText;
1860
- });
1861
- onChangeHandlerForAutocomplete(newEditorState);
1862
- (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
1863
- (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
1864
- },
1865
- children: [
1866
- /* @__PURE__ */ jsx13(TrackerTextEditedSinceLastCursorMovement, {
1867
- setCursorMovedSinceLastTextChange
1868
- }),
1869
- /* @__PURE__ */ jsx13(HoveringToolbar, {
1870
- apiConfig: autosuggestionsConfig.apiConfig
1871
- }),
1872
- /* @__PURE__ */ jsx13(Editable, __spreadValues({
1873
- renderElement: renderElementMemoized,
1874
- renderPlaceholder: renderPlaceholderMemoized,
1875
- onKeyDown: (event) => {
1876
- var _a2;
1877
- onKeyDownHandlerForHoveringEditor(event);
1878
- onKeyDownHandlerForAutocomplete(event);
1879
- (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
1880
- },
1881
- className: moddedClassName
1882
- }, propsToForward))
1883
- ]
1884
- });
1885
- }
1886
- );
1887
- function makeSemiFakeReactTextAreaEvent(currentText) {
1888
- return {
1889
- target: {
1890
- value: currentText,
1891
- type: "copilot-textarea"
1892
- },
1893
- currentTarget: {
1894
- value: currentText,
1895
- type: "copilot-textarea"
1896
- }
1897
- };
1898
- }
1899
- var BaseCopilotTextarea = React9.forwardRef(
1900
- (props, ref) => {
1901
- return /* @__PURE__ */ jsx13(HoveringEditorProvider, {
1902
- children: /* @__PURE__ */ jsx13(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), {
1903
- ref
1904
- }))
1905
- });
1906
- }
1907
- );
1908
-
1909
- // src/components/copilot-textarea/copilot-textarea.tsx
1910
- import React10 from "react";
1911
-
1912
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1913
- import { CopilotContext } from "@copilotkit/react-core";
1914
- import { useCallback as useCallback3, useContext as useContext2 } from "react";
1915
-
1916
- // src/types/autosuggestions-config/suggestions-api-config.tsx
1917
- var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1918
- return `You are a versatile writing assistant.
1919
-
1920
- The user is writing some text.
1921
- The purpose is: "${textareaPurpose}"
1922
-
1923
- Your job is to guess what the user will write next AS BEST YOU CAN.
1924
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
1925
-
1926
- Adjust yourself to the user's style and implied intent.
1927
-
1928
- 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.
1929
- <TextAfterCursor>
1930
- <TextBeforeCursor>
1931
- <YourSuggestion>
1932
-
1933
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
1934
-
1935
- The following external context is also provided. Use it to help you make better suggestions!!!
1936
- \`\`\`
1937
- ${contextString}
1938
- \`\`\`
1939
- `;
1940
- };
1941
- var defaultSuggestionsFewShotMessages = [
1942
- {
1943
- role: "user",
1944
- name: "TextAfterCursor",
1945
- content: "While I was there I also picked up some apples, oranges, and bananas."
1946
- },
1947
- {
1948
- role: "user",
1949
- content: "This morning I woke up and went straight to the grocery store."
1950
- },
1951
- {
1952
- role: "assistant",
1953
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
1954
- },
1955
- {
1956
- role: "user",
1957
- name: "TextAfterCursor",
1958
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
1959
- },
1960
- {
1961
- role: "user",
1962
- name: "TextBeforeCursor",
1963
- 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;`
1964
- },
1965
- {
1966
- role: "assistant",
1967
- 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"; `
1968
- }
1969
- ];
1970
- var defaultSuggestionsApiConfig = {
1971
- makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
1972
- fewShotMessages: defaultSuggestionsFewShotMessages,
1973
- forwardedParams: void 0
1974
- };
1975
-
1976
- // src/types/autosuggestions-config/insertions-api-config.tsx
1977
- var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
1978
- return `You are a versatile writing assistant.
1979
-
1980
- The user is writing some text.
1981
- The purpose is: "${textareaPurpose}"
1982
-
1983
- The user also provides you with a prompt for INSERTIONS into the text they are writing.
1984
- Your job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.
1985
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
1986
-
1987
- Adjust yourself to the user's style and implied intent.
1988
-
1989
- 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.
1990
- <TextAfterCursor>
1991
- <TextBeforeCursor>
1992
- <InsertionPrompt>
1993
- <YourSuggestion>
1994
-
1995
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
1996
-
1997
- The following external context is also provided. Use it to help you make better suggestions!!!
1998
- \`\`\`
1999
- ${contextString}
2000
- \`\`\`
2001
- `;
2002
- };
2003
- var defaultInsertionsFewShotMessages = [
2004
- {
2005
- role: "user",
2006
- name: "TextAfterCursor",
2007
- content: "While I was there I also picked up some apples, oranges, and bananas."
2008
- },
2009
- {
2010
- role: "user",
2011
- name: "TextBeforeCursor",
2012
- content: "This morning I woke up and went straight to the grocery store."
2013
- },
2014
- {
2015
- role: "user",
2016
- name: "InsertionPrompt",
2017
- content: "I bought a big watermelon"
2018
- },
2019
- {
2020
- role: "assistant",
2021
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
2022
- },
2023
- {
2024
- role: "user",
2025
- name: "TextAfterCursor",
2026
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
2027
- },
2028
- {
2029
- role: "user",
2030
- name: "TextBeforeCursor",
2031
- 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;`
2032
- },
2033
- {
2034
- role: "user",
2035
- name: "InsertionPrompt",
2036
- content: "add section about the optionholder's pro rata share"
2037
- },
2038
- {
2039
- role: "assistant",
2040
- 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"; `
2041
- }
2042
- ];
2043
- var defaultInsertionsApiConfig = {
2044
- makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
2045
- fewShotMessages: defaultInsertionsFewShotMessages,
2046
- forwardedParams: void 0
2047
- };
2048
-
2049
- // src/types/autosuggestions-config/editing-api-config.tsx
2050
- var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
2051
- return `You are a versatile writing assistant.
2052
-
2053
- The user is writing some text.
2054
- The purpose is: "${textareaPurpose}"
2055
-
2056
- The user also provides you with a prompt for EDITING some text they are writing.
2057
- Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
2058
-
2059
- Adjust yourself to the user's style and implied intent.
2060
-
2061
- The user will provide the following information; use this to infer the best relevant EDIT:
2062
- <TextBeforeCursor>
2063
- <TextToEdit>
2064
- <TextAfterCursor>
2065
- <EditingPrompt>
2066
-
2067
- <YourEditSuggestion>
2068
-
2069
- If we need to add a whitespace character to the suggested edit text, make sure to explicitly add it in.
2070
-
2071
- The following external context is also provided. Use it to help you make better suggestions!!!
2072
- \`\`\`
2073
- ${contextString}
2074
- \`\`\`
2075
- `;
2076
- };
2077
- var defaultEditingFewShotMessages = [
2078
- {
2079
- role: "user",
2080
- name: "TextBeforeCursor",
2081
- content: "This morning I woke up and went straight to the grocery store. "
2082
- },
2083
- {
2084
- role: "user",
2085
- name: "TextToEdit",
2086
- content: "While I was there I also picked up some apples, oranges, and bananas. "
2087
- },
2088
- {
2089
- role: "user",
2090
- name: "TextAfterCursor",
2091
- content: "The grocery store was having a sale on fruit, so I decided to stock up."
2092
- },
2093
- {
2094
- role: "user",
2095
- name: "EditingPrompt",
2096
- content: "I bought a big watermelon"
2097
- },
2098
- {
2099
- role: "assistant",
2100
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
2101
- },
2102
- {
2103
- role: "user",
2104
- name: "TextAfterCursor",
2105
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
2106
- },
2107
- {
2108
- role: "user",
2109
- name: "TextBeforeCursor",
2110
- 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;`
2111
- },
2112
- {
2113
- role: "user",
2114
- name: "InsertionPrompt",
2115
- content: "add section about the optionholder's pro rata share"
2116
- },
2117
- {
2118
- role: "assistant",
2119
- 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"; `
2120
- }
2121
- ];
2122
- var defaultEditingApiConfig = {
2123
- makeSystemPrompt: defaultEditingMakeSystemPrompt,
2124
- fewShotMessages: defaultEditingFewShotMessages,
2125
- forwardedParams: void 0
2126
- };
2127
-
2128
- // src/types/autosuggestions-config/autosuggestions-config.tsx
2129
- var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
2130
- externalContextCategories: void 0,
2131
- chatApiConfigs: {
2132
- suggestionsApiConfig: defaultSuggestionsApiConfig,
2133
- insertionApiConfig: defaultInsertionsApiConfig,
2134
- editingApiConfig: defaultEditingApiConfig
2135
- }
2136
- });
2137
-
2138
- // src/types/autosuggestions-config/subtypes/chatlike-api-endpoint.tsx
2139
- import {
2140
- copilotApiConfigExtrapolator
2141
- } from "@copilotkit/react-core";
2142
- var ChatlikeApiEndpoint = class {
2143
- constructor(run) {
2144
- this.run = run;
2145
- }
2146
- static fromCopilotApiConfig(copilotApiConfig) {
2147
- return new ChatlikeApiEndpoint(
2148
- (abortSignal, messages, forwardedProps) => __async(this, null, function* () {
2149
- const res = yield fetch(
2150
- copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
2151
- {
2152
- method: "POST",
2153
- body: JSON.stringify(__spreadProps(__spreadValues({}, forwardedProps), {
2154
- messages
2155
- })),
2156
- signal: abortSignal
2157
- }
2158
- );
2159
- const bodySteram = res.body;
2160
- if (!bodySteram) {
2161
- throw new Error("The response body is empty.");
2162
- }
2163
- const stringStream = bodySteram.pipeThrough(new TextDecoderStream());
2164
- return stringStream;
2165
- })
2166
- );
2167
- }
2168
- static custom(run) {
2169
- return new ChatlikeApiEndpoint(run);
2170
- }
2171
- };
2172
-
2173
- // src/lib/retry.tsx
2174
- function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
2175
- return new Promise((resolve, reject) => {
2176
- fn().then(resolve).catch((error) => {
2177
- if (retriesLeft === 1) {
2178
- reject(error);
2179
- return;
2180
- }
2181
- setTimeout(() => {
2182
- retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
2183
- }, interval);
2184
- });
2185
- });
2186
- }
2187
-
2188
- // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
2189
- function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
2190
- const { getContextString, copilotApiConfig } = useContext2(CopilotContext);
2191
- return useCallback3(
2192
- (editorState2, abortSignal) => __async(this, null, function* () {
2193
- const res = yield retry(() => __async(this, null, function* () {
2194
- const messages = [
2195
- {
2196
- role: "system",
2197
- content: apiConfig.makeSystemPrompt(
2198
- textareaPurpose,
2199
- getContextString(contextCategories)
2200
- )
2201
- },
2202
- ...apiConfig.fewShotMessages,
2203
- {
2204
- role: "user",
2205
- name: "TextAfterCursor",
2206
- content: editorState2.textAfterCursor
2207
- },
2208
- {
2209
- role: "user",
2210
- name: "TextBeforeCursor",
2211
- content: editorState2.textBeforeCursor
2212
- }
2213
- ];
2214
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
2215
- const stream = yield apiEndpoint.run(
2216
- abortSignal,
2217
- messages,
2218
- apiConfig.forwardedParams
2219
- );
2220
- const reader = stream.getReader();
2221
- let result = "";
2222
- while (true) {
2223
- const { done, value } = yield reader.read();
2224
- if (done) {
2225
- break;
2226
- }
2227
- result += value;
2228
- }
2229
- return result;
2230
- }));
2231
- return res;
2232
- }),
2233
- [apiConfig, getContextString, contextCategories, textareaPurpose]
2234
- );
2235
- }
2236
-
2237
- // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2238
- import { CopilotContext as CopilotContext2 } from "@copilotkit/react-core";
2239
- import { useCallback as useCallback4, useContext as useContext3 } from "react";
2240
- function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2241
- const { getContextString, copilotApiConfig } = useContext3(CopilotContext2);
2242
- const insertionFunction = useCallback4(
2243
- (editorState2, insertionPrompt, abortSignal) => __async(this, null, function* () {
2244
- const res = yield retry(() => __async(this, null, function* () {
2245
- const messages = [
2246
- {
2247
- role: "system",
2248
- content: insertionApiConfig.makeSystemPrompt(
2249
- textareaPurpose,
2250
- getContextString(contextCategories)
2251
- )
2252
- },
2253
- ...insertionApiConfig.fewShotMessages,
2254
- {
2255
- role: "user",
2256
- name: "TextAfterCursor",
2257
- content: editorState2.textAfterCursor
2258
- },
2259
- {
2260
- role: "user",
2261
- name: "TextBeforeCursor",
2262
- content: editorState2.textBeforeCursor
2263
- },
2264
- {
2265
- role: "user",
2266
- name: "InsertionPrompt",
2267
- content: insertionPrompt
2268
- }
2269
- ];
2270
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
2271
- return yield apiEndpoint.run(
2272
- abortSignal,
2273
- messages,
2274
- insertionApiConfig.forwardedParams
2275
- );
2276
- }));
2277
- return res;
2278
- }),
2279
- [insertionApiConfig, getContextString, contextCategories, textareaPurpose]
2280
- );
2281
- const editingFunction = useCallback4(
2282
- (editorState2, editingPrompt, abortSignal) => __async(this, null, function* () {
2283
- const res = yield retry(() => __async(this, null, function* () {
2284
- const messages = [
2285
- {
2286
- role: "system",
2287
- content: editingApiConfig.makeSystemPrompt(
2288
- textareaPurpose,
2289
- getContextString(contextCategories)
2290
- )
2291
- },
2292
- ...editingApiConfig.fewShotMessages,
2293
- {
2294
- role: "user",
2295
- name: "TextBeforeCursor",
2296
- content: editorState2.textBeforeCursor
2297
- },
2298
- {
2299
- role: "user",
2300
- name: "TextToEdit",
2301
- content: editorState2.selectedText
2302
- },
2303
- {
2304
- role: "user",
2305
- name: "TextAfterCursor",
2306
- content: editorState2.textAfterCursor
2307
- },
2308
- {
2309
- role: "user",
2310
- name: "EditingPrompt",
2311
- content: editingPrompt
2312
- }
2313
- ];
2314
- const apiEndpoint = ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);
2315
- return yield apiEndpoint.run(
2316
- abortSignal,
2317
- messages,
2318
- editingApiConfig.forwardedParams
2319
- );
2320
- }));
2321
- return res;
2322
- }),
2323
- [editingApiConfig, getContextString, contextCategories, textareaPurpose]
2324
- );
2325
- const insertionOrEditingFunction = useCallback4(
2326
- (editorState2, insertionPrompt, abortSignal) => __async(this, null, function* () {
2327
- if (editorState2.selectedText === "") {
2328
- return yield insertionFunction(
2329
- editorState2,
2330
- insertionPrompt,
2331
- abortSignal
2332
- );
2333
- } else {
2334
- return yield editingFunction(editorState2, insertionPrompt, abortSignal);
2335
- }
2336
- }),
2337
- [insertionFunction, editingFunction]
2338
- );
2339
- return insertionOrEditingFunction;
2340
- }
2341
-
2342
- // src/components/copilot-textarea/copilot-textarea.tsx
2343
- import merge from "lodash.merge";
2344
- import { Fragment as Fragment3, jsx as jsx14 } from "react/jsx-runtime";
2345
- var CopilotTextarea = React10.forwardRef(
2346
- (props, ref) => {
2347
- const autosuggestionsConfig = merge(
2348
- defaultAutosuggestionsConfig,
2349
- props.autosuggestionsConfig
2350
- );
2351
- const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
2352
- autosuggestionsConfig.textareaPurpose,
2353
- autosuggestionsConfig.externalContextCategories,
2354
- autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
2355
- );
2356
- const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
2357
- autosuggestionsConfig.textareaPurpose,
2358
- autosuggestionsConfig.externalContextCategories,
2359
- autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
2360
- autosuggestionsConfig.chatApiConfigs.editingApiConfig
2361
- );
2362
- return /* @__PURE__ */ jsx14(Fragment3, {
2363
- children: /* @__PURE__ */ jsx14(BaseCopilotTextarea, __spreadProps(__spreadValues({
2364
- ref
2365
- }, props), {
2366
- baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
2367
- apiConfig: {
2368
- insertionOrEditingFunction,
2369
- autosuggestionsFunction
2370
- }
2371
- })
2372
- }))
2373
- });
2374
- }
2375
- );
2376
- export {
2377
- BaseCopilotTextarea,
2378
- ChatlikeApiEndpoint,
2379
- CopilotTextarea,
2380
- defaultAutosuggestionsConfig,
2381
- defaultBaseAutosuggestionsConfig
2382
- };
1
+ import './chunk-MMVDU6DF.mjs';
2
+ export { CopilotTextarea } from './chunk-RDHPSSHJ.mjs';
3
+ import './chunk-K2AVA67P.mjs';
4
+ import './chunk-OXPXFYUG.mjs';
5
+ import './chunk-DE5K76I2.mjs';
6
+ import './chunk-5FO6ISW4.mjs';
7
+ export { ChatlikeApiEndpoint } from './chunk-KIRROE2K.mjs';
8
+ export { defaultAutosuggestionsConfig } from './chunk-BBKDE7YT.mjs';
9
+ import './chunk-HRTFMM7P.mjs';
10
+ import './chunk-66BDXIX4.mjs';
11
+ import './chunk-JHTAOLEW.mjs';
12
+ import './chunk-WADHCMPK.mjs';
13
+ export { BaseCopilotTextarea } from './chunk-3TK2VELX.mjs';
14
+ import './chunk-CSGFJU3L.mjs';
15
+ import './chunk-KCHYD3EB.mjs';
16
+ import './chunk-YQU7WG7T.mjs';
17
+ import './chunk-WJYQWL4I.mjs';
18
+ import './chunk-F3MHL6ZY.mjs';
19
+ import './chunk-RQHOUUXQ.mjs';
20
+ import './chunk-UHD44NC5.mjs';
21
+ import './chunk-JAFCXEPU.mjs';
22
+ import './chunk-OD7ZMOVE.mjs';
23
+ import './chunk-MPME5BW2.mjs';
24
+ import './chunk-7QWJ3OV7.mjs';
25
+ import './chunk-L7VVZH4Q.mjs';
26
+ import './chunk-QNJ6MXJ2.mjs';
27
+ import './chunk-47JRPWI3.mjs';
28
+ import './chunk-ND5PXTAW.mjs';
29
+ import './chunk-2NURR2DX.mjs';
30
+ import './chunk-5EJ5XOGP.mjs';
31
+ import './chunk-YW3REYX6.mjs';
32
+ import './chunk-XHUMROEY.mjs';
33
+ import './chunk-L6DZHWEL.mjs';
34
+ import './chunk-XA7M72ZO.mjs';
35
+ import './chunk-O5OWT5GE.mjs';
36
+ import './chunk-FN7GDKKG.mjs';
37
+ import './chunk-KGKLUWKW.mjs';
38
+ import './chunk-WJHSY5T6.mjs';
39
+ export { defaultBaseAutosuggestionsConfig } from './chunk-S6JUGJK2.mjs';
40
+ import './chunk-LNAIMEB2.mjs';
41
+ import './chunk-OELUUJZY.mjs';
42
+ import './chunk-IU3WTXLQ.mjs';
43
+ import './chunk-H4VKQGVU.mjs';
44
+ import './chunk-NKW5OU2S.mjs';
45
+ import './chunk-YTOPHPSG.mjs';
46
+ import './chunk-IXJ2HCOA.mjs';
47
+ import './chunk-4S5ZJH3I.mjs';
48
+ import './chunk-MRXNTQOX.mjs';
49
+ //# sourceMappingURL=out.js.map
2383
50
  //# sourceMappingURL=index.mjs.map