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