@copilotkitnext/react 0.0.22-alpha.3 → 0.0.22-alpha.5

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 (423) hide show
  1. package/dist/index.d.mts +635 -46
  2. package/dist/index.d.ts +635 -46
  3. package/dist/index.js +325 -22
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +4286 -109
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +6 -6
  8. package/dist/chunk-32YJ5VJ4.mjs +0 -157
  9. package/dist/chunk-32YJ5VJ4.mjs.map +0 -1
  10. package/dist/chunk-36HFWACS.mjs +0 -1
  11. package/dist/chunk-36HFWACS.mjs.map +0 -1
  12. package/dist/chunk-3TA5QBSZ.mjs +0 -122
  13. package/dist/chunk-3TA5QBSZ.mjs.map +0 -1
  14. package/dist/chunk-46BZRXWT.mjs +0 -16
  15. package/dist/chunk-46BZRXWT.mjs.map +0 -1
  16. package/dist/chunk-4UDBR75C.mjs +0 -106
  17. package/dist/chunk-4UDBR75C.mjs.map +0 -1
  18. package/dist/chunk-4XJK5IVQ.mjs +0 -83
  19. package/dist/chunk-4XJK5IVQ.mjs.map +0 -1
  20. package/dist/chunk-5AAT4Z3C.mjs +0 -107
  21. package/dist/chunk-5AAT4Z3C.mjs.map +0 -1
  22. package/dist/chunk-5JNWVLQI.mjs +0 -72
  23. package/dist/chunk-5JNWVLQI.mjs.map +0 -1
  24. package/dist/chunk-5SC3CO5Q.mjs +0 -69
  25. package/dist/chunk-5SC3CO5Q.mjs.map +0 -1
  26. package/dist/chunk-6VUKDHOD.mjs +0 -1
  27. package/dist/chunk-6VUKDHOD.mjs.map +0 -1
  28. package/dist/chunk-AEFM73CL.mjs +0 -32
  29. package/dist/chunk-AEFM73CL.mjs.map +0 -1
  30. package/dist/chunk-AI3Z3CHN.mjs +0 -97
  31. package/dist/chunk-AI3Z3CHN.mjs.map +0 -1
  32. package/dist/chunk-AXFRCGH6.mjs +0 -107
  33. package/dist/chunk-AXFRCGH6.mjs.map +0 -1
  34. package/dist/chunk-BT6C5OPU.mjs +0 -278
  35. package/dist/chunk-BT6C5OPU.mjs.map +0 -1
  36. package/dist/chunk-CGLGXQAU.mjs +0 -78
  37. package/dist/chunk-CGLGXQAU.mjs.map +0 -1
  38. package/dist/chunk-CSHBUHRW.mjs +0 -69
  39. package/dist/chunk-CSHBUHRW.mjs.map +0 -1
  40. package/dist/chunk-CZ3GI3IF.mjs +0 -283
  41. package/dist/chunk-CZ3GI3IF.mjs.map +0 -1
  42. package/dist/chunk-DVUQO72Z.mjs +0 -1
  43. package/dist/chunk-DVUQO72Z.mjs.map +0 -1
  44. package/dist/chunk-E4HD4M7R.mjs +0 -76
  45. package/dist/chunk-E4HD4M7R.mjs.map +0 -1
  46. package/dist/chunk-E56GYBP3.mjs +0 -101
  47. package/dist/chunk-E56GYBP3.mjs.map +0 -1
  48. package/dist/chunk-EJ5ZEAAN.mjs +0 -57
  49. package/dist/chunk-EJ5ZEAAN.mjs.map +0 -1
  50. package/dist/chunk-ETWJDCGE.mjs +0 -1
  51. package/dist/chunk-ETWJDCGE.mjs.map +0 -1
  52. package/dist/chunk-F43IPGPA.mjs +0 -311
  53. package/dist/chunk-F43IPGPA.mjs.map +0 -1
  54. package/dist/chunk-FIBK3DYE.mjs +0 -26
  55. package/dist/chunk-FIBK3DYE.mjs.map +0 -1
  56. package/dist/chunk-FVURPXQK.mjs +0 -45
  57. package/dist/chunk-FVURPXQK.mjs.map +0 -1
  58. package/dist/chunk-FZR2XQKR.mjs +0 -44
  59. package/dist/chunk-FZR2XQKR.mjs.map +0 -1
  60. package/dist/chunk-IA4CLXDM.mjs +0 -76
  61. package/dist/chunk-IA4CLXDM.mjs.map +0 -1
  62. package/dist/chunk-IH5VFJ4L.mjs +0 -60
  63. package/dist/chunk-IH5VFJ4L.mjs.map +0 -1
  64. package/dist/chunk-IICUCI5S.mjs +0 -43
  65. package/dist/chunk-IICUCI5S.mjs.map +0 -1
  66. package/dist/chunk-JLVGSNAO.mjs +0 -311
  67. package/dist/chunk-JLVGSNAO.mjs.map +0 -1
  68. package/dist/chunk-JWOIINVV.mjs +0 -237
  69. package/dist/chunk-JWOIINVV.mjs.map +0 -1
  70. package/dist/chunk-KCVDFZJX.mjs +0 -873
  71. package/dist/chunk-KCVDFZJX.mjs.map +0 -1
  72. package/dist/chunk-KPRUSQ3K.mjs +0 -1
  73. package/dist/chunk-KPRUSQ3K.mjs.map +0 -1
  74. package/dist/chunk-MWC5OV7Z.mjs +0 -1
  75. package/dist/chunk-MWC5OV7Z.mjs.map +0 -1
  76. package/dist/chunk-N5EP5OD5.mjs +0 -1
  77. package/dist/chunk-N5EP5OD5.mjs.map +0 -1
  78. package/dist/chunk-NASFZS3N.mjs +0 -43
  79. package/dist/chunk-NASFZS3N.mjs.map +0 -1
  80. package/dist/chunk-NB2GZAKG.mjs +0 -131
  81. package/dist/chunk-NB2GZAKG.mjs.map +0 -1
  82. package/dist/chunk-NB4DFAZH.mjs +0 -185
  83. package/dist/chunk-NB4DFAZH.mjs.map +0 -1
  84. package/dist/chunk-NNAYEAP2.mjs +0 -49
  85. package/dist/chunk-NNAYEAP2.mjs.map +0 -1
  86. package/dist/chunk-NNPKBGD6.mjs +0 -37
  87. package/dist/chunk-NNPKBGD6.mjs.map +0 -1
  88. package/dist/chunk-OMPVTGXH.mjs +0 -122
  89. package/dist/chunk-OMPVTGXH.mjs.map +0 -1
  90. package/dist/chunk-QFBM3ZT2.mjs +0 -45
  91. package/dist/chunk-QFBM3ZT2.mjs.map +0 -1
  92. package/dist/chunk-QJ6DZ645.mjs +0 -78
  93. package/dist/chunk-QJ6DZ645.mjs.map +0 -1
  94. package/dist/chunk-R5OLAA3L.mjs +0 -135
  95. package/dist/chunk-R5OLAA3L.mjs.map +0 -1
  96. package/dist/chunk-RF2CGPHQ.mjs +0 -215
  97. package/dist/chunk-RF2CGPHQ.mjs.map +0 -1
  98. package/dist/chunk-RGD2L3Z4.mjs +0 -96
  99. package/dist/chunk-RGD2L3Z4.mjs.map +0 -1
  100. package/dist/chunk-RK5P2LG6.mjs +0 -57
  101. package/dist/chunk-RK5P2LG6.mjs.map +0 -1
  102. package/dist/chunk-RRXDJCXI.mjs +0 -60
  103. package/dist/chunk-RRXDJCXI.mjs.map +0 -1
  104. package/dist/chunk-SPDE34WC.mjs +0 -283
  105. package/dist/chunk-SPDE34WC.mjs.map +0 -1
  106. package/dist/chunk-TAUOEJH2.mjs +0 -120
  107. package/dist/chunk-TAUOEJH2.mjs.map +0 -1
  108. package/dist/chunk-TKFOXPXF.mjs +0 -157
  109. package/dist/chunk-TKFOXPXF.mjs.map +0 -1
  110. package/dist/chunk-UOX5D73C.mjs +0 -22
  111. package/dist/chunk-UOX5D73C.mjs.map +0 -1
  112. package/dist/chunk-US4KNAAV.mjs +0 -1
  113. package/dist/chunk-US4KNAAV.mjs.map +0 -1
  114. package/dist/chunk-UZB3CTOY.mjs +0 -873
  115. package/dist/chunk-UZB3CTOY.mjs.map +0 -1
  116. package/dist/chunk-VBI6JXPC.mjs +0 -1
  117. package/dist/chunk-VBI6JXPC.mjs.map +0 -1
  118. package/dist/chunk-VE3SBLU7.mjs +0 -215
  119. package/dist/chunk-VE3SBLU7.mjs.map +0 -1
  120. package/dist/chunk-VUHFLJWI.mjs +0 -185
  121. package/dist/chunk-VUHFLJWI.mjs.map +0 -1
  122. package/dist/chunk-VVAXSF3M.mjs +0 -61
  123. package/dist/chunk-VVAXSF3M.mjs.map +0 -1
  124. package/dist/chunk-W5DUKRCI.mjs +0 -97
  125. package/dist/chunk-W5DUKRCI.mjs.map +0 -1
  126. package/dist/chunk-WNRDFAZ5.mjs +0 -22
  127. package/dist/chunk-WNRDFAZ5.mjs.map +0 -1
  128. package/dist/chunk-XO4IRKSC.mjs +0 -11
  129. package/dist/chunk-XO4IRKSC.mjs.map +0 -1
  130. package/dist/chunk-XU5CEPYQ.mjs +0 -75
  131. package/dist/chunk-XU5CEPYQ.mjs.map +0 -1
  132. package/dist/chunk-YPH4BHOY.mjs +0 -39
  133. package/dist/chunk-YPH4BHOY.mjs.map +0 -1
  134. package/dist/chunk-YVPPF62K.mjs +0 -32
  135. package/dist/chunk-YVPPF62K.mjs.map +0 -1
  136. package/dist/chunk-YZUPVMHC.mjs +0 -1
  137. package/dist/chunk-YZUPVMHC.mjs.map +0 -1
  138. package/dist/chunk-Z3OIGQCZ.mjs +0 -75
  139. package/dist/chunk-Z3OIGQCZ.mjs.map +0 -1
  140. package/dist/chunk-ZIDT52TM.mjs +0 -131
  141. package/dist/chunk-ZIDT52TM.mjs.map +0 -1
  142. package/dist/components/CopilotKitInspector.d.mts +0 -13
  143. package/dist/components/CopilotKitInspector.d.ts +0 -13
  144. package/dist/components/CopilotKitInspector.js +0 -69
  145. package/dist/components/CopilotKitInspector.js.map +0 -1
  146. package/dist/components/CopilotKitInspector.mjs +0 -7
  147. package/dist/components/CopilotKitInspector.mjs.map +0 -1
  148. package/dist/components/WildcardToolCallRender.d.mts +0 -7
  149. package/dist/components/WildcardToolCallRender.d.ts +0 -7
  150. package/dist/components/WildcardToolCallRender.js +0 -106
  151. package/dist/components/WildcardToolCallRender.js.map +0 -1
  152. package/dist/components/WildcardToolCallRender.mjs +0 -8
  153. package/dist/components/WildcardToolCallRender.mjs.map +0 -1
  154. package/dist/components/chat/CopilotChat.d.mts +0 -30
  155. package/dist/components/chat/CopilotChat.d.ts +0 -30
  156. package/dist/components/chat/CopilotChat.js +0 -2934
  157. package/dist/components/chat/CopilotChat.js.map +0 -1
  158. package/dist/components/chat/CopilotChat.mjs +0 -37
  159. package/dist/components/chat/CopilotChat.mjs.map +0 -1
  160. package/dist/components/chat/CopilotChatAssistantMessage.d.mts +0 -45
  161. package/dist/components/chat/CopilotChatAssistantMessage.d.ts +0 -45
  162. package/dist/components/chat/CopilotChatAssistantMessage.js +0 -735
  163. package/dist/components/chat/CopilotChatAssistantMessage.js.map +0 -1
  164. package/dist/components/chat/CopilotChatAssistantMessage.mjs +0 -29
  165. package/dist/components/chat/CopilotChatAssistantMessage.mjs.map +0 -1
  166. package/dist/components/chat/CopilotChatAudioRecorder.d.mts +0 -11
  167. package/dist/components/chat/CopilotChatAudioRecorder.d.ts +0 -11
  168. package/dist/components/chat/CopilotChatAudioRecorder.js +0 -131
  169. package/dist/components/chat/CopilotChatAudioRecorder.js.map +0 -1
  170. package/dist/components/chat/CopilotChatAudioRecorder.mjs +0 -9
  171. package/dist/components/chat/CopilotChatAudioRecorder.mjs.map +0 -1
  172. package/dist/components/chat/CopilotChatInput.d.mts +0 -67
  173. package/dist/components/chat/CopilotChatInput.d.ts +0 -67
  174. package/dist/components/chat/CopilotChatInput.js +0 -1305
  175. package/dist/components/chat/CopilotChatInput.js.map +0 -1
  176. package/dist/components/chat/CopilotChatInput.mjs +0 -16
  177. package/dist/components/chat/CopilotChatInput.mjs.map +0 -1
  178. package/dist/components/chat/CopilotChatMessageView.d.mts +0 -29
  179. package/dist/components/chat/CopilotChatMessageView.d.ts +0 -29
  180. package/dist/components/chat/CopilotChatMessageView.js +0 -1164
  181. package/dist/components/chat/CopilotChatMessageView.js.map +0 -1
  182. package/dist/components/chat/CopilotChatMessageView.mjs +0 -31
  183. package/dist/components/chat/CopilotChatMessageView.mjs.map +0 -1
  184. package/dist/components/chat/CopilotChatSuggestionPill.d.mts +0 -11
  185. package/dist/components/chat/CopilotChatSuggestionPill.d.ts +0 -11
  186. package/dist/components/chat/CopilotChatSuggestionPill.js +0 -76
  187. package/dist/components/chat/CopilotChatSuggestionPill.js.map +0 -1
  188. package/dist/components/chat/CopilotChatSuggestionPill.mjs +0 -10
  189. package/dist/components/chat/CopilotChatSuggestionPill.mjs.map +0 -1
  190. package/dist/components/chat/CopilotChatSuggestionView.d.mts +0 -33
  191. package/dist/components/chat/CopilotChatSuggestionView.d.ts +0 -33
  192. package/dist/components/chat/CopilotChatSuggestionView.js +0 -179
  193. package/dist/components/chat/CopilotChatSuggestionView.js.map +0 -1
  194. package/dist/components/chat/CopilotChatSuggestionView.mjs +0 -12
  195. package/dist/components/chat/CopilotChatSuggestionView.mjs.map +0 -1
  196. package/dist/components/chat/CopilotChatToggleButton.d.mts +0 -14
  197. package/dist/components/chat/CopilotChatToggleButton.d.ts +0 -14
  198. package/dist/components/chat/CopilotChatToggleButton.js +0 -222
  199. package/dist/components/chat/CopilotChatToggleButton.js.map +0 -1
  200. package/dist/components/chat/CopilotChatToggleButton.mjs +0 -16
  201. package/dist/components/chat/CopilotChatToggleButton.mjs.map +0 -1
  202. package/dist/components/chat/CopilotChatToolCallsView.d.mts +0 -10
  203. package/dist/components/chat/CopilotChatToolCallsView.d.ts +0 -10
  204. package/dist/components/chat/CopilotChatToolCallsView.js +0 -264
  205. package/dist/components/chat/CopilotChatToolCallsView.js.map +0 -1
  206. package/dist/components/chat/CopilotChatToolCallsView.mjs +0 -24
  207. package/dist/components/chat/CopilotChatToolCallsView.mjs.map +0 -1
  208. package/dist/components/chat/CopilotChatUserMessage.d.mts +0 -52
  209. package/dist/components/chat/CopilotChatUserMessage.d.ts +0 -52
  210. package/dist/components/chat/CopilotChatUserMessage.js +0 -523
  211. package/dist/components/chat/CopilotChatUserMessage.js.map +0 -1
  212. package/dist/components/chat/CopilotChatUserMessage.mjs +0 -14
  213. package/dist/components/chat/CopilotChatUserMessage.mjs.map +0 -1
  214. package/dist/components/chat/CopilotChatView.d.mts +0 -54
  215. package/dist/components/chat/CopilotChatView.d.ts +0 -54
  216. package/dist/components/chat/CopilotChatView.js +0 -2640
  217. package/dist/components/chat/CopilotChatView.js.map +0 -1
  218. package/dist/components/chat/CopilotChatView.mjs +0 -38
  219. package/dist/components/chat/CopilotChatView.mjs.map +0 -1
  220. package/dist/components/chat/CopilotModalHeader.d.mts +0 -22
  221. package/dist/components/chat/CopilotModalHeader.d.ts +0 -22
  222. package/dist/components/chat/CopilotModalHeader.js +0 -186
  223. package/dist/components/chat/CopilotModalHeader.js.map +0 -1
  224. package/dist/components/chat/CopilotModalHeader.mjs +0 -12
  225. package/dist/components/chat/CopilotModalHeader.mjs.map +0 -1
  226. package/dist/components/chat/CopilotPopup.d.mts +0 -33
  227. package/dist/components/chat/CopilotPopup.d.ts +0 -33
  228. package/dist/components/chat/CopilotPopup.js +0 -3343
  229. package/dist/components/chat/CopilotPopup.js.map +0 -1
  230. package/dist/components/chat/CopilotPopup.mjs +0 -43
  231. package/dist/components/chat/CopilotPopup.mjs.map +0 -1
  232. package/dist/components/chat/CopilotPopupView.d.mts +0 -30
  233. package/dist/components/chat/CopilotPopupView.d.ts +0 -30
  234. package/dist/components/chat/CopilotPopupView.js +0 -3003
  235. package/dist/components/chat/CopilotPopupView.js.map +0 -1
  236. package/dist/components/chat/CopilotPopupView.mjs +0 -41
  237. package/dist/components/chat/CopilotPopupView.mjs.map +0 -1
  238. package/dist/components/chat/CopilotSidebar.d.mts +0 -31
  239. package/dist/components/chat/CopilotSidebar.d.ts +0 -31
  240. package/dist/components/chat/CopilotSidebar.js +0 -3266
  241. package/dist/components/chat/CopilotSidebar.js.map +0 -1
  242. package/dist/components/chat/CopilotSidebar.mjs +0 -43
  243. package/dist/components/chat/CopilotSidebar.mjs.map +0 -1
  244. package/dist/components/chat/CopilotSidebarView.d.mts +0 -28
  245. package/dist/components/chat/CopilotSidebarView.d.ts +0 -28
  246. package/dist/components/chat/CopilotSidebarView.js +0 -2941
  247. package/dist/components/chat/CopilotSidebarView.js.map +0 -1
  248. package/dist/components/chat/CopilotSidebarView.mjs +0 -41
  249. package/dist/components/chat/CopilotSidebarView.mjs.map +0 -1
  250. package/dist/components/chat/index.d.mts +0 -23
  251. package/dist/components/chat/index.d.ts +0 -23
  252. package/dist/components/chat/index.js +0 -3503
  253. package/dist/components/chat/index.js.map +0 -1
  254. package/dist/components/chat/index.mjs +0 -95
  255. package/dist/components/chat/index.mjs.map +0 -1
  256. package/dist/components/index.d.mts +0 -29
  257. package/dist/components/index.d.ts +0 -29
  258. package/dist/components/index.js +0 -3583
  259. package/dist/components/index.js.map +0 -1
  260. package/dist/components/index.mjs +0 -104
  261. package/dist/components/index.mjs.map +0 -1
  262. package/dist/components/ui/button.d.mts +0 -14
  263. package/dist/components/ui/button.d.ts +0 -14
  264. package/dist/components/ui/button.js +0 -150
  265. package/dist/components/ui/button.js.map +0 -1
  266. package/dist/components/ui/button.mjs +0 -10
  267. package/dist/components/ui/button.mjs.map +0 -1
  268. package/dist/components/ui/dropdown-menu.d.mts +0 -28
  269. package/dist/components/ui/dropdown-menu.d.ts +0 -28
  270. package/dist/components/ui/dropdown-menu.js +0 -291
  271. package/dist/components/ui/dropdown-menu.js.map +0 -1
  272. package/dist/components/ui/dropdown-menu.mjs +0 -37
  273. package/dist/components/ui/dropdown-menu.mjs.map +0 -1
  274. package/dist/components/ui/tooltip.d.mts +0 -10
  275. package/dist/components/ui/tooltip.d.ts +0 -10
  276. package/dist/components/ui/tooltip.js +0 -103
  277. package/dist/components/ui/tooltip.js.map +0 -1
  278. package/dist/components/ui/tooltip.mjs +0 -14
  279. package/dist/components/ui/tooltip.mjs.map +0 -1
  280. package/dist/hooks/index.d.mts +0 -19
  281. package/dist/hooks/index.d.ts +0 -19
  282. package/dist/hooks/index.js +0 -691
  283. package/dist/hooks/index.js.map +0 -1
  284. package/dist/hooks/index.mjs +0 -45
  285. package/dist/hooks/index.mjs.map +0 -1
  286. package/dist/hooks/use-agent-context.d.mts +0 -5
  287. package/dist/hooks/use-agent-context.d.ts +0 -5
  288. package/dist/hooks/use-agent-context.js +0 -116
  289. package/dist/hooks/use-agent-context.js.map +0 -1
  290. package/dist/hooks/use-agent-context.mjs +0 -10
  291. package/dist/hooks/use-agent-context.mjs.map +0 -1
  292. package/dist/hooks/use-agent.d.mts +0 -16
  293. package/dist/hooks/use-agent.d.ts +0 -16
  294. package/dist/hooks/use-agent.js +0 -171
  295. package/dist/hooks/use-agent.js.map +0 -1
  296. package/dist/hooks/use-agent.mjs +0 -12
  297. package/dist/hooks/use-agent.mjs.map +0 -1
  298. package/dist/hooks/use-configure-suggestions.d.mts +0 -13
  299. package/dist/hooks/use-configure-suggestions.d.ts +0 -13
  300. package/dist/hooks/use-configure-suggestions.js +0 -232
  301. package/dist/hooks/use-configure-suggestions.js.map +0 -1
  302. package/dist/hooks/use-configure-suggestions.mjs +0 -11
  303. package/dist/hooks/use-configure-suggestions.mjs.map +0 -1
  304. package/dist/hooks/use-frontend-tool.d.mts +0 -8
  305. package/dist/hooks/use-frontend-tool.d.ts +0 -8
  306. package/dist/hooks/use-frontend-tool.js +0 -137
  307. package/dist/hooks/use-frontend-tool.js.map +0 -1
  308. package/dist/hooks/use-frontend-tool.mjs +0 -10
  309. package/dist/hooks/use-frontend-tool.mjs.map +0 -1
  310. package/dist/hooks/use-human-in-the-loop.d.mts +0 -7
  311. package/dist/hooks/use-human-in-the-loop.d.ts +0 -7
  312. package/dist/hooks/use-human-in-the-loop.js +0 -206
  313. package/dist/hooks/use-human-in-the-loop.js.map +0 -1
  314. package/dist/hooks/use-human-in-the-loop.mjs +0 -11
  315. package/dist/hooks/use-human-in-the-loop.mjs.map +0 -1
  316. package/dist/hooks/use-keyboard-height.d.mts +0 -15
  317. package/dist/hooks/use-keyboard-height.d.ts +0 -15
  318. package/dist/hooks/use-keyboard-height.js +0 -68
  319. package/dist/hooks/use-keyboard-height.js.map +0 -1
  320. package/dist/hooks/use-keyboard-height.mjs +0 -7
  321. package/dist/hooks/use-keyboard-height.mjs.map +0 -1
  322. package/dist/hooks/use-render-activity-message.d.mts +0 -5
  323. package/dist/hooks/use-render-activity-message.d.ts +0 -5
  324. package/dist/hooks/use-render-activity-message.js +0 -158
  325. package/dist/hooks/use-render-activity-message.js.map +0 -1
  326. package/dist/hooks/use-render-activity-message.mjs +0 -12
  327. package/dist/hooks/use-render-activity-message.mjs.map +0 -1
  328. package/dist/hooks/use-render-custom-messages.d.mts +0 -11
  329. package/dist/hooks/use-render-custom-messages.d.ts +0 -11
  330. package/dist/hooks/use-render-custom-messages.js +0 -170
  331. package/dist/hooks/use-render-custom-messages.js.map +0 -1
  332. package/dist/hooks/use-render-custom-messages.mjs +0 -12
  333. package/dist/hooks/use-render-custom-messages.mjs.map +0 -1
  334. package/dist/hooks/use-render-tool-call.d.mts +0 -16
  335. package/dist/hooks/use-render-tool-call.d.ts +0 -16
  336. package/dist/hooks/use-render-tool-call.js +0 -208
  337. package/dist/hooks/use-render-tool-call.js.map +0 -1
  338. package/dist/hooks/use-render-tool-call.mjs +0 -11
  339. package/dist/hooks/use-render-tool-call.mjs.map +0 -1
  340. package/dist/hooks/use-suggestions.d.mts +0 -14
  341. package/dist/hooks/use-suggestions.d.ts +0 -14
  342. package/dist/hooks/use-suggestions.js +0 -176
  343. package/dist/hooks/use-suggestions.js.map +0 -1
  344. package/dist/hooks/use-suggestions.mjs +0 -11
  345. package/dist/hooks/use-suggestions.mjs.map +0 -1
  346. package/dist/lib/react-core.d.mts +0 -33
  347. package/dist/lib/react-core.d.ts +0 -33
  348. package/dist/lib/react-core.js +0 -73
  349. package/dist/lib/react-core.js.map +0 -1
  350. package/dist/lib/react-core.mjs +0 -7
  351. package/dist/lib/react-core.mjs.map +0 -1
  352. package/dist/lib/slots.d.mts +0 -16
  353. package/dist/lib/slots.d.ts +0 -16
  354. package/dist/lib/slots.js +0 -60
  355. package/dist/lib/slots.js.map +0 -1
  356. package/dist/lib/slots.mjs +0 -7
  357. package/dist/lib/slots.mjs.map +0 -1
  358. package/dist/lib/utils.d.mts +0 -5
  359. package/dist/lib/utils.d.ts +0 -5
  360. package/dist/lib/utils.js +0 -35
  361. package/dist/lib/utils.js.map +0 -1
  362. package/dist/lib/utils.mjs +0 -7
  363. package/dist/lib/utils.mjs.map +0 -1
  364. package/dist/providers/CopilotChatConfigurationProvider.d.mts +0 -43
  365. package/dist/providers/CopilotChatConfigurationProvider.d.ts +0 -43
  366. package/dist/providers/CopilotChatConfigurationProvider.js +0 -109
  367. package/dist/providers/CopilotChatConfigurationProvider.js.map +0 -1
  368. package/dist/providers/CopilotChatConfigurationProvider.mjs +0 -11
  369. package/dist/providers/CopilotChatConfigurationProvider.mjs.map +0 -1
  370. package/dist/providers/CopilotKitProvider.d.mts +0 -33
  371. package/dist/providers/CopilotKitProvider.d.ts +0 -33
  372. package/dist/providers/CopilotKitProvider.js +0 -314
  373. package/dist/providers/CopilotKitProvider.js.map +0 -1
  374. package/dist/providers/CopilotKitProvider.mjs +0 -12
  375. package/dist/providers/CopilotKitProvider.mjs.map +0 -1
  376. package/dist/providers/index.d.mts +0 -13
  377. package/dist/providers/index.d.ts +0 -13
  378. package/dist/providers/index.js +0 -396
  379. package/dist/providers/index.js.map +0 -1
  380. package/dist/providers/index.mjs +0 -18
  381. package/dist/providers/index.mjs.map +0 -1
  382. package/dist/types/defineToolCallRenderer.d.mts +0 -41
  383. package/dist/types/defineToolCallRenderer.d.ts +0 -41
  384. package/dist/types/defineToolCallRenderer.js +0 -40
  385. package/dist/types/defineToolCallRenderer.js.map +0 -1
  386. package/dist/types/defineToolCallRenderer.mjs +0 -7
  387. package/dist/types/defineToolCallRenderer.mjs.map +0 -1
  388. package/dist/types/frontend-tool.d.mts +0 -9
  389. package/dist/types/frontend-tool.d.ts +0 -9
  390. package/dist/types/frontend-tool.js +0 -19
  391. package/dist/types/frontend-tool.js.map +0 -1
  392. package/dist/types/frontend-tool.mjs +0 -2
  393. package/dist/types/frontend-tool.mjs.map +0 -1
  394. package/dist/types/human-in-the-loop.d.mts +0 -29
  395. package/dist/types/human-in-the-loop.d.ts +0 -29
  396. package/dist/types/human-in-the-loop.js +0 -19
  397. package/dist/types/human-in-the-loop.js.map +0 -1
  398. package/dist/types/human-in-the-loop.mjs +0 -2
  399. package/dist/types/human-in-the-loop.mjs.map +0 -1
  400. package/dist/types/index.d.mts +0 -11
  401. package/dist/types/index.d.ts +0 -11
  402. package/dist/types/index.js +0 -42
  403. package/dist/types/index.js.map +0 -1
  404. package/dist/types/index.mjs +0 -13
  405. package/dist/types/index.mjs.map +0 -1
  406. package/dist/types/react-activity-message-renderer.d.mts +0 -29
  407. package/dist/types/react-activity-message-renderer.d.ts +0 -29
  408. package/dist/types/react-activity-message-renderer.js +0 -19
  409. package/dist/types/react-activity-message-renderer.js.map +0 -1
  410. package/dist/types/react-activity-message-renderer.mjs +0 -2
  411. package/dist/types/react-activity-message-renderer.mjs.map +0 -1
  412. package/dist/types/react-custom-message-renderer.d.mts +0 -18
  413. package/dist/types/react-custom-message-renderer.d.ts +0 -18
  414. package/dist/types/react-custom-message-renderer.js +0 -19
  415. package/dist/types/react-custom-message-renderer.js.map +0 -1
  416. package/dist/types/react-custom-message-renderer.mjs +0 -2
  417. package/dist/types/react-custom-message-renderer.mjs.map +0 -1
  418. package/dist/types/react-tool-call-renderer.d.mts +0 -30
  419. package/dist/types/react-tool-call-renderer.d.ts +0 -30
  420. package/dist/types/react-tool-call-renderer.js +0 -19
  421. package/dist/types/react-tool-call-renderer.js.map +0 -1
  422. package/dist/types/react-tool-call-renderer.mjs +0 -2
  423. package/dist/types/react-tool-call-renderer.mjs.map +0 -1
