@copilotkit/react-core 1.57.2 → 1.57.4

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 (266) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +12 -13
  3. package/skills/react-core/SKILL.md +108 -0
  4. package/skills/react-core/references/agent-access.md +288 -0
  5. package/skills/react-core/references/attachments.md +291 -0
  6. package/skills/react-core/references/capabilities.md +138 -0
  7. package/skills/react-core/references/chat-components.md +221 -0
  8. package/skills/react-core/references/client-side-tools.md +358 -0
  9. package/skills/react-core/references/custom-message-renderers.md +226 -0
  10. package/skills/react-core/references/debug-mode.md +153 -0
  11. package/skills/react-core/references/human-in-the-loop.md +312 -0
  12. package/skills/react-core/references/provider-setup.md +326 -0
  13. package/skills/react-core/references/rendering-activity-messages.md +207 -0
  14. package/skills/react-core/references/rendering-tool-calls.md +319 -0
  15. package/skills/react-core/references/suggestions.md +211 -0
  16. package/skills/react-core/references/switching-agents-recipes.md +160 -0
  17. package/skills/react-core/references/switching-agents.md +231 -0
  18. package/skills/react-core/references/threads.md +226 -0
  19. package/.attw.json +0 -3
  20. package/CHANGELOG.md +0 -5043
  21. package/scripts/scope-preflight.mjs +0 -100
  22. package/src/components/CopilotListeners.tsx +0 -137
  23. package/src/components/__tests__/CopilotListeners.test.tsx +0 -38
  24. package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +0 -92
  25. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -77
  26. package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +0 -70
  27. package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +0 -107
  28. package/src/components/copilot-provider/copilot-messages.tsx +0 -314
  29. package/src/components/copilot-provider/copilotkit-props.tsx +0 -214
  30. package/src/components/copilot-provider/copilotkit.tsx +0 -853
  31. package/src/components/copilot-provider/index.ts +0 -3
  32. package/src/components/dev-console/console-trigger.tsx +0 -283
  33. package/src/components/dev-console/developer-console-modal.tsx +0 -1016
  34. package/src/components/dev-console/icons.tsx +0 -106
  35. package/src/components/error-boundary/error-boundary.tsx +0 -99
  36. package/src/components/error-boundary/error-utils.tsx +0 -105
  37. package/src/components/index.ts +0 -1
  38. package/src/components/toast/exclamation-mark-icon.tsx +0 -27
  39. package/src/components/toast/toast-provider.tsx +0 -448
  40. package/src/components/usage-banner.tsx +0 -266
  41. package/src/context/__tests__/threads-context.test.tsx +0 -141
  42. package/src/context/coagent-state-renders-context.tsx +0 -89
  43. package/src/context/copilot-context.tsx +0 -365
  44. package/src/context/copilot-messages-context.tsx +0 -35
  45. package/src/context/index.ts +0 -22
  46. package/src/context/threads-context.tsx +0 -69
  47. package/src/hooks/__tests__/use-coagent-config.test.ts +0 -352
  48. package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +0 -107
  49. package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +0 -1209
  50. package/src/hooks/__tests__/use-coagent-state-render.test.tsx +0 -356
  51. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +0 -241
  52. package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -72
  53. package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +0 -102
  54. package/src/hooks/index.ts +0 -33
  55. package/src/hooks/use-agent-nodename.ts +0 -33
  56. package/src/hooks/use-coagent-state-render-bridge.helpers.ts +0 -345
  57. package/src/hooks/use-coagent-state-render-bridge.tsx +0 -222
  58. package/src/hooks/use-coagent-state-render-registry.ts +0 -230
  59. package/src/hooks/use-coagent-state-render.ts +0 -163
  60. package/src/hooks/use-coagent.ts +0 -377
  61. package/src/hooks/use-configure-chat-suggestions.tsx +0 -96
  62. package/src/hooks/use-copilot-action.ts +0 -245
  63. package/src/hooks/use-copilot-additional-instructions.ts +0 -98
  64. package/src/hooks/use-copilot-authenticated-action.ts +0 -73
  65. package/src/hooks/use-copilot-chat-headless_c.ts +0 -264
  66. package/src/hooks/use-copilot-chat-suggestions.tsx +0 -134
  67. package/src/hooks/use-copilot-chat.ts +0 -132
  68. package/src/hooks/use-copilot-chat_internal.ts +0 -875
  69. package/src/hooks/use-copilot-readable.ts +0 -135
  70. package/src/hooks/use-copilot-runtime-client.ts +0 -178
  71. package/src/hooks/use-default-tool.ts +0 -13
  72. package/src/hooks/use-flat-category-store.ts +0 -109
  73. package/src/hooks/use-frontend-tool.ts +0 -113
  74. package/src/hooks/use-human-in-the-loop.ts +0 -138
  75. package/src/hooks/use-langgraph-interrupt.ts +0 -103
  76. package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
  77. package/src/hooks/use-make-copilot-document-readable.ts +0 -30
  78. package/src/hooks/use-render-tool-call.ts +0 -89
  79. package/src/hooks/use-tree.ts +0 -222
  80. package/src/index.tsx +0 -7
  81. package/src/lib/copilot-task.ts +0 -215
  82. package/src/lib/index.ts +0 -1
  83. package/src/lib/status-checker.ts +0 -67
  84. package/src/setupTests.ts +0 -37
  85. package/src/test-helpers/copilot-context.ts +0 -91
  86. package/src/types/chat-suggestion-configuration.ts +0 -23
  87. package/src/types/coagent-action.ts +0 -35
  88. package/src/types/coagent-state.ts +0 -13
  89. package/src/types/crew.ts +0 -89
  90. package/src/types/document-pointer.ts +0 -7
  91. package/src/types/frontend-action.ts +0 -213
  92. package/src/types/index.ts +0 -17
  93. package/src/types/interrupt-action.ts +0 -58
  94. package/src/types/system-message.ts +0 -4
  95. package/src/utils/dev-console.ts +0 -19
  96. package/src/utils/index.ts +0 -2
  97. package/src/utils/suggestions-constants.ts +0 -8
  98. package/src/utils/utils.test.ts +0 -7
  99. package/src/utils/utils.ts +0 -6
  100. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +0 -240
  101. package/src/v2/__tests__/globalSetup.ts +0 -14
  102. package/src/v2/__tests__/setup.ts +0 -93
  103. package/src/v2/__tests__/utils/test-helpers.tsx +0 -570
  104. package/src/v2/a2ui/A2UICatalogContext.tsx +0 -79
  105. package/src/v2/a2ui/A2UIMessageRenderer.tsx +0 -294
  106. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +0 -290
  107. package/src/v2/components/CopilotKitInspector.tsx +0 -52
  108. package/src/v2/components/MCPAppsActivityRenderer.tsx +0 -815
  109. package/src/v2/components/OpenGenerativeUIRenderer.tsx +0 -598
  110. package/src/v2/components/WildcardToolCallRender.tsx +0 -86
  111. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +0 -665
  112. package/src/v2/components/chat/CopilotChat.tsx +0 -664
  113. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +0 -393
  114. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +0 -374
  115. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +0 -159
  116. package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +0 -350
  117. package/src/v2/components/chat/CopilotChatInput.tsx +0 -1412
  118. package/src/v2/components/chat/CopilotChatMessageView.tsx +0 -716
  119. package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +0 -265
  120. package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +0 -59
  121. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +0 -134
  122. package/src/v2/components/chat/CopilotChatToggleButton.tsx +0 -171
  123. package/src/v2/components/chat/CopilotChatToolCallsView.tsx +0 -40
  124. package/src/v2/components/chat/CopilotChatUserMessage.tsx +0 -445
  125. package/src/v2/components/chat/CopilotChatView.tsx +0 -890
  126. package/src/v2/components/chat/CopilotModalHeader.tsx +0 -129
  127. package/src/v2/components/chat/CopilotPopup.tsx +0 -81
  128. package/src/v2/components/chat/CopilotPopupView.tsx +0 -317
  129. package/src/v2/components/chat/CopilotSidebar.tsx +0 -80
  130. package/src/v2/components/chat/CopilotSidebarView.tsx +0 -269
  131. package/src/v2/components/chat/Lightbox.tsx +0 -103
  132. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +0 -66
  133. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +0 -168
  134. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +0 -1239
  135. package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +0 -73
  136. package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +0 -432
  137. package/src/v2/components/chat/__tests__/CopilotChat.suggestionsAlways.test.tsx +0 -183
  138. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +0 -184
  139. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +0 -649
  140. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +0 -624
  141. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -702
  142. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +0 -72
  143. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +0 -241
  144. package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +0 -107
  145. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +0 -929
  146. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +0 -1567
  147. package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +0 -1004
  148. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +0 -279
  149. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +0 -296
  150. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +0 -249
  151. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +0 -530
  152. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +0 -785
  153. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +0 -2416
  154. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +0 -621
  155. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +0 -56
  156. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.tsx +0 -264
  157. package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +0 -853
  158. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +0 -94
  159. package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +0 -1050
  160. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +0 -484
  161. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +0 -612
  162. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +0 -159
  163. package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +0 -502
  164. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +0 -1068
  165. package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +0 -589
  166. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +0 -403
  167. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -137
  168. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -37
  169. package/src/v2/components/chat/__tests__/setup.ts +0 -1
  170. package/src/v2/components/chat/index.ts +0 -90
  171. package/src/v2/components/chat/last-user-message-context.ts +0 -21
  172. package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
  173. package/src/v2/components/chat/scroll-element-context.ts +0 -13
  174. package/src/v2/components/index.ts +0 -8
  175. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -286
  176. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -464
  177. package/src/v2/components/intelligence-indicator/index.ts +0 -2
  178. package/src/v2/components/license-warning-banner.tsx +0 -217
  179. package/src/v2/components/ui/button.tsx +0 -124
  180. package/src/v2/components/ui/dropdown-menu.tsx +0 -258
  181. package/src/v2/components/ui/tooltip.tsx +0 -60
  182. package/src/v2/context.ts +0 -62
  183. package/src/v2/headless.ts +0 -64
  184. package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +0 -152
  185. package/src/v2/hooks/__tests__/standard-schema.test.tsx +0 -282
  186. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +0 -140
  187. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +0 -401
  188. package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +0 -44
  189. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +0 -211
  190. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +0 -1029
  191. package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +0 -159
  192. package/src/v2/hooks/__tests__/use-attachments.test.tsx +0 -169
  193. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +0 -76
  194. package/src/v2/hooks/__tests__/use-component.test.tsx +0 -126
  195. package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +0 -696
  196. package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +0 -153
  197. package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -167
  198. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +0 -2148
  199. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +0 -1261
  200. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +0 -397
  201. package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +0 -56
  202. package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +0 -192
  203. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +0 -219
  204. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +0 -55
  205. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +0 -259
  206. package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +0 -524
  207. package/src/v2/hooks/__tests__/use-threads.test.tsx +0 -757
  208. package/src/v2/hooks/__tests__/zod-regression.test.tsx +0 -311
  209. package/src/v2/hooks/index.ts +0 -24
  210. package/src/v2/hooks/use-agent-context.tsx +0 -45
  211. package/src/v2/hooks/use-agent.tsx +0 -227
  212. package/src/v2/hooks/use-attachments.tsx +0 -269
  213. package/src/v2/hooks/use-capabilities.tsx +0 -25
  214. package/src/v2/hooks/use-component.tsx +0 -91
  215. package/src/v2/hooks/use-configure-suggestions.tsx +0 -236
  216. package/src/v2/hooks/use-default-render-tool.tsx +0 -271
  217. package/src/v2/hooks/use-frontend-tool.tsx +0 -46
  218. package/src/v2/hooks/use-human-in-the-loop.tsx +0 -81
  219. package/src/v2/hooks/use-interrupt.tsx +0 -305
  220. package/src/v2/hooks/use-keyboard-height.tsx +0 -67
  221. package/src/v2/hooks/use-pin-to-send.ts +0 -94
  222. package/src/v2/hooks/use-render-activity-message.tsx +0 -72
  223. package/src/v2/hooks/use-render-custom-messages.tsx +0 -93
  224. package/src/v2/hooks/use-render-tool-call.tsx +0 -208
  225. package/src/v2/hooks/use-render-tool.tsx +0 -184
  226. package/src/v2/hooks/use-suggestions.tsx +0 -91
  227. package/src/v2/hooks/use-threads.tsx +0 -325
  228. package/src/v2/hooks/useKatexStyles.ts +0 -27
  229. package/src/v2/index.css +0 -1
  230. package/src/v2/index.ts +0 -27
  231. package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +0 -495
  232. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -112
  233. package/src/v2/lib/__tests__/renderSlot.test.tsx +0 -588
  234. package/src/v2/lib/__tests__/slots.test.ts +0 -56
  235. package/src/v2/lib/processPartialHtml.ts +0 -45
  236. package/src/v2/lib/react-core.ts +0 -156
  237. package/src/v2/lib/slots.tsx +0 -184
  238. package/src/v2/lib/transcription-client.ts +0 -184
  239. package/src/v2/lib/utils.ts +0 -8
  240. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +0 -196
  241. package/src/v2/providers/CopilotKitProvider.tsx +0 -800
  242. package/src/v2/providers/SandboxFunctionsContext.ts +0 -10
  243. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +0 -652
  244. package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +0 -101
  245. package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +0 -69
  246. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +0 -881
  247. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +0 -198
  248. package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +0 -740
  249. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +0 -713
  250. package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -294
  251. package/src/v2/providers/index.ts +0 -21
  252. package/src/v2/styles/globals.css +0 -349
  253. package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +0 -525
  254. package/src/v2/types/defineToolCallRenderer.ts +0 -68
  255. package/src/v2/types/frontend-tool.ts +0 -8
  256. package/src/v2/types/human-in-the-loop.ts +0 -33
  257. package/src/v2/types/index.ts +0 -8
  258. package/src/v2/types/interrupt.ts +0 -15
  259. package/src/v2/types/react-activity-message-renderer.ts +0 -27
  260. package/src/v2/types/react-custom-message-renderer.ts +0 -17
  261. package/src/v2/types/react-tool-call-renderer.ts +0 -35
  262. package/src/v2/types/sandbox-function.ts +0 -11
  263. package/tsconfig.json +0 -8
  264. package/tsdown.config.ts +0 -193
  265. package/typedoc.json +0 -4
  266. package/vitest.config.mjs +0 -31
