@copilotkit/react-ui 0.0.0-test-custom-tag-prerelease-1-20250108200215

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 (352) hide show
  1. package/CHANGELOG.md +2134 -0
  2. package/README.md +46 -0
  3. package/dist/chunk-375NVWZM.mjs +21 -0
  4. package/dist/chunk-375NVWZM.mjs.map +1 -0
  5. package/dist/chunk-3E7HY2UN.mjs +85 -0
  6. package/dist/chunk-3E7HY2UN.mjs.map +1 -0
  7. package/dist/chunk-3XAXY2Z3.mjs +18 -0
  8. package/dist/chunk-3XAXY2Z3.mjs.map +1 -0
  9. package/dist/chunk-54JAUBUJ.mjs +26 -0
  10. package/dist/chunk-54JAUBUJ.mjs.map +1 -0
  11. package/dist/chunk-6INMITFA.mjs +18 -0
  12. package/dist/chunk-6INMITFA.mjs.map +1 -0
  13. package/dist/chunk-7II4YL7R.mjs +170 -0
  14. package/dist/chunk-7II4YL7R.mjs.map +1 -0
  15. package/dist/chunk-BH6PCAAL.mjs +81 -0
  16. package/dist/chunk-BH6PCAAL.mjs.map +1 -0
  17. package/dist/chunk-CBBFRI3Q.mjs +81 -0
  18. package/dist/chunk-CBBFRI3Q.mjs.map +1 -0
  19. package/dist/chunk-DCNCY2PL.mjs +304 -0
  20. package/dist/chunk-DCNCY2PL.mjs.map +1 -0
  21. package/dist/chunk-EFZPSZWO.mjs +1 -0
  22. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  23. package/dist/chunk-EMQEEXUB.mjs +97 -0
  24. package/dist/chunk-EMQEEXUB.mjs.map +1 -0
  25. package/dist/chunk-F2W5FD7L.mjs +232 -0
  26. package/dist/chunk-F2W5FD7L.mjs.map +1 -0
  27. package/dist/chunk-FZC7X5PK.mjs +262 -0
  28. package/dist/chunk-FZC7X5PK.mjs.map +1 -0
  29. package/dist/chunk-IU3WTXLQ.mjs +1 -0
  30. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  31. package/dist/chunk-KXE2JCUH.mjs +1 -0
  32. package/dist/chunk-KXE2JCUH.mjs.map +1 -0
  33. package/dist/chunk-MMVDU6DF.mjs +1 -0
  34. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  35. package/dist/chunk-MRFF7GSQ.mjs +1 -0
  36. package/dist/chunk-MRFF7GSQ.mjs.map +1 -0
  37. package/dist/chunk-MRXNTQOX.mjs +59 -0
  38. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  39. package/dist/chunk-OTPAZXVR.mjs +92 -0
  40. package/dist/chunk-OTPAZXVR.mjs.map +1 -0
  41. package/dist/chunk-PNQVKBPN.mjs +146 -0
  42. package/dist/chunk-PNQVKBPN.mjs.map +1 -0
  43. package/dist/chunk-RJCZRKTV.mjs +106 -0
  44. package/dist/chunk-RJCZRKTV.mjs.map +1 -0
  45. package/dist/chunk-RQNJNK2W.mjs +25 -0
  46. package/dist/chunk-RQNJNK2W.mjs.map +1 -0
  47. package/dist/chunk-RU73BEZM.mjs +41 -0
  48. package/dist/chunk-RU73BEZM.mjs.map +1 -0
  49. package/dist/chunk-S5MBUNGN.mjs +140 -0
  50. package/dist/chunk-S5MBUNGN.mjs.map +1 -0
  51. package/dist/chunk-T26KLXLH.mjs +1 -0
  52. package/dist/chunk-T26KLXLH.mjs.map +1 -0
  53. package/dist/chunk-TI7SY2RI.mjs +164 -0
  54. package/dist/chunk-TI7SY2RI.mjs.map +1 -0
  55. package/dist/chunk-UPTB2MVO.mjs +395 -0
  56. package/dist/chunk-UPTB2MVO.mjs.map +1 -0
  57. package/dist/chunk-UWVGLGFQ.mjs +95 -0
  58. package/dist/chunk-UWVGLGFQ.mjs.map +1 -0
  59. package/dist/chunk-V7W6IM2V.mjs +1 -0
  60. package/dist/chunk-V7W6IM2V.mjs.map +1 -0
  61. package/dist/chunk-VEC45H6Q.mjs +18 -0
  62. package/dist/chunk-VEC45H6Q.mjs.map +1 -0
  63. package/dist/chunk-WB3YULQ4.mjs +1 -0
  64. package/dist/chunk-WB3YULQ4.mjs.map +1 -0
  65. package/dist/chunk-WSMMTZCM.mjs +30 -0
  66. package/dist/chunk-WSMMTZCM.mjs.map +1 -0
  67. package/dist/chunk-YAGE7RCE.mjs +118 -0
  68. package/dist/chunk-YAGE7RCE.mjs.map +1 -0
  69. package/dist/chunk-YQ3D5IQV.mjs +75 -0
  70. package/dist/chunk-YQ3D5IQV.mjs.map +1 -0
  71. package/dist/chunk-YQFVRDNC.mjs +53 -0
  72. package/dist/chunk-YQFVRDNC.mjs.map +1 -0
  73. package/dist/chunk-Z2UZSN3K.mjs +29 -0
  74. package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
  75. package/dist/chunk-ZABXREBH.mjs +65 -0
  76. package/dist/chunk-ZABXREBH.mjs.map +1 -0
  77. package/dist/components/chat/Button.d.ts +7 -0
  78. package/dist/components/chat/Button.js +71 -0
  79. package/dist/components/chat/Button.js.map +1 -0
  80. package/dist/components/chat/Button.mjs +10 -0
  81. package/dist/components/chat/Button.mjs.map +1 -0
  82. package/dist/components/chat/Chat.d.ts +148 -0
  83. package/dist/components/chat/Chat.js +2427 -0
  84. package/dist/components/chat/Chat.js.map +1 -0
  85. package/dist/components/chat/Chat.mjs +34 -0
  86. package/dist/components/chat/Chat.mjs.map +1 -0
  87. package/dist/components/chat/ChatContext.d.ts +105 -0
  88. package/dist/components/chat/ChatContext.js +279 -0
  89. package/dist/components/chat/ChatContext.js.map +1 -0
  90. package/dist/components/chat/ChatContext.mjs +13 -0
  91. package/dist/components/chat/ChatContext.mjs.map +1 -0
  92. package/dist/components/chat/CodeBlock.d.ts +14 -0
  93. package/dist/components/chat/CodeBlock.js +523 -0
  94. package/dist/components/chat/CodeBlock.js.map +1 -0
  95. package/dist/components/chat/CodeBlock.mjs +14 -0
  96. package/dist/components/chat/CodeBlock.mjs.map +1 -0
  97. package/dist/components/chat/Header.d.ts +7 -0
  98. package/dist/components/chat/Header.js +64 -0
  99. package/dist/components/chat/Header.js.map +1 -0
  100. package/dist/components/chat/Header.mjs +10 -0
  101. package/dist/components/chat/Header.mjs.map +1 -0
  102. package/dist/components/chat/Icons.d.ts +18 -0
  103. package/dist/components/chat/Icons.js +321 -0
  104. package/dist/components/chat/Icons.js.map +1 -0
  105. package/dist/components/chat/Icons.mjs +32 -0
  106. package/dist/components/chat/Icons.mjs.map +1 -0
  107. package/dist/components/chat/Input.d.ts +7 -0
  108. package/dist/components/chat/Input.js +324 -0
  109. package/dist/components/chat/Input.js.map +1 -0
  110. package/dist/components/chat/Input.mjs +12 -0
  111. package/dist/components/chat/Input.mjs.map +1 -0
  112. package/dist/components/chat/Markdown.d.ts +8 -0
  113. package/dist/components/chat/Markdown.js +583 -0
  114. package/dist/components/chat/Markdown.js.map +1 -0
  115. package/dist/components/chat/Markdown.mjs +11 -0
  116. package/dist/components/chat/Markdown.mjs.map +1 -0
  117. package/dist/components/chat/Messages.d.ts +12 -0
  118. package/dist/components/chat/Messages.js +217 -0
  119. package/dist/components/chat/Messages.js.map +1 -0
  120. package/dist/components/chat/Messages.mjs +12 -0
  121. package/dist/components/chat/Messages.mjs.map +1 -0
  122. package/dist/components/chat/Modal.d.ts +51 -0
  123. package/dist/components/chat/Modal.js +2626 -0
  124. package/dist/components/chat/Modal.js.map +1 -0
  125. package/dist/components/chat/Modal.mjs +34 -0
  126. package/dist/components/chat/Modal.mjs.map +1 -0
  127. package/dist/components/chat/Popup.d.ts +13 -0
  128. package/dist/components/chat/Popup.js +2637 -0
  129. package/dist/components/chat/Popup.js.map +1 -0
  130. package/dist/components/chat/Popup.mjs +35 -0
  131. package/dist/components/chat/Popup.mjs.map +1 -0
  132. package/dist/components/chat/Response.d.ts +7 -0
  133. package/dist/components/chat/Response.js +64 -0
  134. package/dist/components/chat/Response.js.map +1 -0
  135. package/dist/components/chat/Response.mjs +10 -0
  136. package/dist/components/chat/Response.mjs.map +1 -0
  137. package/dist/components/chat/Sidebar.d.ts +13 -0
  138. package/dist/components/chat/Sidebar.js +2646 -0
  139. package/dist/components/chat/Sidebar.js.map +1 -0
  140. package/dist/components/chat/Sidebar.mjs +35 -0
  141. package/dist/components/chat/Sidebar.mjs.map +1 -0
  142. package/dist/components/chat/Suggestion.d.ts +14 -0
  143. package/dist/components/chat/Suggestion.js +181 -0
  144. package/dist/components/chat/Suggestion.js.map +1 -0
  145. package/dist/components/chat/Suggestion.mjs +11 -0
  146. package/dist/components/chat/Suggestion.mjs.map +1 -0
  147. package/dist/components/chat/Textarea.d.ts +13 -0
  148. package/dist/components/chat/Textarea.js +73 -0
  149. package/dist/components/chat/Textarea.js.map +1 -0
  150. package/dist/components/chat/Textarea.mjs +8 -0
  151. package/dist/components/chat/Textarea.mjs.map +1 -0
  152. package/dist/components/chat/Window.d.ts +7 -0
  153. package/dist/components/chat/Window.js +164 -0
  154. package/dist/components/chat/Window.js.map +1 -0
  155. package/dist/components/chat/Window.mjs +10 -0
  156. package/dist/components/chat/Window.mjs.map +1 -0
  157. package/dist/components/chat/index.d.ts +11 -0
  158. package/dist/components/chat/index.js +2661 -0
  159. package/dist/components/chat/index.js.map +1 -0
  160. package/dist/components/chat/index.mjs +47 -0
  161. package/dist/components/chat/index.mjs.map +1 -0
  162. package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +7 -0
  163. package/dist/components/chat/messages/RenderActionExecutionMessage.js +131 -0
  164. package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -0
  165. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +10 -0
  166. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs.map +1 -0
  167. package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +7 -0
  168. package/dist/components/chat/messages/RenderAgentStateMessage.js +111 -0
  169. package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -0
  170. package/dist/components/chat/messages/RenderAgentStateMessage.mjs +10 -0
  171. package/dist/components/chat/messages/RenderAgentStateMessage.mjs.map +1 -0
  172. package/dist/components/chat/messages/RenderResultMessage.d.ts +7 -0
  173. package/dist/components/chat/messages/RenderResultMessage.js +64 -0
  174. package/dist/components/chat/messages/RenderResultMessage.js.map +1 -0
  175. package/dist/components/chat/messages/RenderResultMessage.mjs +10 -0
  176. package/dist/components/chat/messages/RenderResultMessage.mjs.map +1 -0
  177. package/dist/components/chat/messages/RenderTextMessage.d.ts +7 -0
  178. package/dist/components/chat/messages/RenderTextMessage.js +629 -0
  179. package/dist/components/chat/messages/RenderTextMessage.js.map +1 -0
  180. package/dist/components/chat/messages/RenderTextMessage.mjs +13 -0
  181. package/dist/components/chat/messages/RenderTextMessage.mjs.map +1 -0
  182. package/dist/components/chat/props.d.ts +46 -0
  183. package/dist/components/chat/props.js +19 -0
  184. package/dist/components/chat/props.js.map +1 -0
  185. package/dist/components/chat/props.mjs +2 -0
  186. package/dist/components/chat/props.mjs.map +1 -0
  187. package/dist/components/dev-console/console.d.ts +10 -0
  188. package/dist/components/dev-console/console.js +720 -0
  189. package/dist/components/dev-console/console.js.map +1 -0
  190. package/dist/components/dev-console/console.mjs +17 -0
  191. package/dist/components/dev-console/console.mjs.map +1 -0
  192. package/dist/components/dev-console/icons.d.ts +9 -0
  193. package/dist/components/dev-console/icons.js +120 -0
  194. package/dist/components/dev-console/icons.js.map +1 -0
  195. package/dist/components/dev-console/icons.mjs +16 -0
  196. package/dist/components/dev-console/icons.mjs.map +1 -0
  197. package/dist/components/dev-console/index.d.ts +5 -0
  198. package/dist/components/dev-console/index.js +720 -0
  199. package/dist/components/dev-console/index.js.map +1 -0
  200. package/dist/components/dev-console/index.mjs +18 -0
  201. package/dist/components/dev-console/index.mjs.map +1 -0
  202. package/dist/components/dev-console/types.d.ts +9 -0
  203. package/dist/components/dev-console/types.js +19 -0
  204. package/dist/components/dev-console/types.js.map +1 -0
  205. package/dist/components/dev-console/types.mjs +1 -0
  206. package/dist/components/dev-console/types.mjs.map +1 -0
  207. package/dist/components/dev-console/utils.d.ts +10 -0
  208. package/dist/components/dev-console/utils.js +188 -0
  209. package/dist/components/dev-console/utils.js.map +1 -0
  210. package/dist/components/dev-console/utils.mjs +16 -0
  211. package/dist/components/dev-console/utils.mjs.map +1 -0
  212. package/dist/components/help-modal/icons.d.ts +9 -0
  213. package/dist/components/help-modal/icons.js +107 -0
  214. package/dist/components/help-modal/icons.js.map +1 -0
  215. package/dist/components/help-modal/icons.mjs +12 -0
  216. package/dist/components/help-modal/icons.mjs.map +1 -0
  217. package/dist/components/help-modal/index.d.ts +2 -0
  218. package/dist/components/help-modal/index.js +255 -0
  219. package/dist/components/help-modal/index.js.map +1 -0
  220. package/dist/components/help-modal/index.mjs +10 -0
  221. package/dist/components/help-modal/index.mjs.map +1 -0
  222. package/dist/components/help-modal/modal.d.ts +5 -0
  223. package/dist/components/help-modal/modal.js +253 -0
  224. package/dist/components/help-modal/modal.js.map +1 -0
  225. package/dist/components/help-modal/modal.mjs +9 -0
  226. package/dist/components/help-modal/modal.mjs.map +1 -0
  227. package/dist/components/index.d.ts +14 -0
  228. package/dist/components/index.js +2665 -0
  229. package/dist/components/index.js.map +1 -0
  230. package/dist/components/index.mjs +54 -0
  231. package/dist/components/index.mjs.map +1 -0
  232. package/dist/context/index.d.ts +2 -0
  233. package/dist/context/index.js +19 -0
  234. package/dist/context/index.js.map +1 -0
  235. package/dist/context/index.mjs +2 -0
  236. package/dist/context/index.mjs.map +1 -0
  237. package/dist/hooks/index.d.ts +1 -0
  238. package/dist/hooks/index.js +55 -0
  239. package/dist/hooks/index.js.map +1 -0
  240. package/dist/hooks/index.mjs +9 -0
  241. package/dist/hooks/index.mjs.map +1 -0
  242. package/dist/hooks/use-copilot-chat-suggestions.d.ts +83 -0
  243. package/dist/hooks/use-copilot-chat-suggestions.js +53 -0
  244. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  245. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  246. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
  247. package/dist/hooks/use-copy-to-clipboard.d.ts +9 -0
  248. package/dist/hooks/use-copy-to-clipboard.js +60 -0
  249. package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
  250. package/dist/hooks/use-copy-to-clipboard.mjs +8 -0
  251. package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -0
  252. package/dist/hooks/use-push-to-talk.d.ts +19 -0
  253. package/dist/hooks/use-push-to-talk.js +195 -0
  254. package/dist/hooks/use-push-to-talk.js.map +1 -0
  255. package/dist/hooks/use-push-to-talk.mjs +12 -0
  256. package/dist/hooks/use-push-to-talk.mjs.map +1 -0
  257. package/dist/index.css +751 -0
  258. package/dist/index.css.map +1 -0
  259. package/dist/index.d.ts +16 -0
  260. package/dist/index.js +2693 -0
  261. package/dist/index.js.map +1 -0
  262. package/dist/index.mjs +62 -0
  263. package/dist/index.mjs.map +1 -0
  264. package/dist/lib/utils.d.ts +4 -0
  265. package/dist/lib/utils.js +76 -0
  266. package/dist/lib/utils.js.map +1 -0
  267. package/dist/lib/utils.mjs +34 -0
  268. package/dist/lib/utils.mjs.map +1 -0
  269. package/dist/lib/utils.test.d.ts +2 -0
  270. package/dist/lib/utils.test.js +9 -0
  271. package/dist/lib/utils.test.js.map +1 -0
  272. package/dist/lib/utils.test.mjs +7 -0
  273. package/dist/lib/utils.test.mjs.map +1 -0
  274. package/dist/types/css.d.ts +16 -0
  275. package/dist/types/css.js +19 -0
  276. package/dist/types/css.js.map +1 -0
  277. package/dist/types/css.mjs +1 -0
  278. package/dist/types/css.mjs.map +1 -0
  279. package/dist/types/index.d.ts +2 -0
  280. package/dist/types/index.js +19 -0
  281. package/dist/types/index.js.map +1 -0
  282. package/dist/types/index.mjs +2 -0
  283. package/dist/types/index.mjs.map +1 -0
  284. package/dist/types/suggestions.d.ts +8 -0
  285. package/dist/types/suggestions.js +19 -0
  286. package/dist/types/suggestions.js.map +1 -0
  287. package/dist/types/suggestions.mjs +1 -0
  288. package/dist/types/suggestions.mjs.map +1 -0
  289. package/jest.config.js +5 -0
  290. package/package.json +78 -0
  291. package/postcss.config.js +60 -0
  292. package/src/components/chat/Button.tsx +18 -0
  293. package/src/components/chat/Chat.tsx +517 -0
  294. package/src/components/chat/ChatContext.tsx +188 -0
  295. package/src/components/chat/CodeBlock.tsx +408 -0
  296. package/src/components/chat/Header.tsx +15 -0
  297. package/src/components/chat/Icons.tsx +223 -0
  298. package/src/components/chat/Input.tsx +100 -0
  299. package/src/components/chat/Markdown.tsx +80 -0
  300. package/src/components/chat/Messages.tsx +178 -0
  301. package/src/components/chat/Modal.tsx +117 -0
  302. package/src/components/chat/Popup.tsx +57 -0
  303. package/src/components/chat/Response.tsx +12 -0
  304. package/src/components/chat/Sidebar.tsx +74 -0
  305. package/src/components/chat/Suggestion.tsx +125 -0
  306. package/src/components/chat/Textarea.tsx +61 -0
  307. package/src/components/chat/Window.tsx +153 -0
  308. package/src/components/chat/index.tsx +5 -0
  309. package/src/components/chat/messages/RenderActionExecutionMessage.tsx +101 -0
  310. package/src/components/chat/messages/RenderAgentStateMessage.tsx +92 -0
  311. package/src/components/chat/messages/RenderResultMessage.tsx +15 -0
  312. package/src/components/chat/messages/RenderTextMessage.tsx +36 -0
  313. package/src/components/chat/props.ts +49 -0
  314. package/src/components/dev-console/console.tsx +281 -0
  315. package/src/components/dev-console/icons.tsx +92 -0
  316. package/src/components/dev-console/index.tsx +2 -0
  317. package/src/components/dev-console/types.ts +7 -0
  318. package/src/components/dev-console/utils.ts +162 -0
  319. package/src/components/help-modal/icons.tsx +68 -0
  320. package/src/components/help-modal/index.tsx +1 -0
  321. package/src/components/help-modal/modal.tsx +164 -0
  322. package/src/components/index.ts +2 -0
  323. package/src/context/index.ts +1 -0
  324. package/src/css/animations.css +35 -0
  325. package/src/css/button.css +56 -0
  326. package/src/css/colors.css +12 -0
  327. package/src/css/console.css +134 -0
  328. package/src/css/header.css +43 -0
  329. package/src/css/input.css +89 -0
  330. package/src/css/markdown.css +136 -0
  331. package/src/css/messages.css +73 -0
  332. package/src/css/panel.css +38 -0
  333. package/src/css/popup.css +22 -0
  334. package/src/css/response.css +26 -0
  335. package/src/css/sidebar.css +34 -0
  336. package/src/css/suggestions.css +35 -0
  337. package/src/css/window.css +60 -0
  338. package/src/hooks/index.ts +1 -0
  339. package/src/hooks/use-copilot-chat-suggestions.tsx +112 -0
  340. package/src/hooks/use-copy-to-clipboard.tsx +29 -0
  341. package/src/hooks/use-push-to-talk.tsx +166 -0
  342. package/src/index.tsx +7 -0
  343. package/src/lib/utils.test.ts +7 -0
  344. package/src/lib/utils.ts +27 -0
  345. package/src/styles.css +14 -0
  346. package/src/types/css.ts +15 -0
  347. package/src/types/index.ts +1 -0
  348. package/src/types/suggestions.ts +6 -0
  349. package/tailwind.config.js +7 -0
  350. package/tsconfig.json +12 -0
  351. package/tsup.config.ts +16 -0
  352. package/typedoc.json +4 -0
