@copilotkit/react-textarea 1.3.0 → 1.3.1

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