@copilotkit/react-textarea 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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