@@ -0,0 +1,517 @@
1
+ /**
2
+ * <br/>
3
+ * <img src="/images/CopilotChat.gif" width="500" />
4
+ *
5
+ * A chatbot panel component for the CopilotKit framework. The component allows for a high degree
6
+ * of customization through various props and custom CSS.
7
+ *
8
+ * ## Install Dependencies
9
+ *
10
+ * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
11
+ *
12
+ * ```shell npm2yarn \"@copilotkit/react-ui"\
13
+ * npm install @copilotkit/react-core @copilotkit/react-ui
14
+ * ```
15
+ *
16
+ * ## Usage
17
+ *
18
+ * ```tsx
19
+ * import { CopilotChat } from "@copilotkit/react-ui";
20
+ * import "@copilotkit/react-ui/styles.css";
21
+ *
22
+ * <CopilotChat
23
+ * labels={{
24
+ * title: "Your Assistant",
25
+ * initial: "Hi! 👋 How can I assist you today?",
26
+ * }}
27
+ * />
28
+ * ```
29
+ *
30
+ * ### Look & Feel
31
+ *
32
+ * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
33
+ * ```tsx title="YourRootComponent.tsx"
34
+ * ...
35
+ * import "@copilotkit/react-ui/styles.css"; // [!code highlight]
36
+ *
37
+ * export function YourRootComponent() {
38
+ * return (
39
+ * <CopilotKit>
40
+ * ...
41
+ * </CopilotKit>
42
+ * );
43
+ * }
44
+ * ```
45
+ * For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
46
+ */
47
+
48
+ import {
49
+ ChatContext,
50
+ ChatContextProvider,
51
+ CopilotChatIcons,
52
+ CopilotChatLabels,
53
+ } from "./ChatContext";
54
+ import { Messages as DefaultMessages } from "./Messages";
55
+ import { Input as DefaultInput } from "./Input";
56
+ import { ResponseButton as DefaultResponseButton } from "./Response";
57
+ import { RenderTextMessage as DefaultRenderTextMessage } from "./messages/RenderTextMessage";
58
+ import { RenderActionExecutionMessage as DefaultRenderActionExecutionMessage } from "./messages/RenderActionExecutionMessage";
59
+ import { RenderResultMessage as DefaultRenderResultMessage } from "./messages/RenderResultMessage";
60
+ import { RenderAgentStateMessage as DefaultRenderAgentStateMessage } from "./messages/RenderAgentStateMessage";
61
+ import { Suggestion } from "./Suggestion";
62
+ import React, { useEffect, useRef, useState } from "react";
63
+ import {
64
+ SystemMessageFunction,
65
+ useCopilotChat,
66
+ useCopilotContext,
67
+ useCopilotMessagesContext,
68
+ } from "@copilotkit/react-core";
69
+ import { reloadSuggestions } from "./Suggestion";
70
+ import { CopilotChatSuggestion } from "../../types/suggestions";
71
+ import { Message, Role, TextMessage } from "@copilotkit/runtime-client-gql";
72
+ import { InputProps, MessagesProps, RenderMessageProps, ResponseButtonProps } from "./props";
73
+ import { randomId } from "@copilotkit/shared";
74
+
75
+ import { CopilotDevConsole } from "../dev-console";
76
+ import { HintFunction, runAgent, stopAgent } from "@copilotkit/react-core";
77
+
78
+ /**
79
+ * Props for CopilotChat component.
80
+ */
81
+ export interface CopilotChatProps {
82
+ /**
83
+ * Custom instructions to be added to the system message. Use this property to
84
+ * provide additional context or guidance to the language model, influencing
85
+ * its responses. These instructions can include specific directions,
86
+ * preferences, or criteria that the model should consider when generating
87
+ * its output, thereby tailoring the conversation more precisely to the
88
+ * user's needs or the application's requirements.
89
+ */
90
+ instructions?: string;
91
+
92
+ /**
93
+ * A callback that gets called when the in progress state changes.
94
+ */
95
+ onInProgress?: (inProgress: boolean) => void;
96
+
97
+ /**
98
+ * A callback that gets called when a new message it submitted.
99
+ */
100
+ onSubmitMessage?: (message: string) => void | Promise<void>;
101
+
102
+ /**
103
+ * A custom stop generation function.
104
+ */
105
+ onStopGeneration?: OnStopGeneration;
106
+
107
+ /**
108
+ * A custom reload messages function.
109
+ */
110
+ onReloadMessages?: OnReloadMessages;
111
+
112
+ /**
113
+ * Icons can be used to set custom icons for the chat window.
114
+ */
115
+ icons?: CopilotChatIcons;
116
+
117
+ /**
118
+ * Labels can be used to set custom labels for the chat window.
119
+ */
120
+ labels?: CopilotChatLabels;
121
+
122
+ /**
123
+ * A function that takes in context string and instructions and returns
124
+ * the system message to include in the chat request.
125
+ * Use this to completely override the system message, when providing
126
+ * instructions is not enough.
127
+ */
128
+ makeSystemMessage?: SystemMessageFunction;
129
+
130
+ /**
131
+ * Whether to show the response button.
132
+ * @default true
133
+ */
134
+ showResponseButton?: boolean;
135
+
136
+ /**
137
+ * A custom Messages component to use instead of the default.
138
+ */
139
+ Messages?: React.ComponentType<MessagesProps>;
140
+
141
+ /**
142
+ * A custom RenderTextMessage component to use instead of the default.
143
+ */
144
+ RenderTextMessage?: React.ComponentType<RenderMessageProps>;
145
+
146
+ /**
147
+ * A custom RenderActionExecutionMessage component to use instead of the default.
148
+ */
149
+ RenderActionExecutionMessage?: React.ComponentType<RenderMessageProps>;
150
+
151
+ /**
152
+ * A custom RenderAgentStateMessage component to use instead of the default.
153
+ */
154
+ RenderAgentStateMessage?: React.ComponentType<RenderMessageProps>;
155
+
156
+ /**
157
+ * A custom RenderResultMessage component to use instead of the default.
158
+ */
159
+ RenderResultMessage?: React.ComponentType<RenderMessageProps>;
160
+
161
+ /**
162
+ * A custom Input component to use instead of the default.
163
+ */
164
+ Input?: React.ComponentType<InputProps>;
165
+
166
+ /**
167
+ * A custom ResponseButton component to use instead of the default.
168
+ */
169
+ ResponseButton?: React.ComponentType<ResponseButtonProps>;
170
+
171
+ /**
172
+ * A class name to apply to the root element.
173
+ */
174
+ className?: string;
175
+
176
+ /**
177
+ * Children to render.
178
+ */
179
+ children?: React.ReactNode;
180
+ }
181
+
182
+ interface OnStopGenerationArguments {
183
+ /**
184
+ * The name of the currently executing agent.
185
+ */
186
+ currentAgentName: string | undefined;
187
+
188
+ /**
189
+ * The messages in the chat.
190
+ */
191
+ messages: Message[];
192
+
193
+ /**
194
+ * Set the messages in the chat.
195
+ */
196
+ setMessages: (messages: Message[]) => void;
197
+
198
+ /**
199
+ * Stop chat generation.
200
+ */
201
+ stopGeneration: () => void;
202
+
203
+ /**
204
+ * Restart the currently executing agent.
205
+ */
206
+ restartCurrentAgent: () => void;
207
+
208
+ /**
209
+ * Stop the currently executing agent.
210
+ */
211
+ stopCurrentAgent: () => void;
212
+
213
+ /**
214
+ * Run the currently executing agent.
215
+ */
216
+ runCurrentAgent: (hint?: HintFunction) => Promise<void>;
217
+
218
+ /**
219
+ * Set the state of the currently executing agent.
220
+ */
221
+ setCurrentAgentState: (state: any) => void;
222
+ }
223
+
224
+ export type OnReloadMessagesArguments = OnStopGenerationArguments;
225
+
226
+ export type OnStopGeneration = (args: OnStopGenerationArguments) => void;
227
+
228
+ export type OnReloadMessages = (args: OnReloadMessagesArguments) => void;
229
+
230
+ export function CopilotChat({
231
+ instructions,
232
+ onSubmitMessage,
233
+ makeSystemMessage,
234
+ showResponseButton = true,
235
+ onInProgress,
236
+ onStopGeneration,
237
+ onReloadMessages,
238
+ Messages = DefaultMessages,
239
+ RenderTextMessage = DefaultRenderTextMessage,
240
+ RenderActionExecutionMessage = DefaultRenderActionExecutionMessage,
241
+ RenderAgentStateMessage = DefaultRenderAgentStateMessage,
242
+ RenderResultMessage = DefaultRenderResultMessage,
243
+ Input = DefaultInput,
244
+ ResponseButton = DefaultResponseButton,
245
+ className,
246
+ icons,
247
+ labels,
248
+ }: CopilotChatProps) {
249
+ const context = useCopilotContext();
250
+
251
+ useEffect(() => {
252
+ context.setChatInstructions(instructions || "");
253
+ }, [instructions]);
254
+
255
+ const {
256
+ visibleMessages,
257
+ isLoading,
258
+ currentSuggestions,
259
+ sendMessage,
260
+ stopGeneration,
261
+ reloadMessages,
262
+ } = useCopilotChatLogic(
263
+ makeSystemMessage,
264
+ onInProgress,
265
+ onSubmitMessage,
266
+ onStopGeneration,
267
+ onReloadMessages,
268
+ );
269
+
270
+ const chatContext = React.useContext(ChatContext);
271
+ const isVisible = chatContext ? chatContext.open : true;
272
+
273
+ return (
274
+ <WrappedCopilotChat icons={icons} labels={labels} className={className}>
275
+ <CopilotDevConsole />
276
+ <Messages
277
+ RenderTextMessage={RenderTextMessage}
278
+ RenderActionExecutionMessage={RenderActionExecutionMessage}
279
+ RenderAgentStateMessage={RenderAgentStateMessage}
280
+ RenderResultMessage={RenderResultMessage}
281
+ messages={visibleMessages}
282
+ inProgress={isLoading}
283
+ >
284
+ {currentSuggestions.length > 0 && (
285
+ <div>
286
+ <h6>Suggested:</h6>
287
+ <div className="suggestions">
288
+ {currentSuggestions.map((suggestion, index) => (
289
+ <Suggestion
290
+ key={index}
291
+ title={suggestion.title}
292
+ message={suggestion.message}
293
+ partial={suggestion.partial}
294
+ className={suggestion.className}
295
+ onClick={(message) => sendMessage(message)}
296
+ />
297
+ ))}
298
+ </div>
299
+ </div>
300
+ )}
301
+ {showResponseButton && visibleMessages.length > 0 && (
302
+ <ResponseButton
303
+ onClick={isLoading ? stopGeneration : reloadMessages}
304
+ inProgress={isLoading}
305
+ />
306
+ )}
307
+ </Messages>
308
+ <Input inProgress={isLoading} onSend={sendMessage} isVisible={isVisible} />
309
+ </WrappedCopilotChat>
310
+ );
311
+ }
312
+
313
+ export function WrappedCopilotChat({
314
+ children,
315
+ icons,
316
+ labels,
317
+ className,
318
+ }: {
319
+ children: React.ReactNode;
320
+ icons?: CopilotChatIcons;
321
+ labels?: CopilotChatLabels;
322
+ className?: string;
323
+ }) {
324
+ const chatContext = React.useContext(ChatContext);
325
+ if (!chatContext) {
326
+ return (
327
+ <ChatContextProvider icons={icons} labels={labels} open={true} setOpen={() => {}}>
328
+ <div className={`copilotKitChat ${className}`}>{children}</div>
329
+ </ChatContextProvider>
330
+ );
331
+ }
332
+ return <>{children}</>;
333
+ }
334
+
335
+ const SUGGESTIONS_DEBOUNCE_TIMEOUT = 1000;
336
+
337
+ export const useCopilotChatLogic = (
338
+ makeSystemMessage?: SystemMessageFunction,
339
+ onInProgress?: (isLoading: boolean) => void,
340
+ onSubmitMessage?: (messageContent: string) => Promise<void> | void,
341
+ onStopGeneration?: OnStopGeneration,
342
+ onReloadMessages?: OnReloadMessages,
343
+ ) => {
344
+ const {
345
+ visibleMessages,
346
+ appendMessage,
347
+ reloadMessages: defaultReloadMessages,
348
+ stopGeneration: defaultStopGeneration,
349
+ runChatCompletion,
350
+ isLoading,
351
+ } = useCopilotChat({
352
+ id: randomId(),
353
+ makeSystemMessage,
354
+ });
355
+
356
+ const [currentSuggestions, setCurrentSuggestions] = useState<CopilotChatSuggestion[]>([]);
357
+ const suggestionsAbortControllerRef = useRef<AbortController | null>(null);
358
+ const debounceTimerRef = useRef<any>();
359
+
360
+ const abortSuggestions = () => {
361
+ suggestionsAbortControllerRef.current?.abort();
362
+ suggestionsAbortControllerRef.current = null;
363
+ };
364
+
365
+ const generalContext = useCopilotContext();
366
+ const messagesContext = useCopilotMessagesContext();
367
+ const context = { ...generalContext, ...messagesContext };
368
+
369
+ useEffect(() => {
370
+ onInProgress?.(isLoading);
371
+
372
+ abortSuggestions();
373
+
374
+ debounceTimerRef.current = setTimeout(
375
+ () => {
376
+ if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
377
+ suggestionsAbortControllerRef.current = new AbortController();
378
+ reloadSuggestions(
379
+ context,
380
+ context.chatSuggestionConfiguration,
381
+ setCurrentSuggestions,
382
+ suggestionsAbortControllerRef,
383
+ );
384
+ }
385
+ },
386
+ currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT,
387
+ );
388
+
389
+ return () => {
390
+ clearTimeout(debounceTimerRef.current);
391
+ };
392
+ }, [
393
+ isLoading,
394
+ context.chatSuggestionConfiguration,
395
+ // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
396
+ // global context
397
+ visibleMessages.length == 0,
398
+ ]);
399
+
400
+ const sendMessage = async (messageContent: string) => {
401
+ abortSuggestions();
402
+ setCurrentSuggestions([]);
403
+
404
+ const message: Message = new TextMessage({
405
+ content: messageContent,
406
+ role: Role.User,
407
+ });
408
+
409
+ if (onSubmitMessage) {
410
+ try {
411
+ await onSubmitMessage(messageContent);
412
+ } catch (error) {
413
+ console.error("Error in onSubmitMessage:", error);
414
+ }
415
+ }
416
+ // this needs to happen after onSubmitMessage, because it will trigger submission
417
+ // of the message to the endpoint. Some users depend on performing some actions
418
+ // before the message is submitted.
419
+ appendMessage(message);
420
+
421
+ return message;
422
+ };
423
+
424
+ const messages = visibleMessages;
425
+ const { setMessages } = messagesContext;
426
+ const currentAgentName = generalContext.agentSession?.agentName;
427
+ const restartCurrentAgent = async (hint?: HintFunction) => {
428
+ if (generalContext.agentSession) {
429
+ generalContext.setAgentSession({
430
+ ...generalContext.agentSession,
431
+ nodeName: undefined,
432
+ threadId: undefined,
433
+ });
434
+ generalContext.setCoagentStates((prevAgentStates) => {
435
+ return {
436
+ ...prevAgentStates,
437
+ [generalContext.agentSession!.agentName]: {
438
+ ...prevAgentStates[generalContext.agentSession!.agentName],
439
+ threadId: undefined,
440
+ nodeName: undefined,
441
+ runId: undefined,
442
+ },
443
+ };
444
+ });
445
+ }
446
+ };
447
+ const runCurrentAgent = async (hint?: HintFunction) => {
448
+ if (generalContext.agentSession) {
449
+ await runAgent(
450
+ generalContext.agentSession.agentName,
451
+ context,
452
+ appendMessage,
453
+ runChatCompletion,
454
+ hint,
455
+ );
456
+ }
457
+ };
458
+ const stopCurrentAgent = () => {
459
+ if (generalContext.agentSession) {
460
+ stopAgent(generalContext.agentSession.agentName, context);
461
+ }
462
+ };
463
+ const setCurrentAgentState = (state: any) => {
464
+ if (generalContext.agentSession) {
465
+ generalContext.setCoagentStates((prevAgentStates) => {
466
+ return {
467
+ ...prevAgentStates,
468
+ [generalContext.agentSession!.agentName]: {
469
+ state,
470
+ },
471
+ } as any;
472
+ });
473
+ }
474
+ };
475
+
476
+ function stopGeneration() {
477
+ if (onStopGeneration) {
478
+ onStopGeneration({
479
+ messages,
480
+ setMessages,
481
+ stopGeneration: defaultStopGeneration,
482
+ currentAgentName,
483
+ restartCurrentAgent,
484
+ stopCurrentAgent,
485
+ runCurrentAgent,
486
+ setCurrentAgentState,
487
+ });
488
+ } else {
489
+ defaultStopGeneration();
490
+ }
491
+ }
492
+ function reloadMessages() {
493
+ if (onReloadMessages) {
494
+ onReloadMessages({
495
+ messages,
496
+ setMessages,
497
+ stopGeneration: defaultStopGeneration,
498
+ currentAgentName,
499
+ restartCurrentAgent,
500
+ stopCurrentAgent,
501
+ runCurrentAgent,
502
+ setCurrentAgentState,
503
+ });
504
+ } else {
505
+ defaultReloadMessages();
506
+ }
507
+ }
508
+
509
+ return {
510
+ visibleMessages,
511
+ isLoading,
512
+ currentSuggestions,
513
+ sendMessage,
514
+ stopGeneration,
515
+ reloadMessages,
516
+ };
517
+ };
@@ -0,0 +1,188 @@
1
+ import React, { useMemo, useState } from "react";
2
+ import * as DefaultIcons from "./Icons";
3
+
4
+ /**
5
+ * Icons for CopilotChat component.
6
+ */
7
+ export interface CopilotChatIcons {
8
+ /**
9
+ * The icon to use for the open chat button.
10
+ * @default <OpenIcon />
11
+ */
12
+ openIcon?: React.ReactNode;
13
+
14
+ /**
15
+ * The icon to use for the close chat button.
16
+ * @default <CloseIcon />
17
+ */
18
+ closeIcon?: React.ReactNode;
19
+
20
+ /**
21
+ * The icon to use for the close chat button in the header.
22
+ * @default <HeaderCloseIcon />
23
+ */
24
+ headerCloseIcon?: React.ReactNode;
25
+
26
+ /**
27
+ * The icon to use for the send button.
28
+ * @default <SendIcon />
29
+ */
30
+ sendIcon?: React.ReactNode;
31
+
32
+ /**
33
+ * The icon to use for the activity indicator.
34
+ * @default <ActivityIcon />
35
+ */
36
+ activityIcon?: React.ReactNode;
37
+
38
+ /**
39
+ * The icon to use for the spinner.
40
+ * @default <SpinnerIcon />
41
+ */
42
+ spinnerIcon?: React.ReactNode;
43
+
44
+ /**
45
+ * The icon to use for the stop button.
46
+ * @default <StopIcon />
47
+ */
48
+ stopIcon?: React.ReactNode;
49
+
50
+ /**
51
+ * The icon to use for the regenerate button.
52
+ * @default <RegenerateIcon />
53
+ */
54
+ regenerateIcon?: React.ReactNode;
55
+
56
+ /**
57
+ * The icons to use for push to talk.
58
+ * @default <PushToTalkIcon />
59
+ */
60
+
61
+ pushToTalkIcon?: React.ReactNode;
62
+ }
63
+
64
+ /**
65
+ * Labels for CopilotChat component.
66
+ */
67
+ export interface CopilotChatLabels {
68
+ /**
69
+ * The initial message(s) to display in the chat window.
70
+ */
71
+ initial?: string | string[];
72
+
73
+ /**
74
+ * The title to display in the header.
75
+ * @default "CopilotKit"
76
+ */
77
+ title?: string;
78
+
79
+ /**
80
+ * The placeholder to display in the input.
81
+ * @default "Type a message..."
82
+ */
83
+ placeholder?: string;
84
+
85
+ /**
86
+ * The message to display when an error occurs.
87
+ * @default "❌ An error occurred. Please try again."
88
+ */
89
+ error?: string;
90
+
91
+ /**
92
+ * The label to display on the stop button.
93
+ * @default "Stop generating"
94
+ */
95
+ stopGenerating?: string;
96
+
97
+ /**
98
+ * The label to display on the regenerate button.
99
+ * @default "Regenerate response"
100
+ */
101
+ regenerateResponse?: string;
102
+ }
103
+
104
+ interface ChatContext {
105
+ labels: Required<CopilotChatLabels>;
106
+ icons: Required<CopilotChatIcons>;
107
+ open: boolean;
108
+ setOpen: (open: boolean) => void;
109
+ }
110
+
111
+ export const ChatContext = React.createContext<ChatContext | undefined>(undefined);
112
+
113
+ export function useChatContext(): ChatContext {
114
+ const context = React.useContext(ChatContext);
115
+ if (context === undefined) {
116
+ throw new Error(
117
+ "Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?",
118
+ );
119
+ }
120
+ return context;
121
+ }
122
+
123
+ interface ChatContextProps {
124
+ // temperature?: number;
125
+ // instructions?: string;
126
+ // maxFeedback?: number;
127
+ labels?: CopilotChatLabels;
128
+ icons?: CopilotChatIcons;
129
+ children?: React.ReactNode;
130
+ open: boolean;
131
+ setOpen: (open: boolean) => void;
132
+ }
133
+
134
+ export const ChatContextProvider = ({
135
+ // temperature,
136
+ // instructions,
137
+ // maxFeedback,
138
+ labels,
139
+ icons,
140
+ children,
141
+ open,
142
+ setOpen,
143
+ }: ChatContextProps) => {
144
+ const memoizedLabels = useMemo(
145
+ () => ({
146
+ ...{
147
+ initial: "",
148
+ title: "CopilotKit",
149
+ placeholder: "Type a message...",
150
+ error: "❌ An error occurred. Please try again.",
151
+ stopGenerating: "Stop generating",
152
+ regenerateResponse: "Regenerate response",
153
+ },
154
+ ...labels,
155
+ }),
156
+ [labels],
157
+ );
158
+
159
+ const memoizedIcons = useMemo(
160
+ () => ({
161
+ ...{
162
+ openIcon: DefaultIcons.OpenIcon,
163
+ closeIcon: DefaultIcons.CloseIcon,
164
+ headerCloseIcon: DefaultIcons.HeaderCloseIcon,
165
+ sendIcon: DefaultIcons.SendIcon,
166
+ activityIcon: DefaultIcons.ActivityIcon,
167
+ spinnerIcon: DefaultIcons.SpinnerIcon,
168
+ stopIcon: DefaultIcons.StopIcon,
169
+ regenerateIcon: DefaultIcons.RegenerateIcon,
170
+ pushToTalkIcon: DefaultIcons.PushToTalkIcon,
171
+ },
172
+ ...icons,
173
+ }),
174
+ [icons],
175
+ );
176
+
177
+ const context = useMemo(
178
+ () => ({
179
+ labels: memoizedLabels,
180
+ icons: memoizedIcons,
181
+ open,
182
+ setOpen,
183
+ }),
184
+ [memoizedLabels, memoizedIcons, open, setOpen],
185
+ );
186
+
187
+ return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;
188
+ };