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

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