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

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