@copilotkit/react-textarea 1.5.9 → 1.5.10

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