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