@copilotkit/react-ui 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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 (395) hide show
  1. package/CHANGELOG.md +17415 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/dist/chunk-3W6J75HS.mjs +126 -0
  5. package/dist/chunk-3W6J75HS.mjs.map +1 -0
  6. package/dist/chunk-54JAUBUJ.mjs +26 -0
  7. package/dist/chunk-54JAUBUJ.mjs.map +1 -0
  8. package/dist/chunk-7OURDQZJ.mjs +133 -0
  9. package/dist/chunk-7OURDQZJ.mjs.map +1 -0
  10. package/dist/chunk-7PR2KJDO.mjs +222 -0
  11. package/dist/chunk-7PR2KJDO.mjs.map +1 -0
  12. package/dist/chunk-BH6PCAAL.mjs +81 -0
  13. package/dist/chunk-BH6PCAAL.mjs.map +1 -0
  14. package/dist/chunk-C3GSYRC3.mjs +118 -0
  15. package/dist/chunk-C3GSYRC3.mjs.map +1 -0
  16. package/dist/chunk-DBKRAOH7.mjs +34 -0
  17. package/dist/chunk-DBKRAOH7.mjs.map +1 -0
  18. package/dist/chunk-EFZPSZWO.mjs +1 -0
  19. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  20. package/dist/chunk-ELGRNEAO.mjs +32 -0
  21. package/dist/chunk-ELGRNEAO.mjs.map +1 -0
  22. package/dist/chunk-ELUJRANC.mjs +21 -0
  23. package/dist/chunk-ELUJRANC.mjs.map +1 -0
  24. package/dist/chunk-FFJHOZX6.mjs +202 -0
  25. package/dist/chunk-FFJHOZX6.mjs.map +1 -0
  26. package/dist/chunk-GDSZGYCE.mjs +32 -0
  27. package/dist/chunk-GDSZGYCE.mjs.map +1 -0
  28. package/dist/chunk-HIW7RXCD.mjs +184 -0
  29. package/dist/chunk-HIW7RXCD.mjs.map +1 -0
  30. package/dist/chunk-IEMQ2SQW.mjs +93 -0
  31. package/dist/chunk-IEMQ2SQW.mjs.map +1 -0
  32. package/dist/chunk-IHFR6PYG.mjs +116 -0
  33. package/dist/chunk-IHFR6PYG.mjs.map +1 -0
  34. package/dist/chunk-IK2BPURM.mjs +400 -0
  35. package/dist/chunk-IK2BPURM.mjs.map +1 -0
  36. package/dist/chunk-IU3WTXLQ.mjs +1 -0
  37. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  38. package/dist/chunk-JGMFJZMG.mjs +11 -0
  39. package/dist/chunk-JGMFJZMG.mjs.map +1 -0
  40. package/dist/chunk-JY2CSDKN.mjs +135 -0
  41. package/dist/chunk-JY2CSDKN.mjs.map +1 -0
  42. package/dist/chunk-JZ3RFQQ6.mjs +128 -0
  43. package/dist/chunk-JZ3RFQQ6.mjs.map +1 -0
  44. package/dist/chunk-KXE2JCUH.mjs +1 -0
  45. package/dist/chunk-KXE2JCUH.mjs.map +1 -0
  46. package/dist/chunk-LQEFRHRT.mjs +30 -0
  47. package/dist/chunk-LQEFRHRT.mjs.map +1 -0
  48. package/dist/chunk-MMVDU6DF.mjs +1 -0
  49. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  50. package/dist/chunk-MRXNTQOX.mjs +59 -0
  51. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  52. package/dist/chunk-NCIAFFQ2.mjs +82 -0
  53. package/dist/chunk-NCIAFFQ2.mjs.map +1 -0
  54. package/dist/chunk-NGJ32FAP.mjs +30 -0
  55. package/dist/chunk-NGJ32FAP.mjs.map +1 -0
  56. package/dist/chunk-NRA3CFEE.mjs +97 -0
  57. package/dist/chunk-NRA3CFEE.mjs.map +1 -0
  58. package/dist/chunk-O72ZB5V3.mjs +140 -0
  59. package/dist/chunk-O72ZB5V3.mjs.map +1 -0
  60. package/dist/chunk-PLHTVHUW.mjs +82 -0
  61. package/dist/chunk-PLHTVHUW.mjs.map +1 -0
  62. package/dist/chunk-Q5V6S67N.mjs +103 -0
  63. package/dist/chunk-Q5V6S67N.mjs.map +1 -0
  64. package/dist/chunk-QB3GUN2N.mjs +31 -0
  65. package/dist/chunk-QB3GUN2N.mjs.map +1 -0
  66. package/dist/chunk-QIOJXTIQ.mjs +64 -0
  67. package/dist/chunk-QIOJXTIQ.mjs.map +1 -0
  68. package/dist/chunk-QPQRLXN3.mjs +435 -0
  69. package/dist/chunk-QPQRLXN3.mjs.map +1 -0
  70. package/dist/chunk-RYUCX3ZK.mjs +32 -0
  71. package/dist/chunk-RYUCX3ZK.mjs.map +1 -0
  72. package/dist/chunk-SC6JRFAJ.mjs +1 -0
  73. package/dist/chunk-SC6JRFAJ.mjs.map +1 -0
  74. package/dist/chunk-T26KLXLH.mjs +1 -0
  75. package/dist/chunk-T26KLXLH.mjs.map +1 -0
  76. package/dist/chunk-UFN2VWSR.mjs +25 -0
  77. package/dist/chunk-UFN2VWSR.mjs.map +1 -0
  78. package/dist/chunk-V7W6IM2V.mjs +1 -0
  79. package/dist/chunk-V7W6IM2V.mjs.map +1 -0
  80. package/dist/chunk-WB3YULQ4.mjs +1 -0
  81. package/dist/chunk-WB3YULQ4.mjs.map +1 -0
  82. package/dist/chunk-XWG3L6QC.mjs +258 -0
  83. package/dist/chunk-XWG3L6QC.mjs.map +1 -0
  84. package/dist/chunk-Y4FKRAKJ.mjs +12 -0
  85. package/dist/chunk-Y4FKRAKJ.mjs.map +1 -0
  86. package/dist/components/chat/Button.d.ts +9 -0
  87. package/dist/components/chat/Button.js +71 -0
  88. package/dist/components/chat/Button.js.map +1 -0
  89. package/dist/components/chat/Button.mjs +10 -0
  90. package/dist/components/chat/Button.mjs.map +1 -0
  91. package/dist/components/chat/Chat.d.ts +204 -0
  92. package/dist/components/chat/Chat.js +2270 -0
  93. package/dist/components/chat/Chat.js.map +1 -0
  94. package/dist/components/chat/Chat.mjs +29 -0
  95. package/dist/components/chat/Chat.mjs.map +1 -0
  96. package/dist/components/chat/ChatContext.d.ts +145 -0
  97. package/dist/components/chat/ChatContext.js +329 -0
  98. package/dist/components/chat/ChatContext.js.map +1 -0
  99. package/dist/components/chat/ChatContext.mjs +13 -0
  100. package/dist/components/chat/ChatContext.mjs.map +1 -0
  101. package/dist/components/chat/CodeBlock.d.ts +14 -0
  102. package/dist/components/chat/CodeBlock.js +510 -0
  103. package/dist/components/chat/CodeBlock.js.map +1 -0
  104. package/dist/components/chat/CodeBlock.mjs +14 -0
  105. package/dist/components/chat/CodeBlock.mjs.map +1 -0
  106. package/dist/components/chat/Header.d.ts +9 -0
  107. package/dist/components/chat/Header.js +582 -0
  108. package/dist/components/chat/Header.js.map +1 -0
  109. package/dist/components/chat/Header.mjs +17 -0
  110. package/dist/components/chat/Header.mjs.map +1 -0
  111. package/dist/components/chat/Icons.d.ts +20 -0
  112. package/dist/components/chat/Icons.js +297 -0
  113. package/dist/components/chat/Icons.js.map +1 -0
  114. package/dist/components/chat/Icons.mjs +38 -0
  115. package/dist/components/chat/Icons.mjs.map +1 -0
  116. package/dist/components/chat/ImageUploadQueue.d.ts +13 -0
  117. package/dist/components/chat/ImageUploadQueue.js +106 -0
  118. package/dist/components/chat/ImageUploadQueue.js.map +1 -0
  119. package/dist/components/chat/ImageUploadQueue.mjs +8 -0
  120. package/dist/components/chat/ImageUploadQueue.mjs.map +1 -0
  121. package/dist/components/chat/Input.d.ts +9 -0
  122. package/dist/components/chat/Input.js +396 -0
  123. package/dist/components/chat/Input.js.map +1 -0
  124. package/dist/components/chat/Input.mjs +14 -0
  125. package/dist/components/chat/Input.mjs.map +1 -0
  126. package/dist/components/chat/Markdown.d.ts +10 -0
  127. package/dist/components/chat/Markdown.js +652 -0
  128. package/dist/components/chat/Markdown.js.map +1 -0
  129. package/dist/components/chat/Markdown.mjs +11 -0
  130. package/dist/components/chat/Markdown.mjs.map +1 -0
  131. package/dist/components/chat/Messages.d.ts +13 -0
  132. package/dist/components/chat/Messages.js +1195 -0
  133. package/dist/components/chat/Messages.js.map +1 -0
  134. package/dist/components/chat/Messages.mjs +20 -0
  135. package/dist/components/chat/Messages.mjs.map +1 -0
  136. package/dist/components/chat/Modal.d.ts +51 -0
  137. package/dist/components/chat/Modal.js +3075 -0
  138. package/dist/components/chat/Modal.js.map +1 -0
  139. package/dist/components/chat/Modal.mjs +38 -0
  140. package/dist/components/chat/Modal.mjs.map +1 -0
  141. package/dist/components/chat/Popup.d.ts +13 -0
  142. package/dist/components/chat/Popup.js +3086 -0
  143. package/dist/components/chat/Popup.js.map +1 -0
  144. package/dist/components/chat/Popup.mjs +39 -0
  145. package/dist/components/chat/Popup.mjs.map +1 -0
  146. package/dist/components/chat/PoweredByTag.d.ts +7 -0
  147. package/dist/components/chat/PoweredByTag.js +61 -0
  148. package/dist/components/chat/PoweredByTag.js.map +1 -0
  149. package/dist/components/chat/PoweredByTag.mjs +9 -0
  150. package/dist/components/chat/PoweredByTag.mjs.map +1 -0
  151. package/dist/components/chat/Sidebar.d.ts +13 -0
  152. package/dist/components/chat/Sidebar.js +3095 -0
  153. package/dist/components/chat/Sidebar.js.map +1 -0
  154. package/dist/components/chat/Sidebar.mjs +39 -0
  155. package/dist/components/chat/Sidebar.mjs.map +1 -0
  156. package/dist/components/chat/Suggestion.d.ts +12 -0
  157. package/dist/components/chat/Suggestion.js +56 -0
  158. package/dist/components/chat/Suggestion.js.map +1 -0
  159. package/dist/components/chat/Suggestion.mjs +9 -0
  160. package/dist/components/chat/Suggestion.mjs.map +1 -0
  161. package/dist/components/chat/Suggestions.d.ts +9 -0
  162. package/dist/components/chat/Suggestions.js +81 -0
  163. package/dist/components/chat/Suggestions.js.map +1 -0
  164. package/dist/components/chat/Suggestions.mjs +10 -0
  165. package/dist/components/chat/Suggestions.mjs.map +1 -0
  166. package/dist/components/chat/Textarea.d.ts +15 -0
  167. package/dist/components/chat/Textarea.js +84 -0
  168. package/dist/components/chat/Textarea.js.map +1 -0
  169. package/dist/components/chat/Textarea.mjs +8 -0
  170. package/dist/components/chat/Textarea.mjs.map +1 -0
  171. package/dist/components/chat/Window.d.ts +9 -0
  172. package/dist/components/chat/Window.js +164 -0
  173. package/dist/components/chat/Window.js.map +1 -0
  174. package/dist/components/chat/Window.mjs +10 -0
  175. package/dist/components/chat/Window.mjs.map +1 -0
  176. package/dist/components/chat/index.d.ts +18 -0
  177. package/dist/components/chat/index.js +3122 -0
  178. package/dist/components/chat/index.js.map +1 -0
  179. package/dist/components/chat/index.mjs +69 -0
  180. package/dist/components/chat/index.mjs.map +1 -0
  181. package/dist/components/chat/messages/AssistantMessage.d.ts +9 -0
  182. package/dist/components/chat/messages/AssistantMessage.js +775 -0
  183. package/dist/components/chat/messages/AssistantMessage.js.map +1 -0
  184. package/dist/components/chat/messages/AssistantMessage.mjs +13 -0
  185. package/dist/components/chat/messages/AssistantMessage.mjs.map +1 -0
  186. package/dist/components/chat/messages/ErrorMessage.d.ts +9 -0
  187. package/dist/components/chat/messages/ErrorMessage.js +722 -0
  188. package/dist/components/chat/messages/ErrorMessage.js.map +1 -0
  189. package/dist/components/chat/messages/ErrorMessage.mjs +66 -0
  190. package/dist/components/chat/messages/ErrorMessage.mjs.map +1 -0
  191. package/dist/components/chat/messages/ImageRenderer.d.ts +12 -0
  192. package/dist/components/chat/messages/ImageRenderer.js +58 -0
  193. package/dist/components/chat/messages/ImageRenderer.js.map +1 -0
  194. package/dist/components/chat/messages/ImageRenderer.mjs +8 -0
  195. package/dist/components/chat/messages/ImageRenderer.mjs.map +1 -0
  196. package/dist/components/chat/messages/LegacyRenderMessage.d.ts +28 -0
  197. package/dist/components/chat/messages/LegacyRenderMessage.js +1023 -0
  198. package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -0
  199. package/dist/components/chat/messages/LegacyRenderMessage.mjs +17 -0
  200. package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +1 -0
  201. package/dist/components/chat/messages/RenderMessage.d.ts +9 -0
  202. package/dist/components/chat/messages/RenderMessage.js +898 -0
  203. package/dist/components/chat/messages/RenderMessage.js.map +1 -0
  204. package/dist/components/chat/messages/RenderMessage.mjs +16 -0
  205. package/dist/components/chat/messages/RenderMessage.mjs.map +1 -0
  206. package/dist/components/chat/messages/UserMessage.d.ts +9 -0
  207. package/dist/components/chat/messages/UserMessage.js +56 -0
  208. package/dist/components/chat/messages/UserMessage.js.map +1 -0
  209. package/dist/components/chat/messages/UserMessage.mjs +8 -0
  210. package/dist/components/chat/messages/UserMessage.mjs.map +1 -0
  211. package/dist/components/chat/props.d.ts +298 -0
  212. package/dist/components/chat/props.js +19 -0
  213. package/dist/components/chat/props.js.map +1 -0
  214. package/dist/components/chat/props.mjs +2 -0
  215. package/dist/components/chat/props.mjs.map +1 -0
  216. package/dist/components/dev-console/console.d.ts +11 -0
  217. package/dist/components/dev-console/console.js +537 -0
  218. package/dist/components/dev-console/console.js.map +1 -0
  219. package/dist/components/dev-console/console.mjs +17 -0
  220. package/dist/components/dev-console/console.mjs.map +1 -0
  221. package/dist/components/dev-console/icons.d.ts +9 -0
  222. package/dist/components/dev-console/icons.js +131 -0
  223. package/dist/components/dev-console/icons.js.map +1 -0
  224. package/dist/components/dev-console/icons.mjs +16 -0
  225. package/dist/components/dev-console/icons.mjs.map +1 -0
  226. package/dist/components/dev-console/index.d.ts +3 -0
  227. package/dist/components/dev-console/index.js +537 -0
  228. package/dist/components/dev-console/index.js.map +1 -0
  229. package/dist/components/dev-console/index.mjs +18 -0
  230. package/dist/components/dev-console/index.mjs.map +1 -0
  231. package/dist/components/dev-console/types.d.ts +9 -0
  232. package/dist/components/dev-console/types.js +19 -0
  233. package/dist/components/dev-console/types.js.map +1 -0
  234. package/dist/components/dev-console/types.mjs +1 -0
  235. package/dist/components/dev-console/types.mjs.map +1 -0
  236. package/dist/components/dev-console/utils.d.ts +10 -0
  237. package/dist/components/dev-console/utils.js +177 -0
  238. package/dist/components/dev-console/utils.js.map +1 -0
  239. package/dist/components/dev-console/utils.mjs +16 -0
  240. package/dist/components/dev-console/utils.mjs.map +1 -0
  241. package/dist/components/help-modal/icons.d.ts +9 -0
  242. package/dist/components/help-modal/icons.js +107 -0
  243. package/dist/components/help-modal/icons.js.map +1 -0
  244. package/dist/components/help-modal/icons.mjs +12 -0
  245. package/dist/components/help-modal/icons.mjs.map +1 -0
  246. package/dist/components/help-modal/index.d.ts +2 -0
  247. package/dist/components/help-modal/index.js +137 -0
  248. package/dist/components/help-modal/index.js.map +1 -0
  249. package/dist/components/help-modal/index.mjs +10 -0
  250. package/dist/components/help-modal/index.mjs.map +1 -0
  251. package/dist/components/help-modal/modal.d.ts +5 -0
  252. package/dist/components/help-modal/modal.js +135 -0
  253. package/dist/components/help-modal/modal.js.map +1 -0
  254. package/dist/components/help-modal/modal.mjs +9 -0
  255. package/dist/components/help-modal/modal.mjs.map +1 -0
  256. package/dist/components/index.d.ts +19 -0
  257. package/dist/components/index.js +3126 -0
  258. package/dist/components/index.js.map +1 -0
  259. package/dist/components/index.mjs +76 -0
  260. package/dist/components/index.mjs.map +1 -0
  261. package/dist/context/index.d.ts +2 -0
  262. package/dist/context/index.js +19 -0
  263. package/dist/context/index.js.map +1 -0
  264. package/dist/context/index.mjs +2 -0
  265. package/dist/context/index.mjs.map +1 -0
  266. package/dist/hooks/index.d.ts +2 -0
  267. package/dist/hooks/index.js +36 -0
  268. package/dist/hooks/index.js.map +1 -0
  269. package/dist/hooks/index.mjs +9 -0
  270. package/dist/hooks/index.mjs.map +1 -0
  271. package/dist/hooks/use-copilot-chat-suggestions.d.ts +66 -0
  272. package/dist/hooks/use-copilot-chat-suggestions.js +34 -0
  273. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  274. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  275. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
  276. package/dist/hooks/use-copy-to-clipboard.d.ts +9 -0
  277. package/dist/hooks/use-copy-to-clipboard.js +60 -0
  278. package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
  279. package/dist/hooks/use-copy-to-clipboard.mjs +8 -0
  280. package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -0
  281. package/dist/hooks/use-dark-mode.d.ts +3 -0
  282. package/dist/hooks/use-dark-mode.js +35 -0
  283. package/dist/hooks/use-dark-mode.js.map +1 -0
  284. package/dist/hooks/use-dark-mode.mjs +8 -0
  285. package/dist/hooks/use-dark-mode.mjs.map +1 -0
  286. package/dist/hooks/use-push-to-talk.d.ts +19 -0
  287. package/dist/hooks/use-push-to-talk.js +195 -0
  288. package/dist/hooks/use-push-to-talk.js.map +1 -0
  289. package/dist/hooks/use-push-to-talk.mjs +12 -0
  290. package/dist/hooks/use-push-to-talk.mjs.map +1 -0
  291. package/dist/index.css +1258 -0
  292. package/dist/index.css.map +1 -0
  293. package/dist/index.d.ts +21 -0
  294. package/dist/index.js +3135 -0
  295. package/dist/index.js.map +1 -0
  296. package/dist/index.mjs +84 -0
  297. package/dist/index.mjs.map +1 -0
  298. package/dist/lib/utils.d.ts +4 -0
  299. package/dist/lib/utils.js +76 -0
  300. package/dist/lib/utils.js.map +1 -0
  301. package/dist/lib/utils.mjs +34 -0
  302. package/dist/lib/utils.mjs.map +1 -0
  303. package/dist/types/css.d.ts +22 -0
  304. package/dist/types/css.js +19 -0
  305. package/dist/types/css.js.map +1 -0
  306. package/dist/types/css.mjs +1 -0
  307. package/dist/types/css.mjs.map +1 -0
  308. package/dist/types/index.d.ts +3 -0
  309. package/dist/types/index.js +19 -0
  310. package/dist/types/index.js.map +1 -0
  311. package/dist/types/index.mjs +2 -0
  312. package/dist/types/index.mjs.map +1 -0
  313. package/dist/types/suggestions.d.ts +9 -0
  314. package/dist/types/suggestions.js +19 -0
  315. package/dist/types/suggestions.js.map +1 -0
  316. package/dist/types/suggestions.mjs +1 -0
  317. package/dist/types/suggestions.mjs.map +1 -0
  318. package/dist/v2/index.css +4 -0
  319. package/dist/v2/index.css.map +1 -0
  320. package/dist/v2/index.d.ts +2 -0
  321. package/dist/v2/index.js +2 -0
  322. package/dist/v2/index.js.map +1 -0
  323. package/dist/v2/index.mjs +2 -0
  324. package/dist/v2/index.mjs.map +1 -0
  325. package/jest.config.js +5 -0
  326. package/package.json +83 -0
  327. package/postcss.config.js +60 -0
  328. package/src/components/chat/Button.tsx +18 -0
  329. package/src/components/chat/Chat.tsx +795 -0
  330. package/src/components/chat/ChatContext.tsx +248 -0
  331. package/src/components/chat/CodeBlock.tsx +418 -0
  332. package/src/components/chat/Header.tsx +24 -0
  333. package/src/components/chat/Icons.tsx +237 -0
  334. package/src/components/chat/ImageUploadQueue.tsx +77 -0
  335. package/src/components/chat/Input.tsx +156 -0
  336. package/src/components/chat/Markdown.tsx +144 -0
  337. package/src/components/chat/Messages.tsx +206 -0
  338. package/src/components/chat/Modal.tsx +220 -0
  339. package/src/components/chat/Popup.tsx +77 -0
  340. package/src/components/chat/PoweredByTag.tsx +42 -0
  341. package/src/components/chat/Sidebar.tsx +96 -0
  342. package/src/components/chat/Suggestion.tsx +29 -0
  343. package/src/components/chat/Suggestions.tsx +23 -0
  344. package/src/components/chat/Textarea.tsx +77 -0
  345. package/src/components/chat/Window.tsx +152 -0
  346. package/src/components/chat/index.tsx +11 -0
  347. package/src/components/chat/messages/AssistantMessage.tsx +118 -0
  348. package/src/components/chat/messages/ErrorMessage.tsx +59 -0
  349. package/src/components/chat/messages/ImageRenderer.tsx +37 -0
  350. package/src/components/chat/messages/LegacyRenderMessage.tsx +150 -0
  351. package/src/components/chat/messages/RenderMessage.tsx +61 -0
  352. package/src/components/chat/messages/UserMessage.tsx +46 -0
  353. package/src/components/chat/props.ts +353 -0
  354. package/src/components/dev-console/console.tsx +242 -0
  355. package/src/components/dev-console/icons.tsx +99 -0
  356. package/src/components/dev-console/index.tsx +2 -0
  357. package/src/components/dev-console/types.ts +7 -0
  358. package/src/components/dev-console/utils.ts +142 -0
  359. package/src/components/help-modal/icons.tsx +68 -0
  360. package/src/components/help-modal/index.tsx +1 -0
  361. package/src/components/help-modal/modal.tsx +101 -0
  362. package/src/components/index.ts +2 -0
  363. package/src/context/index.ts +1 -0
  364. package/src/css/animations.css +35 -0
  365. package/src/css/button.css +67 -0
  366. package/src/css/colors.css +78 -0
  367. package/src/css/console.css +166 -0
  368. package/src/css/crew.css +277 -0
  369. package/src/css/header.css +65 -0
  370. package/src/css/input.css +152 -0
  371. package/src/css/markdown.css +150 -0
  372. package/src/css/messages.css +244 -0
  373. package/src/css/panel.css +39 -0
  374. package/src/css/popup.css +22 -0
  375. package/src/css/sidebar.css +34 -0
  376. package/src/css/suggestions.css +43 -0
  377. package/src/css/window.css +60 -0
  378. package/src/hooks/index.ts +1 -0
  379. package/src/hooks/use-copilot-chat-suggestions.tsx +71 -0
  380. package/src/hooks/use-copy-to-clipboard.tsx +29 -0
  381. package/src/hooks/use-dark-mode.ts +10 -0
  382. package/src/hooks/use-push-to-talk.tsx +167 -0
  383. package/src/index.tsx +7 -0
  384. package/src/lib/utils.test.ts +7 -0
  385. package/src/lib/utils.ts +27 -0
  386. package/src/styles.css +14 -0
  387. package/src/types/css.ts +21 -0
  388. package/src/types/index.ts +2 -0
  389. package/src/types/suggestions.ts +7 -0
  390. package/src/v2/index.ts +1 -0
  391. package/src/v2/styles.css +1 -0
  392. package/tailwind.config.js +7 -0
  393. package/tsconfig.json +12 -0
  394. package/tsup.config.ts +11 -0
  395. package/typedoc.json +4 -0
