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