@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,464 +0,0 @@
1
- import React from "react";
2
- import { afterEach, describe, expect, it } from "vitest";
3
- import { fireEvent, render, screen, waitFor } from "@testing-library/react";
4
- import { EventType } from "@ag-ui/client";
5
- import type { BaseEvent, RunAgentInput } from "@ag-ui/client";
6
- import type { Observable } from "rxjs";
7
- import type { Subject } from "rxjs";
8
- import { takeWhile } from "rxjs/operators";
9
- import {
10
- MockStepwiseAgent,
11
- runStartedEvent,
12
- runFinishedEvent,
13
- textMessageStartEvent,
14
- textMessageContentEvent,
15
- textMessageEndEvent,
16
- toolCallChunkEvent,
17
- toolCallResultEvent,
18
- } from "../../../__tests__/utils/test-helpers";
19
- import { CopilotChat } from "../../chat/CopilotChat";
20
- import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
21
- import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
22
- import { useCopilotKit } from "../../../providers/CopilotKitProvider";
23
- import { useAgent } from "../../../hooks/use-agent";
24
-
25
- /**
26
- * Mock agent with accurate per-run `isRunning` lifecycle. The shared
27
- * `MockStepwiseAgent` returns the un-terminating `subject.asObservable()`
28
- * for backward compatibility, so emitting `RUN_FINISHED` on it doesn't
29
- * complete the rxjs pipeline → `isRunning` never flips back. The
30
- * `takeWhile(..., true)` here makes the per-run observable terminate on
31
- * RUN_FINISHED / RUN_ERROR (the `true` is "inclusive" — emit the
32
- * terminal event before completing). That terminates AG-UI's run
33
- * pipeline like a real agent so the indicator sees the falling edge.
34
- */
35
- class IsRunningAccurateMockAgent extends MockStepwiseAgent {
36
- override run(_input: RunAgentInput): Observable<BaseEvent> {
37
- return (this as unknown as { subject: Subject<BaseEvent> }).subject.pipe(
38
- takeWhile(
39
- (event) =>
40
- event.type !== EventType.RUN_FINISHED &&
41
- event.type !== EventType.RUN_ERROR,
42
- true,
43
- ),
44
- );
45
- }
46
- }
47
-
48
- const PILL_TESTID_RE = /^cpk-intelligence-pill-/;
49
-
50
- const expectPillCount = (n: number): void => {
51
- expect(screen.queryAllByTestId(PILL_TESTID_RE).length).toBe(n);
52
- };
53
-
54
- const expectPillOn = (messageId: string): void => {
55
- expect(
56
- screen.getByTestId(`cpk-intelligence-pill-${messageId}`).textContent,
57
- ).toContain("Using CopilotKit Intelligence");
58
- };
59
-
60
- const expectNoPillOn = (messageId: string): void => {
61
- expect(screen.queryByTestId(`cpk-intelligence-pill-${messageId}`)).toBeNull();
62
- };
63
-
64
- const expectNoPillAnywhere = (): void => {
65
- expect(screen.queryAllByTestId(PILL_TESTID_RE).length).toBe(0);
66
- };
67
-
68
- const emitAssistantMessageWithToolCalls = (
69
- agent: MockStepwiseAgent,
70
- messageId: string,
71
- toolCalls: Array<{ id: string; name?: string; arg: string }>,
72
- ): void => {
73
- agent.emit(textMessageStartEvent(messageId));
74
- agent.emit(textMessageEndEvent(messageId));
75
- for (const tc of toolCalls) {
76
- agent.emit(
77
- toolCallChunkEvent({
78
- toolCallId: tc.id,
79
- toolCallName: tc.name ?? "copilotkit_knowledge_base_shell",
80
- parentMessageId: messageId,
81
- delta: tc.arg,
82
- }),
83
- );
84
- }
85
- };
86
-
87
- const emitToolResult = (
88
- agent: MockStepwiseAgent,
89
- toolCallId: string,
90
- resultMessageId: string,
91
- content = "ok",
92
- ): void => {
93
- agent.emit(
94
- toolCallResultEvent({ toolCallId, messageId: resultMessageId, content }),
95
- );
96
- };
97
-
98
- const emitAssistantProse = (
99
- agent: MockStepwiseAgent,
100
- messageId: string,
101
- text: string,
102
- ): void => {
103
- agent.emit(textMessageStartEvent(messageId));
104
- agent.emit(textMessageContentEvent(messageId, text));
105
- agent.emit(textMessageEndEvent(messageId));
106
- };
107
-
108
- const startRun = (agent: MockStepwiseAgent): void => {
109
- agent.emit(runStartedEvent());
110
- };
111
-
112
- /**
113
- * Test harness: drives `copilotkit.runAgent` from a click and force-sets
114
- * `copilotkit.intelligence` on the live core. Apps observe the
115
- * intelligence-set-up state via a real `/info` round trip; tests bypass
116
- * that plumbing by writing directly into the registry's private slot.
117
- */
118
- const RunAgentHarness: React.FC<{ withIntelligence: boolean }> = ({
119
- withIntelligence,
120
- }) => {
121
- const { copilotkit } = useCopilotKit();
122
- const { agent } = useAgent();
123
-
124
- React.useEffect(() => {
125
- const reg = (
126
- copilotkit as unknown as {
127
- agentRegistry: { _intelligence?: { wsUrl: string } };
128
- }
129
- ).agentRegistry;
130
- if (withIntelligence) {
131
- reg._intelligence = { wsUrl: "wss://test/intelligence" };
132
- } else {
133
- reg._intelligence = undefined;
134
- }
135
- }, [copilotkit, withIntelligence]);
136
-
137
- const handleClick = React.useCallback(() => {
138
- if (!agent) return;
139
- copilotkit.runAgent({ agent }).catch((err: unknown) => {
140
- console.error("[test] copilotkit.runAgent rejected:", err);
141
- throw err;
142
- });
143
- }, [copilotkit, agent]);
144
-
145
- return (
146
- <button data-testid="trigger-run" onClick={handleClick}>
147
- run
148
- </button>
149
- );
150
- };
151
-
152
- interface RenderOptions {
153
- withIntelligence?: boolean;
154
- }
155
-
156
- const renderForIndicator = (
157
- agent: MockStepwiseAgent,
158
- options: RenderOptions = {},
159
- ): void => {
160
- const { withIntelligence = true } = options;
161
-
162
- // No `renderCustomMessages` prop is passed — the indicator
163
- // auto-mounts when intelligence is configured.
164
- render(
165
- <CopilotKitProvider agents__unsafe_dev_only={{ default: agent }}>
166
- <CopilotChatConfigurationProvider agentId="default" threadId="t">
167
- <RunAgentHarness withIntelligence={withIntelligence} />
168
- <div style={{ height: 400 }}>
169
- <CopilotChat welcomeScreen={false} />
170
- </div>
171
- </CopilotChatConfigurationProvider>
172
- </CopilotKitProvider>,
173
- );
174
- };
175
-
176
- const triggerRun = async (agent: MockStepwiseAgent): Promise<void> => {
177
- await waitFor(() => expect(agent.isRunning).toBe(false));
178
- fireEvent.click(screen.getByTestId("trigger-run"));
179
- await waitFor(() => expect(agent.isRunning).toBe(true));
180
- };
181
-
182
- /** Phase machine fades over up to ~1780 ms (500 + 800 + 480). */
183
- const FADE_OUT_TIMEOUT_MS = 2500;
184
-
185
- describe('IntelligenceIndicator — "Using CopilotKit Intelligence" (auto-mounted)', () => {
186
- const activeAgents: IsRunningAccurateMockAgent[] = [];
187
- const makeAgent = (): IsRunningAccurateMockAgent => {
188
- const agent = new IsRunningAccurateMockAgent();
189
- activeAgents.push(agent);
190
- return agent;
191
- };
192
- afterEach(() => {
193
- while (activeAgents.length) {
194
- const agent = activeAgents.pop()!;
195
- try {
196
- agent.complete();
197
- } catch (err) {
198
- console.error("[test] agent.complete() threw during cleanup:", err);
199
- }
200
- }
201
- });
202
-
203
- /**
204
- * Walks through the canonical scenario:
205
- *
206
- * RUN A
207
- * m_a1 (assistant) → toolCall bash#1, bash#2
208
- * RUN B
209
- * m_b1 (assistant) → toolCall bash
210
- * m_b2 (assistant) → toolCall bash#1, bash#2
211
- *
212
- * The pill must render only on the last message of the latest
213
- * in-flight run — never on multiple messages, never on stale runs,
214
- * never on a non-last message of the current run.
215
- */
216
- it("renders only on the last message of the latest in-flight run", async () => {
217
- const agent = makeAgent();
218
- renderForIndicator(agent);
219
- await screen.findByTestId("trigger-run");
220
-
221
- expectNoPillAnywhere();
222
-
223
- // ─── Run A: m_a1 with two tool calls → pill on m_a1 ───────────────
224
- await triggerRun(agent);
225
- startRun(agent);
226
- emitAssistantMessageWithToolCalls(agent, "m_a1", [
227
- { id: "tc_a1_1", arg: '{"cmd":"ls"}' },
228
- { id: "tc_a1_2", arg: '{"cmd":"pwd"}' },
229
- ]);
230
- await waitFor(() => expectPillOn("m_a1"));
231
- expectPillCount(1);
232
-
233
- agent.emit(runFinishedEvent());
234
-
235
- // ─── Run B: m_b1 (one bash) ──────────────────────────────────────
236
- await triggerRun(agent);
237
- startRun(agent);
238
- emitAssistantMessageWithToolCalls(agent, "m_b1", [
239
- { id: "tc_b1", arg: '{"cmd":"echo b1"}' },
240
- ]);
241
- await waitFor(() => expectPillOn("m_b1"));
242
- // m_a1's pill may briefly remain in fade-out; lock the post-debounce
243
- // state.
244
- await waitFor(() => expectNoPillOn("m_a1"), {
245
- timeout: FADE_OUT_TIMEOUT_MS,
246
- });
247
- expectPillCount(1);
248
-
249
- // ─── m_b2 streams in — pill moves to m_b2, m_b1 loses pill ────────
250
- emitAssistantMessageWithToolCalls(agent, "m_b2", [
251
- { id: "tc_b2_1", arg: '{"cmd":"echo b2-1"}' },
252
- { id: "tc_b2_2", arg: '{"cmd":"echo b2-2"}' },
253
- ]);
254
- await waitFor(() => expectPillOn("m_b2"));
255
- expectNoPillOn("m_b1");
256
- expectNoPillOn("m_a1");
257
- expectPillCount(1);
258
-
259
- // ─── Run B finishes — pill fades, eventually no pill anywhere ─────
260
- agent.emit(runFinishedEvent());
261
- await waitFor(() => expectNoPillAnywhere(), {
262
- timeout: FADE_OUT_TIMEOUT_MS,
263
- });
264
- });
265
-
266
- // ─── Per-condition focused tests ────────────────────────────────────
267
-
268
- it("condition (last-in-run): never renders on a non-last message of the run", async () => {
269
- const agent = makeAgent();
270
- renderForIndicator(agent);
271
- await screen.findByTestId("trigger-run");
272
-
273
- await triggerRun(agent);
274
- startRun(agent);
275
- emitAssistantMessageWithToolCalls(agent, "m_first", [
276
- { id: "tc_first", arg: "{}" },
277
- ]);
278
- // Wait for m_first to render the pill while it is still the last
279
- // message in the run. Without this gate, both messages would land
280
- // synchronously and m_first's renderer would never have been
281
- // invoked while it was the last — turning a reactive assertion
282
- // into a first-render correctness test by accident.
283
- await waitFor(() => expectPillOn("m_first"));
284
-
285
- emitAssistantMessageWithToolCalls(agent, "m_second", [
286
- { id: "tc_second", arg: "{}" },
287
- ]);
288
-
289
- await waitFor(() => expectPillOn("m_second"));
290
- expectNoPillOn("m_first");
291
- expectPillCount(1);
292
- });
293
-
294
- it("condition (in-flight): pill clears after the run finishes", async () => {
295
- const agent = makeAgent();
296
- renderForIndicator(agent);
297
- await screen.findByTestId("trigger-run");
298
-
299
- await triggerRun(agent);
300
- startRun(agent);
301
- emitAssistantMessageWithToolCalls(agent, "m_only", [
302
- { id: "tc", arg: "{}" },
303
- ]);
304
- await waitFor(() => expectPillOn("m_only"));
305
-
306
- agent.emit(runFinishedEvent());
307
- await waitFor(() => expectNoPillOn("m_only"), {
308
- timeout: FADE_OUT_TIMEOUT_MS,
309
- });
310
- });
311
-
312
- it("condition (latest-run): never renders on a stale run after a newer run starts", async () => {
313
- const agent = makeAgent();
314
- renderForIndicator(agent);
315
- await screen.findByTestId("trigger-run");
316
-
317
- await triggerRun(agent);
318
- startRun(agent);
319
- emitAssistantMessageWithToolCalls(agent, "m_run1", [
320
- { id: "tc_run1", arg: "{}" },
321
- ]);
322
- await waitFor(() => expectPillOn("m_run1"));
323
- agent.emit(runFinishedEvent());
324
-
325
- await triggerRun(agent);
326
- startRun(agent);
327
- emitAssistantMessageWithToolCalls(agent, "m_run2", [
328
- { id: "tc_run2", arg: "{}" },
329
- ]);
330
- await waitFor(() => expectPillOn("m_run2"));
331
- expectNoPillOn("m_run1");
332
- });
333
-
334
- it("condition (tool-match): only renders when a configured tool name matches", async () => {
335
- const agent = makeAgent();
336
- renderForIndicator(agent);
337
- await screen.findByTestId("trigger-run");
338
-
339
- await triggerRun(agent);
340
- startRun(agent);
341
- // First message has only a non-matching tool call; no pill.
342
- emitAssistantMessageWithToolCalls(agent, "m_no_match", [
343
- { id: "tc_no_match", name: "fetch", arg: "{}" },
344
- ]);
345
- await new Promise((r) => setTimeout(r, 80));
346
- expectNoPillOn("m_no_match");
347
-
348
- // Second message has a bash call — pill should appear on it.
349
- emitAssistantMessageWithToolCalls(agent, "m_match", [
350
- { id: "tc_match", name: "copilotkit_knowledge_base_shell", arg: "{}" },
351
- ]);
352
- await waitFor(() => expectPillOn("m_match"));
353
- expectPillCount(1);
354
- });
355
-
356
- it("intelligence gate: does not render when copilotkit.intelligence is undefined", async () => {
357
- const agent = makeAgent();
358
- renderForIndicator(agent, { withIntelligence: false });
359
- await screen.findByTestId("trigger-run");
360
-
361
- await triggerRun(agent);
362
- startRun(agent);
363
- emitAssistantMessageWithToolCalls(agent, "m1", [{ id: "tc1", arg: "{}" }]);
364
-
365
- // Without the gate, the pill would be visible by now.
366
- await new Promise((r) => setTimeout(r, 80));
367
- expectNoPillAnywhere();
368
- });
369
-
370
- it("auto-registration: no renderCustomMessages prop is required", async () => {
371
- // This is the explicit assertion that the indicator auto-mounts.
372
- // `renderForIndicator` does not pass `renderCustomMessages`, yet
373
- // the pill renders solely because intelligence is configured.
374
- const agent = makeAgent();
375
- renderForIndicator(agent);
376
- await screen.findByTestId("trigger-run");
377
-
378
- await triggerRun(agent);
379
- startRun(agent);
380
- emitAssistantMessageWithToolCalls(agent, "m1", [{ id: "tc1", arg: "{}" }]);
381
-
382
- await waitFor(() => expectPillOn("m1"));
383
- expectPillCount(1);
384
- });
385
-
386
- // ─── New gate: tool-call pending past grace window ──────────────────
387
-
388
- it("replay-flash suppression: no pill when tool result arrives within the grace window", async () => {
389
- // Models a `connectAgent` history replay: the tool call and its
390
- // matching `tool`-role result arrive in the same tick, well below
391
- // PENDING_THRESHOLD_MS. The pill timer should be cancelled before
392
- // it fires, so nothing renders.
393
- const agent = makeAgent();
394
- renderForIndicator(agent);
395
- await screen.findByTestId("trigger-run");
396
-
397
- await triggerRun(agent);
398
- startRun(agent);
399
- emitAssistantMessageWithToolCalls(agent, "m_replay", [
400
- { id: "tc_replay", arg: '{"cmd":"ls"}' },
401
- ]);
402
- emitToolResult(agent, "tc_replay", "tr_replay");
403
-
404
- // Wait past the grace window — pill should never appear.
405
- await new Promise((r) => setTimeout(r, 200));
406
- expectNoPillAnywhere();
407
- });
408
-
409
- it("multi-step: pill stays continuously across tool-result interleaving", async () => {
410
- // Tool result arrives, then a second assistant message with bash.
411
- // The pill must not show the completed/fade animation between
412
- // calls — it stays on m_step1 until m_step2 takes over the slot.
413
- const agent = makeAgent();
414
- renderForIndicator(agent);
415
- await screen.findByTestId("trigger-run");
416
-
417
- await triggerRun(agent);
418
- startRun(agent);
419
- emitAssistantMessageWithToolCalls(agent, "m_step1", [
420
- { id: "tc_step1", arg: '{"cmd":"ls"}' },
421
- ]);
422
- await waitFor(() => expectPillOn("m_step1"));
423
-
424
- // Tool result lands. agent.isRunning is still true, no real
425
- // follow-up yet → pill stays on m_step1 in spinner.
426
- emitToolResult(agent, "tc_step1", "tr_step1");
427
- await new Promise((r) => setTimeout(r, 150));
428
- expectPillOn("m_step1");
429
- expectPillCount(1);
430
-
431
- // Second assistant message with bash arrives. Slot moves; old
432
- // instance returns null without a fade animation.
433
- emitAssistantMessageWithToolCalls(agent, "m_step2", [
434
- { id: "tc_step2", arg: '{"cmd":"pwd"}' },
435
- ]);
436
- await waitFor(() => expectPillOn("m_step2"));
437
- expectNoPillOn("m_step1");
438
- expectPillCount(1);
439
- });
440
-
441
- it("real-followup exit: prose assistant message after the tool flow clears the pill", async () => {
442
- // After the tool result the agent emits a final prose message —
443
- // that's a "real follow-up" and should immediately exit the
444
- // spinner (without waiting on isRunning), advancing to check
445
- // → fading → hidden.
446
- const agent = makeAgent();
447
- renderForIndicator(agent);
448
- await screen.findByTestId("trigger-run");
449
-
450
- await triggerRun(agent);
451
- startRun(agent);
452
- emitAssistantMessageWithToolCalls(agent, "m_tool", [
453
- { id: "tc_only", arg: '{"cmd":"ls"}' },
454
- ]);
455
- await waitFor(() => expectPillOn("m_tool"));
456
-
457
- emitToolResult(agent, "tc_only", "tr_only");
458
- emitAssistantProse(agent, "m_prose", "All done.");
459
-
460
- await waitFor(() => expectNoPillAnywhere(), {
461
- timeout: FADE_OUT_TIMEOUT_MS,
462
- });
463
- });
464
- });
@@ -1,2 +0,0 @@
1
- export { IntelligenceIndicator } from "./IntelligenceIndicator";
2
- export type { IntelligenceIndicatorProps } from "./IntelligenceIndicator";
@@ -1,217 +0,0 @@
1
- import React, { useEffect } from "react";
2
-
3
- // Total reserved vertical space for the fixed license banner: banner height
4
- // (~36px) + bottom offset (8px) + visual gap above the chat input (~8px).
5
- const LICENSE_BANNER_OFFSET_PX = 52;
6
- const LICENSE_BANNER_OFFSET_VAR = "--copilotkit-license-banner-offset";
7
-
8
- interface LicenseWarningBannerProps {
9
- type:
10
- | "no_license"
11
- | "expired"
12
- | "expiring"
13
- | "invalid"
14
- | "feature_unlicensed";
15
- featureName?: string;
16
- expiryDate?: string;
17
- graceRemaining?: number;
18
- onDismiss?: () => void;
19
- }
20
-
21
- const BANNER_STYLES: Record<string, React.CSSProperties> = {
22
- base: {
23
- position: "fixed",
24
- bottom: "8px",
25
- left: "50%",
26
- transform: "translateX(-50%)",
27
- zIndex: 99999,
28
- display: "inline-flex",
29
- alignItems: "center",
30
- gap: "12px",
31
- whiteSpace: "nowrap",
32
- padding: "8px 16px",
33
- fontSize: "13px",
34
- fontFamily:
35
- "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
36
- borderRadius: "6px",
37
- boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
38
- },
39
- info: {
40
- backgroundColor: "#eff6ff",
41
- border: "1px solid #93c5fd",
42
- color: "#1e40af",
43
- },
44
- warning: {
45
- backgroundColor: "#fffbeb",
46
- border: "1px solid #fbbf24",
47
- color: "#92400e",
48
- },
49
- critical: {
50
- backgroundColor: "#fef2f2",
51
- border: "1px solid #fca5a5",
52
- color: "#991b1b",
53
- },
54
- };
55
-
56
- function getSeverityStyle(severity: string): React.CSSProperties {
57
- switch (severity) {
58
- case "warning":
59
- return BANNER_STYLES.warning;
60
- case "critical":
61
- return BANNER_STYLES.critical;
62
- default:
63
- return BANNER_STYLES.info;
64
- }
65
- }
66
-
67
- function BannerShell({
68
- severity,
69
- message,
70
- actionLabel,
71
- actionUrl,
72
- onDismiss,
73
- }: {
74
- severity: string;
75
- message: string;
76
- actionLabel: string;
77
- actionUrl: string;
78
- onDismiss?: () => void;
79
- }) {
80
- // Publish the banner's reserved bottom offset so the chat input can lift
81
- // itself above it via padding-bottom: var(--copilotkit-license-banner-offset).
82
- useEffect(() => {
83
- if (typeof document === "undefined") return;
84
- const root = document.documentElement;
85
- root.style.setProperty(
86
- LICENSE_BANNER_OFFSET_VAR,
87
- `${LICENSE_BANNER_OFFSET_PX}px`,
88
- );
89
- return () => {
90
- root.style.removeProperty(LICENSE_BANNER_OFFSET_VAR);
91
- };
92
- }, []);
93
-
94
- return (
95
- <div style={{ ...BANNER_STYLES.base, ...getSeverityStyle(severity) }}>
96
- <span>{message}</span>
97
- <div style={{ display: "flex", gap: "8px", alignItems: "center" }}>
98
- <a
99
- href={actionUrl}
100
- target="_blank"
101
- rel="noopener noreferrer"
102
- style={{
103
- fontWeight: 600,
104
- textDecoration: "underline",
105
- color: "inherit",
106
- }}
107
- >
108
- {actionLabel}
109
- </a>
110
- {onDismiss && (
111
- <button
112
- onClick={onDismiss}
113
- style={{
114
- background: "none",
115
- border: "none",
116
- cursor: "pointer",
117
- color: "inherit",
118
- fontSize: "16px",
119
- }}
120
- >
121
- ×
122
- </button>
123
- )}
124
- </div>
125
- </div>
126
- );
127
- }
128
-
129
- export function LicenseWarningBanner({
130
- type,
131
- featureName,
132
- expiryDate,
133
- graceRemaining,
134
- onDismiss,
135
- }: LicenseWarningBannerProps) {
136
- switch (type) {
137
- case "no_license":
138
- return (
139
- <BannerShell
140
- severity="info"
141
- message="Powered by CopilotKit"
142
- actionLabel="Get a license"
143
- actionUrl="https://copilotkit.ai/pricing"
144
- onDismiss={onDismiss}
145
- />
146
- );
147
- case "feature_unlicensed":
148
- return (
149
- <BannerShell
150
- severity="warning"
151
- message={`⚠ The "${featureName}" feature requires a CopilotKit license.`}
152
- actionLabel="Get a license"
153
- actionUrl="https://copilotkit.ai/pricing"
154
- onDismiss={onDismiss}
155
- />
156
- );
157
- case "expiring":
158
- return (
159
- <BannerShell
160
- severity="warning"
161
- message={`Your CopilotKit license expires in ${graceRemaining} day${graceRemaining !== 1 ? "s" : ""}. Please renew.`}
162
- actionLabel="Renew"
163
- actionUrl="https://cloud.copilotkit.ai"
164
- onDismiss={onDismiss}
165
- />
166
- );
167
- case "expired":
168
- return (
169
- <BannerShell
170
- severity="critical"
171
- message={`Your CopilotKit license expired${expiryDate ? ` on ${expiryDate}` : ""}. Please renew at copilotkit.ai/pricing`}
172
- actionLabel="Renew now"
173
- actionUrl="https://copilotkit.ai/pricing"
174
- onDismiss={onDismiss}
175
- />
176
- );
177
- case "invalid":
178
- return (
179
- <BannerShell
180
- severity="critical"
181
- message="Invalid CopilotKit license token. Please check your configuration."
182
- actionLabel="Get a license"
183
- actionUrl="https://copilotkit.ai/pricing"
184
- onDismiss={onDismiss}
185
- />
186
- );
187
- default:
188
- return null;
189
- }
190
- }
191
-
192
- export function InlineFeatureWarning({ featureName }: { featureName: string }) {
193
- return (
194
- <div
195
- style={{
196
- padding: "8px 12px",
197
- backgroundColor: "#fffbeb",
198
- border: "1px solid #fbbf24",
199
- borderRadius: "6px",
200
- fontSize: "13px",
201
- color: "#92400e",
202
- fontFamily:
203
- "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
204
- }}
205
- >
206
- ⚠ The &quot;{featureName}&quot; feature requires a CopilotKit license.{" "}
207
- <a
208
- href="https://copilotkit.ai/pricing"
209
- target="_blank"
210
- rel="noopener noreferrer"
211
- style={{ color: "#b45309", textDecoration: "underline" }}
212
- >
213
- Get one at copilotkit.ai/pricing
214
- </a>
215
- </div>
216
- );
217
- }