@copilotkit/react-core 1.57.3 → 1.58.0

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 (282) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{copilotkit-CC8DjOiC.mjs → copilotkit-BIn7HE8f.mjs} +2 -2
  3. package/dist/{copilotkit-CC8DjOiC.mjs.map → copilotkit-BIn7HE8f.mjs.map} +1 -1
  4. package/dist/{copilotkit-CtXcs1ea.cjs → copilotkit-Drw-g6zA.cjs} +2 -2
  5. package/dist/{copilotkit-CtXcs1ea.cjs.map → copilotkit-Drw-g6zA.cjs.map} +1 -1
  6. package/dist/index.cjs +3 -77
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +2 -2
  9. package/dist/index.d.mts +2 -2
  10. package/dist/index.mjs +3 -77
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/index.umd.js +3 -77
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/v2/index.cjs +1 -1
  15. package/dist/v2/index.mjs +1 -1
  16. package/dist/v2/index.umd.js +1 -1
  17. package/dist/v2/index.umd.js.map +1 -1
  18. package/package.json +12 -13
  19. package/skills/react-core/SKILL.md +108 -0
  20. package/skills/react-core/references/agent-access.md +288 -0
  21. package/skills/react-core/references/attachments.md +291 -0
  22. package/skills/react-core/references/capabilities.md +138 -0
  23. package/skills/react-core/references/chat-components.md +221 -0
  24. package/skills/react-core/references/client-side-tools.md +358 -0
  25. package/skills/react-core/references/custom-message-renderers.md +226 -0
  26. package/skills/react-core/references/debug-mode.md +153 -0
  27. package/skills/react-core/references/human-in-the-loop.md +312 -0
  28. package/skills/react-core/references/provider-setup.md +326 -0
  29. package/skills/react-core/references/rendering-activity-messages.md +207 -0
  30. package/skills/react-core/references/rendering-tool-calls.md +319 -0
  31. package/skills/react-core/references/suggestions.md +211 -0
  32. package/skills/react-core/references/switching-agents-recipes.md +160 -0
  33. package/skills/react-core/references/switching-agents.md +231 -0
  34. package/skills/react-core/references/threads.md +226 -0
  35. package/.attw.json +0 -3
  36. package/CHANGELOG.md +0 -5043
  37. package/scripts/scope-preflight.mjs +0 -100
  38. package/src/components/CopilotListeners.tsx +0 -137
  39. package/src/components/__tests__/CopilotListeners.test.tsx +0 -38
  40. package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +0 -92
  41. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -77
  42. package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +0 -70
  43. package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +0 -107
  44. package/src/components/copilot-provider/copilot-messages.tsx +0 -314
  45. package/src/components/copilot-provider/copilotkit-props.tsx +0 -214
  46. package/src/components/copilot-provider/copilotkit.tsx +0 -853
  47. package/src/components/copilot-provider/index.ts +0 -3
  48. package/src/components/dev-console/console-trigger.tsx +0 -283
  49. package/src/components/dev-console/developer-console-modal.tsx +0 -1016
  50. package/src/components/dev-console/icons.tsx +0 -106
  51. package/src/components/error-boundary/error-boundary.tsx +0 -99
  52. package/src/components/error-boundary/error-utils.tsx +0 -105
  53. package/src/components/index.ts +0 -1
  54. package/src/components/toast/exclamation-mark-icon.tsx +0 -27
  55. package/src/components/toast/toast-provider.tsx +0 -448
  56. package/src/components/usage-banner.tsx +0 -266
  57. package/src/context/__tests__/threads-context.test.tsx +0 -141
  58. package/src/context/coagent-state-renders-context.tsx +0 -89
  59. package/src/context/copilot-context.tsx +0 -365
  60. package/src/context/copilot-messages-context.tsx +0 -35
  61. package/src/context/index.ts +0 -22
  62. package/src/context/threads-context.tsx +0 -69
  63. package/src/hooks/__tests__/use-coagent-config.test.ts +0 -352
  64. package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +0 -107
  65. package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +0 -1209
  66. package/src/hooks/__tests__/use-coagent-state-render.test.tsx +0 -356
  67. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +0 -241
  68. package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -72
  69. package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +0 -102
  70. package/src/hooks/index.ts +0 -33
  71. package/src/hooks/use-agent-nodename.ts +0 -33
  72. package/src/hooks/use-coagent-state-render-bridge.helpers.ts +0 -345
  73. package/src/hooks/use-coagent-state-render-bridge.tsx +0 -222
  74. package/src/hooks/use-coagent-state-render-registry.ts +0 -230
  75. package/src/hooks/use-coagent-state-render.ts +0 -163
  76. package/src/hooks/use-coagent.ts +0 -377
  77. package/src/hooks/use-configure-chat-suggestions.tsx +0 -96
  78. package/src/hooks/use-copilot-action.ts +0 -245
  79. package/src/hooks/use-copilot-additional-instructions.ts +0 -98
  80. package/src/hooks/use-copilot-authenticated-action.ts +0 -73
  81. package/src/hooks/use-copilot-chat-headless_c.ts +0 -264
  82. package/src/hooks/use-copilot-chat-suggestions.tsx +0 -134
  83. package/src/hooks/use-copilot-chat.ts +0 -132
  84. package/src/hooks/use-copilot-chat_internal.ts +0 -875
  85. package/src/hooks/use-copilot-readable.ts +0 -135
  86. package/src/hooks/use-copilot-runtime-client.ts +0 -178
  87. package/src/hooks/use-default-tool.ts +0 -13
  88. package/src/hooks/use-flat-category-store.ts +0 -109
  89. package/src/hooks/use-frontend-tool.ts +0 -113
  90. package/src/hooks/use-human-in-the-loop.ts +0 -138
  91. package/src/hooks/use-langgraph-interrupt.ts +0 -103
  92. package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
  93. package/src/hooks/use-make-copilot-document-readable.ts +0 -30
  94. package/src/hooks/use-render-tool-call.ts +0 -89
  95. package/src/hooks/use-tree.ts +0 -222
  96. package/src/index.tsx +0 -7
  97. package/src/lib/copilot-task.ts +0 -215
  98. package/src/lib/index.ts +0 -1
  99. package/src/lib/status-checker.ts +0 -67
  100. package/src/setupTests.ts +0 -37
  101. package/src/test-helpers/copilot-context.ts +0 -91
  102. package/src/types/chat-suggestion-configuration.ts +0 -23
  103. package/src/types/coagent-action.ts +0 -35
  104. package/src/types/coagent-state.ts +0 -13
  105. package/src/types/crew.ts +0 -89
  106. package/src/types/document-pointer.ts +0 -7
  107. package/src/types/frontend-action.ts +0 -213
  108. package/src/types/index.ts +0 -17
  109. package/src/types/interrupt-action.ts +0 -58
  110. package/src/types/system-message.ts +0 -4
  111. package/src/utils/dev-console.ts +0 -19
  112. package/src/utils/index.ts +0 -2
  113. package/src/utils/suggestions-constants.ts +0 -8
  114. package/src/utils/utils.test.ts +0 -7
  115. package/src/utils/utils.ts +0 -6
  116. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +0 -240
  117. package/src/v2/__tests__/globalSetup.ts +0 -14
  118. package/src/v2/__tests__/setup.ts +0 -93
  119. package/src/v2/__tests__/utils/test-helpers.tsx +0 -570
  120. package/src/v2/a2ui/A2UICatalogContext.tsx +0 -79
  121. package/src/v2/a2ui/A2UIMessageRenderer.tsx +0 -294
  122. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +0 -290
  123. package/src/v2/components/CopilotKitInspector.tsx +0 -52
  124. package/src/v2/components/MCPAppsActivityRenderer.tsx +0 -815
  125. package/src/v2/components/OpenGenerativeUIRenderer.tsx +0 -598
  126. package/src/v2/components/WildcardToolCallRender.tsx +0 -86
  127. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +0 -665
  128. package/src/v2/components/chat/CopilotChat.tsx +0 -664
  129. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +0 -393
  130. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +0 -374
  131. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +0 -159
  132. package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +0 -350
  133. package/src/v2/components/chat/CopilotChatInput.tsx +0 -1412
  134. package/src/v2/components/chat/CopilotChatMessageView.tsx +0 -716
  135. package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +0 -265
  136. package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +0 -59
  137. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +0 -134
  138. package/src/v2/components/chat/CopilotChatToggleButton.tsx +0 -171
  139. package/src/v2/components/chat/CopilotChatToolCallsView.tsx +0 -40
  140. package/src/v2/components/chat/CopilotChatUserMessage.tsx +0 -445
  141. package/src/v2/components/chat/CopilotChatView.tsx +0 -890
  142. package/src/v2/components/chat/CopilotModalHeader.tsx +0 -129
  143. package/src/v2/components/chat/CopilotPopup.tsx +0 -81
  144. package/src/v2/components/chat/CopilotPopupView.tsx +0 -317
  145. package/src/v2/components/chat/CopilotSidebar.tsx +0 -80
  146. package/src/v2/components/chat/CopilotSidebarView.tsx +0 -269
  147. package/src/v2/components/chat/Lightbox.tsx +0 -103
  148. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +0 -66
  149. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +0 -168
  150. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +0 -1239
  151. package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +0 -73
  152. package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +0 -432
  153. package/src/v2/components/chat/__tests__/CopilotChat.suggestionsAlways.test.tsx +0 -183
  154. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +0 -184
  155. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +0 -649
  156. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +0 -624
  157. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -702
  158. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +0 -72
  159. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +0 -241
  160. package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +0 -107
  161. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +0 -929
  162. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +0 -1567
  163. package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +0 -1004
  164. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +0 -279
  165. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +0 -336
  166. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +0 -249
  167. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +0 -530
  168. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +0 -785
  169. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +0 -2416
  170. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +0 -621
  171. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +0 -56
  172. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.tsx +0 -264
  173. package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +0 -853
  174. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +0 -94
  175. package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +0 -1050
  176. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +0 -484
  177. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +0 -612
  178. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +0 -159
  179. package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +0 -502
  180. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +0 -1068
  181. package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +0 -589
  182. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +0 -403
  183. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -137
  184. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -37
  185. package/src/v2/components/chat/__tests__/setup.ts +0 -1
  186. package/src/v2/components/chat/index.ts +0 -90
  187. package/src/v2/components/chat/last-user-message-context.ts +0 -21
  188. package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
  189. package/src/v2/components/chat/scroll-element-context.ts +0 -13
  190. package/src/v2/components/index.ts +0 -8
  191. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -286
  192. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -464
  193. package/src/v2/components/intelligence-indicator/index.ts +0 -2
  194. package/src/v2/components/license-warning-banner.tsx +0 -217
  195. package/src/v2/components/ui/button.tsx +0 -124
  196. package/src/v2/components/ui/dropdown-menu.tsx +0 -258
  197. package/src/v2/components/ui/tooltip.tsx +0 -60
  198. package/src/v2/context.ts +0 -62
  199. package/src/v2/headless.ts +0 -64
  200. package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +0 -152
  201. package/src/v2/hooks/__tests__/standard-schema.test.tsx +0 -282
  202. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +0 -140
  203. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +0 -401
  204. package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +0 -44
  205. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +0 -211
  206. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +0 -1029
  207. package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +0 -159
  208. package/src/v2/hooks/__tests__/use-attachments.test.tsx +0 -169
  209. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +0 -76
  210. package/src/v2/hooks/__tests__/use-component.test.tsx +0 -126
  211. package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +0 -696
  212. package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +0 -153
  213. package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -167
  214. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +0 -2148
  215. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +0 -1261
  216. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +0 -397
  217. package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +0 -56
  218. package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +0 -192
  219. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +0 -219
  220. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +0 -55
  221. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +0 -259
  222. package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +0 -524
  223. package/src/v2/hooks/__tests__/use-threads.test.tsx +0 -757
  224. package/src/v2/hooks/__tests__/zod-regression.test.tsx +0 -311
  225. package/src/v2/hooks/index.ts +0 -24
  226. package/src/v2/hooks/use-agent-context.tsx +0 -45
  227. package/src/v2/hooks/use-agent.tsx +0 -227
  228. package/src/v2/hooks/use-attachments.tsx +0 -269
  229. package/src/v2/hooks/use-capabilities.tsx +0 -25
  230. package/src/v2/hooks/use-component.tsx +0 -91
  231. package/src/v2/hooks/use-configure-suggestions.tsx +0 -236
  232. package/src/v2/hooks/use-default-render-tool.tsx +0 -271
  233. package/src/v2/hooks/use-frontend-tool.tsx +0 -46
  234. package/src/v2/hooks/use-human-in-the-loop.tsx +0 -81
  235. package/src/v2/hooks/use-interrupt.tsx +0 -305
  236. package/src/v2/hooks/use-keyboard-height.tsx +0 -67
  237. package/src/v2/hooks/use-pin-to-send.ts +0 -94
  238. package/src/v2/hooks/use-render-activity-message.tsx +0 -72
  239. package/src/v2/hooks/use-render-custom-messages.tsx +0 -93
  240. package/src/v2/hooks/use-render-tool-call.tsx +0 -208
  241. package/src/v2/hooks/use-render-tool.tsx +0 -184
  242. package/src/v2/hooks/use-suggestions.tsx +0 -91
  243. package/src/v2/hooks/use-threads.tsx +0 -325
  244. package/src/v2/hooks/useKatexStyles.ts +0 -27
  245. package/src/v2/index.css +0 -1
  246. package/src/v2/index.ts +0 -27
  247. package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +0 -495
  248. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -112
  249. package/src/v2/lib/__tests__/renderSlot.test.tsx +0 -588
  250. package/src/v2/lib/__tests__/slots.test.ts +0 -56
  251. package/src/v2/lib/processPartialHtml.ts +0 -45
  252. package/src/v2/lib/react-core.ts +0 -156
  253. package/src/v2/lib/slots.tsx +0 -184
  254. package/src/v2/lib/transcription-client.ts +0 -184
  255. package/src/v2/lib/utils.ts +0 -8
  256. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +0 -196
  257. package/src/v2/providers/CopilotKitProvider.tsx +0 -800
  258. package/src/v2/providers/SandboxFunctionsContext.ts +0 -10
  259. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +0 -652
  260. package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +0 -101
  261. package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +0 -69
  262. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +0 -881
  263. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +0 -198
  264. package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +0 -740
  265. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +0 -713
  266. package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -294
  267. package/src/v2/providers/index.ts +0 -21
  268. package/src/v2/styles/globals.css +0 -349
  269. package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +0 -525
  270. package/src/v2/types/defineToolCallRenderer.ts +0 -68
  271. package/src/v2/types/frontend-tool.ts +0 -8
  272. package/src/v2/types/human-in-the-loop.ts +0 -33
  273. package/src/v2/types/index.ts +0 -8
  274. package/src/v2/types/interrupt.ts +0 -15
  275. package/src/v2/types/react-activity-message-renderer.ts +0 -27
  276. package/src/v2/types/react-custom-message-renderer.ts +0 -17
  277. package/src/v2/types/react-tool-call-renderer.ts +0 -35
  278. package/src/v2/types/sandbox-function.ts +0 -11
  279. package/tsconfig.json +0 -8
  280. package/tsdown.config.ts +0 -193
  281. package/typedoc.json +0 -4
  282. package/vitest.config.mjs +0 -31
