@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
package/dist/index.mjs CHANGED
@@ -1,118 +1,4295 @@
1
1
  "use client";
2
- import "./chunk-N5EP5OD5.mjs";
3
- import "./chunk-KPRUSQ3K.mjs";
4
- import "./chunk-US4KNAAV.mjs";
5
- import "./chunk-36HFWACS.mjs";
6
- import "./chunk-DVUQO72Z.mjs";
7
- import "./chunk-VBI6JXPC.mjs";
8
- import "./chunk-MWC5OV7Z.mjs";
9
- import "./chunk-6VUKDHOD.mjs";
10
- import {
11
- CopilotPopup
12
- } from "./chunk-IH5VFJ4L.mjs";
13
- import {
14
- CopilotPopupView
15
- } from "./chunk-VUHFLJWI.mjs";
16
- import {
17
- CopilotSidebar
18
- } from "./chunk-QFBM3ZT2.mjs";
19
- import {
20
- CopilotSidebarView
21
- } from "./chunk-3TA5QBSZ.mjs";
22
- import {
23
- CopilotModalHeader
24
- } from "./chunk-E56GYBP3.mjs";
25
- import {
26
- CopilotChatToggleButton,
27
- DefaultCloseIcon,
28
- DefaultOpenIcon
29
- } from "./chunk-R5OLAA3L.mjs";
30
- import {
31
- CopilotChat
32
- } from "./chunk-TKFOXPXF.mjs";
33
- import {
34
- CopilotChatView_default
35
- } from "./chunk-F43IPGPA.mjs";
36
- import {
37
- CopilotChatInput_default
38
- } from "./chunk-KCVDFZJX.mjs";
39
- import {
40
- AudioRecorderError,
41
- CopilotChatAudioRecorder
42
- } from "./chunk-4UDBR75C.mjs";
43
- import {
44
- CopilotChatMessageView_default
45
- } from "./chunk-W5DUKRCI.mjs";
46
- import {
47
- CopilotChatUserMessage_default
48
- } from "./chunk-BT6C5OPU.mjs";
49
- import {
50
- CopilotChatAssistantMessage_default
51
- } from "./chunk-CZ3GI3IF.mjs";
52
- import {
53
- CopilotChatSuggestionView_default
54
- } from "./chunk-RGD2L3Z4.mjs";
55
- import {
56
- CopilotChatSuggestionPill_default
57
- } from "./chunk-NNPKBGD6.mjs";
58
- import {
59
- CopilotChatToolCallsView_default
60
- } from "./chunk-YVPPF62K.mjs";
61
- import "./chunk-TAUOEJH2.mjs";
62
- import "./chunk-JWOIINVV.mjs";
63
- import "./chunk-VVAXSF3M.mjs";
64
- import "./chunk-FZR2XQKR.mjs";
65
- import {
66
- WildcardToolCallRender
67
- } from "./chunk-5JNWVLQI.mjs";
68
- import {
69
- defineToolCallRenderer
70
- } from "./chunk-46BZRXWT.mjs";
71
- import "./chunk-FIBK3DYE.mjs";
72
- import "./chunk-XO4IRKSC.mjs";
73
- import "./chunk-ETWJDCGE.mjs";
74
- import {
75
- useRenderToolCall
76
- } from "./chunk-5AAT4Z3C.mjs";
77
- import {
78
- useSuggestions
79
- } from "./chunk-Z3OIGQCZ.mjs";
80
- import {
81
- useAgentContext
82
- } from "./chunk-WNRDFAZ5.mjs";
83
- import {
84
- useAgent
85
- } from "./chunk-E4HD4M7R.mjs";
86
- import {
87
- useConfigureSuggestions
88
- } from "./chunk-ZIDT52TM.mjs";
89
- import {
90
- useHumanInTheLoop
91
- } from "./chunk-QJ6DZ645.mjs";
92
- import {
93
- useFrontendTool
94
- } from "./chunk-NASFZS3N.mjs";
95
- import {
96
- useRenderActivityMessage
97
- } from "./chunk-EJ5ZEAAN.mjs";
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 __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ // ../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js
29
+ var require_options = __commonJS({
30
+ "../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js"(exports) {
31
+ "use strict";
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;
34
+ exports.STR = 1;
35
+ exports.NUM = 2;
36
+ exports.ARR = 4;
37
+ exports.OBJ = 8;
38
+ exports.NULL = 16;
39
+ exports.BOOL = 32;
40
+ exports.NAN = 64;
41
+ exports.INFINITY = 128;
42
+ exports._INFINITY = 256;
43
+ exports.INF = exports.INFINITY | exports._INFINITY;
44
+ exports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;
45
+ exports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;
46
+ exports.COLLECTION = exports.ARR | exports.OBJ;
47
+ exports.ALL = exports.ATOM | exports.COLLECTION;
48
+ exports.Allow = { STR: exports.STR, NUM: exports.NUM, ARR: exports.ARR, OBJ: exports.OBJ, NULL: exports.NULL, BOOL: exports.BOOL, NAN: exports.NAN, INFINITY: exports.INFINITY, _INFINITY: exports._INFINITY, INF: exports.INF, SPECIAL: exports.SPECIAL, ATOM: exports.ATOM, COLLECTION: exports.COLLECTION, ALL: exports.ALL };
49
+ exports.default = exports.Allow;
50
+ }
51
+ });
52
+
53
+ // ../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/index.js
54
+ var require_dist = __commonJS({
55
+ "../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/index.js"(exports) {
56
+ "use strict";
57
+ var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
58
+ if (k2 === void 0) k2 = k;
59
+ var desc = Object.getOwnPropertyDescriptor(m, k);
60
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
61
+ desc = { enumerable: true, get: function() {
62
+ return m[k];
63
+ } };
64
+ }
65
+ Object.defineProperty(o, k2, desc);
66
+ } : function(o, m, k, k2) {
67
+ if (k2 === void 0) k2 = k;
68
+ o[k2] = m[k];
69
+ });
70
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
71
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
72
+ };
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ exports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;
75
+ var options_1 = require_options();
76
+ Object.defineProperty(exports, "Allow", { enumerable: true, get: function() {
77
+ return options_1.Allow;
78
+ } });
79
+ __exportStar(require_options(), exports);
80
+ var PartialJSON2 = class extends Error {
81
+ };
82
+ exports.PartialJSON = PartialJSON2;
83
+ var MalformedJSON = class extends Error {
84
+ };
85
+ exports.MalformedJSON = MalformedJSON;
86
+ function parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {
87
+ if (typeof jsonString !== "string") {
88
+ throw new TypeError(`expecting str, got ${typeof jsonString}`);
89
+ }
90
+ if (!jsonString.trim()) {
91
+ throw new Error(`${jsonString} is empty`);
92
+ }
93
+ return _parseJSON(jsonString.trim(), allowPartial);
94
+ }
95
+ exports.parseJSON = parseJSON;
96
+ var _parseJSON = (jsonString, allow) => {
97
+ const length = jsonString.length;
98
+ let index = 0;
99
+ const markPartialJSON = (msg) => {
100
+ throw new PartialJSON2(`${msg} at position ${index}`);
101
+ };
102
+ const throwMalformedError = (msg) => {
103
+ throw new MalformedJSON(`${msg} at position ${index}`);
104
+ };
105
+ const parseAny = () => {
106
+ skipBlank();
107
+ if (index >= length)
108
+ markPartialJSON("Unexpected end of input");
109
+ if (jsonString[index] === '"')
110
+ return parseStr();
111
+ if (jsonString[index] === "{")
112
+ return parseObj();
113
+ if (jsonString[index] === "[")
114
+ return parseArr();
115
+ if (jsonString.substring(index, index + 4) === "null" || options_1.Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index))) {
116
+ index += 4;
117
+ return null;
118
+ }
119
+ if (jsonString.substring(index, index + 4) === "true" || options_1.Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index))) {
120
+ index += 4;
121
+ return true;
122
+ }
123
+ if (jsonString.substring(index, index + 5) === "false" || options_1.Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index))) {
124
+ index += 5;
125
+ return false;
126
+ }
127
+ if (jsonString.substring(index, index + 8) === "Infinity" || options_1.Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index))) {
128
+ index += 8;
129
+ return Infinity;
130
+ }
131
+ if (jsonString.substring(index, index + 9) === "-Infinity" || options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && "-Infinity".startsWith(jsonString.substring(index))) {
132
+ index += 9;
133
+ return -Infinity;
134
+ }
135
+ if (jsonString.substring(index, index + 3) === "NaN" || options_1.Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index))) {
136
+ index += 3;
137
+ return NaN;
138
+ }
139
+ return parseNum();
140
+ };
141
+ const parseStr = () => {
142
+ const start = index;
143
+ let escape = false;
144
+ index++;
145
+ while (index < length && (jsonString[index] !== '"' || escape && jsonString[index - 1] === "\\")) {
146
+ escape = jsonString[index] === "\\" ? !escape : false;
147
+ index++;
148
+ }
149
+ if (jsonString.charAt(index) == '"') {
150
+ try {
151
+ return JSON.parse(jsonString.substring(start, ++index - Number(escape)));
152
+ } catch (e) {
153
+ throwMalformedError(String(e));
154
+ }
155
+ } else if (options_1.Allow.STR & allow) {
156
+ try {
157
+ return JSON.parse(jsonString.substring(start, index - Number(escape)) + '"');
158
+ } catch (e) {
159
+ return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("\\")) + '"');
160
+ }
161
+ }
162
+ markPartialJSON("Unterminated string literal");
163
+ };
164
+ const parseObj = () => {
165
+ index++;
166
+ skipBlank();
167
+ const obj = {};
168
+ try {
169
+ while (jsonString[index] !== "}") {
170
+ skipBlank();
171
+ if (index >= length && options_1.Allow.OBJ & allow)
172
+ return obj;
173
+ const key = parseStr();
174
+ skipBlank();
175
+ index++;
176
+ try {
177
+ const value = parseAny();
178
+ obj[key] = value;
179
+ } catch (e) {
180
+ if (options_1.Allow.OBJ & allow)
181
+ return obj;
182
+ else
183
+ throw e;
184
+ }
185
+ skipBlank();
186
+ if (jsonString[index] === ",")
187
+ index++;
188
+ }
189
+ } catch (e) {
190
+ if (options_1.Allow.OBJ & allow)
191
+ return obj;
192
+ else
193
+ markPartialJSON("Expected '}' at end of object");
194
+ }
195
+ index++;
196
+ return obj;
197
+ };
198
+ const parseArr = () => {
199
+ index++;
200
+ const arr = [];
201
+ try {
202
+ while (jsonString[index] !== "]") {
203
+ arr.push(parseAny());
204
+ skipBlank();
205
+ if (jsonString[index] === ",") {
206
+ index++;
207
+ }
208
+ }
209
+ } catch (e) {
210
+ if (options_1.Allow.ARR & allow) {
211
+ return arr;
212
+ }
213
+ markPartialJSON("Expected ']' at end of array");
214
+ }
215
+ index++;
216
+ return arr;
217
+ };
218
+ const parseNum = () => {
219
+ if (index === 0) {
220
+ if (jsonString === "-")
221
+ throwMalformedError("Not sure what '-' is");
222
+ try {
223
+ return JSON.parse(jsonString);
224
+ } catch (e) {
225
+ if (options_1.Allow.NUM & allow)
226
+ try {
227
+ return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf("e")));
228
+ } catch (e2) {
229
+ }
230
+ throwMalformedError(String(e));
231
+ }
232
+ }
233
+ const start = index;
234
+ if (jsonString[index] === "-")
235
+ index++;
236
+ while (jsonString[index] && ",]}".indexOf(jsonString[index]) === -1)
237
+ index++;
238
+ if (index == length && !(options_1.Allow.NUM & allow))
239
+ markPartialJSON("Unterminated number literal");
240
+ try {
241
+ return JSON.parse(jsonString.substring(start, index));
242
+ } catch (e) {
243
+ if (jsonString.substring(start, index) === "-")
244
+ markPartialJSON("Not sure what '-' is");
245
+ try {
246
+ return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("e")));
247
+ } catch (e2) {
248
+ throwMalformedError(String(e2));
249
+ }
250
+ }
251
+ };
252
+ const skipBlank = () => {
253
+ while (index < length && " \n\r ".includes(jsonString[index])) {
254
+ index++;
255
+ }
256
+ };
257
+ return parseAny();
258
+ };
259
+ var parse2 = parseJSON;
260
+ exports.parse = parse2;
261
+ }
262
+ });
263
+
264
+ // src/components/chat/CopilotChatInput.tsx
98
265
  import {
99
- useRenderCustomMessages
100
- } from "./chunk-CSHBUHRW.mjs";
101
- import "./chunk-YZUPVMHC.mjs";
266
+ useState as useState2,
267
+ useRef as useRef2,
268
+ useEffect as useEffect2,
269
+ useLayoutEffect,
270
+ forwardRef as forwardRef2,
271
+ useImperativeHandle as useImperativeHandle2,
272
+ useCallback,
273
+ useMemo as useMemo2
274
+ } from "react";
275
+ import { twMerge as twMerge3 } from "tailwind-merge";
276
+ import { Plus, Mic, ArrowUp, X, Check, Square } from "lucide-react";
277
+
278
+ // src/providers/CopilotChatConfigurationProvider.tsx
279
+ import { createContext, useContext, useMemo, useState } from "react";
280
+
281
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
282
+ var byteToHex = [];
283
+ for (let i = 0; i < 256; ++i) {
284
+ byteToHex.push((i + 256).toString(16).slice(1));
285
+ }
286
+ function unsafeStringify(arr, offset = 0) {
287
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
288
+ }
289
+
290
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
291
+ import { randomFillSync } from "crypto";
292
+ var rnds8Pool = new Uint8Array(256);
293
+ var poolPtr = rnds8Pool.length;
294
+ function rng() {
295
+ if (poolPtr > rnds8Pool.length - 16) {
296
+ randomFillSync(rnds8Pool);
297
+ poolPtr = 0;
298
+ }
299
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
300
+ }
301
+
302
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
303
+ import { randomUUID } from "crypto";
304
+ var native_default = { randomUUID };
305
+
306
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
307
+ function v4(options, buf, offset) {
308
+ if (native_default.randomUUID && !buf && !options) {
309
+ return native_default.randomUUID();
310
+ }
311
+ options = options || {};
312
+ const rnds = options.random ?? options.rng?.() ?? rng();
313
+ if (rnds.length < 16) {
314
+ throw new Error("Random bytes length must be >= 16");
315
+ }
316
+ rnds[6] = rnds[6] & 15 | 64;
317
+ rnds[8] = rnds[8] & 63 | 128;
318
+ if (buf) {
319
+ offset = offset || 0;
320
+ if (offset < 0 || offset + 16 > buf.length) {
321
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
322
+ }
323
+ for (let i = 0; i < 16; ++i) {
324
+ buf[offset + i] = rnds[i];
325
+ }
326
+ return buf;
327
+ }
328
+ return unsafeStringify(rnds);
329
+ }
330
+ var v4_default = v4;
331
+
332
+ // ../shared/src/utils.ts
333
+ var PartialJSON = __toESM(require_dist());
334
+ function randomUUID2() {
335
+ return v4_default();
336
+ }
337
+ function partialJSONParse(json) {
338
+ try {
339
+ return PartialJSON.parse(json);
340
+ } catch (error) {
341
+ return {};
342
+ }
343
+ }
344
+
345
+ // ../shared/src/constants.ts
346
+ var DEFAULT_AGENT_ID = "default";
347
+
348
+ // ../shared/src/finalize-events.ts
102
349
  import {
103
- CopilotChatConfigurationProvider,
104
- useCopilotChatConfiguration
105
- } from "./chunk-4XJK5IVQ.mjs";
350
+ EventType
351
+ } from "@ag-ui/client";
352
+
353
+ // src/providers/CopilotChatConfigurationProvider.tsx
354
+ import { jsx } from "react/jsx-runtime";
355
+ var CopilotChatDefaultLabels = {
356
+ chatInputPlaceholder: "Type a message...",
357
+ chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
358
+ chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
359
+ chatInputToolbarFinishTranscribeButtonLabel: "Finish",
360
+ chatInputToolbarAddButtonLabel: "Add photos or files",
361
+ chatInputToolbarToolsButtonLabel: "Tools",
362
+ assistantMessageToolbarCopyCodeLabel: "Copy",
363
+ assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
364
+ assistantMessageToolbarCopyMessageLabel: "Copy",
365
+ assistantMessageToolbarThumbsUpLabel: "Good response",
366
+ assistantMessageToolbarThumbsDownLabel: "Bad response",
367
+ assistantMessageToolbarReadAloudLabel: "Read aloud",
368
+ assistantMessageToolbarRegenerateLabel: "Regenerate",
369
+ userMessageToolbarCopyMessageLabel: "Copy",
370
+ userMessageToolbarEditMessageLabel: "Edit",
371
+ chatDisclaimerText: "AI can make mistakes. Please verify important information.",
372
+ chatToggleOpenLabel: "Open chat",
373
+ chatToggleCloseLabel: "Close chat",
374
+ modalHeaderTitle: "CopilotKit Chat"
375
+ };
376
+ var CopilotChatConfiguration = createContext(null);
377
+ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, isModalDefaultOpen }) => {
378
+ const parentConfig = useContext(CopilotChatConfiguration);
379
+ const mergedLabels = useMemo(
380
+ () => ({
381
+ ...CopilotChatDefaultLabels,
382
+ ...parentConfig?.labels ?? {},
383
+ ...labels ?? {}
384
+ }),
385
+ [labels, parentConfig?.labels]
386
+ );
387
+ const resolvedAgentId = agentId ?? parentConfig?.agentId ?? DEFAULT_AGENT_ID;
388
+ const resolvedThreadId = useMemo(() => {
389
+ if (threadId) {
390
+ return threadId;
391
+ }
392
+ if (parentConfig?.threadId) {
393
+ return parentConfig.threadId;
394
+ }
395
+ return randomUUID2();
396
+ }, [threadId, parentConfig?.threadId]);
397
+ const resolvedDefaultOpen = isModalDefaultOpen ?? parentConfig?.isModalDefaultOpen ?? true;
398
+ const [internalModalOpen, setInternalModalOpen] = useState(
399
+ parentConfig?.isModalOpen ?? resolvedDefaultOpen
400
+ );
401
+ const resolvedIsModalOpen = parentConfig?.isModalOpen ?? internalModalOpen;
402
+ const resolvedSetModalOpen = parentConfig?.setModalOpen ?? setInternalModalOpen;
403
+ const configurationValue = useMemo(
404
+ () => ({
405
+ labels: mergedLabels,
406
+ agentId: resolvedAgentId,
407
+ threadId: resolvedThreadId,
408
+ isModalOpen: resolvedIsModalOpen,
409
+ setModalOpen: resolvedSetModalOpen,
410
+ isModalDefaultOpen: resolvedDefaultOpen
411
+ }),
412
+ [
413
+ mergedLabels,
414
+ resolvedAgentId,
415
+ resolvedThreadId,
416
+ resolvedIsModalOpen,
417
+ resolvedSetModalOpen,
418
+ resolvedDefaultOpen
419
+ ]
420
+ );
421
+ return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, { value: configurationValue, children });
422
+ };
423
+ var useCopilotChatConfiguration = () => {
424
+ const configuration = useContext(CopilotChatConfiguration);
425
+ return configuration;
426
+ };
427
+
428
+ // src/components/ui/button.tsx
429
+ import { Slot } from "@radix-ui/react-slot";
430
+ import { cva } from "class-variance-authority";
431
+
432
+ // src/lib/utils.ts
433
+ import { clsx } from "clsx";
434
+ import { twMerge } from "tailwind-merge";
435
+ function cn(...inputs) {
436
+ return twMerge(clsx(inputs));
437
+ }
438
+
439
+ // src/components/ui/button.tsx
440
+ import { jsx as jsx2 } from "react/jsx-runtime";
441
+ var buttonVariants = cva(
442
+ "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",
443
+ {
444
+ variants: {
445
+ variant: {
446
+ default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
447
+ 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",
448
+ 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",
449
+ secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
450
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50 cursor-pointer",
451
+ link: "text-primary underline-offset-4 hover:underline",
452
+ assistantMessageToolbarButton: [
453
+ "cursor-pointer",
454
+ // Background and text
455
+ "p-0 text-[rgb(93,93,93)] hover:bg-[#E8E8E8]",
456
+ // Dark mode - lighter gray for better contrast
457
+ "dark:text-[rgb(243,243,243)] dark:hover:bg-[#303030]",
458
+ // Shape and sizing
459
+ "h-8 w-8",
460
+ // Interactions
461
+ "transition-colors",
462
+ // Hover states
463
+ "hover:text-[rgb(93,93,93)]",
464
+ "dark:hover:text-[rgb(243,243,243)]"
465
+ ],
466
+ chatInputToolbarPrimary: [
467
+ "cursor-pointer",
468
+ // Background and text
469
+ "bg-black text-white",
470
+ // Dark mode
471
+ "dark:bg-white dark:text-black dark:focus-visible:outline-white",
472
+ // Shape and sizing
473
+ "rounded-full",
474
+ // Interactions
475
+ "transition-colors",
476
+ // Focus states
477
+ "focus:outline-none",
478
+ // Hover states
479
+ "hover:opacity-70 disabled:hover:opacity-100",
480
+ // Disabled states
481
+ "disabled:cursor-not-allowed disabled:bg-[#00000014] disabled:text-[rgb(13,13,13)]",
482
+ "dark:disabled:bg-[#454545] dark:disabled:text-white "
483
+ ],
484
+ chatInputToolbarSecondary: [
485
+ "cursor-pointer",
486
+ // Background and text
487
+ "bg-transparent text-[#444444]",
488
+ // Dark mode
489
+ "dark:text-white dark:border-[#404040]",
490
+ // Shape and sizing
491
+ "rounded-full",
492
+ // Interactions
493
+ "transition-colors",
494
+ // Focus states
495
+ "focus:outline-none",
496
+ // Hover states
497
+ "hover:bg-[#f8f8f8] hover:text-[#333333]",
498
+ "dark:hover:bg-[#404040] dark:hover:text-[#FFFFFF]",
499
+ // Disabled states
500
+ "disabled:cursor-not-allowed disabled:opacity-50",
501
+ "disabled:hover:bg-transparent disabled:hover:text-[#444444]",
502
+ "dark:disabled:hover:bg-transparent dark:disabled:hover:text-[#CCCCCC]"
503
+ ]
504
+ },
505
+ size: {
506
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
507
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
508
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
509
+ icon: "size-9",
510
+ chatInputToolbarIcon: [
511
+ // Shape and sizing
512
+ "h-9 w-9 rounded-full"
513
+ ],
514
+ chatInputToolbarIconLabel: [
515
+ // Shape and sizing
516
+ "h-9 px-3 rounded-full",
517
+ // Layout
518
+ "gap-2",
519
+ // Typography
520
+ "font-normal"
521
+ ]
522
+ }
523
+ },
524
+ defaultVariants: {
525
+ variant: "default",
526
+ size: "default"
527
+ }
528
+ }
529
+ );
530
+ function Button({
531
+ className,
532
+ variant,
533
+ size,
534
+ asChild = false,
535
+ ...props
536
+ }) {
537
+ const Comp = asChild ? Slot : "button";
538
+ return /* @__PURE__ */ jsx2(
539
+ Comp,
540
+ {
541
+ "data-slot": "button",
542
+ className: cn(buttonVariants({ variant, size, className })),
543
+ ...props
544
+ }
545
+ );
546
+ }
547
+
548
+ // src/components/ui/tooltip.tsx
549
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
550
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
551
+ function TooltipProvider({
552
+ delayDuration = 0,
553
+ ...props
554
+ }) {
555
+ return /* @__PURE__ */ jsx3(
556
+ TooltipPrimitive.Provider,
557
+ {
558
+ "data-slot": "tooltip-provider",
559
+ delayDuration,
560
+ ...props
561
+ }
562
+ );
563
+ }
564
+ function Tooltip({
565
+ ...props
566
+ }) {
567
+ return /* @__PURE__ */ jsx3(TooltipProvider, { children: /* @__PURE__ */ jsx3(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
568
+ }
569
+ function TooltipTrigger({
570
+ ...props
571
+ }) {
572
+ return /* @__PURE__ */ jsx3(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
573
+ }
574
+ function TooltipContent({
575
+ className,
576
+ sideOffset = 0,
577
+ children,
578
+ ...props
579
+ }) {
580
+ return /* @__PURE__ */ jsx3(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
581
+ TooltipPrimitive.Content,
582
+ {
583
+ "data-slot": "tooltip-content",
584
+ sideOffset,
585
+ className: cn(
586
+ "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",
587
+ className
588
+ ),
589
+ ...props,
590
+ children: [
591
+ children,
592
+ /* @__PURE__ */ jsx3(TooltipPrimitive.Arrow, { className: "bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
593
+ ]
594
+ }
595
+ ) });
596
+ }
597
+
598
+ // src/components/ui/dropdown-menu.tsx
599
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
600
+ import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
601
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
602
+ function DropdownMenu({
603
+ ...props
604
+ }) {
605
+ return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
606
+ }
607
+ function DropdownMenuTrigger({
608
+ ...props
609
+ }) {
610
+ return /* @__PURE__ */ jsx4(
611
+ DropdownMenuPrimitive.Trigger,
612
+ {
613
+ "data-slot": "dropdown-menu-trigger",
614
+ ...props
615
+ }
616
+ );
617
+ }
618
+ function DropdownMenuContent({
619
+ className,
620
+ sideOffset = 4,
621
+ ...props
622
+ }) {
623
+ return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx4(
624
+ DropdownMenuPrimitive.Content,
625
+ {
626
+ "data-slot": "dropdown-menu-content",
627
+ sideOffset,
628
+ className: cn(
629
+ "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",
630
+ className
631
+ ),
632
+ ...props
633
+ }
634
+ ) });
635
+ }
636
+ function DropdownMenuItem({
637
+ className,
638
+ inset,
639
+ variant = "default",
640
+ ...props
641
+ }) {
642
+ return /* @__PURE__ */ jsx4(
643
+ DropdownMenuPrimitive.Item,
644
+ {
645
+ "data-slot": "dropdown-menu-item",
646
+ "data-inset": inset,
647
+ "data-variant": variant,
648
+ className: cn(
649
+ "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",
650
+ className
651
+ ),
652
+ ...props
653
+ }
654
+ );
655
+ }
656
+ function DropdownMenuSeparator({
657
+ className,
658
+ ...props
659
+ }) {
660
+ return /* @__PURE__ */ jsx4(
661
+ DropdownMenuPrimitive.Separator,
662
+ {
663
+ "data-slot": "dropdown-menu-separator",
664
+ className: cn("bg-border -mx-1 my-1 h-px", className),
665
+ ...props
666
+ }
667
+ );
668
+ }
669
+ function DropdownMenuSub({
670
+ ...props
671
+ }) {
672
+ return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Sub, { "data-slot": "dropdown-menu-sub", ...props });
673
+ }
674
+ function DropdownMenuSubTrigger({
675
+ className,
676
+ inset,
677
+ children,
678
+ ...props
679
+ }) {
680
+ return /* @__PURE__ */ jsxs2(
681
+ DropdownMenuPrimitive.SubTrigger,
682
+ {
683
+ "data-slot": "dropdown-menu-sub-trigger",
684
+ "data-inset": inset,
685
+ className: cn(
686
+ "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",
687
+ className
688
+ ),
689
+ ...props,
690
+ children: [
691
+ children,
692
+ /* @__PURE__ */ jsx4(ChevronRightIcon, { className: "ml-auto size-4" })
693
+ ]
694
+ }
695
+ );
696
+ }
697
+ function DropdownMenuSubContent({
698
+ className,
699
+ ...props
700
+ }) {
701
+ return /* @__PURE__ */ jsx4(
702
+ DropdownMenuPrimitive.SubContent,
703
+ {
704
+ "data-slot": "dropdown-menu-sub-content",
705
+ className: cn(
706
+ "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",
707
+ className
708
+ ),
709
+ ...props
710
+ }
711
+ );
712
+ }
713
+
714
+ // src/components/chat/CopilotChatAudioRecorder.tsx
715
+ import { useRef, useEffect, useImperativeHandle, forwardRef } from "react";
716
+ import { twMerge as twMerge2 } from "tailwind-merge";
717
+ import { jsx as jsx5 } from "react/jsx-runtime";
718
+ var AudioRecorderError = class extends Error {
719
+ constructor(message) {
720
+ super(message);
721
+ this.name = "AudioRecorderError";
722
+ }
723
+ };
724
+ var CopilotChatAudioRecorder = forwardRef((props, ref) => {
725
+ const { className, ...divProps } = props;
726
+ const canvasRef = useRef(null);
727
+ const getLoudness = (n) => {
728
+ const elapsed = Date.now() / 1e3;
729
+ const samples = [];
730
+ for (let i = 0; i < n; i++) {
731
+ const position = i / n * 10 + elapsed * 0.5;
732
+ const wave1 = Math.sin(position * 2) * 0.3;
733
+ const wave2 = Math.sin(position * 5 + elapsed) * 0.2;
734
+ const wave3 = Math.sin(position * 0.5 + elapsed * 0.3) * 0.4;
735
+ const noise = (Math.random() - 0.5) * 0.1;
736
+ const envelope = Math.sin(elapsed * 0.7) * 0.5 + 0.5;
737
+ let amplitude = (wave1 + wave2 + wave3 + noise) * envelope;
738
+ amplitude = Math.max(0, Math.min(1, amplitude * 0.5 + 0.3));
739
+ samples.push(amplitude);
740
+ }
741
+ return samples;
742
+ };
743
+ useEffect(() => {
744
+ const canvas = canvasRef.current;
745
+ if (!canvas) return;
746
+ const ctx = canvas.getContext("2d");
747
+ if (!ctx) return;
748
+ let animationId;
749
+ const draw = () => {
750
+ const rect = canvas.getBoundingClientRect();
751
+ const dpr = window.devicePixelRatio || 1;
752
+ if (canvas.width !== rect.width * dpr || canvas.height !== rect.height * dpr) {
753
+ canvas.width = rect.width * dpr;
754
+ canvas.height = rect.height * dpr;
755
+ ctx.scale(dpr, dpr);
756
+ ctx.imageSmoothingEnabled = false;
757
+ }
758
+ const barWidth = 2;
759
+ const minHeight = 2;
760
+ const maxHeight = 20;
761
+ const gap = 2;
762
+ const numSamples = Math.ceil(rect.width / (barWidth + gap));
763
+ const loudnessData = getLoudness(numSamples);
764
+ ctx.clearRect(0, 0, rect.width, rect.height);
765
+ const computedStyle = getComputedStyle(canvas);
766
+ const currentForeground = computedStyle.color;
767
+ ctx.fillStyle = currentForeground;
768
+ const centerY = rect.height / 2;
769
+ for (let i = 0; i < loudnessData.length; i++) {
770
+ const sample = loudnessData[i] ?? 0;
771
+ const barHeight = Math.round(
772
+ sample * (maxHeight - minHeight) + minHeight
773
+ );
774
+ const x = Math.round(i * (barWidth + gap));
775
+ const y = Math.round(centerY - barHeight / 2);
776
+ ctx.fillRect(x, y, barWidth, barHeight);
777
+ }
778
+ animationId = requestAnimationFrame(draw);
779
+ };
780
+ draw();
781
+ return () => {
782
+ if (animationId) {
783
+ cancelAnimationFrame(animationId);
784
+ }
785
+ };
786
+ }, []);
787
+ useImperativeHandle(
788
+ ref,
789
+ () => ({
790
+ get state() {
791
+ return "idle";
792
+ },
793
+ start: async () => {
794
+ },
795
+ stop: () => new Promise((resolve) => {
796
+ const emptyBlob = new Blob([], { type: "audio/webm" });
797
+ resolve(emptyBlob);
798
+ }),
799
+ dispose: () => {
800
+ }
801
+ }),
802
+ []
803
+ );
804
+ return /* @__PURE__ */ jsx5("div", { className: twMerge2("h-[44px] w-full px-5", className), ...divProps, children: /* @__PURE__ */ jsx5(
805
+ "canvas",
806
+ {
807
+ ref: canvasRef,
808
+ className: "w-full h-full",
809
+ style: { imageRendering: "pixelated" }
810
+ }
811
+ ) });
812
+ });
813
+ CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
814
+
815
+ // src/lib/slots.tsx
816
+ import React2 from "react";
817
+ function renderSlot(slot, DefaultComponent, props) {
818
+ if (typeof slot === "string") {
819
+ return React2.createElement(DefaultComponent, {
820
+ ...props,
821
+ className: slot
822
+ });
823
+ }
824
+ if (typeof slot === "function") {
825
+ const Comp = slot;
826
+ return React2.createElement(Comp, props);
827
+ }
828
+ if (slot && typeof slot === "object" && !React2.isValidElement(slot)) {
829
+ return React2.createElement(DefaultComponent, {
830
+ ...props,
831
+ ...slot
832
+ });
833
+ }
834
+ return React2.createElement(DefaultComponent, props);
835
+ }
836
+
837
+ // src/components/chat/CopilotChatInput.tsx
838
+ import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
839
+ var SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
840
+ var SLASH_MENU_ITEM_HEIGHT_PX = 40;
841
+ function CopilotChatInput({
842
+ mode = "input",
843
+ onSubmitMessage,
844
+ onStop,
845
+ isRunning = false,
846
+ onStartTranscribe,
847
+ onCancelTranscribe,
848
+ onFinishTranscribe,
849
+ onAddFile,
850
+ onChange,
851
+ value,
852
+ toolsMenu,
853
+ autoFocus = true,
854
+ textArea,
855
+ sendButton,
856
+ startTranscribeButton,
857
+ cancelTranscribeButton,
858
+ finishTranscribeButton,
859
+ addMenuButton,
860
+ audioRecorder,
861
+ children,
862
+ className,
863
+ ...props
864
+ }) {
865
+ const isControlled = value !== void 0;
866
+ const [internalValue, setInternalValue] = useState2(() => value ?? "");
867
+ useEffect2(() => {
868
+ if (!isControlled && value !== void 0) {
869
+ setInternalValue(value);
870
+ }
871
+ }, [isControlled, value]);
872
+ const resolvedValue = isControlled ? value ?? "" : internalValue;
873
+ const [layout, setLayout] = useState2("compact");
874
+ const ignoreResizeRef = useRef2(false);
875
+ const resizeEvaluationRafRef = useRef2(null);
876
+ const isExpanded = mode === "input" && layout === "expanded";
877
+ const [commandQuery, setCommandQuery] = useState2(null);
878
+ const [slashHighlightIndex, setSlashHighlightIndex] = useState2(0);
879
+ const inputRef = useRef2(null);
880
+ const gridRef = useRef2(null);
881
+ const addButtonContainerRef = useRef2(null);
882
+ const actionsContainerRef = useRef2(null);
883
+ const audioRecorderRef = useRef2(null);
884
+ const slashMenuRef = useRef2(null);
885
+ const config = useCopilotChatConfiguration();
886
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
887
+ const previousModalStateRef = useRef2(void 0);
888
+ const measurementCanvasRef = useRef2(null);
889
+ const measurementsRef = useRef2({
890
+ singleLineHeight: 0,
891
+ maxHeight: 0,
892
+ paddingLeft: 0,
893
+ paddingRight: 0
894
+ });
895
+ const commandItems = useMemo2(() => {
896
+ const entries = [];
897
+ const seen = /* @__PURE__ */ new Set();
898
+ const pushItem = (item) => {
899
+ if (item === "-") {
900
+ return;
901
+ }
902
+ if (item.items && item.items.length > 0) {
903
+ for (const nested of item.items) {
904
+ pushItem(nested);
905
+ }
906
+ return;
907
+ }
908
+ if (!seen.has(item.label)) {
909
+ seen.add(item.label);
910
+ entries.push(item);
911
+ }
912
+ };
913
+ if (onAddFile) {
914
+ pushItem({
915
+ label: labels.chatInputToolbarAddButtonLabel,
916
+ action: onAddFile
917
+ });
918
+ }
919
+ if (toolsMenu && toolsMenu.length > 0) {
920
+ for (const item of toolsMenu) {
921
+ pushItem(item);
922
+ }
923
+ }
924
+ return entries;
925
+ }, [labels.chatInputToolbarAddButtonLabel, onAddFile, toolsMenu]);
926
+ const filteredCommands = useMemo2(() => {
927
+ if (commandQuery === null) {
928
+ return [];
929
+ }
930
+ if (commandItems.length === 0) {
931
+ return [];
932
+ }
933
+ const query = commandQuery.trim().toLowerCase();
934
+ if (query.length === 0) {
935
+ return commandItems;
936
+ }
937
+ const startsWith = [];
938
+ const contains = [];
939
+ for (const item of commandItems) {
940
+ const label = item.label.toLowerCase();
941
+ if (label.startsWith(query)) {
942
+ startsWith.push(item);
943
+ } else if (label.includes(query)) {
944
+ contains.push(item);
945
+ }
946
+ }
947
+ return [...startsWith, ...contains];
948
+ }, [commandItems, commandQuery]);
949
+ useEffect2(() => {
950
+ if (!autoFocus) {
951
+ previousModalStateRef.current = config?.isModalOpen;
952
+ return;
953
+ }
954
+ if (config?.isModalOpen && !previousModalStateRef.current) {
955
+ inputRef.current?.focus();
956
+ }
957
+ previousModalStateRef.current = config?.isModalOpen;
958
+ }, [config?.isModalOpen, autoFocus]);
959
+ useEffect2(() => {
960
+ if (commandItems.length === 0 && commandQuery !== null) {
961
+ setCommandQuery(null);
962
+ }
963
+ }, [commandItems.length, commandQuery]);
964
+ const previousCommandQueryRef = useRef2(null);
965
+ useEffect2(() => {
966
+ if (commandQuery !== null && commandQuery !== previousCommandQueryRef.current && filteredCommands.length > 0) {
967
+ setSlashHighlightIndex(0);
968
+ }
969
+ previousCommandQueryRef.current = commandQuery;
970
+ }, [commandQuery, filteredCommands.length]);
971
+ useEffect2(() => {
972
+ if (commandQuery === null) {
973
+ setSlashHighlightIndex(0);
974
+ return;
975
+ }
976
+ if (filteredCommands.length === 0) {
977
+ setSlashHighlightIndex(-1);
978
+ } else if (slashHighlightIndex < 0 || slashHighlightIndex >= filteredCommands.length) {
979
+ setSlashHighlightIndex(0);
980
+ }
981
+ }, [commandQuery, filteredCommands, slashHighlightIndex]);
982
+ useEffect2(() => {
983
+ const recorder = audioRecorderRef.current;
984
+ if (!recorder) {
985
+ return;
986
+ }
987
+ if (mode === "transcribe") {
988
+ recorder.start().catch(console.error);
989
+ } else {
990
+ if (recorder.state === "recording") {
991
+ recorder.stop().catch(console.error);
992
+ }
993
+ }
994
+ }, [mode]);
995
+ useEffect2(() => {
996
+ if (mode !== "input") {
997
+ setLayout("compact");
998
+ setCommandQuery(null);
999
+ }
1000
+ }, [mode]);
1001
+ const updateSlashState = useCallback(
1002
+ (value2) => {
1003
+ if (commandItems.length === 0) {
1004
+ setCommandQuery((prev) => prev === null ? prev : null);
1005
+ return;
1006
+ }
1007
+ if (value2.startsWith("/")) {
1008
+ const firstLine = value2.split(/\r?\n/, 1)[0] ?? "";
1009
+ const query = firstLine.slice(1);
1010
+ setCommandQuery((prev) => prev === query ? prev : query);
1011
+ } else {
1012
+ setCommandQuery((prev) => prev === null ? prev : null);
1013
+ }
1014
+ },
1015
+ [commandItems.length]
1016
+ );
1017
+ useEffect2(() => {
1018
+ updateSlashState(resolvedValue);
1019
+ }, [resolvedValue, updateSlashState]);
1020
+ const handleChange = (e) => {
1021
+ const nextValue = e.target.value;
1022
+ if (!isControlled) {
1023
+ setInternalValue(nextValue);
1024
+ }
1025
+ onChange?.(nextValue);
1026
+ updateSlashState(nextValue);
1027
+ };
1028
+ const clearInputValue = useCallback(() => {
1029
+ if (!isControlled) {
1030
+ setInternalValue("");
1031
+ }
1032
+ if (onChange) {
1033
+ onChange("");
1034
+ }
1035
+ }, [isControlled, onChange]);
1036
+ const runCommand = useCallback(
1037
+ (item) => {
1038
+ clearInputValue();
1039
+ item.action?.();
1040
+ setCommandQuery(null);
1041
+ setSlashHighlightIndex(0);
1042
+ requestAnimationFrame(() => {
1043
+ inputRef.current?.focus();
1044
+ });
1045
+ },
1046
+ [clearInputValue]
1047
+ );
1048
+ const handleKeyDown = (e) => {
1049
+ if (commandQuery !== null && mode === "input") {
1050
+ if (e.key === "ArrowDown") {
1051
+ if (filteredCommands.length > 0) {
1052
+ e.preventDefault();
1053
+ setSlashHighlightIndex((prev) => {
1054
+ if (filteredCommands.length === 0) {
1055
+ return prev;
1056
+ }
1057
+ const next = prev === -1 ? 0 : (prev + 1) % filteredCommands.length;
1058
+ return next;
1059
+ });
1060
+ }
1061
+ return;
1062
+ }
1063
+ if (e.key === "ArrowUp") {
1064
+ if (filteredCommands.length > 0) {
1065
+ e.preventDefault();
1066
+ setSlashHighlightIndex((prev) => {
1067
+ if (filteredCommands.length === 0) {
1068
+ return prev;
1069
+ }
1070
+ if (prev === -1) {
1071
+ return filteredCommands.length - 1;
1072
+ }
1073
+ return prev <= 0 ? filteredCommands.length - 1 : prev - 1;
1074
+ });
1075
+ }
1076
+ return;
1077
+ }
1078
+ if (e.key === "Enter") {
1079
+ const selected = slashHighlightIndex >= 0 ? filteredCommands[slashHighlightIndex] : void 0;
1080
+ if (selected) {
1081
+ e.preventDefault();
1082
+ runCommand(selected);
1083
+ return;
1084
+ }
1085
+ }
1086
+ if (e.key === "Escape") {
1087
+ e.preventDefault();
1088
+ setCommandQuery(null);
1089
+ return;
1090
+ }
1091
+ }
1092
+ if (e.key === "Enter" && !e.shiftKey) {
1093
+ e.preventDefault();
1094
+ if (isProcessing) {
1095
+ onStop?.();
1096
+ } else {
1097
+ send();
1098
+ }
1099
+ }
1100
+ };
1101
+ const send = () => {
1102
+ if (!onSubmitMessage) {
1103
+ return;
1104
+ }
1105
+ const trimmed = resolvedValue.trim();
1106
+ if (!trimmed) {
1107
+ return;
1108
+ }
1109
+ onSubmitMessage(trimmed);
1110
+ if (!isControlled) {
1111
+ setInternalValue("");
1112
+ onChange?.("");
1113
+ }
1114
+ if (inputRef.current) {
1115
+ inputRef.current.focus();
1116
+ }
1117
+ };
1118
+ const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
1119
+ ref: inputRef,
1120
+ value: resolvedValue,
1121
+ onChange: handleChange,
1122
+ onKeyDown: handleKeyDown,
1123
+ autoFocus,
1124
+ className: twMerge3(
1125
+ "w-full py-3",
1126
+ isExpanded ? "px-5" : "pr-5"
1127
+ )
1128
+ });
1129
+ const isProcessing = mode !== "transcribe" && isRunning;
1130
+ const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
1131
+ const canStop = !!onStop;
1132
+ const handleSendButtonClick = () => {
1133
+ if (isProcessing) {
1134
+ onStop?.();
1135
+ return;
1136
+ }
1137
+ send();
1138
+ };
1139
+ const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
1140
+ ref: audioRecorderRef
1141
+ });
1142
+ const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
1143
+ onClick: handleSendButtonClick,
1144
+ disabled: isProcessing ? !canStop : !canSend,
1145
+ children: isProcessing && canStop ? /* @__PURE__ */ jsx6(Square, { className: "size-[18px] fill-current" }) : void 0
1146
+ });
1147
+ const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
1148
+ onClick: onStartTranscribe
1149
+ });
1150
+ const BoundCancelTranscribeButton = renderSlot(cancelTranscribeButton, CopilotChatInput.CancelTranscribeButton, {
1151
+ onClick: onCancelTranscribe
1152
+ });
1153
+ const BoundFinishTranscribeButton = renderSlot(finishTranscribeButton, CopilotChatInput.FinishTranscribeButton, {
1154
+ onClick: onFinishTranscribe
1155
+ });
1156
+ const BoundAddMenuButton = renderSlot(addMenuButton, CopilotChatInput.AddMenuButton, {
1157
+ disabled: mode === "transcribe",
1158
+ onAddFile,
1159
+ toolsMenu
1160
+ });
1161
+ if (children) {
1162
+ const childProps = {
1163
+ textArea: BoundTextArea,
1164
+ audioRecorder: BoundAudioRecorder,
1165
+ sendButton: BoundSendButton,
1166
+ startTranscribeButton: BoundStartTranscribeButton,
1167
+ cancelTranscribeButton: BoundCancelTranscribeButton,
1168
+ finishTranscribeButton: BoundFinishTranscribeButton,
1169
+ addMenuButton: BoundAddMenuButton,
1170
+ onSubmitMessage,
1171
+ onStop,
1172
+ isRunning,
1173
+ onStartTranscribe,
1174
+ onCancelTranscribe,
1175
+ onFinishTranscribe,
1176
+ onAddFile,
1177
+ mode,
1178
+ toolsMenu,
1179
+ autoFocus
1180
+ };
1181
+ return /* @__PURE__ */ jsx6(Fragment, { children: children(childProps) });
1182
+ }
1183
+ const handleContainerClick = (e) => {
1184
+ const target = e.target;
1185
+ if (target.tagName !== "BUTTON" && !target.closest("button") && inputRef.current && mode === "input") {
1186
+ inputRef.current.focus();
1187
+ }
1188
+ };
1189
+ const ensureMeasurements = useCallback(() => {
1190
+ const textarea = inputRef.current;
1191
+ if (!textarea) {
1192
+ return;
1193
+ }
1194
+ const previousValue = textarea.value;
1195
+ const previousHeight = textarea.style.height;
1196
+ textarea.style.height = "auto";
1197
+ const computedStyle = window.getComputedStyle(textarea);
1198
+ const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
1199
+ const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
1200
+ const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
1201
+ const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0;
1202
+ textarea.value = "";
1203
+ const singleLineHeight = textarea.scrollHeight;
1204
+ textarea.value = previousValue;
1205
+ const contentHeight = singleLineHeight - paddingTop - paddingBottom;
1206
+ const maxHeight = contentHeight * 5 + paddingTop + paddingBottom;
1207
+ measurementsRef.current = {
1208
+ singleLineHeight,
1209
+ maxHeight,
1210
+ paddingLeft,
1211
+ paddingRight
1212
+ };
1213
+ textarea.style.height = previousHeight;
1214
+ textarea.style.maxHeight = `${maxHeight}px`;
1215
+ }, []);
1216
+ const adjustTextareaHeight = useCallback(() => {
1217
+ const textarea = inputRef.current;
1218
+ if (!textarea) {
1219
+ return 0;
1220
+ }
1221
+ if (measurementsRef.current.singleLineHeight === 0) {
1222
+ ensureMeasurements();
1223
+ }
1224
+ const { maxHeight } = measurementsRef.current;
1225
+ if (maxHeight) {
1226
+ textarea.style.maxHeight = `${maxHeight}px`;
1227
+ }
1228
+ textarea.style.height = "auto";
1229
+ const scrollHeight = textarea.scrollHeight;
1230
+ if (maxHeight) {
1231
+ textarea.style.height = `${Math.min(scrollHeight, maxHeight)}px`;
1232
+ } else {
1233
+ textarea.style.height = `${scrollHeight}px`;
1234
+ }
1235
+ return scrollHeight;
1236
+ }, [ensureMeasurements]);
1237
+ const updateLayout = useCallback((nextLayout) => {
1238
+ setLayout((prev) => {
1239
+ if (prev === nextLayout) {
1240
+ return prev;
1241
+ }
1242
+ ignoreResizeRef.current = true;
1243
+ return nextLayout;
1244
+ });
1245
+ }, []);
1246
+ const evaluateLayout = useCallback(() => {
1247
+ if (mode !== "input") {
1248
+ updateLayout("compact");
1249
+ return;
1250
+ }
1251
+ if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
1252
+ const isMobileViewport = window.matchMedia("(max-width: 767px)").matches;
1253
+ if (isMobileViewport) {
1254
+ ensureMeasurements();
1255
+ adjustTextareaHeight();
1256
+ updateLayout("expanded");
1257
+ return;
1258
+ }
1259
+ }
1260
+ const textarea = inputRef.current;
1261
+ const grid = gridRef.current;
1262
+ const addContainer = addButtonContainerRef.current;
1263
+ const actionsContainer = actionsContainerRef.current;
1264
+ if (!textarea || !grid || !addContainer || !actionsContainer) {
1265
+ return;
1266
+ }
1267
+ if (measurementsRef.current.singleLineHeight === 0) {
1268
+ ensureMeasurements();
1269
+ }
1270
+ const scrollHeight = adjustTextareaHeight();
1271
+ const baseline = measurementsRef.current.singleLineHeight;
1272
+ const hasExplicitBreak = resolvedValue.includes("\n");
1273
+ const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
1274
+ let shouldExpand = hasExplicitBreak || renderedMultiline;
1275
+ if (!shouldExpand) {
1276
+ const gridStyles = window.getComputedStyle(grid);
1277
+ const paddingLeft = parseFloat(gridStyles.paddingLeft) || 0;
1278
+ const paddingRight = parseFloat(gridStyles.paddingRight) || 0;
1279
+ const columnGap = parseFloat(gridStyles.columnGap) || 0;
1280
+ const gridAvailableWidth = grid.clientWidth - paddingLeft - paddingRight;
1281
+ if (gridAvailableWidth > 0) {
1282
+ const addWidth = addContainer.getBoundingClientRect().width;
1283
+ const actionsWidth = actionsContainer.getBoundingClientRect().width;
1284
+ const compactWidth = Math.max(gridAvailableWidth - addWidth - actionsWidth - columnGap * 2, 0);
1285
+ const canvas = measurementCanvasRef.current ?? document.createElement("canvas");
1286
+ if (!measurementCanvasRef.current) {
1287
+ measurementCanvasRef.current = canvas;
1288
+ }
1289
+ const context = canvas.getContext("2d");
1290
+ if (context) {
1291
+ const textareaStyles = window.getComputedStyle(textarea);
1292
+ const font = textareaStyles.font || `${textareaStyles.fontStyle} ${textareaStyles.fontVariant} ${textareaStyles.fontWeight} ${textareaStyles.fontSize}/${textareaStyles.lineHeight} ${textareaStyles.fontFamily}`;
1293
+ context.font = font;
1294
+ const compactInnerWidth = Math.max(
1295
+ compactWidth - (measurementsRef.current.paddingLeft || 0) - (measurementsRef.current.paddingRight || 0),
1296
+ 0
1297
+ );
1298
+ if (compactInnerWidth > 0) {
1299
+ const lines = resolvedValue.length > 0 ? resolvedValue.split("\n") : [""];
1300
+ let longestWidth = 0;
1301
+ for (const line of lines) {
1302
+ const metrics = context.measureText(line || " ");
1303
+ if (metrics.width > longestWidth) {
1304
+ longestWidth = metrics.width;
1305
+ }
1306
+ }
1307
+ if (longestWidth > compactInnerWidth) {
1308
+ shouldExpand = true;
1309
+ }
1310
+ }
1311
+ }
1312
+ }
1313
+ }
1314
+ const nextLayout = shouldExpand ? "expanded" : "compact";
1315
+ updateLayout(nextLayout);
1316
+ }, [adjustTextareaHeight, ensureMeasurements, mode, resolvedValue, updateLayout]);
1317
+ useLayoutEffect(() => {
1318
+ evaluateLayout();
1319
+ }, [evaluateLayout]);
1320
+ useEffect2(() => {
1321
+ if (typeof ResizeObserver === "undefined") {
1322
+ return;
1323
+ }
1324
+ const textarea = inputRef.current;
1325
+ const grid = gridRef.current;
1326
+ const addContainer = addButtonContainerRef.current;
1327
+ const actionsContainer = actionsContainerRef.current;
1328
+ if (!textarea || !grid || !addContainer || !actionsContainer) {
1329
+ return;
1330
+ }
1331
+ const scheduleEvaluation = () => {
1332
+ if (ignoreResizeRef.current) {
1333
+ ignoreResizeRef.current = false;
1334
+ return;
1335
+ }
1336
+ if (typeof window === "undefined") {
1337
+ evaluateLayout();
1338
+ return;
1339
+ }
1340
+ if (resizeEvaluationRafRef.current !== null) {
1341
+ cancelAnimationFrame(resizeEvaluationRafRef.current);
1342
+ }
1343
+ resizeEvaluationRafRef.current = window.requestAnimationFrame(() => {
1344
+ resizeEvaluationRafRef.current = null;
1345
+ evaluateLayout();
1346
+ });
1347
+ };
1348
+ const observer = new ResizeObserver(() => {
1349
+ scheduleEvaluation();
1350
+ });
1351
+ observer.observe(grid);
1352
+ observer.observe(addContainer);
1353
+ observer.observe(actionsContainer);
1354
+ observer.observe(textarea);
1355
+ return () => {
1356
+ observer.disconnect();
1357
+ if (typeof window !== "undefined" && resizeEvaluationRafRef.current !== null) {
1358
+ cancelAnimationFrame(resizeEvaluationRafRef.current);
1359
+ resizeEvaluationRafRef.current = null;
1360
+ }
1361
+ };
1362
+ }, [evaluateLayout]);
1363
+ const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
1364
+ useEffect2(() => {
1365
+ if (!slashMenuVisible || slashHighlightIndex < 0) {
1366
+ return;
1367
+ }
1368
+ const active = slashMenuRef.current?.querySelector(
1369
+ `[data-slash-index="${slashHighlightIndex}"]`
1370
+ );
1371
+ active?.scrollIntoView({ block: "nearest" });
1372
+ }, [slashMenuVisible, slashHighlightIndex]);
1373
+ const slashMenu = slashMenuVisible ? /* @__PURE__ */ jsx6(
1374
+ "div",
1375
+ {
1376
+ "data-testid": "copilot-slash-menu",
1377
+ role: "listbox",
1378
+ "aria-label": "Slash commands",
1379
+ ref: slashMenuRef,
1380
+ 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]",
1381
+ style: { maxHeight: `${SLASH_MENU_MAX_VISIBLE_ITEMS * SLASH_MENU_ITEM_HEIGHT_PX}px` },
1382
+ children: filteredCommands.length === 0 ? /* @__PURE__ */ jsx6("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No commands found" }) : filteredCommands.map((item, index) => {
1383
+ const isActive = index === slashHighlightIndex;
1384
+ return /* @__PURE__ */ jsx6(
1385
+ "button",
1386
+ {
1387
+ type: "button",
1388
+ role: "option",
1389
+ "aria-selected": isActive,
1390
+ "data-active": isActive ? "true" : void 0,
1391
+ "data-slash-index": index,
1392
+ className: twMerge3(
1393
+ "w-full px-3 py-2 text-left text-sm transition-colors",
1394
+ "hover:bg-muted dark:hover:bg-[#2f2f2f]",
1395
+ isActive ? "bg-muted dark:bg-[#2f2f2f]" : "bg-transparent"
1396
+ ),
1397
+ onMouseEnter: () => setSlashHighlightIndex(index),
1398
+ onMouseDown: (event) => {
1399
+ event.preventDefault();
1400
+ runCommand(item);
1401
+ },
1402
+ children: item.label
1403
+ },
1404
+ `${item.label}-${index}`
1405
+ );
1406
+ })
1407
+ }
1408
+ ) : null;
1409
+ return /* @__PURE__ */ jsx6(
1410
+ "div",
1411
+ {
1412
+ className: twMerge3(
1413
+ // Layout
1414
+ "flex w-full flex-col items-center justify-center",
1415
+ // Interaction
1416
+ "cursor-text",
1417
+ // Overflow and clipping
1418
+ "overflow-visible bg-clip-padding contain-inline-size",
1419
+ // Background
1420
+ "bg-white dark:bg-[#303030]",
1421
+ // Visual effects
1422
+ "shadow-[0_4px_4px_0_#0000000a,0_0_1px_0_#0000009e] rounded-[28px]",
1423
+ className
1424
+ ),
1425
+ onClick: handleContainerClick,
1426
+ ...props,
1427
+ "data-layout": isExpanded ? "expanded" : "compact",
1428
+ children: /* @__PURE__ */ jsxs3(
1429
+ "div",
1430
+ {
1431
+ ref: gridRef,
1432
+ className: twMerge3(
1433
+ "grid w-full gap-x-3 gap-y-3 px-3 py-2",
1434
+ isExpanded ? "grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_auto]" : "grid-cols-[auto_minmax(0,1fr)_auto] items-center"
1435
+ ),
1436
+ "data-layout": isExpanded ? "expanded" : "compact",
1437
+ children: [
1438
+ /* @__PURE__ */ jsx6(
1439
+ "div",
1440
+ {
1441
+ ref: addButtonContainerRef,
1442
+ className: twMerge3(
1443
+ "flex items-center",
1444
+ isExpanded ? "row-start-2" : "row-start-1",
1445
+ "col-start-1"
1446
+ ),
1447
+ children: BoundAddMenuButton
1448
+ }
1449
+ ),
1450
+ /* @__PURE__ */ jsx6(
1451
+ "div",
1452
+ {
1453
+ className: twMerge3(
1454
+ "relative flex min-w-0 flex-col",
1455
+ isExpanded ? "col-span-3 row-start-1" : "col-start-2 row-start-1"
1456
+ ),
1457
+ children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */ jsxs3(Fragment, { children: [
1458
+ BoundTextArea,
1459
+ slashMenu
1460
+ ] })
1461
+ }
1462
+ ),
1463
+ /* @__PURE__ */ jsx6(
1464
+ "div",
1465
+ {
1466
+ ref: actionsContainerRef,
1467
+ className: twMerge3(
1468
+ "flex items-center justify-end gap-2",
1469
+ isExpanded ? "col-start-3 row-start-2" : "col-start-3 row-start-1"
1470
+ ),
1471
+ children: mode === "transcribe" ? /* @__PURE__ */ jsxs3(Fragment, { children: [
1472
+ onCancelTranscribe && BoundCancelTranscribeButton,
1473
+ onFinishTranscribe && BoundFinishTranscribeButton
1474
+ ] }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
1475
+ onStartTranscribe && BoundStartTranscribeButton,
1476
+ BoundSendButton
1477
+ ] })
1478
+ }
1479
+ )
1480
+ ]
1481
+ }
1482
+ )
1483
+ }
1484
+ );
1485
+ }
1486
+ ((CopilotChatInput2) => {
1487
+ CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ jsx6("div", { className: "mr-[10px]", children: /* @__PURE__ */ jsx6(
1488
+ Button,
1489
+ {
1490
+ type: "button",
1491
+ variant: "chatInputToolbarPrimary",
1492
+ size: "chatInputToolbarIcon",
1493
+ className,
1494
+ ...props,
1495
+ children: children ?? /* @__PURE__ */ jsx6(ArrowUp, { className: "size-[18px]" })
1496
+ }
1497
+ ) });
1498
+ CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
1499
+ const config = useCopilotChatConfiguration();
1500
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1501
+ return /* @__PURE__ */ jsxs3(Tooltip, { children: [
1502
+ /* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
1503
+ Button,
1504
+ {
1505
+ type: "button",
1506
+ variant: "chatInputToolbarSecondary",
1507
+ size: "chatInputToolbarIcon",
1508
+ className: twMerge3(defaultClassName, className),
1509
+ ...props,
1510
+ children: icon
1511
+ }
1512
+ ) }),
1513
+ /* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx6("p", { children: labels[labelKey] }) })
1514
+ ] });
1515
+ };
1516
+ CopilotChatInput2.StartTranscribeButton = (props) => /* @__PURE__ */ jsx6(
1517
+ CopilotChatInput2.ToolbarButton,
1518
+ {
1519
+ icon: /* @__PURE__ */ jsx6(Mic, { className: "size-[18px]" }),
1520
+ labelKey: "chatInputToolbarStartTranscribeButtonLabel",
1521
+ defaultClassName: "mr-2",
1522
+ ...props
1523
+ }
1524
+ );
1525
+ CopilotChatInput2.CancelTranscribeButton = (props) => /* @__PURE__ */ jsx6(
1526
+ CopilotChatInput2.ToolbarButton,
1527
+ {
1528
+ icon: /* @__PURE__ */ jsx6(X, { className: "size-[18px]" }),
1529
+ labelKey: "chatInputToolbarCancelTranscribeButtonLabel",
1530
+ defaultClassName: "mr-2",
1531
+ ...props
1532
+ }
1533
+ );
1534
+ CopilotChatInput2.FinishTranscribeButton = (props) => /* @__PURE__ */ jsx6(
1535
+ CopilotChatInput2.ToolbarButton,
1536
+ {
1537
+ icon: /* @__PURE__ */ jsx6(Check, { className: "size-[18px]" }),
1538
+ labelKey: "chatInputToolbarFinishTranscribeButtonLabel",
1539
+ defaultClassName: "mr-[10px]",
1540
+ ...props
1541
+ }
1542
+ );
1543
+ CopilotChatInput2.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
1544
+ const config = useCopilotChatConfiguration();
1545
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1546
+ const menuItems = useMemo2(() => {
1547
+ const items = [];
1548
+ if (onAddFile) {
1549
+ items.push({
1550
+ label: labels.chatInputToolbarAddButtonLabel,
1551
+ action: onAddFile
1552
+ });
1553
+ }
1554
+ if (toolsMenu && toolsMenu.length > 0) {
1555
+ if (items.length > 0) {
1556
+ items.push("-");
1557
+ }
1558
+ for (const item of toolsMenu) {
1559
+ if (item === "-") {
1560
+ if (items.length === 0 || items[items.length - 1] === "-") {
1561
+ continue;
1562
+ }
1563
+ items.push(item);
1564
+ } else {
1565
+ items.push(item);
1566
+ }
1567
+ }
1568
+ while (items.length > 0 && items[items.length - 1] === "-") {
1569
+ items.pop();
1570
+ }
1571
+ }
1572
+ return items;
1573
+ }, [onAddFile, toolsMenu, labels.chatInputToolbarAddButtonLabel]);
1574
+ const renderMenuItems = useCallback(
1575
+ (items) => items.map((item, index) => {
1576
+ if (item === "-") {
1577
+ return /* @__PURE__ */ jsx6(DropdownMenuSeparator, {}, `separator-${index}`);
1578
+ }
1579
+ if (item.items && item.items.length > 0) {
1580
+ return /* @__PURE__ */ jsxs3(DropdownMenuSub, { children: [
1581
+ /* @__PURE__ */ jsx6(DropdownMenuSubTrigger, { children: item.label }),
1582
+ /* @__PURE__ */ jsx6(DropdownMenuSubContent, { children: renderMenuItems(item.items) })
1583
+ ] }, `group-${index}`);
1584
+ }
1585
+ return /* @__PURE__ */ jsx6(DropdownMenuItem, { onClick: item.action, children: item.label }, `item-${index}`);
1586
+ }),
1587
+ []
1588
+ );
1589
+ const hasMenuItems = menuItems.length > 0;
1590
+ const isDisabled = disabled || !hasMenuItems;
1591
+ return /* @__PURE__ */ jsxs3(DropdownMenu, { children: [
1592
+ /* @__PURE__ */ jsxs3(Tooltip, { children: [
1593
+ /* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
1594
+ Button,
1595
+ {
1596
+ type: "button",
1597
+ variant: "chatInputToolbarSecondary",
1598
+ size: "chatInputToolbarIcon",
1599
+ className: twMerge3("ml-1", className),
1600
+ disabled: isDisabled,
1601
+ ...props,
1602
+ children: /* @__PURE__ */ jsx6(Plus, { className: "size-[20px]" })
1603
+ }
1604
+ ) }) }),
1605
+ /* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsxs3("p", { className: "flex items-center gap-1 text-xs font-medium", children: [
1606
+ /* @__PURE__ */ jsx6("span", { children: "Add files and more" }),
1607
+ /* @__PURE__ */ jsx6("code", { className: "rounded bg-[#4a4a4a] px-1 py-[1px] font-mono text-[11px] text-white dark:bg-[#e0e0e0] dark:text-black", children: "/" })
1608
+ ] }) })
1609
+ ] }),
1610
+ hasMenuItems && /* @__PURE__ */ jsx6(DropdownMenuContent, { side: "top", align: "start", children: renderMenuItems(menuItems) })
1611
+ ] });
1612
+ };
1613
+ CopilotChatInput2.TextArea = forwardRef2(function TextArea2({ style, className, autoFocus, ...props }, ref) {
1614
+ const internalTextareaRef = useRef2(null);
1615
+ const config = useCopilotChatConfiguration();
1616
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1617
+ useImperativeHandle2(ref, () => internalTextareaRef.current);
1618
+ useEffect2(() => {
1619
+ const textarea = internalTextareaRef.current;
1620
+ if (!textarea) return;
1621
+ const handleFocus = () => {
1622
+ setTimeout(() => {
1623
+ textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
1624
+ }, 300);
1625
+ };
1626
+ textarea.addEventListener("focus", handleFocus);
1627
+ return () => textarea.removeEventListener("focus", handleFocus);
1628
+ }, []);
1629
+ useEffect2(() => {
1630
+ if (autoFocus) {
1631
+ internalTextareaRef.current?.focus();
1632
+ }
1633
+ }, [autoFocus]);
1634
+ return /* @__PURE__ */ jsx6(
1635
+ "textarea",
1636
+ {
1637
+ ref: internalTextareaRef,
1638
+ ...props,
1639
+ style: {
1640
+ overflow: "auto",
1641
+ resize: "none",
1642
+ ...style
1643
+ },
1644
+ placeholder: labels.chatInputPlaceholder,
1645
+ className: twMerge3(
1646
+ "bg-transparent outline-none antialiased font-regular leading-relaxed text-[16px] placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
1647
+ className
1648
+ ),
1649
+ rows: 1
1650
+ }
1651
+ );
1652
+ });
1653
+ CopilotChatInput2.AudioRecorder = CopilotChatAudioRecorder;
1654
+ })(CopilotChatInput || (CopilotChatInput = {}));
1655
+ CopilotChatInput.TextArea.displayName = "CopilotChatInput.TextArea";
1656
+ CopilotChatInput.SendButton.displayName = "CopilotChatInput.SendButton";
1657
+ CopilotChatInput.ToolbarButton.displayName = "CopilotChatInput.ToolbarButton";
1658
+ CopilotChatInput.StartTranscribeButton.displayName = "CopilotChatInput.StartTranscribeButton";
1659
+ CopilotChatInput.CancelTranscribeButton.displayName = "CopilotChatInput.CancelTranscribeButton";
1660
+ CopilotChatInput.FinishTranscribeButton.displayName = "CopilotChatInput.FinishTranscribeButton";
1661
+ CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
1662
+ var CopilotChatInput_default = CopilotChatInput;
1663
+
1664
+ // src/components/chat/CopilotChatAssistantMessage.tsx
1665
+ import { useState as useState6 } from "react";
106
1666
  import {
107
- CopilotKitProvider,
108
- useCopilotKit
109
- } from "./chunk-VE3SBLU7.mjs";
1667
+ Copy,
1668
+ Check as Check2,
1669
+ ThumbsUp,
1670
+ ThumbsDown,
1671
+ Volume2,
1672
+ RefreshCw
1673
+ } from "lucide-react";
1674
+ import { twMerge as twMerge4 } from "tailwind-merge";
1675
+ import "katex/dist/katex.min.css";
1676
+ import { Streamdown } from "streamdown";
1677
+
1678
+ // src/hooks/use-render-tool-call.tsx
1679
+ import { useCallback as useCallback2, useEffect as useEffect5, useState as useState4, useSyncExternalStore } from "react";
1680
+ import { ToolCallStatus } from "@copilotkitnext/core";
1681
+
1682
+ // src/providers/CopilotKitProvider.tsx
110
1683
  import {
111
- CopilotKitInspector
112
- } from "./chunk-YPH4BHOY.mjs";
1684
+ createContext as createContext2,
1685
+ useContext as useContext2,
1686
+ useMemo as useMemo3,
1687
+ useEffect as useEffect4,
1688
+ useReducer,
1689
+ useRef as useRef4,
1690
+ useState as useState3
1691
+ } from "react";
1692
+ import { z } from "zod";
1693
+
1694
+ // src/lib/react-core.ts
1695
+ import { CopilotKitCore } from "@copilotkitnext/core";
1696
+ var CopilotKitCoreReact = class extends CopilotKitCore {
1697
+ _renderToolCalls = [];
1698
+ _renderCustomMessages = [];
1699
+ _renderActivityMessages = [];
1700
+ constructor(config) {
1701
+ super(config);
1702
+ this._renderToolCalls = config.renderToolCalls ?? [];
1703
+ this._renderCustomMessages = config.renderCustomMessages ?? [];
1704
+ this._renderActivityMessages = config.renderActivityMessages ?? [];
1705
+ }
1706
+ get renderCustomMessages() {
1707
+ return this._renderCustomMessages;
1708
+ }
1709
+ get renderActivityMessages() {
1710
+ return this._renderActivityMessages;
1711
+ }
1712
+ get renderToolCalls() {
1713
+ return this._renderToolCalls;
1714
+ }
1715
+ setRenderToolCalls(renderToolCalls) {
1716
+ this._renderToolCalls = renderToolCalls;
1717
+ void this.notifySubscribers(
1718
+ (subscriber) => {
1719
+ const reactSubscriber = subscriber;
1720
+ if (reactSubscriber.onRenderToolCallsChanged) {
1721
+ reactSubscriber.onRenderToolCallsChanged({
1722
+ copilotkit: this,
1723
+ renderToolCalls: this.renderToolCalls
1724
+ });
1725
+ }
1726
+ },
1727
+ "Subscriber onRenderToolCallsChanged error:"
1728
+ );
1729
+ }
1730
+ // Override to accept React-specific subscriber type
1731
+ subscribe(subscriber) {
1732
+ return super.subscribe(subscriber);
1733
+ }
1734
+ unsubscribe(subscriber) {
1735
+ super.unsubscribe(subscriber);
1736
+ }
1737
+ };
1738
+
1739
+ // src/components/CopilotKitInspector.tsx
1740
+ import * as React4 from "react";
1741
+ import { createComponent } from "@lit-labs/react";
113
1742
  import {
114
- CopilotKitCoreReact
115
- } from "./chunk-NNAYEAP2.mjs";
1743
+ WEB_INSPECTOR_TAG,
1744
+ WebInspectorElement,
1745
+ defineWebInspector
1746
+ } from "@copilotkitnext/web-inspector";
1747
+ import { jsx as jsx7 } from "react/jsx-runtime";
1748
+ defineWebInspector();
1749
+ var CopilotKitInspectorBase = createComponent({
1750
+ tagName: WEB_INSPECTOR_TAG,
1751
+ elementClass: WebInspectorElement,
1752
+ react: React4
1753
+ });
1754
+ var CopilotKitInspector = React4.forwardRef(
1755
+ ({ core, ...rest }, ref) => {
1756
+ const innerRef = React4.useRef(null);
1757
+ React4.useImperativeHandle(ref, () => innerRef.current, []);
1758
+ React4.useEffect(() => {
1759
+ if (innerRef.current) {
1760
+ innerRef.current.core = core ?? null;
1761
+ }
1762
+ }, [core]);
1763
+ return /* @__PURE__ */ jsx7(
1764
+ CopilotKitInspectorBase,
1765
+ {
1766
+ ...rest,
1767
+ ref: innerRef
1768
+ }
1769
+ );
1770
+ }
1771
+ );
1772
+ CopilotKitInspector.displayName = "CopilotKitInspector";
1773
+
1774
+ // src/providers/CopilotKitProvider.tsx
1775
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
1776
+ var CopilotKitContext = createContext2({
1777
+ copilotkit: null
1778
+ });
1779
+ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
1780
+ const empty = useMemo3(() => [], []);
1781
+ const value = prop ?? empty;
1782
+ const initial = useRef4(value);
1783
+ useEffect4(() => {
1784
+ if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) {
1785
+ console.error(warningMessage);
1786
+ }
1787
+ }, [value, warningMessage]);
1788
+ return value;
1789
+ }
1790
+ var CopilotKitProvider = ({
1791
+ children,
1792
+ runtimeUrl,
1793
+ headers = {},
1794
+ properties = {},
1795
+ agents__unsafe_dev_only: agents = {},
1796
+ renderToolCalls,
1797
+ renderActivityMessages,
1798
+ renderCustomMessages,
1799
+ frontendTools,
1800
+ humanInTheLoop,
1801
+ showDevConsole = false,
1802
+ useSingleEndpoint = false
1803
+ }) => {
1804
+ const [shouldRenderInspector, setShouldRenderInspector] = useState3(false);
1805
+ useEffect4(() => {
1806
+ if (typeof window === "undefined") {
1807
+ return;
1808
+ }
1809
+ if (showDevConsole === true) {
1810
+ setShouldRenderInspector(true);
1811
+ } else if (showDevConsole === "auto") {
1812
+ const localhostHosts = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
1813
+ if (localhostHosts.has(window.location.hostname)) {
1814
+ setShouldRenderInspector(true);
1815
+ } else {
1816
+ setShouldRenderInspector(false);
1817
+ }
1818
+ } else {
1819
+ setShouldRenderInspector(false);
1820
+ }
1821
+ }, [showDevConsole]);
1822
+ const renderToolCallsList = useStableArrayProp(
1823
+ renderToolCalls,
1824
+ "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.",
1825
+ (initial, next) => {
1826
+ const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
1827
+ const setFrom = (arr) => new Set(arr.map(key));
1828
+ const a = setFrom(initial);
1829
+ const b = setFrom(next);
1830
+ if (a.size !== b.size) return true;
1831
+ for (const k of a) if (!b.has(k)) return true;
1832
+ return false;
1833
+ }
1834
+ );
1835
+ const renderCustomMessagesList = useStableArrayProp(
1836
+ renderCustomMessages,
1837
+ "renderCustomMessages must be a stable array."
1838
+ );
1839
+ const renderActivityMessagesList = useStableArrayProp(
1840
+ renderActivityMessages,
1841
+ "renderActivityMessages must be a stable array."
1842
+ );
1843
+ const frontendToolsList = useStableArrayProp(
1844
+ frontendTools,
1845
+ "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
1846
+ );
1847
+ const humanInTheLoopList = useStableArrayProp(
1848
+ humanInTheLoop,
1849
+ "humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead."
1850
+ );
1851
+ const processedHumanInTheLoopTools = useMemo3(() => {
1852
+ const processedTools = [];
1853
+ const processedRenderToolCalls = [];
1854
+ humanInTheLoopList.forEach((tool) => {
1855
+ const frontendTool = {
1856
+ name: tool.name,
1857
+ description: tool.description,
1858
+ parameters: tool.parameters,
1859
+ followUp: tool.followUp,
1860
+ ...tool.agentId && { agentId: tool.agentId },
1861
+ handler: async () => {
1862
+ return new Promise((resolve) => {
1863
+ console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
1864
+ resolve(void 0);
1865
+ });
1866
+ }
1867
+ };
1868
+ processedTools.push(frontendTool);
1869
+ if (tool.render) {
1870
+ processedRenderToolCalls.push({
1871
+ name: tool.name,
1872
+ args: tool.parameters,
1873
+ render: tool.render,
1874
+ ...tool.agentId && { agentId: tool.agentId }
1875
+ });
1876
+ }
1877
+ });
1878
+ return { tools: processedTools, renderToolCalls: processedRenderToolCalls };
1879
+ }, [humanInTheLoopList]);
1880
+ const allTools = useMemo3(() => {
1881
+ const tools = [];
1882
+ tools.push(...frontendToolsList);
1883
+ tools.push(...processedHumanInTheLoopTools.tools);
1884
+ return tools;
1885
+ }, [frontendToolsList, processedHumanInTheLoopTools]);
1886
+ const allRenderToolCalls = useMemo3(() => {
1887
+ const combined = [...renderToolCallsList];
1888
+ frontendToolsList.forEach((tool) => {
1889
+ if (tool.render) {
1890
+ const args = tool.parameters || (tool.name === "*" ? z.any() : void 0);
1891
+ if (args) {
1892
+ combined.push({
1893
+ name: tool.name,
1894
+ args,
1895
+ render: tool.render
1896
+ });
1897
+ }
1898
+ }
1899
+ });
1900
+ combined.push(...processedHumanInTheLoopTools.renderToolCalls);
1901
+ return combined;
1902
+ }, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
1903
+ const copilotkit = useMemo3(() => {
1904
+ const copilotkit2 = new CopilotKitCoreReact({
1905
+ runtimeUrl,
1906
+ runtimeTransport: useSingleEndpoint ? "single" : "rest",
1907
+ headers,
1908
+ properties,
1909
+ agents__unsafe_dev_only: agents,
1910
+ tools: allTools,
1911
+ renderToolCalls: allRenderToolCalls,
1912
+ renderActivityMessages: renderActivityMessagesList,
1913
+ renderCustomMessages: renderCustomMessagesList
1914
+ });
1915
+ return copilotkit2;
1916
+ }, [allTools, allRenderToolCalls, renderActivityMessagesList, renderCustomMessagesList, useSingleEndpoint]);
1917
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
1918
+ useEffect4(() => {
1919
+ const unsubscribe = copilotkit.subscribe({
1920
+ onRenderToolCallsChanged: () => {
1921
+ forceUpdate();
1922
+ }
1923
+ });
1924
+ return () => {
1925
+ unsubscribe();
1926
+ };
1927
+ }, [copilotkit]);
1928
+ useEffect4(() => {
1929
+ copilotkit.setRuntimeUrl(runtimeUrl);
1930
+ copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
1931
+ copilotkit.setHeaders(headers);
1932
+ copilotkit.setProperties(properties);
1933
+ copilotkit.setAgents__unsafe_dev_only(agents);
1934
+ }, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
1935
+ return /* @__PURE__ */ jsxs4(
1936
+ CopilotKitContext.Provider,
1937
+ {
1938
+ value: {
1939
+ copilotkit
1940
+ },
1941
+ children: [
1942
+ children,
1943
+ shouldRenderInspector ? /* @__PURE__ */ jsx8(CopilotKitInspector, { core: copilotkit }) : null
1944
+ ]
1945
+ }
1946
+ );
1947
+ };
1948
+ var useCopilotKit = () => {
1949
+ const context = useContext2(CopilotKitContext);
1950
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
1951
+ if (!context) {
1952
+ throw new Error("useCopilotKit must be used within CopilotKitProvider");
1953
+ }
1954
+ useEffect4(() => {
1955
+ const unsubscribe = context.copilotkit.subscribe({
1956
+ onRuntimeConnectionStatusChanged: () => {
1957
+ forceUpdate();
1958
+ }
1959
+ });
1960
+ return () => {
1961
+ unsubscribe();
1962
+ };
1963
+ }, []);
1964
+ return context;
1965
+ };
1966
+
1967
+ // src/hooks/use-render-tool-call.tsx
1968
+ import { jsx as jsx9 } from "react/jsx-runtime";
1969
+ function useRenderToolCall() {
1970
+ const { copilotkit } = useCopilotKit();
1971
+ const config = useCopilotChatConfiguration();
1972
+ const agentId = config?.agentId ?? DEFAULT_AGENT_ID;
1973
+ const [executingToolCallIds, setExecutingToolCallIds] = useState4(() => /* @__PURE__ */ new Set());
1974
+ const renderToolCalls = useSyncExternalStore(
1975
+ (callback) => {
1976
+ return copilotkit.subscribe({
1977
+ onRenderToolCallsChanged: callback
1978
+ });
1979
+ },
1980
+ () => copilotkit.renderToolCalls,
1981
+ () => copilotkit.renderToolCalls
1982
+ );
1983
+ useEffect5(() => {
1984
+ const unsubscribe = copilotkit.subscribe({
1985
+ onToolExecutionStart: ({ toolCallId }) => {
1986
+ setExecutingToolCallIds((prev) => {
1987
+ if (prev.has(toolCallId)) return prev;
1988
+ const next = new Set(prev);
1989
+ next.add(toolCallId);
1990
+ return next;
1991
+ });
1992
+ },
1993
+ onToolExecutionEnd: ({ toolCallId }) => {
1994
+ setExecutingToolCallIds((prev) => {
1995
+ if (!prev.has(toolCallId)) return prev;
1996
+ const next = new Set(prev);
1997
+ next.delete(toolCallId);
1998
+ return next;
1999
+ });
2000
+ }
2001
+ });
2002
+ return () => unsubscribe();
2003
+ }, [copilotkit]);
2004
+ const renderToolCall = useCallback2(
2005
+ ({
2006
+ toolCall,
2007
+ toolMessage
2008
+ }) => {
2009
+ const exactMatches = renderToolCalls.filter(
2010
+ (rc) => rc.name === toolCall.function.name
2011
+ );
2012
+ const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
2013
+ if (!renderConfig) {
2014
+ return null;
2015
+ }
2016
+ const RenderComponent = renderConfig.render;
2017
+ const args = partialJSONParse(toolCall.function.arguments);
2018
+ const toolName = toolCall.function.name;
2019
+ if (toolMessage) {
2020
+ return /* @__PURE__ */ jsx9(
2021
+ RenderComponent,
2022
+ {
2023
+ name: toolName,
2024
+ args,
2025
+ status: ToolCallStatus.Complete,
2026
+ result: toolMessage.content
2027
+ },
2028
+ toolCall.id
2029
+ );
2030
+ } else if (executingToolCallIds.has(toolCall.id)) {
2031
+ return /* @__PURE__ */ jsx9(
2032
+ RenderComponent,
2033
+ {
2034
+ name: toolName,
2035
+ args,
2036
+ status: ToolCallStatus.Executing,
2037
+ result: void 0
2038
+ },
2039
+ toolCall.id
2040
+ );
2041
+ } else {
2042
+ return /* @__PURE__ */ jsx9(
2043
+ RenderComponent,
2044
+ {
2045
+ name: toolName,
2046
+ args,
2047
+ status: ToolCallStatus.InProgress,
2048
+ result: void 0
2049
+ },
2050
+ toolCall.id
2051
+ );
2052
+ }
2053
+ },
2054
+ [renderToolCalls, executingToolCallIds, agentId]
2055
+ );
2056
+ return renderToolCall;
2057
+ }
2058
+
2059
+ // src/hooks/use-render-custom-messages.tsx
2060
+ import { jsx as jsx10 } from "react/jsx-runtime";
2061
+ function useRenderCustomMessages() {
2062
+ const { copilotkit } = useCopilotKit();
2063
+ const config = useCopilotChatConfiguration();
2064
+ if (!config) {
2065
+ return null;
2066
+ }
2067
+ const { agentId, threadId } = config;
2068
+ const customMessageRenderers = copilotkit.renderCustomMessages.filter((renderer) => renderer.agentId === void 0 || renderer.agentId === agentId).sort((a, b) => {
2069
+ const aHasAgent = a.agentId !== void 0;
2070
+ const bHasAgent = b.agentId !== void 0;
2071
+ if (aHasAgent === bHasAgent) return 0;
2072
+ return aHasAgent ? -1 : 1;
2073
+ });
2074
+ return function(params) {
2075
+ if (!customMessageRenderers.length) {
2076
+ return null;
2077
+ }
2078
+ const { message, position } = params;
2079
+ const runId = copilotkit.getRunIdForMessage(agentId, threadId, message.id);
2080
+ const agent = copilotkit.getAgent(agentId);
2081
+ if (!agent) {
2082
+ throw new Error("Agent not found");
2083
+ }
2084
+ const messagesIdsInRun = agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === runId).map((msg) => msg.id);
2085
+ const messageIndex = agent.messages.findIndex((msg) => msg.id === message.id) ?? 0;
2086
+ const messageIndexInRun = Math.min(messagesIdsInRun.indexOf(message.id), 0);
2087
+ const numberOfMessagesInRun = messagesIdsInRun.length;
2088
+ const stateSnapshot = copilotkit.getStateByRun(agentId, threadId, runId);
2089
+ let result = null;
2090
+ for (const renderer of customMessageRenderers) {
2091
+ if (!renderer.render) {
2092
+ continue;
2093
+ }
2094
+ const Component = renderer.render;
2095
+ result = /* @__PURE__ */ jsx10(
2096
+ Component,
2097
+ {
2098
+ message,
2099
+ position,
2100
+ runId,
2101
+ messageIndex,
2102
+ messageIndexInRun,
2103
+ numberOfMessagesInRun,
2104
+ agentId,
2105
+ stateSnapshot
2106
+ },
2107
+ `${runId}-${message.id}-${position}`
2108
+ );
2109
+ if (result) {
2110
+ break;
2111
+ }
2112
+ }
2113
+ return result;
2114
+ };
2115
+ }
2116
+
2117
+ // src/hooks/use-render-activity-message.tsx
2118
+ import { useCallback as useCallback3 } from "react";
2119
+ import { jsx as jsx11 } from "react/jsx-runtime";
2120
+ function useRenderActivityMessage() {
2121
+ const { copilotkit } = useCopilotKit();
2122
+ const config = useCopilotChatConfiguration();
2123
+ const agentId = config?.agentId ?? DEFAULT_AGENT_ID;
2124
+ const renderers = copilotkit.renderActivityMessages;
2125
+ return useCallback3(
2126
+ (message) => {
2127
+ if (!renderers.length) {
2128
+ return null;
2129
+ }
2130
+ const matches = renderers.filter(
2131
+ (renderer2) => renderer2.activityType === message.activityType
2132
+ );
2133
+ const renderer = matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*");
2134
+ if (!renderer) {
2135
+ return null;
2136
+ }
2137
+ const parseResult = renderer.content.safeParse(message.content);
2138
+ if (!parseResult.success) {
2139
+ console.warn(
2140
+ `Failed to parse content for activity message '${message.activityType}':`,
2141
+ parseResult.error
2142
+ );
2143
+ return null;
2144
+ }
2145
+ const Component = renderer.render;
2146
+ const agent = copilotkit.getAgent(agentId);
2147
+ return /* @__PURE__ */ jsx11(
2148
+ Component,
2149
+ {
2150
+ activityType: message.activityType,
2151
+ content: parseResult.data,
2152
+ message,
2153
+ agent
2154
+ },
2155
+ message.id
2156
+ );
2157
+ },
2158
+ [agentId, copilotkit, renderers]
2159
+ );
2160
+ }
2161
+
2162
+ // src/hooks/use-frontend-tool.tsx
2163
+ import { useEffect as useEffect6 } from "react";
2164
+ function useFrontendTool(tool) {
2165
+ const { copilotkit } = useCopilotKit();
2166
+ useEffect6(() => {
2167
+ const name = tool.name;
2168
+ if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
2169
+ console.warn(
2170
+ `Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`
2171
+ );
2172
+ copilotkit.removeTool(name, tool.agentId);
2173
+ }
2174
+ copilotkit.addTool(tool);
2175
+ if (tool.render) {
2176
+ const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
2177
+ const currentRenderToolCalls = copilotkit.renderToolCalls;
2178
+ const mergedMap = /* @__PURE__ */ new Map();
2179
+ for (const rc of currentRenderToolCalls) {
2180
+ mergedMap.set(keyOf(rc), rc);
2181
+ }
2182
+ const newEntry = {
2183
+ name,
2184
+ args: tool.parameters,
2185
+ agentId: tool.agentId,
2186
+ render: tool.render
2187
+ };
2188
+ mergedMap.set(keyOf(newEntry), newEntry);
2189
+ copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
2190
+ }
2191
+ return () => {
2192
+ copilotkit.removeTool(name, tool.agentId);
2193
+ };
2194
+ }, [tool.name, copilotkit]);
2195
+ }
2196
+
2197
+ // src/hooks/use-human-in-the-loop.tsx
2198
+ import { useCallback as useCallback4, useRef as useRef5, useEffect as useEffect7 } from "react";
2199
+ import React7 from "react";
2200
+ function useHumanInTheLoop(tool) {
2201
+ const { copilotkit } = useCopilotKit();
2202
+ const resolvePromiseRef = useRef5(null);
2203
+ const respond = useCallback4(async (result) => {
2204
+ if (resolvePromiseRef.current) {
2205
+ resolvePromiseRef.current(result);
2206
+ resolvePromiseRef.current = null;
2207
+ }
2208
+ }, []);
2209
+ const handler = useCallback4(async () => {
2210
+ return new Promise((resolve) => {
2211
+ resolvePromiseRef.current = resolve;
2212
+ });
2213
+ }, []);
2214
+ const RenderComponent = useCallback4(
2215
+ (props) => {
2216
+ const ToolComponent = tool.render;
2217
+ if (props.status === "inProgress") {
2218
+ const enhancedProps = {
2219
+ ...props,
2220
+ name: tool.name,
2221
+ description: tool.description || "",
2222
+ respond: void 0
2223
+ };
2224
+ return React7.createElement(ToolComponent, enhancedProps);
2225
+ } else if (props.status === "executing") {
2226
+ const enhancedProps = {
2227
+ ...props,
2228
+ name: tool.name,
2229
+ description: tool.description || "",
2230
+ respond
2231
+ };
2232
+ return React7.createElement(ToolComponent, enhancedProps);
2233
+ } else if (props.status === "complete") {
2234
+ const enhancedProps = {
2235
+ ...props,
2236
+ name: tool.name,
2237
+ description: tool.description || "",
2238
+ respond: void 0
2239
+ };
2240
+ return React7.createElement(ToolComponent, enhancedProps);
2241
+ }
2242
+ return React7.createElement(ToolComponent, props);
2243
+ },
2244
+ [tool.render, tool.name, tool.description, respond]
2245
+ );
2246
+ const frontendTool = {
2247
+ ...tool,
2248
+ handler,
2249
+ render: RenderComponent
2250
+ };
2251
+ useFrontendTool(frontendTool);
2252
+ useEffect7(() => {
2253
+ return () => {
2254
+ const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
2255
+ const currentRenderToolCalls = copilotkit.renderToolCalls;
2256
+ const filtered = currentRenderToolCalls.filter(
2257
+ (rc) => keyOf(rc) !== keyOf({ name: tool.name, agentId: tool.agentId })
2258
+ );
2259
+ copilotkit.setRenderToolCalls(filtered);
2260
+ };
2261
+ }, [copilotkit, tool.name, tool.agentId]);
2262
+ }
2263
+
2264
+ // src/hooks/use-agent.tsx
2265
+ import { useMemo as useMemo4, useEffect as useEffect8, useReducer as useReducer2 } from "react";
2266
+ var ALL_UPDATES = [
2267
+ "OnMessagesChanged" /* OnMessagesChanged */,
2268
+ "OnStateChanged" /* OnStateChanged */,
2269
+ "OnRunStatusChanged" /* OnRunStatusChanged */
2270
+ ];
2271
+ function useAgent({ agentId, updates } = {}) {
2272
+ agentId ??= DEFAULT_AGENT_ID;
2273
+ const { copilotkit } = useCopilotKit();
2274
+ const [, forceUpdate] = useReducer2((x) => x + 1, 0);
2275
+ const updateFlags = useMemo4(
2276
+ () => updates ?? ALL_UPDATES,
2277
+ [JSON.stringify(updates)]
2278
+ );
2279
+ const agent = useMemo4(() => {
2280
+ return copilotkit.getAgent(agentId);
2281
+ }, [
2282
+ agentId,
2283
+ copilotkit.agents,
2284
+ copilotkit.runtimeConnectionStatus,
2285
+ copilotkit
2286
+ ]);
2287
+ useEffect8(() => {
2288
+ if (!agent) {
2289
+ return;
2290
+ }
2291
+ if (updateFlags.length === 0) {
2292
+ return;
2293
+ }
2294
+ const handlers = {};
2295
+ if (updateFlags.includes("OnMessagesChanged" /* OnMessagesChanged */)) {
2296
+ handlers.onMessagesChanged = () => {
2297
+ forceUpdate();
2298
+ };
2299
+ }
2300
+ if (updateFlags.includes("OnStateChanged" /* OnStateChanged */)) {
2301
+ handlers.onStateChanged = () => {
2302
+ forceUpdate();
2303
+ };
2304
+ }
2305
+ if (updateFlags.includes("OnRunStatusChanged" /* OnRunStatusChanged */)) {
2306
+ handlers.onRunInitialized = () => {
2307
+ forceUpdate();
2308
+ };
2309
+ handlers.onRunFinalized = () => {
2310
+ forceUpdate();
2311
+ };
2312
+ handlers.onRunFailed = () => {
2313
+ forceUpdate();
2314
+ };
2315
+ }
2316
+ const subscription = agent.subscribe(handlers);
2317
+ return () => subscription.unsubscribe();
2318
+ }, [agent, forceUpdate, JSON.stringify(updateFlags)]);
2319
+ return {
2320
+ agent
2321
+ };
2322
+ }
2323
+
2324
+ // src/hooks/use-agent-context.tsx
2325
+ import { useEffect as useEffect9 } from "react";
2326
+ function useAgentContext(context) {
2327
+ const { description, value } = context;
2328
+ const { copilotkit } = useCopilotKit();
2329
+ useEffect9(() => {
2330
+ if (!copilotkit) return;
2331
+ const id = copilotkit.addContext(context);
2332
+ return () => {
2333
+ copilotkit.removeContext(id);
2334
+ };
2335
+ }, [description, value, copilotkit]);
2336
+ }
2337
+
2338
+ // src/hooks/use-suggestions.tsx
2339
+ import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo5, useState as useState5 } from "react";
2340
+ function useSuggestions({ agentId } = {}) {
2341
+ const { copilotkit } = useCopilotKit();
2342
+ const config = useCopilotChatConfiguration();
2343
+ const resolvedAgentId = useMemo5(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID, [agentId, config?.agentId]);
2344
+ const [suggestions, setSuggestions] = useState5(() => {
2345
+ const result = copilotkit.getSuggestions(resolvedAgentId);
2346
+ return result.suggestions;
2347
+ });
2348
+ const [isLoading, setIsLoading] = useState5(() => {
2349
+ const result = copilotkit.getSuggestions(resolvedAgentId);
2350
+ return result.isLoading;
2351
+ });
2352
+ useEffect10(() => {
2353
+ const result = copilotkit.getSuggestions(resolvedAgentId);
2354
+ setSuggestions(result.suggestions);
2355
+ setIsLoading(result.isLoading);
2356
+ }, [copilotkit, resolvedAgentId]);
2357
+ useEffect10(() => {
2358
+ const unsubscribe = copilotkit.subscribe({
2359
+ onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
2360
+ if (changedAgentId !== resolvedAgentId) {
2361
+ return;
2362
+ }
2363
+ setSuggestions(suggestions2);
2364
+ },
2365
+ onSuggestionsStartedLoading: ({ agentId: changedAgentId }) => {
2366
+ if (changedAgentId !== resolvedAgentId) {
2367
+ return;
2368
+ }
2369
+ setIsLoading(true);
2370
+ },
2371
+ onSuggestionsFinishedLoading: ({ agentId: changedAgentId }) => {
2372
+ if (changedAgentId !== resolvedAgentId) {
2373
+ return;
2374
+ }
2375
+ setIsLoading(false);
2376
+ },
2377
+ onSuggestionsConfigChanged: () => {
2378
+ const result = copilotkit.getSuggestions(resolvedAgentId);
2379
+ setSuggestions(result.suggestions);
2380
+ setIsLoading(result.isLoading);
2381
+ }
2382
+ });
2383
+ return () => {
2384
+ unsubscribe();
2385
+ };
2386
+ }, [copilotkit, resolvedAgentId]);
2387
+ const reloadSuggestions = useCallback5(() => {
2388
+ copilotkit.reloadSuggestions(resolvedAgentId);
2389
+ }, [copilotkit, resolvedAgentId]);
2390
+ const clearSuggestions = useCallback5(() => {
2391
+ copilotkit.clearSuggestions(resolvedAgentId);
2392
+ }, [copilotkit, resolvedAgentId]);
2393
+ return {
2394
+ suggestions,
2395
+ reloadSuggestions,
2396
+ clearSuggestions,
2397
+ isLoading
2398
+ };
2399
+ }
2400
+
2401
+ // src/hooks/use-configure-suggestions.tsx
2402
+ import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo6, useRef as useRef6 } from "react";
2403
+ var EMPTY_DEPS = [];
2404
+ function useConfigureSuggestions(config, options) {
2405
+ const { copilotkit } = useCopilotKit();
2406
+ const chatConfig = useCopilotChatConfiguration();
2407
+ const extraDeps = options?.deps ?? EMPTY_DEPS;
2408
+ const resolvedConsumerAgentId = useMemo6(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID, [chatConfig?.agentId]);
2409
+ const rawConsumerAgentId = useMemo6(() => config ? config.consumerAgentId : void 0, [config]);
2410
+ const normalizationCacheRef = useRef6({
2411
+ serialized: null,
2412
+ config: null
2413
+ });
2414
+ const { normalizedConfig, serializedConfig } = useMemo6(() => {
2415
+ if (!config) {
2416
+ normalizationCacheRef.current = { serialized: null, config: null };
2417
+ return { normalizedConfig: null, serializedConfig: null };
2418
+ }
2419
+ if (config.available === "disabled") {
2420
+ normalizationCacheRef.current = { serialized: null, config: null };
2421
+ return { normalizedConfig: null, serializedConfig: null };
2422
+ }
2423
+ let built;
2424
+ if (isDynamicConfig(config)) {
2425
+ built = {
2426
+ ...config
2427
+ };
2428
+ } else {
2429
+ const normalizedSuggestions = normalizeStaticSuggestions(config.suggestions);
2430
+ const baseConfig = {
2431
+ ...config,
2432
+ suggestions: normalizedSuggestions
2433
+ };
2434
+ built = baseConfig;
2435
+ }
2436
+ const serialized = JSON.stringify(built);
2437
+ const cache = normalizationCacheRef.current;
2438
+ if (cache.serialized === serialized && cache.config) {
2439
+ return { normalizedConfig: cache.config, serializedConfig: serialized };
2440
+ }
2441
+ normalizationCacheRef.current = { serialized, config: built };
2442
+ return { normalizedConfig: built, serializedConfig: serialized };
2443
+ }, [config, resolvedConsumerAgentId, ...extraDeps]);
2444
+ const latestConfigRef = useRef6(null);
2445
+ latestConfigRef.current = normalizedConfig;
2446
+ const previousSerializedConfigRef = useRef6(null);
2447
+ const targetAgentId = useMemo6(() => {
2448
+ if (!normalizedConfig) {
2449
+ return resolvedConsumerAgentId;
2450
+ }
2451
+ const consumer = normalizedConfig.consumerAgentId;
2452
+ if (!consumer || consumer === "*") {
2453
+ return resolvedConsumerAgentId;
2454
+ }
2455
+ return consumer;
2456
+ }, [normalizedConfig, resolvedConsumerAgentId]);
2457
+ const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
2458
+ const requestReload = useCallback6(() => {
2459
+ if (!normalizedConfig) {
2460
+ return;
2461
+ }
2462
+ if (isGlobalConfig) {
2463
+ const agents = Object.values(copilotkit.agents ?? {});
2464
+ for (const entry of agents) {
2465
+ const agentId = entry.agentId;
2466
+ if (!agentId) {
2467
+ continue;
2468
+ }
2469
+ if (!entry.isRunning) {
2470
+ copilotkit.reloadSuggestions(agentId);
2471
+ }
2472
+ }
2473
+ return;
2474
+ }
2475
+ if (!targetAgentId) {
2476
+ return;
2477
+ }
2478
+ copilotkit.reloadSuggestions(targetAgentId);
2479
+ }, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
2480
+ useEffect11(() => {
2481
+ if (!serializedConfig || !latestConfigRef.current) {
2482
+ return;
2483
+ }
2484
+ const id = copilotkit.addSuggestionsConfig(latestConfigRef.current);
2485
+ requestReload();
2486
+ return () => {
2487
+ copilotkit.removeSuggestionsConfig(id);
2488
+ };
2489
+ }, [copilotkit, serializedConfig, requestReload]);
2490
+ useEffect11(() => {
2491
+ if (!normalizedConfig) {
2492
+ previousSerializedConfigRef.current = null;
2493
+ return;
2494
+ }
2495
+ if (serializedConfig && previousSerializedConfigRef.current === serializedConfig) {
2496
+ return;
2497
+ }
2498
+ if (serializedConfig) {
2499
+ previousSerializedConfigRef.current = serializedConfig;
2500
+ }
2501
+ requestReload();
2502
+ }, [normalizedConfig, requestReload, serializedConfig]);
2503
+ useEffect11(() => {
2504
+ if (!normalizedConfig || extraDeps.length === 0) {
2505
+ return;
2506
+ }
2507
+ requestReload();
2508
+ }, [extraDeps.length, normalizedConfig, requestReload, ...extraDeps]);
2509
+ }
2510
+ function isDynamicConfig(config) {
2511
+ return "instructions" in config;
2512
+ }
2513
+ function normalizeStaticSuggestions(suggestions) {
2514
+ return suggestions.map((suggestion) => ({
2515
+ ...suggestion,
2516
+ isLoading: suggestion.isLoading ?? false
2517
+ }));
2518
+ }
2519
+
2520
+ // src/components/chat/CopilotChatToolCallsView.tsx
2521
+ import React8 from "react";
2522
+ import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
2523
+ function CopilotChatToolCallsView({
2524
+ message,
2525
+ messages = []
2526
+ }) {
2527
+ const renderToolCall = useRenderToolCall();
2528
+ if (!message.toolCalls || message.toolCalls.length === 0) {
2529
+ return null;
2530
+ }
2531
+ return /* @__PURE__ */ jsx12(Fragment2, { children: message.toolCalls.map((toolCall) => {
2532
+ const toolMessage = messages.find(
2533
+ (m) => m.role === "tool" && m.toolCallId === toolCall.id
2534
+ );
2535
+ return /* @__PURE__ */ jsx12(React8.Fragment, { children: renderToolCall({
2536
+ toolCall,
2537
+ toolMessage
2538
+ }) }, toolCall.id);
2539
+ }) });
2540
+ }
2541
+ var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
2542
+
2543
+ // src/components/chat/CopilotChatAssistantMessage.tsx
2544
+ import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
2545
+ function CopilotChatAssistantMessage({
2546
+ message,
2547
+ messages,
2548
+ isRunning,
2549
+ onThumbsUp,
2550
+ onThumbsDown,
2551
+ onReadAloud,
2552
+ onRegenerate,
2553
+ additionalToolbarItems,
2554
+ toolbarVisible = true,
2555
+ markdownRenderer,
2556
+ toolbar,
2557
+ copyButton,
2558
+ thumbsUpButton,
2559
+ thumbsDownButton,
2560
+ readAloudButton,
2561
+ regenerateButton,
2562
+ toolCallsView,
2563
+ children,
2564
+ className,
2565
+ ...props
2566
+ }) {
2567
+ const boundMarkdownRenderer = renderSlot(
2568
+ markdownRenderer,
2569
+ CopilotChatAssistantMessage.MarkdownRenderer,
2570
+ {
2571
+ content: message.content || ""
2572
+ }
2573
+ );
2574
+ const boundCopyButton = renderSlot(
2575
+ copyButton,
2576
+ CopilotChatAssistantMessage.CopyButton,
2577
+ {
2578
+ onClick: async () => {
2579
+ if (message.content) {
2580
+ try {
2581
+ await navigator.clipboard.writeText(message.content);
2582
+ } catch (err) {
2583
+ console.error("Failed to copy message:", err);
2584
+ }
2585
+ }
2586
+ }
2587
+ }
2588
+ );
2589
+ const boundThumbsUpButton = renderSlot(
2590
+ thumbsUpButton,
2591
+ CopilotChatAssistantMessage.ThumbsUpButton,
2592
+ {
2593
+ onClick: onThumbsUp
2594
+ }
2595
+ );
2596
+ const boundThumbsDownButton = renderSlot(
2597
+ thumbsDownButton,
2598
+ CopilotChatAssistantMessage.ThumbsDownButton,
2599
+ {
2600
+ onClick: onThumbsDown
2601
+ }
2602
+ );
2603
+ const boundReadAloudButton = renderSlot(
2604
+ readAloudButton,
2605
+ CopilotChatAssistantMessage.ReadAloudButton,
2606
+ {
2607
+ onClick: onReadAloud
2608
+ }
2609
+ );
2610
+ const boundRegenerateButton = renderSlot(
2611
+ regenerateButton,
2612
+ CopilotChatAssistantMessage.RegenerateButton,
2613
+ {
2614
+ onClick: onRegenerate
2615
+ }
2616
+ );
2617
+ const boundToolbar = renderSlot(
2618
+ toolbar,
2619
+ CopilotChatAssistantMessage.Toolbar,
2620
+ {
2621
+ children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1", children: [
2622
+ boundCopyButton,
2623
+ (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
2624
+ (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
2625
+ (onReadAloud || readAloudButton) && boundReadAloudButton,
2626
+ (onRegenerate || regenerateButton) && boundRegenerateButton,
2627
+ additionalToolbarItems
2628
+ ] })
2629
+ }
2630
+ );
2631
+ const boundToolCallsView = renderSlot(
2632
+ toolCallsView,
2633
+ CopilotChatToolCallsView_default,
2634
+ {
2635
+ message,
2636
+ messages
2637
+ }
2638
+ );
2639
+ const hasContent = !!(message.content && message.content.trim().length > 0);
2640
+ const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
2641
+ const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
2642
+ if (children) {
2643
+ return /* @__PURE__ */ jsx13(Fragment3, { children: children({
2644
+ markdownRenderer: boundMarkdownRenderer,
2645
+ toolbar: boundToolbar,
2646
+ toolCallsView: boundToolCallsView,
2647
+ copyButton: boundCopyButton,
2648
+ thumbsUpButton: boundThumbsUpButton,
2649
+ thumbsDownButton: boundThumbsDownButton,
2650
+ readAloudButton: boundReadAloudButton,
2651
+ regenerateButton: boundRegenerateButton,
2652
+ message,
2653
+ messages,
2654
+ isRunning,
2655
+ onThumbsUp,
2656
+ onThumbsDown,
2657
+ onReadAloud,
2658
+ onRegenerate,
2659
+ additionalToolbarItems,
2660
+ toolbarVisible: shouldShowToolbar
2661
+ }) });
2662
+ }
2663
+ return /* @__PURE__ */ jsxs5(
2664
+ "div",
2665
+ {
2666
+ className: twMerge4(
2667
+ "prose max-w-full break-words dark:prose-invert",
2668
+ className
2669
+ ),
2670
+ ...props,
2671
+ "data-message-id": message.id,
2672
+ children: [
2673
+ boundMarkdownRenderer,
2674
+ boundToolCallsView,
2675
+ shouldShowToolbar && boundToolbar
2676
+ ]
2677
+ }
2678
+ );
2679
+ }
2680
+ ((CopilotChatAssistantMessage2) => {
2681
+ CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ jsx13(Streamdown, { className, ...props, children: content ?? "" });
2682
+ CopilotChatAssistantMessage2.Toolbar = ({
2683
+ className,
2684
+ ...props
2685
+ }) => /* @__PURE__ */ jsx13(
2686
+ "div",
2687
+ {
2688
+ className: twMerge4(
2689
+ "w-full bg-transparent flex items-center -ml-[5px] -mt-[0px]",
2690
+ className
2691
+ ),
2692
+ ...props
2693
+ }
2694
+ );
2695
+ CopilotChatAssistantMessage2.ToolbarButton = ({ title, children, ...props }) => {
2696
+ return /* @__PURE__ */ jsxs5(Tooltip, { children: [
2697
+ /* @__PURE__ */ jsx13(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx13(
2698
+ Button,
2699
+ {
2700
+ type: "button",
2701
+ variant: "assistantMessageToolbarButton",
2702
+ "aria-label": title,
2703
+ ...props,
2704
+ children
2705
+ }
2706
+ ) }),
2707
+ /* @__PURE__ */ jsx13(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx13("p", { children: title }) })
2708
+ ] });
2709
+ };
2710
+ CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
2711
+ const config = useCopilotChatConfiguration();
2712
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2713
+ const [copied, setCopied] = useState6(false);
2714
+ const handleClick = (event) => {
2715
+ setCopied(true);
2716
+ setTimeout(() => setCopied(false), 2e3);
2717
+ if (onClick) {
2718
+ onClick(event);
2719
+ }
2720
+ };
2721
+ return /* @__PURE__ */ jsx13(
2722
+ CopilotChatAssistantMessage2.ToolbarButton,
2723
+ {
2724
+ title: title || labels.assistantMessageToolbarCopyMessageLabel,
2725
+ onClick: handleClick,
2726
+ className,
2727
+ ...props,
2728
+ children: copied ? /* @__PURE__ */ jsx13(Check2, { className: "size-[18px]" }) : /* @__PURE__ */ jsx13(Copy, { className: "size-[18px]" })
2729
+ }
2730
+ );
2731
+ };
2732
+ CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
2733
+ const config = useCopilotChatConfiguration();
2734
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2735
+ return /* @__PURE__ */ jsx13(
2736
+ CopilotChatAssistantMessage2.ToolbarButton,
2737
+ {
2738
+ title: title || labels.assistantMessageToolbarThumbsUpLabel,
2739
+ ...props,
2740
+ children: /* @__PURE__ */ jsx13(ThumbsUp, { className: "size-[18px]" })
2741
+ }
2742
+ );
2743
+ };
2744
+ CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
2745
+ const config = useCopilotChatConfiguration();
2746
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2747
+ return /* @__PURE__ */ jsx13(
2748
+ CopilotChatAssistantMessage2.ToolbarButton,
2749
+ {
2750
+ title: title || labels.assistantMessageToolbarThumbsDownLabel,
2751
+ ...props,
2752
+ children: /* @__PURE__ */ jsx13(ThumbsDown, { className: "size-[18px]" })
2753
+ }
2754
+ );
2755
+ };
2756
+ CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
2757
+ const config = useCopilotChatConfiguration();
2758
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2759
+ return /* @__PURE__ */ jsx13(
2760
+ CopilotChatAssistantMessage2.ToolbarButton,
2761
+ {
2762
+ title: title || labels.assistantMessageToolbarReadAloudLabel,
2763
+ ...props,
2764
+ children: /* @__PURE__ */ jsx13(Volume2, { className: "size-[20px]" })
2765
+ }
2766
+ );
2767
+ };
2768
+ CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
2769
+ const config = useCopilotChatConfiguration();
2770
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2771
+ return /* @__PURE__ */ jsx13(
2772
+ CopilotChatAssistantMessage2.ToolbarButton,
2773
+ {
2774
+ title: title || labels.assistantMessageToolbarRegenerateLabel,
2775
+ ...props,
2776
+ children: /* @__PURE__ */ jsx13(RefreshCw, { className: "size-[18px]" })
2777
+ }
2778
+ );
2779
+ };
2780
+ })(CopilotChatAssistantMessage || (CopilotChatAssistantMessage = {}));
2781
+ CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistantMessage.MarkdownRenderer";
2782
+ CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
2783
+ CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
2784
+ CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
2785
+ CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
2786
+ CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
2787
+ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
2788
+ var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
2789
+
2790
+ // src/components/chat/CopilotChatUserMessage.tsx
2791
+ import { useMemo as useMemo7, useState as useState7 } from "react";
2792
+ import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
2793
+ import { twMerge as twMerge5 } from "tailwind-merge";
2794
+ import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
2795
+ function flattenUserMessageContent(content) {
2796
+ if (!content) {
2797
+ return "";
2798
+ }
2799
+ if (typeof content === "string") {
2800
+ return content;
2801
+ }
2802
+ return content.map((part) => {
2803
+ if (part && typeof part === "object" && "type" in part && part.type === "text" && typeof part.text === "string") {
2804
+ return part.text;
2805
+ }
2806
+ return "";
2807
+ }).filter((text) => text.length > 0).join("\n");
2808
+ }
2809
+ function CopilotChatUserMessage({
2810
+ message,
2811
+ onEditMessage,
2812
+ branchIndex,
2813
+ numberOfBranches,
2814
+ onSwitchToBranch,
2815
+ additionalToolbarItems,
2816
+ messageRenderer,
2817
+ toolbar,
2818
+ copyButton,
2819
+ editButton,
2820
+ branchNavigation,
2821
+ children,
2822
+ className,
2823
+ ...props
2824
+ }) {
2825
+ const flattenedContent = useMemo7(
2826
+ () => flattenUserMessageContent(message.content),
2827
+ [message.content]
2828
+ );
2829
+ const BoundMessageRenderer = renderSlot(
2830
+ messageRenderer,
2831
+ CopilotChatUserMessage.MessageRenderer,
2832
+ {
2833
+ content: flattenedContent
2834
+ }
2835
+ );
2836
+ const BoundCopyButton = renderSlot(
2837
+ copyButton,
2838
+ CopilotChatUserMessage.CopyButton,
2839
+ {
2840
+ onClick: async () => {
2841
+ if (flattenedContent) {
2842
+ try {
2843
+ await navigator.clipboard.writeText(flattenedContent);
2844
+ } catch (err) {
2845
+ console.error("Failed to copy message:", err);
2846
+ }
2847
+ }
2848
+ }
2849
+ }
2850
+ );
2851
+ const BoundEditButton = renderSlot(
2852
+ editButton,
2853
+ CopilotChatUserMessage.EditButton,
2854
+ {
2855
+ onClick: () => onEditMessage?.({ message })
2856
+ }
2857
+ );
2858
+ const BoundBranchNavigation = renderSlot(
2859
+ branchNavigation,
2860
+ CopilotChatUserMessage.BranchNavigation,
2861
+ {
2862
+ currentBranch: branchIndex,
2863
+ numberOfBranches,
2864
+ onSwitchToBranch,
2865
+ message
2866
+ }
2867
+ );
2868
+ const showBranchNavigation = numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
2869
+ const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
2870
+ children: /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-1 justify-end", children: [
2871
+ additionalToolbarItems,
2872
+ BoundCopyButton,
2873
+ onEditMessage && BoundEditButton,
2874
+ showBranchNavigation && BoundBranchNavigation
2875
+ ] })
2876
+ });
2877
+ if (children) {
2878
+ return /* @__PURE__ */ jsx14(Fragment4, { children: children({
2879
+ messageRenderer: BoundMessageRenderer,
2880
+ toolbar: BoundToolbar,
2881
+ copyButton: BoundCopyButton,
2882
+ editButton: BoundEditButton,
2883
+ branchNavigation: BoundBranchNavigation,
2884
+ message,
2885
+ branchIndex,
2886
+ numberOfBranches,
2887
+ additionalToolbarItems
2888
+ }) });
2889
+ }
2890
+ return /* @__PURE__ */ jsxs6(
2891
+ "div",
2892
+ {
2893
+ className: twMerge5("flex flex-col items-end group pt-10", className),
2894
+ "data-message-id": message.id,
2895
+ ...props,
2896
+ children: [
2897
+ BoundMessageRenderer,
2898
+ BoundToolbar
2899
+ ]
2900
+ }
2901
+ );
2902
+ }
2903
+ ((CopilotChatUserMessage2) => {
2904
+ CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */ jsx14(
2905
+ "div",
2906
+ {
2907
+ className: twMerge5("flex flex-col items-end group", className),
2908
+ ...props,
2909
+ children
2910
+ }
2911
+ );
2912
+ CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ jsx14(
2913
+ "div",
2914
+ {
2915
+ className: twMerge5(
2916
+ "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",
2917
+ className
2918
+ ),
2919
+ children: content
2920
+ }
2921
+ );
2922
+ CopilotChatUserMessage2.Toolbar = ({
2923
+ className,
2924
+ ...props
2925
+ }) => /* @__PURE__ */ jsx14(
2926
+ "div",
2927
+ {
2928
+ className: twMerge5(
2929
+ "w-full bg-transparent flex items-center justify-end -mr-[5px] mt-[4px] invisible group-hover:visible",
2930
+ className
2931
+ ),
2932
+ ...props
2933
+ }
2934
+ );
2935
+ CopilotChatUserMessage2.ToolbarButton = ({ title, children, className, ...props }) => {
2936
+ return /* @__PURE__ */ jsxs6(Tooltip, { children: [
2937
+ /* @__PURE__ */ jsx14(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx14(
2938
+ Button,
2939
+ {
2940
+ type: "button",
2941
+ variant: "assistantMessageToolbarButton",
2942
+ "aria-label": title,
2943
+ className: twMerge5(className),
2944
+ ...props,
2945
+ children
2946
+ }
2947
+ ) }),
2948
+ /* @__PURE__ */ jsx14(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx14("p", { children: title }) })
2949
+ ] });
2950
+ };
2951
+ CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
2952
+ const config = useCopilotChatConfiguration();
2953
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2954
+ const [copied, setCopied] = useState7(false);
2955
+ const handleClick = (event) => {
2956
+ setCopied(true);
2957
+ setTimeout(() => setCopied(false), 2e3);
2958
+ if (onClick) {
2959
+ onClick(event);
2960
+ }
2961
+ };
2962
+ return /* @__PURE__ */ jsx14(
2963
+ CopilotChatUserMessage2.ToolbarButton,
2964
+ {
2965
+ title: title || labels.userMessageToolbarCopyMessageLabel,
2966
+ onClick: handleClick,
2967
+ className,
2968
+ ...props,
2969
+ children: copied ? /* @__PURE__ */ jsx14(Check3, { className: "size-[18px]" }) : /* @__PURE__ */ jsx14(Copy2, { className: "size-[18px]" })
2970
+ }
2971
+ );
2972
+ };
2973
+ CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
2974
+ const config = useCopilotChatConfiguration();
2975
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2976
+ return /* @__PURE__ */ jsx14(
2977
+ CopilotChatUserMessage2.ToolbarButton,
2978
+ {
2979
+ title: title || labels.userMessageToolbarEditMessageLabel,
2980
+ className,
2981
+ ...props,
2982
+ children: /* @__PURE__ */ jsx14(Edit, { className: "size-[18px]" })
2983
+ }
2984
+ );
2985
+ };
2986
+ CopilotChatUserMessage2.BranchNavigation = ({
2987
+ className,
2988
+ currentBranch = 0,
2989
+ numberOfBranches = 1,
2990
+ onSwitchToBranch,
2991
+ message,
2992
+ ...props
2993
+ }) => {
2994
+ if (!numberOfBranches || numberOfBranches <= 1 || !onSwitchToBranch) {
2995
+ return null;
2996
+ }
2997
+ const canGoPrev = currentBranch > 0;
2998
+ const canGoNext = currentBranch < numberOfBranches - 1;
2999
+ return /* @__PURE__ */ jsxs6("div", { className: twMerge5("flex items-center gap-1", className), ...props, children: [
3000
+ /* @__PURE__ */ jsx14(
3001
+ Button,
3002
+ {
3003
+ type: "button",
3004
+ variant: "assistantMessageToolbarButton",
3005
+ onClick: () => onSwitchToBranch?.({
3006
+ branchIndex: currentBranch - 1,
3007
+ numberOfBranches,
3008
+ message
3009
+ }),
3010
+ disabled: !canGoPrev,
3011
+ className: "h-6 w-6 p-0",
3012
+ children: /* @__PURE__ */ jsx14(ChevronLeft, { className: "size-[20px]" })
3013
+ }
3014
+ ),
3015
+ /* @__PURE__ */ jsxs6("span", { className: "text-sm text-muted-foreground px-0 font-medium", children: [
3016
+ currentBranch + 1,
3017
+ "/",
3018
+ numberOfBranches
3019
+ ] }),
3020
+ /* @__PURE__ */ jsx14(
3021
+ Button,
3022
+ {
3023
+ type: "button",
3024
+ variant: "assistantMessageToolbarButton",
3025
+ onClick: () => onSwitchToBranch?.({
3026
+ branchIndex: currentBranch + 1,
3027
+ numberOfBranches,
3028
+ message
3029
+ }),
3030
+ disabled: !canGoNext,
3031
+ className: "h-6 w-6 p-0",
3032
+ children: /* @__PURE__ */ jsx14(ChevronRight, { className: "size-[20px]" })
3033
+ }
3034
+ )
3035
+ ] });
3036
+ };
3037
+ })(CopilotChatUserMessage || (CopilotChatUserMessage = {}));
3038
+ CopilotChatUserMessage.Container.displayName = "CopilotChatUserMessage.Container";
3039
+ CopilotChatUserMessage.MessageRenderer.displayName = "CopilotChatUserMessage.MessageRenderer";
3040
+ CopilotChatUserMessage.Toolbar.displayName = "CopilotChatUserMessage.Toolbar";
3041
+ CopilotChatUserMessage.ToolbarButton.displayName = "CopilotChatUserMessage.ToolbarButton";
3042
+ CopilotChatUserMessage.CopyButton.displayName = "CopilotChatUserMessage.CopyButton";
3043
+ CopilotChatUserMessage.EditButton.displayName = "CopilotChatUserMessage.EditButton";
3044
+ CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.BranchNavigation";
3045
+ var CopilotChatUserMessage_default = CopilotChatUserMessage;
3046
+
3047
+ // src/components/chat/CopilotChatSuggestionPill.tsx
3048
+ import React9 from "react";
3049
+ import { Loader2 } from "lucide-react";
3050
+ import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
3051
+ 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";
3052
+ var labelClasses = "whitespace-nowrap font-medium leading-none";
3053
+ var CopilotChatSuggestionPill = React9.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
3054
+ const showIcon = !isLoading && icon;
3055
+ return /* @__PURE__ */ jsxs7(
3056
+ "button",
3057
+ {
3058
+ ref,
3059
+ "data-slot": "suggestion-pill",
3060
+ className: cn(baseClasses, className),
3061
+ type: type ?? "button",
3062
+ "aria-busy": isLoading || void 0,
3063
+ disabled: isLoading || props.disabled,
3064
+ ...props,
3065
+ children: [
3066
+ isLoading ? /* @__PURE__ */ jsx15("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsx15(Loader2, { className: "h-3.5 sm:h-4 w-3.5 sm:w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ jsx15("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: icon }),
3067
+ /* @__PURE__ */ jsx15("span", { className: labelClasses, children })
3068
+ ]
3069
+ }
3070
+ );
3071
+ });
3072
+ CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
3073
+ var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
3074
+
3075
+ // src/components/chat/CopilotChatSuggestionView.tsx
3076
+ import React10 from "react";
3077
+ import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
3078
+ var DefaultContainer = React10.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
3079
+ return /* @__PURE__ */ jsx16(
3080
+ "div",
3081
+ {
3082
+ ref,
3083
+ className: cn(
3084
+ "flex flex-wrap items-center gap-1.5 sm:gap-2 pl-0 pr-4 sm:px-0 pointer-events-none",
3085
+ className
3086
+ ),
3087
+ ...props
3088
+ }
3089
+ );
3090
+ });
3091
+ var CopilotChatSuggestionView = React10.forwardRef(function CopilotChatSuggestionView2({
3092
+ suggestions,
3093
+ onSelectSuggestion,
3094
+ loadingIndexes,
3095
+ container,
3096
+ suggestion: suggestionSlot,
3097
+ className,
3098
+ children,
3099
+ ...restProps
3100
+ }, ref) {
3101
+ const loadingSet = React10.useMemo(() => {
3102
+ if (!loadingIndexes || loadingIndexes.length === 0) {
3103
+ return /* @__PURE__ */ new Set();
3104
+ }
3105
+ return new Set(loadingIndexes);
3106
+ }, [loadingIndexes]);
3107
+ const ContainerElement = renderSlot(container, DefaultContainer, {
3108
+ ref,
3109
+ className,
3110
+ ...restProps
3111
+ });
3112
+ const suggestionElements = suggestions.map((suggestion, index) => {
3113
+ const isLoading = loadingSet.has(index) || suggestion.isLoading === true;
3114
+ const pill = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
3115
+ children: suggestion.title,
3116
+ isLoading,
3117
+ type: "button",
3118
+ onClick: () => onSelectSuggestion?.(suggestion, index)
3119
+ });
3120
+ return React10.cloneElement(pill, {
3121
+ key: `${suggestion.title}-${index}`
3122
+ });
3123
+ });
3124
+ const boundContainer = React10.cloneElement(
3125
+ ContainerElement,
3126
+ void 0,
3127
+ suggestionElements
3128
+ );
3129
+ if (typeof children === "function") {
3130
+ const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
3131
+ children: suggestions[0]?.title ?? "",
3132
+ isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
3133
+ type: "button"
3134
+ });
3135
+ return /* @__PURE__ */ jsx16(Fragment5, { children: children({
3136
+ container: boundContainer,
3137
+ suggestion: sampleSuggestion,
3138
+ suggestions,
3139
+ onSelectSuggestion,
3140
+ loadingIndexes,
3141
+ className,
3142
+ ...restProps
3143
+ }) });
3144
+ }
3145
+ if (children) {
3146
+ return /* @__PURE__ */ jsxs8(Fragment5, { children: [
3147
+ boundContainer,
3148
+ children
3149
+ ] });
3150
+ }
3151
+ return boundContainer;
3152
+ });
3153
+ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
3154
+ var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
3155
+
3156
+ // src/components/chat/CopilotChatMessageView.tsx
3157
+ import { twMerge as twMerge6 } from "tailwind-merge";
3158
+ import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
3159
+ function CopilotChatMessageView({
3160
+ messages = [],
3161
+ assistantMessage,
3162
+ userMessage,
3163
+ cursor,
3164
+ isRunning = false,
3165
+ children,
3166
+ className,
3167
+ ...props
3168
+ }) {
3169
+ const renderCustomMessage = useRenderCustomMessages();
3170
+ const renderActivityMessage = useRenderActivityMessage();
3171
+ const messageElements = messages.flatMap((message) => {
3172
+ const elements = [];
3173
+ if (renderCustomMessage) {
3174
+ elements.push(
3175
+ renderCustomMessage({
3176
+ message,
3177
+ position: "before"
3178
+ })
3179
+ );
3180
+ }
3181
+ if (message.role === "assistant") {
3182
+ elements.push(
3183
+ renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
3184
+ key: message.id,
3185
+ message,
3186
+ messages,
3187
+ isRunning
3188
+ })
3189
+ );
3190
+ } else if (message.role === "user") {
3191
+ elements.push(
3192
+ renderSlot(userMessage, CopilotChatUserMessage_default, {
3193
+ key: message.id,
3194
+ message
3195
+ })
3196
+ );
3197
+ } else if (message.role === "activity") {
3198
+ const renderedActivity = renderActivityMessage(message);
3199
+ if (renderedActivity) {
3200
+ elements.push(renderedActivity);
3201
+ }
3202
+ }
3203
+ if (renderCustomMessage) {
3204
+ elements.push(
3205
+ renderCustomMessage({
3206
+ message,
3207
+ position: "after"
3208
+ })
3209
+ );
3210
+ }
3211
+ return elements;
3212
+ }).filter(Boolean);
3213
+ if (children) {
3214
+ return children({ messageElements, messages, isRunning });
3215
+ }
3216
+ return /* @__PURE__ */ jsxs9("div", { className: twMerge6("flex flex-col", className), ...props, children: [
3217
+ messageElements,
3218
+ isRunning && renderSlot(cursor, CopilotChatMessageView.Cursor, {})
3219
+ ] });
3220
+ }
3221
+ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
3222
+ return /* @__PURE__ */ jsx17(
3223
+ "div",
3224
+ {
3225
+ className: twMerge6("w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1", className),
3226
+ ...props
3227
+ }
3228
+ );
3229
+ };
3230
+ var CopilotChatMessageView_default = CopilotChatMessageView;
3231
+
3232
+ // src/components/chat/CopilotChatView.tsx
3233
+ import React11, { useRef as useRef7, useState as useState9, useEffect as useEffect13 } from "react";
3234
+ import { twMerge as twMerge7 } from "tailwind-merge";
3235
+ import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
3236
+ import { ChevronDown } from "lucide-react";
3237
+
3238
+ // src/hooks/use-keyboard-height.tsx
3239
+ import { useState as useState8, useEffect as useEffect12 } from "react";
3240
+ function useKeyboardHeight() {
3241
+ const [keyboardState, setKeyboardState] = useState8({
3242
+ isKeyboardOpen: false,
3243
+ keyboardHeight: 0,
3244
+ availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
3245
+ viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
3246
+ });
3247
+ useEffect12(() => {
3248
+ if (typeof window === "undefined") {
3249
+ return;
3250
+ }
3251
+ const visualViewport = window.visualViewport;
3252
+ if (!visualViewport) {
3253
+ return;
3254
+ }
3255
+ const updateKeyboardState = () => {
3256
+ const layoutHeight = window.innerHeight;
3257
+ const visualHeight = visualViewport.height;
3258
+ const keyboardHeight = Math.max(0, layoutHeight - visualHeight);
3259
+ const isKeyboardOpen = keyboardHeight > 150;
3260
+ setKeyboardState({
3261
+ isKeyboardOpen,
3262
+ keyboardHeight,
3263
+ availableHeight: visualHeight,
3264
+ viewportHeight: layoutHeight
3265
+ });
3266
+ };
3267
+ updateKeyboardState();
3268
+ visualViewport.addEventListener("resize", updateKeyboardState);
3269
+ visualViewport.addEventListener("scroll", updateKeyboardState);
3270
+ return () => {
3271
+ visualViewport.removeEventListener("resize", updateKeyboardState);
3272
+ visualViewport.removeEventListener("scroll", updateKeyboardState);
3273
+ };
3274
+ }, []);
3275
+ return keyboardState;
3276
+ }
3277
+
3278
+ // src/components/chat/CopilotChatView.tsx
3279
+ import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
3280
+ function CopilotChatView({
3281
+ messageView,
3282
+ input,
3283
+ scrollView,
3284
+ scrollToBottomButton,
3285
+ feather,
3286
+ inputContainer,
3287
+ disclaimer,
3288
+ suggestionView,
3289
+ messages = [],
3290
+ autoScroll = true,
3291
+ inputProps,
3292
+ isRunning = false,
3293
+ suggestions,
3294
+ suggestionLoadingIndexes,
3295
+ onSelectSuggestion,
3296
+ children,
3297
+ className,
3298
+ ...props
3299
+ }) {
3300
+ const inputContainerRef = useRef7(null);
3301
+ const [inputContainerHeight, setInputContainerHeight] = useState9(0);
3302
+ const [isResizing, setIsResizing] = useState9(false);
3303
+ const resizeTimeoutRef = useRef7(null);
3304
+ const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
3305
+ useEffect13(() => {
3306
+ const element = inputContainerRef.current;
3307
+ if (!element) return;
3308
+ const resizeObserver = new ResizeObserver((entries) => {
3309
+ for (const entry of entries) {
3310
+ const newHeight = entry.contentRect.height;
3311
+ setInputContainerHeight((prevHeight) => {
3312
+ if (newHeight !== prevHeight) {
3313
+ setIsResizing(true);
3314
+ if (resizeTimeoutRef.current) {
3315
+ clearTimeout(resizeTimeoutRef.current);
3316
+ }
3317
+ resizeTimeoutRef.current = setTimeout(() => {
3318
+ setIsResizing(false);
3319
+ }, 250);
3320
+ return newHeight;
3321
+ }
3322
+ return prevHeight;
3323
+ });
3324
+ }
3325
+ });
3326
+ resizeObserver.observe(element);
3327
+ setInputContainerHeight(element.offsetHeight);
3328
+ return () => {
3329
+ resizeObserver.disconnect();
3330
+ if (resizeTimeoutRef.current) {
3331
+ clearTimeout(resizeTimeoutRef.current);
3332
+ }
3333
+ };
3334
+ }, []);
3335
+ const BoundMessageView = renderSlot(messageView, CopilotChatMessageView_default, {
3336
+ messages,
3337
+ isRunning
3338
+ });
3339
+ const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
3340
+ const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
3341
+ const BoundSuggestionView = hasSuggestions ? renderSlot(
3342
+ suggestionView,
3343
+ CopilotChatSuggestionView_default,
3344
+ {
3345
+ suggestions,
3346
+ loadingIndexes: suggestionLoadingIndexes,
3347
+ onSelectSuggestion,
3348
+ className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
3349
+ }
3350
+ ) : null;
3351
+ const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
3352
+ const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
3353
+ autoScroll,
3354
+ scrollToBottomButton,
3355
+ inputContainerHeight,
3356
+ isResizing,
3357
+ children: /* @__PURE__ */ jsx18("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ jsxs10("div", { className: "max-w-3xl mx-auto", children: [
3358
+ BoundMessageView,
3359
+ hasSuggestions ? /* @__PURE__ */ jsx18("div", { className: "pl-0 pr-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
3360
+ ] }) })
3361
+ });
3362
+ const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
3363
+ const BoundDisclaimer = renderSlot(disclaimer, CopilotChatView.Disclaimer, {});
3364
+ const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
3365
+ ref: inputContainerRef,
3366
+ keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
3367
+ children: /* @__PURE__ */ jsxs10(Fragment6, { children: [
3368
+ /* @__PURE__ */ jsx18("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 }),
3369
+ BoundDisclaimer
3370
+ ] })
3371
+ });
3372
+ if (children) {
3373
+ return children({
3374
+ messageView: BoundMessageView,
3375
+ input: BoundInput,
3376
+ scrollView: BoundScrollView,
3377
+ scrollToBottomButton: BoundScrollToBottomButton,
3378
+ feather: BoundFeather,
3379
+ inputContainer: BoundInputContainer,
3380
+ disclaimer: BoundDisclaimer,
3381
+ suggestionView: BoundSuggestionView ?? /* @__PURE__ */ jsx18(Fragment6, {})
3382
+ });
3383
+ }
3384
+ return /* @__PURE__ */ jsxs10("div", { className: twMerge7("relative h-full", className), ...props, children: [
3385
+ BoundScrollView,
3386
+ BoundFeather,
3387
+ BoundInputContainer
3388
+ ] });
3389
+ }
3390
+ ((CopilotChatView2) => {
3391
+ const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
3392
+ const { isAtBottom, scrollToBottom } = useStickToBottomContext();
3393
+ return /* @__PURE__ */ jsxs10(Fragment6, { children: [
3394
+ /* @__PURE__ */ jsx18(StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx18("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) }),
3395
+ !isAtBottom && !isResizing && /* @__PURE__ */ jsx18(
3396
+ "div",
3397
+ {
3398
+ className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
3399
+ style: {
3400
+ bottom: `${inputContainerHeight + 16}px`
3401
+ },
3402
+ children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
3403
+ onClick: () => scrollToBottom()
3404
+ })
3405
+ }
3406
+ )
3407
+ ] });
3408
+ };
3409
+ CopilotChatView2.ScrollView = ({
3410
+ children,
3411
+ autoScroll = true,
3412
+ scrollToBottomButton,
3413
+ inputContainerHeight = 0,
3414
+ isResizing = false,
3415
+ className,
3416
+ ...props
3417
+ }) => {
3418
+ const [hasMounted, setHasMounted] = useState9(false);
3419
+ const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
3420
+ const [showScrollButton, setShowScrollButton] = useState9(false);
3421
+ useEffect13(() => {
3422
+ setHasMounted(true);
3423
+ }, []);
3424
+ useEffect13(() => {
3425
+ if (autoScroll) return;
3426
+ const scrollElement = scrollRef.current;
3427
+ if (!scrollElement) return;
3428
+ const checkScroll = () => {
3429
+ const atBottom = scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight < 10;
3430
+ setShowScrollButton(!atBottom);
3431
+ };
3432
+ checkScroll();
3433
+ scrollElement.addEventListener("scroll", checkScroll);
3434
+ const resizeObserver = new ResizeObserver(checkScroll);
3435
+ resizeObserver.observe(scrollElement);
3436
+ return () => {
3437
+ scrollElement.removeEventListener("scroll", checkScroll);
3438
+ resizeObserver.disconnect();
3439
+ };
3440
+ }, [scrollRef, autoScroll]);
3441
+ if (!hasMounted) {
3442
+ return /* @__PURE__ */ jsx18("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx18("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) });
3443
+ }
3444
+ if (!autoScroll) {
3445
+ return /* @__PURE__ */ jsxs10(
3446
+ "div",
3447
+ {
3448
+ ref: scrollRef,
3449
+ className: cn(
3450
+ "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden relative",
3451
+ className
3452
+ ),
3453
+ ...props,
3454
+ children: [
3455
+ /* @__PURE__ */ jsx18("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }),
3456
+ showScrollButton && !isResizing && /* @__PURE__ */ jsx18(
3457
+ "div",
3458
+ {
3459
+ className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
3460
+ style: {
3461
+ bottom: `${inputContainerHeight + 16}px`
3462
+ },
3463
+ children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
3464
+ onClick: () => scrollToBottom()
3465
+ })
3466
+ }
3467
+ )
3468
+ ]
3469
+ }
3470
+ );
3471
+ }
3472
+ return /* @__PURE__ */ jsx18(
3473
+ StickToBottom,
3474
+ {
3475
+ className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
3476
+ resize: "smooth",
3477
+ initial: "smooth",
3478
+ ...props,
3479
+ children: /* @__PURE__ */ jsx18(
3480
+ ScrollContent,
3481
+ {
3482
+ scrollToBottomButton,
3483
+ inputContainerHeight,
3484
+ isResizing,
3485
+ children
3486
+ }
3487
+ )
3488
+ }
3489
+ );
3490
+ };
3491
+ CopilotChatView2.ScrollToBottomButton = ({
3492
+ className,
3493
+ ...props
3494
+ }) => /* @__PURE__ */ jsx18(
3495
+ Button,
3496
+ {
3497
+ variant: "outline",
3498
+ size: "sm",
3499
+ className: twMerge7(
3500
+ "rounded-full w-10 h-10 p-0 pointer-events-auto",
3501
+ "bg-white dark:bg-gray-900",
3502
+ "shadow-lg border border-gray-200 dark:border-gray-700",
3503
+ "hover:bg-gray-50 dark:hover:bg-gray-800",
3504
+ "flex items-center justify-center cursor-pointer",
3505
+ className
3506
+ ),
3507
+ ...props,
3508
+ children: /* @__PURE__ */ jsx18(ChevronDown, { className: "w-4 h-4 text-gray-600 dark:text-white" })
3509
+ }
3510
+ );
3511
+ CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */ jsx18(
3512
+ "div",
3513
+ {
3514
+ className: cn(
3515
+ "absolute bottom-0 left-0 right-4 h-24 pointer-events-none z-10 bg-gradient-to-t",
3516
+ "from-white via-white to-transparent",
3517
+ "dark:from-[rgb(33,33,33)] dark:via-[rgb(33,33,33)]",
3518
+ className
3519
+ ),
3520
+ style,
3521
+ ...props
3522
+ }
3523
+ );
3524
+ CopilotChatView2.InputContainer = React11.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ jsx18(
3525
+ "div",
3526
+ {
3527
+ ref,
3528
+ className: cn("absolute bottom-0 left-0 right-0 z-20 pointer-events-none", className),
3529
+ style: {
3530
+ // Adjust position when keyboard is open to keep input visible
3531
+ transform: keyboardHeight > 0 ? `translateY(-${keyboardHeight}px)` : void 0,
3532
+ transition: "transform 0.2s ease-out"
3533
+ },
3534
+ ...props,
3535
+ children
3536
+ }
3537
+ ));
3538
+ CopilotChatView2.InputContainer.displayName = "CopilotChatView.InputContainer";
3539
+ CopilotChatView2.Disclaimer = ({ className, ...props }) => {
3540
+ const config = useCopilotChatConfiguration();
3541
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
3542
+ return /* @__PURE__ */ jsx18(
3543
+ "div",
3544
+ {
3545
+ className: cn("text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto", className),
3546
+ ...props,
3547
+ children: labels.chatDisclaimerText
3548
+ }
3549
+ );
3550
+ };
3551
+ })(CopilotChatView || (CopilotChatView = {}));
3552
+ var CopilotChatView_default = CopilotChatView;
3553
+
3554
+ // src/components/chat/CopilotChat.tsx
3555
+ import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo8 } from "react";
3556
+ import { merge } from "ts-deepmerge";
3557
+ import { AGUIConnectNotImplementedError } from "@ag-ui/client";
3558
+ import { jsx as jsx19 } from "react/jsx-runtime";
3559
+ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
3560
+ const existingConfig = useCopilotChatConfiguration();
3561
+ const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;
3562
+ const resolvedThreadId = useMemo8(
3563
+ () => threadId ?? existingConfig?.threadId ?? randomUUID2(),
3564
+ [threadId, existingConfig?.threadId]
3565
+ );
3566
+ const { agent } = useAgent({ agentId: resolvedAgentId });
3567
+ const { copilotkit } = useCopilotKit();
3568
+ const { suggestions: autoSuggestions } = useSuggestions({ agentId: resolvedAgentId });
3569
+ const {
3570
+ inputProps: providedInputProps,
3571
+ messageView: providedMessageView,
3572
+ suggestionView: providedSuggestionView,
3573
+ ...restProps
3574
+ } = props;
3575
+ useEffect14(() => {
3576
+ const connect = async (agent2) => {
3577
+ try {
3578
+ await copilotkit.connectAgent({ agent: agent2 });
3579
+ } catch (error) {
3580
+ if (error instanceof AGUIConnectNotImplementedError) {
3581
+ } else {
3582
+ throw error;
3583
+ }
3584
+ }
3585
+ };
3586
+ if (agent) {
3587
+ agent.threadId = resolvedThreadId;
3588
+ connect(agent);
3589
+ }
3590
+ return () => {
3591
+ };
3592
+ }, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
3593
+ const onSubmitInput = useCallback7(
3594
+ async (value) => {
3595
+ agent?.addMessage({
3596
+ id: randomUUID2(),
3597
+ role: "user",
3598
+ content: value
3599
+ });
3600
+ if (agent) {
3601
+ try {
3602
+ await copilotkit.runAgent({ agent });
3603
+ } catch (error) {
3604
+ console.error("CopilotChat: runAgent failed", error);
3605
+ }
3606
+ }
3607
+ },
3608
+ [agent, copilotkit]
3609
+ );
3610
+ const handleSelectSuggestion = useCallback7(
3611
+ async (suggestion) => {
3612
+ if (!agent) {
3613
+ return;
3614
+ }
3615
+ agent.addMessage({
3616
+ id: randomUUID2(),
3617
+ role: "user",
3618
+ content: suggestion.message
3619
+ });
3620
+ try {
3621
+ await copilotkit.runAgent({ agent });
3622
+ } catch (error) {
3623
+ console.error("CopilotChat: runAgent failed after selecting suggestion", error);
3624
+ }
3625
+ },
3626
+ [agent, copilotkit]
3627
+ );
3628
+ const stopCurrentRun = useCallback7(() => {
3629
+ if (!agent) {
3630
+ return;
3631
+ }
3632
+ try {
3633
+ copilotkit.stopAgent({ agent });
3634
+ } catch (error) {
3635
+ console.error("CopilotChat: stopAgent failed", error);
3636
+ try {
3637
+ agent.abortRun();
3638
+ } catch (abortError) {
3639
+ console.error("CopilotChat: abortRun fallback failed", abortError);
3640
+ }
3641
+ }
3642
+ }, [agent, copilotkit]);
3643
+ const mergedProps = merge(
3644
+ {
3645
+ isRunning: agent?.isRunning ?? false,
3646
+ suggestions: autoSuggestions,
3647
+ onSelectSuggestion: handleSelectSuggestion,
3648
+ suggestionView: providedSuggestionView
3649
+ },
3650
+ {
3651
+ ...restProps,
3652
+ ...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
3653
+ }
3654
+ );
3655
+ const providedStopHandler = providedInputProps?.onStop;
3656
+ const hasMessages = (agent?.messages?.length ?? 0) > 0;
3657
+ const shouldAllowStop = (agent?.isRunning ?? false) && hasMessages;
3658
+ const effectiveStopHandler = shouldAllowStop ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
3659
+ const finalInputProps = {
3660
+ ...providedInputProps,
3661
+ onSubmitMessage: onSubmitInput,
3662
+ onStop: effectiveStopHandler,
3663
+ isRunning: agent?.isRunning ?? false
3664
+ };
3665
+ finalInputProps.mode = agent?.isRunning ? "processing" : finalInputProps.mode ?? "input";
3666
+ const finalProps = merge(mergedProps, {
3667
+ messages: agent?.messages ?? [],
3668
+ inputProps: finalInputProps
3669
+ });
3670
+ const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
3671
+ return /* @__PURE__ */ jsx19(
3672
+ CopilotChatConfigurationProvider,
3673
+ {
3674
+ agentId: resolvedAgentId,
3675
+ threadId: resolvedThreadId,
3676
+ labels,
3677
+ isModalDefaultOpen,
3678
+ children: RenderedChatView
3679
+ }
3680
+ );
3681
+ }
3682
+ ((CopilotChat2) => {
3683
+ CopilotChat2.View = CopilotChatView;
3684
+ })(CopilotChat || (CopilotChat = {}));
3685
+
3686
+ // src/components/chat/CopilotChatToggleButton.tsx
3687
+ import React12, { useState as useState10 } from "react";
3688
+ import { MessageCircle, X as X2 } from "lucide-react";
3689
+ import { jsx as jsx20, jsxs as jsxs11 } from "react/jsx-runtime";
3690
+ var DefaultOpenIcon = ({
3691
+ className,
3692
+ ...props
3693
+ }) => /* @__PURE__ */ jsx20(MessageCircle, { className: cn("h-6 w-6", className), strokeWidth: 1.75, fill: "currentColor", ...props });
3694
+ var DefaultCloseIcon = ({
3695
+ className,
3696
+ ...props
3697
+ }) => /* @__PURE__ */ jsx20(X2, { className: cn("h-6 w-6", className), strokeWidth: 1.75, ...props });
3698
+ DefaultOpenIcon.displayName = "CopilotChatToggleButton.OpenIcon";
3699
+ DefaultCloseIcon.displayName = "CopilotChatToggleButton.CloseIcon";
3700
+ var ICON_TRANSITION_STYLE = Object.freeze({
3701
+ transition: "opacity 120ms ease-out, transform 260ms cubic-bezier(0.22, 1, 0.36, 1)"
3702
+ });
3703
+ var ICON_WRAPPER_BASE = "pointer-events-none absolute inset-0 flex items-center justify-center will-change-transform";
3704
+ var BUTTON_BASE_CLASSES = cn(
3705
+ "fixed bottom-6 right-6 z-[1100] flex h-14 w-14 items-center justify-center",
3706
+ "rounded-full border border-primary bg-primary text-primary-foreground",
3707
+ "shadow-sm transition-all duration-200 ease-out",
3708
+ "hover:scale-[1.04] hover:shadow-md",
3709
+ "cursor-pointer",
3710
+ "active:scale-[0.96]",
3711
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
3712
+ "disabled:pointer-events-none disabled:opacity-60"
3713
+ );
3714
+ var CopilotChatToggleButton = React12.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
3715
+ const { onClick, type, disabled, ...restProps } = buttonProps;
3716
+ const configuration = useCopilotChatConfiguration();
3717
+ const labels = configuration?.labels ?? CopilotChatDefaultLabels;
3718
+ const [fallbackOpen, setFallbackOpen] = useState10(false);
3719
+ const isOpen = configuration?.isModalOpen ?? fallbackOpen;
3720
+ const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
3721
+ const handleClick = (event) => {
3722
+ if (disabled) {
3723
+ return;
3724
+ }
3725
+ if (onClick) {
3726
+ onClick(event);
3727
+ }
3728
+ if (event.defaultPrevented) {
3729
+ return;
3730
+ }
3731
+ const nextOpen = !isOpen;
3732
+ setModalOpen(nextOpen);
3733
+ };
3734
+ const renderedOpenIcon = renderSlot(
3735
+ openIcon,
3736
+ DefaultOpenIcon,
3737
+ {
3738
+ className: "h-6 w-6",
3739
+ "aria-hidden": true,
3740
+ focusable: false
3741
+ }
3742
+ );
3743
+ const renderedCloseIcon = renderSlot(
3744
+ closeIcon,
3745
+ DefaultCloseIcon,
3746
+ {
3747
+ className: "h-6 w-6",
3748
+ "aria-hidden": true,
3749
+ focusable: false
3750
+ }
3751
+ );
3752
+ const openIconElement = /* @__PURE__ */ jsx20(
3753
+ "span",
3754
+ {
3755
+ "aria-hidden": "true",
3756
+ "data-slot": "chat-toggle-button-open-icon",
3757
+ className: ICON_WRAPPER_BASE,
3758
+ style: {
3759
+ ...ICON_TRANSITION_STYLE,
3760
+ opacity: isOpen ? 0 : 1,
3761
+ transform: `scale(${isOpen ? 0.75 : 1}) rotate(${isOpen ? 90 : 0}deg)`
3762
+ },
3763
+ children: renderedOpenIcon
3764
+ }
3765
+ );
3766
+ const closeIconElement = /* @__PURE__ */ jsx20(
3767
+ "span",
3768
+ {
3769
+ "aria-hidden": "true",
3770
+ "data-slot": "chat-toggle-button-close-icon",
3771
+ className: ICON_WRAPPER_BASE,
3772
+ style: {
3773
+ ...ICON_TRANSITION_STYLE,
3774
+ opacity: isOpen ? 1 : 0,
3775
+ transform: `scale(${isOpen ? 1 : 0.75}) rotate(${isOpen ? 0 : -90}deg)`
3776
+ },
3777
+ children: renderedCloseIcon
3778
+ }
3779
+ );
3780
+ return /* @__PURE__ */ jsxs11(
3781
+ "button",
3782
+ {
3783
+ ref,
3784
+ type: type ?? "button",
3785
+ "data-slot": "chat-toggle-button",
3786
+ "data-state": isOpen ? "open" : "closed",
3787
+ className: cn(BUTTON_BASE_CLASSES, className),
3788
+ "aria-label": isOpen ? labels.chatToggleCloseLabel : labels.chatToggleOpenLabel,
3789
+ "aria-pressed": isOpen,
3790
+ disabled,
3791
+ onClick: handleClick,
3792
+ ...restProps,
3793
+ children: [
3794
+ openIconElement,
3795
+ closeIconElement
3796
+ ]
3797
+ }
3798
+ );
3799
+ });
3800
+ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
3801
+ var CopilotChatToggleButton_default = CopilotChatToggleButton;
3802
+
3803
+ // src/components/chat/CopilotSidebarView.tsx
3804
+ import { useEffect as useEffect15, useRef as useRef8, useState as useState11 } from "react";
3805
+
3806
+ // src/components/chat/CopilotModalHeader.tsx
3807
+ import { useCallback as useCallback8 } from "react";
3808
+ import { X as X3 } from "lucide-react";
3809
+ import { jsx as jsx21, jsxs as jsxs12 } from "react/jsx-runtime";
3810
+ function CopilotModalHeader({
3811
+ title,
3812
+ titleContent,
3813
+ closeButton,
3814
+ children,
3815
+ className,
3816
+ ...rest
3817
+ }) {
3818
+ const configuration = useCopilotChatConfiguration();
3819
+ const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
3820
+ const resolvedTitle = title ?? fallbackTitle;
3821
+ const handleClose = useCallback8(() => {
3822
+ configuration?.setModalOpen(false);
3823
+ }, [configuration]);
3824
+ const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
3825
+ children: resolvedTitle
3826
+ });
3827
+ const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, {
3828
+ onClick: handleClose
3829
+ });
3830
+ if (children) {
3831
+ return children({
3832
+ titleContent: BoundTitle,
3833
+ closeButton: BoundCloseButton,
3834
+ title: resolvedTitle,
3835
+ ...rest
3836
+ });
3837
+ }
3838
+ return /* @__PURE__ */ jsx21(
3839
+ "header",
3840
+ {
3841
+ "data-slot": "copilot-modal-header",
3842
+ className: cn(
3843
+ "flex items-center justify-between border-b border-border px-4 py-4",
3844
+ "bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",
3845
+ className
3846
+ ),
3847
+ ...rest,
3848
+ children: /* @__PURE__ */ jsxs12("div", { className: "flex w-full items-center gap-2", children: [
3849
+ /* @__PURE__ */ jsx21("div", { className: "flex-1", "aria-hidden": "true" }),
3850
+ /* @__PURE__ */ jsx21("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
3851
+ /* @__PURE__ */ jsx21("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
3852
+ ] })
3853
+ }
3854
+ );
3855
+ }
3856
+ CopilotModalHeader.displayName = "CopilotModalHeader";
3857
+ ((CopilotModalHeader2) => {
3858
+ CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */ jsx21(
3859
+ "div",
3860
+ {
3861
+ className: cn(
3862
+ "w-full text-base font-medium leading-none tracking-tight text-foreground",
3863
+ className
3864
+ ),
3865
+ ...props,
3866
+ children
3867
+ }
3868
+ );
3869
+ CopilotModalHeader2.CloseButton = ({
3870
+ className,
3871
+ ...props
3872
+ }) => /* @__PURE__ */ jsx21(
3873
+ "button",
3874
+ {
3875
+ type: "button",
3876
+ className: cn(
3877
+ "inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition cursor-pointer",
3878
+ "hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
3879
+ className
3880
+ ),
3881
+ "aria-label": "Close",
3882
+ ...props,
3883
+ children: /* @__PURE__ */ jsx21(X3, { className: "h-4 w-4", "aria-hidden": "true" })
3884
+ }
3885
+ );
3886
+ })(CopilotModalHeader || (CopilotModalHeader = {}));
3887
+ CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
3888
+ CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
3889
+
3890
+ // src/components/chat/CopilotSidebarView.tsx
3891
+ import { Fragment as Fragment7, jsx as jsx22, jsxs as jsxs13 } from "react/jsx-runtime";
3892
+ var DEFAULT_SIDEBAR_WIDTH = 480;
3893
+ var SIDEBAR_TRANSITION_MS = 260;
3894
+ function CopilotSidebarView({ header, width, ...props }) {
3895
+ const configuration = useCopilotChatConfiguration();
3896
+ const isSidebarOpen = configuration?.isModalOpen ?? false;
3897
+ const sidebarRef = useRef8(null);
3898
+ const [sidebarWidth, setSidebarWidth] = useState11(width ?? DEFAULT_SIDEBAR_WIDTH);
3899
+ const widthToCss = (w) => {
3900
+ return typeof w === "number" ? `${w}px` : w;
3901
+ };
3902
+ const widthToMargin = (w) => {
3903
+ if (typeof w === "number") {
3904
+ return `${w}px`;
3905
+ }
3906
+ return w;
3907
+ };
3908
+ useEffect15(() => {
3909
+ if (width !== void 0) {
3910
+ return;
3911
+ }
3912
+ if (typeof window === "undefined") {
3913
+ return;
3914
+ }
3915
+ const element = sidebarRef.current;
3916
+ if (!element) {
3917
+ return;
3918
+ }
3919
+ const updateWidth = () => {
3920
+ const rect = element.getBoundingClientRect();
3921
+ if (rect.width > 0) {
3922
+ setSidebarWidth(rect.width);
3923
+ }
3924
+ };
3925
+ updateWidth();
3926
+ if (typeof ResizeObserver !== "undefined") {
3927
+ const observer = new ResizeObserver(() => updateWidth());
3928
+ observer.observe(element);
3929
+ return () => observer.disconnect();
3930
+ }
3931
+ window.addEventListener("resize", updateWidth);
3932
+ return () => window.removeEventListener("resize", updateWidth);
3933
+ }, [width]);
3934
+ const headerElement = renderSlot(header, CopilotModalHeader, {});
3935
+ return /* @__PURE__ */ jsxs13(Fragment7, { children: [
3936
+ isSidebarOpen && /* @__PURE__ */ jsx22(
3937
+ "style",
3938
+ {
3939
+ dangerouslySetInnerHTML: {
3940
+ __html: `
3941
+ @media (min-width: 768px) {
3942
+ body {
3943
+ margin-inline-end: ${widthToMargin(sidebarWidth)};
3944
+ transition: margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease;
3945
+ }
3946
+ }`
3947
+ }
3948
+ }
3949
+ ),
3950
+ /* @__PURE__ */ jsx22(CopilotChatToggleButton_default, {}),
3951
+ /* @__PURE__ */ jsx22(
3952
+ "aside",
3953
+ {
3954
+ ref: sidebarRef,
3955
+ "data-copilot-sidebar": true,
3956
+ className: cn(
3957
+ "fixed right-0 top-0 z-[1200] flex",
3958
+ // Height with dvh fallback and safe area support
3959
+ "h-[100vh] h-[100dvh] max-h-screen",
3960
+ // Responsive width: full on mobile, custom on desktop
3961
+ "w-full",
3962
+ "border-l border-border bg-background text-foreground shadow-xl",
3963
+ "transition-transform duration-300 ease-out",
3964
+ isSidebarOpen ? "translate-x-0" : "translate-x-full pointer-events-none"
3965
+ ),
3966
+ style: {
3967
+ // Use CSS custom property for responsive width
3968
+ ["--sidebar-width"]: widthToCss(sidebarWidth),
3969
+ // Safe area insets for iOS
3970
+ paddingTop: "env(safe-area-inset-top)",
3971
+ paddingBottom: "env(safe-area-inset-bottom)"
3972
+ },
3973
+ "aria-hidden": !isSidebarOpen,
3974
+ "aria-label": "Copilot chat sidebar",
3975
+ role: "complementary",
3976
+ children: /* @__PURE__ */ jsxs13("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
3977
+ headerElement,
3978
+ /* @__PURE__ */ jsx22("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ jsx22(CopilotChatView_default, { ...props }) })
3979
+ ] })
3980
+ }
3981
+ )
3982
+ ] });
3983
+ }
3984
+ CopilotSidebarView.displayName = "CopilotSidebarView";
3985
+
3986
+ // src/components/chat/CopilotPopupView.tsx
3987
+ import { useEffect as useEffect16, useMemo as useMemo9, useRef as useRef9, useState as useState12 } from "react";
3988
+ import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
3989
+ var DEFAULT_POPUP_WIDTH = 420;
3990
+ var DEFAULT_POPUP_HEIGHT = 560;
3991
+ var dimensionToCss = (value, fallback) => {
3992
+ if (typeof value === "number" && Number.isFinite(value)) {
3993
+ return `${value}px`;
3994
+ }
3995
+ if (typeof value === "string" && value.trim().length > 0) {
3996
+ return value;
3997
+ }
3998
+ return `${fallback}px`;
3999
+ };
4000
+ function CopilotPopupView({
4001
+ header,
4002
+ width,
4003
+ height,
4004
+ clickOutsideToClose,
4005
+ className,
4006
+ ...restProps
4007
+ }) {
4008
+ const configuration = useCopilotChatConfiguration();
4009
+ const isPopupOpen = configuration?.isModalOpen ?? false;
4010
+ const setModalOpen = configuration?.setModalOpen;
4011
+ const labels = configuration?.labels ?? CopilotChatDefaultLabels;
4012
+ const containerRef = useRef9(null);
4013
+ const [isRendered, setIsRendered] = useState12(isPopupOpen);
4014
+ const [isAnimatingOut, setIsAnimatingOut] = useState12(false);
4015
+ useEffect16(() => {
4016
+ if (isPopupOpen) {
4017
+ setIsRendered(true);
4018
+ setIsAnimatingOut(false);
4019
+ return;
4020
+ }
4021
+ if (!isRendered) {
4022
+ return;
4023
+ }
4024
+ setIsAnimatingOut(true);
4025
+ const timeout = setTimeout(() => {
4026
+ setIsRendered(false);
4027
+ setIsAnimatingOut(false);
4028
+ }, 200);
4029
+ return () => clearTimeout(timeout);
4030
+ }, [isPopupOpen, isRendered]);
4031
+ useEffect16(() => {
4032
+ if (!isPopupOpen) {
4033
+ return;
4034
+ }
4035
+ if (typeof window === "undefined") {
4036
+ return;
4037
+ }
4038
+ const handleKeyDown = (event) => {
4039
+ if (event.key === "Escape") {
4040
+ event.preventDefault();
4041
+ setModalOpen?.(false);
4042
+ }
4043
+ };
4044
+ window.addEventListener("keydown", handleKeyDown);
4045
+ return () => window.removeEventListener("keydown", handleKeyDown);
4046
+ }, [isPopupOpen, setModalOpen]);
4047
+ useEffect16(() => {
4048
+ if (!isPopupOpen) {
4049
+ return;
4050
+ }
4051
+ const focusTimer = setTimeout(() => {
4052
+ containerRef.current?.focus({ preventScroll: true });
4053
+ }, 200);
4054
+ return () => clearTimeout(focusTimer);
4055
+ }, [isPopupOpen]);
4056
+ useEffect16(() => {
4057
+ if (!isPopupOpen || !clickOutsideToClose) {
4058
+ return;
4059
+ }
4060
+ if (typeof document === "undefined") {
4061
+ return;
4062
+ }
4063
+ const handlePointerDown = (event) => {
4064
+ const target = event.target;
4065
+ if (!target) {
4066
+ return;
4067
+ }
4068
+ const container = containerRef.current;
4069
+ if (container?.contains(target)) {
4070
+ return;
4071
+ }
4072
+ const toggleButton = document.querySelector("[data-slot='chat-toggle-button']");
4073
+ if (toggleButton && toggleButton.contains(target)) {
4074
+ return;
4075
+ }
4076
+ setModalOpen?.(false);
4077
+ };
4078
+ document.addEventListener("pointerdown", handlePointerDown);
4079
+ return () => document.removeEventListener("pointerdown", handlePointerDown);
4080
+ }, [isPopupOpen, clickOutsideToClose, setModalOpen]);
4081
+ const headerElement = useMemo9(() => renderSlot(header, CopilotModalHeader, {}), [header]);
4082
+ const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
4083
+ const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
4084
+ const popupStyle = useMemo9(
4085
+ () => ({
4086
+ "--copilot-popup-width": resolvedWidth,
4087
+ "--copilot-popup-height": resolvedHeight,
4088
+ "--copilot-popup-max-width": "calc(100vw - 3rem)",
4089
+ "--copilot-popup-max-height": "calc(100dvh - 7.5rem)",
4090
+ paddingTop: "env(safe-area-inset-top)",
4091
+ paddingBottom: "env(safe-area-inset-bottom)",
4092
+ paddingLeft: "env(safe-area-inset-left)",
4093
+ paddingRight: "env(safe-area-inset-right)"
4094
+ }),
4095
+ [resolvedHeight, resolvedWidth]
4096
+ );
4097
+ const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "pointer-events-auto translate-y-0 opacity-100 md:scale-100" : "pointer-events-none translate-y-4 opacity-0 md:translate-y-5 md:scale-[0.95]";
4098
+ const popupContent = isRendered ? /* @__PURE__ */ jsx23(
4099
+ "div",
4100
+ {
4101
+ className: cn(
4102
+ "fixed inset-0 z-[1200] flex max-w-full flex-col items-stretch",
4103
+ "md:inset-auto md:bottom-24 md:right-6 md:items-end md:gap-4"
4104
+ ),
4105
+ children: /* @__PURE__ */ jsxs14(
4106
+ "div",
4107
+ {
4108
+ ref: containerRef,
4109
+ tabIndex: -1,
4110
+ role: "dialog",
4111
+ "aria-label": labels.modalHeaderTitle,
4112
+ "data-copilot-popup": true,
4113
+ className: cn(
4114
+ "relative flex h-full w-full flex-col overflow-hidden bg-background text-foreground",
4115
+ "origin-bottom focus:outline-none transform-gpu transition-transform transition-opacity duration-200 ease-out",
4116
+ "md:transition-transform md:transition-opacity",
4117
+ "rounded-none border border-border/0 shadow-none ring-0",
4118
+ "md:h-[var(--copilot-popup-height)] md:w-[var(--copilot-popup-width)]",
4119
+ "md:max-h-[var(--copilot-popup-max-height)] md:max-w-[var(--copilot-popup-max-width)]",
4120
+ "md:origin-bottom-right md:rounded-2xl md:border-border md:shadow-xl md:ring-1 md:ring-border/40",
4121
+ popupAnimationClass
4122
+ ),
4123
+ style: popupStyle,
4124
+ children: [
4125
+ headerElement,
4126
+ /* @__PURE__ */ jsx23("div", { className: "flex-1 overflow-hidden", "data-popup-chat": true, children: /* @__PURE__ */ jsx23(
4127
+ CopilotChatView_default,
4128
+ {
4129
+ ...restProps,
4130
+ className: cn("h-full min-h-0", className)
4131
+ }
4132
+ ) })
4133
+ ]
4134
+ }
4135
+ )
4136
+ }
4137
+ ) : null;
4138
+ return /* @__PURE__ */ jsxs14(Fragment8, { children: [
4139
+ /* @__PURE__ */ jsx23(CopilotChatToggleButton_default, {}),
4140
+ popupContent
4141
+ ] });
4142
+ }
4143
+ CopilotPopupView.displayName = "CopilotPopupView";
4144
+
4145
+ // src/components/chat/CopilotSidebar.tsx
4146
+ import { useMemo as useMemo10 } from "react";
4147
+ import { jsx as jsx24 } from "react/jsx-runtime";
4148
+ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
4149
+ const SidebarViewOverride = useMemo10(() => {
4150
+ const Component = (viewProps) => {
4151
+ const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
4152
+ return /* @__PURE__ */ jsx24(
4153
+ CopilotSidebarView,
4154
+ {
4155
+ ...restProps,
4156
+ header: header ?? viewHeader,
4157
+ width: width ?? viewWidth
4158
+ }
4159
+ );
4160
+ };
4161
+ return Object.assign(Component, CopilotChatView_default);
4162
+ }, [header, width]);
4163
+ return /* @__PURE__ */ jsx24(
4164
+ CopilotChat,
4165
+ {
4166
+ ...chatProps,
4167
+ chatView: SidebarViewOverride,
4168
+ isModalDefaultOpen: defaultOpen
4169
+ }
4170
+ );
4171
+ }
4172
+ CopilotSidebar.displayName = "CopilotSidebar";
4173
+
4174
+ // src/components/chat/CopilotPopup.tsx
4175
+ import { useMemo as useMemo11 } from "react";
4176
+ import { jsx as jsx25 } from "react/jsx-runtime";
4177
+ function CopilotPopup({
4178
+ header,
4179
+ defaultOpen,
4180
+ width,
4181
+ height,
4182
+ clickOutsideToClose,
4183
+ ...chatProps
4184
+ }) {
4185
+ const PopupViewOverride = useMemo11(() => {
4186
+ const Component = (viewProps) => {
4187
+ const {
4188
+ header: viewHeader,
4189
+ width: viewWidth,
4190
+ height: viewHeight,
4191
+ clickOutsideToClose: viewClickOutsideToClose,
4192
+ ...restProps
4193
+ } = viewProps;
4194
+ return /* @__PURE__ */ jsx25(
4195
+ CopilotPopupView,
4196
+ {
4197
+ ...restProps,
4198
+ header: header ?? viewHeader,
4199
+ width: width ?? viewWidth,
4200
+ height: height ?? viewHeight,
4201
+ clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose
4202
+ }
4203
+ );
4204
+ };
4205
+ return Object.assign(Component, CopilotChatView_default);
4206
+ }, [clickOutsideToClose, header, height, width]);
4207
+ return /* @__PURE__ */ jsx25(
4208
+ CopilotChat,
4209
+ {
4210
+ ...chatProps,
4211
+ chatView: PopupViewOverride,
4212
+ isModalDefaultOpen: defaultOpen
4213
+ }
4214
+ );
4215
+ }
4216
+ CopilotPopup.displayName = "CopilotPopup";
4217
+
4218
+ // src/types/defineToolCallRenderer.ts
4219
+ import { z as z2 } from "zod";
4220
+ function defineToolCallRenderer(def) {
4221
+ const argsSchema = def.name === "*" && !def.args ? z2.any() : def.args;
4222
+ return {
4223
+ name: def.name,
4224
+ args: argsSchema,
4225
+ render: def.render,
4226
+ ...def.agentId ? { agentId: def.agentId } : {}
4227
+ };
4228
+ }
4229
+
4230
+ // src/components/WildcardToolCallRender.tsx
4231
+ import { useState as useState13 } from "react";
4232
+ import { jsx as jsx26, jsxs as jsxs15 } from "react/jsx-runtime";
4233
+ var WildcardToolCallRender = defineToolCallRenderer({
4234
+ name: "*",
4235
+ render: ({ args, result, name, status }) => {
4236
+ const [isExpanded, setIsExpanded] = useState13(false);
4237
+ const statusString = String(status);
4238
+ const isActive = statusString === "inProgress" || statusString === "executing";
4239
+ const isComplete = statusString === "complete";
4240
+ const statusStyles = isActive ? "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-400" : isComplete ? "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400" : "bg-zinc-100 text-zinc-800 dark:bg-zinc-700/40 dark:text-zinc-300";
4241
+ return /* @__PURE__ */ jsx26("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ jsxs15("div", { className: "rounded-xl border border-zinc-200/60 dark:border-zinc-800/60 bg-white/70 dark:bg-zinc-900/50 shadow-sm backdrop-blur p-4", children: [
4242
+ /* @__PURE__ */ jsxs15(
4243
+ "div",
4244
+ {
4245
+ className: "flex items-center justify-between gap-3 cursor-pointer",
4246
+ onClick: () => setIsExpanded(!isExpanded),
4247
+ children: [
4248
+ /* @__PURE__ */ jsxs15("div", { className: "flex items-center gap-2 min-w-0", children: [
4249
+ /* @__PURE__ */ jsx26(
4250
+ "svg",
4251
+ {
4252
+ className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
4253
+ fill: "none",
4254
+ viewBox: "0 0 24 24",
4255
+ strokeWidth: 2,
4256
+ stroke: "currentColor",
4257
+ children: /* @__PURE__ */ jsx26(
4258
+ "path",
4259
+ {
4260
+ strokeLinecap: "round",
4261
+ strokeLinejoin: "round",
4262
+ d: "M8.25 4.5l7.5 7.5-7.5 7.5"
4263
+ }
4264
+ )
4265
+ }
4266
+ ),
4267
+ /* @__PURE__ */ jsx26("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
4268
+ /* @__PURE__ */ jsx26("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
4269
+ ] }),
4270
+ /* @__PURE__ */ jsx26(
4271
+ "span",
4272
+ {
4273
+ className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
4274
+ children: String(status)
4275
+ }
4276
+ )
4277
+ ]
4278
+ }
4279
+ ),
4280
+ isExpanded && /* @__PURE__ */ jsxs15("div", { className: "mt-3 grid gap-4", children: [
4281
+ /* @__PURE__ */ jsxs15("div", { children: [
4282
+ /* @__PURE__ */ jsx26("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
4283
+ /* @__PURE__ */ jsx26("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: JSON.stringify(args ?? {}, null, 2) })
4284
+ ] }),
4285
+ result !== void 0 && /* @__PURE__ */ jsxs15("div", { children: [
4286
+ /* @__PURE__ */ jsx26("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
4287
+ /* @__PURE__ */ jsx26("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) })
4288
+ ] })
4289
+ ] })
4290
+ ] }) });
4291
+ }
4292
+ });
116
4293
  export {
117
4294
  AudioRecorderError,
118
4295
  CopilotChat,