@@ -1,2941 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/components/chat/CopilotSidebarView.tsx
31
- var CopilotSidebarView_exports = {};
32
- __export(CopilotSidebarView_exports, {
33
- CopilotSidebarView: () => CopilotSidebarView,
34
- default: () => CopilotSidebarView_default
35
- });
36
- module.exports = __toCommonJS(CopilotSidebarView_exports);
37
- var import_react25 = require("react");
38
-
39
- // src/components/chat/CopilotChatView.tsx
40
- var import_react22 = __toESM(require("react"));
41
-
42
- // src/lib/slots.tsx
43
- var import_react = __toESM(require("react"));
44
- function renderSlot(slot, DefaultComponent, props) {
45
- if (typeof slot === "string") {
46
- return import_react.default.createElement(DefaultComponent, {
47
- ...props,
48
- className: slot
49
- });
50
- }
51
- if (typeof slot === "function") {
52
- const Comp = slot;
53
- return import_react.default.createElement(Comp, props);
54
- }
55
- if (slot && typeof slot === "object" && !import_react.default.isValidElement(slot)) {
56
- return import_react.default.createElement(DefaultComponent, {
57
- ...props,
58
- ...slot
59
- });
60
- }
61
- return import_react.default.createElement(DefaultComponent, props);
62
- }
63
-
64
- // src/components/chat/CopilotChatAssistantMessage.tsx
65
- var import_react15 = require("react");
66
- var import_lucide_react = require("lucide-react");
67
-
68
- // src/providers/CopilotChatConfigurationProvider.tsx
69
- var import_react2 = require("react");
70
- var import_shared = require("@copilotkitnext/shared");
71
- var import_jsx_runtime = require("react/jsx-runtime");
72
- var CopilotChatDefaultLabels = {
73
- chatInputPlaceholder: "Type a message...",
74
- chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
75
- chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
76
- chatInputToolbarFinishTranscribeButtonLabel: "Finish",
77
- chatInputToolbarAddButtonLabel: "Add photos or files",
78
- chatInputToolbarToolsButtonLabel: "Tools",
79
- assistantMessageToolbarCopyCodeLabel: "Copy",
80
- assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
81
- assistantMessageToolbarCopyMessageLabel: "Copy",
82
- assistantMessageToolbarThumbsUpLabel: "Good response",
83
- assistantMessageToolbarThumbsDownLabel: "Bad response",
84
- assistantMessageToolbarReadAloudLabel: "Read aloud",
85
- assistantMessageToolbarRegenerateLabel: "Regenerate",
86
- userMessageToolbarCopyMessageLabel: "Copy",
87
- userMessageToolbarEditMessageLabel: "Edit",
88
- chatDisclaimerText: "AI can make mistakes. Please verify important information.",
89
- chatToggleOpenLabel: "Open chat",
90
- chatToggleCloseLabel: "Close chat",
91
- modalHeaderTitle: "CopilotKit Chat"
92
- };
93
- var CopilotChatConfiguration = (0, import_react2.createContext)(null);
94
- var useCopilotChatConfiguration = () => {
95
- const configuration = (0, import_react2.useContext)(CopilotChatConfiguration);
96
- return configuration;
97
- };
98
-
99
- // src/components/chat/CopilotChatAssistantMessage.tsx
100
- var import_tailwind_merge2 = require("tailwind-merge");
101
-
102
- // src/components/ui/button.tsx
103
- var import_react_slot = require("@radix-ui/react-slot");
104
- var import_class_variance_authority = require("class-variance-authority");
105
-
106
- // src/lib/utils.ts
107
- var import_clsx = require("clsx");
108
- var import_tailwind_merge = require("tailwind-merge");
109
- function cn(...inputs) {
110
- return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
111
- }
112
-
113
- // src/components/ui/button.tsx
114
- var import_jsx_runtime2 = require("react/jsx-runtime");
115
- var buttonVariants = (0, import_class_variance_authority.cva)(
116
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
117
- {
118
- variants: {
119
- variant: {
120
- default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
121
- destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
122
- outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
123
- secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
124
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50 cursor-pointer",
125
- link: "text-primary underline-offset-4 hover:underline",
126
- assistantMessageToolbarButton: [
127
- "cursor-pointer",
128
- // Background and text
129
- "p-0 text-[rgb(93,93,93)] hover:bg-[#E8E8E8]",
130
- // Dark mode - lighter gray for better contrast
131
- "dark:text-[rgb(243,243,243)] dark:hover:bg-[#303030]",
132
- // Shape and sizing
133
- "h-8 w-8",
134
- // Interactions
135
- "transition-colors",
136
- // Hover states
137
- "hover:text-[rgb(93,93,93)]",
138
- "dark:hover:text-[rgb(243,243,243)]"
139
- ],
140
- chatInputToolbarPrimary: [
141
- "cursor-pointer",
142
- // Background and text
143
- "bg-black text-white",
144
- // Dark mode
145
- "dark:bg-white dark:text-black dark:focus-visible:outline-white",
146
- // Shape and sizing
147
- "rounded-full",
148
- // Interactions
149
- "transition-colors",
150
- // Focus states
151
- "focus:outline-none",
152
- // Hover states
153
- "hover:opacity-70 disabled:hover:opacity-100",
154
- // Disabled states
155
- "disabled:cursor-not-allowed disabled:bg-[#00000014] disabled:text-[rgb(13,13,13)]",
156
- "dark:disabled:bg-[#454545] dark:disabled:text-white "
157
- ],
158
- chatInputToolbarSecondary: [
159
- "cursor-pointer",
160
- // Background and text
161
- "bg-transparent text-[#444444]",
162
- // Dark mode
163
- "dark:text-white dark:border-[#404040]",
164
- // Shape and sizing
165
- "rounded-full",
166
- // Interactions
167
- "transition-colors",
168
- // Focus states
169
- "focus:outline-none",
170
- // Hover states
171
- "hover:bg-[#f8f8f8] hover:text-[#333333]",
172
- "dark:hover:bg-[#404040] dark:hover:text-[#FFFFFF]",
173
- // Disabled states
174
- "disabled:cursor-not-allowed disabled:opacity-50",
175
- "disabled:hover:bg-transparent disabled:hover:text-[#444444]",
176
- "dark:disabled:hover:bg-transparent dark:disabled:hover:text-[#CCCCCC]"
177
- ]
178
- },
179
- size: {
180
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
181
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
182
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
183
- icon: "size-9",
184
- chatInputToolbarIcon: [
185
- // Shape and sizing
186
- "h-9 w-9 rounded-full"
187
- ],
188
- chatInputToolbarIconLabel: [
189
- // Shape and sizing
190
- "h-9 px-3 rounded-full",
191
- // Layout
192
- "gap-2",
193
- // Typography
194
- "font-normal"
195
- ]
196
- }
197
- },
198
- defaultVariants: {
199
- variant: "default",
200
- size: "default"
201
- }
202
- }
203
- );
204
- function Button({
205
- className,
206
- variant,
207
- size,
208
- asChild = false,
209
- ...props
210
- }) {
211
- const Comp = asChild ? import_react_slot.Slot : "button";
212
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
213
- Comp,
214
- {
215
- "data-slot": "button",
216
- className: cn(buttonVariants({ variant, size, className })),
217
- ...props
218
- }
219
- );
220
- }
221
-
222
- // src/components/ui/tooltip.tsx
223
- var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
224
- var import_jsx_runtime3 = require("react/jsx-runtime");
225
- function TooltipProvider({
226
- delayDuration = 0,
227
- ...props
228
- }) {
229
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
230
- TooltipPrimitive.Provider,
231
- {
232
- "data-slot": "tooltip-provider",
233
- delayDuration,
234
- ...props
235
- }
236
- );
237
- }
238
- function Tooltip({
239
- ...props
240
- }) {
241
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
242
- }
243
- function TooltipTrigger({
244
- ...props
245
- }) {
246
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
247
- }
248
- function TooltipContent({
249
- className,
250
- sideOffset = 0,
251
- children,
252
- ...props
253
- }) {
254
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
255
- TooltipPrimitive.Content,
256
- {
257
- "data-slot": "tooltip-content",
258
- sideOffset,
259
- className: cn(
260
- "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
261
- className
262
- ),
263
- ...props,
264
- children: [
265
- children,
266
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Arrow, { className: "bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
267
- ]
268
- }
269
- ) });
270
- }
271
-
272
- // src/components/chat/CopilotChatAssistantMessage.tsx
273
- var import_katex_min = require("katex/dist/katex.min.css");
274
- var import_streamdown = require("streamdown");
275
-
276
- // src/hooks/use-render-tool-call.tsx
277
- var import_react5 = require("react");
278
- var import_core2 = require("@copilotkitnext/core");
279
-
280
- // src/providers/CopilotKitProvider.tsx
281
- var import_react4 = require("react");
282
- var import_zod = require("zod");
283
-
284
- // src/lib/react-core.ts
285
- var import_core = require("@copilotkitnext/core");
286
-
287
- // src/components/CopilotKitInspector.tsx
288
- var React3 = __toESM(require("react"));
289
- var import_react3 = require("@lit-labs/react");
290
- var import_web_inspector = require("@copilotkitnext/web-inspector");
291
- var import_jsx_runtime4 = require("react/jsx-runtime");
292
- (0, import_web_inspector.defineWebInspector)();
293
- var CopilotKitInspectorBase = (0, import_react3.createComponent)({
294
- tagName: import_web_inspector.WEB_INSPECTOR_TAG,
295
- elementClass: import_web_inspector.WebInspectorElement,
296
- react: React3
297
- });
298
- var CopilotKitInspector = React3.forwardRef(
299
- ({ core, ...rest }, ref) => {
300
- const innerRef = React3.useRef(null);
301
- React3.useImperativeHandle(ref, () => innerRef.current, []);
302
- React3.useEffect(() => {
303
- if (innerRef.current) {
304
- innerRef.current.core = core ?? null;
305
- }
306
- }, [core]);
307
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
308
- CopilotKitInspectorBase,
309
- {
310
- ...rest,
311
- ref: innerRef
312
- }
313
- );
314
- }
315
- );
316
- CopilotKitInspector.displayName = "CopilotKitInspector";
317
-
318
- // src/providers/CopilotKitProvider.tsx
319
- var import_jsx_runtime5 = require("react/jsx-runtime");
320
- var CopilotKitContext = (0, import_react4.createContext)({
321
- copilotkit: null
322
- });
323
- var useCopilotKit = () => {
324
- const context = (0, import_react4.useContext)(CopilotKitContext);
325
- const [, forceUpdate] = (0, import_react4.useReducer)((x) => x + 1, 0);
326
- if (!context) {
327
- throw new Error("useCopilotKit must be used within CopilotKitProvider");
328
- }
329
- (0, import_react4.useEffect)(() => {
330
- const unsubscribe = context.copilotkit.subscribe({
331
- onRuntimeConnectionStatusChanged: () => {
332
- forceUpdate();
333
- }
334
- });
335
- return () => {
336
- unsubscribe();
337
- };
338
- }, []);
339
- return context;
340
- };
341
-
342
- // src/hooks/use-render-tool-call.tsx
343
- var import_shared2 = require("@copilotkitnext/shared");
344
- var import_shared3 = require("@copilotkitnext/shared");
345
- var import_jsx_runtime6 = require("react/jsx-runtime");
346
- function useRenderToolCall() {
347
- const { copilotkit } = useCopilotKit();
348
- const config = useCopilotChatConfiguration();
349
- const agentId = config?.agentId ?? import_shared2.DEFAULT_AGENT_ID;
350
- const [executingToolCallIds, setExecutingToolCallIds] = (0, import_react5.useState)(() => /* @__PURE__ */ new Set());
351
- const renderToolCalls = (0, import_react5.useSyncExternalStore)(
352
- (callback) => {
353
- return copilotkit.subscribe({
354
- onRenderToolCallsChanged: callback
355
- });
356
- },
357
- () => copilotkit.renderToolCalls,
358
- () => copilotkit.renderToolCalls
359
- );
360
- (0, import_react5.useEffect)(() => {
361
- const unsubscribe = copilotkit.subscribe({
362
- onToolExecutionStart: ({ toolCallId }) => {
363
- setExecutingToolCallIds((prev) => {
364
- if (prev.has(toolCallId)) return prev;
365
- const next = new Set(prev);
366
- next.add(toolCallId);
367
- return next;
368
- });
369
- },
370
- onToolExecutionEnd: ({ toolCallId }) => {
371
- setExecutingToolCallIds((prev) => {
372
- if (!prev.has(toolCallId)) return prev;
373
- const next = new Set(prev);
374
- next.delete(toolCallId);
375
- return next;
376
- });
377
- }
378
- });
379
- return () => unsubscribe();
380
- }, [copilotkit]);
381
- const renderToolCall = (0, import_react5.useCallback)(
382
- ({
383
- toolCall,
384
- toolMessage
385
- }) => {
386
- const exactMatches = renderToolCalls.filter(
387
- (rc) => rc.name === toolCall.function.name
388
- );
389
- const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
390
- if (!renderConfig) {
391
- return null;
392
- }
393
- const RenderComponent = renderConfig.render;
394
- const args = (0, import_shared3.partialJSONParse)(toolCall.function.arguments);
395
- const toolName = toolCall.function.name;
396
- if (toolMessage) {
397
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
398
- RenderComponent,
399
- {
400
- name: toolName,
401
- args,
402
- status: import_core2.ToolCallStatus.Complete,
403
- result: toolMessage.content
404
- },
405
- toolCall.id
406
- );
407
- } else if (executingToolCallIds.has(toolCall.id)) {
408
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
409
- RenderComponent,
410
- {
411
- name: toolName,
412
- args,
413
- status: import_core2.ToolCallStatus.Executing,
414
- result: void 0
415
- },
416
- toolCall.id
417
- );
418
- } else {
419
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
420
- RenderComponent,
421
- {
422
- name: toolName,
423
- args,
424
- status: import_core2.ToolCallStatus.InProgress,
425
- result: void 0
426
- },
427
- toolCall.id
428
- );
429
- }
430
- },
431
- [renderToolCalls, executingToolCallIds, agentId]
432
- );
433
- return renderToolCall;
434
- }
435
-
436
- // src/hooks/use-render-custom-messages.tsx
437
- var import_jsx_runtime7 = require("react/jsx-runtime");
438
- function useRenderCustomMessages() {
439
- const { copilotkit } = useCopilotKit();
440
- const config = useCopilotChatConfiguration();
441
- if (!config) {
442
- return null;
443
- }
444
- const { agentId, threadId } = config;
445
- const customMessageRenderers = copilotkit.renderCustomMessages.filter((renderer) => renderer.agentId === void 0 || renderer.agentId === agentId).sort((a, b) => {
446
- const aHasAgent = a.agentId !== void 0;
447
- const bHasAgent = b.agentId !== void 0;
448
- if (aHasAgent === bHasAgent) return 0;
449
- return aHasAgent ? -1 : 1;
450
- });
451
- return function(params) {
452
- if (!customMessageRenderers.length) {
453
- return null;
454
- }
455
- const { message, position } = params;
456
- const runId = copilotkit.getRunIdForMessage(agentId, threadId, message.id);
457
- const agent = copilotkit.getAgent(agentId);
458
- if (!agent) {
459
- throw new Error("Agent not found");
460
- }
461
- const messagesIdsInRun = agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === runId).map((msg) => msg.id);
462
- const messageIndex = agent.messages.findIndex((msg) => msg.id === message.id) ?? 0;
463
- const messageIndexInRun = Math.min(messagesIdsInRun.indexOf(message.id), 0);
464
- const numberOfMessagesInRun = messagesIdsInRun.length;
465
- const stateSnapshot = copilotkit.getStateByRun(agentId, threadId, runId);
466
- let result = null;
467
- for (const renderer of customMessageRenderers) {
468
- if (!renderer.render) {
469
- continue;
470
- }
471
- const Component = renderer.render;
472
- result = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
473
- Component,
474
- {
475
- message,
476
- position,
477
- runId,
478
- messageIndex,
479
- messageIndexInRun,
480
- numberOfMessagesInRun,
481
- agentId,
482
- stateSnapshot
483
- },
484
- `${runId}-${message.id}-${position}`
485
- );
486
- if (result) {
487
- break;
488
- }
489
- }
490
- return result;
491
- };
492
- }
493
-
494
- // src/hooks/use-render-activity-message.tsx
495
- var import_shared4 = require("@copilotkitnext/shared");
496
- var import_react6 = require("react");
497
- var import_jsx_runtime8 = require("react/jsx-runtime");
498
- function useRenderActivityMessage() {
499
- const { copilotkit } = useCopilotKit();
500
- const config = useCopilotChatConfiguration();
501
- const agentId = config?.agentId ?? import_shared4.DEFAULT_AGENT_ID;
502
- const renderers = copilotkit.renderActivityMessages;
503
- return (0, import_react6.useCallback)(
504
- (message) => {
505
- if (!renderers.length) {
506
- return null;
507
- }
508
- const matches = renderers.filter(
509
- (renderer2) => renderer2.activityType === message.activityType
510
- );
511
- const renderer = matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*");
512
- if (!renderer) {
513
- return null;
514
- }
515
- const parseResult = renderer.content.safeParse(message.content);
516
- if (!parseResult.success) {
517
- console.warn(
518
- `Failed to parse content for activity message '${message.activityType}':`,
519
- parseResult.error
520
- );
521
- return null;
522
- }
523
- const Component = renderer.render;
524
- const agent = copilotkit.getAgent(agentId);
525
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
526
- Component,
527
- {
528
- activityType: message.activityType,
529
- content: parseResult.data,
530
- message,
531
- agent
532
- },
533
- message.id
534
- );
535
- },
536
- [agentId, copilotkit, renderers]
537
- );
538
- }
539
-
540
- // src/hooks/use-frontend-tool.tsx
541
- var import_react7 = require("react");
542
-
543
- // src/hooks/use-human-in-the-loop.tsx
544
- var import_react8 = require("react");
545
- var import_react9 = __toESM(require("react"));
546
-
547
- // src/hooks/use-agent.tsx
548
- var import_react10 = require("react");
549
- var import_shared5 = require("@copilotkitnext/shared");
550
-
551
- // src/hooks/use-agent-context.tsx
552
- var import_react11 = require("react");
553
-
554
- // src/hooks/use-suggestions.tsx
555
- var import_react12 = require("react");
556
- var import_shared6 = require("@copilotkitnext/shared");
557
-
558
- // src/hooks/use-configure-suggestions.tsx
559
- var import_react13 = require("react");
560
- var import_shared7 = require("@copilotkitnext/shared");
561
-
562
- // src/components/chat/CopilotChatToolCallsView.tsx
563
- var import_react14 = __toESM(require("react"));
564
- var import_jsx_runtime9 = require("react/jsx-runtime");
565
- function CopilotChatToolCallsView({
566
- message,
567
- messages = []
568
- }) {
569
- const renderToolCall = useRenderToolCall();
570
- if (!message.toolCalls || message.toolCalls.length === 0) {
571
- return null;
572
- }
573
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: message.toolCalls.map((toolCall) => {
574
- const toolMessage = messages.find(
575
- (m) => m.role === "tool" && m.toolCallId === toolCall.id
576
- );
577
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react14.default.Fragment, { children: renderToolCall({
578
- toolCall,
579
- toolMessage
580
- }) }, toolCall.id);
581
- }) });
582
- }
583
- var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
584
-
585
- // src/components/chat/CopilotChatAssistantMessage.tsx
586
- var import_jsx_runtime10 = require("react/jsx-runtime");
587
- function CopilotChatAssistantMessage({
588
- message,
589
- messages,
590
- isRunning,
591
- onThumbsUp,
592
- onThumbsDown,
593
- onReadAloud,
594
- onRegenerate,
595
- additionalToolbarItems,
596
- toolbarVisible = true,
597
- markdownRenderer,
598
- toolbar,
599
- copyButton,
600
- thumbsUpButton,
601
- thumbsDownButton,
602
- readAloudButton,
603
- regenerateButton,
604
- toolCallsView,
605
- children,
606
- className,
607
- ...props
608
- }) {
609
- const boundMarkdownRenderer = renderSlot(
610
- markdownRenderer,
611
- CopilotChatAssistantMessage.MarkdownRenderer,
612
- {
613
- content: message.content || ""
614
- }
615
- );
616
- const boundCopyButton = renderSlot(
617
- copyButton,
618
- CopilotChatAssistantMessage.CopyButton,
619
- {
620
- onClick: async () => {
621
- if (message.content) {
622
- try {
623
- await navigator.clipboard.writeText(message.content);
624
- } catch (err) {
625
- console.error("Failed to copy message:", err);
626
- }
627
- }
628
- }
629
- }
630
- );
631
- const boundThumbsUpButton = renderSlot(
632
- thumbsUpButton,
633
- CopilotChatAssistantMessage.ThumbsUpButton,
634
- {
635
- onClick: onThumbsUp
636
- }
637
- );
638
- const boundThumbsDownButton = renderSlot(
639
- thumbsDownButton,
640
- CopilotChatAssistantMessage.ThumbsDownButton,
641
- {
642
- onClick: onThumbsDown
643
- }
644
- );
645
- const boundReadAloudButton = renderSlot(
646
- readAloudButton,
647
- CopilotChatAssistantMessage.ReadAloudButton,
648
- {
649
- onClick: onReadAloud
650
- }
651
- );
652
- const boundRegenerateButton = renderSlot(
653
- regenerateButton,
654
- CopilotChatAssistantMessage.RegenerateButton,
655
- {
656
- onClick: onRegenerate
657
- }
658
- );
659
- const boundToolbar = renderSlot(
660
- toolbar,
661
- CopilotChatAssistantMessage.Toolbar,
662
- {
663
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex items-center gap-1", children: [
664
- boundCopyButton,
665
- (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
666
- (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
667
- (onReadAloud || readAloudButton) && boundReadAloudButton,
668
- (onRegenerate || regenerateButton) && boundRegenerateButton,
669
- additionalToolbarItems
670
- ] })
671
- }
672
- );
673
- const boundToolCallsView = renderSlot(
674
- toolCallsView,
675
- CopilotChatToolCallsView_default,
676
- {
677
- message,
678
- messages
679
- }
680
- );
681
- const hasContent = !!(message.content && message.content.trim().length > 0);
682
- const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
683
- const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
684
- if (children) {
685
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: children({
686
- markdownRenderer: boundMarkdownRenderer,
687
- toolbar: boundToolbar,
688
- toolCallsView: boundToolCallsView,
689
- copyButton: boundCopyButton,
690
- thumbsUpButton: boundThumbsUpButton,
691
- thumbsDownButton: boundThumbsDownButton,
692
- readAloudButton: boundReadAloudButton,
693
- regenerateButton: boundRegenerateButton,
694
- message,
695
- messages,
696
- isRunning,
697
- onThumbsUp,
698
- onThumbsDown,
699
- onReadAloud,
700
- onRegenerate,
701
- additionalToolbarItems,
702
- toolbarVisible: shouldShowToolbar
703
- }) });
704
- }
705
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
706
- "div",
707
- {
708
- className: (0, import_tailwind_merge2.twMerge)(
709
- "prose max-w-full break-words dark:prose-invert",
710
- className
711
- ),
712
- ...props,
713
- "data-message-id": message.id,
714
- children: [
715
- boundMarkdownRenderer,
716
- boundToolCallsView,
717
- shouldShowToolbar && boundToolbar
718
- ]
719
- }
720
- );
721
- }
722
- ((CopilotChatAssistantMessage2) => {
723
- CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_streamdown.Streamdown, { className, ...props, children: content ?? "" });
724
- CopilotChatAssistantMessage2.Toolbar = ({
725
- className,
726
- ...props
727
- }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
728
- "div",
729
- {
730
- className: (0, import_tailwind_merge2.twMerge)(
731
- "w-full bg-transparent flex items-center -ml-[5px] -mt-[0px]",
732
- className
733
- ),
734
- ...props
735
- }
736
- );
737
- CopilotChatAssistantMessage2.ToolbarButton = ({ title, children, ...props }) => {
738
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Tooltip, { children: [
739
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
740
- Button,
741
- {
742
- type: "button",
743
- variant: "assistantMessageToolbarButton",
744
- "aria-label": title,
745
- ...props,
746
- children
747
- }
748
- ) }),
749
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { children: title }) })
750
- ] });
751
- };
752
- CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
753
- const config = useCopilotChatConfiguration();
754
- const labels = config?.labels ?? CopilotChatDefaultLabels;
755
- const [copied, setCopied] = (0, import_react15.useState)(false);
756
- const handleClick = (event) => {
757
- setCopied(true);
758
- setTimeout(() => setCopied(false), 2e3);
759
- if (onClick) {
760
- onClick(event);
761
- }
762
- };
763
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
764
- CopilotChatAssistantMessage2.ToolbarButton,
765
- {
766
- title: title || labels.assistantMessageToolbarCopyMessageLabel,
767
- onClick: handleClick,
768
- className,
769
- ...props,
770
- children: copied ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.Check, { className: "size-[18px]" }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.Copy, { className: "size-[18px]" })
771
- }
772
- );
773
- };
774
- CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
775
- const config = useCopilotChatConfiguration();
776
- const labels = config?.labels ?? CopilotChatDefaultLabels;
777
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
778
- CopilotChatAssistantMessage2.ToolbarButton,
779
- {
780
- title: title || labels.assistantMessageToolbarThumbsUpLabel,
781
- ...props,
782
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.ThumbsUp, { className: "size-[18px]" })
783
- }
784
- );
785
- };
786
- CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
787
- const config = useCopilotChatConfiguration();
788
- const labels = config?.labels ?? CopilotChatDefaultLabels;
789
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
790
- CopilotChatAssistantMessage2.ToolbarButton,
791
- {
792
- title: title || labels.assistantMessageToolbarThumbsDownLabel,
793
- ...props,
794
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.ThumbsDown, { className: "size-[18px]" })
795
- }
796
- );
797
- };
798
- CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
799
- const config = useCopilotChatConfiguration();
800
- const labels = config?.labels ?? CopilotChatDefaultLabels;
801
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
802
- CopilotChatAssistantMessage2.ToolbarButton,
803
- {
804
- title: title || labels.assistantMessageToolbarReadAloudLabel,
805
- ...props,
806
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.Volume2, { className: "size-[20px]" })
807
- }
808
- );
809
- };
810
- CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
811
- const config = useCopilotChatConfiguration();
812
- const labels = config?.labels ?? CopilotChatDefaultLabels;
813
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
814
- CopilotChatAssistantMessage2.ToolbarButton,
815
- {
816
- title: title || labels.assistantMessageToolbarRegenerateLabel,
817
- ...props,
818
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react.RefreshCw, { className: "size-[18px]" })
819
- }
820
- );
821
- };
822
- })(CopilotChatAssistantMessage || (CopilotChatAssistantMessage = {}));
823
- CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistantMessage.MarkdownRenderer";
824
- CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
825
- CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
826
- CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
827
- CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
828
- CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
829
- CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
830
- var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
831
-
832
- // src/components/chat/CopilotChatUserMessage.tsx
833
- var import_react16 = require("react");
834
- var import_lucide_react2 = require("lucide-react");
835
- var import_tailwind_merge3 = require("tailwind-merge");
836
- var import_jsx_runtime11 = require("react/jsx-runtime");
837
- function flattenUserMessageContent(content) {
838
- if (!content) {
839
- return "";
840
- }
841
- if (typeof content === "string") {
842
- return content;
843
- }
844
- return content.map((part) => {
845
- if (part && typeof part === "object" && "type" in part && part.type === "text" && typeof part.text === "string") {
846
- return part.text;
847
- }
848
- return "";
849
- }).filter((text) => text.length > 0).join("\n");
850
- }
851
- function CopilotChatUserMessage({
852
- message,
853
- onEditMessage,
854
- branchIndex,
855
- numberOfBranches,
856
- onSwitchToBranch,
857
- additionalToolbarItems,
858
- messageRenderer,
859
- toolbar,
860
- copyButton,
861
- editButton,
862
- branchNavigation,
863
- children,
864
- className,
865
- ...props
866
- }) {
867
- const flattenedContent = (0, import_react16.useMemo)(
868
- () => flattenUserMessageContent(message.content),
869
- [message.content]
870
- );
871
- const BoundMessageRenderer = renderSlot(
872
- messageRenderer,
873
- CopilotChatUserMessage.MessageRenderer,
874
- {
875
- content: flattenedContent
876
- }
877
- );
878
- const BoundCopyButton = renderSlot(
879
- copyButton,
880
- CopilotChatUserMessage.CopyButton,
881
- {
882
- onClick: async () => {
883
- if (flattenedContent) {
884
- try {
885
- await navigator.clipboard.writeText(flattenedContent);
886
- } catch (err) {
887
- console.error("Failed to copy message:", err);
888
- }
889
- }
890
- }
891
- }
892
- );
893
- const BoundEditButton = renderSlot(
894
- editButton,
895
- CopilotChatUserMessage.EditButton,
896
- {
897
- onClick: () => onEditMessage?.({ message })
898
- }
899
- );
900
- const BoundBranchNavigation = renderSlot(
901
- branchNavigation,
902
- CopilotChatUserMessage.BranchNavigation,
903
- {
904
- currentBranch: branchIndex,
905
- numberOfBranches,
906
- onSwitchToBranch,
907
- message
908
- }
909
- );
910
- const showBranchNavigation = numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
911
- const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
912
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex items-center gap-1 justify-end", children: [
913
- additionalToolbarItems,
914
- BoundCopyButton,
915
- onEditMessage && BoundEditButton,
916
- showBranchNavigation && BoundBranchNavigation
917
- ] })
918
- });
919
- if (children) {
920
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: children({
921
- messageRenderer: BoundMessageRenderer,
922
- toolbar: BoundToolbar,
923
- copyButton: BoundCopyButton,
924
- editButton: BoundEditButton,
925
- branchNavigation: BoundBranchNavigation,
926
- message,
927
- branchIndex,
928
- numberOfBranches,
929
- additionalToolbarItems
930
- }) });
931
- }
932
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
933
- "div",
934
- {
935
- className: (0, import_tailwind_merge3.twMerge)("flex flex-col items-end group pt-10", className),
936
- "data-message-id": message.id,
937
- ...props,
938
- children: [
939
- BoundMessageRenderer,
940
- BoundToolbar
941
- ]
942
- }
943
- );
944
- }
945
- ((CopilotChatUserMessage2) => {
946
- CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
947
- "div",
948
- {
949
- className: (0, import_tailwind_merge3.twMerge)("flex flex-col items-end group", className),
950
- ...props,
951
- children
952
- }
953
- );
954
- CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
955
- "div",
956
- {
957
- className: (0, import_tailwind_merge3.twMerge)(
958
- "prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
959
- className
960
- ),
961
- children: content
962
- }
963
- );
964
- CopilotChatUserMessage2.Toolbar = ({
965
- className,
966
- ...props
967
- }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
968
- "div",
969
- {
970
- className: (0, import_tailwind_merge3.twMerge)(
971
- "w-full bg-transparent flex items-center justify-end -mr-[5px] mt-[4px] invisible group-hover:visible",
972
- className
973
- ),
974
- ...props
975
- }
976
- );
977
- CopilotChatUserMessage2.ToolbarButton = ({ title, children, className, ...props }) => {
978
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Tooltip, { children: [
979
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
980
- Button,
981
- {
982
- type: "button",
983
- variant: "assistantMessageToolbarButton",
984
- "aria-label": title,
985
- className: (0, import_tailwind_merge3.twMerge)(className),
986
- ...props,
987
- children
988
- }
989
- ) }),
990
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children: title }) })
991
- ] });
992
- };
993
- CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
994
- const config = useCopilotChatConfiguration();
995
- const labels = config?.labels ?? CopilotChatDefaultLabels;
996
- const [copied, setCopied] = (0, import_react16.useState)(false);
997
- const handleClick = (event) => {
998
- setCopied(true);
999
- setTimeout(() => setCopied(false), 2e3);
1000
- if (onClick) {
1001
- onClick(event);
1002
- }
1003
- };
1004
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1005
- CopilotChatUserMessage2.ToolbarButton,
1006
- {
1007
- title: title || labels.userMessageToolbarCopyMessageLabel,
1008
- onClick: handleClick,
1009
- className,
1010
- ...props,
1011
- children: copied ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Check, { className: "size-[18px]" }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Copy, { className: "size-[18px]" })
1012
- }
1013
- );
1014
- };
1015
- CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
1016
- const config = useCopilotChatConfiguration();
1017
- const labels = config?.labels ?? CopilotChatDefaultLabels;
1018
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1019
- CopilotChatUserMessage2.ToolbarButton,
1020
- {
1021
- title: title || labels.userMessageToolbarEditMessageLabel,
1022
- className,
1023
- ...props,
1024
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Edit, { className: "size-[18px]" })
1025
- }
1026
- );
1027
- };
1028
- CopilotChatUserMessage2.BranchNavigation = ({
1029
- className,
1030
- currentBranch = 0,
1031
- numberOfBranches = 1,
1032
- onSwitchToBranch,
1033
- message,
1034
- ...props
1035
- }) => {
1036
- if (!numberOfBranches || numberOfBranches <= 1 || !onSwitchToBranch) {
1037
- return null;
1038
- }
1039
- const canGoPrev = currentBranch > 0;
1040
- const canGoNext = currentBranch < numberOfBranches - 1;
1041
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: (0, import_tailwind_merge3.twMerge)("flex items-center gap-1", className), ...props, children: [
1042
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1043
- Button,
1044
- {
1045
- type: "button",
1046
- variant: "assistantMessageToolbarButton",
1047
- onClick: () => onSwitchToBranch?.({
1048
- branchIndex: currentBranch - 1,
1049
- numberOfBranches,
1050
- message
1051
- }),
1052
- disabled: !canGoPrev,
1053
- className: "h-6 w-6 p-0",
1054
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.ChevronLeft, { className: "size-[20px]" })
1055
- }
1056
- ),
1057
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "text-sm text-muted-foreground px-0 font-medium", children: [
1058
- currentBranch + 1,
1059
- "/",
1060
- numberOfBranches
1061
- ] }),
1062
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1063
- Button,
1064
- {
1065
- type: "button",
1066
- variant: "assistantMessageToolbarButton",
1067
- onClick: () => onSwitchToBranch?.({
1068
- branchIndex: currentBranch + 1,
1069
- numberOfBranches,
1070
- message
1071
- }),
1072
- disabled: !canGoNext,
1073
- className: "h-6 w-6 p-0",
1074
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.ChevronRight, { className: "size-[20px]" })
1075
- }
1076
- )
1077
- ] });
1078
- };
1079
- })(CopilotChatUserMessage || (CopilotChatUserMessage = {}));
1080
- CopilotChatUserMessage.Container.displayName = "CopilotChatUserMessage.Container";
1081
- CopilotChatUserMessage.MessageRenderer.displayName = "CopilotChatUserMessage.MessageRenderer";
1082
- CopilotChatUserMessage.Toolbar.displayName = "CopilotChatUserMessage.Toolbar";
1083
- CopilotChatUserMessage.ToolbarButton.displayName = "CopilotChatUserMessage.ToolbarButton";
1084
- CopilotChatUserMessage.CopyButton.displayName = "CopilotChatUserMessage.CopyButton";
1085
- CopilotChatUserMessage.EditButton.displayName = "CopilotChatUserMessage.EditButton";
1086
- CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.BranchNavigation";
1087
- var CopilotChatUserMessage_default = CopilotChatUserMessage;
1088
-
1089
- // src/components/chat/CopilotChatMessageView.tsx
1090
- var import_tailwind_merge4 = require("tailwind-merge");
1091
- var import_jsx_runtime12 = require("react/jsx-runtime");
1092
- function CopilotChatMessageView({
1093
- messages = [],
1094
- assistantMessage,
1095
- userMessage,
1096
- cursor,
1097
- isRunning = false,
1098
- children,
1099
- className,
1100
- ...props
1101
- }) {
1102
- const renderCustomMessage = useRenderCustomMessages();
1103
- const renderActivityMessage = useRenderActivityMessage();
1104
- const messageElements = messages.flatMap((message) => {
1105
- const elements = [];
1106
- if (renderCustomMessage) {
1107
- elements.push(
1108
- renderCustomMessage({
1109
- message,
1110
- position: "before"
1111
- })
1112
- );
1113
- }
1114
- if (message.role === "assistant") {
1115
- elements.push(
1116
- renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
1117
- key: message.id,
1118
- message,
1119
- messages,
1120
- isRunning
1121
- })
1122
- );
1123
- } else if (message.role === "user") {
1124
- elements.push(
1125
- renderSlot(userMessage, CopilotChatUserMessage_default, {
1126
- key: message.id,
1127
- message
1128
- })
1129
- );
1130
- } else if (message.role === "activity") {
1131
- const renderedActivity = renderActivityMessage(message);
1132
- if (renderedActivity) {
1133
- elements.push(renderedActivity);
1134
- }
1135
- }
1136
- if (renderCustomMessage) {
1137
- elements.push(
1138
- renderCustomMessage({
1139
- message,
1140
- position: "after"
1141
- })
1142
- );
1143
- }
1144
- return elements;
1145
- }).filter(Boolean);
1146
- if (children) {
1147
- return children({ messageElements, messages, isRunning });
1148
- }
1149
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: (0, import_tailwind_merge4.twMerge)("flex flex-col", className), ...props, children: [
1150
- messageElements,
1151
- isRunning && renderSlot(cursor, CopilotChatMessageView.Cursor, {})
1152
- ] });
1153
- }
1154
- CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
1155
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1156
- "div",
1157
- {
1158
- className: (0, import_tailwind_merge4.twMerge)("w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1", className),
1159
- ...props
1160
- }
1161
- );
1162
- };
1163
- var CopilotChatMessageView_default = CopilotChatMessageView;
1164
-
1165
- // src/components/chat/CopilotChatInput.tsx
1166
- var import_react18 = require("react");
1167
- var import_tailwind_merge6 = require("tailwind-merge");
1168
- var import_lucide_react4 = require("lucide-react");
1169
-
1170
- // src/components/ui/dropdown-menu.tsx
1171
- var DropdownMenuPrimitive = __toESM(require("@radix-ui/react-dropdown-menu"));
1172
- var import_lucide_react3 = require("lucide-react");
1173
- var import_jsx_runtime13 = require("react/jsx-runtime");
1174
- function DropdownMenu({
1175
- ...props
1176
- }) {
1177
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
1178
- }
1179
- function DropdownMenuTrigger({
1180
- ...props
1181
- }) {
1182
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1183
- DropdownMenuPrimitive.Trigger,
1184
- {
1185
- "data-slot": "dropdown-menu-trigger",
1186
- ...props
1187
- }
1188
- );
1189
- }
1190
- function DropdownMenuContent({
1191
- className,
1192
- sideOffset = 4,
1193
- ...props
1194
- }) {
1195
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1196
- DropdownMenuPrimitive.Content,
1197
- {
1198
- "data-slot": "dropdown-menu-content",
1199
- sideOffset,
1200
- className: cn(
1201
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
1202
- className
1203
- ),
1204
- ...props
1205
- }
1206
- ) });
1207
- }
1208
- function DropdownMenuItem({
1209
- className,
1210
- inset,
1211
- variant = "default",
1212
- ...props
1213
- }) {
1214
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1215
- DropdownMenuPrimitive.Item,
1216
- {
1217
- "data-slot": "dropdown-menu-item",
1218
- "data-inset": inset,
1219
- "data-variant": variant,
1220
- className: cn(
1221
- "focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
1222
- className
1223
- ),
1224
- ...props
1225
- }
1226
- );
1227
- }
1228
- function DropdownMenuSeparator({
1229
- className,
1230
- ...props
1231
- }) {
1232
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1233
- DropdownMenuPrimitive.Separator,
1234
- {
1235
- "data-slot": "dropdown-menu-separator",
1236
- className: cn("bg-border -mx-1 my-1 h-px", className),
1237
- ...props
1238
- }
1239
- );
1240
- }
1241
- function DropdownMenuSub({
1242
- ...props
1243
- }) {
1244
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DropdownMenuPrimitive.Sub, { "data-slot": "dropdown-menu-sub", ...props });
1245
- }
1246
- function DropdownMenuSubTrigger({
1247
- className,
1248
- inset,
1249
- children,
1250
- ...props
1251
- }) {
1252
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1253
- DropdownMenuPrimitive.SubTrigger,
1254
- {
1255
- "data-slot": "dropdown-menu-sub-trigger",
1256
- "data-inset": inset,
1257
- className: cn(
1258
- "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
1259
- className
1260
- ),
1261
- ...props,
1262
- children: [
1263
- children,
1264
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.ChevronRightIcon, { className: "ml-auto size-4" })
1265
- ]
1266
- }
1267
- );
1268
- }
1269
- function DropdownMenuSubContent({
1270
- className,
1271
- ...props
1272
- }) {
1273
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1274
- DropdownMenuPrimitive.SubContent,
1275
- {
1276
- "data-slot": "dropdown-menu-sub-content",
1277
- className: cn(
1278
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
1279
- className
1280
- ),
1281
- ...props
1282
- }
1283
- );
1284
- }
1285
-
1286
- // src/components/chat/CopilotChatAudioRecorder.tsx
1287
- var import_react17 = require("react");
1288
- var import_tailwind_merge5 = require("tailwind-merge");
1289
- var import_jsx_runtime14 = require("react/jsx-runtime");
1290
- var CopilotChatAudioRecorder = (0, import_react17.forwardRef)((props, ref) => {
1291
- const { className, ...divProps } = props;
1292
- const canvasRef = (0, import_react17.useRef)(null);
1293
- const getLoudness = (n) => {
1294
- const elapsed = Date.now() / 1e3;
1295
- const samples = [];
1296
- for (let i = 0; i < n; i++) {
1297
- const position = i / n * 10 + elapsed * 0.5;
1298
- const wave1 = Math.sin(position * 2) * 0.3;
1299
- const wave2 = Math.sin(position * 5 + elapsed) * 0.2;
1300
- const wave3 = Math.sin(position * 0.5 + elapsed * 0.3) * 0.4;
1301
- const noise = (Math.random() - 0.5) * 0.1;
1302
- const envelope = Math.sin(elapsed * 0.7) * 0.5 + 0.5;
1303
- let amplitude = (wave1 + wave2 + wave3 + noise) * envelope;
1304
- amplitude = Math.max(0, Math.min(1, amplitude * 0.5 + 0.3));
1305
- samples.push(amplitude);
1306
- }
1307
- return samples;
1308
- };
1309
- (0, import_react17.useEffect)(() => {
1310
- const canvas = canvasRef.current;
1311
- if (!canvas) return;
1312
- const ctx = canvas.getContext("2d");
1313
- if (!ctx) return;
1314
- let animationId;
1315
- const draw = () => {
1316
- const rect = canvas.getBoundingClientRect();
1317
- const dpr = window.devicePixelRatio || 1;
1318
- if (canvas.width !== rect.width * dpr || canvas.height !== rect.height * dpr) {
1319
- canvas.width = rect.width * dpr;
1320
- canvas.height = rect.height * dpr;
1321
- ctx.scale(dpr, dpr);
1322
- ctx.imageSmoothingEnabled = false;
1323
- }
1324
- const barWidth = 2;
1325
- const minHeight = 2;
1326
- const maxHeight = 20;
1327
- const gap = 2;
1328
- const numSamples = Math.ceil(rect.width / (barWidth + gap));
1329
- const loudnessData = getLoudness(numSamples);
1330
- ctx.clearRect(0, 0, rect.width, rect.height);
1331
- const computedStyle = getComputedStyle(canvas);
1332
- const currentForeground = computedStyle.color;
1333
- ctx.fillStyle = currentForeground;
1334
- const centerY = rect.height / 2;
1335
- for (let i = 0; i < loudnessData.length; i++) {
1336
- const sample = loudnessData[i] ?? 0;
1337
- const barHeight = Math.round(
1338
- sample * (maxHeight - minHeight) + minHeight
1339
- );
1340
- const x = Math.round(i * (barWidth + gap));
1341
- const y = Math.round(centerY - barHeight / 2);
1342
- ctx.fillRect(x, y, barWidth, barHeight);
1343
- }
1344
- animationId = requestAnimationFrame(draw);
1345
- };
1346
- draw();
1347
- return () => {
1348
- if (animationId) {
1349
- cancelAnimationFrame(animationId);
1350
- }
1351
- };
1352
- }, []);
1353
- (0, import_react17.useImperativeHandle)(
1354
- ref,
1355
- () => ({
1356
- get state() {
1357
- return "idle";
1358
- },
1359
- start: async () => {
1360
- },
1361
- stop: () => new Promise((resolve) => {
1362
- const emptyBlob = new Blob([], { type: "audio/webm" });
1363
- resolve(emptyBlob);
1364
- }),
1365
- dispose: () => {
1366
- }
1367
- }),
1368
- []
1369
- );
1370
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: (0, import_tailwind_merge5.twMerge)("h-[44px] w-full px-5", className), ...divProps, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1371
- "canvas",
1372
- {
1373
- ref: canvasRef,
1374
- className: "w-full h-full",
1375
- style: { imageRendering: "pixelated" }
1376
- }
1377
- ) });
1378
- });
1379
- CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
1380
-
1381
- // src/components/chat/CopilotChatInput.tsx
1382
- var import_jsx_runtime15 = require("react/jsx-runtime");
1383
- var SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
1384
- var SLASH_MENU_ITEM_HEIGHT_PX = 40;
1385
- function CopilotChatInput({
1386
- mode = "input",
1387
- onSubmitMessage,
1388
- onStop,
1389
- isRunning = false,
1390
- onStartTranscribe,
1391
- onCancelTranscribe,
1392
- onFinishTranscribe,
1393
- onAddFile,
1394
- onChange,
1395
- value,
1396
- toolsMenu,
1397
- autoFocus = true,
1398
- textArea,
1399
- sendButton,
1400
- startTranscribeButton,
1401
- cancelTranscribeButton,
1402
- finishTranscribeButton,
1403
- addMenuButton,
1404
- audioRecorder,
1405
- children,
1406
- className,
1407
- ...props
1408
- }) {
1409
- const isControlled = value !== void 0;
1410
- const [internalValue, setInternalValue] = (0, import_react18.useState)(() => value ?? "");
1411
- (0, import_react18.useEffect)(() => {
1412
- if (!isControlled && value !== void 0) {
1413
- setInternalValue(value);
1414
- }
1415
- }, [isControlled, value]);
1416
- const resolvedValue = isControlled ? value ?? "" : internalValue;
1417
- const [layout, setLayout] = (0, import_react18.useState)("compact");
1418
- const ignoreResizeRef = (0, import_react18.useRef)(false);
1419
- const resizeEvaluationRafRef = (0, import_react18.useRef)(null);
1420
- const isExpanded = mode === "input" && layout === "expanded";
1421
- const [commandQuery, setCommandQuery] = (0, import_react18.useState)(null);
1422
- const [slashHighlightIndex, setSlashHighlightIndex] = (0, import_react18.useState)(0);
1423
- const inputRef = (0, import_react18.useRef)(null);
1424
- const gridRef = (0, import_react18.useRef)(null);
1425
- const addButtonContainerRef = (0, import_react18.useRef)(null);
1426
- const actionsContainerRef = (0, import_react18.useRef)(null);
1427
- const audioRecorderRef = (0, import_react18.useRef)(null);
1428
- const slashMenuRef = (0, import_react18.useRef)(null);
1429
- const config = useCopilotChatConfiguration();
1430
- const labels = config?.labels ?? CopilotChatDefaultLabels;
1431
- const previousModalStateRef = (0, import_react18.useRef)(void 0);
1432
- const measurementCanvasRef = (0, import_react18.useRef)(null);
1433
- const measurementsRef = (0, import_react18.useRef)({
1434
- singleLineHeight: 0,
1435
- maxHeight: 0,
1436
- paddingLeft: 0,
1437
- paddingRight: 0
1438
- });
1439
- const commandItems = (0, import_react18.useMemo)(() => {
1440
- const entries = [];
1441
- const seen = /* @__PURE__ */ new Set();
1442
- const pushItem = (item) => {
1443
- if (item === "-") {
1444
- return;
1445
- }
1446
- if (item.items && item.items.length > 0) {
1447
- for (const nested of item.items) {
1448
- pushItem(nested);
1449
- }
1450
- return;
1451
- }
1452
- if (!seen.has(item.label)) {
1453
- seen.add(item.label);
1454
- entries.push(item);
1455
- }
1456
- };
1457
- if (onAddFile) {
1458
- pushItem({
1459
- label: labels.chatInputToolbarAddButtonLabel,
1460
- action: onAddFile
1461
- });
1462
- }
1463
- if (toolsMenu && toolsMenu.length > 0) {
1464
- for (const item of toolsMenu) {
1465
- pushItem(item);
1466
- }
1467
- }
1468
- return entries;
1469
- }, [labels.chatInputToolbarAddButtonLabel, onAddFile, toolsMenu]);
1470
- const filteredCommands = (0, import_react18.useMemo)(() => {
1471
- if (commandQuery === null) {
1472
- return [];
1473
- }
1474
- if (commandItems.length === 0) {
1475
- return [];
1476
- }
1477
- const query = commandQuery.trim().toLowerCase();
1478
- if (query.length === 0) {
1479
- return commandItems;
1480
- }
1481
- const startsWith = [];
1482
- const contains = [];
1483
- for (const item of commandItems) {
1484
- const label = item.label.toLowerCase();
1485
- if (label.startsWith(query)) {
1486
- startsWith.push(item);
1487
- } else if (label.includes(query)) {
1488
- contains.push(item);
1489
- }
1490
- }
1491
- return [...startsWith, ...contains];
1492
- }, [commandItems, commandQuery]);
1493
- (0, import_react18.useEffect)(() => {
1494
- if (!autoFocus) {
1495
- previousModalStateRef.current = config?.isModalOpen;
1496
- return;
1497
- }
1498
- if (config?.isModalOpen && !previousModalStateRef.current) {
1499
- inputRef.current?.focus();
1500
- }
1501
- previousModalStateRef.current = config?.isModalOpen;
1502
- }, [config?.isModalOpen, autoFocus]);
1503
- (0, import_react18.useEffect)(() => {
1504
- if (commandItems.length === 0 && commandQuery !== null) {
1505
- setCommandQuery(null);
1506
- }
1507
- }, [commandItems.length, commandQuery]);
1508
- const previousCommandQueryRef = (0, import_react18.useRef)(null);
1509
- (0, import_react18.useEffect)(() => {
1510
- if (commandQuery !== null && commandQuery !== previousCommandQueryRef.current && filteredCommands.length > 0) {
1511
- setSlashHighlightIndex(0);
1512
- }
1513
- previousCommandQueryRef.current = commandQuery;
1514
- }, [commandQuery, filteredCommands.length]);
1515
- (0, import_react18.useEffect)(() => {
1516
- if (commandQuery === null) {
1517
- setSlashHighlightIndex(0);
1518
- return;
1519
- }
1520
- if (filteredCommands.length === 0) {
1521
- setSlashHighlightIndex(-1);
1522
- } else if (slashHighlightIndex < 0 || slashHighlightIndex >= filteredCommands.length) {
1523
- setSlashHighlightIndex(0);
1524
- }
1525
- }, [commandQuery, filteredCommands, slashHighlightIndex]);
1526
- (0, import_react18.useEffect)(() => {
1527
- const recorder = audioRecorderRef.current;
1528
- if (!recorder) {
1529
- return;
1530
- }
1531
- if (mode === "transcribe") {
1532
- recorder.start().catch(console.error);
1533
- } else {
1534
- if (recorder.state === "recording") {
1535
- recorder.stop().catch(console.error);
1536
- }
1537
- }
1538
- }, [mode]);
1539
- (0, import_react18.useEffect)(() => {
1540
- if (mode !== "input") {
1541
- setLayout("compact");
1542
- setCommandQuery(null);
1543
- }
1544
- }, [mode]);
1545
- const updateSlashState = (0, import_react18.useCallback)(
1546
- (value2) => {
1547
- if (commandItems.length === 0) {
1548
- setCommandQuery((prev) => prev === null ? prev : null);
1549
- return;
1550
- }
1551
- if (value2.startsWith("/")) {
1552
- const firstLine = value2.split(/\r?\n/, 1)[0] ?? "";
1553
- const query = firstLine.slice(1);
1554
- setCommandQuery((prev) => prev === query ? prev : query);
1555
- } else {
1556
- setCommandQuery((prev) => prev === null ? prev : null);
1557
- }
1558
- },
1559
- [commandItems.length]
1560
- );
1561
- (0, import_react18.useEffect)(() => {
1562
- updateSlashState(resolvedValue);
1563
- }, [resolvedValue, updateSlashState]);
1564
- const handleChange = (e) => {
1565
- const nextValue = e.target.value;
1566
- if (!isControlled) {
1567
- setInternalValue(nextValue);
1568
- }
1569
- onChange?.(nextValue);
1570
- updateSlashState(nextValue);
1571
- };
1572
- const clearInputValue = (0, import_react18.useCallback)(() => {
1573
- if (!isControlled) {
1574
- setInternalValue("");
1575
- }
1576
- if (onChange) {
1577
- onChange("");
1578
- }
1579
- }, [isControlled, onChange]);
1580
- const runCommand = (0, import_react18.useCallback)(
1581
- (item) => {
1582
- clearInputValue();
1583
- item.action?.();
1584
- setCommandQuery(null);
1585
- setSlashHighlightIndex(0);
1586
- requestAnimationFrame(() => {
1587
- inputRef.current?.focus();
1588
- });
1589
- },
1590
- [clearInputValue]
1591
- );
1592
- const handleKeyDown = (e) => {
1593
- if (commandQuery !== null && mode === "input") {
1594
- if (e.key === "ArrowDown") {
1595
- if (filteredCommands.length > 0) {
1596
- e.preventDefault();
1597
- setSlashHighlightIndex((prev) => {
1598
- if (filteredCommands.length === 0) {
1599
- return prev;
1600
- }
1601
- const next = prev === -1 ? 0 : (prev + 1) % filteredCommands.length;
1602
- return next;
1603
- });
1604
- }
1605
- return;
1606
- }
1607
- if (e.key === "ArrowUp") {
1608
- if (filteredCommands.length > 0) {
1609
- e.preventDefault();
1610
- setSlashHighlightIndex((prev) => {
1611
- if (filteredCommands.length === 0) {
1612
- return prev;
1613
- }
1614
- if (prev === -1) {
1615
- return filteredCommands.length - 1;
1616
- }
1617
- return prev <= 0 ? filteredCommands.length - 1 : prev - 1;
1618
- });
1619
- }
1620
- return;
1621
- }
1622
- if (e.key === "Enter") {
1623
- const selected = slashHighlightIndex >= 0 ? filteredCommands[slashHighlightIndex] : void 0;
1624
- if (selected) {
1625
- e.preventDefault();
1626
- runCommand(selected);
1627
- return;
1628
- }
1629
- }
1630
- if (e.key === "Escape") {
1631
- e.preventDefault();
1632
- setCommandQuery(null);
1633
- return;
1634
- }
1635
- }
1636
- if (e.key === "Enter" && !e.shiftKey) {
1637
- e.preventDefault();
1638
- if (isProcessing) {
1639
- onStop?.();
1640
- } else {
1641
- send();
1642
- }
1643
- }
1644
- };
1645
- const send = () => {
1646
- if (!onSubmitMessage) {
1647
- return;
1648
- }
1649
- const trimmed = resolvedValue.trim();
1650
- if (!trimmed) {
1651
- return;
1652
- }
1653
- onSubmitMessage(trimmed);
1654
- if (!isControlled) {
1655
- setInternalValue("");
1656
- onChange?.("");
1657
- }
1658
- if (inputRef.current) {
1659
- inputRef.current.focus();
1660
- }
1661
- };
1662
- const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
1663
- ref: inputRef,
1664
- value: resolvedValue,
1665
- onChange: handleChange,
1666
- onKeyDown: handleKeyDown,
1667
- autoFocus,
1668
- className: (0, import_tailwind_merge6.twMerge)(
1669
- "w-full py-3",
1670
- isExpanded ? "px-5" : "pr-5"
1671
- )
1672
- });
1673
- const isProcessing = mode !== "transcribe" && isRunning;
1674
- const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
1675
- const canStop = !!onStop;
1676
- const handleSendButtonClick = () => {
1677
- if (isProcessing) {
1678
- onStop?.();
1679
- return;
1680
- }
1681
- send();
1682
- };
1683
- const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
1684
- ref: audioRecorderRef
1685
- });
1686
- const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
1687
- onClick: handleSendButtonClick,
1688
- disabled: isProcessing ? !canStop : !canSend,
1689
- children: isProcessing && canStop ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.Square, { className: "size-[18px] fill-current" }) : void 0
1690
- });
1691
- const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
1692
- onClick: onStartTranscribe
1693
- });
1694
- const BoundCancelTranscribeButton = renderSlot(cancelTranscribeButton, CopilotChatInput.CancelTranscribeButton, {
1695
- onClick: onCancelTranscribe
1696
- });
1697
- const BoundFinishTranscribeButton = renderSlot(finishTranscribeButton, CopilotChatInput.FinishTranscribeButton, {
1698
- onClick: onFinishTranscribe
1699
- });
1700
- const BoundAddMenuButton = renderSlot(addMenuButton, CopilotChatInput.AddMenuButton, {
1701
- disabled: mode === "transcribe",
1702
- onAddFile,
1703
- toolsMenu
1704
- });
1705
- if (children) {
1706
- const childProps = {
1707
- textArea: BoundTextArea,
1708
- audioRecorder: BoundAudioRecorder,
1709
- sendButton: BoundSendButton,
1710
- startTranscribeButton: BoundStartTranscribeButton,
1711
- cancelTranscribeButton: BoundCancelTranscribeButton,
1712
- finishTranscribeButton: BoundFinishTranscribeButton,
1713
- addMenuButton: BoundAddMenuButton,
1714
- onSubmitMessage,
1715
- onStop,
1716
- isRunning,
1717
- onStartTranscribe,
1718
- onCancelTranscribe,
1719
- onFinishTranscribe,
1720
- onAddFile,
1721
- mode,
1722
- toolsMenu,
1723
- autoFocus
1724
- };
1725
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: children(childProps) });
1726
- }
1727
- const handleContainerClick = (e) => {
1728
- const target = e.target;
1729
- if (target.tagName !== "BUTTON" && !target.closest("button") && inputRef.current && mode === "input") {
1730
- inputRef.current.focus();
1731
- }
1732
- };
1733
- const ensureMeasurements = (0, import_react18.useCallback)(() => {
1734
- const textarea = inputRef.current;
1735
- if (!textarea) {
1736
- return;
1737
- }
1738
- const previousValue = textarea.value;
1739
- const previousHeight = textarea.style.height;
1740
- textarea.style.height = "auto";
1741
- const computedStyle = window.getComputedStyle(textarea);
1742
- const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
1743
- const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
1744
- const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
1745
- const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0;
1746
- textarea.value = "";
1747
- const singleLineHeight = textarea.scrollHeight;
1748
- textarea.value = previousValue;
1749
- const contentHeight = singleLineHeight - paddingTop - paddingBottom;
1750
- const maxHeight = contentHeight * 5 + paddingTop + paddingBottom;
1751
- measurementsRef.current = {
1752
- singleLineHeight,
1753
- maxHeight,
1754
- paddingLeft,
1755
- paddingRight
1756
- };
1757
- textarea.style.height = previousHeight;
1758
- textarea.style.maxHeight = `${maxHeight}px`;
1759
- }, []);
1760
- const adjustTextareaHeight = (0, import_react18.useCallback)(() => {
1761
- const textarea = inputRef.current;
1762
- if (!textarea) {
1763
- return 0;
1764
- }
1765
- if (measurementsRef.current.singleLineHeight === 0) {
1766
- ensureMeasurements();
1767
- }
1768
- const { maxHeight } = measurementsRef.current;
1769
- if (maxHeight) {
1770
- textarea.style.maxHeight = `${maxHeight}px`;
1771
- }
1772
- textarea.style.height = "auto";
1773
- const scrollHeight = textarea.scrollHeight;
1774
- if (maxHeight) {
1775
- textarea.style.height = `${Math.min(scrollHeight, maxHeight)}px`;
1776
- } else {
1777
- textarea.style.height = `${scrollHeight}px`;
1778
- }
1779
- return scrollHeight;
1780
- }, [ensureMeasurements]);
1781
- const updateLayout = (0, import_react18.useCallback)((nextLayout) => {
1782
- setLayout((prev) => {
1783
- if (prev === nextLayout) {
1784
- return prev;
1785
- }
1786
- ignoreResizeRef.current = true;
1787
- return nextLayout;
1788
- });
1789
- }, []);
1790
- const evaluateLayout = (0, import_react18.useCallback)(() => {
1791
- if (mode !== "input") {
1792
- updateLayout("compact");
1793
- return;
1794
- }
1795
- if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
1796
- const isMobileViewport = window.matchMedia("(max-width: 767px)").matches;
1797
- if (isMobileViewport) {
1798
- ensureMeasurements();
1799
- adjustTextareaHeight();
1800
- updateLayout("expanded");
1801
- return;
1802
- }
1803
- }
1804
- const textarea = inputRef.current;
1805
- const grid = gridRef.current;
1806
- const addContainer = addButtonContainerRef.current;
1807
- const actionsContainer = actionsContainerRef.current;
1808
- if (!textarea || !grid || !addContainer || !actionsContainer) {
1809
- return;
1810
- }
1811
- if (measurementsRef.current.singleLineHeight === 0) {
1812
- ensureMeasurements();
1813
- }
1814
- const scrollHeight = adjustTextareaHeight();
1815
- const baseline = measurementsRef.current.singleLineHeight;
1816
- const hasExplicitBreak = resolvedValue.includes("\n");
1817
- const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
1818
- let shouldExpand = hasExplicitBreak || renderedMultiline;
1819
- if (!shouldExpand) {
1820
- const gridStyles = window.getComputedStyle(grid);
1821
- const paddingLeft = parseFloat(gridStyles.paddingLeft) || 0;
1822
- const paddingRight = parseFloat(gridStyles.paddingRight) || 0;
1823
- const columnGap = parseFloat(gridStyles.columnGap) || 0;
1824
- const gridAvailableWidth = grid.clientWidth - paddingLeft - paddingRight;
1825
- if (gridAvailableWidth > 0) {
1826
- const addWidth = addContainer.getBoundingClientRect().width;
1827
- const actionsWidth = actionsContainer.getBoundingClientRect().width;
1828
- const compactWidth = Math.max(gridAvailableWidth - addWidth - actionsWidth - columnGap * 2, 0);
1829
- const canvas = measurementCanvasRef.current ?? document.createElement("canvas");
1830
- if (!measurementCanvasRef.current) {
1831
- measurementCanvasRef.current = canvas;
1832
- }
1833
- const context = canvas.getContext("2d");
1834
- if (context) {
1835
- const textareaStyles = window.getComputedStyle(textarea);
1836
- const font = textareaStyles.font || `${textareaStyles.fontStyle} ${textareaStyles.fontVariant} ${textareaStyles.fontWeight} ${textareaStyles.fontSize}/${textareaStyles.lineHeight} ${textareaStyles.fontFamily}`;
1837
- context.font = font;
1838
- const compactInnerWidth = Math.max(
1839
- compactWidth - (measurementsRef.current.paddingLeft || 0) - (measurementsRef.current.paddingRight || 0),
1840
- 0
1841
- );
1842
- if (compactInnerWidth > 0) {
1843
- const lines = resolvedValue.length > 0 ? resolvedValue.split("\n") : [""];
1844
- let longestWidth = 0;
1845
- for (const line of lines) {
1846
- const metrics = context.measureText(line || " ");
1847
- if (metrics.width > longestWidth) {
1848
- longestWidth = metrics.width;
1849
- }
1850
- }
1851
- if (longestWidth > compactInnerWidth) {
1852
- shouldExpand = true;
1853
- }
1854
- }
1855
- }
1856
- }
1857
- }
1858
- const nextLayout = shouldExpand ? "expanded" : "compact";
1859
- updateLayout(nextLayout);
1860
- }, [adjustTextareaHeight, ensureMeasurements, mode, resolvedValue, updateLayout]);
1861
- (0, import_react18.useLayoutEffect)(() => {
1862
- evaluateLayout();
1863
- }, [evaluateLayout]);
1864
- (0, import_react18.useEffect)(() => {
1865
- if (typeof ResizeObserver === "undefined") {
1866
- return;
1867
- }
1868
- const textarea = inputRef.current;
1869
- const grid = gridRef.current;
1870
- const addContainer = addButtonContainerRef.current;
1871
- const actionsContainer = actionsContainerRef.current;
1872
- if (!textarea || !grid || !addContainer || !actionsContainer) {
1873
- return;
1874
- }
1875
- const scheduleEvaluation = () => {
1876
- if (ignoreResizeRef.current) {
1877
- ignoreResizeRef.current = false;
1878
- return;
1879
- }
1880
- if (typeof window === "undefined") {
1881
- evaluateLayout();
1882
- return;
1883
- }
1884
- if (resizeEvaluationRafRef.current !== null) {
1885
- cancelAnimationFrame(resizeEvaluationRafRef.current);
1886
- }
1887
- resizeEvaluationRafRef.current = window.requestAnimationFrame(() => {
1888
- resizeEvaluationRafRef.current = null;
1889
- evaluateLayout();
1890
- });
1891
- };
1892
- const observer = new ResizeObserver(() => {
1893
- scheduleEvaluation();
1894
- });
1895
- observer.observe(grid);
1896
- observer.observe(addContainer);
1897
- observer.observe(actionsContainer);
1898
- observer.observe(textarea);
1899
- return () => {
1900
- observer.disconnect();
1901
- if (typeof window !== "undefined" && resizeEvaluationRafRef.current !== null) {
1902
- cancelAnimationFrame(resizeEvaluationRafRef.current);
1903
- resizeEvaluationRafRef.current = null;
1904
- }
1905
- };
1906
- }, [evaluateLayout]);
1907
- const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
1908
- (0, import_react18.useEffect)(() => {
1909
- if (!slashMenuVisible || slashHighlightIndex < 0) {
1910
- return;
1911
- }
1912
- const active = slashMenuRef.current?.querySelector(
1913
- `[data-slash-index="${slashHighlightIndex}"]`
1914
- );
1915
- active?.scrollIntoView({ block: "nearest" });
1916
- }, [slashMenuVisible, slashHighlightIndex]);
1917
- const slashMenu = slashMenuVisible ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1918
- "div",
1919
- {
1920
- "data-testid": "copilot-slash-menu",
1921
- role: "listbox",
1922
- "aria-label": "Slash commands",
1923
- ref: slashMenuRef,
1924
- className: "absolute bottom-full left-0 right-0 z-30 mb-2 max-h-64 overflow-y-auto rounded-lg border border-border bg-white shadow-lg dark:border-[#3a3a3a] dark:bg-[#1f1f1f]",
1925
- style: { maxHeight: `${SLASH_MENU_MAX_VISIBLE_ITEMS * SLASH_MENU_ITEM_HEIGHT_PX}px` },
1926
- children: filteredCommands.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No commands found" }) : filteredCommands.map((item, index) => {
1927
- const isActive = index === slashHighlightIndex;
1928
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1929
- "button",
1930
- {
1931
- type: "button",
1932
- role: "option",
1933
- "aria-selected": isActive,
1934
- "data-active": isActive ? "true" : void 0,
1935
- "data-slash-index": index,
1936
- className: (0, import_tailwind_merge6.twMerge)(
1937
- "w-full px-3 py-2 text-left text-sm transition-colors",
1938
- "hover:bg-muted dark:hover:bg-[#2f2f2f]",
1939
- isActive ? "bg-muted dark:bg-[#2f2f2f]" : "bg-transparent"
1940
- ),
1941
- onMouseEnter: () => setSlashHighlightIndex(index),
1942
- onMouseDown: (event) => {
1943
- event.preventDefault();
1944
- runCommand(item);
1945
- },
1946
- children: item.label
1947
- },
1948
- `${item.label}-${index}`
1949
- );
1950
- })
1951
- }
1952
- ) : null;
1953
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1954
- "div",
1955
- {
1956
- className: (0, import_tailwind_merge6.twMerge)(
1957
- // Layout
1958
- "flex w-full flex-col items-center justify-center",
1959
- // Interaction
1960
- "cursor-text",
1961
- // Overflow and clipping
1962
- "overflow-visible bg-clip-padding contain-inline-size",
1963
- // Background
1964
- "bg-white dark:bg-[#303030]",
1965
- // Visual effects
1966
- "shadow-[0_4px_4px_0_#0000000a,0_0_1px_0_#0000009e] rounded-[28px]",
1967
- className
1968
- ),
1969
- onClick: handleContainerClick,
1970
- ...props,
1971
- "data-layout": isExpanded ? "expanded" : "compact",
1972
- children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1973
- "div",
1974
- {
1975
- ref: gridRef,
1976
- className: (0, import_tailwind_merge6.twMerge)(
1977
- "grid w-full gap-x-3 gap-y-3 px-3 py-2",
1978
- isExpanded ? "grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_auto]" : "grid-cols-[auto_minmax(0,1fr)_auto] items-center"
1979
- ),
1980
- "data-layout": isExpanded ? "expanded" : "compact",
1981
- children: [
1982
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1983
- "div",
1984
- {
1985
- ref: addButtonContainerRef,
1986
- className: (0, import_tailwind_merge6.twMerge)(
1987
- "flex items-center",
1988
- isExpanded ? "row-start-2" : "row-start-1",
1989
- "col-start-1"
1990
- ),
1991
- children: BoundAddMenuButton
1992
- }
1993
- ),
1994
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1995
- "div",
1996
- {
1997
- className: (0, import_tailwind_merge6.twMerge)(
1998
- "relative flex min-w-0 flex-col",
1999
- isExpanded ? "col-span-3 row-start-1" : "col-start-2 row-start-1"
2000
- ),
2001
- children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
2002
- BoundTextArea,
2003
- slashMenu
2004
- ] })
2005
- }
2006
- ),
2007
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2008
- "div",
2009
- {
2010
- ref: actionsContainerRef,
2011
- className: (0, import_tailwind_merge6.twMerge)(
2012
- "flex items-center justify-end gap-2",
2013
- isExpanded ? "col-start-3 row-start-2" : "col-start-3 row-start-1"
2014
- ),
2015
- children: mode === "transcribe" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
2016
- onCancelTranscribe && BoundCancelTranscribeButton,
2017
- onFinishTranscribe && BoundFinishTranscribeButton
2018
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
2019
- onStartTranscribe && BoundStartTranscribeButton,
2020
- BoundSendButton
2021
- ] })
2022
- }
2023
- )
2024
- ]
2025
- }
2026
- )
2027
- }
2028
- );
2029
- }
2030
- ((CopilotChatInput2) => {
2031
- CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "mr-[10px]", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2032
- Button,
2033
- {
2034
- type: "button",
2035
- variant: "chatInputToolbarPrimary",
2036
- size: "chatInputToolbarIcon",
2037
- className,
2038
- ...props,
2039
- children: children ?? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.ArrowUp, { className: "size-[18px]" })
2040
- }
2041
- ) });
2042
- CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
2043
- const config = useCopilotChatConfiguration();
2044
- const labels = config?.labels ?? CopilotChatDefaultLabels;
2045
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Tooltip, { children: [
2046
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2047
- Button,
2048
- {
2049
- type: "button",
2050
- variant: "chatInputToolbarSecondary",
2051
- size: "chatInputToolbarIcon",
2052
- className: (0, import_tailwind_merge6.twMerge)(defaultClassName, className),
2053
- ...props,
2054
- children: icon
2055
- }
2056
- ) }),
2057
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: labels[labelKey] }) })
2058
- ] });
2059
- };
2060
- CopilotChatInput2.StartTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2061
- CopilotChatInput2.ToolbarButton,
2062
- {
2063
- icon: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.Mic, { className: "size-[18px]" }),
2064
- labelKey: "chatInputToolbarStartTranscribeButtonLabel",
2065
- defaultClassName: "mr-2",
2066
- ...props
2067
- }
2068
- );
2069
- CopilotChatInput2.CancelTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2070
- CopilotChatInput2.ToolbarButton,
2071
- {
2072
- icon: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.X, { className: "size-[18px]" }),
2073
- labelKey: "chatInputToolbarCancelTranscribeButtonLabel",
2074
- defaultClassName: "mr-2",
2075
- ...props
2076
- }
2077
- );
2078
- CopilotChatInput2.FinishTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2079
- CopilotChatInput2.ToolbarButton,
2080
- {
2081
- icon: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.Check, { className: "size-[18px]" }),
2082
- labelKey: "chatInputToolbarFinishTranscribeButtonLabel",
2083
- defaultClassName: "mr-[10px]",
2084
- ...props
2085
- }
2086
- );
2087
- CopilotChatInput2.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
2088
- const config = useCopilotChatConfiguration();
2089
- const labels = config?.labels ?? CopilotChatDefaultLabels;
2090
- const menuItems = (0, import_react18.useMemo)(() => {
2091
- const items = [];
2092
- if (onAddFile) {
2093
- items.push({
2094
- label: labels.chatInputToolbarAddButtonLabel,
2095
- action: onAddFile
2096
- });
2097
- }
2098
- if (toolsMenu && toolsMenu.length > 0) {
2099
- if (items.length > 0) {
2100
- items.push("-");
2101
- }
2102
- for (const item of toolsMenu) {
2103
- if (item === "-") {
2104
- if (items.length === 0 || items[items.length - 1] === "-") {
2105
- continue;
2106
- }
2107
- items.push(item);
2108
- } else {
2109
- items.push(item);
2110
- }
2111
- }
2112
- while (items.length > 0 && items[items.length - 1] === "-") {
2113
- items.pop();
2114
- }
2115
- }
2116
- return items;
2117
- }, [onAddFile, toolsMenu, labels.chatInputToolbarAddButtonLabel]);
2118
- const renderMenuItems = (0, import_react18.useCallback)(
2119
- (items) => items.map((item, index) => {
2120
- if (item === "-") {
2121
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuSeparator, {}, `separator-${index}`);
2122
- }
2123
- if (item.items && item.items.length > 0) {
2124
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(DropdownMenuSub, { children: [
2125
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuSubTrigger, { children: item.label }),
2126
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuSubContent, { children: renderMenuItems(item.items) })
2127
- ] }, `group-${index}`);
2128
- }
2129
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuItem, { onClick: item.action, children: item.label }, `item-${index}`);
2130
- }),
2131
- []
2132
- );
2133
- const hasMenuItems = menuItems.length > 0;
2134
- const isDisabled = disabled || !hasMenuItems;
2135
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(DropdownMenu, { children: [
2136
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Tooltip, { children: [
2137
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2138
- Button,
2139
- {
2140
- type: "button",
2141
- variant: "chatInputToolbarSecondary",
2142
- size: "chatInputToolbarIcon",
2143
- className: (0, import_tailwind_merge6.twMerge)("ml-1", className),
2144
- disabled: isDisabled,
2145
- ...props,
2146
- children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.Plus, { className: "size-[20px]" })
2147
- }
2148
- ) }) }),
2149
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("p", { className: "flex items-center gap-1 text-xs font-medium", children: [
2150
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: "Add files and more" }),
2151
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("code", { className: "rounded bg-[#4a4a4a] px-1 py-[1px] font-mono text-[11px] text-white dark:bg-[#e0e0e0] dark:text-black", children: "/" })
2152
- ] }) })
2153
- ] }),
2154
- hasMenuItems && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuContent, { side: "top", align: "start", children: renderMenuItems(menuItems) })
2155
- ] });
2156
- };
2157
- CopilotChatInput2.TextArea = (0, import_react18.forwardRef)(function TextArea2({ style, className, autoFocus, ...props }, ref) {
2158
- const internalTextareaRef = (0, import_react18.useRef)(null);
2159
- const config = useCopilotChatConfiguration();
2160
- const labels = config?.labels ?? CopilotChatDefaultLabels;
2161
- (0, import_react18.useImperativeHandle)(ref, () => internalTextareaRef.current);
2162
- (0, import_react18.useEffect)(() => {
2163
- const textarea = internalTextareaRef.current;
2164
- if (!textarea) return;
2165
- const handleFocus = () => {
2166
- setTimeout(() => {
2167
- textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
2168
- }, 300);
2169
- };
2170
- textarea.addEventListener("focus", handleFocus);
2171
- return () => textarea.removeEventListener("focus", handleFocus);
2172
- }, []);
2173
- (0, import_react18.useEffect)(() => {
2174
- if (autoFocus) {
2175
- internalTextareaRef.current?.focus();
2176
- }
2177
- }, [autoFocus]);
2178
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2179
- "textarea",
2180
- {
2181
- ref: internalTextareaRef,
2182
- ...props,
2183
- style: {
2184
- overflow: "auto",
2185
- resize: "none",
2186
- ...style
2187
- },
2188
- placeholder: labels.chatInputPlaceholder,
2189
- className: (0, import_tailwind_merge6.twMerge)(
2190
- "bg-transparent outline-none antialiased font-regular leading-relaxed text-[16px] placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
2191
- className
2192
- ),
2193
- rows: 1
2194
- }
2195
- );
2196
- });
2197
- CopilotChatInput2.AudioRecorder = CopilotChatAudioRecorder;
2198
- })(CopilotChatInput || (CopilotChatInput = {}));
2199
- CopilotChatInput.TextArea.displayName = "CopilotChatInput.TextArea";
2200
- CopilotChatInput.SendButton.displayName = "CopilotChatInput.SendButton";
2201
- CopilotChatInput.ToolbarButton.displayName = "CopilotChatInput.ToolbarButton";
2202
- CopilotChatInput.StartTranscribeButton.displayName = "CopilotChatInput.StartTranscribeButton";
2203
- CopilotChatInput.CancelTranscribeButton.displayName = "CopilotChatInput.CancelTranscribeButton";
2204
- CopilotChatInput.FinishTranscribeButton.displayName = "CopilotChatInput.FinishTranscribeButton";
2205
- CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
2206
- var CopilotChatInput_default = CopilotChatInput;
2207
-
2208
- // src/components/chat/CopilotChatSuggestionView.tsx
2209
- var import_react20 = __toESM(require("react"));
2210
-
2211
- // src/components/chat/CopilotChatSuggestionPill.tsx
2212
- var import_react19 = __toESM(require("react"));
2213
- var import_lucide_react5 = require("lucide-react");
2214
- var import_jsx_runtime16 = require("react/jsx-runtime");
2215
- var baseClasses = "group inline-flex h-7 sm:h-8 items-center gap-1 sm:gap-1.5 rounded-full border border-border/60 bg-background px-2.5 sm:px-3 text-[11px] sm:text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
2216
- var labelClasses = "whitespace-nowrap font-medium leading-none";
2217
- var CopilotChatSuggestionPill = import_react19.default.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
2218
- const showIcon = !isLoading && icon;
2219
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
2220
- "button",
2221
- {
2222
- ref,
2223
- "data-slot": "suggestion-pill",
2224
- className: cn(baseClasses, className),
2225
- type: type ?? "button",
2226
- "aria-busy": isLoading || void 0,
2227
- disabled: isLoading || props.disabled,
2228
- ...props,
2229
- children: [
2230
- isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_lucide_react5.Loader2, { className: "h-3.5 sm:h-4 w-3.5 sm:w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: icon }),
2231
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: labelClasses, children })
2232
- ]
2233
- }
2234
- );
2235
- });
2236
- CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
2237
- var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
2238
-
2239
- // src/components/chat/CopilotChatSuggestionView.tsx
2240
- var import_jsx_runtime17 = require("react/jsx-runtime");
2241
- var DefaultContainer = import_react20.default.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
2242
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2243
- "div",
2244
- {
2245
- ref,
2246
- className: cn(
2247
- "flex flex-wrap items-center gap-1.5 sm:gap-2 pl-0 pr-4 sm:px-0 pointer-events-none",
2248
- className
2249
- ),
2250
- ...props
2251
- }
2252
- );
2253
- });
2254
- var CopilotChatSuggestionView = import_react20.default.forwardRef(function CopilotChatSuggestionView2({
2255
- suggestions,
2256
- onSelectSuggestion,
2257
- loadingIndexes,
2258
- container,
2259
- suggestion: suggestionSlot,
2260
- className,
2261
- children,
2262
- ...restProps
2263
- }, ref) {
2264
- const loadingSet = import_react20.default.useMemo(() => {
2265
- if (!loadingIndexes || loadingIndexes.length === 0) {
2266
- return /* @__PURE__ */ new Set();
2267
- }
2268
- return new Set(loadingIndexes);
2269
- }, [loadingIndexes]);
2270
- const ContainerElement = renderSlot(container, DefaultContainer, {
2271
- ref,
2272
- className,
2273
- ...restProps
2274
- });
2275
- const suggestionElements = suggestions.map((suggestion, index) => {
2276
- const isLoading = loadingSet.has(index) || suggestion.isLoading === true;
2277
- const pill = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
2278
- children: suggestion.title,
2279
- isLoading,
2280
- type: "button",
2281
- onClick: () => onSelectSuggestion?.(suggestion, index)
2282
- });
2283
- return import_react20.default.cloneElement(pill, {
2284
- key: `${suggestion.title}-${index}`
2285
- });
2286
- });
2287
- const boundContainer = import_react20.default.cloneElement(
2288
- ContainerElement,
2289
- void 0,
2290
- suggestionElements
2291
- );
2292
- if (typeof children === "function") {
2293
- const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
2294
- children: suggestions[0]?.title ?? "",
2295
- isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
2296
- type: "button"
2297
- });
2298
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children: children({
2299
- container: boundContainer,
2300
- suggestion: sampleSuggestion,
2301
- suggestions,
2302
- onSelectSuggestion,
2303
- loadingIndexes,
2304
- className,
2305
- ...restProps
2306
- }) });
2307
- }
2308
- if (children) {
2309
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
2310
- boundContainer,
2311
- children
2312
- ] });
2313
- }
2314
- return boundContainer;
2315
- });
2316
- CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
2317
- var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
2318
-
2319
- // src/components/chat/CopilotChatView.tsx
2320
- var import_tailwind_merge7 = require("tailwind-merge");
2321
- var import_use_stick_to_bottom = require("use-stick-to-bottom");
2322
- var import_lucide_react6 = require("lucide-react");
2323
-
2324
- // src/hooks/use-keyboard-height.tsx
2325
- var import_react21 = require("react");
2326
- function useKeyboardHeight() {
2327
- const [keyboardState, setKeyboardState] = (0, import_react21.useState)({
2328
- isKeyboardOpen: false,
2329
- keyboardHeight: 0,
2330
- availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
2331
- viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
2332
- });
2333
- (0, import_react21.useEffect)(() => {
2334
- if (typeof window === "undefined") {
2335
- return;
2336
- }
2337
- const visualViewport = window.visualViewport;
2338
- if (!visualViewport) {
2339
- return;
2340
- }
2341
- const updateKeyboardState = () => {
2342
- const layoutHeight = window.innerHeight;
2343
- const visualHeight = visualViewport.height;
2344
- const keyboardHeight = Math.max(0, layoutHeight - visualHeight);
2345
- const isKeyboardOpen = keyboardHeight > 150;
2346
- setKeyboardState({
2347
- isKeyboardOpen,
2348
- keyboardHeight,
2349
- availableHeight: visualHeight,
2350
- viewportHeight: layoutHeight
2351
- });
2352
- };
2353
- updateKeyboardState();
2354
- visualViewport.addEventListener("resize", updateKeyboardState);
2355
- visualViewport.addEventListener("scroll", updateKeyboardState);
2356
- return () => {
2357
- visualViewport.removeEventListener("resize", updateKeyboardState);
2358
- visualViewport.removeEventListener("scroll", updateKeyboardState);
2359
- };
2360
- }, []);
2361
- return keyboardState;
2362
- }
2363
-
2364
- // src/components/chat/CopilotChatView.tsx
2365
- var import_jsx_runtime18 = require("react/jsx-runtime");
2366
- function CopilotChatView({
2367
- messageView,
2368
- input,
2369
- scrollView,
2370
- scrollToBottomButton,
2371
- feather,
2372
- inputContainer,
2373
- disclaimer,
2374
- suggestionView,
2375
- messages = [],
2376
- autoScroll = true,
2377
- inputProps,
2378
- isRunning = false,
2379
- suggestions,
2380
- suggestionLoadingIndexes,
2381
- onSelectSuggestion,
2382
- children,
2383
- className,
2384
- ...props
2385
- }) {
2386
- const inputContainerRef = (0, import_react22.useRef)(null);
2387
- const [inputContainerHeight, setInputContainerHeight] = (0, import_react22.useState)(0);
2388
- const [isResizing, setIsResizing] = (0, import_react22.useState)(false);
2389
- const resizeTimeoutRef = (0, import_react22.useRef)(null);
2390
- const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
2391
- (0, import_react22.useEffect)(() => {
2392
- const element = inputContainerRef.current;
2393
- if (!element) return;
2394
- const resizeObserver = new ResizeObserver((entries) => {
2395
- for (const entry of entries) {
2396
- const newHeight = entry.contentRect.height;
2397
- setInputContainerHeight((prevHeight) => {
2398
- if (newHeight !== prevHeight) {
2399
- setIsResizing(true);
2400
- if (resizeTimeoutRef.current) {
2401
- clearTimeout(resizeTimeoutRef.current);
2402
- }
2403
- resizeTimeoutRef.current = setTimeout(() => {
2404
- setIsResizing(false);
2405
- }, 250);
2406
- return newHeight;
2407
- }
2408
- return prevHeight;
2409
- });
2410
- }
2411
- });
2412
- resizeObserver.observe(element);
2413
- setInputContainerHeight(element.offsetHeight);
2414
- return () => {
2415
- resizeObserver.disconnect();
2416
- if (resizeTimeoutRef.current) {
2417
- clearTimeout(resizeTimeoutRef.current);
2418
- }
2419
- };
2420
- }, []);
2421
- const BoundMessageView = renderSlot(messageView, CopilotChatMessageView_default, {
2422
- messages,
2423
- isRunning
2424
- });
2425
- const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
2426
- const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
2427
- const BoundSuggestionView = hasSuggestions ? renderSlot(
2428
- suggestionView,
2429
- CopilotChatSuggestionView_default,
2430
- {
2431
- suggestions,
2432
- loadingIndexes: suggestionLoadingIndexes,
2433
- onSelectSuggestion,
2434
- className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
2435
- }
2436
- ) : null;
2437
- const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
2438
- const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
2439
- autoScroll,
2440
- scrollToBottomButton,
2441
- inputContainerHeight,
2442
- isResizing,
2443
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "max-w-3xl mx-auto", children: [
2444
- BoundMessageView,
2445
- hasSuggestions ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "pl-0 pr-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
2446
- ] }) })
2447
- });
2448
- const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
2449
- const BoundDisclaimer = renderSlot(disclaimer, CopilotChatView.Disclaimer, {});
2450
- const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
2451
- ref: inputContainerRef,
2452
- keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
2453
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
2454
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6 pointer-events-auto", children: BoundInput }),
2455
- BoundDisclaimer
2456
- ] })
2457
- });
2458
- if (children) {
2459
- return children({
2460
- messageView: BoundMessageView,
2461
- input: BoundInput,
2462
- scrollView: BoundScrollView,
2463
- scrollToBottomButton: BoundScrollToBottomButton,
2464
- feather: BoundFeather,
2465
- inputContainer: BoundInputContainer,
2466
- disclaimer: BoundDisclaimer,
2467
- suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, {})
2468
- });
2469
- }
2470
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: (0, import_tailwind_merge7.twMerge)("relative h-full", className), ...props, children: [
2471
- BoundScrollView,
2472
- BoundFeather,
2473
- BoundInputContainer
2474
- ] });
2475
- }
2476
- ((CopilotChatView2) => {
2477
- const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
2478
- const { isAtBottom, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottomContext)();
2479
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
2480
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_use_stick_to_bottom.StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) }),
2481
- !isAtBottom && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2482
- "div",
2483
- {
2484
- className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
2485
- style: {
2486
- bottom: `${inputContainerHeight + 16}px`
2487
- },
2488
- children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
2489
- onClick: () => scrollToBottom()
2490
- })
2491
- }
2492
- )
2493
- ] });
2494
- };
2495
- CopilotChatView2.ScrollView = ({
2496
- children,
2497
- autoScroll = true,
2498
- scrollToBottomButton,
2499
- inputContainerHeight = 0,
2500
- isResizing = false,
2501
- className,
2502
- ...props
2503
- }) => {
2504
- const [hasMounted, setHasMounted] = (0, import_react22.useState)(false);
2505
- const { scrollRef, contentRef, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottom)();
2506
- const [showScrollButton, setShowScrollButton] = (0, import_react22.useState)(false);
2507
- (0, import_react22.useEffect)(() => {
2508
- setHasMounted(true);
2509
- }, []);
2510
- (0, import_react22.useEffect)(() => {
2511
- if (autoScroll) return;
2512
- const scrollElement = scrollRef.current;
2513
- if (!scrollElement) return;
2514
- const checkScroll = () => {
2515
- const atBottom = scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight < 10;
2516
- setShowScrollButton(!atBottom);
2517
- };
2518
- checkScroll();
2519
- scrollElement.addEventListener("scroll", checkScroll);
2520
- const resizeObserver = new ResizeObserver(checkScroll);
2521
- resizeObserver.observe(scrollElement);
2522
- return () => {
2523
- scrollElement.removeEventListener("scroll", checkScroll);
2524
- resizeObserver.disconnect();
2525
- };
2526
- }, [scrollRef, autoScroll]);
2527
- if (!hasMounted) {
2528
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) });
2529
- }
2530
- if (!autoScroll) {
2531
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
2532
- "div",
2533
- {
2534
- ref: scrollRef,
2535
- className: cn(
2536
- "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden relative",
2537
- className
2538
- ),
2539
- ...props,
2540
- children: [
2541
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }),
2542
- showScrollButton && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2543
- "div",
2544
- {
2545
- className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
2546
- style: {
2547
- bottom: `${inputContainerHeight + 16}px`
2548
- },
2549
- children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
2550
- onClick: () => scrollToBottom()
2551
- })
2552
- }
2553
- )
2554
- ]
2555
- }
2556
- );
2557
- }
2558
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2559
- import_use_stick_to_bottom.StickToBottom,
2560
- {
2561
- className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
2562
- resize: "smooth",
2563
- initial: "smooth",
2564
- ...props,
2565
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2566
- ScrollContent,
2567
- {
2568
- scrollToBottomButton,
2569
- inputContainerHeight,
2570
- isResizing,
2571
- children
2572
- }
2573
- )
2574
- }
2575
- );
2576
- };
2577
- CopilotChatView2.ScrollToBottomButton = ({
2578
- className,
2579
- ...props
2580
- }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2581
- Button,
2582
- {
2583
- variant: "outline",
2584
- size: "sm",
2585
- className: (0, import_tailwind_merge7.twMerge)(
2586
- "rounded-full w-10 h-10 p-0 pointer-events-auto",
2587
- "bg-white dark:bg-gray-900",
2588
- "shadow-lg border border-gray-200 dark:border-gray-700",
2589
- "hover:bg-gray-50 dark:hover:bg-gray-800",
2590
- "flex items-center justify-center cursor-pointer",
2591
- className
2592
- ),
2593
- ...props,
2594
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react6.ChevronDown, { className: "w-4 h-4 text-gray-600 dark:text-white" })
2595
- }
2596
- );
2597
- CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2598
- "div",
2599
- {
2600
- className: cn(
2601
- "absolute bottom-0 left-0 right-4 h-24 pointer-events-none z-10 bg-gradient-to-t",
2602
- "from-white via-white to-transparent",
2603
- "dark:from-[rgb(33,33,33)] dark:via-[rgb(33,33,33)]",
2604
- className
2605
- ),
2606
- style,
2607
- ...props
2608
- }
2609
- );
2610
- CopilotChatView2.InputContainer = import_react22.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2611
- "div",
2612
- {
2613
- ref,
2614
- className: cn("absolute bottom-0 left-0 right-0 z-20 pointer-events-none", className),
2615
- style: {
2616
- // Adjust position when keyboard is open to keep input visible
2617
- transform: keyboardHeight > 0 ? `translateY(-${keyboardHeight}px)` : void 0,
2618
- transition: "transform 0.2s ease-out"
2619
- },
2620
- ...props,
2621
- children
2622
- }
2623
- ));
2624
- CopilotChatView2.InputContainer.displayName = "CopilotChatView.InputContainer";
2625
- CopilotChatView2.Disclaimer = ({ className, ...props }) => {
2626
- const config = useCopilotChatConfiguration();
2627
- const labels = config?.labels ?? CopilotChatDefaultLabels;
2628
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2629
- "div",
2630
- {
2631
- className: cn("text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto", className),
2632
- ...props,
2633
- children: labels.chatDisclaimerText
2634
- }
2635
- );
2636
- };
2637
- })(CopilotChatView || (CopilotChatView = {}));
2638
- var CopilotChatView_default = CopilotChatView;
2639
-
2640
- // src/components/chat/CopilotChatToggleButton.tsx
2641
- var import_react23 = __toESM(require("react"));
2642
- var import_lucide_react7 = require("lucide-react");
2643
- var import_jsx_runtime19 = require("react/jsx-runtime");
2644
- var DefaultOpenIcon = ({
2645
- className,
2646
- ...props
2647
- }) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react7.MessageCircle, { className: cn("h-6 w-6", className), strokeWidth: 1.75, fill: "currentColor", ...props });
2648
- var DefaultCloseIcon = ({
2649
- className,
2650
- ...props
2651
- }) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react7.X, { className: cn("h-6 w-6", className), strokeWidth: 1.75, ...props });
2652
- DefaultOpenIcon.displayName = "CopilotChatToggleButton.OpenIcon";
2653
- DefaultCloseIcon.displayName = "CopilotChatToggleButton.CloseIcon";
2654
- var ICON_TRANSITION_STYLE = Object.freeze({
2655
- transition: "opacity 120ms ease-out, transform 260ms cubic-bezier(0.22, 1, 0.36, 1)"
2656
- });
2657
- var ICON_WRAPPER_BASE = "pointer-events-none absolute inset-0 flex items-center justify-center will-change-transform";
2658
- var BUTTON_BASE_CLASSES = cn(
2659
- "fixed bottom-6 right-6 z-[1100] flex h-14 w-14 items-center justify-center",
2660
- "rounded-full border border-primary bg-primary text-primary-foreground",
2661
- "shadow-sm transition-all duration-200 ease-out",
2662
- "hover:scale-[1.04] hover:shadow-md",
2663
- "cursor-pointer",
2664
- "active:scale-[0.96]",
2665
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
2666
- "disabled:pointer-events-none disabled:opacity-60"
2667
- );
2668
- var CopilotChatToggleButton = import_react23.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
2669
- const { onClick, type, disabled, ...restProps } = buttonProps;
2670
- const configuration = useCopilotChatConfiguration();
2671
- const labels = configuration?.labels ?? CopilotChatDefaultLabels;
2672
- const [fallbackOpen, setFallbackOpen] = (0, import_react23.useState)(false);
2673
- const isOpen = configuration?.isModalOpen ?? fallbackOpen;
2674
- const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
2675
- const handleClick = (event) => {
2676
- if (disabled) {
2677
- return;
2678
- }
2679
- if (onClick) {
2680
- onClick(event);
2681
- }
2682
- if (event.defaultPrevented) {
2683
- return;
2684
- }
2685
- const nextOpen = !isOpen;
2686
- setModalOpen(nextOpen);
2687
- };
2688
- const renderedOpenIcon = renderSlot(
2689
- openIcon,
2690
- DefaultOpenIcon,
2691
- {
2692
- className: "h-6 w-6",
2693
- "aria-hidden": true,
2694
- focusable: false
2695
- }
2696
- );
2697
- const renderedCloseIcon = renderSlot(
2698
- closeIcon,
2699
- DefaultCloseIcon,
2700
- {
2701
- className: "h-6 w-6",
2702
- "aria-hidden": true,
2703
- focusable: false
2704
- }
2705
- );
2706
- const openIconElement = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2707
- "span",
2708
- {
2709
- "aria-hidden": "true",
2710
- "data-slot": "chat-toggle-button-open-icon",
2711
- className: ICON_WRAPPER_BASE,
2712
- style: {
2713
- ...ICON_TRANSITION_STYLE,
2714
- opacity: isOpen ? 0 : 1,
2715
- transform: `scale(${isOpen ? 0.75 : 1}) rotate(${isOpen ? 90 : 0}deg)`
2716
- },
2717
- children: renderedOpenIcon
2718
- }
2719
- );
2720
- const closeIconElement = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2721
- "span",
2722
- {
2723
- "aria-hidden": "true",
2724
- "data-slot": "chat-toggle-button-close-icon",
2725
- className: ICON_WRAPPER_BASE,
2726
- style: {
2727
- ...ICON_TRANSITION_STYLE,
2728
- opacity: isOpen ? 1 : 0,
2729
- transform: `scale(${isOpen ? 1 : 0.75}) rotate(${isOpen ? 0 : -90}deg)`
2730
- },
2731
- children: renderedCloseIcon
2732
- }
2733
- );
2734
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2735
- "button",
2736
- {
2737
- ref,
2738
- type: type ?? "button",
2739
- "data-slot": "chat-toggle-button",
2740
- "data-state": isOpen ? "open" : "closed",
2741
- className: cn(BUTTON_BASE_CLASSES, className),
2742
- "aria-label": isOpen ? labels.chatToggleCloseLabel : labels.chatToggleOpenLabel,
2743
- "aria-pressed": isOpen,
2744
- disabled,
2745
- onClick: handleClick,
2746
- ...restProps,
2747
- children: [
2748
- openIconElement,
2749
- closeIconElement
2750
- ]
2751
- }
2752
- );
2753
- });
2754
- CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
2755
- var CopilotChatToggleButton_default = CopilotChatToggleButton;
2756
-
2757
- // src/components/chat/CopilotModalHeader.tsx
2758
- var import_react24 = require("react");
2759
- var import_lucide_react8 = require("lucide-react");
2760
- var import_jsx_runtime20 = require("react/jsx-runtime");
2761
- function CopilotModalHeader({
2762
- title,
2763
- titleContent,
2764
- closeButton,
2765
- children,
2766
- className,
2767
- ...rest
2768
- }) {
2769
- const configuration = useCopilotChatConfiguration();
2770
- const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
2771
- const resolvedTitle = title ?? fallbackTitle;
2772
- const handleClose = (0, import_react24.useCallback)(() => {
2773
- configuration?.setModalOpen(false);
2774
- }, [configuration]);
2775
- const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
2776
- children: resolvedTitle
2777
- });
2778
- const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, {
2779
- onClick: handleClose
2780
- });
2781
- if (children) {
2782
- return children({
2783
- titleContent: BoundTitle,
2784
- closeButton: BoundCloseButton,
2785
- title: resolvedTitle,
2786
- ...rest
2787
- });
2788
- }
2789
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2790
- "header",
2791
- {
2792
- "data-slot": "copilot-modal-header",
2793
- className: cn(
2794
- "flex items-center justify-between border-b border-border px-4 py-4",
2795
- "bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",
2796
- className
2797
- ),
2798
- ...rest,
2799
- children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex w-full items-center gap-2", children: [
2800
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex-1", "aria-hidden": "true" }),
2801
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
2802
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
2803
- ] })
2804
- }
2805
- );
2806
- }
2807
- CopilotModalHeader.displayName = "CopilotModalHeader";
2808
- ((CopilotModalHeader2) => {
2809
- CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2810
- "div",
2811
- {
2812
- className: cn(
2813
- "w-full text-base font-medium leading-none tracking-tight text-foreground",
2814
- className
2815
- ),
2816
- ...props,
2817
- children
2818
- }
2819
- );
2820
- CopilotModalHeader2.CloseButton = ({
2821
- className,
2822
- ...props
2823
- }) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2824
- "button",
2825
- {
2826
- type: "button",
2827
- className: cn(
2828
- "inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition cursor-pointer",
2829
- "hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
2830
- className
2831
- ),
2832
- "aria-label": "Close",
2833
- ...props,
2834
- children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react8.X, { className: "h-4 w-4", "aria-hidden": "true" })
2835
- }
2836
- );
2837
- })(CopilotModalHeader || (CopilotModalHeader = {}));
2838
- CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
2839
- CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
2840
-
2841
- // src/components/chat/CopilotSidebarView.tsx
2842
- var import_jsx_runtime21 = require("react/jsx-runtime");
2843
- var DEFAULT_SIDEBAR_WIDTH = 480;
2844
- var SIDEBAR_TRANSITION_MS = 260;
2845
- function CopilotSidebarView({ header, width, ...props }) {
2846
- const configuration = useCopilotChatConfiguration();
2847
- const isSidebarOpen = configuration?.isModalOpen ?? false;
2848
- const sidebarRef = (0, import_react25.useRef)(null);
2849
- const [sidebarWidth, setSidebarWidth] = (0, import_react25.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
2850
- const widthToCss = (w) => {
2851
- return typeof w === "number" ? `${w}px` : w;
2852
- };
2853
- const widthToMargin = (w) => {
2854
- if (typeof w === "number") {
2855
- return `${w}px`;
2856
- }
2857
- return w;
2858
- };
2859
- (0, import_react25.useEffect)(() => {
2860
- if (width !== void 0) {
2861
- return;
2862
- }
2863
- if (typeof window === "undefined") {
2864
- return;
2865
- }
2866
- const element = sidebarRef.current;
2867
- if (!element) {
2868
- return;
2869
- }
2870
- const updateWidth = () => {
2871
- const rect = element.getBoundingClientRect();
2872
- if (rect.width > 0) {
2873
- setSidebarWidth(rect.width);
2874
- }
2875
- };
2876
- updateWidth();
2877
- if (typeof ResizeObserver !== "undefined") {
2878
- const observer = new ResizeObserver(() => updateWidth());
2879
- observer.observe(element);
2880
- return () => observer.disconnect();
2881
- }
2882
- window.addEventListener("resize", updateWidth);
2883
- return () => window.removeEventListener("resize", updateWidth);
2884
- }, [width]);
2885
- const headerElement = renderSlot(header, CopilotModalHeader, {});
2886
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
2887
- isSidebarOpen && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2888
- "style",
2889
- {
2890
- dangerouslySetInnerHTML: {
2891
- __html: `
2892
- @media (min-width: 768px) {
2893
- body {
2894
- margin-inline-end: ${widthToMargin(sidebarWidth)};
2895
- transition: margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease;
2896
- }
2897
- }`
2898
- }
2899
- }
2900
- ),
2901
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotChatToggleButton_default, {}),
2902
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2903
- "aside",
2904
- {
2905
- ref: sidebarRef,
2906
- "data-copilot-sidebar": true,
2907
- className: cn(
2908
- "fixed right-0 top-0 z-[1200] flex",
2909
- // Height with dvh fallback and safe area support
2910
- "h-[100vh] h-[100dvh] max-h-screen",
2911
- // Responsive width: full on mobile, custom on desktop
2912
- "w-full",
2913
- "border-l border-border bg-background text-foreground shadow-xl",
2914
- "transition-transform duration-300 ease-out",
2915
- isSidebarOpen ? "translate-x-0" : "translate-x-full pointer-events-none"
2916
- ),
2917
- style: {
2918
- // Use CSS custom property for responsive width
2919
- ["--sidebar-width"]: widthToCss(sidebarWidth),
2920
- // Safe area insets for iOS
2921
- paddingTop: "env(safe-area-inset-top)",
2922
- paddingBottom: "env(safe-area-inset-bottom)"
2923
- },
2924
- "aria-hidden": !isSidebarOpen,
2925
- "aria-label": "Copilot chat sidebar",
2926
- role: "complementary",
2927
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
2928
- headerElement,
2929
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotChatView_default, { ...props }) })
2930
- ] })
2931
- }
2932
- )
2933
- ] });
2934
- }
2935
- CopilotSidebarView.displayName = "CopilotSidebarView";
2936
- var CopilotSidebarView_default = CopilotSidebarView;
2937
- // Annotate the CommonJS export names for ESM import in node:
2938
- 0 && (module.exports = {
2939
- CopilotSidebarView
2940
- });
2941
- //# sourceMappingURL=CopilotSidebarView.js.map