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