@copilotkit/react-ui 1.51.5-next.0 → 1.51.5-next.2

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 (339) hide show
  1. package/.attw.json +3 -0
  2. package/CHANGELOG.md +17 -0
  3. package/dist/index.cjs +2737 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.css +258 -70
  6. package/dist/index.css.map +1 -1
  7. package/dist/index.d.cts +781 -0
  8. package/dist/index.d.cts.map +1 -0
  9. package/dist/index.d.mts +781 -0
  10. package/dist/index.d.mts.map +1 -0
  11. package/dist/index.mjs +2685 -81
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/index.umd.js +2750 -25
  14. package/dist/index.umd.js.map +1 -1
  15. package/package.json +19 -18
  16. package/src/components/chat/Popup.tsx +1 -1
  17. package/src/components/chat/Sidebar.tsx +1 -1
  18. package/tsdown.config.ts +58 -0
  19. package/vitest.config.mjs +11 -0
  20. package/dist/chunk-2QEDCM6H.mjs +0 -150
  21. package/dist/chunk-2QEDCM6H.mjs.map +0 -1
  22. package/dist/chunk-6SMTHXVA.mjs +0 -28
  23. package/dist/chunk-6SMTHXVA.mjs.map +0 -1
  24. package/dist/chunk-6TLDRWAD.mjs +0 -95
  25. package/dist/chunk-6TLDRWAD.mjs.map +0 -1
  26. package/dist/chunk-72FQQMQ2.mjs +0 -25
  27. package/dist/chunk-72FQQMQ2.mjs.map +0 -1
  28. package/dist/chunk-AOUHT4JR.mjs +0 -34
  29. package/dist/chunk-AOUHT4JR.mjs.map +0 -1
  30. package/dist/chunk-BNJX66OH.mjs +0 -118
  31. package/dist/chunk-BNJX66OH.mjs.map +0 -1
  32. package/dist/chunk-C27LZFA5.mjs +0 -97
  33. package/dist/chunk-C27LZFA5.mjs.map +0 -1
  34. package/dist/chunk-C7WM7GM3.mjs +0 -235
  35. package/dist/chunk-C7WM7GM3.mjs.map +0 -1
  36. package/dist/chunk-CNIC5HO5.mjs +0 -36
  37. package/dist/chunk-CNIC5HO5.mjs.map +0 -1
  38. package/dist/chunk-CQCXH5LY.mjs +0 -143
  39. package/dist/chunk-CQCXH5LY.mjs.map +0 -1
  40. package/dist/chunk-DM2V5WTG.mjs +0 -34
  41. package/dist/chunk-DM2V5WTG.mjs.map +0 -1
  42. package/dist/chunk-DSHTRV2R.mjs +0 -140
  43. package/dist/chunk-DSHTRV2R.mjs.map +0 -1
  44. package/dist/chunk-EACIYBQH.mjs +0 -32
  45. package/dist/chunk-EACIYBQH.mjs.map +0 -1
  46. package/dist/chunk-EFZPSZWO.mjs +0 -1
  47. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  48. package/dist/chunk-GBAPANZE.mjs +0 -323
  49. package/dist/chunk-GBAPANZE.mjs.map +0 -1
  50. package/dist/chunk-GFE5ZSPV.mjs +0 -112
  51. package/dist/chunk-GFE5ZSPV.mjs.map +0 -1
  52. package/dist/chunk-HHLX4MQN.mjs +0 -31
  53. package/dist/chunk-HHLX4MQN.mjs.map +0 -1
  54. package/dist/chunk-ICA2EXIX.mjs +0 -187
  55. package/dist/chunk-ICA2EXIX.mjs.map +0 -1
  56. package/dist/chunk-IU3WTXLQ.mjs +0 -1
  57. package/dist/chunk-IU3WTXLQ.mjs.map +0 -1
  58. package/dist/chunk-IWOCQACI.mjs +0 -73
  59. package/dist/chunk-IWOCQACI.mjs.map +0 -1
  60. package/dist/chunk-JGMFJZMG.mjs +0 -11
  61. package/dist/chunk-JGMFJZMG.mjs.map +0 -1
  62. package/dist/chunk-JYHRHKV5.mjs +0 -90
  63. package/dist/chunk-JYHRHKV5.mjs.map +0 -1
  64. package/dist/chunk-KXE2JCUH.mjs +0 -1
  65. package/dist/chunk-KXE2JCUH.mjs.map +0 -1
  66. package/dist/chunk-LIXN3OVQ.mjs +0 -405
  67. package/dist/chunk-LIXN3OVQ.mjs.map +0 -1
  68. package/dist/chunk-MC6PY7XH.mjs +0 -456
  69. package/dist/chunk-MC6PY7XH.mjs.map +0 -1
  70. package/dist/chunk-MMVDU6DF.mjs +0 -1
  71. package/dist/chunk-MMVDU6DF.mjs.map +0 -1
  72. package/dist/chunk-MRXNTQOX.mjs +0 -59
  73. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  74. package/dist/chunk-OQWEOBRX.mjs +0 -120
  75. package/dist/chunk-OQWEOBRX.mjs.map +0 -1
  76. package/dist/chunk-P34CL4LC.mjs +0 -82
  77. package/dist/chunk-P34CL4LC.mjs.map +0 -1
  78. package/dist/chunk-PF3QBO7V.mjs +0 -133
  79. package/dist/chunk-PF3QBO7V.mjs.map +0 -1
  80. package/dist/chunk-PLHTVHUW.mjs +0 -82
  81. package/dist/chunk-PLHTVHUW.mjs.map +0 -1
  82. package/dist/chunk-PP2A5RP6.mjs +0 -21
  83. package/dist/chunk-PP2A5RP6.mjs.map +0 -1
  84. package/dist/chunk-Q64GLWPQ.mjs +0 -30
  85. package/dist/chunk-Q64GLWPQ.mjs.map +0 -1
  86. package/dist/chunk-SC6JRFAJ.mjs +0 -1
  87. package/dist/chunk-SC6JRFAJ.mjs.map +0 -1
  88. package/dist/chunk-T26KLXLH.mjs +0 -1
  89. package/dist/chunk-T26KLXLH.mjs.map +0 -1
  90. package/dist/chunk-T4NNQG6T.mjs +0 -231
  91. package/dist/chunk-T4NNQG6T.mjs.map +0 -1
  92. package/dist/chunk-TGM5PKBF.mjs +0 -44
  93. package/dist/chunk-TGM5PKBF.mjs.map +0 -1
  94. package/dist/chunk-V7W6IM2V.mjs +0 -1
  95. package/dist/chunk-V7W6IM2V.mjs.map +0 -1
  96. package/dist/chunk-WB3YULQ4.mjs +0 -1
  97. package/dist/chunk-WB3YULQ4.mjs.map +0 -1
  98. package/dist/chunk-Y4FKRAKJ.mjs +0 -12
  99. package/dist/chunk-Y4FKRAKJ.mjs.map +0 -1
  100. package/dist/chunk-YDJ4YUUF.mjs +0 -141
  101. package/dist/chunk-YDJ4YUUF.mjs.map +0 -1
  102. package/dist/components/chat/Button.d.ts +0 -9
  103. package/dist/components/chat/Button.js +0 -73
  104. package/dist/components/chat/Button.js.map +0 -1
  105. package/dist/components/chat/Button.mjs +0 -10
  106. package/dist/components/chat/Button.mjs.map +0 -1
  107. package/dist/components/chat/Chat.d.ts +0 -204
  108. package/dist/components/chat/Chat.js +0 -2428
  109. package/dist/components/chat/Chat.js.map +0 -1
  110. package/dist/components/chat/Chat.mjs +0 -29
  111. package/dist/components/chat/Chat.mjs.map +0 -1
  112. package/dist/components/chat/ChatContext.d.ts +0 -145
  113. package/dist/components/chat/ChatContext.js +0 -383
  114. package/dist/components/chat/ChatContext.js.map +0 -1
  115. package/dist/components/chat/ChatContext.mjs +0 -13
  116. package/dist/components/chat/ChatContext.mjs.map +0 -1
  117. package/dist/components/chat/CodeBlock.d.ts +0 -14
  118. package/dist/components/chat/CodeBlock.js +0 -524
  119. package/dist/components/chat/CodeBlock.js.map +0 -1
  120. package/dist/components/chat/CodeBlock.mjs +0 -14
  121. package/dist/components/chat/CodeBlock.mjs.map +0 -1
  122. package/dist/components/chat/Header.d.ts +0 -9
  123. package/dist/components/chat/Header.js +0 -642
  124. package/dist/components/chat/Header.js.map +0 -1
  125. package/dist/components/chat/Header.mjs +0 -17
  126. package/dist/components/chat/Header.mjs.map +0 -1
  127. package/dist/components/chat/Icons.d.ts +0 -20
  128. package/dist/components/chat/Icons.js +0 -362
  129. package/dist/components/chat/Icons.js.map +0 -1
  130. package/dist/components/chat/Icons.mjs +0 -38
  131. package/dist/components/chat/Icons.mjs.map +0 -1
  132. package/dist/components/chat/ImageUploadQueue.d.ts +0 -13
  133. package/dist/components/chat/ImageUploadQueue.js +0 -106
  134. package/dist/components/chat/ImageUploadQueue.js.map +0 -1
  135. package/dist/components/chat/ImageUploadQueue.mjs +0 -8
  136. package/dist/components/chat/ImageUploadQueue.mjs.map +0 -1
  137. package/dist/components/chat/Input.d.ts +0 -9
  138. package/dist/components/chat/Input.js +0 -424
  139. package/dist/components/chat/Input.js.map +0 -1
  140. package/dist/components/chat/Input.mjs +0 -14
  141. package/dist/components/chat/Input.mjs.map +0 -1
  142. package/dist/components/chat/Markdown.d.ts +0 -10
  143. package/dist/components/chat/Markdown.js +0 -678
  144. package/dist/components/chat/Markdown.js.map +0 -1
  145. package/dist/components/chat/Markdown.mjs +0 -11
  146. package/dist/components/chat/Markdown.mjs.map +0 -1
  147. package/dist/components/chat/Messages.d.ts +0 -13
  148. package/dist/components/chat/Messages.js +0 -1242
  149. package/dist/components/chat/Messages.js.map +0 -1
  150. package/dist/components/chat/Messages.mjs +0 -20
  151. package/dist/components/chat/Messages.mjs.map +0 -1
  152. package/dist/components/chat/Modal.d.ts +0 -51
  153. package/dist/components/chat/Modal.js +0 -3294
  154. package/dist/components/chat/Modal.js.map +0 -1
  155. package/dist/components/chat/Modal.mjs +0 -38
  156. package/dist/components/chat/Modal.mjs.map +0 -1
  157. package/dist/components/chat/Popup.d.ts +0 -13
  158. package/dist/components/chat/Popup.js +0 -3305
  159. package/dist/components/chat/Popup.js.map +0 -1
  160. package/dist/components/chat/Popup.mjs +0 -39
  161. package/dist/components/chat/Popup.mjs.map +0 -1
  162. package/dist/components/chat/PoweredByTag.d.ts +0 -7
  163. package/dist/components/chat/PoweredByTag.js +0 -63
  164. package/dist/components/chat/PoweredByTag.js.map +0 -1
  165. package/dist/components/chat/PoweredByTag.mjs +0 -9
  166. package/dist/components/chat/PoweredByTag.mjs.map +0 -1
  167. package/dist/components/chat/Sidebar.d.ts +0 -13
  168. package/dist/components/chat/Sidebar.js +0 -3314
  169. package/dist/components/chat/Sidebar.js.map +0 -1
  170. package/dist/components/chat/Sidebar.mjs +0 -39
  171. package/dist/components/chat/Sidebar.mjs.map +0 -1
  172. package/dist/components/chat/Suggestion.d.ts +0 -12
  173. package/dist/components/chat/Suggestion.js +0 -68
  174. package/dist/components/chat/Suggestion.js.map +0 -1
  175. package/dist/components/chat/Suggestion.mjs +0 -9
  176. package/dist/components/chat/Suggestion.mjs.map +0 -1
  177. package/dist/components/chat/Suggestions.d.ts +0 -9
  178. package/dist/components/chat/Suggestions.js +0 -93
  179. package/dist/components/chat/Suggestions.js.map +0 -1
  180. package/dist/components/chat/Suggestions.mjs +0 -10
  181. package/dist/components/chat/Suggestions.mjs.map +0 -1
  182. package/dist/components/chat/Textarea.d.ts +0 -15
  183. package/dist/components/chat/Textarea.js +0 -87
  184. package/dist/components/chat/Textarea.js.map +0 -1
  185. package/dist/components/chat/Textarea.mjs +0 -8
  186. package/dist/components/chat/Textarea.mjs.map +0 -1
  187. package/dist/components/chat/Window.d.ts +0 -9
  188. package/dist/components/chat/Window.js +0 -166
  189. package/dist/components/chat/Window.js.map +0 -1
  190. package/dist/components/chat/Window.mjs +0 -10
  191. package/dist/components/chat/Window.mjs.map +0 -1
  192. package/dist/components/chat/index.d.ts +0 -18
  193. package/dist/components/chat/index.js +0 -3341
  194. package/dist/components/chat/index.js.map +0 -1
  195. package/dist/components/chat/index.mjs +0 -69
  196. package/dist/components/chat/index.mjs.map +0 -1
  197. package/dist/components/chat/messages/AssistantMessage.d.ts +0 -9
  198. package/dist/components/chat/messages/AssistantMessage.js +0 -807
  199. package/dist/components/chat/messages/AssistantMessage.js.map +0 -1
  200. package/dist/components/chat/messages/AssistantMessage.mjs +0 -13
  201. package/dist/components/chat/messages/AssistantMessage.mjs.map +0 -1
  202. package/dist/components/chat/messages/ErrorMessage.d.ts +0 -9
  203. package/dist/components/chat/messages/ErrorMessage.js +0 -756
  204. package/dist/components/chat/messages/ErrorMessage.js.map +0 -1
  205. package/dist/components/chat/messages/ErrorMessage.mjs +0 -72
  206. package/dist/components/chat/messages/ErrorMessage.mjs.map +0 -1
  207. package/dist/components/chat/messages/ImageRenderer.d.ts +0 -12
  208. package/dist/components/chat/messages/ImageRenderer.js +0 -68
  209. package/dist/components/chat/messages/ImageRenderer.js.map +0 -1
  210. package/dist/components/chat/messages/ImageRenderer.mjs +0 -8
  211. package/dist/components/chat/messages/ImageRenderer.mjs.map +0 -1
  212. package/dist/components/chat/messages/LegacyRenderMessage.d.ts +0 -28
  213. package/dist/components/chat/messages/LegacyRenderMessage.js +0 -1067
  214. package/dist/components/chat/messages/LegacyRenderMessage.js.map +0 -1
  215. package/dist/components/chat/messages/LegacyRenderMessage.mjs +0 -17
  216. package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +0 -1
  217. package/dist/components/chat/messages/RenderMessage.d.ts +0 -9
  218. package/dist/components/chat/messages/RenderMessage.js +0 -942
  219. package/dist/components/chat/messages/RenderMessage.js.map +0 -1
  220. package/dist/components/chat/messages/RenderMessage.mjs +0 -16
  221. package/dist/components/chat/messages/RenderMessage.mjs.map +0 -1
  222. package/dist/components/chat/messages/UserMessage.d.ts +0 -9
  223. package/dist/components/chat/messages/UserMessage.js +0 -58
  224. package/dist/components/chat/messages/UserMessage.js.map +0 -1
  225. package/dist/components/chat/messages/UserMessage.mjs +0 -8
  226. package/dist/components/chat/messages/UserMessage.mjs.map +0 -1
  227. package/dist/components/chat/props.d.ts +0 -298
  228. package/dist/components/chat/props.js +0 -19
  229. package/dist/components/chat/props.js.map +0 -1
  230. package/dist/components/chat/props.mjs +0 -2
  231. package/dist/components/chat/props.mjs.map +0 -1
  232. package/dist/components/dev-console/console.d.ts +0 -11
  233. package/dist/components/dev-console/console.js +0 -595
  234. package/dist/components/dev-console/console.js.map +0 -1
  235. package/dist/components/dev-console/console.mjs +0 -17
  236. package/dist/components/dev-console/console.mjs.map +0 -1
  237. package/dist/components/dev-console/icons.d.ts +0 -9
  238. package/dist/components/dev-console/icons.js +0 -140
  239. package/dist/components/dev-console/icons.js.map +0 -1
  240. package/dist/components/dev-console/icons.mjs +0 -16
  241. package/dist/components/dev-console/icons.mjs.map +0 -1
  242. package/dist/components/dev-console/index.d.ts +0 -3
  243. package/dist/components/dev-console/index.js +0 -595
  244. package/dist/components/dev-console/index.js.map +0 -1
  245. package/dist/components/dev-console/index.mjs +0 -18
  246. package/dist/components/dev-console/index.mjs.map +0 -1
  247. package/dist/components/dev-console/types.d.ts +0 -9
  248. package/dist/components/dev-console/types.js +0 -19
  249. package/dist/components/dev-console/types.js.map +0 -1
  250. package/dist/components/dev-console/types.mjs +0 -1
  251. package/dist/components/dev-console/types.mjs.map +0 -1
  252. package/dist/components/dev-console/utils.d.ts +0 -10
  253. package/dist/components/dev-console/utils.js +0 -183
  254. package/dist/components/dev-console/utils.js.map +0 -1
  255. package/dist/components/dev-console/utils.mjs +0 -16
  256. package/dist/components/dev-console/utils.mjs.map +0 -1
  257. package/dist/components/help-modal/icons.d.ts +0 -9
  258. package/dist/components/help-modal/icons.js +0 -116
  259. package/dist/components/help-modal/icons.js.map +0 -1
  260. package/dist/components/help-modal/icons.mjs +0 -12
  261. package/dist/components/help-modal/icons.mjs.map +0 -1
  262. package/dist/components/help-modal/index.d.ts +0 -2
  263. package/dist/components/help-modal/index.js +0 -144
  264. package/dist/components/help-modal/index.js.map +0 -1
  265. package/dist/components/help-modal/index.mjs +0 -10
  266. package/dist/components/help-modal/index.mjs.map +0 -1
  267. package/dist/components/help-modal/modal.d.ts +0 -5
  268. package/dist/components/help-modal/modal.js +0 -142
  269. package/dist/components/help-modal/modal.js.map +0 -1
  270. package/dist/components/help-modal/modal.mjs +0 -9
  271. package/dist/components/help-modal/modal.mjs.map +0 -1
  272. package/dist/components/index.d.ts +0 -19
  273. package/dist/components/index.js +0 -3345
  274. package/dist/components/index.js.map +0 -1
  275. package/dist/components/index.mjs +0 -76
  276. package/dist/components/index.mjs.map +0 -1
  277. package/dist/context/index.d.ts +0 -2
  278. package/dist/context/index.js +0 -19
  279. package/dist/context/index.js.map +0 -1
  280. package/dist/context/index.mjs +0 -2
  281. package/dist/context/index.mjs.map +0 -1
  282. package/dist/hooks/index.d.ts +0 -2
  283. package/dist/hooks/index.js +0 -36
  284. package/dist/hooks/index.js.map +0 -1
  285. package/dist/hooks/index.mjs +0 -9
  286. package/dist/hooks/index.mjs.map +0 -1
  287. package/dist/hooks/use-copilot-chat-suggestions.d.ts +0 -66
  288. package/dist/hooks/use-copilot-chat-suggestions.js +0 -34
  289. package/dist/hooks/use-copilot-chat-suggestions.js.map +0 -1
  290. package/dist/hooks/use-copilot-chat-suggestions.mjs +0 -8
  291. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +0 -1
  292. package/dist/hooks/use-copy-to-clipboard.d.ts +0 -9
  293. package/dist/hooks/use-copy-to-clipboard.js +0 -62
  294. package/dist/hooks/use-copy-to-clipboard.js.map +0 -1
  295. package/dist/hooks/use-copy-to-clipboard.mjs +0 -8
  296. package/dist/hooks/use-copy-to-clipboard.mjs.map +0 -1
  297. package/dist/hooks/use-dark-mode.d.ts +0 -3
  298. package/dist/hooks/use-dark-mode.js +0 -35
  299. package/dist/hooks/use-dark-mode.js.map +0 -1
  300. package/dist/hooks/use-dark-mode.mjs +0 -8
  301. package/dist/hooks/use-dark-mode.mjs.map +0 -1
  302. package/dist/hooks/use-push-to-talk.d.ts +0 -19
  303. package/dist/hooks/use-push-to-talk.js +0 -202
  304. package/dist/hooks/use-push-to-talk.js.map +0 -1
  305. package/dist/hooks/use-push-to-talk.mjs +0 -12
  306. package/dist/hooks/use-push-to-talk.mjs.map +0 -1
  307. package/dist/index.d.ts +0 -21
  308. package/dist/index.js +0 -3354
  309. package/dist/index.js.map +0 -1
  310. package/dist/lib/utils.d.ts +0 -4
  311. package/dist/lib/utils.js +0 -76
  312. package/dist/lib/utils.js.map +0 -1
  313. package/dist/lib/utils.mjs +0 -34
  314. package/dist/lib/utils.mjs.map +0 -1
  315. package/dist/types/css.d.ts +0 -22
  316. package/dist/types/css.js +0 -19
  317. package/dist/types/css.js.map +0 -1
  318. package/dist/types/css.mjs +0 -1
  319. package/dist/types/css.mjs.map +0 -1
  320. package/dist/types/index.d.ts +0 -3
  321. package/dist/types/index.js +0 -19
  322. package/dist/types/index.js.map +0 -1
  323. package/dist/types/index.mjs +0 -2
  324. package/dist/types/index.mjs.map +0 -1
  325. package/dist/types/suggestions.d.ts +0 -9
  326. package/dist/types/suggestions.js +0 -19
  327. package/dist/types/suggestions.js.map +0 -1
  328. package/dist/types/suggestions.mjs +0 -1
  329. package/dist/types/suggestions.mjs.map +0 -1
  330. package/dist/v2/index.css +0 -4
  331. package/dist/v2/index.css.map +0 -1
  332. package/dist/v2/index.d.ts +0 -2
  333. package/dist/v2/index.js +0 -2
  334. package/dist/v2/index.js.map +0 -1
  335. package/dist/v2/index.mjs +0 -2
  336. package/dist/v2/index.mjs.map +0 -1
  337. package/jest.config.js +0 -5
  338. package/rollup.config.mjs +0 -64
  339. package/tsup.config.ts +0 -15