@@ -0,0 +1,2270 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // src/components/chat/Chat.tsx
80
+ var Chat_exports = {};
81
+ __export(Chat_exports, {
82
+ CopilotChat: () => CopilotChat,
83
+ WrappedCopilotChat: () => WrappedCopilotChat
84
+ });
85
+ module.exports = __toCommonJS(Chat_exports);
86
+
87
+ // src/components/chat/ChatContext.tsx
88
+ var import_react = __toESM(require("react"));
89
+
90
+ // src/components/chat/Icons.tsx
91
+ var import_jsx_runtime = require("react/jsx-runtime");
92
+ var OpenIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
+ "svg",
94
+ {
95
+ xmlns: "http://www.w3.org/2000/svg",
96
+ viewBox: "0 0 24 24",
97
+ fill: "currentColor",
98
+ width: "24",
99
+ height: "24",
100
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(24, 0) scale(-1, 1)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
101
+ "path",
102
+ {
103
+ fillRule: "evenodd",
104
+ d: "M5.337 21.718a6.707 6.707 0 01-.533-.074.75.75 0 01-.44-1.223 3.73 3.73 0 00.814-1.686c.023-.115-.022-.317-.254-.543C3.274 16.587 2.25 14.41 2.25 12c0-5.03 4.428-9 9.75-9s9.75 3.97 9.75 9c0 5.03-4.428 9-9.75 9-.833 0-1.643-.097-2.417-.279a6.721 6.721 0 01-4.246.997z",
105
+ clipRule: "evenodd"
106
+ }
107
+ ) })
108
+ }
109
+ );
110
+ var CloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
111
+ "svg",
112
+ {
113
+ xmlns: "http://www.w3.org/2000/svg",
114
+ fill: "none",
115
+ viewBox: "0 0 24 24",
116
+ strokeWidth: "1.5",
117
+ stroke: "currentColor",
118
+ width: "24",
119
+ height: "24",
120
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" })
121
+ }
122
+ );
123
+ var HeaderCloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ "svg",
125
+ {
126
+ xmlns: "http://www.w3.org/2000/svg",
127
+ fill: "none",
128
+ viewBox: "0 0 24 24",
129
+ strokeWidth: "1.5",
130
+ stroke: "currentColor",
131
+ width: "24",
132
+ height: "24",
133
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
134
+ }
135
+ );
136
+ var SendIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
+ "svg",
138
+ {
139
+ xmlns: "http://www.w3.org/2000/svg",
140
+ fill: "none",
141
+ viewBox: "0 0 24 24",
142
+ strokeWidth: "1.5",
143
+ stroke: "currentColor",
144
+ width: "24",
145
+ height: "24",
146
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 19V5m0 0l-7 7m7-7l7 7" })
147
+ }
148
+ );
149
+ var MicrophoneIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
+ "svg",
151
+ {
152
+ xmlns: "http://www.w3.org/2000/svg",
153
+ fill: "none",
154
+ viewBox: "0 0 24 24",
155
+ strokeWidth: "1.5",
156
+ stroke: "currentColor",
157
+ width: "24",
158
+ height: "24",
159
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
160
+ "path",
161
+ {
162
+ strokeLinecap: "round",
163
+ strokeLinejoin: "round",
164
+ d: "M12 18.75a6 6 0 006-6v-1.5m-6 7.5a6 6 0 01-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 01-3-3V4.5a3 3 0 116 0v8.25a3 3 0 01-3 3z"
165
+ }
166
+ )
167
+ }
168
+ );
169
+ var StopIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
170
+ "svg",
171
+ {
172
+ xmlns: "http://www.w3.org/2000/svg",
173
+ fill: "none",
174
+ viewBox: "0 0 24 24",
175
+ strokeWidth: "1.5",
176
+ stroke: "currentColor",
177
+ width: "24",
178
+ height: "24",
179
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
180
+ "path",
181
+ {
182
+ strokeLinecap: "round",
183
+ strokeLinejoin: "round",
184
+ d: "M5.25 7.5A2.25 2.25 0 017.5 5.25h9a2.25 2.25 0 012.25 2.25v9a2.25 2.25 0 01-2.25 2.25h-9a2.25 2.25 0 01-2.25-2.25v-9z"
185
+ }
186
+ )
187
+ }
188
+ );
189
+ var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
190
+ "svg",
191
+ {
192
+ xmlns: "http://www.w3.org/2000/svg",
193
+ fill: "none",
194
+ viewBox: "0 0 24 24",
195
+ strokeWidth: "2",
196
+ stroke: "currentColor",
197
+ width: "16",
198
+ height: "16",
199
+ style: { minWidth: "16px", minHeight: "16px" },
200
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
201
+ "path",
202
+ {
203
+ strokeLinecap: "round",
204
+ strokeLinejoin: "round",
205
+ d: "M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"
206
+ }
207
+ )
208
+ }
209
+ );
210
+ var CopyIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
211
+ "svg",
212
+ {
213
+ xmlns: "http://www.w3.org/2000/svg",
214
+ fill: "none",
215
+ viewBox: "0 0 24 24",
216
+ strokeWidth: "2",
217
+ stroke: "currentColor",
218
+ width: "16",
219
+ height: "16",
220
+ style: { minWidth: "16px", minHeight: "16px" },
221
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
222
+ "path",
223
+ {
224
+ strokeLinecap: "round",
225
+ strokeLinejoin: "round",
226
+ d: "M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75"
227
+ }
228
+ )
229
+ }
230
+ );
231
+ var SmallSpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitSpinner", style: { width: "13px", height: "13px" } });
232
+ var SpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitSpinner", style: { width: "24px", height: "24px" } });
233
+ var ActivityIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "4px" }, children: [
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0s" } }),
235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0.2s" } }),
236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0.4s" } })
237
+ ] });
238
+ var ThumbsUpIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
239
+ "svg",
240
+ {
241
+ xmlns: "http://www.w3.org/2000/svg",
242
+ fill: "none",
243
+ viewBox: "0 0 24 24",
244
+ strokeWidth: "2",
245
+ stroke: "currentColor",
246
+ width: "16",
247
+ height: "16",
248
+ style: { minWidth: "16px", minHeight: "16px" },
249
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
250
+ "path",
251
+ {
252
+ strokeLinecap: "round",
253
+ strokeLinejoin: "round",
254
+ d: "M6.633 10.5c.806 0 1.533-.446 2.031-1.08a9.041 9.041 0 012.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.498 4.498 0 00.322-1.672V3a.75.75 0 01.75-.75A2.25 2.25 0 0116.5 4.5c0 1.152-.26 2.243-.723 3.218-.266.558.107 1.282.725 1.282h3.126c1.026 0 1.945.694 2.054 1.715.045.422.068.85.068 1.285a11.95 11.95 0 01-2.649 7.521c-.388.482-.987.729-1.605.729H13.48c-.483 0-.964-.078-1.423-.23l-3.114-1.04a4.501 4.501 0 00-1.423-.23H5.904M14.25 9h2.25M5.904 18.75c.083.205.173.405.27.602.197.4-.078.898-.523.898h-.908c-.889 0-1.713-.518-1.972-1.368a12 12 0 01-.521-3.507c0-1.553.295-3.036.831-4.398C3.387 10.203 4.167 9.75 5 9.75h1.053c.472 0 .745.556.5.96a8.958 8.958 0 00-1.302 4.665c0 1.194.232 2.333.654 3.375z"
255
+ }
256
+ )
257
+ }
258
+ );
259
+ var ThumbsDownIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
260
+ "svg",
261
+ {
262
+ xmlns: "http://www.w3.org/2000/svg",
263
+ fill: "none",
264
+ viewBox: "0 0 24 24",
265
+ strokeWidth: "2",
266
+ stroke: "currentColor",
267
+ width: "16",
268
+ height: "16",
269
+ style: { minWidth: "16px", minHeight: "16px" },
270
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
+ "path",
272
+ {
273
+ strokeLinecap: "round",
274
+ strokeLinejoin: "round",
275
+ d: "M7.5 15h2.25m8.024-9.75c.011.05.028.1.052.148.591 1.2.924 2.55.924 3.977a8.96 8.96 0 01-.999 4.125m.023-8.25c-.076-.365.183-.75.575-.75h.908c.889 0 1.713.518 1.972 1.368.339 1.11.521 2.287.521 3.507 0 1.553-.295 3.036-.831 4.398C20.613 14.547 19.833 15 19 15h-1.053c-.472 0-.745-.556-.5-.96a8.95 8.95 0 00.303-.54m.023-8.25H16.48a4.5 4.5 0 01-1.423-.23l-3.114-1.04a4.5 4.5 0 00-1.423-.23H6.504c-.618 0-1.217.247-1.605.729A11.95 11.95 0 002.25 12c0 .434.023.863.068 1.285C2.427 14.306 3.346 15 4.372 15h3.126c.618 0 .991.724.725 1.282A7.471 7.471 0 007.5 19.5a2.25 2.25 0 002.25 2.25.75.75 0 00.75-.75v-.633c0-.573.11-1.14.322-1.672.304-.76.93-1.33 1.653-1.715a9.04 9.04 0 002.86-2.4c.498-.634 1.226-1.08 2.032-1.08h.384"
276
+ }
277
+ )
278
+ }
279
+ );
280
+ var DownloadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
281
+ "svg",
282
+ {
283
+ xmlns: "http://www.w3.org/2000/svg",
284
+ fill: "none",
285
+ viewBox: "0 0 24 24",
286
+ strokeWidth: "2",
287
+ stroke: "currentColor",
288
+ width: "16",
289
+ height: "16",
290
+ style: { minWidth: "16px", minHeight: "16px" },
291
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
292
+ "path",
293
+ {
294
+ strokeLinecap: "round",
295
+ strokeLinejoin: "round",
296
+ d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3"
297
+ }
298
+ )
299
+ }
300
+ );
301
+ var UploadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
302
+ "svg",
303
+ {
304
+ xmlns: "http://www.w3.org/2000/svg",
305
+ fill: "none",
306
+ viewBox: "0 0 24 24",
307
+ strokeWidth: "1.5",
308
+ stroke: "currentColor",
309
+ width: "24",
310
+ height: "24",
311
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 4.5v15m7.5-7.5h-15" })
312
+ }
313
+ );
314
+ var CheckIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
315
+ "svg",
316
+ {
317
+ xmlns: "http://www.w3.org/2000/svg",
318
+ fill: "none",
319
+ viewBox: "0 0 24 24",
320
+ strokeWidth: "2",
321
+ stroke: "currentColor",
322
+ width: "16",
323
+ height: "16",
324
+ style: { minWidth: "16px", minHeight: "16px" },
325
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4.5 12.75l6 6 9-13.5" })
326
+ }
327
+ );
328
+
329
+ // src/components/chat/ChatContext.tsx
330
+ var import_jsx_runtime2 = require("react/jsx-runtime");
331
+ var ChatContext = import_react.default.createContext(void 0);
332
+ function useChatContext() {
333
+ const context = import_react.default.useContext(ChatContext);
334
+ if (context === void 0) {
335
+ throw new Error(
336
+ "Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?"
337
+ );
338
+ }
339
+ return context;
340
+ }
341
+ var ChatContextProvider = ({
342
+ // temperature,
343
+ // instructions,
344
+ // maxFeedback,
345
+ labels,
346
+ icons,
347
+ children,
348
+ open,
349
+ setOpen
350
+ }) => {
351
+ const memoizedLabels = (0, import_react.useMemo)(
352
+ () => __spreadValues(__spreadValues({}, {
353
+ initial: "",
354
+ title: "CopilotKit",
355
+ placeholder: "Type a message...",
356
+ error: "\u274C An error occurred. Please try again.",
357
+ stopGenerating: "Stop generating",
358
+ regenerateResponse: "Regenerate response",
359
+ copyToClipboard: "Copy to clipboard",
360
+ thumbsUp: "Thumbs up",
361
+ thumbsDown: "Thumbs down",
362
+ copied: "Copied!"
363
+ }), labels),
364
+ [labels]
365
+ );
366
+ const memoizedIcons = (0, import_react.useMemo)(
367
+ () => __spreadValues(__spreadValues({}, {
368
+ openIcon: OpenIcon,
369
+ closeIcon: CloseIcon,
370
+ headerCloseIcon: HeaderCloseIcon,
371
+ sendIcon: SendIcon,
372
+ activityIcon: ActivityIcon,
373
+ spinnerIcon: SpinnerIcon,
374
+ stopIcon: StopIcon,
375
+ regenerateIcon: RegenerateIcon,
376
+ pushToTalkIcon: MicrophoneIcon,
377
+ copyIcon: CopyIcon,
378
+ thumbsUpIcon: ThumbsUpIcon,
379
+ thumbsDownIcon: ThumbsDownIcon,
380
+ uploadIcon: UploadIcon
381
+ }), icons),
382
+ [icons]
383
+ );
384
+ const context = (0, import_react.useMemo)(
385
+ () => ({
386
+ labels: memoizedLabels,
387
+ icons: memoizedIcons,
388
+ open,
389
+ setOpen
390
+ }),
391
+ [memoizedLabels, memoizedIcons, open, setOpen]
392
+ );
393
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
394
+ };
395
+
396
+ // src/components/chat/Messages.tsx
397
+ var import_react6 = require("react");
398
+ var import_react_core = require("@copilotkit/react-core");
399
+
400
+ // src/components/chat/messages/UserMessage.tsx
401
+ var import_jsx_runtime3 = require("react/jsx-runtime");
402
+ var getTextContent = (content) => {
403
+ if (typeof content === "undefined") {
404
+ return void 0;
405
+ }
406
+ if (typeof content === "string") {
407
+ return content;
408
+ }
409
+ return content.map((part) => {
410
+ if (part.type === "text") {
411
+ return part.text;
412
+ }
413
+ return void 0;
414
+ }).filter((value) => typeof value === "string" && value.length > 0).join(" ").trim() || void 0;
415
+ };
416
+ var UserMessage = (props) => {
417
+ const { message, ImageRenderer: ImageRenderer2 } = props;
418
+ const isImageMessage = message && "image" in message && Boolean(message.image);
419
+ if (isImageMessage) {
420
+ const imageMessage = message;
421
+ const content2 = getTextContent(imageMessage == null ? void 0 : imageMessage.content);
422
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ImageRenderer2, { image: imageMessage.image, content: content2 }) });
423
+ }
424
+ const content = getTextContent(message == null ? void 0 : message.content);
425
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: content });
426
+ };
427
+
428
+ // src/components/chat/Markdown.tsx
429
+ var import_react3 = require("react");
430
+ var import_react_markdown = __toESM(require("react-markdown"));
431
+
432
+ // src/components/chat/CodeBlock.tsx
433
+ var import_react2 = require("react");
434
+ var import_react_syntax_highlighter = require("react-syntax-highlighter");
435
+
436
+ // src/hooks/use-copy-to-clipboard.tsx
437
+ var React2 = __toESM(require("react"));
438
+ function useCopyToClipboard({ timeout = 2e3 }) {
439
+ const [isCopied, setIsCopied] = React2.useState(false);
440
+ const copyToClipboard = (value) => {
441
+ var _a;
442
+ if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
443
+ return;
444
+ }
445
+ if (!value) {
446
+ return;
447
+ }
448
+ navigator.clipboard.writeText(value).then(() => {
449
+ setIsCopied(true);
450
+ setTimeout(() => {
451
+ setIsCopied(false);
452
+ }, timeout);
453
+ });
454
+ };
455
+ return { isCopied, copyToClipboard };
456
+ }
457
+
458
+ // src/components/chat/CodeBlock.tsx
459
+ var import_jsx_runtime4 = require("react/jsx-runtime");
460
+ var programmingLanguages = {
461
+ javascript: ".js",
462
+ python: ".py",
463
+ java: ".java",
464
+ c: ".c",
465
+ cpp: ".cpp",
466
+ "c++": ".cpp",
467
+ "c#": ".cs",
468
+ ruby: ".rb",
469
+ php: ".php",
470
+ swift: ".swift",
471
+ "objective-c": ".m",
472
+ kotlin: ".kt",
473
+ typescript: ".ts",
474
+ go: ".go",
475
+ perl: ".pl",
476
+ rust: ".rs",
477
+ scala: ".scala",
478
+ haskell: ".hs",
479
+ lua: ".lua",
480
+ shell: ".sh",
481
+ sql: ".sql",
482
+ html: ".html",
483
+ css: ".css"
484
+ // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
485
+ };
486
+ var generateRandomString = (length, lowercase = false) => {
487
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
488
+ let result = "";
489
+ for (let i = 0; i < length; i++) {
490
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
491
+ }
492
+ return lowercase ? result.toLowerCase() : result;
493
+ };
494
+ var CodeBlock = (0, import_react2.memo)(({ language, value }) => {
495
+ const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
496
+ const [SyntaxHighlighter, setSyntaxHighlighter] = (0, import_react2.useState)(
497
+ () => import_react_syntax_highlighter.Light
498
+ );
499
+ (0, import_react2.useEffect)(() => {
500
+ try {
501
+ new RegExp("(?<=#)\\w+");
502
+ setSyntaxHighlighter(() => import_react_syntax_highlighter.Prism);
503
+ } catch (e) {
504
+ setSyntaxHighlighter(() => import_react_syntax_highlighter.Light);
505
+ }
506
+ }, []);
507
+ const downloadAsFile = () => {
508
+ if (typeof window === "undefined") {
509
+ return;
510
+ }
511
+ const fileExtension = programmingLanguages[language] || ".file";
512
+ const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
513
+ const fileName = window.prompt("Enter file name", suggestedFileName);
514
+ if (!fileName) {
515
+ return;
516
+ }
517
+ const blob = new Blob([value], { type: "text/plain" });
518
+ const url = URL.createObjectURL(blob);
519
+ const link = document.createElement("a");
520
+ link.download = fileName;
521
+ link.href = url;
522
+ link.style.display = "none";
523
+ document.body.appendChild(link);
524
+ link.click();
525
+ document.body.removeChild(link);
526
+ URL.revokeObjectURL(url);
527
+ };
528
+ const onCopy = () => {
529
+ if (isCopied)
530
+ return;
531
+ copyToClipboard(value);
532
+ };
533
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "copilotKitCodeBlock", children: [
534
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
535
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
536
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
537
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: DownloadIcon }),
538
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: isCopied ? CheckIcon : CopyIcon })
539
+ ] })
540
+ ] }),
541
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
542
+ SyntaxHighlighter,
543
+ {
544
+ language,
545
+ style: highlightStyle,
546
+ PreTag: "div",
547
+ customStyle: {
548
+ margin: 0,
549
+ borderBottomLeftRadius: "0.375rem",
550
+ borderBottomRightRadius: "0.375rem"
551
+ },
552
+ children: value
553
+ }
554
+ )
555
+ ] });
556
+ });
557
+ CodeBlock.displayName = "CodeBlock";
558
+ var highlightStyle = {
559
+ 'pre[class*="language-"]': {
560
+ color: "#d4d4d4",
561
+ fontSize: "13px",
562
+ textShadow: "none",
563
+ fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
564
+ direction: "ltr",
565
+ textAlign: "left",
566
+ whiteSpace: "pre",
567
+ wordSpacing: "normal",
568
+ wordBreak: "normal",
569
+ lineHeight: "1.5",
570
+ MozTabSize: "4",
571
+ OTabSize: "4",
572
+ tabSize: "4",
573
+ WebkitHyphens: "none",
574
+ MozHyphens: "none",
575
+ msHyphens: "none",
576
+ hyphens: "none",
577
+ padding: "1em",
578
+ margin: ".5em 0",
579
+ overflow: "auto",
580
+ background: "#1e1e1e"
581
+ },
582
+ 'code[class*="language-"]': {
583
+ color: "#d4d4d4",
584
+ fontSize: "13px",
585
+ textShadow: "none",
586
+ fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
587
+ direction: "ltr",
588
+ textAlign: "left",
589
+ whiteSpace: "pre",
590
+ wordSpacing: "normal",
591
+ wordBreak: "normal",
592
+ lineHeight: "1.5",
593
+ MozTabSize: "4",
594
+ OTabSize: "4",
595
+ tabSize: "4",
596
+ WebkitHyphens: "none",
597
+ MozHyphens: "none",
598
+ msHyphens: "none",
599
+ hyphens: "none"
600
+ },
601
+ 'pre[class*="language-"]::selection': {
602
+ textShadow: "none",
603
+ background: "#264F78"
604
+ },
605
+ 'code[class*="language-"]::selection': {
606
+ textShadow: "none",
607
+ background: "#264F78"
608
+ },
609
+ 'pre[class*="language-"] *::selection': {
610
+ textShadow: "none",
611
+ background: "#264F78"
612
+ },
613
+ 'code[class*="language-"] *::selection': {
614
+ textShadow: "none",
615
+ background: "#264F78"
616
+ },
617
+ ':not(pre) > code[class*="language-"]': {
618
+ padding: ".1em .3em",
619
+ borderRadius: ".3em",
620
+ color: "#db4c69",
621
+ background: "#1e1e1e"
622
+ },
623
+ ".namespace": {
624
+ Opacity: ".7"
625
+ },
626
+ "doctype.doctype-tag": {
627
+ color: "#569CD6"
628
+ },
629
+ "doctype.name": {
630
+ color: "#9cdcfe"
631
+ },
632
+ comment: {
633
+ color: "#6a9955"
634
+ },
635
+ prolog: {
636
+ color: "#6a9955"
637
+ },
638
+ punctuation: {
639
+ color: "#d4d4d4"
640
+ },
641
+ ".language-html .language-css .token.punctuation": {
642
+ color: "#d4d4d4"
643
+ },
644
+ ".language-html .language-javascript .token.punctuation": {
645
+ color: "#d4d4d4"
646
+ },
647
+ property: {
648
+ color: "#9cdcfe"
649
+ },
650
+ tag: {
651
+ color: "#569cd6"
652
+ },
653
+ boolean: {
654
+ color: "#569cd6"
655
+ },
656
+ number: {
657
+ color: "#b5cea8"
658
+ },
659
+ constant: {
660
+ color: "#9cdcfe"
661
+ },
662
+ symbol: {
663
+ color: "#b5cea8"
664
+ },
665
+ inserted: {
666
+ color: "#b5cea8"
667
+ },
668
+ unit: {
669
+ color: "#b5cea8"
670
+ },
671
+ selector: {
672
+ color: "#d7ba7d"
673
+ },
674
+ "attr-name": {
675
+ color: "#9cdcfe"
676
+ },
677
+ string: {
678
+ color: "#ce9178"
679
+ },
680
+ char: {
681
+ color: "#ce9178"
682
+ },
683
+ builtin: {
684
+ color: "#ce9178"
685
+ },
686
+ deleted: {
687
+ color: "#ce9178"
688
+ },
689
+ ".language-css .token.string.url": {
690
+ textDecoration: "underline"
691
+ },
692
+ operator: {
693
+ color: "#d4d4d4"
694
+ },
695
+ entity: {
696
+ color: "#569cd6"
697
+ },
698
+ "operator.arrow": {
699
+ color: "#569CD6"
700
+ },
701
+ atrule: {
702
+ color: "#ce9178"
703
+ },
704
+ "atrule.rule": {
705
+ color: "#c586c0"
706
+ },
707
+ "atrule.url": {
708
+ color: "#9cdcfe"
709
+ },
710
+ "atrule.url.function": {
711
+ color: "#dcdcaa"
712
+ },
713
+ "atrule.url.punctuation": {
714
+ color: "#d4d4d4"
715
+ },
716
+ keyword: {
717
+ color: "#569CD6"
718
+ },
719
+ "keyword.module": {
720
+ color: "#c586c0"
721
+ },
722
+ "keyword.control-flow": {
723
+ color: "#c586c0"
724
+ },
725
+ function: {
726
+ color: "#dcdcaa"
727
+ },
728
+ "function.maybe-class-name": {
729
+ color: "#dcdcaa"
730
+ },
731
+ regex: {
732
+ color: "#d16969"
733
+ },
734
+ important: {
735
+ color: "#569cd6"
736
+ },
737
+ italic: {
738
+ fontStyle: "italic"
739
+ },
740
+ "class-name": {
741
+ color: "#4ec9b0"
742
+ },
743
+ "maybe-class-name": {
744
+ color: "#4ec9b0"
745
+ },
746
+ console: {
747
+ color: "#9cdcfe"
748
+ },
749
+ parameter: {
750
+ color: "#9cdcfe"
751
+ },
752
+ interpolation: {
753
+ color: "#9cdcfe"
754
+ },
755
+ "punctuation.interpolation-punctuation": {
756
+ color: "#569cd6"
757
+ },
758
+ variable: {
759
+ color: "#9cdcfe"
760
+ },
761
+ "imports.maybe-class-name": {
762
+ color: "#9cdcfe"
763
+ },
764
+ "exports.maybe-class-name": {
765
+ color: "#9cdcfe"
766
+ },
767
+ escape: {
768
+ color: "#d7ba7d"
769
+ },
770
+ "tag.punctuation": {
771
+ color: "#808080"
772
+ },
773
+ cdata: {
774
+ color: "#808080"
775
+ },
776
+ "attr-value": {
777
+ color: "#ce9178"
778
+ },
779
+ "attr-value.punctuation": {
780
+ color: "#ce9178"
781
+ },
782
+ "attr-value.punctuation.attr-equals": {
783
+ color: "#d4d4d4"
784
+ },
785
+ namespace: {
786
+ color: "#4ec9b0"
787
+ },
788
+ 'pre[class*="language-javascript"]': {
789
+ color: "#9cdcfe"
790
+ },
791
+ 'code[class*="language-javascript"]': {
792
+ color: "#9cdcfe"
793
+ },
794
+ 'pre[class*="language-jsx"]': {
795
+ color: "#9cdcfe"
796
+ },
797
+ 'code[class*="language-jsx"]': {
798
+ color: "#9cdcfe"
799
+ },
800
+ 'pre[class*="language-typescript"]': {
801
+ color: "#9cdcfe"
802
+ },
803
+ 'code[class*="language-typescript"]': {
804
+ color: "#9cdcfe"
805
+ },
806
+ 'pre[class*="language-tsx"]': {
807
+ color: "#9cdcfe"
808
+ },
809
+ 'code[class*="language-tsx"]': {
810
+ color: "#9cdcfe"
811
+ },
812
+ 'pre[class*="language-css"]': {
813
+ color: "#ce9178"
814
+ },
815
+ 'code[class*="language-css"]': {
816
+ color: "#ce9178"
817
+ },
818
+ 'pre[class*="language-html"]': {
819
+ color: "#d4d4d4"
820
+ },
821
+ 'code[class*="language-html"]': {
822
+ color: "#d4d4d4"
823
+ },
824
+ ".language-regex .token.anchor": {
825
+ color: "#dcdcaa"
826
+ },
827
+ ".language-html .token.punctuation": {
828
+ color: "#808080"
829
+ },
830
+ 'pre[class*="language-"] > code[class*="language-"]': {
831
+ position: "relative",
832
+ zIndex: "1"
833
+ },
834
+ ".line-highlight.line-highlight": {
835
+ background: "#f7ebc6",
836
+ boxShadow: "inset 5px 0 0 #f7d87c",
837
+ zIndex: "0"
838
+ }
839
+ };
840
+
841
+ // src/components/chat/Markdown.tsx
842
+ var import_remark_gfm = __toESM(require("remark-gfm"));
843
+ var import_remark_math = __toESM(require("remark-math"));
844
+ var import_rehype_raw = __toESM(require("rehype-raw"));
845
+ var import_jsx_runtime5 = require("react/jsx-runtime");
846
+ var defaultComponents = {
847
+ a(_a) {
848
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
849
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { target: "_blank", rel: "noopener noreferrer", children }));
850
+ },
851
+ // @ts-expect-error -- inline
852
+ code(_c) {
853
+ var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
854
+ if (Array.isArray(children) && children.length) {
855
+ if (children[0] == "\u258D") {
856
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
857
+ "span",
858
+ {
859
+ style: {
860
+ animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
861
+ marginTop: "0.25rem"
862
+ },
863
+ children: "\u258D"
864
+ }
865
+ );
866
+ }
867
+ children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
868
+ }
869
+ const match = /language-(\w+)/.exec(className || "");
870
+ const hasLanguage = match && match[1];
871
+ const content = String(children);
872
+ const hasNewlines = content.includes("\n");
873
+ const isInline = !hasLanguage && !hasNewlines;
874
+ if (isInline) {
875
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
876
+ "code",
877
+ __spreadProps(__spreadValues({
878
+ className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
879
+ }, props), {
880
+ children
881
+ })
882
+ );
883
+ }
884
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
885
+ CodeBlock,
886
+ __spreadValues({
887
+ language: match && match[1] || "",
888
+ value: String(children).replace(/\n$/, "")
889
+ }, props),
890
+ Math.random()
891
+ );
892
+ },
893
+ h1: (_e) => {
894
+ var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
895
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
896
+ },
897
+ h2: (_g) => {
898
+ var _h = _g, { children } = _h, props = __objRest(_h, ["children"]);
899
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
900
+ },
901
+ h3: (_i) => {
902
+ var _j = _i, { children } = _j, props = __objRest(_j, ["children"]);
903
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
904
+ },
905
+ h4: (_k) => {
906
+ var _l = _k, { children } = _l, props = __objRest(_l, ["children"]);
907
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h4", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
908
+ },
909
+ h5: (_m) => {
910
+ var _n = _m, { children } = _n, props = __objRest(_n, ["children"]);
911
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h5", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
912
+ },
913
+ h6: (_o) => {
914
+ var _p = _o, { children } = _p, props = __objRest(_p, ["children"]);
915
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h6", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
916
+ },
917
+ p: (_q) => {
918
+ var _r = _q, { children } = _r, props = __objRest(_r, ["children"]);
919
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
920
+ },
921
+ pre: (_s) => {
922
+ var _t = _s, { children } = _t, props = __objRest(_t, ["children"]);
923
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
924
+ },
925
+ blockquote: (_u) => {
926
+ var _v = _u, { children } = _v, props = __objRest(_v, ["children"]);
927
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("blockquote", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
928
+ },
929
+ ul: (_w) => {
930
+ var _x = _w, { children } = _x, props = __objRest(_x, ["children"]);
931
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
932
+ },
933
+ li: (_y) => {
934
+ var _z = _y, { children } = _z, props = __objRest(_z, ["children"]);
935
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
936
+ }
937
+ };
938
+ var MemoizedReactMarkdown = (0, import_react3.memo)(
939
+ import_react_markdown.default,
940
+ (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
941
+ );
942
+ var Markdown = ({ content, components }) => {
943
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
944
+ MemoizedReactMarkdown,
945
+ {
946
+ components: __spreadValues(__spreadValues({}, defaultComponents), components),
947
+ remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
948
+ rehypePlugins: [import_rehype_raw.default],
949
+ children: content
950
+ }
951
+ ) });
952
+ };
953
+
954
+ // src/components/chat/messages/AssistantMessage.tsx
955
+ var import_react4 = require("react");
956
+ var import_jsx_runtime6 = require("react/jsx-runtime");
957
+ var AssistantMessage = (props) => {
958
+ var _a;
959
+ const { icons, labels } = useChatContext();
960
+ const {
961
+ message,
962
+ isLoading,
963
+ onRegenerate,
964
+ onCopy,
965
+ onThumbsUp,
966
+ onThumbsDown,
967
+ isCurrentMessage,
968
+ feedback,
969
+ markdownTagRenderers
970
+ } = props;
971
+ const [copied, setCopied] = (0, import_react4.useState)(false);
972
+ const handleCopy = () => {
973
+ const content2 = (message == null ? void 0 : message.content) || "";
974
+ if (content2 && onCopy) {
975
+ navigator.clipboard.writeText(content2);
976
+ setCopied(true);
977
+ onCopy(content2);
978
+ setTimeout(() => setCopied(false), 2e3);
979
+ } else if (content2) {
980
+ navigator.clipboard.writeText(content2);
981
+ setCopied(true);
982
+ setTimeout(() => setCopied(false), 2e3);
983
+ }
984
+ };
985
+ const handleRegenerate = () => {
986
+ if (onRegenerate)
987
+ onRegenerate();
988
+ };
989
+ const handleThumbsUp = () => {
990
+ if (onThumbsUp && message) {
991
+ onThumbsUp(message);
992
+ }
993
+ };
994
+ const handleThumbsDown = () => {
995
+ if (onThumbsDown && message) {
996
+ onThumbsDown(message);
997
+ }
998
+ };
999
+ const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: icons.activityIcon });
1000
+ const content = (message == null ? void 0 : message.content) || "";
1001
+ const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
1002
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1003
+ content && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
1004
+ content && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Markdown, { content, components: markdownTagRenderers }),
1005
+ content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1006
+ "div",
1007
+ {
1008
+ className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
1009
+ children: [
1010
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1011
+ "button",
1012
+ {
1013
+ className: "copilotKitMessageControlButton",
1014
+ onClick: handleRegenerate,
1015
+ "aria-label": labels.regenerateResponse,
1016
+ title: labels.regenerateResponse,
1017
+ children: icons.regenerateIcon
1018
+ }
1019
+ ),
1020
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1021
+ "button",
1022
+ {
1023
+ className: "copilotKitMessageControlButton",
1024
+ onClick: handleCopy,
1025
+ "aria-label": labels.copyToClipboard,
1026
+ title: labels.copyToClipboard,
1027
+ children: copied ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
1028
+ }
1029
+ ),
1030
+ onThumbsUp && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1031
+ "button",
1032
+ {
1033
+ className: `copilotKitMessageControlButton ${feedback === "thumbsUp" ? "active" : ""}`,
1034
+ onClick: handleThumbsUp,
1035
+ "aria-label": labels.thumbsUp,
1036
+ title: labels.thumbsUp,
1037
+ children: icons.thumbsUpIcon
1038
+ }
1039
+ ),
1040
+ onThumbsDown && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1041
+ "button",
1042
+ {
1043
+ className: `copilotKitMessageControlButton ${feedback === "thumbsDown" ? "active" : ""}`,
1044
+ onClick: handleThumbsDown,
1045
+ "aria-label": labels.thumbsDown,
1046
+ title: labels.thumbsDown,
1047
+ children: icons.thumbsDownIcon
1048
+ }
1049
+ )
1050
+ ]
1051
+ }
1052
+ )
1053
+ ] }),
1054
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
1055
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LoadingIcon, {})
1056
+ ] });
1057
+ };
1058
+
1059
+ // src/components/chat/messages/ImageRenderer.tsx
1060
+ var import_react5 = require("react");
1061
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1062
+ var ImageRenderer = ({ image, content, className = "" }) => {
1063
+ const [imageError, setImageError] = (0, import_react5.useState)(false);
1064
+ const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
1065
+ const altText = content || "User uploaded image";
1066
+ const handleImageError = () => {
1067
+ setImageError(true);
1068
+ };
1069
+ if (imageError) {
1070
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `copilotKitImageRendering copilotKitImageRenderingError ${className}`, children: [
1071
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitImageRenderingErrorMessage", children: "Failed to load image" }),
1072
+ content && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1073
+ ] });
1074
+ }
1075
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `copilotKitImageRendering ${className}`, children: [
1076
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1077
+ "img",
1078
+ {
1079
+ src: imageSrc,
1080
+ alt: altText,
1081
+ className: "copilotKitImageRenderingImage",
1082
+ onError: handleImageError
1083
+ }
1084
+ ),
1085
+ content && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1086
+ ] });
1087
+ };
1088
+
1089
+ // src/components/chat/messages/RenderMessage.tsx
1090
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1091
+ function RenderMessage(_a) {
1092
+ var _b = _a, {
1093
+ UserMessage: UserMessage2 = UserMessage,
1094
+ AssistantMessage: AssistantMessage2 = AssistantMessage,
1095
+ ImageRenderer: ImageRenderer2 = ImageRenderer
1096
+ } = _b, props = __objRest(_b, [
1097
+ "UserMessage",
1098
+ "AssistantMessage",
1099
+ "ImageRenderer"
1100
+ ]);
1101
+ var _a2;
1102
+ const {
1103
+ message,
1104
+ messages,
1105
+ inProgress,
1106
+ index,
1107
+ isCurrentMessage,
1108
+ onRegenerate,
1109
+ onCopy,
1110
+ onThumbsUp,
1111
+ onThumbsDown,
1112
+ messageFeedback,
1113
+ markdownTagRenderers
1114
+ } = props;
1115
+ switch (message.role) {
1116
+ case "user":
1117
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1118
+ UserMessage2,
1119
+ {
1120
+ rawData: message,
1121
+ "data-message-role": "user",
1122
+ message,
1123
+ ImageRenderer: ImageRenderer2
1124
+ },
1125
+ index
1126
+ );
1127
+ case "assistant":
1128
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1129
+ AssistantMessage2,
1130
+ {
1131
+ "data-message-role": "assistant",
1132
+ subComponent: (_a2 = message.generativeUI) == null ? void 0 : _a2.call(message),
1133
+ rawData: message,
1134
+ message,
1135
+ messages,
1136
+ isLoading: inProgress && isCurrentMessage && !message.content,
1137
+ isGenerating: inProgress && isCurrentMessage && !!message.content,
1138
+ isCurrentMessage,
1139
+ onRegenerate: () => onRegenerate == null ? void 0 : onRegenerate(message.id),
1140
+ onCopy,
1141
+ onThumbsUp,
1142
+ onThumbsDown,
1143
+ feedback: (messageFeedback == null ? void 0 : messageFeedback[message.id]) || null,
1144
+ markdownTagRenderers,
1145
+ ImageRenderer: ImageRenderer2
1146
+ },
1147
+ index
1148
+ );
1149
+ default:
1150
+ return null;
1151
+ }
1152
+ }
1153
+
1154
+ // src/components/chat/messages/LegacyRenderMessage.tsx
1155
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1156
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1157
+ var LegacyRenderMessage = ({
1158
+ message,
1159
+ messages,
1160
+ inProgress,
1161
+ index,
1162
+ isCurrentMessage,
1163
+ actionResult,
1164
+ AssistantMessage: AssistantMessage2,
1165
+ UserMessage: UserMessage2,
1166
+ ImageRenderer: ImageRenderer2,
1167
+ onRegenerate,
1168
+ onCopy,
1169
+ onThumbsUp,
1170
+ onThumbsDown,
1171
+ markdownTagRenderers,
1172
+ legacyProps
1173
+ }) => {
1174
+ var _a;
1175
+ const {
1176
+ RenderTextMessage,
1177
+ RenderActionExecutionMessage,
1178
+ RenderAgentStateMessage,
1179
+ RenderResultMessage,
1180
+ RenderImageMessage
1181
+ } = legacyProps;
1182
+ const deprecatedMessage = (_a = (0, import_runtime_client_gql.aguiToGQL)(message)[0]) != null ? _a : void 0;
1183
+ if (deprecatedMessage.isTextMessage() && RenderTextMessage) {
1184
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1185
+ RenderTextMessage,
1186
+ {
1187
+ message,
1188
+ messages,
1189
+ inProgress,
1190
+ index,
1191
+ isCurrentMessage,
1192
+ AssistantMessage: AssistantMessage2,
1193
+ UserMessage: UserMessage2,
1194
+ onRegenerate,
1195
+ onCopy,
1196
+ onThumbsUp,
1197
+ onThumbsDown,
1198
+ markdownTagRenderers
1199
+ }
1200
+ );
1201
+ }
1202
+ if (deprecatedMessage.isActionExecutionMessage() && RenderActionExecutionMessage) {
1203
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1204
+ RenderActionExecutionMessage,
1205
+ {
1206
+ messages,
1207
+ message,
1208
+ inProgress,
1209
+ index,
1210
+ isCurrentMessage,
1211
+ actionResult,
1212
+ AssistantMessage: AssistantMessage2,
1213
+ UserMessage: UserMessage2
1214
+ }
1215
+ );
1216
+ }
1217
+ if (deprecatedMessage.isAgentStateMessage() && RenderAgentStateMessage) {
1218
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1219
+ RenderAgentStateMessage,
1220
+ {
1221
+ messages,
1222
+ message,
1223
+ inProgress,
1224
+ index,
1225
+ isCurrentMessage,
1226
+ AssistantMessage: AssistantMessage2,
1227
+ UserMessage: UserMessage2
1228
+ }
1229
+ );
1230
+ }
1231
+ if (deprecatedMessage.isResultMessage() && RenderResultMessage) {
1232
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1233
+ RenderResultMessage,
1234
+ {
1235
+ messages,
1236
+ message,
1237
+ inProgress,
1238
+ index,
1239
+ isCurrentMessage,
1240
+ AssistantMessage: AssistantMessage2,
1241
+ UserMessage: UserMessage2
1242
+ }
1243
+ );
1244
+ }
1245
+ if (deprecatedMessage.isImageMessage() && RenderImageMessage) {
1246
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1247
+ RenderImageMessage,
1248
+ {
1249
+ messages,
1250
+ message,
1251
+ inProgress,
1252
+ index,
1253
+ isCurrentMessage,
1254
+ AssistantMessage: AssistantMessage2,
1255
+ UserMessage: UserMessage2
1256
+ }
1257
+ );
1258
+ }
1259
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1260
+ RenderMessage,
1261
+ {
1262
+ messages,
1263
+ message,
1264
+ inProgress,
1265
+ index,
1266
+ isCurrentMessage,
1267
+ AssistantMessage: AssistantMessage2,
1268
+ UserMessage: UserMessage2,
1269
+ ImageRenderer: ImageRenderer2,
1270
+ onRegenerate,
1271
+ onCopy,
1272
+ onThumbsUp,
1273
+ onThumbsDown,
1274
+ markdownTagRenderers
1275
+ }
1276
+ );
1277
+ };
1278
+
1279
+ // src/components/chat/Messages.tsx
1280
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1281
+ var Messages = ({
1282
+ inProgress,
1283
+ children,
1284
+ RenderMessage: RenderMessage2,
1285
+ AssistantMessage: AssistantMessage2,
1286
+ UserMessage: UserMessage2,
1287
+ ErrorMessage,
1288
+ ImageRenderer: ImageRenderer2,
1289
+ onRegenerate,
1290
+ onCopy,
1291
+ onThumbsUp,
1292
+ onThumbsDown,
1293
+ messageFeedback,
1294
+ markdownTagRenderers,
1295
+ chatError,
1296
+ // Legacy props
1297
+ RenderTextMessage,
1298
+ RenderActionExecutionMessage,
1299
+ RenderAgentStateMessage,
1300
+ RenderResultMessage,
1301
+ RenderImageMessage
1302
+ }) => {
1303
+ var _a;
1304
+ const { labels, icons } = useChatContext();
1305
+ const { messages: visibleMessages, interrupt } = (0, import_react_core.useCopilotChatInternal)();
1306
+ const initialMessages = (0, import_react6.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
1307
+ const messages = [...initialMessages, ...visibleMessages];
1308
+ const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
1309
+ const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
1310
+ (0, import_react6.useEffect)(() => {
1311
+ if (hasLegacyProps) {
1312
+ console.warn(
1313
+ "[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. Please use the unified 'RenderMessage' prop instead. See migration guide: https://docs.copilotkit.ai/migration/render-message"
1314
+ );
1315
+ }
1316
+ }, [hasLegacyProps]);
1317
+ const legacyProps = (0, import_react6.useMemo)(
1318
+ () => ({
1319
+ RenderTextMessage,
1320
+ RenderActionExecutionMessage,
1321
+ RenderAgentStateMessage,
1322
+ RenderResultMessage,
1323
+ RenderImageMessage
1324
+ }),
1325
+ [
1326
+ RenderTextMessage,
1327
+ RenderActionExecutionMessage,
1328
+ RenderAgentStateMessage,
1329
+ RenderResultMessage,
1330
+ RenderImageMessage
1331
+ ]
1332
+ );
1333
+ const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LegacyRenderMessage, __spreadProps(__spreadValues({}, props), { legacyProps })) : RenderMessage2;
1334
+ const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: icons.activityIcon });
1335
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
1336
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessagesContainer", children: [
1337
+ messages.map((message, index) => {
1338
+ const isCurrentMessage = index === messages.length - 1;
1339
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1340
+ MessageRenderer,
1341
+ {
1342
+ message,
1343
+ messages,
1344
+ inProgress,
1345
+ index,
1346
+ isCurrentMessage,
1347
+ AssistantMessage: AssistantMessage2,
1348
+ UserMessage: UserMessage2,
1349
+ ImageRenderer: ImageRenderer2,
1350
+ onRegenerate,
1351
+ onCopy,
1352
+ onThumbsUp,
1353
+ onThumbsDown,
1354
+ messageFeedback,
1355
+ markdownTagRenderers
1356
+ },
1357
+ index
1358
+ );
1359
+ }),
1360
+ ((_a = messages[messages.length - 1]) == null ? void 0 : _a.role) === "user" && inProgress && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LoadingIcon, {}),
1361
+ interrupt,
1362
+ chatError && ErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ErrorMessage, { error: chatError, isCurrentMessage: true })
1363
+ ] }),
1364
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
1365
+ ] });
1366
+ };
1367
+ function makeInitialMessages(initial) {
1368
+ if (!initial)
1369
+ return [];
1370
+ if (Array.isArray(initial)) {
1371
+ return initial.map((message) => {
1372
+ return {
1373
+ id: message,
1374
+ role: "assistant",
1375
+ content: message
1376
+ };
1377
+ });
1378
+ }
1379
+ return [
1380
+ {
1381
+ id: initial,
1382
+ role: "assistant",
1383
+ content: initial
1384
+ }
1385
+ ];
1386
+ }
1387
+ function useScrollToBottom(messages) {
1388
+ const messagesEndRef = (0, import_react6.useRef)(null);
1389
+ const messagesContainerRef = (0, import_react6.useRef)(null);
1390
+ const isProgrammaticScrollRef = (0, import_react6.useRef)(false);
1391
+ const isUserScrollUpRef = (0, import_react6.useRef)(false);
1392
+ const scrollToBottom = () => {
1393
+ if (messagesContainerRef.current && messagesEndRef.current) {
1394
+ isProgrammaticScrollRef.current = true;
1395
+ messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
1396
+ }
1397
+ };
1398
+ const handleScroll = () => {
1399
+ if (isProgrammaticScrollRef.current) {
1400
+ isProgrammaticScrollRef.current = false;
1401
+ return;
1402
+ }
1403
+ if (messagesContainerRef.current) {
1404
+ const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
1405
+ isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
1406
+ }
1407
+ };
1408
+ (0, import_react6.useEffect)(() => {
1409
+ const container = messagesContainerRef.current;
1410
+ if (container) {
1411
+ container.addEventListener("scroll", handleScroll);
1412
+ }
1413
+ return () => {
1414
+ if (container) {
1415
+ container.removeEventListener("scroll", handleScroll);
1416
+ }
1417
+ };
1418
+ }, []);
1419
+ (0, import_react6.useEffect)(() => {
1420
+ const container = messagesContainerRef.current;
1421
+ if (!container) {
1422
+ return;
1423
+ }
1424
+ const mutationObserver = new MutationObserver(() => {
1425
+ if (!isUserScrollUpRef.current) {
1426
+ scrollToBottom();
1427
+ }
1428
+ });
1429
+ mutationObserver.observe(container, {
1430
+ childList: true,
1431
+ subtree: true,
1432
+ characterData: true
1433
+ });
1434
+ return () => {
1435
+ mutationObserver.disconnect();
1436
+ };
1437
+ }, []);
1438
+ (0, import_react6.useEffect)(() => {
1439
+ isUserScrollUpRef.current = false;
1440
+ scrollToBottom();
1441
+ }, [messages.filter((m) => m.role === "user").length]);
1442
+ return { messagesEndRef, messagesContainerRef };
1443
+ }
1444
+
1445
+ // src/components/chat/Input.tsx
1446
+ var import_react10 = require("react");
1447
+
1448
+ // src/components/chat/Textarea.tsx
1449
+ var import_react7 = require("react");
1450
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1451
+ var AutoResizingTextarea = (0, import_react7.forwardRef)(
1452
+ ({
1453
+ maxRows = 1,
1454
+ placeholder,
1455
+ value,
1456
+ onChange,
1457
+ onKeyDown,
1458
+ onCompositionStart,
1459
+ onCompositionEnd,
1460
+ autoFocus
1461
+ }, ref) => {
1462
+ const internalTextareaRef = (0, import_react7.useRef)(null);
1463
+ const [maxHeight, setMaxHeight] = (0, import_react7.useState)(0);
1464
+ (0, import_react7.useImperativeHandle)(ref, () => internalTextareaRef.current);
1465
+ (0, import_react7.useEffect)(() => {
1466
+ const calculateMaxHeight = () => {
1467
+ const textarea = internalTextareaRef.current;
1468
+ if (textarea) {
1469
+ textarea.style.height = "auto";
1470
+ const singleRowHeight = textarea.scrollHeight;
1471
+ setMaxHeight(singleRowHeight * maxRows);
1472
+ if (autoFocus) {
1473
+ textarea.focus();
1474
+ }
1475
+ }
1476
+ };
1477
+ calculateMaxHeight();
1478
+ }, [maxRows]);
1479
+ (0, import_react7.useEffect)(() => {
1480
+ const textarea = internalTextareaRef.current;
1481
+ if (textarea) {
1482
+ textarea.style.height = "auto";
1483
+ textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
1484
+ }
1485
+ }, [value, maxHeight]);
1486
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1487
+ "textarea",
1488
+ {
1489
+ ref: internalTextareaRef,
1490
+ value,
1491
+ onChange,
1492
+ onKeyDown,
1493
+ onCompositionStart,
1494
+ onCompositionEnd,
1495
+ placeholder,
1496
+ style: {
1497
+ overflow: "auto",
1498
+ resize: "none",
1499
+ maxHeight: `${maxHeight}px`
1500
+ },
1501
+ rows: 1
1502
+ }
1503
+ );
1504
+ }
1505
+ );
1506
+ var Textarea_default = AutoResizingTextarea;
1507
+
1508
+ // src/hooks/use-push-to-talk.tsx
1509
+ var import_react_core2 = require("@copilotkit/react-core");
1510
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1511
+ var import_react8 = require("react");
1512
+ var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
1513
+ if (!mediaStreamRef.current || !audioContextRef.current) {
1514
+ mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
1515
+ audioContextRef.current = new window.AudioContext();
1516
+ yield audioContextRef.current.resume();
1517
+ }
1518
+ mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
1519
+ mediaRecorderRef.current.start(1e3);
1520
+ mediaRecorderRef.current.ondataavailable = (event) => {
1521
+ recordedChunks.push(event.data);
1522
+ };
1523
+ mediaRecorderRef.current.onstop = onStop;
1524
+ });
1525
+ var stopRecording = (mediaRecorderRef) => {
1526
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
1527
+ mediaRecorderRef.current.stop();
1528
+ }
1529
+ };
1530
+ var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
1531
+ const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1532
+ const formData = new FormData();
1533
+ formData.append("file", completeBlob, "recording.mp4");
1534
+ const response = yield fetch(transcribeAudioUrl, {
1535
+ method: "POST",
1536
+ body: formData
1537
+ });
1538
+ if (!response.ok) {
1539
+ throw new Error(`Error: ${response.statusText}`);
1540
+ }
1541
+ const transcription = yield response.json();
1542
+ return transcription.text;
1543
+ });
1544
+ var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
1545
+ const encodedText = encodeURIComponent(text);
1546
+ const url = `${textToSpeechUrl}?text=${encodedText}`;
1547
+ fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
1548
+ const source = audioContext.createBufferSource();
1549
+ source.buffer = audioBuffer;
1550
+ source.connect(audioContext.destination);
1551
+ source.start(0);
1552
+ }).catch((error) => {
1553
+ console.error("Error with decoding audio data", error);
1554
+ });
1555
+ };
1556
+ var usePushToTalk = ({
1557
+ sendFunction,
1558
+ inProgress
1559
+ }) => {
1560
+ const [pushToTalkState, setPushToTalkState] = (0, import_react8.useState)("idle");
1561
+ const mediaStreamRef = (0, import_react8.useRef)(null);
1562
+ const audioContextRef = (0, import_react8.useRef)(null);
1563
+ const mediaRecorderRef = (0, import_react8.useRef)(null);
1564
+ const recordedChunks = (0, import_react8.useRef)([]);
1565
+ const generalContext = (0, import_react_core2.useCopilotContext)();
1566
+ const messagesContext = (0, import_react_core2.useCopilotMessagesContext)();
1567
+ const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1568
+ const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react8.useState)(null);
1569
+ (0, import_react8.useEffect)(() => {
1570
+ if (pushToTalkState === "recording") {
1571
+ startRecording(
1572
+ mediaStreamRef,
1573
+ mediaRecorderRef,
1574
+ audioContextRef,
1575
+ recordedChunks.current,
1576
+ () => {
1577
+ setPushToTalkState("transcribing");
1578
+ }
1579
+ );
1580
+ } else {
1581
+ stopRecording(mediaRecorderRef);
1582
+ if (pushToTalkState === "transcribing") {
1583
+ transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
1584
+ (transcription) => __async(void 0, null, function* () {
1585
+ recordedChunks.current = [];
1586
+ setPushToTalkState("idle");
1587
+ const message = yield sendFunction(transcription);
1588
+ setStartReadingFromMessageId(message.id);
1589
+ })
1590
+ );
1591
+ }
1592
+ }
1593
+ return () => {
1594
+ stopRecording(mediaRecorderRef);
1595
+ };
1596
+ }, [pushToTalkState]);
1597
+ (0, import_react8.useEffect)(() => {
1598
+ if (inProgress === false && startReadingFromMessageId) {
1599
+ const lastMessageIndex = context.messages.findIndex(
1600
+ (message) => message.id === startReadingFromMessageId
1601
+ );
1602
+ const aguiMessages = (0, import_runtime_client_gql2.gqlToAGUI)(context.messages);
1603
+ const messagesAfterLast = aguiMessages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant");
1604
+ const text = messagesAfterLast.map((message) => message.content).join("\n");
1605
+ playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
1606
+ setStartReadingFromMessageId(null);
1607
+ }
1608
+ }, [startReadingFromMessageId, inProgress]);
1609
+ return { pushToTalkState, setPushToTalkState };
1610
+ };
1611
+
1612
+ // src/components/chat/Input.tsx
1613
+ var import_react_core3 = require("@copilotkit/react-core");
1614
+
1615
+ // src/components/chat/PoweredByTag.tsx
1616
+ var import_react9 = require("react");
1617
+
1618
+ // src/hooks/use-dark-mode.ts
1619
+ var useDarkMode = () => {
1620
+ if (typeof window === "undefined")
1621
+ return false;
1622
+ return document.documentElement.classList.contains("dark") || document.body.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || document.body.getAttribute("data-theme") === "dark" || window.matchMedia("(prefers-color-scheme: dark)").matches;
1623
+ };
1624
+
1625
+ // src/components/chat/PoweredByTag.tsx
1626
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1627
+ function PoweredByTag({ showPoweredBy = true }) {
1628
+ const [mounted, setMounted] = (0, import_react9.useState)(false);
1629
+ const isDark = useDarkMode();
1630
+ (0, import_react9.useEffect)(() => {
1631
+ setMounted(true);
1632
+ }, []);
1633
+ if (!showPoweredBy) {
1634
+ return null;
1635
+ }
1636
+ const poweredByStyle = {
1637
+ visibility: "visible",
1638
+ display: "block",
1639
+ position: "static",
1640
+ textAlign: "center",
1641
+ fontSize: "12px",
1642
+ padding: "3px 0",
1643
+ color: mounted && isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)"
1644
+ };
1645
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "poweredBy", style: poweredByStyle, children: "Powered by CopilotKit" }) });
1646
+ }
1647
+
1648
+ // src/components/chat/Input.tsx
1649
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1650
+ var MAX_NEWLINES = 6;
1651
+ var Input = ({
1652
+ inProgress,
1653
+ onSend,
1654
+ chatReady = false,
1655
+ onStop,
1656
+ onUpload,
1657
+ hideStopButton = false
1658
+ }) => {
1659
+ var _a;
1660
+ const context = useChatContext();
1661
+ const copilotContext = (0, import_react_core3.useCopilotContext)();
1662
+ const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
1663
+ const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
1664
+ const textareaRef = (0, import_react10.useRef)(null);
1665
+ const [isComposing, setIsComposing] = (0, import_react10.useState)(false);
1666
+ const handleDivClick = (event) => {
1667
+ var _a2;
1668
+ const target = event.target;
1669
+ if (target.closest("button"))
1670
+ return;
1671
+ if (target.tagName === "TEXTAREA")
1672
+ return;
1673
+ (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
1674
+ };
1675
+ const [text, setText] = (0, import_react10.useState)("");
1676
+ const send = () => {
1677
+ var _a2;
1678
+ if (inProgress)
1679
+ return;
1680
+ onSend(text);
1681
+ setText("");
1682
+ (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
1683
+ };
1684
+ const { pushToTalkState, setPushToTalkState } = usePushToTalk({
1685
+ sendFunction: onSend,
1686
+ inProgress
1687
+ });
1688
+ const isInProgress = inProgress || pushToTalkState === "transcribing";
1689
+ const { buttonIcon, buttonAlt } = (0, import_react10.useMemo)(() => {
1690
+ if (!chatReady)
1691
+ return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
1692
+ return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
1693
+ }, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
1694
+ const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
1695
+ const { interrupt } = (0, import_react_core3.useCopilotChatInternal)();
1696
+ const canSend = (0, import_react10.useMemo)(() => {
1697
+ return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
1698
+ }, [interrupt, isInProgress, text, pushToTalkState]);
1699
+ const canStop = (0, import_react10.useMemo)(() => {
1700
+ return isInProgress && !hideStopButton;
1701
+ }, [isInProgress, hideStopButton]);
1702
+ const sendDisabled = !canSend && !canStop;
1703
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`, children: [
1704
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
1705
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1706
+ Textarea_default,
1707
+ {
1708
+ ref: textareaRef,
1709
+ placeholder: context.labels.placeholder,
1710
+ autoFocus: false,
1711
+ maxRows: MAX_NEWLINES,
1712
+ value: text,
1713
+ onChange: (event) => setText(event.target.value),
1714
+ onCompositionStart: () => setIsComposing(true),
1715
+ onCompositionEnd: () => setIsComposing(false),
1716
+ onKeyDown: (event) => {
1717
+ if (event.key === "Enter" && !event.shiftKey && !isComposing) {
1718
+ event.preventDefault();
1719
+ if (canSend) {
1720
+ send();
1721
+ }
1722
+ }
1723
+ }
1724
+ }
1725
+ ),
1726
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitInputControls", children: [
1727
+ onUpload && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
1728
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { flexGrow: 1 } }),
1729
+ showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1730
+ "button",
1731
+ {
1732
+ onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
1733
+ className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
1734
+ children: context.icons.pushToTalkIcon
1735
+ }
1736
+ ),
1737
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1738
+ "button",
1739
+ {
1740
+ disabled: sendDisabled,
1741
+ onClick: isInProgress && !hideStopButton ? onStop : send,
1742
+ "data-copilotkit-in-progress": inProgress,
1743
+ "data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
1744
+ className: "copilotKitInputControlButton",
1745
+ "aria-label": buttonAlt,
1746
+ children: buttonIcon
1747
+ }
1748
+ )
1749
+ ] })
1750
+ ] }),
1751
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(PoweredByTag, { showPoweredBy })
1752
+ ] });
1753
+ };
1754
+
1755
+ // src/components/chat/Chat.tsx
1756
+ var import_react11 = __toESM(require("react"));
1757
+ var import_react_core5 = require("@copilotkit/react-core");
1758
+ var import_shared = require("@copilotkit/shared");
1759
+
1760
+ // src/components/chat/ImageUploadQueue.tsx
1761
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1762
+ var ImageUploadQueue = ({
1763
+ images,
1764
+ onRemoveImage,
1765
+ className = ""
1766
+ }) => {
1767
+ if (images.length === 0)
1768
+ return null;
1769
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1770
+ "div",
1771
+ {
1772
+ className: `copilotKitImageUploadQueue ${className}`,
1773
+ style: {
1774
+ display: "flex",
1775
+ flexWrap: "wrap",
1776
+ gap: "8px",
1777
+ margin: "8px",
1778
+ padding: "8px"
1779
+ },
1780
+ children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1781
+ "div",
1782
+ {
1783
+ className: "copilotKitImageUploadQueueItem",
1784
+ style: {
1785
+ position: "relative",
1786
+ display: "inline-block",
1787
+ width: "60px",
1788
+ height: "60px",
1789
+ borderRadius: "4px",
1790
+ overflow: "hidden"
1791
+ },
1792
+ children: [
1793
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1794
+ "img",
1795
+ {
1796
+ src: `data:${image.contentType};base64,${image.bytes}`,
1797
+ alt: `Selected image ${index + 1}`,
1798
+ style: {
1799
+ width: "100%",
1800
+ height: "100%",
1801
+ objectFit: "cover"
1802
+ }
1803
+ }
1804
+ ),
1805
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1806
+ "button",
1807
+ {
1808
+ onClick: () => onRemoveImage(index),
1809
+ className: "copilotKitImageUploadQueueRemoveButton",
1810
+ style: {
1811
+ position: "absolute",
1812
+ top: "2px",
1813
+ right: "2px",
1814
+ background: "rgba(0,0,0,0.6)",
1815
+ color: "white",
1816
+ border: "none",
1817
+ borderRadius: "50%",
1818
+ width: "18px",
1819
+ height: "18px",
1820
+ display: "flex",
1821
+ alignItems: "center",
1822
+ justifyContent: "center",
1823
+ cursor: "pointer",
1824
+ fontSize: "10px",
1825
+ padding: 0
1826
+ },
1827
+ children: "\u2715"
1828
+ }
1829
+ )
1830
+ ]
1831
+ },
1832
+ index
1833
+ ))
1834
+ }
1835
+ );
1836
+ };
1837
+
1838
+ // src/components/chat/Suggestion.tsx
1839
+ var import_react_core4 = require("@copilotkit/react-core");
1840
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1841
+ function Suggestion({ title, onClick, partial, className }) {
1842
+ if (!title)
1843
+ return null;
1844
+ const { isLoading } = (0, import_react_core4.useCopilotChatInternal)();
1845
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1846
+ "button",
1847
+ {
1848
+ disabled: partial || isLoading,
1849
+ onClick: (e) => {
1850
+ e.preventDefault();
1851
+ onClick();
1852
+ },
1853
+ className: className || (partial ? "suggestion loading" : "suggestion"),
1854
+ "data-test-id": "suggestion",
1855
+ children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: title })
1856
+ }
1857
+ );
1858
+ }
1859
+
1860
+ // src/components/chat/Suggestions.tsx
1861
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1862
+ function Suggestions({
1863
+ suggestions,
1864
+ onSuggestionClick,
1865
+ isLoading
1866
+ }) {
1867
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => {
1868
+ var _a, _b;
1869
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1870
+ Suggestion,
1871
+ {
1872
+ title: suggestion.title,
1873
+ message: suggestion.message,
1874
+ partial: (_b = (_a = suggestion.isLoading) != null ? _a : suggestion.partial) != null ? _b : isLoading,
1875
+ className: suggestion.className,
1876
+ onClick: () => onSuggestionClick(suggestion.message)
1877
+ },
1878
+ index
1879
+ );
1880
+ }) });
1881
+ }
1882
+
1883
+ // src/components/chat/Chat.tsx
1884
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1885
+ function CopilotChat({
1886
+ instructions,
1887
+ suggestions = "auto",
1888
+ onSubmitMessage,
1889
+ makeSystemMessage,
1890
+ disableSystemMessage,
1891
+ onInProgress,
1892
+ onStopGeneration,
1893
+ onReloadMessages,
1894
+ onRegenerate,
1895
+ onCopy,
1896
+ onThumbsUp,
1897
+ onThumbsDown,
1898
+ markdownTagRenderers,
1899
+ Messages: Messages2 = Messages,
1900
+ RenderMessage: RenderMessage2 = RenderMessage,
1901
+ RenderSuggestionsList = Suggestions,
1902
+ Input: Input2 = Input,
1903
+ className,
1904
+ icons,
1905
+ labels,
1906
+ AssistantMessage: AssistantMessage2 = AssistantMessage,
1907
+ UserMessage: UserMessage2 = UserMessage,
1908
+ ImageRenderer: ImageRenderer2 = ImageRenderer,
1909
+ ErrorMessage,
1910
+ imageUploadsEnabled,
1911
+ inputFileAccept = "image/*",
1912
+ hideStopButton,
1913
+ observabilityHooks,
1914
+ renderError,
1915
+ onError,
1916
+ // Legacy props - deprecated
1917
+ RenderTextMessage,
1918
+ RenderActionExecutionMessage,
1919
+ RenderAgentStateMessage,
1920
+ RenderResultMessage,
1921
+ RenderImageMessage
1922
+ }) {
1923
+ const {
1924
+ additionalInstructions,
1925
+ setChatInstructions,
1926
+ copilotApiConfig,
1927
+ setBannerError,
1928
+ setInternalErrorHandler,
1929
+ removeInternalErrorHandler
1930
+ } = (0, import_react_core5.useCopilotContext)();
1931
+ const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
1932
+ const [selectedImages, setSelectedImages] = (0, import_react11.useState)([]);
1933
+ const [chatError, setChatError] = (0, import_react11.useState)(null);
1934
+ const [messageFeedback, setMessageFeedback] = (0, import_react11.useState)(
1935
+ {}
1936
+ );
1937
+ const fileInputRef = (0, import_react11.useRef)(null);
1938
+ const triggerObservabilityHook = (0, import_react11.useCallback)(
1939
+ (hookName, ...args) => {
1940
+ if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
1941
+ observabilityHooks[hookName](...args);
1942
+ }
1943
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
1944
+ setBannerError(
1945
+ new import_shared.CopilotKitError({
1946
+ message: "observabilityHooks requires a publicApiKey to function.",
1947
+ code: import_shared.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
1948
+ severity: import_shared.Severity.CRITICAL,
1949
+ visibility: import_shared.ErrorVisibility.BANNER
1950
+ })
1951
+ );
1952
+ import_shared.styledConsole.publicApiKeyRequired("observabilityHooks");
1953
+ }
1954
+ },
1955
+ [publicApiKey, observabilityHooks, setBannerError]
1956
+ );
1957
+ const triggerChatError = (0, import_react11.useCallback)(
1958
+ (error, operation, originalError) => {
1959
+ const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
1960
+ setChatError({
1961
+ message: errorMessage,
1962
+ operation,
1963
+ timestamp: Date.now()
1964
+ });
1965
+ const errorEvent = {
1966
+ type: "error",
1967
+ timestamp: Date.now(),
1968
+ context: {
1969
+ source: "ui",
1970
+ request: {
1971
+ operation,
1972
+ url: chatApiEndpoint,
1973
+ startTime: Date.now()
1974
+ },
1975
+ technical: {
1976
+ environment: "browser",
1977
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
1978
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
1979
+ }
1980
+ },
1981
+ error
1982
+ };
1983
+ if (onError) {
1984
+ onError(errorEvent);
1985
+ }
1986
+ if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
1987
+ observabilityHooks.onError(errorEvent);
1988
+ }
1989
+ if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
1990
+ setBannerError(
1991
+ new import_shared.CopilotKitError({
1992
+ message: "observabilityHooks.onError requires a publicApiKey to function.",
1993
+ code: import_shared.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
1994
+ severity: import_shared.Severity.CRITICAL,
1995
+ visibility: import_shared.ErrorVisibility.BANNER
1996
+ })
1997
+ );
1998
+ import_shared.styledConsole.publicApiKeyRequired("observabilityHooks.onError");
1999
+ }
2000
+ },
2001
+ [publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
2002
+ );
2003
+ (0, import_react11.useEffect)(() => {
2004
+ const id = "chat-component";
2005
+ setInternalErrorHandler({
2006
+ [id]: (error) => {
2007
+ if (!error)
2008
+ return;
2009
+ triggerChatError(error.error, "sendMessage");
2010
+ }
2011
+ });
2012
+ return () => {
2013
+ removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
2014
+ };
2015
+ }, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
2016
+ (0, import_react11.useEffect)(() => {
2017
+ if (!imageUploadsEnabled)
2018
+ return;
2019
+ const handlePaste = (e) => __async(this, null, function* () {
2020
+ var _a, _b;
2021
+ const target = e.target;
2022
+ if (!((_a = target.parentElement) == null ? void 0 : _a.classList.contains("copilotKitInput")))
2023
+ return;
2024
+ const items = Array.from(((_b = e.clipboardData) == null ? void 0 : _b.items) || []);
2025
+ const imageItems = items.filter((item) => item.type.startsWith("image/"));
2026
+ if (imageItems.length === 0)
2027
+ return;
2028
+ e.preventDefault();
2029
+ const imagePromises = imageItems.map((item) => {
2030
+ const file = item.getAsFile();
2031
+ if (!file)
2032
+ return Promise.resolve(null);
2033
+ return new Promise((resolve, reject) => {
2034
+ const reader = new FileReader();
2035
+ reader.onload = (e2) => {
2036
+ var _a2, _b2;
2037
+ const base64String = (_b2 = (_a2 = e2.target) == null ? void 0 : _a2.result) == null ? void 0 : _b2.split(",")[1];
2038
+ if (base64String) {
2039
+ resolve({
2040
+ contentType: file.type,
2041
+ bytes: base64String
2042
+ });
2043
+ } else {
2044
+ resolve(null);
2045
+ }
2046
+ };
2047
+ reader.onerror = reject;
2048
+ reader.readAsDataURL(file);
2049
+ });
2050
+ });
2051
+ try {
2052
+ const loadedImages = (yield Promise.all(imagePromises)).filter((img) => img !== null);
2053
+ setSelectedImages((prev) => [...prev, ...loadedImages]);
2054
+ } catch (error) {
2055
+ triggerChatError(error, "processClipboardImages", error);
2056
+ console.error("Error processing pasted images:", error);
2057
+ }
2058
+ });
2059
+ document.addEventListener("paste", handlePaste);
2060
+ return () => document.removeEventListener("paste", handlePaste);
2061
+ }, [imageUploadsEnabled, triggerChatError]);
2062
+ (0, import_react11.useEffect)(() => {
2063
+ if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
2064
+ setChatInstructions(instructions || "");
2065
+ return;
2066
+ }
2067
+ const combinedAdditionalInstructions = [
2068
+ instructions,
2069
+ "Additionally, follow these instructions:",
2070
+ ...additionalInstructions.map((instruction) => `- ${instruction}`)
2071
+ ];
2072
+ setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
2073
+ }, [instructions, additionalInstructions]);
2074
+ const {
2075
+ messages,
2076
+ isLoading,
2077
+ sendMessage,
2078
+ stopGeneration,
2079
+ reloadMessages,
2080
+ suggestions: currentSuggestions,
2081
+ isLoadingSuggestions,
2082
+ agent
2083
+ } = (0, import_react_core5.useCopilotChatInternal)({
2084
+ suggestions,
2085
+ onInProgress,
2086
+ onSubmitMessage,
2087
+ onStopGeneration,
2088
+ onReloadMessages
2089
+ });
2090
+ const prevIsLoading = (0, import_react11.useRef)(isLoading);
2091
+ (0, import_react11.useEffect)(() => {
2092
+ if (prevIsLoading.current !== isLoading) {
2093
+ if (isLoading) {
2094
+ triggerObservabilityHook("onChatStarted");
2095
+ } else {
2096
+ triggerObservabilityHook("onChatStopped");
2097
+ }
2098
+ prevIsLoading.current = isLoading;
2099
+ }
2100
+ }, [isLoading, triggerObservabilityHook]);
2101
+ const handleSendMessage = (text) => {
2102
+ const images = selectedImages;
2103
+ setSelectedImages([]);
2104
+ if (fileInputRef.current) {
2105
+ fileInputRef.current.value = "";
2106
+ }
2107
+ triggerObservabilityHook("onMessageSent", text);
2108
+ return sendMessage({
2109
+ id: (0, import_shared.randomUUID)(),
2110
+ content: text,
2111
+ role: "user"
2112
+ });
2113
+ };
2114
+ const chatContext = import_react11.default.useContext(ChatContext);
2115
+ const isVisible = chatContext ? chatContext.open : true;
2116
+ const handleRegenerate = (messageId) => {
2117
+ if (onRegenerate) {
2118
+ onRegenerate(messageId);
2119
+ }
2120
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2121
+ reloadMessages(messageId);
2122
+ };
2123
+ const handleCopy = (message) => {
2124
+ if (onCopy) {
2125
+ onCopy(message);
2126
+ }
2127
+ triggerObservabilityHook("onMessageCopied", message);
2128
+ };
2129
+ const handleImageUpload = (event) => __async(this, null, function* () {
2130
+ if (!event.target.files || event.target.files.length === 0) {
2131
+ return;
2132
+ }
2133
+ const files = Array.from(event.target.files).filter((file) => file.type.startsWith("image/"));
2134
+ if (files.length === 0)
2135
+ return;
2136
+ const fileReadPromises = files.map((file) => {
2137
+ return new Promise((resolve, reject) => {
2138
+ const reader = new FileReader();
2139
+ reader.onload = (e) => {
2140
+ var _a, _b;
2141
+ const base64String = ((_b = (_a = e.target) == null ? void 0 : _a.result) == null ? void 0 : _b.split(",")[1]) || "";
2142
+ if (base64String) {
2143
+ resolve({
2144
+ contentType: file.type,
2145
+ bytes: base64String
2146
+ });
2147
+ }
2148
+ };
2149
+ reader.onerror = reject;
2150
+ reader.readAsDataURL(file);
2151
+ });
2152
+ });
2153
+ try {
2154
+ const loadedImages = yield Promise.all(fileReadPromises);
2155
+ setSelectedImages((prev) => [...prev, ...loadedImages]);
2156
+ } catch (error) {
2157
+ triggerChatError(error, "processUploadedImages", error);
2158
+ console.error("Error reading files:", error);
2159
+ }
2160
+ });
2161
+ const removeSelectedImage = (index) => {
2162
+ setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2163
+ };
2164
+ const handleThumbsUp = (message) => {
2165
+ if (onThumbsUp) {
2166
+ onThumbsUp(message);
2167
+ }
2168
+ setMessageFeedback((prev) => __spreadProps(__spreadValues({}, prev), {
2169
+ [message.id]: "thumbsUp"
2170
+ }));
2171
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2172
+ };
2173
+ const handleThumbsDown = (message) => {
2174
+ if (onThumbsDown) {
2175
+ onThumbsDown(message);
2176
+ }
2177
+ setMessageFeedback((prev) => __spreadProps(__spreadValues({}, prev), {
2178
+ [message.id]: "thumbsDown"
2179
+ }));
2180
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2181
+ };
2182
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2183
+ chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
2184
+ onDismiss: () => setChatError(null),
2185
+ onRetry: () => {
2186
+ setChatError(null);
2187
+ }
2188
+ })),
2189
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2190
+ Messages2,
2191
+ {
2192
+ AssistantMessage: AssistantMessage2,
2193
+ UserMessage: UserMessage2,
2194
+ RenderMessage: RenderMessage2,
2195
+ messages,
2196
+ inProgress: isLoading,
2197
+ onRegenerate: handleRegenerate,
2198
+ onCopy: handleCopy,
2199
+ onThumbsUp: handleThumbsUp,
2200
+ onThumbsDown: handleThumbsDown,
2201
+ messageFeedback,
2202
+ markdownTagRenderers,
2203
+ ImageRenderer: ImageRenderer2,
2204
+ ErrorMessage,
2205
+ chatError,
2206
+ RenderTextMessage,
2207
+ RenderActionExecutionMessage,
2208
+ RenderAgentStateMessage,
2209
+ RenderResultMessage,
2210
+ RenderImageMessage,
2211
+ children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2212
+ RenderSuggestionsList,
2213
+ {
2214
+ onSuggestionClick: handleSendMessage,
2215
+ suggestions: currentSuggestions,
2216
+ isLoading: isLoadingSuggestions
2217
+ }
2218
+ )
2219
+ }
2220
+ ),
2221
+ imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
2222
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
2223
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2224
+ "input",
2225
+ {
2226
+ type: "file",
2227
+ multiple: true,
2228
+ ref: fileInputRef,
2229
+ onChange: handleImageUpload,
2230
+ accept: inputFileAccept,
2231
+ style: { display: "none" }
2232
+ }
2233
+ )
2234
+ ] }),
2235
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2236
+ Input2,
2237
+ {
2238
+ inProgress: isLoading,
2239
+ chatReady: Boolean(agent),
2240
+ onSend: handleSendMessage,
2241
+ isVisible,
2242
+ onStop: stopGeneration,
2243
+ onUpload: imageUploadsEnabled ? () => {
2244
+ var _a;
2245
+ return (_a = fileInputRef.current) == null ? void 0 : _a.click();
2246
+ } : void 0,
2247
+ hideStopButton
2248
+ }
2249
+ )
2250
+ ] });
2251
+ }
2252
+ function WrappedCopilotChat({
2253
+ children,
2254
+ icons,
2255
+ labels,
2256
+ className
2257
+ }) {
2258
+ const chatContext = import_react11.default.useContext(ChatContext);
2259
+ if (!chatContext) {
2260
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
2261
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
2262
+ }
2263
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children });
2264
+ }
2265
+ // Annotate the CommonJS export names for ESM import in node:
2266
+ 0 && (module.exports = {
2267
+ CopilotChat,
2268
+ WrappedCopilotChat
2269
+ });
2270
+ //# sourceMappingURL=Chat.js.map