@@ -1,448 +0,0 @@
1
- import { GraphQLError } from "@copilotkit/runtime-client-gql";
2
- import React, { createContext, useContext, useState, useCallback } from "react";
3
- import { PartialBy, CopilotKitError, Severity } from "@copilotkit/shared";
4
-
5
- interface Toast {
6
- id: string;
7
- message: string | React.ReactNode;
8
- type: "info" | "success" | "warning" | "error";
9
- duration?: number;
10
- }
11
-
12
- interface ToastContextValue {
13
- toasts: Toast[];
14
- addToast: (toast: PartialBy<Toast, "id">) => void;
15
- addGraphQLErrorsToast: (errors: GraphQLError[]) => void;
16
- removeToast: (id: string) => void;
17
- enabled: boolean;
18
- // Banner management
19
- bannerError: CopilotKitError | null;
20
- setBannerError: (error: CopilotKitError | null) => void;
21
- }
22
-
23
- const ToastContext = createContext<ToastContextValue | undefined>(undefined);
24
-
25
- // Helper functions for error banner styling
26
- type ErrorSeverity = "critical" | "warning" | "info";
27
-
28
- interface ErrorColors {
29
- background: string;
30
- border: string;
31
- text: string;
32
- icon: string;
33
- }
34
-
35
- function getErrorSeverity(error: CopilotKitError): ErrorSeverity {
36
- // Use structured error severity if available
37
- if (error.severity) {
38
- switch (error.severity) {
39
- case Severity.CRITICAL:
40
- return "critical";
41
- case Severity.WARNING:
42
- return "warning";
43
- case Severity.INFO:
44
- return "info";
45
- default:
46
- return "info";
47
- }
48
- }
49
-
50
- // Fallback: Check for API key errors which should always be critical
51
- const message = error.message.toLowerCase();
52
- if (
53
- message.includes("api key") ||
54
- message.includes("401") ||
55
- message.includes("unauthorized") ||
56
- message.includes("authentication") ||
57
- message.includes("incorrect api key")
58
- ) {
59
- return "critical";
60
- }
61
-
62
- // Default to info level
63
- return "info";
64
- }
65
-
66
- function getErrorColors(severity: ErrorSeverity): ErrorColors {
67
- switch (severity) {
68
- case "critical":
69
- return {
70
- background: "#fee2e2",
71
- border: "#dc2626",
72
- text: "#7f1d1d",
73
- icon: "#dc2626",
74
- };
75
- case "warning":
76
- return {
77
- background: "#fef3c7",
78
- border: "#d97706",
79
- text: "#78350f",
80
- icon: "#d97706",
81
- };
82
- case "info":
83
- return {
84
- background: "#dbeafe",
85
- border: "#2563eb",
86
- text: "#1e3a8a",
87
- icon: "#2563eb",
88
- };
89
- }
90
- }
91
-
92
- export function useToast() {
93
- const context = useContext(ToastContext);
94
- if (!context) {
95
- throw new Error("useToast must be used within a ToastProvider");
96
- }
97
- return context;
98
- }
99
-
100
- function formatBannerMessage(message: string): string {
101
- // Try to extract the useful message from JSON first
102
- const jsonMatch = message.match(/'message':\s*'([^']+)'/);
103
- if (jsonMatch) {
104
- return jsonMatch[1];
105
- }
106
-
107
- // Strip technical garbage but keep the meaningful message
108
- let cleaned = message.split(" - ")[0];
109
- cleaned = cleaned.split(": Error code")[0];
110
- cleaned = cleaned.replace(/:\s*\d{3}$/, "");
111
- cleaned = cleaned.replace(/See more:.*$/g, "");
112
- cleaned = cleaned.trim();
113
-
114
- return cleaned || "An error occurred.";
115
- }
116
-
117
- function extractUrl(message: string): { url: string; text: string } | null {
118
- const markdownMatch = /\[([^\]]+)\]\(([^)]+)\)/.exec(message);
119
- if (markdownMatch) {
120
- return { url: markdownMatch[2], text: "See More" };
121
- }
122
- const plainMatch = /(https?:\/\/[^\s)]+)/.exec(message);
123
- if (plainMatch) {
124
- return {
125
- url: plainMatch[0].replace(/[.,;:'"]*$/, ""),
126
- text: "See More",
127
- };
128
- }
129
- return null;
130
- }
131
-
132
- function BannerErrorDisplay({
133
- bannerError,
134
- onDismiss,
135
- }: {
136
- bannerError: CopilotKitError;
137
- onDismiss: () => void;
138
- }) {
139
- const [detailsExpanded, setDetailsExpanded] = useState(false);
140
- const severity = getErrorSeverity(bannerError);
141
- const colors = getErrorColors(severity);
142
-
143
- // Extract optional error details attached by CopilotListeners
144
- const details = (bannerError as any).details as
145
- | {
146
- code?: string;
147
- context?: Record<string, any>;
148
- stack?: string;
149
- originalMessage?: string;
150
- }
151
- | undefined;
152
-
153
- const link = extractUrl(bannerError.message);
154
-
155
- return (
156
- <div
157
- style={{
158
- position: "fixed",
159
- bottom: "20px",
160
- left: "50%",
161
- transform: "translateX(-50%)",
162
- zIndex: 9999,
163
- backgroundColor: colors.background,
164
- border: `1px solid ${colors.border}`,
165
- borderLeft: `4px solid ${colors.border}`,
166
- borderRadius: "8px",
167
- padding: "12px 16px",
168
- fontSize: "13px",
169
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
170
- backdropFilter: "blur(8px)",
171
- maxWidth: "min(90vw, 700px)",
172
- width: "100%",
173
- boxSizing: "border-box",
174
- overflow: "hidden",
175
- }}
176
- >
177
- <div
178
- style={{
179
- display: "flex",
180
- justifyContent: "space-between",
181
- alignItems: "center",
182
- gap: "10px",
183
- }}
184
- >
185
- <div
186
- style={{
187
- display: "flex",
188
- alignItems: "center",
189
- gap: "8px",
190
- flex: 1,
191
- minWidth: 0,
192
- }}
193
- >
194
- <div
195
- style={{
196
- width: "12px",
197
- height: "12px",
198
- borderRadius: "50%",
199
- backgroundColor: colors.border,
200
- flexShrink: 0,
201
- }}
202
- />
203
- <div
204
- style={{
205
- display: "flex",
206
- alignItems: "center",
207
- gap: "10px",
208
- flex: 1,
209
- minWidth: 0,
210
- }}
211
- >
212
- <div
213
- style={{
214
- color: colors.text,
215
- lineHeight: "1.4",
216
- fontWeight: "400",
217
- fontSize: "13px",
218
- flex: 1,
219
- wordBreak: "break-all",
220
- overflowWrap: "break-word",
221
- maxWidth: "550px",
222
- overflow: "hidden",
223
- display: "-webkit-box",
224
- WebkitLineClamp: 10,
225
- WebkitBoxOrient: "vertical",
226
- }}
227
- >
228
- {formatBannerMessage(bannerError.message)}
229
- </div>
230
-
231
- {link && (
232
- <button
233
- onClick={() =>
234
- window.open(link.url, "_blank", "noopener,noreferrer")
235
- }
236
- style={{
237
- background: colors.border,
238
- color: "white",
239
- border: "none",
240
- borderRadius: "5px",
241
- padding: "4px 10px",
242
- fontSize: "11px",
243
- fontWeight: "500",
244
- cursor: "pointer",
245
- transition: "all 0.2s ease",
246
- flexShrink: 0,
247
- }}
248
- onMouseEnter={(e) => {
249
- e.currentTarget.style.opacity = "0.9";
250
- e.currentTarget.style.transform = "translateY(-1px)";
251
- }}
252
- onMouseLeave={(e) => {
253
- e.currentTarget.style.opacity = "1";
254
- e.currentTarget.style.transform = "translateY(0)";
255
- }}
256
- >
257
- {link.text}
258
- </button>
259
- )}
260
-
261
- {details && (
262
- <button
263
- onClick={() => setDetailsExpanded(!detailsExpanded)}
264
- style={{
265
- background: "transparent",
266
- border: `1px solid ${colors.border}`,
267
- borderRadius: "5px",
268
- padding: "4px 10px",
269
- fontSize: "11px",
270
- fontWeight: "500",
271
- cursor: "pointer",
272
- color: colors.text,
273
- flexShrink: 0,
274
- transition: "all 0.2s ease",
275
- }}
276
- onMouseEnter={(e) => {
277
- e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
278
- }}
279
- onMouseLeave={(e) => {
280
- e.currentTarget.style.background = "transparent";
281
- }}
282
- >
283
- {detailsExpanded ? "Hide Details" : "Show Details"}
284
- </button>
285
- )}
286
- </div>
287
- </div>
288
- <button
289
- onClick={onDismiss}
290
- style={{
291
- background: "transparent",
292
- border: "none",
293
- color: colors.text,
294
- cursor: "pointer",
295
- padding: "2px",
296
- borderRadius: "3px",
297
- fontSize: "14px",
298
- lineHeight: "1",
299
- opacity: 0.6,
300
- transition: "all 0.2s ease",
301
- flexShrink: 0,
302
- }}
303
- title="Dismiss"
304
- onMouseEnter={(e) => {
305
- e.currentTarget.style.opacity = "1";
306
- e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
307
- }}
308
- onMouseLeave={(e) => {
309
- e.currentTarget.style.opacity = "0.6";
310
- e.currentTarget.style.background = "transparent";
311
- }}
312
- >
313
- x
314
- </button>
315
- </div>
316
-
317
- {detailsExpanded && details && (
318
- <div
319
- style={{
320
- marginTop: "10px",
321
- padding: "10px",
322
- background: "rgba(0, 0, 0, 0.04)",
323
- borderRadius: "6px",
324
- fontSize: "11px",
325
- fontFamily: "monospace",
326
- color: colors.text,
327
- lineHeight: "1.5",
328
- maxHeight: "200px",
329
- overflowY: "auto",
330
- whiteSpace: "pre-wrap",
331
- wordBreak: "break-all",
332
- }}
333
- >
334
- {details.code && (
335
- <div>
336
- <strong>Code:</strong> {details.code}
337
- </div>
338
- )}
339
- {details.originalMessage && (
340
- <div style={{ marginTop: "4px" }}>
341
- <strong>Message:</strong> {details.originalMessage}
342
- </div>
343
- )}
344
- {details.context && Object.keys(details.context).length > 0 && (
345
- <div style={{ marginTop: "4px" }}>
346
- <strong>Context:</strong>{" "}
347
- {JSON.stringify(details.context, null, 2)}
348
- </div>
349
- )}
350
- {details.stack && (
351
- <div style={{ marginTop: "4px", opacity: 0.7 }}>
352
- <strong>Stack:</strong>
353
- {"\n"}
354
- {details.stack}
355
- </div>
356
- )}
357
- </div>
358
- )}
359
- </div>
360
- );
361
- }
362
-
363
- export function ToastProvider({
364
- enabled,
365
- children,
366
- }: {
367
- enabled: boolean;
368
- children: React.ReactNode;
369
- }) {
370
- const [toasts, setToasts] = useState<Toast[]>([]);
371
- const [bannerError, setBannerErrorState] = useState<CopilotKitError | null>(
372
- null,
373
- );
374
-
375
- const removeToast = useCallback((id: string) => {
376
- setToasts((prev) => prev.filter((toast) => toast.id !== id));
377
- }, []);
378
-
379
- const addToast = useCallback(
380
- (toast: PartialBy<Toast, "id">) => {
381
- // Respect the enabled flag for ALL toasts
382
- if (!enabled) {
383
- return;
384
- }
385
-
386
- const id = toast.id ?? Math.random().toString(36).substring(2, 9);
387
-
388
- setToasts((currentToasts) => {
389
- if (currentToasts.find((toast) => toast.id === id))
390
- return currentToasts;
391
- return [...currentToasts, { ...toast, id }];
392
- });
393
-
394
- if (toast.duration) {
395
- setTimeout(() => {
396
- removeToast(id);
397
- }, toast.duration);
398
- }
399
- },
400
- [enabled, removeToast],
401
- );
402
-
403
- const setBannerError = useCallback(
404
- (error: CopilotKitError | null) => {
405
- // Respect the enabled flag for ALL errors
406
- if (!enabled && error !== null) {
407
- return;
408
- }
409
- setBannerErrorState(error);
410
- },
411
- [enabled],
412
- );
413
-
414
- const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {
415
- // DEPRECATED: All errors now route to banners for consistency
416
- console.warn(
417
- "addGraphQLErrorsToast is deprecated. All errors now show as banners.",
418
- );
419
- // Function kept for backward compatibility - does nothing
420
- }, []);
421
-
422
- const value = {
423
- toasts,
424
- addToast,
425
- addGraphQLErrorsToast,
426
- removeToast,
427
- enabled,
428
- bannerError,
429
- setBannerError,
430
- };
431
-
432
- return (
433
- <ToastContext.Provider value={value}>
434
- {/* Banner Error Display */}
435
- {bannerError && (
436
- <BannerErrorDisplay
437
- bannerError={bannerError}
438
- onDismiss={() => setBannerError(null)}
439
- />
440
- )}
441
-
442
- {/* Toast Display - Deprecated: All errors now show as banners */}
443
- {children}
444
- </ToastContext.Provider>
445
- );
446
- }
447
-
448
- // Toast component removed - all errors now show as banners for consistency
@@ -1,266 +0,0 @@
1
- import {
2
- Severity,
3
- CopilotKitError,
4
- ErrorVisibility,
5
- CopilotKitErrorCode,
6
- } from "@copilotkit/shared";
7
- import React from "react";
8
-
9
- interface UsageBannerProps {
10
- severity?: Severity;
11
- message?: string | React.ReactNode;
12
- onClose?: () => void;
13
- actions?: {
14
- primary?: {
15
- label: string;
16
- onClick: () => void;
17
- };
18
- secondary?: {
19
- label: string;
20
- onClick: () => void;
21
- };
22
- };
23
- }
24
-
25
- export function UsageBanner({
26
- severity = Severity.CRITICAL,
27
- message = "",
28
- onClose,
29
- actions,
30
- }: UsageBannerProps) {
31
- if (!message || !severity) {
32
- return null;
33
- }
34
-
35
- const themes = {
36
- [Severity.INFO]: {
37
- bg: "#f8fafc",
38
- border: "#e2e8f0",
39
- text: "#475569",
40
- accent: "#3b82f6",
41
- },
42
- [Severity.WARNING]: {
43
- bg: "#fffbeb",
44
- border: "#fbbf24",
45
- text: "#92400e",
46
- accent: "#f59e0b",
47
- },
48
- [Severity.CRITICAL]: {
49
- bg: "#fef2f2",
50
- border: "#fecaca",
51
- text: "#dc2626",
52
- accent: "#ef4444",
53
- },
54
- };
55
-
56
- const theme = themes[severity];
57
-
58
- return (
59
- <>
60
- <style>
61
- {`
62
- @keyframes slideUp {
63
- from { opacity: 0; transform: translateX(-50%) translateY(8px); }
64
- to { opacity: 1; transform: translateX(-50%) translateY(0); }
65
- }
66
-
67
- .usage-banner {
68
- position: fixed;
69
- bottom: 24px;
70
- left: 50%;
71
- transform: translateX(-50%);
72
- width: min(600px, calc(100vw - 32px));
73
- z-index: 10000;
74
- animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
75
- }
76
-
77
- .banner-content {
78
- background: linear-gradient(135deg, ${theme.bg} 0%, ${theme.bg}f5 100%);
79
- border: 1px solid ${theme.border};
80
- border-radius: 12px;
81
- padding: 18px 20px;
82
- box-shadow:
83
- 0 4px 24px rgba(0, 0, 0, 0.08),
84
- 0 2px 8px rgba(0, 0, 0, 0.04),
85
- inset 0 1px 0 rgba(255, 255, 255, 0.7);
86
- display: flex;
87
- align-items: center;
88
- gap: 16px;
89
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
90
- backdrop-filter: blur(12px);
91
- position: relative;
92
- overflow: hidden;
93
- }
94
-
95
- .banner-content::before {
96
- content: '';
97
- position: absolute;
98
- top: 0;
99
- left: 0;
100
- right: 0;
101
- height: 1px;
102
- background: linear-gradient(90deg, transparent, ${theme.accent}40, transparent);
103
- }
104
-
105
- .banner-message {
106
- color: ${theme.text};
107
- font-size: 14px;
108
- line-height: 1.5;
109
- font-weight: 500;
110
- flex: 1;
111
- letter-spacing: -0.01em;
112
- }
113
-
114
- .close-btn {
115
- background: rgba(0, 0, 0, 0.05);
116
- border: none;
117
- color: ${theme.text};
118
- cursor: pointer;
119
- padding: 0;
120
- border-radius: 6px;
121
- opacity: 0.6;
122
- transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
123
- font-size: 14px;
124
- line-height: 1;
125
- flex-shrink: 0;
126
- width: 24px;
127
- height: 24px;
128
- display: flex;
129
- align-items: center;
130
- justify-content: center;
131
- }
132
-
133
- .close-btn:hover {
134
- opacity: 1;
135
- background: rgba(0, 0, 0, 0.08);
136
- transform: scale(1.05);
137
- }
138
-
139
- .btn-primary {
140
- background: linear-gradient(135deg, ${theme.accent} 0%, ${theme.accent}e6 100%);
141
- color: white;
142
- border: none;
143
- border-radius: 8px;
144
- padding: 10px 18px;
145
- font-size: 13px;
146
- font-weight: 600;
147
- cursor: pointer;
148
- transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
149
- font-family: inherit;
150
- flex-shrink: 0;
151
- box-shadow:
152
- 0 2px 8px ${theme.accent}30,
153
- inset 0 1px 0 rgba(255, 255, 255, 0.2);
154
- letter-spacing: -0.01em;
155
- }
156
-
157
- .btn-primary:hover {
158
- transform: translateY(-1px) scale(1.02);
159
- box-shadow:
160
- 0 4px 12px ${theme.accent}40,
161
- inset 0 1px 0 rgba(255, 255, 255, 0.25);
162
- }
163
-
164
- .btn-primary:active {
165
- transform: translateY(0) scale(0.98);
166
- transition: all 0.08s cubic-bezier(0.16, 1, 0.3, 1);
167
- }
168
-
169
- @media (max-width: 640px) {
170
- .usage-banner {
171
- width: calc(100vw - 24px);
172
- }
173
-
174
- .banner-content {
175
- padding: 16px;
176
- gap: 12px;
177
- }
178
-
179
- .banner-message {
180
- font-size: 13px;
181
- line-height: 1.45;
182
- }
183
-
184
- .btn-primary {
185
- padding: 8px 14px;
186
- font-size: 12px;
187
- }
188
-
189
- .close-btn {
190
- width: 22px;
191
- height: 22px;
192
- font-size: 12px;
193
- }
194
- }
195
- `}
196
- </style>
197
-
198
- <div className="usage-banner">
199
- <div className="banner-content">
200
- <div className="banner-message">{message}</div>
201
- {actions?.primary && (
202
- <button className="btn-primary" onClick={actions.primary.onClick}>
203
- {actions.primary.label}
204
- </button>
205
- )}
206
- {onClose && (
207
- <button className="close-btn" onClick={onClose} title="Close">
208
- ×
209
- </button>
210
- )}
211
- </div>
212
- </div>
213
- </>
214
- );
215
- }
216
-
217
- // Get action button based on error type
218
- export const getErrorActions = (error: CopilotKitError) => {
219
- switch (error.code) {
220
- case CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR:
221
- return {
222
- primary: {
223
- label: "Show me how",
224
- onClick: () =>
225
- window.open(
226
- "https://docs.copilotkit.ai/premium#how-do-i-get-access-to-premium-features",
227
- "_blank",
228
- "noopener,noreferrer",
229
- ),
230
- },
231
- };
232
- case CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR:
233
- return {
234
- primary: {
235
- label: "Upgrade",
236
- onClick: () =>
237
- window.open(
238
- "https://cloud.copilotkit.ai",
239
- "_blank",
240
- "noopener,noreferrer",
241
- ),
242
- },
243
- };
244
- default:
245
- return undefined;
246
- }
247
- };
248
-
249
- export function renderCopilotKitUsage(
250
- error: CopilotKitError,
251
- onClose?: () => void,
252
- ) {
253
- // Route based on error visibility level
254
- if (error.visibility !== ErrorVisibility.BANNER) {
255
- return null;
256
- }
257
-
258
- return (
259
- <UsageBanner
260
- severity={error.severity || Severity.CRITICAL}
261
- message={error.message}
262
- onClose={onClose}
263
- actions={getErrorActions(error)}
264
- />
265
- );
266
- }