@@ -1,3341 +0,0 @@
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/index.tsx
80
- var chat_exports = {};
81
- __export(chat_exports, {
82
- AssistantMessage: () => AssistantMessage,
83
- CopilotChat: () => CopilotChat,
84
- CopilotPopup: () => CopilotPopup,
85
- CopilotSidebar: () => CopilotSidebar,
86
- ImageRenderer: () => ImageRenderer,
87
- Markdown: () => Markdown,
88
- RenderSuggestion: () => Suggestion,
89
- RenderSuggestionsList: () => Suggestions,
90
- UserMessage: () => UserMessage,
91
- useChatContext: () => useChatContext
92
- });
93
- module.exports = __toCommonJS(chat_exports);
94
-
95
- // src/components/chat/Modal.tsx
96
- var import_react16 = __toESM(require("react"));
97
-
98
- // src/components/chat/ChatContext.tsx
99
- var import_react = __toESM(require("react"));
100
-
101
- // src/components/chat/Icons.tsx
102
- var import_jsx_runtime = require("react/jsx-runtime");
103
- var OpenIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
- "svg",
105
- {
106
- xmlns: "http://www.w3.org/2000/svg",
107
- viewBox: "0 0 24 24",
108
- fill: "currentColor",
109
- width: "24",
110
- height: "24",
111
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(24, 0) scale(-1, 1)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
- "path",
113
- {
114
- fillRule: "evenodd",
115
- 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",
116
- clipRule: "evenodd"
117
- }
118
- ) })
119
- }
120
- );
121
- var CloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
- "svg",
123
- {
124
- xmlns: "http://www.w3.org/2000/svg",
125
- fill: "none",
126
- viewBox: "0 0 24 24",
127
- strokeWidth: "1.5",
128
- stroke: "currentColor",
129
- width: "24",
130
- height: "24",
131
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
132
- "path",
133
- {
134
- strokeLinecap: "round",
135
- strokeLinejoin: "round",
136
- d: "M19.5 8.25l-7.5 7.5-7.5-7.5"
137
- }
138
- )
139
- }
140
- );
141
- var HeaderCloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
142
- "svg",
143
- {
144
- xmlns: "http://www.w3.org/2000/svg",
145
- fill: "none",
146
- viewBox: "0 0 24 24",
147
- strokeWidth: "1.5",
148
- stroke: "currentColor",
149
- width: "24",
150
- height: "24",
151
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
152
- "path",
153
- {
154
- strokeLinecap: "round",
155
- strokeLinejoin: "round",
156
- d: "M6 18L18 6M6 6l12 12"
157
- }
158
- )
159
- }
160
- );
161
- var SendIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
162
- "svg",
163
- {
164
- xmlns: "http://www.w3.org/2000/svg",
165
- fill: "none",
166
- viewBox: "0 0 24 24",
167
- strokeWidth: "1.5",
168
- stroke: "currentColor",
169
- width: "24",
170
- height: "24",
171
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
172
- "path",
173
- {
174
- strokeLinecap: "round",
175
- strokeLinejoin: "round",
176
- d: "M12 19V5m0 0l-7 7m7-7l7 7"
177
- }
178
- )
179
- }
180
- );
181
- var MicrophoneIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
182
- "svg",
183
- {
184
- xmlns: "http://www.w3.org/2000/svg",
185
- fill: "none",
186
- viewBox: "0 0 24 24",
187
- strokeWidth: "1.5",
188
- stroke: "currentColor",
189
- width: "24",
190
- height: "24",
191
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
192
- "path",
193
- {
194
- strokeLinecap: "round",
195
- strokeLinejoin: "round",
196
- 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"
197
- }
198
- )
199
- }
200
- );
201
- var StopIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
202
- "svg",
203
- {
204
- xmlns: "http://www.w3.org/2000/svg",
205
- fill: "none",
206
- viewBox: "0 0 24 24",
207
- strokeWidth: "1.5",
208
- stroke: "currentColor",
209
- width: "24",
210
- height: "24",
211
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
212
- "path",
213
- {
214
- strokeLinecap: "round",
215
- strokeLinejoin: "round",
216
- 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"
217
- }
218
- )
219
- }
220
- );
221
- var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
222
- "svg",
223
- {
224
- xmlns: "http://www.w3.org/2000/svg",
225
- fill: "none",
226
- viewBox: "0 0 24 24",
227
- strokeWidth: "2",
228
- stroke: "currentColor",
229
- width: "16",
230
- height: "16",
231
- style: { minWidth: "16px", minHeight: "16px" },
232
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
233
- "path",
234
- {
235
- strokeLinecap: "round",
236
- strokeLinejoin: "round",
237
- 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"
238
- }
239
- )
240
- }
241
- );
242
- var CopyIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
243
- "svg",
244
- {
245
- xmlns: "http://www.w3.org/2000/svg",
246
- fill: "none",
247
- viewBox: "0 0 24 24",
248
- strokeWidth: "2",
249
- stroke: "currentColor",
250
- width: "16",
251
- height: "16",
252
- style: { minWidth: "16px", minHeight: "16px" },
253
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
- "path",
255
- {
256
- strokeLinecap: "round",
257
- strokeLinejoin: "round",
258
- 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"
259
- }
260
- )
261
- }
262
- );
263
- var SmallSpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
264
- "span",
265
- {
266
- className: "copilotKitSpinner",
267
- style: { width: "13px", height: "13px" }
268
- }
269
- );
270
- var SpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
- "span",
272
- {
273
- className: "copilotKitSpinner",
274
- style: { width: "24px", height: "24px" }
275
- }
276
- );
277
- var ActivityIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "4px" }, children: [
278
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
279
- "span",
280
- {
281
- className: "copilotKitActivityDot",
282
- style: { animationDelay: "0s" }
283
- }
284
- ),
285
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
286
- "span",
287
- {
288
- className: "copilotKitActivityDot",
289
- style: { animationDelay: "0.2s" }
290
- }
291
- ),
292
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
- "span",
294
- {
295
- className: "copilotKitActivityDot",
296
- style: { animationDelay: "0.4s" }
297
- }
298
- )
299
- ] });
300
- var ThumbsUpIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
301
- "svg",
302
- {
303
- xmlns: "http://www.w3.org/2000/svg",
304
- fill: "none",
305
- viewBox: "0 0 24 24",
306
- strokeWidth: "2",
307
- stroke: "currentColor",
308
- width: "16",
309
- height: "16",
310
- style: { minWidth: "16px", minHeight: "16px" },
311
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
312
- "path",
313
- {
314
- strokeLinecap: "round",
315
- strokeLinejoin: "round",
316
- 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"
317
- }
318
- )
319
- }
320
- );
321
- var ThumbsDownIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
322
- "svg",
323
- {
324
- xmlns: "http://www.w3.org/2000/svg",
325
- fill: "none",
326
- viewBox: "0 0 24 24",
327
- strokeWidth: "2",
328
- stroke: "currentColor",
329
- width: "16",
330
- height: "16",
331
- style: { minWidth: "16px", minHeight: "16px" },
332
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
333
- "path",
334
- {
335
- strokeLinecap: "round",
336
- strokeLinejoin: "round",
337
- 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"
338
- }
339
- )
340
- }
341
- );
342
- var DownloadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
343
- "svg",
344
- {
345
- xmlns: "http://www.w3.org/2000/svg",
346
- fill: "none",
347
- viewBox: "0 0 24 24",
348
- strokeWidth: "2",
349
- stroke: "currentColor",
350
- width: "16",
351
- height: "16",
352
- style: { minWidth: "16px", minHeight: "16px" },
353
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
354
- "path",
355
- {
356
- strokeLinecap: "round",
357
- strokeLinejoin: "round",
358
- 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"
359
- }
360
- )
361
- }
362
- );
363
- var UploadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
364
- "svg",
365
- {
366
- xmlns: "http://www.w3.org/2000/svg",
367
- fill: "none",
368
- viewBox: "0 0 24 24",
369
- strokeWidth: "1.5",
370
- stroke: "currentColor",
371
- width: "24",
372
- height: "24",
373
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
374
- "path",
375
- {
376
- strokeLinecap: "round",
377
- strokeLinejoin: "round",
378
- d: "M12 4.5v15m7.5-7.5h-15"
379
- }
380
- )
381
- }
382
- );
383
- var CheckIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
384
- "svg",
385
- {
386
- xmlns: "http://www.w3.org/2000/svg",
387
- fill: "none",
388
- viewBox: "0 0 24 24",
389
- strokeWidth: "2",
390
- stroke: "currentColor",
391
- width: "16",
392
- height: "16",
393
- style: { minWidth: "16px", minHeight: "16px" },
394
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
395
- "path",
396
- {
397
- strokeLinecap: "round",
398
- strokeLinejoin: "round",
399
- d: "M4.5 12.75l6 6 9-13.5"
400
- }
401
- )
402
- }
403
- );
404
-
405
- // src/components/chat/ChatContext.tsx
406
- var import_jsx_runtime2 = require("react/jsx-runtime");
407
- var ChatContext = import_react.default.createContext(
408
- void 0
409
- );
410
- function useChatContext() {
411
- const context = import_react.default.useContext(ChatContext);
412
- if (context === void 0) {
413
- throw new Error(
414
- "Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?"
415
- );
416
- }
417
- return context;
418
- }
419
- var ChatContextProvider = ({
420
- // temperature,
421
- // instructions,
422
- // maxFeedback,
423
- labels,
424
- icons,
425
- children,
426
- open,
427
- setOpen
428
- }) => {
429
- const memoizedLabels = (0, import_react.useMemo)(
430
- () => __spreadValues(__spreadValues({}, {
431
- initial: "",
432
- title: "CopilotKit",
433
- placeholder: "Type a message...",
434
- error: "\u274C An error occurred. Please try again.",
435
- stopGenerating: "Stop generating",
436
- regenerateResponse: "Regenerate response",
437
- copyToClipboard: "Copy to clipboard",
438
- thumbsUp: "Thumbs up",
439
- thumbsDown: "Thumbs down",
440
- copied: "Copied!"
441
- }), labels),
442
- [labels]
443
- );
444
- const memoizedIcons = (0, import_react.useMemo)(
445
- () => __spreadValues(__spreadValues({}, {
446
- openIcon: OpenIcon,
447
- closeIcon: CloseIcon,
448
- headerCloseIcon: HeaderCloseIcon,
449
- sendIcon: SendIcon,
450
- activityIcon: ActivityIcon,
451
- spinnerIcon: SpinnerIcon,
452
- stopIcon: StopIcon,
453
- regenerateIcon: RegenerateIcon,
454
- pushToTalkIcon: MicrophoneIcon,
455
- copyIcon: CopyIcon,
456
- thumbsUpIcon: ThumbsUpIcon,
457
- thumbsDownIcon: ThumbsDownIcon,
458
- uploadIcon: UploadIcon
459
- }), icons),
460
- [icons]
461
- );
462
- const context = (0, import_react.useMemo)(
463
- () => ({
464
- labels: memoizedLabels,
465
- icons: memoizedIcons,
466
- open,
467
- setOpen
468
- }),
469
- [memoizedLabels, memoizedIcons, open, setOpen]
470
- );
471
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
472
- };
473
-
474
- // src/components/chat/Window.tsx
475
- var import_react2 = __toESM(require("react"));
476
- var import_react_core = require("@copilotkit/react-core");
477
- var import_shared = require("@copilotkit/shared");
478
- var import_jsx_runtime3 = require("react/jsx-runtime");
479
- var Window = ({
480
- children,
481
- clickOutsideToClose,
482
- shortcut,
483
- hitEscapeToClose
484
- }) => {
485
- const windowRef = import_react2.default.useRef(null);
486
- const context = (0, import_react_core.useCopilotContext)();
487
- const { open, setOpen } = useChatContext();
488
- const handleClickOutside = (0, import_react2.useCallback)(
489
- (event) => {
490
- var _a;
491
- if (!clickOutsideToClose) {
492
- return;
493
- }
494
- const parentElement = (_a = windowRef.current) == null ? void 0 : _a.parentElement;
495
- let className = "";
496
- if (event.target instanceof HTMLElement) {
497
- className = event.target.className;
498
- }
499
- if (open && parentElement && !parentElement.contains(event.target) && // prevent closing the window when clicking on the debug menu
500
- !className.includes("copilotKitDebugMenu")) {
501
- setOpen(false);
502
- }
503
- },
504
- [clickOutsideToClose, open, setOpen]
505
- );
506
- const handleKeyDown = (0, import_react2.useCallback)(
507
- (event) => {
508
- var _a;
509
- const target = event.target;
510
- const isInput = target.tagName === "INPUT" || target.tagName === "SELECT" || target.tagName === "TEXTAREA" || target.isContentEditable;
511
- const isDescendantOfWrapper = (_a = windowRef.current) == null ? void 0 : _a.contains(target);
512
- if (open && event.key === "Escape" && (!isInput || isDescendantOfWrapper) && hitEscapeToClose) {
513
- setOpen(false);
514
- } else if (event.key === shortcut && ((0, import_shared.isMacOS)() && event.metaKey || !(0, import_shared.isMacOS)() && event.ctrlKey) && (!isInput || isDescendantOfWrapper)) {
515
- setOpen(!open);
516
- }
517
- },
518
- [hitEscapeToClose, shortcut, open, setOpen]
519
- );
520
- const adjustForMobile = (0, import_react2.useCallback)(() => {
521
- const copilotKitWindow = windowRef.current;
522
- const vv = window.visualViewport;
523
- if (!copilotKitWindow || !vv) {
524
- return;
525
- }
526
- if (window.innerWidth < 640 && open) {
527
- copilotKitWindow.style.height = `${vv.height}px`;
528
- copilotKitWindow.style.left = `${vv.offsetLeft}px`;
529
- copilotKitWindow.style.top = `${vv.offsetTop}px`;
530
- document.body.style.position = "fixed";
531
- document.body.style.width = "100%";
532
- document.body.style.height = `${window.innerHeight}px`;
533
- document.body.style.overflow = "hidden";
534
- document.body.style.touchAction = "none";
535
- document.body.addEventListener("touchmove", preventScroll, {
536
- passive: false
537
- });
538
- } else {
539
- copilotKitWindow.style.height = "";
540
- copilotKitWindow.style.left = "";
541
- copilotKitWindow.style.top = "";
542
- document.body.style.position = "";
543
- document.body.style.height = "";
544
- document.body.style.width = "";
545
- document.body.style.overflow = "";
546
- document.body.style.top = "";
547
- document.body.style.touchAction = "";
548
- document.body.removeEventListener("touchmove", preventScroll);
549
- }
550
- }, [open]);
551
- (0, import_react2.useEffect)(() => {
552
- document.addEventListener("mousedown", handleClickOutside);
553
- document.addEventListener("keydown", handleKeyDown);
554
- if (window.visualViewport) {
555
- window.visualViewport.addEventListener("resize", adjustForMobile);
556
- adjustForMobile();
557
- }
558
- return () => {
559
- document.removeEventListener("mousedown", handleClickOutside);
560
- document.removeEventListener("keydown", handleKeyDown);
561
- if (window.visualViewport) {
562
- window.visualViewport.removeEventListener("resize", adjustForMobile);
563
- }
564
- };
565
- }, [adjustForMobile, handleClickOutside, handleKeyDown]);
566
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `copilotKitWindow ${open ? " open" : ""}`, ref: windowRef, children });
567
- };
568
- var preventScroll = (event) => {
569
- let targetElement = event.target;
570
- const hasParentWithClass = (element, className) => {
571
- while (element && element !== document.body) {
572
- if (element.classList.contains(className)) {
573
- return true;
574
- }
575
- element = element.parentElement;
576
- }
577
- return false;
578
- };
579
- if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
580
- event.preventDefault();
581
- }
582
- };
583
-
584
- // src/components/chat/Button.tsx
585
- var import_jsx_runtime4 = require("react/jsx-runtime");
586
- var Button = ({}) => {
587
- const { open, setOpen, icons } = useChatContext();
588
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
589
- "button",
590
- {
591
- className: `copilotKitButton ${open ? "open" : ""}`,
592
- "aria-label": open ? "Close Chat" : "Open Chat",
593
- children: [
594
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconOpen", children: icons.openIcon }),
595
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconClose", children: icons.closeIcon })
596
- ]
597
- }
598
- ) });
599
- };
600
-
601
- // src/components/dev-console/utils.ts
602
- var import_react_core2 = require("@copilotkit/react-core");
603
- var import_react_core3 = require("@copilotkit/react-core");
604
- function getPublishedCopilotKitVersion(current, forceCheck = false) {
605
- return __async(this, null, function* () {
606
- const LOCAL_STORAGE_KEY = "__copilotkit_version_check__";
607
- const serializedVersion = localStorage.getItem(LOCAL_STORAGE_KEY);
608
- if (serializedVersion && !forceCheck) {
609
- try {
610
- const parsedVersion = JSON.parse(serializedVersion);
611
- const oneHour = 60 * 60 * 1e3;
612
- const now = (/* @__PURE__ */ new Date()).getTime();
613
- if (parsedVersion.current === current && now - new Date(parsedVersion.lastChecked).getTime() < oneHour) {
614
- return parsedVersion;
615
- }
616
- } catch (error) {
617
- console.error(
618
- "Failed to parse CopilotKitVersion from localStorage",
619
- error
620
- );
621
- }
622
- }
623
- try {
624
- const response = yield fetch(
625
- "https://api.cloud.copilotkit.ai/check-for-updates",
626
- {
627
- method: "POST",
628
- headers: {
629
- "Content-Type": "application/json"
630
- },
631
- body: JSON.stringify({
632
- packages: [
633
- {
634
- packageName: "@copilotkit/shared",
635
- packageVersion: current
636
- }
637
- ]
638
- })
639
- }
640
- );
641
- const data = yield response.json();
642
- const version = {
643
- current,
644
- lastChecked: (/* @__PURE__ */ new Date()).getTime(),
645
- latest: data.packages[0].latestVersion,
646
- severity: data.packages[0].severity,
647
- advisory: data.packages[0].advisory || null
648
- };
649
- localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(version));
650
- return version;
651
- } catch (error) {
652
- console.error("Failed to check for updates", error);
653
- throw error;
654
- }
655
- });
656
- }
657
- function logReadables(context) {
658
- console.log("%cCurrent Readables:", "font-size: 16px; font-weight: bold;");
659
- const readables = context.getContextString([], import_react_core2.defaultCopilotContextCategories).trim();
660
- if (readables.length === 0) {
661
- console.log("No readables found");
662
- return;
663
- }
664
- console.log(readables);
665
- }
666
- function logActions(context) {
667
- console.log("%cCurrent Actions:", "font-size: 16px; font-weight: bold;");
668
- if (Object.values(context.actions).length === 0) {
669
- console.log("No actions found");
670
- return;
671
- }
672
- for (const action of Object.values(context.actions)) {
673
- console.group(action.name);
674
- console.log("name", action.name);
675
- console.log("description", action.description);
676
- console.log("parameters", action.parameters);
677
- console.groupEnd();
678
- }
679
- }
680
- function logMessages(context) {
681
- console.log("%cCurrent Messages:", "font-size: 16px; font-weight: bold;");
682
- if (context.messages.length === 0) {
683
- console.log("No messages found");
684
- return;
685
- }
686
- const tableData = context.messages.map((message) => {
687
- if (message.isTextMessage()) {
688
- return {
689
- id: message.id,
690
- type: "TextMessage",
691
- role: message.role,
692
- name: void 0,
693
- scope: void 0,
694
- content: message.content
695
- };
696
- } else if (message.isActionExecutionMessage()) {
697
- return {
698
- id: message.id,
699
- type: "ActionExecutionMessage",
700
- role: void 0,
701
- name: message.name,
702
- scope: message.parentMessageId,
703
- content: message.arguments
704
- };
705
- } else if (message.isResultMessage()) {
706
- return {
707
- id: message.id,
708
- type: "ResultMessage",
709
- role: void 0,
710
- name: message.actionName,
711
- scope: message.actionExecutionId,
712
- content: message.result
713
- };
714
- } else if (message.isAgentStateMessage()) {
715
- return {
716
- id: message.id,
717
- type: `AgentStateMessage (running: ${message.running})`,
718
- role: message.role,
719
- name: void 0,
720
- scope: message.threadId,
721
- content: message.state
722
- };
723
- }
724
- });
725
- console.table(tableData);
726
- }
727
-
728
- // src/components/dev-console/console.tsx
729
- var import_react_core4 = require("@copilotkit/react-core");
730
- var import_react4 = require("react");
731
-
732
- // src/components/dev-console/icons.tsx
733
- var import_jsx_runtime5 = require("react/jsx-runtime");
734
- var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
735
- "svg",
736
- {
737
- width: "13.3967723px",
738
- height: "12px",
739
- viewBox: "0 0 13.3967723 12",
740
- version: "1.1",
741
- xmlns: "http://www.w3.org/2000/svg",
742
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "exclamation-triangle", fill: "#CD2121", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
743
- "path",
744
- {
745
- d: "M5.39935802,0.75 C5.97670802,-0.25 7.42007802,-0.25 7.99742802,0.75 L13.193588,9.75 C13.770888,10.75 13.049288,12 11.894588,12 L1.50223802,12 C0.34753802,12 -0.37414898,10.75 0.20319802,9.75 L5.39935802,0.75 Z M6.69838802,2.5 C7.11260802,2.5 7.44838802,2.83579 7.44838802,3.25 L7.44838802,6.25 C7.44838802,6.66421 7.11260802,7 6.69838802,7 C6.28417802,7 5.94838802,6.66421 5.94838802,6.25 L5.94838802,3.25 C5.94838802,2.83579 6.28417802,2.5 6.69838802,2.5 Z M6.69838802,10.5 C7.25067802,10.5 7.69838802,10.0523 7.69838802,9.5 C7.69838802,8.9477 7.25067802,8.5 6.69838802,8.5 C6.14610802,8.5 5.69838802,8.9477 5.69838802,9.5 C5.69838802,10.0523 6.14610802,10.5 6.69838802,10.5 Z",
746
- id: "Shape"
747
- }
748
- ) }) })
749
- }
750
- );
751
- var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
752
- "svg",
753
- {
754
- width: "14px",
755
- height: "14px",
756
- viewBox: "0 0 14 14",
757
- version: "1.1",
758
- xmlns: "http://www.w3.org/2000/svg",
759
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "exclamation-circle", fill: "#EC662C", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
760
- "path",
761
- {
762
- d: "M7,14 C10.866,14 14,10.866 14,7 C14,3.13401 10.866,0 7,0 C3.13401,0 0,3.13401 0,7 C0,10.866 3.13401,14 7,14 Z M7,3 C7.41421,3 7.75,3.33579 7.75,3.75 L7.75,6.75 C7.75,7.16421 7.41421,7.5 7,7.5 C6.58579,7.5 6.25,7.16421 6.25,6.75 L6.25,3.75 C6.25,3.33579 6.58579,3 7,3 Z M7,11 C7.55228,11 8,10.5523 8,10 C8,9.4477 7.55228,9 7,9 C6.44772,9 6,9.4477 6,10 C6,10.5523 6.44772,11 7,11 Z",
763
- id: "Shape"
764
- }
765
- ) }) })
766
- }
767
- );
768
- var ChevronDownIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
769
- "svg",
770
- {
771
- width: "7px",
772
- height: "4px",
773
- viewBox: "0 0 7 4",
774
- version: "1.1",
775
- xmlns: "http://www.w3.org/2000/svg",
776
- fill: "currentColor",
777
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Group", fill: "currentColor", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
778
- "path",
779
- {
780
- d: "M3.71690723,3.90271086 C3.59268176,4.03242971 3.39143629,4.03242971 3.26721082,3.90271086 L0.0853966595,0.57605615 C-0.0314221035,0.444981627 -0.0279751448,0.240725043 0.0931934622,0.114040675 C0.214362069,-0.0126436935 0.409725445,-0.0162475626 0.535093061,0.105888951 L3.49205902,3.19746006 L6.44902499,0.105888951 C6.52834574,0.0168884389 6.64780588,-0.0197473458 6.7605411,0.0103538404 C6.87327633,0.0404550266 6.96130636,0.132492308 6.99009696,0.250359396 C7.01888756,0.368226483 6.98384687,0.493124608 6.89872139,0.57605615 L3.71690723,3.90271086 Z",
781
- id: "Path"
782
- }
783
- ) }) })
784
- }
785
- );
786
- var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
787
- "svg",
788
- {
789
- width: "14px",
790
- height: "14px",
791
- viewBox: "0 0 14 14",
792
- version: "1.1",
793
- xmlns: "http://www.w3.org/2000/svg",
794
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
795
- "g",
796
- {
797
- id: "Group-2",
798
- transform: "translate(-118, 0)",
799
- fill: "#1BC030",
800
- fillRule: "nonzero",
801
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Group", transform: "translate(118, 0)", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
802
- "path",
803
- {
804
- d: "M0,7 C0,3.13384615 3.13384615,0 7,0 C10.8661538,0 14,3.13384615 14,7 C14,10.8661538 10.8661538,14 7,14 C3.13384615,14 0,10.8661538 0,7 Z M9.59179487,5.69764103 C9.70905818,5.54139023 9.73249341,5.33388318 9.65303227,5.15541491 C9.57357113,4.97694665 9.40367989,4.85551619 9.20909814,4.83811118 C9.01451638,4.82070616 8.82577109,4.91005717 8.71589744,5.07158974 L6.39261538,8.32389744 L5.22666667,7.15794872 C5.01450582,6.96025518 4.68389046,6.9660885 4.47883563,7.17114332 C4.27378081,7.37619815 4.26794748,7.70681351 4.46564103,7.91897436 L6.08102564,9.53435897 C6.19289944,9.64614839 6.3482622,9.70310251 6.50588106,9.69010587 C6.66349993,9.67710922 6.80743532,9.59547613 6.89948718,9.46687179 L9.59179487,5.69764103 L9.59179487,5.69764103 Z",
805
- id: "Shape"
806
- }
807
- ) })
808
- }
809
- ) })
810
- }
811
- );
812
-
813
- // src/components/dev-console/console.tsx
814
- var import_react5 = require("@headlessui/react");
815
- var import_shared2 = require("@copilotkit/shared");
816
-
817
- // src/components/help-modal/modal.tsx
818
- var import_react3 = require("react");
819
-
820
- // src/components/help-modal/icons.tsx
821
- var import_jsx_runtime6 = require("react/jsx-runtime");
822
- var CloseIcon2 = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
823
- "svg",
824
- {
825
- xmlns: "http://www.w3.org/2000/svg",
826
- fill: "none",
827
- viewBox: "0 0 24 24",
828
- strokeWidth: "1.5",
829
- stroke: "currentColor",
830
- width: "20",
831
- height: "20",
832
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
833
- "path",
834
- {
835
- strokeLinecap: "round",
836
- strokeLinejoin: "round",
837
- d: "M6 18L18 6M6 6l12 12"
838
- }
839
- )
840
- }
841
- );
842
-
843
- // src/components/help-modal/modal.tsx
844
- var import_jsx_runtime7 = require("react/jsx-runtime");
845
- function CopilotKitHelpModal() {
846
- const [showHelpModal, setShowHelpModal] = (0, import_react3.useState)(false);
847
- const buttonRef = (0, import_react3.useRef)(null);
848
- const popoverRef = (0, import_react3.useRef)(null);
849
- (0, import_react3.useEffect)(() => {
850
- const handleClickOutside = (event) => {
851
- if (popoverRef.current && !popoverRef.current.contains(event.target) && buttonRef.current && !buttonRef.current.contains(event.target)) {
852
- setShowHelpModal(false);
853
- }
854
- };
855
- if (showHelpModal) {
856
- document.addEventListener("mousedown", handleClickOutside);
857
- }
858
- return () => {
859
- document.removeEventListener("mousedown", handleClickOutside);
860
- };
861
- }, [showHelpModal]);
862
- const HelpButton = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
863
- "button",
864
- {
865
- ref: buttonRef,
866
- onClick: () => setShowHelpModal(!showHelpModal),
867
- className: "copilotKitDebugMenuTriggerButton relative",
868
- "aria-label": "Open Help",
869
- children: "Help"
870
- }
871
- );
872
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative", children: [
873
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HelpButton, {}),
874
- showHelpModal && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
875
- "div",
876
- {
877
- ref: popoverRef,
878
- className: "absolute mt-2 z-50",
879
- style: {
880
- top: "100%",
881
- right: "-120px",
882
- width: "380px"
883
- },
884
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "copilotKitHelpModal rounded-lg shadow-xl w-full p-4 flex-col relative", children: [
885
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
886
- "button",
887
- {
888
- className: "copilotKitHelpModalCloseButton absolute text-gray-400 hover:text-gray-600 focus:outline-none",
889
- style: { top: "10px", right: "10px" },
890
- onClick: () => setShowHelpModal(false),
891
- "aria-label": "Close",
892
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CloseIcon2, {})
893
- }
894
- ),
895
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "w-full flex mb-6 justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: "text-2xl font-bold", children: "Help Options" }) }),
896
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-4 mb-4", children: [
897
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
898
- "a",
899
- {
900
- href: "https://docs.copilotkit.ai/coagents/troubleshooting/common-issues",
901
- target: "_blank",
902
- rel: "noopener noreferrer",
903
- children: "Visit the Troubleshooting and FAQ section in the docs"
904
- }
905
- ) }),
906
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
907
- "a",
908
- {
909
- href: "https://go.copilotkit.ai/dev-console-support-discord",
910
- target: "_blank",
911
- rel: "noopener noreferrer",
912
- children: "Go to Discord Support Channel (Community Support)"
913
- }
914
- ) }),
915
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
916
- "a",
917
- {
918
- href: "https://go.copilotkit.ai/dev-console-support-slack",
919
- target: "_blank",
920
- rel: "noopener noreferrer",
921
- children: "Apply for Priority Direct Slack Support"
922
- }
923
- ) })
924
- ] })
925
- ] })
926
- }
927
- )
928
- ] });
929
- }
930
-
931
- // src/components/dev-console/console.tsx
932
- var import_jsx_runtime8 = require("react/jsx-runtime");
933
- function CopilotDevConsole() {
934
- const currentVersion = import_shared2.COPILOTKIT_VERSION;
935
- const context = (0, import_react_core4.useCopilotContext)();
936
- const [showDevConsole, setShowDevConsole] = (0, import_react4.useState)(false);
937
- (0, import_react4.useEffect)(() => {
938
- setShowDevConsole((0, import_react_core3.shouldShowDevConsole)(context.showDevConsole));
939
- }, [context.showDevConsole]);
940
- const dontRunTwiceInDevMode = (0, import_react4.useRef)(false);
941
- const [versionStatus, setVersionStatus] = (0, import_react4.useState)("unknown");
942
- const [latestVersion, setLatestVersion] = (0, import_react4.useState)("");
943
- const consoleRef = (0, import_react4.useRef)(null);
944
- const [debugButtonMode, setDebugButtonMode] = (0, import_react4.useState)(
945
- "full"
946
- );
947
- const checkForUpdates = (force = false) => {
948
- setVersionStatus("checking");
949
- getPublishedCopilotKitVersion(currentVersion, force).then((v) => {
950
- setLatestVersion(v.latest);
951
- let versionOk = false;
952
- if (v.current === v.latest) {
953
- versionOk = true;
954
- } else if (/[a-zA-Z]/.test(v.current)) {
955
- versionOk = true;
956
- }
957
- if (versionOk) {
958
- setVersionStatus("latest");
959
- } else if (v.severity !== "low") {
960
- setVersionStatus("outdated");
961
- } else {
962
- setVersionStatus("update-available");
963
- }
964
- }).catch((e) => {
965
- console.error(e);
966
- setVersionStatus("unknown");
967
- });
968
- };
969
- (0, import_react4.useEffect)(() => {
970
- if (dontRunTwiceInDevMode.current === true) {
971
- return;
972
- }
973
- dontRunTwiceInDevMode.current = true;
974
- checkForUpdates();
975
- }, []);
976
- if (!showDevConsole) {
977
- return null;
978
- }
979
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
980
- "div",
981
- {
982
- ref: consoleRef,
983
- className: "copilotKitDevConsole " + (versionStatus === "update-available" ? "copilotKitDevConsoleUpgrade" : "") + (versionStatus === "outdated" ? "copilotKitDevConsoleWarnOutdated" : ""),
984
- children: [
985
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
986
- VersionInfo,
987
- {
988
- showDevConsole: context.showDevConsole,
989
- versionStatus,
990
- currentVersion,
991
- latestVersion
992
- }
993
- ),
994
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotKitHelpModal, {}),
995
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
996
- DebugMenuButton,
997
- {
998
- setShowDevConsole,
999
- checkForUpdates,
1000
- mode: debugButtonMode
1001
- }
1002
- )
1003
- ]
1004
- }
1005
- );
1006
- }
1007
- function VersionInfo({
1008
- showDevConsole,
1009
- versionStatus,
1010
- currentVersion,
1011
- latestVersion
1012
- }) {
1013
- const [copyStatus, setCopyStatus] = (0, import_react4.useState)("");
1014
- let versionLabel = "";
1015
- let versionIcon = "";
1016
- let currentVersionLabel = currentVersion;
1017
- if (versionStatus === "latest") {
1018
- versionLabel = "latest";
1019
- versionIcon = CheckIcon2;
1020
- } else if (versionStatus === "checking") {
1021
- versionLabel = "checking";
1022
- versionIcon = SmallSpinnerIcon;
1023
- } else if (versionStatus === "update-available") {
1024
- versionLabel = "update available";
1025
- versionIcon = ExclamationMarkIcon;
1026
- currentVersionLabel = `${currentVersion} \u2192 ${latestVersion}`;
1027
- } else if (versionStatus === "outdated") {
1028
- versionLabel = "outdated";
1029
- versionIcon = ExclamationMarkTriangleIcon;
1030
- currentVersionLabel = `${currentVersion} \u2192 ${latestVersion}`;
1031
- }
1032
- let asideLabel = "";
1033
- if (showDevConsole === true) {
1034
- asideLabel = "(enabled)";
1035
- }
1036
- const installCommand = [
1037
- `npm install`,
1038
- `@copilotkit/react-core@${latestVersion}`,
1039
- `@copilotkit/react-ui@${latestVersion}`,
1040
- `@copilotkit/react-textarea@${latestVersion}`,
1041
- `&& npm install @copilotkit/runtime@${latestVersion}`
1042
- ].join(" ");
1043
- const handleCopyClick = () => {
1044
- navigator.clipboard.writeText(installCommand.trim()).then(() => {
1045
- setCopyStatus("Command copied to clipboard!");
1046
- setTimeout(() => setCopyStatus(""), 1e3);
1047
- });
1048
- };
1049
- if (versionStatus === "update-available" || versionStatus === "outdated") {
1050
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitVersionInfo", children: [
1051
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { children: [
1052
- currentVersionLabel,
1053
- " ",
1054
- versionIcon
1055
- ] }),
1056
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { onClick: handleCopyClick, children: copyStatus || installCommand })
1057
- ] });
1058
- }
1059
- return null;
1060
- }
1061
- function DebugMenuButton({
1062
- setShowDevConsole,
1063
- checkForUpdates,
1064
- mode
1065
- }) {
1066
- const context = (0, import_react_core4.useCopilotContext)();
1067
- const messagesContext = (0, import_react_core4.useCopilotMessagesContext)();
1068
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react5.Menu, { children: [
1069
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1070
- import_react5.MenuButton,
1071
- {
1072
- className: `copilotKitDebugMenuTriggerButton ${mode === "compact" ? "compact" : ""}`,
1073
- children: mode == "compact" ? "Debug" : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1074
- "Debug ",
1075
- ChevronDownIcon
1076
- ] })
1077
- }
1078
- ),
1079
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1080
- import_react5.MenuItems,
1081
- {
1082
- transition: true,
1083
- anchor: "bottom end",
1084
- className: "copilotKitDebugMenu",
1085
- style: { zIndex: 40 },
1086
- children: [
1087
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1088
- "button",
1089
- {
1090
- className: "copilotKitDebugMenuItem",
1091
- onClick: () => logReadables(context),
1092
- children: "Log Readables"
1093
- }
1094
- ) }),
1095
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1096
- "button",
1097
- {
1098
- className: "copilotKitDebugMenuItem",
1099
- onClick: () => logActions(context),
1100
- children: "Log Actions"
1101
- }
1102
- ) }),
1103
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1104
- "button",
1105
- {
1106
- className: "copilotKitDebugMenuItem",
1107
- onClick: () => logMessages(messagesContext),
1108
- children: "Log Messages"
1109
- }
1110
- ) }),
1111
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1112
- "button",
1113
- {
1114
- className: "copilotKitDebugMenuItem",
1115
- onClick: () => checkForUpdates(true),
1116
- children: "Check for Updates"
1117
- }
1118
- ) }),
1119
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("hr", {}),
1120
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1121
- "button",
1122
- {
1123
- className: "copilotKitDebugMenuItem",
1124
- onClick: () => setShowDevConsole(false),
1125
- children: "Hide Dev Console"
1126
- }
1127
- ) })
1128
- ]
1129
- }
1130
- )
1131
- ] }) });
1132
- }
1133
-
1134
- // src/components/chat/Header.tsx
1135
- var import_jsx_runtime9 = require("react/jsx-runtime");
1136
- var Header = ({}) => {
1137
- const { setOpen, icons, labels } = useChatContext();
1138
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "copilotKitHeader", children: [
1139
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: labels.title }),
1140
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "copilotKitHeaderControls", children: [
1141
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotDevConsole, {}),
1142
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1143
- "button",
1144
- {
1145
- onClick: () => setOpen(false),
1146
- "aria-label": "Close",
1147
- className: "copilotKitHeaderCloseButton",
1148
- children: icons.headerCloseIcon
1149
- }
1150
- )
1151
- ] })
1152
- ] });
1153
- };
1154
-
1155
- // src/components/chat/Messages.tsx
1156
- var import_react10 = require("react");
1157
- var import_react_core5 = require("@copilotkit/react-core");
1158
-
1159
- // src/components/chat/messages/UserMessage.tsx
1160
- var import_jsx_runtime10 = require("react/jsx-runtime");
1161
- var getTextContent = (content) => {
1162
- if (typeof content === "undefined") {
1163
- return void 0;
1164
- }
1165
- if (typeof content === "string") {
1166
- return content;
1167
- }
1168
- return content.map((part) => {
1169
- if (part.type === "text") {
1170
- return part.text;
1171
- }
1172
- return void 0;
1173
- }).filter(
1174
- (value) => typeof value === "string" && value.length > 0
1175
- ).join(" ").trim() || void 0;
1176
- };
1177
- var UserMessage = (props) => {
1178
- const { message, ImageRenderer: ImageRenderer2 } = props;
1179
- const isImageMessage = message && "image" in message && Boolean(message.image);
1180
- if (isImageMessage) {
1181
- const imageMessage = message;
1182
- const content2 = getTextContent(imageMessage == null ? void 0 : imageMessage.content);
1183
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ImageRenderer2, { image: imageMessage.image, content: content2 }) });
1184
- }
1185
- const content = getTextContent(message == null ? void 0 : message.content);
1186
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: content });
1187
- };
1188
-
1189
- // src/components/chat/Markdown.tsx
1190
- var import_react7 = require("react");
1191
- var import_react_markdown = __toESM(require("react-markdown"));
1192
-
1193
- // src/components/chat/CodeBlock.tsx
1194
- var import_react6 = require("react");
1195
- var import_react_syntax_highlighter = require("react-syntax-highlighter");
1196
-
1197
- // src/hooks/use-copy-to-clipboard.tsx
1198
- var React5 = __toESM(require("react"));
1199
- function useCopyToClipboard({
1200
- timeout = 2e3
1201
- }) {
1202
- const [isCopied, setIsCopied] = React5.useState(false);
1203
- const copyToClipboard = (value) => {
1204
- var _a;
1205
- if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
1206
- return;
1207
- }
1208
- if (!value) {
1209
- return;
1210
- }
1211
- navigator.clipboard.writeText(value).then(() => {
1212
- setIsCopied(true);
1213
- setTimeout(() => {
1214
- setIsCopied(false);
1215
- }, timeout);
1216
- });
1217
- };
1218
- return { isCopied, copyToClipboard };
1219
- }
1220
-
1221
- // src/components/chat/CodeBlock.tsx
1222
- var import_jsx_runtime11 = require("react/jsx-runtime");
1223
- var programmingLanguages = {
1224
- javascript: ".js",
1225
- python: ".py",
1226
- java: ".java",
1227
- c: ".c",
1228
- cpp: ".cpp",
1229
- "c++": ".cpp",
1230
- "c#": ".cs",
1231
- ruby: ".rb",
1232
- php: ".php",
1233
- swift: ".swift",
1234
- "objective-c": ".m",
1235
- kotlin: ".kt",
1236
- typescript: ".ts",
1237
- go: ".go",
1238
- perl: ".pl",
1239
- rust: ".rs",
1240
- scala: ".scala",
1241
- haskell: ".hs",
1242
- lua: ".lua",
1243
- shell: ".sh",
1244
- sql: ".sql",
1245
- html: ".html",
1246
- css: ".css"
1247
- // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
1248
- };
1249
- var generateRandomString = (length, lowercase = false) => {
1250
- const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
1251
- let result = "";
1252
- for (let i = 0; i < length; i++) {
1253
- result += chars.charAt(Math.floor(Math.random() * chars.length));
1254
- }
1255
- return lowercase ? result.toLowerCase() : result;
1256
- };
1257
- var CodeBlock = (0, import_react6.memo)(({ language, value }) => {
1258
- const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
1259
- const [SyntaxHighlighter, setSyntaxHighlighter] = (0, import_react6.useState)(() => import_react_syntax_highlighter.Light);
1260
- (0, import_react6.useEffect)(() => {
1261
- try {
1262
- new RegExp("(?<=#)\\w+");
1263
- setSyntaxHighlighter(() => import_react_syntax_highlighter.Prism);
1264
- } catch (e) {
1265
- setSyntaxHighlighter(() => import_react_syntax_highlighter.Light);
1266
- }
1267
- }, []);
1268
- const downloadAsFile = () => {
1269
- if (typeof window === "undefined") {
1270
- return;
1271
- }
1272
- const fileExtension = programmingLanguages[language] || ".file";
1273
- const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
1274
- const fileName = window.prompt("Enter file name", suggestedFileName);
1275
- if (!fileName) {
1276
- return;
1277
- }
1278
- const blob = new Blob([value], { type: "text/plain" });
1279
- const url = URL.createObjectURL(blob);
1280
- const link = document.createElement("a");
1281
- link.download = fileName;
1282
- link.href = url;
1283
- link.style.display = "none";
1284
- document.body.appendChild(link);
1285
- link.click();
1286
- document.body.removeChild(link);
1287
- URL.revokeObjectURL(url);
1288
- };
1289
- const onCopy = () => {
1290
- if (isCopied)
1291
- return;
1292
- copyToClipboard(value);
1293
- };
1294
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlock", children: [
1295
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
1296
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
1297
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
1298
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1299
- "button",
1300
- {
1301
- className: "copilotKitCodeBlockToolbarButton",
1302
- onClick: downloadAsFile,
1303
- children: DownloadIcon
1304
- }
1305
- ),
1306
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: isCopied ? CheckIcon : CopyIcon })
1307
- ] })
1308
- ] }),
1309
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1310
- SyntaxHighlighter,
1311
- {
1312
- language,
1313
- style: highlightStyle,
1314
- PreTag: "div",
1315
- customStyle: {
1316
- margin: 0,
1317
- borderBottomLeftRadius: "0.375rem",
1318
- borderBottomRightRadius: "0.375rem"
1319
- },
1320
- children: value
1321
- }
1322
- )
1323
- ] });
1324
- });
1325
- CodeBlock.displayName = "CodeBlock";
1326
- var highlightStyle = {
1327
- 'pre[class*="language-"]': {
1328
- color: "#d4d4d4",
1329
- fontSize: "13px",
1330
- textShadow: "none",
1331
- fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
1332
- direction: "ltr",
1333
- textAlign: "left",
1334
- whiteSpace: "pre",
1335
- wordSpacing: "normal",
1336
- wordBreak: "normal",
1337
- lineHeight: "1.5",
1338
- MozTabSize: "4",
1339
- OTabSize: "4",
1340
- tabSize: "4",
1341
- WebkitHyphens: "none",
1342
- MozHyphens: "none",
1343
- msHyphens: "none",
1344
- hyphens: "none",
1345
- padding: "1em",
1346
- margin: ".5em 0",
1347
- overflow: "auto",
1348
- background: "#1e1e1e"
1349
- },
1350
- 'code[class*="language-"]': {
1351
- color: "#d4d4d4",
1352
- fontSize: "13px",
1353
- textShadow: "none",
1354
- fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
1355
- direction: "ltr",
1356
- textAlign: "left",
1357
- whiteSpace: "pre",
1358
- wordSpacing: "normal",
1359
- wordBreak: "normal",
1360
- lineHeight: "1.5",
1361
- MozTabSize: "4",
1362
- OTabSize: "4",
1363
- tabSize: "4",
1364
- WebkitHyphens: "none",
1365
- MozHyphens: "none",
1366
- msHyphens: "none",
1367
- hyphens: "none"
1368
- },
1369
- 'pre[class*="language-"]::selection': {
1370
- textShadow: "none",
1371
- background: "#264F78"
1372
- },
1373
- 'code[class*="language-"]::selection': {
1374
- textShadow: "none",
1375
- background: "#264F78"
1376
- },
1377
- 'pre[class*="language-"] *::selection': {
1378
- textShadow: "none",
1379
- background: "#264F78"
1380
- },
1381
- 'code[class*="language-"] *::selection': {
1382
- textShadow: "none",
1383
- background: "#264F78"
1384
- },
1385
- ':not(pre) > code[class*="language-"]': {
1386
- padding: ".1em .3em",
1387
- borderRadius: ".3em",
1388
- color: "#db4c69",
1389
- background: "#1e1e1e"
1390
- },
1391
- ".namespace": {
1392
- Opacity: ".7"
1393
- },
1394
- "doctype.doctype-tag": {
1395
- color: "#569CD6"
1396
- },
1397
- "doctype.name": {
1398
- color: "#9cdcfe"
1399
- },
1400
- comment: {
1401
- color: "#6a9955"
1402
- },
1403
- prolog: {
1404
- color: "#6a9955"
1405
- },
1406
- punctuation: {
1407
- color: "#d4d4d4"
1408
- },
1409
- ".language-html .language-css .token.punctuation": {
1410
- color: "#d4d4d4"
1411
- },
1412
- ".language-html .language-javascript .token.punctuation": {
1413
- color: "#d4d4d4"
1414
- },
1415
- property: {
1416
- color: "#9cdcfe"
1417
- },
1418
- tag: {
1419
- color: "#569cd6"
1420
- },
1421
- boolean: {
1422
- color: "#569cd6"
1423
- },
1424
- number: {
1425
- color: "#b5cea8"
1426
- },
1427
- constant: {
1428
- color: "#9cdcfe"
1429
- },
1430
- symbol: {
1431
- color: "#b5cea8"
1432
- },
1433
- inserted: {
1434
- color: "#b5cea8"
1435
- },
1436
- unit: {
1437
- color: "#b5cea8"
1438
- },
1439
- selector: {
1440
- color: "#d7ba7d"
1441
- },
1442
- "attr-name": {
1443
- color: "#9cdcfe"
1444
- },
1445
- string: {
1446
- color: "#ce9178"
1447
- },
1448
- char: {
1449
- color: "#ce9178"
1450
- },
1451
- builtin: {
1452
- color: "#ce9178"
1453
- },
1454
- deleted: {
1455
- color: "#ce9178"
1456
- },
1457
- ".language-css .token.string.url": {
1458
- textDecoration: "underline"
1459
- },
1460
- operator: {
1461
- color: "#d4d4d4"
1462
- },
1463
- entity: {
1464
- color: "#569cd6"
1465
- },
1466
- "operator.arrow": {
1467
- color: "#569CD6"
1468
- },
1469
- atrule: {
1470
- color: "#ce9178"
1471
- },
1472
- "atrule.rule": {
1473
- color: "#c586c0"
1474
- },
1475
- "atrule.url": {
1476
- color: "#9cdcfe"
1477
- },
1478
- "atrule.url.function": {
1479
- color: "#dcdcaa"
1480
- },
1481
- "atrule.url.punctuation": {
1482
- color: "#d4d4d4"
1483
- },
1484
- keyword: {
1485
- color: "#569CD6"
1486
- },
1487
- "keyword.module": {
1488
- color: "#c586c0"
1489
- },
1490
- "keyword.control-flow": {
1491
- color: "#c586c0"
1492
- },
1493
- function: {
1494
- color: "#dcdcaa"
1495
- },
1496
- "function.maybe-class-name": {
1497
- color: "#dcdcaa"
1498
- },
1499
- regex: {
1500
- color: "#d16969"
1501
- },
1502
- important: {
1503
- color: "#569cd6"
1504
- },
1505
- italic: {
1506
- fontStyle: "italic"
1507
- },
1508
- "class-name": {
1509
- color: "#4ec9b0"
1510
- },
1511
- "maybe-class-name": {
1512
- color: "#4ec9b0"
1513
- },
1514
- console: {
1515
- color: "#9cdcfe"
1516
- },
1517
- parameter: {
1518
- color: "#9cdcfe"
1519
- },
1520
- interpolation: {
1521
- color: "#9cdcfe"
1522
- },
1523
- "punctuation.interpolation-punctuation": {
1524
- color: "#569cd6"
1525
- },
1526
- variable: {
1527
- color: "#9cdcfe"
1528
- },
1529
- "imports.maybe-class-name": {
1530
- color: "#9cdcfe"
1531
- },
1532
- "exports.maybe-class-name": {
1533
- color: "#9cdcfe"
1534
- },
1535
- escape: {
1536
- color: "#d7ba7d"
1537
- },
1538
- "tag.punctuation": {
1539
- color: "#808080"
1540
- },
1541
- cdata: {
1542
- color: "#808080"
1543
- },
1544
- "attr-value": {
1545
- color: "#ce9178"
1546
- },
1547
- "attr-value.punctuation": {
1548
- color: "#ce9178"
1549
- },
1550
- "attr-value.punctuation.attr-equals": {
1551
- color: "#d4d4d4"
1552
- },
1553
- namespace: {
1554
- color: "#4ec9b0"
1555
- },
1556
- 'pre[class*="language-javascript"]': {
1557
- color: "#9cdcfe"
1558
- },
1559
- 'code[class*="language-javascript"]': {
1560
- color: "#9cdcfe"
1561
- },
1562
- 'pre[class*="language-jsx"]': {
1563
- color: "#9cdcfe"
1564
- },
1565
- 'code[class*="language-jsx"]': {
1566
- color: "#9cdcfe"
1567
- },
1568
- 'pre[class*="language-typescript"]': {
1569
- color: "#9cdcfe"
1570
- },
1571
- 'code[class*="language-typescript"]': {
1572
- color: "#9cdcfe"
1573
- },
1574
- 'pre[class*="language-tsx"]': {
1575
- color: "#9cdcfe"
1576
- },
1577
- 'code[class*="language-tsx"]': {
1578
- color: "#9cdcfe"
1579
- },
1580
- 'pre[class*="language-css"]': {
1581
- color: "#ce9178"
1582
- },
1583
- 'code[class*="language-css"]': {
1584
- color: "#ce9178"
1585
- },
1586
- 'pre[class*="language-html"]': {
1587
- color: "#d4d4d4"
1588
- },
1589
- 'code[class*="language-html"]': {
1590
- color: "#d4d4d4"
1591
- },
1592
- ".language-regex .token.anchor": {
1593
- color: "#dcdcaa"
1594
- },
1595
- ".language-html .token.punctuation": {
1596
- color: "#808080"
1597
- },
1598
- 'pre[class*="language-"] > code[class*="language-"]': {
1599
- position: "relative",
1600
- zIndex: "1"
1601
- },
1602
- ".line-highlight.line-highlight": {
1603
- background: "#f7ebc6",
1604
- boxShadow: "inset 5px 0 0 #f7d87c",
1605
- zIndex: "0"
1606
- }
1607
- };
1608
-
1609
- // src/components/chat/Markdown.tsx
1610
- var import_remark_gfm = __toESM(require("remark-gfm"));
1611
- var import_remark_math = __toESM(require("remark-math"));
1612
- var import_rehype_raw = __toESM(require("rehype-raw"));
1613
- var import_jsx_runtime12 = require("react/jsx-runtime");
1614
- var defaultComponents = {
1615
- a(_a) {
1616
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1617
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1618
- "a",
1619
- __spreadProps(__spreadValues({
1620
- className: "copilotKitMarkdownElement"
1621
- }, props), {
1622
- target: "_blank",
1623
- rel: "noopener noreferrer",
1624
- children
1625
- })
1626
- );
1627
- },
1628
- // @ts-expect-error -- inline
1629
- code(_c) {
1630
- var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
1631
- if (Array.isArray(children) && children.length) {
1632
- if (children[0] == "\u258D") {
1633
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1634
- "span",
1635
- {
1636
- style: {
1637
- animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
1638
- marginTop: "0.25rem"
1639
- },
1640
- children: "\u258D"
1641
- }
1642
- );
1643
- }
1644
- children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
1645
- }
1646
- const match = /language-(\w+)/.exec(className || "");
1647
- const hasLanguage = match && match[1];
1648
- const content = String(children);
1649
- const hasNewlines = content.includes("\n");
1650
- const isInline = !hasLanguage && !hasNewlines;
1651
- if (isInline) {
1652
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1653
- "code",
1654
- __spreadProps(__spreadValues({
1655
- className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
1656
- }, props), {
1657
- children
1658
- })
1659
- );
1660
- }
1661
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1662
- CodeBlock,
1663
- __spreadValues({
1664
- language: match && match[1] || "",
1665
- value: String(children).replace(/\n$/, "")
1666
- }, props),
1667
- Math.random()
1668
- );
1669
- },
1670
- h1: (_e) => {
1671
- var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
1672
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h1", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1673
- },
1674
- h2: (_g) => {
1675
- var _h = _g, { children } = _h, props = __objRest(_h, ["children"]);
1676
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h2", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1677
- },
1678
- h3: (_i) => {
1679
- var _j = _i, { children } = _j, props = __objRest(_j, ["children"]);
1680
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h3", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1681
- },
1682
- h4: (_k) => {
1683
- var _l = _k, { children } = _l, props = __objRest(_l, ["children"]);
1684
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h4", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1685
- },
1686
- h5: (_m) => {
1687
- var _n = _m, { children } = _n, props = __objRest(_n, ["children"]);
1688
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h5", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1689
- },
1690
- h6: (_o) => {
1691
- var _p = _o, { children } = _p, props = __objRest(_p, ["children"]);
1692
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h6", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1693
- },
1694
- p: (_q) => {
1695
- var _r = _q, { children } = _r, props = __objRest(_r, ["children"]);
1696
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1697
- },
1698
- pre: (_s) => {
1699
- var _t = _s, { children } = _t, props = __objRest(_t, ["children"]);
1700
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("pre", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1701
- },
1702
- blockquote: (_u) => {
1703
- var _v = _u, { children } = _v, props = __objRest(_v, ["children"]);
1704
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("blockquote", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1705
- },
1706
- ul: (_w) => {
1707
- var _x = _w, { children } = _x, props = __objRest(_x, ["children"]);
1708
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1709
- },
1710
- li: (_y) => {
1711
- var _z = _y, { children } = _z, props = __objRest(_z, ["children"]);
1712
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1713
- }
1714
- };
1715
- var MemoizedReactMarkdown = (0, import_react7.memo)(
1716
- import_react_markdown.default,
1717
- (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
1718
- );
1719
- var Markdown = ({ content, components }) => {
1720
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1721
- MemoizedReactMarkdown,
1722
- {
1723
- components: __spreadValues(__spreadValues({}, defaultComponents), components),
1724
- remarkPlugins: [
1725
- import_remark_gfm.default,
1726
- [import_remark_math.default, { singleDollarTextMath: false }]
1727
- ],
1728
- rehypePlugins: [import_rehype_raw.default],
1729
- children: content
1730
- }
1731
- ) });
1732
- };
1733
-
1734
- // src/components/chat/messages/AssistantMessage.tsx
1735
- var import_react8 = require("react");
1736
- var import_jsx_runtime13 = require("react/jsx-runtime");
1737
- var AssistantMessage = (props) => {
1738
- var _a, _b, _c;
1739
- const { icons, labels } = useChatContext();
1740
- const {
1741
- message,
1742
- isLoading,
1743
- onRegenerate,
1744
- onCopy,
1745
- onThumbsUp,
1746
- onThumbsDown,
1747
- isCurrentMessage,
1748
- feedback,
1749
- markdownTagRenderers
1750
- } = props;
1751
- const [copied, setCopied] = (0, import_react8.useState)(false);
1752
- const handleCopy = () => {
1753
- const content2 = (message == null ? void 0 : message.content) || "";
1754
- if (content2 && onCopy) {
1755
- navigator.clipboard.writeText(content2);
1756
- setCopied(true);
1757
- onCopy(content2);
1758
- setTimeout(() => setCopied(false), 2e3);
1759
- } else if (content2) {
1760
- navigator.clipboard.writeText(content2);
1761
- setCopied(true);
1762
- setTimeout(() => setCopied(false), 2e3);
1763
- }
1764
- };
1765
- const handleRegenerate = () => {
1766
- if (onRegenerate)
1767
- onRegenerate();
1768
- };
1769
- const handleThumbsUp = () => {
1770
- if (onThumbsUp && message) {
1771
- onThumbsUp(message);
1772
- }
1773
- };
1774
- const handleThumbsDown = () => {
1775
- if (onThumbsDown && message) {
1776
- onThumbsDown(message);
1777
- }
1778
- };
1779
- const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: icons.activityIcon });
1780
- const content = (message == null ? void 0 : message.content) || "";
1781
- const subComponent = (_b = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message)) != null ? _b : props.subComponent;
1782
- const subComponentPosition = (_c = message == null ? void 0 : message.generativeUIPosition) != null ? _c : "after";
1783
- const renderBefore = subComponent && subComponentPosition === "before";
1784
- const renderAfter = subComponent && subComponentPosition !== "before";
1785
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1786
- renderBefore ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
1787
- content && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
1788
- content && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Markdown, { content, components: markdownTagRenderers }),
1789
- content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1790
- "div",
1791
- {
1792
- className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
1793
- children: [
1794
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1795
- "button",
1796
- {
1797
- className: "copilotKitMessageControlButton",
1798
- onClick: handleRegenerate,
1799
- "aria-label": labels.regenerateResponse,
1800
- title: labels.regenerateResponse,
1801
- children: icons.regenerateIcon
1802
- }
1803
- ),
1804
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1805
- "button",
1806
- {
1807
- className: "copilotKitMessageControlButton",
1808
- onClick: handleCopy,
1809
- "aria-label": labels.copyToClipboard,
1810
- title: labels.copyToClipboard,
1811
- children: copied ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
1812
- }
1813
- ),
1814
- onThumbsUp && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1815
- "button",
1816
- {
1817
- className: `copilotKitMessageControlButton ${feedback === "thumbsUp" ? "active" : ""}`,
1818
- onClick: handleThumbsUp,
1819
- "aria-label": labels.thumbsUp,
1820
- title: labels.thumbsUp,
1821
- children: icons.thumbsUpIcon
1822
- }
1823
- ),
1824
- onThumbsDown && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1825
- "button",
1826
- {
1827
- className: `copilotKitMessageControlButton ${feedback === "thumbsDown" ? "active" : ""}`,
1828
- onClick: handleThumbsDown,
1829
- "aria-label": labels.thumbsDown,
1830
- title: labels.thumbsDown,
1831
- children: icons.thumbsDownIcon
1832
- }
1833
- )
1834
- ]
1835
- }
1836
- )
1837
- ] }),
1838
- renderAfter ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
1839
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(LoadingIcon, {})
1840
- ] });
1841
- };
1842
-
1843
- // src/components/chat/messages/ImageRenderer.tsx
1844
- var import_react9 = require("react");
1845
- var import_jsx_runtime14 = require("react/jsx-runtime");
1846
- var ImageRenderer = ({
1847
- image,
1848
- content,
1849
- className = ""
1850
- }) => {
1851
- const [imageError, setImageError] = (0, import_react9.useState)(false);
1852
- const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
1853
- const altText = content || "User uploaded image";
1854
- const handleImageError = () => {
1855
- setImageError(true);
1856
- };
1857
- if (imageError) {
1858
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1859
- "div",
1860
- {
1861
- className: `copilotKitImageRendering copilotKitImageRenderingError ${className}`,
1862
- children: [
1863
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingErrorMessage", children: "Failed to load image" }),
1864
- content && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1865
- ]
1866
- }
1867
- );
1868
- }
1869
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `copilotKitImageRendering ${className}`, children: [
1870
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1871
- "img",
1872
- {
1873
- src: imageSrc,
1874
- alt: altText,
1875
- className: "copilotKitImageRenderingImage",
1876
- onError: handleImageError
1877
- }
1878
- ),
1879
- content && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1880
- ] });
1881
- };
1882
-
1883
- // src/components/chat/messages/RenderMessage.tsx
1884
- var import_jsx_runtime15 = require("react/jsx-runtime");
1885
- function RenderMessage(_a) {
1886
- var _b = _a, {
1887
- UserMessage: UserMessage2 = UserMessage,
1888
- AssistantMessage: AssistantMessage2 = AssistantMessage,
1889
- ImageRenderer: ImageRenderer2 = ImageRenderer
1890
- } = _b, props = __objRest(_b, [
1891
- "UserMessage",
1892
- "AssistantMessage",
1893
- "ImageRenderer"
1894
- ]);
1895
- var _a2;
1896
- const {
1897
- message,
1898
- messages,
1899
- inProgress,
1900
- index,
1901
- isCurrentMessage,
1902
- onRegenerate,
1903
- onCopy,
1904
- onThumbsUp,
1905
- onThumbsDown,
1906
- messageFeedback,
1907
- markdownTagRenderers
1908
- } = props;
1909
- switch (message.role) {
1910
- case "user":
1911
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1912
- UserMessage2,
1913
- {
1914
- rawData: message,
1915
- "data-message-role": "user",
1916
- message,
1917
- ImageRenderer: ImageRenderer2
1918
- },
1919
- index
1920
- );
1921
- case "assistant":
1922
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1923
- AssistantMessage2,
1924
- {
1925
- "data-message-role": "assistant",
1926
- subComponent: (_a2 = message.generativeUI) == null ? void 0 : _a2.call(message),
1927
- rawData: message,
1928
- message,
1929
- messages,
1930
- isLoading: inProgress && isCurrentMessage && !message.content,
1931
- isGenerating: inProgress && isCurrentMessage && !!message.content,
1932
- isCurrentMessage,
1933
- onRegenerate: () => onRegenerate == null ? void 0 : onRegenerate(message.id),
1934
- onCopy,
1935
- onThumbsUp,
1936
- onThumbsDown,
1937
- feedback: (messageFeedback == null ? void 0 : messageFeedback[message.id]) || null,
1938
- markdownTagRenderers,
1939
- ImageRenderer: ImageRenderer2
1940
- },
1941
- index
1942
- );
1943
- default:
1944
- return null;
1945
- }
1946
- }
1947
-
1948
- // src/components/chat/messages/LegacyRenderMessage.tsx
1949
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1950
- var import_jsx_runtime16 = require("react/jsx-runtime");
1951
- var LegacyRenderMessage = ({
1952
- message,
1953
- messages,
1954
- inProgress,
1955
- index,
1956
- isCurrentMessage,
1957
- actionResult,
1958
- AssistantMessage: AssistantMessage2,
1959
- UserMessage: UserMessage2,
1960
- ImageRenderer: ImageRenderer2,
1961
- onRegenerate,
1962
- onCopy,
1963
- onThumbsUp,
1964
- onThumbsDown,
1965
- markdownTagRenderers,
1966
- legacyProps
1967
- }) => {
1968
- var _a;
1969
- const {
1970
- RenderTextMessage,
1971
- RenderActionExecutionMessage,
1972
- RenderAgentStateMessage,
1973
- RenderResultMessage,
1974
- RenderImageMessage
1975
- } = legacyProps;
1976
- const deprecatedMessage = (_a = (0, import_runtime_client_gql.aguiToGQL)(message)[0]) != null ? _a : void 0;
1977
- if (deprecatedMessage.isTextMessage() && RenderTextMessage) {
1978
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1979
- RenderTextMessage,
1980
- {
1981
- message,
1982
- messages,
1983
- inProgress,
1984
- index,
1985
- isCurrentMessage,
1986
- AssistantMessage: AssistantMessage2,
1987
- UserMessage: UserMessage2,
1988
- onRegenerate,
1989
- onCopy,
1990
- onThumbsUp,
1991
- onThumbsDown,
1992
- markdownTagRenderers
1993
- }
1994
- );
1995
- }
1996
- if (deprecatedMessage.isActionExecutionMessage() && RenderActionExecutionMessage) {
1997
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1998
- RenderActionExecutionMessage,
1999
- {
2000
- messages,
2001
- message,
2002
- inProgress,
2003
- index,
2004
- isCurrentMessage,
2005
- actionResult,
2006
- AssistantMessage: AssistantMessage2,
2007
- UserMessage: UserMessage2
2008
- }
2009
- );
2010
- }
2011
- if (deprecatedMessage.isAgentStateMessage() && RenderAgentStateMessage) {
2012
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2013
- RenderAgentStateMessage,
2014
- {
2015
- messages,
2016
- message,
2017
- inProgress,
2018
- index,
2019
- isCurrentMessage,
2020
- AssistantMessage: AssistantMessage2,
2021
- UserMessage: UserMessage2
2022
- }
2023
- );
2024
- }
2025
- if (deprecatedMessage.isResultMessage() && RenderResultMessage) {
2026
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2027
- RenderResultMessage,
2028
- {
2029
- messages,
2030
- message,
2031
- inProgress,
2032
- index,
2033
- isCurrentMessage,
2034
- AssistantMessage: AssistantMessage2,
2035
- UserMessage: UserMessage2
2036
- }
2037
- );
2038
- }
2039
- if (deprecatedMessage.isImageMessage() && RenderImageMessage) {
2040
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2041
- RenderImageMessage,
2042
- {
2043
- messages,
2044
- message,
2045
- inProgress,
2046
- index,
2047
- isCurrentMessage,
2048
- AssistantMessage: AssistantMessage2,
2049
- UserMessage: UserMessage2
2050
- }
2051
- );
2052
- }
2053
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2054
- RenderMessage,
2055
- {
2056
- messages,
2057
- message,
2058
- inProgress,
2059
- index,
2060
- isCurrentMessage,
2061
- AssistantMessage: AssistantMessage2,
2062
- UserMessage: UserMessage2,
2063
- ImageRenderer: ImageRenderer2,
2064
- onRegenerate,
2065
- onCopy,
2066
- onThumbsUp,
2067
- onThumbsDown,
2068
- markdownTagRenderers
2069
- }
2070
- );
2071
- };
2072
-
2073
- // src/components/chat/Messages.tsx
2074
- var import_jsx_runtime17 = require("react/jsx-runtime");
2075
- var Messages = ({
2076
- inProgress,
2077
- children,
2078
- RenderMessage: RenderMessage2,
2079
- AssistantMessage: AssistantMessage2,
2080
- UserMessage: UserMessage2,
2081
- ErrorMessage,
2082
- ImageRenderer: ImageRenderer2,
2083
- onRegenerate,
2084
- onCopy,
2085
- onThumbsUp,
2086
- onThumbsDown,
2087
- messageFeedback,
2088
- markdownTagRenderers,
2089
- chatError,
2090
- // Legacy props
2091
- RenderTextMessage,
2092
- RenderActionExecutionMessage,
2093
- RenderAgentStateMessage,
2094
- RenderResultMessage,
2095
- RenderImageMessage
2096
- }) => {
2097
- var _a;
2098
- const { labels, icons } = useChatContext();
2099
- const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
2100
- const initialMessages = (0, import_react10.useMemo)(
2101
- () => makeInitialMessages(labels.initial),
2102
- [labels.initial]
2103
- );
2104
- const messages = [...initialMessages, ...visibleMessages];
2105
- const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
2106
- const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
2107
- (0, import_react10.useEffect)(() => {
2108
- if (hasLegacyProps) {
2109
- console.warn(
2110
- "[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"
2111
- );
2112
- }
2113
- }, [hasLegacyProps]);
2114
- const legacyProps = (0, import_react10.useMemo)(
2115
- () => ({
2116
- RenderTextMessage,
2117
- RenderActionExecutionMessage,
2118
- RenderAgentStateMessage,
2119
- RenderResultMessage,
2120
- RenderImageMessage
2121
- }),
2122
- [
2123
- RenderTextMessage,
2124
- RenderActionExecutionMessage,
2125
- RenderAgentStateMessage,
2126
- RenderResultMessage,
2127
- RenderImageMessage
2128
- ]
2129
- );
2130
- const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(LegacyRenderMessage, __spreadProps(__spreadValues({}, props), { legacyProps })) : RenderMessage2;
2131
- const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: icons.activityIcon });
2132
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
2133
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "copilotKitMessagesContainer", children: [
2134
- messages.map((message, index) => {
2135
- const isCurrentMessage = index === messages.length - 1;
2136
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2137
- MessageRenderer,
2138
- {
2139
- message,
2140
- messages,
2141
- inProgress,
2142
- index,
2143
- isCurrentMessage,
2144
- AssistantMessage: AssistantMessage2,
2145
- UserMessage: UserMessage2,
2146
- ImageRenderer: ImageRenderer2,
2147
- onRegenerate,
2148
- onCopy,
2149
- onThumbsUp,
2150
- onThumbsDown,
2151
- messageFeedback,
2152
- markdownTagRenderers
2153
- },
2154
- index
2155
- );
2156
- }),
2157
- ((_a = messages[messages.length - 1]) == null ? void 0 : _a.role) === "user" && inProgress && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(LoadingIcon, {}),
2158
- interrupt,
2159
- chatError && ErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ErrorMessage, { error: chatError, isCurrentMessage: true })
2160
- ] }),
2161
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
2162
- ] });
2163
- };
2164
- function makeInitialMessages(initial) {
2165
- if (!initial)
2166
- return [];
2167
- if (Array.isArray(initial)) {
2168
- return initial.map((message) => {
2169
- return {
2170
- id: message,
2171
- role: "assistant",
2172
- content: message
2173
- };
2174
- });
2175
- }
2176
- return [
2177
- {
2178
- id: initial,
2179
- role: "assistant",
2180
- content: initial
2181
- }
2182
- ];
2183
- }
2184
- function useScrollToBottom(messages) {
2185
- const messagesEndRef = (0, import_react10.useRef)(null);
2186
- const messagesContainerRef = (0, import_react10.useRef)(null);
2187
- const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
2188
- const isUserScrollUpRef = (0, import_react10.useRef)(false);
2189
- const scrollToBottom = () => {
2190
- if (messagesContainerRef.current && messagesEndRef.current) {
2191
- isProgrammaticScrollRef.current = true;
2192
- messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
2193
- }
2194
- };
2195
- const handleScroll = () => {
2196
- if (isProgrammaticScrollRef.current) {
2197
- isProgrammaticScrollRef.current = false;
2198
- return;
2199
- }
2200
- if (messagesContainerRef.current) {
2201
- const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
2202
- isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
2203
- }
2204
- };
2205
- (0, import_react10.useEffect)(() => {
2206
- const container = messagesContainerRef.current;
2207
- if (container) {
2208
- container.addEventListener("scroll", handleScroll);
2209
- }
2210
- return () => {
2211
- if (container) {
2212
- container.removeEventListener("scroll", handleScroll);
2213
- }
2214
- };
2215
- }, []);
2216
- (0, import_react10.useEffect)(() => {
2217
- const container = messagesContainerRef.current;
2218
- if (!container) {
2219
- return;
2220
- }
2221
- const mutationObserver = new MutationObserver(() => {
2222
- if (!isUserScrollUpRef.current) {
2223
- scrollToBottom();
2224
- }
2225
- });
2226
- mutationObserver.observe(container, {
2227
- childList: true,
2228
- subtree: true,
2229
- characterData: true
2230
- });
2231
- return () => {
2232
- mutationObserver.disconnect();
2233
- };
2234
- }, []);
2235
- (0, import_react10.useEffect)(() => {
2236
- isUserScrollUpRef.current = false;
2237
- scrollToBottom();
2238
- }, [messages.filter((m) => m.role === "user").length]);
2239
- return { messagesEndRef, messagesContainerRef };
2240
- }
2241
-
2242
- // src/components/chat/Input.tsx
2243
- var import_react14 = require("react");
2244
-
2245
- // src/components/chat/Textarea.tsx
2246
- var import_react11 = require("react");
2247
- var import_jsx_runtime18 = require("react/jsx-runtime");
2248
- var AutoResizingTextarea = (0, import_react11.forwardRef)(
2249
- ({
2250
- maxRows = 1,
2251
- placeholder,
2252
- value,
2253
- onChange,
2254
- onKeyDown,
2255
- onCompositionStart,
2256
- onCompositionEnd,
2257
- autoFocus
2258
- }, ref) => {
2259
- const internalTextareaRef = (0, import_react11.useRef)(null);
2260
- const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
2261
- (0, import_react11.useImperativeHandle)(
2262
- ref,
2263
- () => internalTextareaRef.current
2264
- );
2265
- (0, import_react11.useEffect)(() => {
2266
- const calculateMaxHeight = () => {
2267
- const textarea = internalTextareaRef.current;
2268
- if (textarea) {
2269
- textarea.style.height = "auto";
2270
- const singleRowHeight = textarea.scrollHeight;
2271
- setMaxHeight(singleRowHeight * maxRows);
2272
- if (autoFocus) {
2273
- textarea.focus();
2274
- }
2275
- }
2276
- };
2277
- calculateMaxHeight();
2278
- }, [maxRows]);
2279
- (0, import_react11.useEffect)(() => {
2280
- const textarea = internalTextareaRef.current;
2281
- if (textarea) {
2282
- textarea.style.height = "auto";
2283
- textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
2284
- }
2285
- }, [value, maxHeight]);
2286
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2287
- "textarea",
2288
- {
2289
- ref: internalTextareaRef,
2290
- value,
2291
- onChange,
2292
- onKeyDown,
2293
- onCompositionStart,
2294
- onCompositionEnd,
2295
- placeholder,
2296
- style: {
2297
- overflow: "auto",
2298
- resize: "none",
2299
- maxHeight: `${maxHeight}px`
2300
- },
2301
- rows: 1
2302
- }
2303
- );
2304
- }
2305
- );
2306
- var Textarea_default = AutoResizingTextarea;
2307
-
2308
- // src/hooks/use-push-to-talk.tsx
2309
- var import_react_core6 = require("@copilotkit/react-core");
2310
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
2311
- var import_react12 = require("react");
2312
- var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
2313
- if (!mediaStreamRef.current || !audioContextRef.current) {
2314
- mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({
2315
- audio: true
2316
- });
2317
- audioContextRef.current = new window.AudioContext();
2318
- yield audioContextRef.current.resume();
2319
- }
2320
- mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
2321
- mediaRecorderRef.current.start(1e3);
2322
- mediaRecorderRef.current.ondataavailable = (event) => {
2323
- recordedChunks.push(event.data);
2324
- };
2325
- mediaRecorderRef.current.onstop = onStop;
2326
- });
2327
- var stopRecording = (mediaRecorderRef) => {
2328
- if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
2329
- mediaRecorderRef.current.stop();
2330
- }
2331
- };
2332
- var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
2333
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
2334
- const formData = new FormData();
2335
- formData.append("file", completeBlob, "recording.mp4");
2336
- const response = yield fetch(transcribeAudioUrl, {
2337
- method: "POST",
2338
- body: formData
2339
- });
2340
- if (!response.ok) {
2341
- throw new Error(`Error: ${response.statusText}`);
2342
- }
2343
- const transcription = yield response.json();
2344
- return transcription.text;
2345
- });
2346
- var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
2347
- const encodedText = encodeURIComponent(text);
2348
- const url = `${textToSpeechUrl}?text=${encodedText}`;
2349
- fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
2350
- const source = audioContext.createBufferSource();
2351
- source.buffer = audioBuffer;
2352
- source.connect(audioContext.destination);
2353
- source.start(0);
2354
- }).catch((error) => {
2355
- console.error("Error with decoding audio data", error);
2356
- });
2357
- };
2358
- var usePushToTalk = ({
2359
- sendFunction,
2360
- inProgress
2361
- }) => {
2362
- const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
2363
- const mediaStreamRef = (0, import_react12.useRef)(null);
2364
- const audioContextRef = (0, import_react12.useRef)(null);
2365
- const mediaRecorderRef = (0, import_react12.useRef)(null);
2366
- const recordedChunks = (0, import_react12.useRef)([]);
2367
- const generalContext = (0, import_react_core6.useCopilotContext)();
2368
- const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
2369
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
2370
- const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
2371
- (0, import_react12.useEffect)(() => {
2372
- if (pushToTalkState === "recording") {
2373
- startRecording(
2374
- mediaStreamRef,
2375
- mediaRecorderRef,
2376
- audioContextRef,
2377
- recordedChunks.current,
2378
- () => {
2379
- setPushToTalkState("transcribing");
2380
- }
2381
- );
2382
- } else {
2383
- stopRecording(mediaRecorderRef);
2384
- if (pushToTalkState === "transcribing") {
2385
- transcribeAudio(
2386
- recordedChunks.current,
2387
- context.copilotApiConfig.transcribeAudioUrl
2388
- ).then((transcription) => __async(void 0, null, function* () {
2389
- recordedChunks.current = [];
2390
- setPushToTalkState("idle");
2391
- const message = yield sendFunction(transcription);
2392
- setStartReadingFromMessageId(message.id);
2393
- }));
2394
- }
2395
- }
2396
- return () => {
2397
- stopRecording(mediaRecorderRef);
2398
- };
2399
- }, [pushToTalkState]);
2400
- (0, import_react12.useEffect)(() => {
2401
- if (inProgress === false && startReadingFromMessageId) {
2402
- const lastMessageIndex = context.messages.findIndex(
2403
- (message) => message.id === startReadingFromMessageId
2404
- );
2405
- const aguiMessages = (0, import_runtime_client_gql2.gqlToAGUI)(context.messages);
2406
- const messagesAfterLast = aguiMessages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant");
2407
- const text = messagesAfterLast.map((message) => message.content).join("\n");
2408
- playAudioResponse(
2409
- text,
2410
- context.copilotApiConfig.textToSpeechUrl,
2411
- audioContextRef.current
2412
- );
2413
- setStartReadingFromMessageId(null);
2414
- }
2415
- }, [startReadingFromMessageId, inProgress]);
2416
- return { pushToTalkState, setPushToTalkState };
2417
- };
2418
-
2419
- // src/components/chat/Input.tsx
2420
- var import_react_core7 = require("@copilotkit/react-core");
2421
-
2422
- // src/components/chat/PoweredByTag.tsx
2423
- var import_react13 = require("react");
2424
-
2425
- // src/hooks/use-dark-mode.ts
2426
- var useDarkMode = () => {
2427
- if (typeof window === "undefined")
2428
- return false;
2429
- 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;
2430
- };
2431
-
2432
- // src/components/chat/PoweredByTag.tsx
2433
- var import_jsx_runtime19 = require("react/jsx-runtime");
2434
- function PoweredByTag({
2435
- showPoweredBy = true
2436
- }) {
2437
- const [mounted, setMounted] = (0, import_react13.useState)(false);
2438
- const isDark = useDarkMode();
2439
- (0, import_react13.useEffect)(() => {
2440
- setMounted(true);
2441
- }, []);
2442
- if (!showPoweredBy) {
2443
- return null;
2444
- }
2445
- const poweredByStyle = {
2446
- visibility: "visible",
2447
- display: "block",
2448
- position: "static",
2449
- textAlign: "center",
2450
- fontSize: "12px",
2451
- padding: "3px 0",
2452
- color: mounted && isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)"
2453
- };
2454
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "poweredBy", style: poweredByStyle, children: "Powered by CopilotKit" }) });
2455
- }
2456
-
2457
- // src/components/chat/Input.tsx
2458
- var import_jsx_runtime20 = require("react/jsx-runtime");
2459
- var MAX_NEWLINES = 6;
2460
- var Input = ({
2461
- inProgress,
2462
- onSend,
2463
- chatReady = false,
2464
- onStop,
2465
- onUpload,
2466
- hideStopButton = false
2467
- }) => {
2468
- var _a;
2469
- const context = useChatContext();
2470
- const copilotContext = (0, import_react_core7.useCopilotContext)();
2471
- const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
2472
- const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
2473
- const textareaRef = (0, import_react14.useRef)(null);
2474
- const [isComposing, setIsComposing] = (0, import_react14.useState)(false);
2475
- const handleDivClick = (event) => {
2476
- var _a2;
2477
- const target = event.target;
2478
- if (target.closest("button"))
2479
- return;
2480
- if (target.tagName === "TEXTAREA")
2481
- return;
2482
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
2483
- };
2484
- const [text, setText] = (0, import_react14.useState)("");
2485
- const send = () => {
2486
- var _a2;
2487
- if (inProgress)
2488
- return;
2489
- onSend(text);
2490
- setText("");
2491
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
2492
- };
2493
- const { pushToTalkState, setPushToTalkState } = usePushToTalk({
2494
- sendFunction: onSend,
2495
- inProgress
2496
- });
2497
- const isInProgress = inProgress || pushToTalkState === "transcribing";
2498
- const { buttonIcon, buttonAlt } = (0, import_react14.useMemo)(() => {
2499
- if (!chatReady)
2500
- return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
2501
- return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
2502
- }, [
2503
- isInProgress,
2504
- chatReady,
2505
- hideStopButton,
2506
- context.icons.stopIcon,
2507
- context.icons.sendIcon
2508
- ]);
2509
- const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
2510
- const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
2511
- const canSend = (0, import_react14.useMemo)(() => {
2512
- return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
2513
- }, [interrupt, isInProgress, text, pushToTalkState]);
2514
- const canStop = (0, import_react14.useMemo)(() => {
2515
- return isInProgress && !hideStopButton;
2516
- }, [isInProgress, hideStopButton]);
2517
- const sendDisabled = !canSend && !canStop;
2518
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
2519
- "div",
2520
- {
2521
- className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`,
2522
- children: [
2523
- /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
2524
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2525
- Textarea_default,
2526
- {
2527
- ref: textareaRef,
2528
- placeholder: context.labels.placeholder,
2529
- autoFocus: false,
2530
- maxRows: MAX_NEWLINES,
2531
- value: text,
2532
- onChange: (event) => setText(event.target.value),
2533
- onCompositionStart: () => setIsComposing(true),
2534
- onCompositionEnd: () => setIsComposing(false),
2535
- onKeyDown: (event) => {
2536
- if (event.key === "Enter" && !event.shiftKey && !isComposing) {
2537
- event.preventDefault();
2538
- if (canSend) {
2539
- send();
2540
- }
2541
- }
2542
- }
2543
- }
2544
- ),
2545
- /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "copilotKitInputControls", children: [
2546
- onUpload && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
2547
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { style: { flexGrow: 1 } }),
2548
- showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2549
- "button",
2550
- {
2551
- onClick: () => setPushToTalkState(
2552
- pushToTalkState === "idle" ? "recording" : "transcribing"
2553
- ),
2554
- className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
2555
- children: context.icons.pushToTalkIcon
2556
- }
2557
- ),
2558
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2559
- "button",
2560
- {
2561
- disabled: sendDisabled,
2562
- onClick: isInProgress && !hideStopButton ? onStop : send,
2563
- "data-copilotkit-in-progress": inProgress,
2564
- "data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
2565
- className: "copilotKitInputControlButton",
2566
- "aria-label": buttonAlt,
2567
- children: buttonIcon
2568
- }
2569
- )
2570
- ] })
2571
- ] }),
2572
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(PoweredByTag, { showPoweredBy })
2573
- ]
2574
- }
2575
- );
2576
- };
2577
-
2578
- // src/components/chat/Chat.tsx
2579
- var import_react15 = __toESM(require("react"));
2580
- var import_react_core9 = require("@copilotkit/react-core");
2581
- var import_shared3 = require("@copilotkit/shared");
2582
-
2583
- // src/components/chat/ImageUploadQueue.tsx
2584
- var import_jsx_runtime21 = require("react/jsx-runtime");
2585
- var ImageUploadQueue = ({
2586
- images,
2587
- onRemoveImage,
2588
- className = ""
2589
- }) => {
2590
- if (images.length === 0)
2591
- return null;
2592
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2593
- "div",
2594
- {
2595
- className: `copilotKitImageUploadQueue ${className}`,
2596
- style: {
2597
- display: "flex",
2598
- flexWrap: "wrap",
2599
- gap: "8px",
2600
- margin: "8px",
2601
- padding: "8px"
2602
- },
2603
- children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2604
- "div",
2605
- {
2606
- className: "copilotKitImageUploadQueueItem",
2607
- style: {
2608
- position: "relative",
2609
- display: "inline-block",
2610
- width: "60px",
2611
- height: "60px",
2612
- borderRadius: "4px",
2613
- overflow: "hidden"
2614
- },
2615
- children: [
2616
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2617
- "img",
2618
- {
2619
- src: `data:${image.contentType};base64,${image.bytes}`,
2620
- alt: `Selected image ${index + 1}`,
2621
- style: {
2622
- width: "100%",
2623
- height: "100%",
2624
- objectFit: "cover"
2625
- }
2626
- }
2627
- ),
2628
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2629
- "button",
2630
- {
2631
- onClick: () => onRemoveImage(index),
2632
- className: "copilotKitImageUploadQueueRemoveButton",
2633
- style: {
2634
- position: "absolute",
2635
- top: "2px",
2636
- right: "2px",
2637
- background: "rgba(0,0,0,0.6)",
2638
- color: "white",
2639
- border: "none",
2640
- borderRadius: "50%",
2641
- width: "18px",
2642
- height: "18px",
2643
- display: "flex",
2644
- alignItems: "center",
2645
- justifyContent: "center",
2646
- cursor: "pointer",
2647
- fontSize: "10px",
2648
- padding: 0
2649
- },
2650
- children: "\u2715"
2651
- }
2652
- )
2653
- ]
2654
- },
2655
- index
2656
- ))
2657
- }
2658
- );
2659
- };
2660
-
2661
- // src/components/chat/Suggestion.tsx
2662
- var import_react_core8 = require("@copilotkit/react-core");
2663
- var import_jsx_runtime22 = require("react/jsx-runtime");
2664
- function Suggestion({
2665
- title,
2666
- onClick,
2667
- partial,
2668
- className
2669
- }) {
2670
- const { isLoading } = (0, import_react_core8.useCopilotChatInternal)();
2671
- if (!title)
2672
- return null;
2673
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2674
- "button",
2675
- {
2676
- disabled: partial || isLoading,
2677
- onClick: (e) => {
2678
- e.preventDefault();
2679
- onClick();
2680
- },
2681
- className: `suggestion ${className != null ? className : ""} ${partial ? "loading" : ""}`,
2682
- "data-test-id": "suggestion",
2683
- type: "button",
2684
- children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { children: title })
2685
- }
2686
- );
2687
- }
2688
-
2689
- // src/components/chat/Suggestions.tsx
2690
- var import_jsx_runtime23 = require("react/jsx-runtime");
2691
- function Suggestions({
2692
- suggestions,
2693
- onSuggestionClick,
2694
- isLoading
2695
- }) {
2696
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => {
2697
- var _a, _b;
2698
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2699
- Suggestion,
2700
- {
2701
- title: suggestion.title,
2702
- message: suggestion.message,
2703
- partial: (_b = (_a = suggestion.isLoading) != null ? _a : suggestion.partial) != null ? _b : isLoading,
2704
- className: suggestion.className,
2705
- onClick: () => onSuggestionClick(suggestion.message)
2706
- },
2707
- index
2708
- );
2709
- }) });
2710
- }
2711
-
2712
- // src/components/chat/Chat.tsx
2713
- var import_jsx_runtime24 = require("react/jsx-runtime");
2714
- function CopilotChat({
2715
- instructions,
2716
- suggestions = "auto",
2717
- onSubmitMessage,
2718
- makeSystemMessage,
2719
- disableSystemMessage,
2720
- onInProgress,
2721
- onStopGeneration,
2722
- onReloadMessages,
2723
- onRegenerate,
2724
- onCopy,
2725
- onThumbsUp,
2726
- onThumbsDown,
2727
- markdownTagRenderers,
2728
- Messages: Messages2 = Messages,
2729
- RenderMessage: RenderMessage2 = RenderMessage,
2730
- RenderSuggestionsList = Suggestions,
2731
- Input: Input2 = Input,
2732
- className,
2733
- icons,
2734
- labels,
2735
- AssistantMessage: AssistantMessage2 = AssistantMessage,
2736
- UserMessage: UserMessage2 = UserMessage,
2737
- ImageRenderer: ImageRenderer2 = ImageRenderer,
2738
- ErrorMessage,
2739
- imageUploadsEnabled,
2740
- inputFileAccept = "image/*",
2741
- hideStopButton,
2742
- observabilityHooks,
2743
- renderError,
2744
- onError,
2745
- // Legacy props - deprecated
2746
- RenderTextMessage,
2747
- RenderActionExecutionMessage,
2748
- RenderAgentStateMessage,
2749
- RenderResultMessage,
2750
- RenderImageMessage
2751
- }) {
2752
- const {
2753
- additionalInstructions,
2754
- setChatInstructions,
2755
- copilotApiConfig,
2756
- setBannerError,
2757
- setInternalErrorHandler,
2758
- removeInternalErrorHandler
2759
- } = (0, import_react_core9.useCopilotContext)();
2760
- const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
2761
- const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
2762
- const [chatError, setChatError] = (0, import_react15.useState)(null);
2763
- const [messageFeedback, setMessageFeedback] = (0, import_react15.useState)({});
2764
- const fileInputRef = (0, import_react15.useRef)(null);
2765
- const triggerObservabilityHook = (0, import_react15.useCallback)(
2766
- (hookName, ...args) => {
2767
- if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2768
- observabilityHooks[hookName](...args);
2769
- }
2770
- if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
2771
- setBannerError(
2772
- new import_shared3.CopilotKitError({
2773
- message: "observabilityHooks requires a publicApiKey to function.",
2774
- code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2775
- severity: import_shared3.Severity.CRITICAL,
2776
- visibility: import_shared3.ErrorVisibility.BANNER
2777
- })
2778
- );
2779
- import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2780
- }
2781
- },
2782
- [publicApiKey, observabilityHooks, setBannerError]
2783
- );
2784
- const triggerChatError = (0, import_react15.useCallback)(
2785
- (error, operation, originalError) => {
2786
- const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
2787
- setChatError({
2788
- message: errorMessage,
2789
- operation,
2790
- timestamp: Date.now()
2791
- });
2792
- const errorEvent = {
2793
- type: "error",
2794
- timestamp: Date.now(),
2795
- context: {
2796
- source: "ui",
2797
- request: {
2798
- operation,
2799
- url: chatApiEndpoint,
2800
- startTime: Date.now()
2801
- },
2802
- technical: {
2803
- environment: "browser",
2804
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
2805
- stackTrace: originalError instanceof Error ? originalError.stack : void 0
2806
- }
2807
- },
2808
- error
2809
- };
2810
- if (onError) {
2811
- onError(errorEvent);
2812
- }
2813
- if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
2814
- observabilityHooks.onError(errorEvent);
2815
- }
2816
- if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
2817
- setBannerError(
2818
- new import_shared3.CopilotKitError({
2819
- message: "observabilityHooks.onError requires a publicApiKey to function.",
2820
- code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2821
- severity: import_shared3.Severity.CRITICAL,
2822
- visibility: import_shared3.ErrorVisibility.BANNER
2823
- })
2824
- );
2825
- import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks.onError");
2826
- }
2827
- },
2828
- [publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
2829
- );
2830
- (0, import_react15.useEffect)(() => {
2831
- const id = "chat-component";
2832
- setInternalErrorHandler({
2833
- [id]: (error) => {
2834
- if (!error)
2835
- return;
2836
- triggerChatError(error.error, "sendMessage");
2837
- }
2838
- });
2839
- return () => {
2840
- removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
2841
- };
2842
- }, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
2843
- (0, import_react15.useEffect)(() => {
2844
- if (!imageUploadsEnabled)
2845
- return;
2846
- const handlePaste = (e) => __async(this, null, function* () {
2847
- var _a, _b;
2848
- const target = e.target;
2849
- if (!((_a = target.parentElement) == null ? void 0 : _a.classList.contains("copilotKitInput")))
2850
- return;
2851
- const items = Array.from(((_b = e.clipboardData) == null ? void 0 : _b.items) || []);
2852
- const imageItems = items.filter((item) => item.type.startsWith("image/"));
2853
- if (imageItems.length === 0)
2854
- return;
2855
- e.preventDefault();
2856
- const imagePromises = imageItems.map(
2857
- (item) => {
2858
- const file = item.getAsFile();
2859
- if (!file)
2860
- return Promise.resolve(null);
2861
- return new Promise((resolve, reject) => {
2862
- const reader = new FileReader();
2863
- reader.onload = (e2) => {
2864
- var _a2, _b2;
2865
- const base64String = (_b2 = (_a2 = e2.target) == null ? void 0 : _a2.result) == null ? void 0 : _b2.split(",")[1];
2866
- if (base64String) {
2867
- resolve({
2868
- contentType: file.type,
2869
- bytes: base64String
2870
- });
2871
- } else {
2872
- resolve(null);
2873
- }
2874
- };
2875
- reader.onerror = reject;
2876
- reader.readAsDataURL(file);
2877
- });
2878
- }
2879
- );
2880
- try {
2881
- const loadedImages = (yield Promise.all(imagePromises)).filter(
2882
- (img) => img !== null
2883
- );
2884
- setSelectedImages((prev) => [...prev, ...loadedImages]);
2885
- } catch (error) {
2886
- triggerChatError(error, "processClipboardImages", error);
2887
- console.error("Error processing pasted images:", error);
2888
- }
2889
- });
2890
- document.addEventListener("paste", handlePaste);
2891
- return () => document.removeEventListener("paste", handlePaste);
2892
- }, [imageUploadsEnabled, triggerChatError]);
2893
- (0, import_react15.useEffect)(() => {
2894
- if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
2895
- setChatInstructions(instructions || "");
2896
- return;
2897
- }
2898
- const combinedAdditionalInstructions = [
2899
- instructions,
2900
- "Additionally, follow these instructions:",
2901
- ...additionalInstructions.map((instruction) => `- ${instruction}`)
2902
- ];
2903
- setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
2904
- }, [instructions, additionalInstructions]);
2905
- const {
2906
- messages,
2907
- isLoading,
2908
- sendMessage,
2909
- stopGeneration,
2910
- reloadMessages,
2911
- suggestions: currentSuggestions,
2912
- isLoadingSuggestions,
2913
- agent
2914
- } = (0, import_react_core9.useCopilotChatInternal)({
2915
- suggestions,
2916
- onInProgress,
2917
- onSubmitMessage,
2918
- onStopGeneration,
2919
- onReloadMessages
2920
- });
2921
- const prevIsLoading = (0, import_react15.useRef)(isLoading);
2922
- (0, import_react15.useEffect)(() => {
2923
- if (prevIsLoading.current !== isLoading) {
2924
- if (isLoading) {
2925
- triggerObservabilityHook("onChatStarted");
2926
- } else {
2927
- triggerObservabilityHook("onChatStopped");
2928
- }
2929
- prevIsLoading.current = isLoading;
2930
- }
2931
- }, [isLoading, triggerObservabilityHook]);
2932
- const handleSendMessage = (text) => {
2933
- const images = selectedImages;
2934
- setSelectedImages([]);
2935
- if (fileInputRef.current) {
2936
- fileInputRef.current.value = "";
2937
- }
2938
- triggerObservabilityHook("onMessageSent", text);
2939
- return sendMessage({
2940
- id: (0, import_shared3.randomUUID)(),
2941
- content: text,
2942
- role: "user"
2943
- });
2944
- };
2945
- const chatContext = import_react15.default.useContext(ChatContext);
2946
- const isVisible = chatContext ? chatContext.open : true;
2947
- const handleRegenerate = (messageId) => {
2948
- if (onRegenerate) {
2949
- onRegenerate(messageId);
2950
- }
2951
- triggerObservabilityHook("onMessageRegenerated", messageId);
2952
- reloadMessages(messageId);
2953
- };
2954
- const handleCopy = (message) => {
2955
- if (onCopy) {
2956
- onCopy(message);
2957
- }
2958
- triggerObservabilityHook("onMessageCopied", message);
2959
- };
2960
- const handleImageUpload = (event) => __async(this, null, function* () {
2961
- if (!event.target.files || event.target.files.length === 0) {
2962
- return;
2963
- }
2964
- const files = Array.from(event.target.files).filter(
2965
- (file) => file.type.startsWith("image/")
2966
- );
2967
- if (files.length === 0)
2968
- return;
2969
- const fileReadPromises = files.map((file) => {
2970
- return new Promise(
2971
- (resolve, reject) => {
2972
- const reader = new FileReader();
2973
- reader.onload = (e) => {
2974
- var _a, _b;
2975
- const base64String = ((_b = (_a = e.target) == null ? void 0 : _a.result) == null ? void 0 : _b.split(",")[1]) || "";
2976
- if (base64String) {
2977
- resolve({
2978
- contentType: file.type,
2979
- bytes: base64String
2980
- });
2981
- }
2982
- };
2983
- reader.onerror = reject;
2984
- reader.readAsDataURL(file);
2985
- }
2986
- );
2987
- });
2988
- try {
2989
- const loadedImages = yield Promise.all(fileReadPromises);
2990
- setSelectedImages((prev) => [...prev, ...loadedImages]);
2991
- } catch (error) {
2992
- triggerChatError(error, "processUploadedImages", error);
2993
- console.error("Error reading files:", error);
2994
- }
2995
- });
2996
- const removeSelectedImage = (index) => {
2997
- setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2998
- };
2999
- const handleThumbsUp = (message) => {
3000
- if (onThumbsUp) {
3001
- onThumbsUp(message);
3002
- }
3003
- setMessageFeedback((prev) => __spreadProps(__spreadValues({}, prev), {
3004
- [message.id]: "thumbsUp"
3005
- }));
3006
- triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
3007
- };
3008
- const handleThumbsDown = (message) => {
3009
- if (onThumbsDown) {
3010
- onThumbsDown(message);
3011
- }
3012
- setMessageFeedback((prev) => __spreadProps(__spreadValues({}, prev), {
3013
- [message.id]: "thumbsDown"
3014
- }));
3015
- triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
3016
- };
3017
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
3018
- chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
3019
- onDismiss: () => setChatError(null),
3020
- onRetry: () => {
3021
- setChatError(null);
3022
- }
3023
- })),
3024
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3025
- Messages2,
3026
- {
3027
- AssistantMessage: AssistantMessage2,
3028
- UserMessage: UserMessage2,
3029
- RenderMessage: RenderMessage2,
3030
- messages,
3031
- inProgress: isLoading,
3032
- onRegenerate: handleRegenerate,
3033
- onCopy: handleCopy,
3034
- onThumbsUp: handleThumbsUp,
3035
- onThumbsDown: handleThumbsDown,
3036
- messageFeedback,
3037
- markdownTagRenderers,
3038
- ImageRenderer: ImageRenderer2,
3039
- ErrorMessage,
3040
- chatError,
3041
- RenderTextMessage,
3042
- RenderActionExecutionMessage,
3043
- RenderAgentStateMessage,
3044
- RenderResultMessage,
3045
- RenderImageMessage,
3046
- children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3047
- RenderSuggestionsList,
3048
- {
3049
- onSuggestionClick: handleSendMessage,
3050
- suggestions: currentSuggestions,
3051
- isLoading: isLoadingSuggestions
3052
- }
3053
- )
3054
- }
3055
- ),
3056
- imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
3057
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3058
- ImageUploadQueue,
3059
- {
3060
- images: selectedImages,
3061
- onRemoveImage: removeSelectedImage
3062
- }
3063
- ),
3064
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3065
- "input",
3066
- {
3067
- type: "file",
3068
- multiple: true,
3069
- ref: fileInputRef,
3070
- onChange: handleImageUpload,
3071
- accept: inputFileAccept,
3072
- style: { display: "none" }
3073
- }
3074
- )
3075
- ] }),
3076
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3077
- Input2,
3078
- {
3079
- inProgress: isLoading,
3080
- chatReady: Boolean(agent),
3081
- onSend: handleSendMessage,
3082
- isVisible,
3083
- onStop: stopGeneration,
3084
- onUpload: imageUploadsEnabled ? () => {
3085
- var _a;
3086
- return (_a = fileInputRef.current) == null ? void 0 : _a.click();
3087
- } : void 0,
3088
- hideStopButton
3089
- }
3090
- )
3091
- ] });
3092
- }
3093
- function WrappedCopilotChat({
3094
- children,
3095
- icons,
3096
- labels,
3097
- className
3098
- }) {
3099
- const chatContext = import_react15.default.useContext(ChatContext);
3100
- if (!chatContext) {
3101
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3102
- ChatContextProvider,
3103
- {
3104
- icons,
3105
- labels,
3106
- open: true,
3107
- setOpen: () => {
3108
- },
3109
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children })
3110
- }
3111
- );
3112
- }
3113
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children });
3114
- }
3115
-
3116
- // src/components/chat/Modal.tsx
3117
- var import_react_core10 = require("@copilotkit/react-core");
3118
- var import_shared4 = require("@copilotkit/shared");
3119
- var import_jsx_runtime25 = require("react/jsx-runtime");
3120
- var CopilotModalInner = (_a) => {
3121
- var _b = _a, {
3122
- observabilityHooks,
3123
- onSetOpen,
3124
- clickOutsideToClose,
3125
- hitEscapeToClose,
3126
- shortcut,
3127
- className,
3128
- children,
3129
- Window: Window2,
3130
- Button: Button2,
3131
- Header: Header2
3132
- } = _b, chatProps = __objRest(_b, [
3133
- "observabilityHooks",
3134
- "onSetOpen",
3135
- "clickOutsideToClose",
3136
- "hitEscapeToClose",
3137
- "shortcut",
3138
- "className",
3139
- "children",
3140
- "Window",
3141
- "Button",
3142
- "Header"
3143
- ]);
3144
- const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
3145
- const { publicApiKey } = copilotApiConfig;
3146
- const triggerObservabilityHook = (0, import_react16.useCallback)(
3147
- (hookName, ...args) => {
3148
- if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
3149
- observabilityHooks[hookName](...args);
3150
- }
3151
- if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
3152
- setBannerError(
3153
- new import_shared4.CopilotKitError({
3154
- message: "observabilityHooks requires a publicApiKey to function.",
3155
- code: import_shared4.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
3156
- severity: import_shared4.Severity.CRITICAL,
3157
- visibility: import_shared4.ErrorVisibility.BANNER
3158
- })
3159
- );
3160
- import_shared4.styledConsole.publicApiKeyRequired("observabilityHooks");
3161
- }
3162
- },
3163
- [publicApiKey, observabilityHooks, setBannerError]
3164
- );
3165
- const { open } = useChatContext();
3166
- const prevOpen = (0, import_react16.useRef)(open);
3167
- (0, import_react16.useEffect)(() => {
3168
- if (prevOpen.current !== open) {
3169
- onSetOpen == null ? void 0 : onSetOpen(open);
3170
- if (open) {
3171
- triggerObservabilityHook("onChatExpanded");
3172
- } else {
3173
- triggerObservabilityHook("onChatMinimized");
3174
- }
3175
- prevOpen.current = open;
3176
- }
3177
- }, [open, onSetOpen, triggerObservabilityHook]);
3178
- const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
3179
- const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
3180
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
3181
- memoizedChildren,
3182
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
3183
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Button2, {}),
3184
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
3185
- Window2,
3186
- {
3187
- clickOutsideToClose,
3188
- shortcut,
3189
- hitEscapeToClose,
3190
- children: [
3191
- memoizedHeader,
3192
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
3193
- ]
3194
- }
3195
- )
3196
- ] })
3197
- ] });
3198
- };
3199
- var CopilotModal = (_a) => {
3200
- var _b = _a, {
3201
- instructions,
3202
- defaultOpen = false,
3203
- clickOutsideToClose = true,
3204
- hitEscapeToClose = true,
3205
- onSetOpen,
3206
- onSubmitMessage,
3207
- onStopGeneration,
3208
- onReloadMessages,
3209
- shortcut = "/",
3210
- icons,
3211
- labels,
3212
- makeSystemMessage,
3213
- onInProgress,
3214
- Window: Window2 = Window,
3215
- Button: Button2 = Button,
3216
- Header: Header2 = Header,
3217
- Messages: Messages2 = Messages,
3218
- Input: Input2 = Input,
3219
- AssistantMessage: AssistantMessage2 = AssistantMessage,
3220
- UserMessage: UserMessage2 = UserMessage,
3221
- onThumbsUp,
3222
- onThumbsDown,
3223
- onCopy,
3224
- onRegenerate,
3225
- markdownTagRenderers,
3226
- className,
3227
- children,
3228
- observabilityHooks
3229
- } = _b, props = __objRest(_b, [
3230
- "instructions",
3231
- "defaultOpen",
3232
- "clickOutsideToClose",
3233
- "hitEscapeToClose",
3234
- "onSetOpen",
3235
- "onSubmitMessage",
3236
- "onStopGeneration",
3237
- "onReloadMessages",
3238
- "shortcut",
3239
- "icons",
3240
- "labels",
3241
- "makeSystemMessage",
3242
- "onInProgress",
3243
- "Window",
3244
- "Button",
3245
- "Header",
3246
- "Messages",
3247
- "Input",
3248
- "AssistantMessage",
3249
- "UserMessage",
3250
- "onThumbsUp",
3251
- "onThumbsDown",
3252
- "onCopy",
3253
- "onRegenerate",
3254
- "markdownTagRenderers",
3255
- "className",
3256
- "children",
3257
- "observabilityHooks"
3258
- ]);
3259
- const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
3260
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
3261
- ChatContextProvider,
3262
- {
3263
- icons,
3264
- labels,
3265
- open: openState,
3266
- setOpen: setOpenState,
3267
- children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
3268
- CopilotModalInner,
3269
- __spreadProps(__spreadValues({
3270
- observabilityHooks,
3271
- onSetOpen,
3272
- clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
3273
- hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
3274
- shortcut: shortcut != null ? shortcut : "/",
3275
- className,
3276
- Window: Window2,
3277
- Button: Button2,
3278
- Header: Header2,
3279
- instructions,
3280
- onSubmitMessage,
3281
- onStopGeneration,
3282
- onReloadMessages,
3283
- makeSystemMessage,
3284
- onInProgress,
3285
- Messages: Messages2,
3286
- Input: Input2,
3287
- AssistantMessage: AssistantMessage2,
3288
- UserMessage: UserMessage2,
3289
- onThumbsUp,
3290
- onThumbsDown,
3291
- onCopy,
3292
- onRegenerate,
3293
- markdownTagRenderers
3294
- }, props), {
3295
- children
3296
- })
3297
- )
3298
- }
3299
- );
3300
- };
3301
-
3302
- // src/components/chat/Popup.tsx
3303
- var import_jsx_runtime26 = require("react/jsx-runtime");
3304
- function CopilotPopup(props) {
3305
- props = __spreadProps(__spreadValues({}, props), {
3306
- className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
3307
- });
3308
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
3309
- }
3310
-
3311
- // src/components/chat/Sidebar.tsx
3312
- var import_react17 = require("react");
3313
- var import_jsx_runtime27 = require("react/jsx-runtime");
3314
- function CopilotSidebar(props) {
3315
- props = __spreadProps(__spreadValues({}, props), {
3316
- className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
3317
- });
3318
- const [expandedClassName, setExpandedClassName] = (0, import_react17.useState)(
3319
- props.defaultOpen ? "sidebarExpanded" : ""
3320
- );
3321
- const onSetOpen = (open) => {
3322
- var _a;
3323
- (_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
3324
- setExpandedClassName(open ? "sidebarExpanded" : "");
3325
- };
3326
- return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(CopilotModal, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
3327
- }
3328
- // Annotate the CommonJS export names for ESM import in node:
3329
- 0 && (module.exports = {
3330
- AssistantMessage,
3331
- CopilotChat,
3332
- CopilotPopup,
3333
- CopilotSidebar,
3334
- ImageRenderer,
3335
- Markdown,
3336
- RenderSuggestion,
3337
- RenderSuggestionsList,
3338
- UserMessage,
3339
- useChatContext
3340
- });
3341
- //# sourceMappingURL=index.js.map