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