@copilotkit/react-core 1.57.3 → 1.58.0-canary.thread-id-propagation

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 (292) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{copilotkit-CtXcs1ea.cjs → copilotkit-B4ouY7qC.cjs} +14 -3
  3. package/dist/copilotkit-B4ouY7qC.cjs.map +1 -0
  4. package/dist/copilotkit-BK9CVq9A.d.cts.map +1 -1
  5. package/dist/{copilotkit-CC8DjOiC.mjs → copilotkit-L4mM_JqG.mjs} +14 -3
  6. package/dist/copilotkit-L4mM_JqG.mjs.map +1 -0
  7. package/dist/copilotkit-WlmeVijs.d.mts.map +1 -1
  8. package/dist/index.cjs +3 -77
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +2 -2
  11. package/dist/index.d.mts +2 -2
  12. package/dist/index.mjs +3 -77
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/index.umd.js +15 -78
  15. package/dist/index.umd.js.map +1 -1
  16. package/dist/v2/headless.cjs +11 -0
  17. package/dist/v2/headless.cjs.map +1 -1
  18. package/dist/v2/headless.d.cts.map +1 -1
  19. package/dist/v2/headless.d.mts.map +1 -1
  20. package/dist/v2/headless.mjs +11 -0
  21. package/dist/v2/headless.mjs.map +1 -1
  22. package/dist/v2/index.cjs +1 -1
  23. package/dist/v2/index.mjs +1 -1
  24. package/dist/v2/index.umd.js +13 -2
  25. package/dist/v2/index.umd.js.map +1 -1
  26. package/package.json +12 -13
  27. package/skills/react-core/SKILL.md +108 -0
  28. package/skills/react-core/references/agent-access.md +288 -0
  29. package/skills/react-core/references/attachments.md +291 -0
  30. package/skills/react-core/references/capabilities.md +138 -0
  31. package/skills/react-core/references/chat-components.md +221 -0
  32. package/skills/react-core/references/client-side-tools.md +358 -0
  33. package/skills/react-core/references/custom-message-renderers.md +226 -0
  34. package/skills/react-core/references/debug-mode.md +153 -0
  35. package/skills/react-core/references/human-in-the-loop.md +312 -0
  36. package/skills/react-core/references/provider-setup.md +326 -0
  37. package/skills/react-core/references/rendering-activity-messages.md +207 -0
  38. package/skills/react-core/references/rendering-tool-calls.md +319 -0
  39. package/skills/react-core/references/suggestions.md +211 -0
  40. package/skills/react-core/references/switching-agents-recipes.md +160 -0
  41. package/skills/react-core/references/switching-agents.md +231 -0
  42. package/skills/react-core/references/threads.md +226 -0
  43. package/.attw.json +0 -3
  44. package/CHANGELOG.md +0 -5043
  45. package/dist/copilotkit-CC8DjOiC.mjs.map +0 -1
  46. package/dist/copilotkit-CtXcs1ea.cjs.map +0 -1
  47. package/scripts/scope-preflight.mjs +0 -100
  48. package/src/components/CopilotListeners.tsx +0 -137
  49. package/src/components/__tests__/CopilotListeners.test.tsx +0 -38
  50. package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +0 -92
  51. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -77
  52. package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +0 -70
  53. package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +0 -107
  54. package/src/components/copilot-provider/copilot-messages.tsx +0 -314
  55. package/src/components/copilot-provider/copilotkit-props.tsx +0 -214
  56. package/src/components/copilot-provider/copilotkit.tsx +0 -853
  57. package/src/components/copilot-provider/index.ts +0 -3
  58. package/src/components/dev-console/console-trigger.tsx +0 -283
  59. package/src/components/dev-console/developer-console-modal.tsx +0 -1016
  60. package/src/components/dev-console/icons.tsx +0 -106
  61. package/src/components/error-boundary/error-boundary.tsx +0 -99
  62. package/src/components/error-boundary/error-utils.tsx +0 -105
  63. package/src/components/index.ts +0 -1
  64. package/src/components/toast/exclamation-mark-icon.tsx +0 -27
  65. package/src/components/toast/toast-provider.tsx +0 -448
  66. package/src/components/usage-banner.tsx +0 -266
  67. package/src/context/__tests__/threads-context.test.tsx +0 -141
  68. package/src/context/coagent-state-renders-context.tsx +0 -89
  69. package/src/context/copilot-context.tsx +0 -365
  70. package/src/context/copilot-messages-context.tsx +0 -35
  71. package/src/context/index.ts +0 -22
  72. package/src/context/threads-context.tsx +0 -69
  73. package/src/hooks/__tests__/use-coagent-config.test.ts +0 -352
  74. package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +0 -107
  75. package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +0 -1209
  76. package/src/hooks/__tests__/use-coagent-state-render.test.tsx +0 -356
  77. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +0 -241
  78. package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -72
  79. package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +0 -102
  80. package/src/hooks/index.ts +0 -33
  81. package/src/hooks/use-agent-nodename.ts +0 -33
  82. package/src/hooks/use-coagent-state-render-bridge.helpers.ts +0 -345
  83. package/src/hooks/use-coagent-state-render-bridge.tsx +0 -222
  84. package/src/hooks/use-coagent-state-render-registry.ts +0 -230
  85. package/src/hooks/use-coagent-state-render.ts +0 -163
  86. package/src/hooks/use-coagent.ts +0 -377
  87. package/src/hooks/use-configure-chat-suggestions.tsx +0 -96
  88. package/src/hooks/use-copilot-action.ts +0 -245
  89. package/src/hooks/use-copilot-additional-instructions.ts +0 -98
  90. package/src/hooks/use-copilot-authenticated-action.ts +0 -73
  91. package/src/hooks/use-copilot-chat-headless_c.ts +0 -264
  92. package/src/hooks/use-copilot-chat-suggestions.tsx +0 -134
  93. package/src/hooks/use-copilot-chat.ts +0 -132
  94. package/src/hooks/use-copilot-chat_internal.ts +0 -875
  95. package/src/hooks/use-copilot-readable.ts +0 -135
  96. package/src/hooks/use-copilot-runtime-client.ts +0 -178
  97. package/src/hooks/use-default-tool.ts +0 -13
  98. package/src/hooks/use-flat-category-store.ts +0 -109
  99. package/src/hooks/use-frontend-tool.ts +0 -113
  100. package/src/hooks/use-human-in-the-loop.ts +0 -138
  101. package/src/hooks/use-langgraph-interrupt.ts +0 -103
  102. package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
  103. package/src/hooks/use-make-copilot-document-readable.ts +0 -30
  104. package/src/hooks/use-render-tool-call.ts +0 -89
  105. package/src/hooks/use-tree.ts +0 -222
  106. package/src/index.tsx +0 -7
  107. package/src/lib/copilot-task.ts +0 -215
  108. package/src/lib/index.ts +0 -1
  109. package/src/lib/status-checker.ts +0 -67
  110. package/src/setupTests.ts +0 -37
  111. package/src/test-helpers/copilot-context.ts +0 -91
  112. package/src/types/chat-suggestion-configuration.ts +0 -23
  113. package/src/types/coagent-action.ts +0 -35
  114. package/src/types/coagent-state.ts +0 -13
  115. package/src/types/crew.ts +0 -89
  116. package/src/types/document-pointer.ts +0 -7
  117. package/src/types/frontend-action.ts +0 -213
  118. package/src/types/index.ts +0 -17
  119. package/src/types/interrupt-action.ts +0 -58
  120. package/src/types/system-message.ts +0 -4
  121. package/src/utils/dev-console.ts +0 -19
  122. package/src/utils/index.ts +0 -2
  123. package/src/utils/suggestions-constants.ts +0 -8
  124. package/src/utils/utils.test.ts +0 -7
  125. package/src/utils/utils.ts +0 -6
  126. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +0 -240
  127. package/src/v2/__tests__/globalSetup.ts +0 -14
  128. package/src/v2/__tests__/setup.ts +0 -93
  129. package/src/v2/__tests__/utils/test-helpers.tsx +0 -570
  130. package/src/v2/a2ui/A2UICatalogContext.tsx +0 -79
  131. package/src/v2/a2ui/A2UIMessageRenderer.tsx +0 -294
  132. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +0 -290
  133. package/src/v2/components/CopilotKitInspector.tsx +0 -52
  134. package/src/v2/components/MCPAppsActivityRenderer.tsx +0 -815
  135. package/src/v2/components/OpenGenerativeUIRenderer.tsx +0 -598
  136. package/src/v2/components/WildcardToolCallRender.tsx +0 -86
  137. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +0 -665
  138. package/src/v2/components/chat/CopilotChat.tsx +0 -664
  139. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +0 -393
  140. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +0 -374
  141. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +0 -159
  142. package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +0 -350
  143. package/src/v2/components/chat/CopilotChatInput.tsx +0 -1412
  144. package/src/v2/components/chat/CopilotChatMessageView.tsx +0 -716
  145. package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +0 -265
  146. package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +0 -59
  147. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +0 -134
  148. package/src/v2/components/chat/CopilotChatToggleButton.tsx +0 -171
  149. package/src/v2/components/chat/CopilotChatToolCallsView.tsx +0 -40
  150. package/src/v2/components/chat/CopilotChatUserMessage.tsx +0 -445
  151. package/src/v2/components/chat/CopilotChatView.tsx +0 -890
  152. package/src/v2/components/chat/CopilotModalHeader.tsx +0 -129
  153. package/src/v2/components/chat/CopilotPopup.tsx +0 -81
  154. package/src/v2/components/chat/CopilotPopupView.tsx +0 -317
  155. package/src/v2/components/chat/CopilotSidebar.tsx +0 -80
  156. package/src/v2/components/chat/CopilotSidebarView.tsx +0 -269
  157. package/src/v2/components/chat/Lightbox.tsx +0 -103
  158. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +0 -66
  159. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +0 -168
  160. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +0 -1239
  161. package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +0 -73
  162. package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +0 -432
  163. package/src/v2/components/chat/__tests__/CopilotChat.suggestionsAlways.test.tsx +0 -183
  164. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +0 -184
  165. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +0 -649
  166. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +0 -624
  167. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -702
  168. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +0 -72
  169. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +0 -241
  170. package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +0 -107
  171. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +0 -929
  172. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +0 -1567
  173. package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +0 -1004
  174. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +0 -279
  175. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +0 -336
  176. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +0 -249
  177. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +0 -530
  178. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +0 -785
  179. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +0 -2416
  180. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +0 -621
  181. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +0 -56
  182. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.tsx +0 -264
  183. package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +0 -853
  184. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +0 -94
  185. package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +0 -1050
  186. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +0 -484
  187. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +0 -612
  188. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +0 -159
  189. package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +0 -502
  190. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +0 -1068
  191. package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +0 -589
  192. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +0 -403
  193. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -137
  194. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -37
  195. package/src/v2/components/chat/__tests__/setup.ts +0 -1
  196. package/src/v2/components/chat/index.ts +0 -90
  197. package/src/v2/components/chat/last-user-message-context.ts +0 -21
  198. package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
  199. package/src/v2/components/chat/scroll-element-context.ts +0 -13
  200. package/src/v2/components/index.ts +0 -8
  201. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -286
  202. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -464
  203. package/src/v2/components/intelligence-indicator/index.ts +0 -2
  204. package/src/v2/components/license-warning-banner.tsx +0 -217
  205. package/src/v2/components/ui/button.tsx +0 -124
  206. package/src/v2/components/ui/dropdown-menu.tsx +0 -258
  207. package/src/v2/components/ui/tooltip.tsx +0 -60
  208. package/src/v2/context.ts +0 -62
  209. package/src/v2/headless.ts +0 -64
  210. package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +0 -152
  211. package/src/v2/hooks/__tests__/standard-schema.test.tsx +0 -282
  212. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +0 -140
  213. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +0 -401
  214. package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +0 -44
  215. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +0 -211
  216. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +0 -1029
  217. package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +0 -159
  218. package/src/v2/hooks/__tests__/use-attachments.test.tsx +0 -169
  219. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +0 -76
  220. package/src/v2/hooks/__tests__/use-component.test.tsx +0 -126
  221. package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +0 -696
  222. package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +0 -153
  223. package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -167
  224. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +0 -2148
  225. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +0 -1261
  226. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +0 -397
  227. package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +0 -56
  228. package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +0 -192
  229. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +0 -219
  230. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +0 -55
  231. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +0 -259
  232. package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +0 -524
  233. package/src/v2/hooks/__tests__/use-threads.test.tsx +0 -757
  234. package/src/v2/hooks/__tests__/zod-regression.test.tsx +0 -311
  235. package/src/v2/hooks/index.ts +0 -24
  236. package/src/v2/hooks/use-agent-context.tsx +0 -45
  237. package/src/v2/hooks/use-agent.tsx +0 -227
  238. package/src/v2/hooks/use-attachments.tsx +0 -269
  239. package/src/v2/hooks/use-capabilities.tsx +0 -25
  240. package/src/v2/hooks/use-component.tsx +0 -91
  241. package/src/v2/hooks/use-configure-suggestions.tsx +0 -236
  242. package/src/v2/hooks/use-default-render-tool.tsx +0 -271
  243. package/src/v2/hooks/use-frontend-tool.tsx +0 -46
  244. package/src/v2/hooks/use-human-in-the-loop.tsx +0 -81
  245. package/src/v2/hooks/use-interrupt.tsx +0 -305
  246. package/src/v2/hooks/use-keyboard-height.tsx +0 -67
  247. package/src/v2/hooks/use-pin-to-send.ts +0 -94
  248. package/src/v2/hooks/use-render-activity-message.tsx +0 -72
  249. package/src/v2/hooks/use-render-custom-messages.tsx +0 -93
  250. package/src/v2/hooks/use-render-tool-call.tsx +0 -208
  251. package/src/v2/hooks/use-render-tool.tsx +0 -184
  252. package/src/v2/hooks/use-suggestions.tsx +0 -91
  253. package/src/v2/hooks/use-threads.tsx +0 -325
  254. package/src/v2/hooks/useKatexStyles.ts +0 -27
  255. package/src/v2/index.css +0 -1
  256. package/src/v2/index.ts +0 -27
  257. package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +0 -495
  258. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -112
  259. package/src/v2/lib/__tests__/renderSlot.test.tsx +0 -588
  260. package/src/v2/lib/__tests__/slots.test.ts +0 -56
  261. package/src/v2/lib/processPartialHtml.ts +0 -45
  262. package/src/v2/lib/react-core.ts +0 -156
  263. package/src/v2/lib/slots.tsx +0 -184
  264. package/src/v2/lib/transcription-client.ts +0 -184
  265. package/src/v2/lib/utils.ts +0 -8
  266. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +0 -196
  267. package/src/v2/providers/CopilotKitProvider.tsx +0 -800
  268. package/src/v2/providers/SandboxFunctionsContext.ts +0 -10
  269. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +0 -652
  270. package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +0 -101
  271. package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +0 -69
  272. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +0 -881
  273. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +0 -198
  274. package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +0 -740
  275. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +0 -713
  276. package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -294
  277. package/src/v2/providers/index.ts +0 -21
  278. package/src/v2/styles/globals.css +0 -349
  279. package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +0 -525
  280. package/src/v2/types/defineToolCallRenderer.ts +0 -68
  281. package/src/v2/types/frontend-tool.ts +0 -8
  282. package/src/v2/types/human-in-the-loop.ts +0 -33
  283. package/src/v2/types/index.ts +0 -8
  284. package/src/v2/types/interrupt.ts +0 -15
  285. package/src/v2/types/react-activity-message-renderer.ts +0 -27
  286. package/src/v2/types/react-custom-message-renderer.ts +0 -17
  287. package/src/v2/types/react-tool-call-renderer.ts +0 -35
  288. package/src/v2/types/sandbox-function.ts +0 -11
  289. package/tsconfig.json +0 -8
  290. package/tsdown.config.ts +0 -193
  291. package/typedoc.json +0 -4
  292. 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
- }