@copilotkit/react-textarea 1.5.8 → 1.5.10-next.0

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