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