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