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