@@ -1,271 +0,0 @@
1
- import React, { useState } from "react";
2
- import { useRenderTool } from "./use-render-tool";
3
-
4
- type DefaultRenderProps = {
5
- /** The name of the tool being called. */
6
- name: string;
7
- /** The parsed parameters passed to the tool call. */
8
- parameters: unknown;
9
- /** Current execution status of the tool call. */
10
- status: "inProgress" | "executing" | "complete";
11
- /** The tool call result string, available only when `status` is `"complete"`. */
12
- result: string | undefined;
13
- };
14
-
15
- /**
16
- * Registers a wildcard (`"*"`) tool-call renderer via `useRenderTool`.
17
- *
18
- * - Call with no config to use CopilotKit's built-in default tool-call card.
19
- * - Pass `config.render` to replace the default UI with your own fallback renderer.
20
- *
21
- * This is useful when you want a generic renderer for tools that do not have a
22
- * dedicated `useRenderTool({ name: "..." })` registration.
23
- *
24
- * @param config - Optional custom wildcard render function.
25
- * @param deps - Optional dependencies to refresh registration.
26
- *
27
- * @example
28
- * ```tsx
29
- * useDefaultRenderTool();
30
- * ```
31
- *
32
- * @example
33
- * ```tsx
34
- * useDefaultRenderTool({
35
- * render: ({ name, status }) => <div>{name}: {status}</div>,
36
- * });
37
- * ```
38
- *
39
- * @example
40
- * ```tsx
41
- * useDefaultRenderTool(
42
- * {
43
- * render: ({ name, result }) => (
44
- * <ToolEventRow title={name} payload={result} compact={compactMode} />
45
- * ),
46
- * },
47
- * [compactMode],
48
- * );
49
- * ```
50
- */
51
- export function useDefaultRenderTool(
52
- config?: {
53
- render?: (props: DefaultRenderProps) => React.ReactElement;
54
- },
55
- deps?: ReadonlyArray<unknown>,
56
- ): void {
57
- useRenderTool(
58
- {
59
- name: "*",
60
- render: config?.render ?? DefaultToolCallRenderer,
61
- },
62
- deps,
63
- );
64
- }
65
-
66
- export function DefaultToolCallRenderer({
67
- name,
68
- parameters,
69
- status,
70
- result,
71
- }: DefaultRenderProps): React.ReactElement {
72
- const [isExpanded, setIsExpanded] = useState(false);
73
-
74
- const statusString = String(status) as
75
- | "inProgress"
76
- | "executing"
77
- | "complete";
78
- const isActive =
79
- statusString === "inProgress" || statusString === "executing";
80
- const isComplete = statusString === "complete";
81
-
82
- const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
83
- const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
84
- const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
85
- const badgeColor = isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46";
86
-
87
- return (
88
- <div
89
- data-testid="copilot-tool-render"
90
- data-tool-name={name}
91
- data-status={statusString}
92
- data-args={safeStringifyForAttr(parameters)}
93
- data-result={safeStringifyForAttr(result)}
94
- style={{
95
- marginTop: "8px",
96
- paddingBottom: "8px",
97
- }}
98
- >
99
- <div
100
- style={{
101
- borderRadius: "12px",
102
- border: "1px solid #e4e4e7",
103
- backgroundColor: "#fafafa",
104
- padding: "14px 16px",
105
- }}
106
- >
107
- {/* Header row — always visible */}
108
- <div
109
- onClick={() => setIsExpanded(!isExpanded)}
110
- style={{
111
- display: "flex",
112
- alignItems: "center",
113
- justifyContent: "space-between",
114
- gap: "10px",
115
- cursor: "pointer",
116
- userSelect: "none",
117
- }}
118
- >
119
- <div
120
- style={{
121
- display: "flex",
122
- alignItems: "center",
123
- gap: "8px",
124
- minWidth: 0,
125
- }}
126
- >
127
- <svg
128
- style={{
129
- height: "14px",
130
- width: "14px",
131
- color: "#71717a",
132
- transition: "transform 0.15s",
133
- transform: isExpanded ? "rotate(90deg)" : "rotate(0deg)",
134
- flexShrink: 0,
135
- }}
136
- fill="none"
137
- viewBox="0 0 24 24"
138
- strokeWidth={2}
139
- stroke="currentColor"
140
- >
141
- <path
142
- strokeLinecap="round"
143
- strokeLinejoin="round"
144
- d="M8.25 4.5l7.5 7.5-7.5 7.5"
145
- />
146
- </svg>
147
- <span
148
- style={{
149
- display: "inline-block",
150
- height: "8px",
151
- width: "8px",
152
- borderRadius: "50%",
153
- backgroundColor: dotColor,
154
- flexShrink: 0,
155
- }}
156
- />
157
- <span
158
- data-testid="copilot-tool-render-name"
159
- style={{
160
- fontSize: "13px",
161
- fontWeight: 600,
162
- color: "#18181b",
163
- overflow: "hidden",
164
- textOverflow: "ellipsis",
165
- whiteSpace: "nowrap",
166
- }}
167
- >
168
- {name}
169
- </span>
170
- </div>
171
-
172
- <span
173
- data-testid="copilot-tool-render-status"
174
- style={{
175
- display: "inline-flex",
176
- alignItems: "center",
177
- borderRadius: "9999px",
178
- padding: "2px 8px",
179
- fontSize: "11px",
180
- fontWeight: 500,
181
- backgroundColor: badgeBg,
182
- color: badgeColor,
183
- flexShrink: 0,
184
- }}
185
- >
186
- {statusLabel}
187
- </span>
188
- </div>
189
-
190
- {/* Expandable details */}
191
- {isExpanded && (
192
- <div style={{ marginTop: "12px", display: "grid", gap: "12px" }}>
193
- <div>
194
- <div
195
- style={{
196
- fontSize: "10px",
197
- textTransform: "uppercase",
198
- letterSpacing: "0.05em",
199
- color: "#71717a",
200
- }}
201
- >
202
- Arguments
203
- </div>
204
- <pre
205
- style={{
206
- marginTop: "6px",
207
- maxHeight: "200px",
208
- overflow: "auto",
209
- borderRadius: "6px",
210
- backgroundColor: "#f4f4f5",
211
- padding: "10px",
212
- fontSize: "11px",
213
- lineHeight: 1.6,
214
- color: "#27272a",
215
- whiteSpace: "pre-wrap",
216
- wordBreak: "break-word",
217
- }}
218
- >
219
- {JSON.stringify(parameters ?? {}, null, 2)}
220
- </pre>
221
- </div>
222
-
223
- {result !== undefined && (
224
- <div>
225
- <div
226
- style={{
227
- fontSize: "10px",
228
- textTransform: "uppercase",
229
- letterSpacing: "0.05em",
230
- color: "#71717a",
231
- }}
232
- >
233
- Result
234
- </div>
235
- <pre
236
- style={{
237
- marginTop: "6px",
238
- maxHeight: "200px",
239
- overflow: "auto",
240
- borderRadius: "6px",
241
- backgroundColor: "#f4f4f5",
242
- padding: "10px",
243
- fontSize: "11px",
244
- lineHeight: 1.6,
245
- color: "#27272a",
246
- whiteSpace: "pre-wrap",
247
- wordBreak: "break-word",
248
- }}
249
- >
250
- {typeof result === "string"
251
- ? result
252
- : JSON.stringify(result, null, 2)}
253
- </pre>
254
- </div>
255
- )}
256
- </div>
257
- )}
258
- </div>
259
- </div>
260
- );
261
- }
262
-
263
- function safeStringifyForAttr(value: unknown): string {
264
- if (value === undefined || value === null) return "";
265
- if (typeof value === "string") return value;
266
- try {
267
- return JSON.stringify(value);
268
- } catch {
269
- return String(value);
270
- }
271
- }
@@ -1,46 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useCopilotKit } from "../context";
3
- import type { ReactFrontendTool } from "../types/frontend-tool";
4
-
5
- const EMPTY_DEPS: ReadonlyArray<unknown> = [];
6
-
7
- export function useFrontendTool<
8
- T extends Record<string, unknown> = Record<string, unknown>,
9
- >(tool: ReactFrontendTool<T>, deps?: ReadonlyArray<unknown>) {
10
- const { copilotkit } = useCopilotKit();
11
- const extraDeps = deps ?? EMPTY_DEPS;
12
-
13
- useEffect(() => {
14
- const name = tool.name;
15
-
16
- // Always register/override the tool for this name on mount
17
- if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
18
- console.warn(
19
- `Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`,
20
- );
21
- copilotkit.removeTool(name, tool.agentId);
22
- }
23
- copilotkit.addTool(tool);
24
-
25
- // Register/override renderer by name and agentId through core.
26
- // The render function is registered even when tool.parameters is
27
- // undefined — tools like HITL confirm dialogs have no parameters
28
- // but still need their UI rendered in the chat.
29
- if (tool.render) {
30
- copilotkit.addHookRenderToolCall({
31
- name,
32
- args: tool.parameters,
33
- agentId: tool.agentId,
34
- render: tool.render,
35
- });
36
- }
37
-
38
- return () => {
39
- copilotkit.removeTool(name, tool.agentId);
40
- // we are intentionally not removing the render here so that the tools can still render in the chat history
41
- };
42
- // Depend on stable keys by default and allow callers to opt into
43
- // additional dependencies for dynamic tool configuration.
44
- // tool.available is included so toggling availability re-registers the tool.
45
- }, [tool.name, tool.available, copilotkit, JSON.stringify(extraDeps)]);
46
- }
@@ -1,81 +0,0 @@
1
- import { useCopilotKit } from "../context";
2
- import type { ReactFrontendTool } from "../types/frontend-tool";
3
- import type { ReactHumanInTheLoop } from "../types/human-in-the-loop";
4
- import type { ReactToolCallRenderer } from "../types/react-tool-call-renderer";
5
- import { useCallback, useEffect, useRef } from "react";
6
- import React from "react";
7
- import { useFrontendTool } from "./use-frontend-tool";
8
-
9
- export function useHumanInTheLoop<
10
- T extends Record<string, unknown> = Record<string, unknown>,
11
- >(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>) {
12
- const { copilotkit } = useCopilotKit();
13
- const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);
14
-
15
- const respond = useCallback(async (result: unknown) => {
16
- if (resolvePromiseRef.current) {
17
- resolvePromiseRef.current(result);
18
- resolvePromiseRef.current = null;
19
- }
20
- }, []);
21
-
22
- const handler = useCallback(async () => {
23
- return new Promise((resolve) => {
24
- resolvePromiseRef.current = resolve;
25
- });
26
- }, []);
27
-
28
- const RenderComponent: ReactToolCallRenderer<T>["render"] = useCallback(
29
- (props) => {
30
- const ToolComponent = tool.render;
31
-
32
- // Enhance props based on current status
33
- if (props.status === "inProgress") {
34
- const enhancedProps = {
35
- ...props,
36
- name: tool.name,
37
- description: tool.description || "",
38
- respond: undefined,
39
- };
40
- return React.createElement(ToolComponent, enhancedProps);
41
- } else if (props.status === "executing") {
42
- const enhancedProps = {
43
- ...props,
44
- name: tool.name,
45
- description: tool.description || "",
46
- respond,
47
- };
48
- return React.createElement(ToolComponent, enhancedProps);
49
- } else if (props.status === "complete") {
50
- const enhancedProps = {
51
- ...props,
52
- name: tool.name,
53
- description: tool.description || "",
54
- respond: undefined,
55
- };
56
- return React.createElement(ToolComponent, enhancedProps);
57
- }
58
-
59
- // Fallback - just render with original props
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- return React.createElement(ToolComponent, props as any);
62
- },
63
- [tool.render, tool.name, tool.description, respond],
64
- );
65
-
66
- const frontendTool: ReactFrontendTool<T> = {
67
- ...tool,
68
- handler,
69
- render: RenderComponent,
70
- };
71
-
72
- useFrontendTool(frontendTool, deps);
73
-
74
- // Human-in-the-loop tools should remove their renderer on unmount
75
- // since they can't respond to user interactions anymore
76
- useEffect(() => {
77
- return () => {
78
- copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
79
- };
80
- }, [copilotkit, tool.name, tool.agentId]);
81
- }
@@ -1,305 +0,0 @@
1
- import React, {
2
- useState,
3
- useEffect,
4
- useCallback,
5
- useMemo,
6
- useRef,
7
- } from "react";
8
- import { useCopilotKit } from "../context";
9
- import { useAgent } from "./use-agent";
10
- import type {
11
- InterruptEvent,
12
- InterruptRenderProps,
13
- InterruptHandlerProps,
14
- } from "../types/interrupt";
15
-
16
- export type { InterruptEvent, InterruptRenderProps, InterruptHandlerProps };
17
-
18
- const INTERRUPT_EVENT_NAME = "on_interrupt";
19
-
20
- type InterruptHandlerFn<TValue, TResult> = (
21
- props: InterruptHandlerProps<TValue>,
22
- ) => TResult | PromiseLike<TResult>;
23
-
24
- type InterruptResultFromHandler<THandler> = THandler extends (
25
- ...args: never[]
26
- ) => infer TResult
27
- ? TResult extends PromiseLike<infer TResolved>
28
- ? TResolved | null
29
- : TResult | null
30
- : null;
31
-
32
- type InterruptResult<TValue, TResult> = InterruptResultFromHandler<
33
- InterruptHandlerFn<TValue, TResult>
34
- >;
35
-
36
- type InterruptRenderInChat = boolean | undefined;
37
-
38
- type UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> =
39
- TRenderInChat extends false
40
- ? React.ReactElement | null
41
- : TRenderInChat extends true | undefined
42
- ? void
43
- : React.ReactElement | null | void;
44
-
45
- export function isPromiseLike<TValue>(
46
- value: TValue | PromiseLike<TValue>,
47
- ): value is PromiseLike<TValue> {
48
- return (
49
- (typeof value === "object" || typeof value === "function") &&
50
- value !== null &&
51
- typeof Reflect.get(value, "then") === "function"
52
- );
53
- }
54
-
55
- /**
56
- * Configuration options for `useInterrupt`.
57
- */
58
- interface UseInterruptConfigBase<TValue = unknown, TResult = never> {
59
- /**
60
- * Render function for the interrupt UI.
61
- *
62
- * This is called once an interrupt is finalized and accepted by `enabled` (if provided).
63
- * Use `resolve` from render props to resume the agent run with user input.
64
- */
65
- render: (
66
- props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>,
67
- ) => React.ReactElement;
68
- /**
69
- * Optional pre-render handler invoked when an interrupt is received.
70
- *
71
- * Return either a sync value or an async value to pass into `render` as `result`.
72
- * Rejecting/throwing falls back to `result = null`.
73
- */
74
- handler?: InterruptHandlerFn<TValue, TResult>;
75
- /**
76
- * Optional predicate to filter which interrupts should be handled by this hook.
77
- * Return `false` to ignore an interrupt.
78
- */
79
- enabled?: (event: InterruptEvent<TValue>) => boolean;
80
- /** Optional agent id. Defaults to the current configured chat agent. */
81
- agentId?: string;
82
- }
83
-
84
- export interface UseInterruptInChatConfig<
85
- TValue = unknown,
86
- TResult = never,
87
- > extends UseInterruptConfigBase<TValue, TResult> {
88
- /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */
89
- renderInChat?: true;
90
- }
91
-
92
- export interface UseInterruptExternalConfig<
93
- TValue = unknown,
94
- TResult = never,
95
- > extends UseInterruptConfigBase<TValue, TResult> {
96
- /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */
97
- renderInChat: false;
98
- }
99
-
100
- export interface UseInterruptDynamicConfig<
101
- TValue = unknown,
102
- TResult = never,
103
- > extends UseInterruptConfigBase<TValue, TResult> {
104
- /** Dynamic boolean mode. When non-literal, return type is a union. */
105
- renderInChat: boolean;
106
- }
107
-
108
- export type UseInterruptConfig<
109
- TValue = unknown,
110
- TResult = never,
111
- TRenderInChat extends InterruptRenderInChat = undefined,
112
- > = UseInterruptConfigBase<TValue, TResult> & {
113
- /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */
114
- renderInChat?: TRenderInChat;
115
- };
116
-
117
- /**
118
- * Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.
119
- *
120
- * The hook listens to custom events on the active agent, stores interrupt payloads per run,
121
- * and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
122
- * execution with user-provided data.
123
- *
124
- * - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
125
- * - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
126
- *
127
- * `event.value` is typed as `any` since the interrupt payload shape depends on your agent.
128
- * Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.
129
- *
130
- * @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
131
- * @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
132
- * @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
133
- * Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
134
- * either the handler's resolved return value or `null` (including when no handler is provided,
135
- * when filtering skips the interrupt, or when handler execution fails).
136
- *
137
- * @example
138
- * ```tsx
139
- * import { useInterrupt } from "@copilotkit/react-core/v2";
140
- *
141
- * function InterruptUI() {
142
- * useInterrupt({
143
- * render: ({ event, resolve }) => (
144
- * <div>
145
- * <p>{event.value.question}</p>
146
- * <button onClick={() => resolve({ approved: true })}>Approve</button>
147
- * <button onClick={() => resolve({ approved: false })}>Reject</button>
148
- * </div>
149
- * ),
150
- * });
151
- *
152
- * return null;
153
- * }
154
- * ```
155
- *
156
- * @example
157
- * ```tsx
158
- * import { useInterrupt } from "@copilotkit/react-core/v2";
159
- *
160
- * function CustomPanel() {
161
- * const interruptElement = useInterrupt({
162
- * renderInChat: false,
163
- * enabled: (event) => event.value.startsWith("approval:"),
164
- * handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
165
- * render: ({ event, result, resolve }) => (
166
- * <aside>
167
- * <strong>{result?.label ?? ""}</strong>
168
- * <button onClick={() => resolve({ value: event.value })}>Continue</button>
169
- * </aside>
170
- * ),
171
- * });
172
- *
173
- * return <>{interruptElement}</>;
174
- * }
175
- * ```
176
- */
177
- /* eslint-disable @typescript-eslint/no-explicit-any */
178
- export function useInterrupt<
179
- TResult = never,
180
- TRenderInChat extends InterruptRenderInChat = undefined,
181
- >(
182
- config: UseInterruptConfig<any, TResult, TRenderInChat>,
183
- ): UseInterruptReturn<TRenderInChat> {
184
- /* eslint-enable @typescript-eslint/no-explicit-any */
185
- const { copilotkit } = useCopilotKit();
186
- const { agent } = useAgent({ agentId: config.agentId });
187
- const [pendingEvent, setPendingEvent] = useState<InterruptEvent | null>(null);
188
- const pendingEventRef = useRef(pendingEvent);
189
- pendingEventRef.current = pendingEvent;
190
- const [handlerResult, setHandlerResult] =
191
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
- useState<InterruptResult<any, TResult>>(null);
193
-
194
- useEffect(() => {
195
- let localInterrupt: InterruptEvent | null = null;
196
-
197
- const subscription = agent.subscribe({
198
- onCustomEvent: ({ event }) => {
199
- if (event.name === INTERRUPT_EVENT_NAME) {
200
- localInterrupt = { name: event.name, value: event.value };
201
- }
202
- },
203
- onRunStartedEvent: () => {
204
- localInterrupt = null;
205
- setPendingEvent(null);
206
- },
207
- onRunFinalized: () => {
208
- if (localInterrupt) {
209
- setPendingEvent(localInterrupt);
210
- localInterrupt = null;
211
- }
212
- },
213
- onRunFailed: () => {
214
- localInterrupt = null;
215
- },
216
- });
217
-
218
- return () => subscription.unsubscribe();
219
- }, [agent]);
220
-
221
- const resolve = useCallback(
222
- (response: unknown) => {
223
- setPendingEvent(null);
224
- copilotkit.runAgent({
225
- agent,
226
- forwardedProps: {
227
- command: {
228
- resume: response,
229
- interruptEvent: pendingEventRef.current?.value,
230
- },
231
- },
232
- });
233
- },
234
- [agent, copilotkit],
235
- );
236
-
237
- useEffect(() => {
238
- // No interrupt to process — reset any stale handler result from a previous interrupt
239
- if (!pendingEvent) {
240
- setHandlerResult(null);
241
- return;
242
- }
243
- // Interrupt exists but the consumer's filter rejects it — treat as no-op
244
- if (config.enabled && !config.enabled(pendingEvent)) {
245
- setHandlerResult(null);
246
- return;
247
- }
248
- const handler = config.handler;
249
- // No handler provided — skip straight to rendering with a null result
250
- if (!handler) {
251
- setHandlerResult(null);
252
- return;
253
- }
254
-
255
- let cancelled = false;
256
- const maybePromise = handler({
257
- event: pendingEvent,
258
- resolve,
259
- });
260
-
261
- // If the handler returns a promise/thenable, wait for resolution before setting result.
262
- if (isPromiseLike(maybePromise)) {
263
- Promise.resolve(maybePromise)
264
- .then((resolved) => {
265
- if (!cancelled) setHandlerResult(resolved);
266
- })
267
- .catch(() => {
268
- if (!cancelled) setHandlerResult(null);
269
- });
270
- } else {
271
- setHandlerResult(maybePromise);
272
- }
273
-
274
- return () => {
275
- cancelled = true;
276
- };
277
- // eslint-disable-next-line react-hooks/exhaustive-deps
278
- }, [pendingEvent, config.enabled, config.handler, resolve]);
279
-
280
- const element = useMemo(() => {
281
- if (!pendingEvent) return null;
282
- if (config.enabled && !config.enabled(pendingEvent)) return null;
283
-
284
- return config.render({
285
- event: pendingEvent,
286
- result: handlerResult,
287
- resolve,
288
- });
289
- // eslint-disable-next-line react-hooks/exhaustive-deps
290
- }, [pendingEvent, handlerResult, config.enabled, config.render, resolve]);
291
-
292
- // Publish to core for in-chat rendering
293
- useEffect(() => {
294
- if (config.renderInChat === false) return;
295
- copilotkit.setInterruptElement(element);
296
- return () => copilotkit.setInterruptElement(null);
297
- }, [element, config.renderInChat, copilotkit]);
298
-
299
- // Only return element when rendering outside chat
300
- if (config.renderInChat === false) {
301
- return element as UseInterruptReturn<TRenderInChat>;
302
- }
303
-
304
- return undefined as UseInterruptReturn<TRenderInChat>;
305
- }