@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,67 +0,0 @@
1
- import { useState, useEffect } from "react";
2
-
3
- export interface KeyboardState {
4
- isKeyboardOpen: boolean;
5
- keyboardHeight: number;
6
- availableHeight: number;
7
- viewportHeight: number;
8
- }
9
-
10
- /**
11
- * Hook to detect mobile keyboard appearance and calculate available viewport height.
12
- * Uses the Visual Viewport API to track keyboard state on mobile devices.
13
- *
14
- * @returns KeyboardState object with keyboard information
15
- */
16
- export function useKeyboardHeight(): KeyboardState {
17
- const [keyboardState, setKeyboardState] = useState<KeyboardState>({
18
- isKeyboardOpen: false,
19
- keyboardHeight: 0,
20
- availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
21
- viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0,
22
- });
23
-
24
- useEffect(() => {
25
- if (typeof window === "undefined") {
26
- return;
27
- }
28
-
29
- // Check if Visual Viewport API is available
30
- const visualViewport = window.visualViewport;
31
- if (!visualViewport) {
32
- return;
33
- }
34
-
35
- const updateKeyboardState = () => {
36
- const layoutHeight = window.innerHeight;
37
- const visualHeight = visualViewport.height;
38
-
39
- // Calculate keyboard height (difference between layout and visual viewport)
40
- const keyboardHeight = Math.max(0, layoutHeight - visualHeight);
41
-
42
- // Keyboard is considered open if the height difference is significant (> 150px)
43
- const isKeyboardOpen = keyboardHeight > 150;
44
-
45
- setKeyboardState({
46
- isKeyboardOpen,
47
- keyboardHeight,
48
- availableHeight: visualHeight,
49
- viewportHeight: layoutHeight,
50
- });
51
- };
52
-
53
- // Initial state
54
- updateKeyboardState();
55
-
56
- // Listen for viewport changes
57
- visualViewport.addEventListener("resize", updateKeyboardState);
58
- visualViewport.addEventListener("scroll", updateKeyboardState);
59
-
60
- return () => {
61
- visualViewport.removeEventListener("resize", updateKeyboardState);
62
- visualViewport.removeEventListener("scroll", updateKeyboardState);
63
- };
64
- }, []);
65
-
66
- return keyboardState;
67
- }
@@ -1,94 +0,0 @@
1
- import { useContext, useEffect, useRef } from "react";
2
- import { LastUserMessageContext } from "../components/chat/last-user-message-context";
3
-
4
- export type UsePinToSendOptions = {
5
- scrollRef: React.RefObject<HTMLElement | null>;
6
- contentRef: React.RefObject<HTMLElement | null>;
7
- spacerRef: React.RefObject<HTMLElement | null>;
8
- topOffset?: number;
9
- };
10
-
11
- export function usePinToSend({
12
- scrollRef,
13
- contentRef,
14
- spacerRef,
15
- topOffset = 16,
16
- }: UsePinToSendOptions): void {
17
- const { id, sendNonce } = useContext(LastUserMessageContext);
18
- const lastNonceRef = useRef<number>(-1);
19
- const currentSpacerHeightRef = useRef<number>(0);
20
-
21
- useEffect(() => {
22
- if (sendNonce === lastNonceRef.current) return;
23
- lastNonceRef.current = sendNonce;
24
-
25
- if (!id) return;
26
- const scrollEl = scrollRef.current;
27
- const contentEl = contentRef.current;
28
- const spacerEl = spacerRef.current;
29
- if (!scrollEl || !contentEl || !spacerEl) return;
30
-
31
- const escaped =
32
- typeof CSS !== "undefined" && CSS.escape
33
- ? CSS.escape(id)
34
- : id.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "\\$&");
35
- const targetEl = contentEl.querySelector<HTMLElement>(
36
- `[data-message-id="${escaped}"]`,
37
- );
38
- if (!targetEl) return;
39
-
40
- // The target message's element has a top padding (e.g. `pt-10`) that
41
- // creates breathing room above the visible bubble. When we "anchor at
42
- // the top", we mean anchor the *bubble*, not the element's padded box.
43
- // So we scroll past the padding (it goes above the viewport, hiding
44
- // whatever was above the element too — including the previous message's
45
- // trailing copy button).
46
- const viewportHeight = scrollEl.clientHeight;
47
- const userMessageHeight = targetEl.getBoundingClientRect().height;
48
- const paddingTop = parseFloat(getComputedStyle(targetEl).paddingTop) || 0;
49
- const bubbleHeight = Math.max(0, userMessageHeight - paddingTop);
50
- const spacerHeight = Math.max(0, viewportHeight - bubbleHeight - topOffset);
51
-
52
- spacerEl.style.height = `${spacerHeight}px`;
53
- currentSpacerHeightRef.current = spacerHeight;
54
-
55
- const raf = requestAnimationFrame(() => {
56
- // Scroll so the BUBBLE is `topOffset` from the viewport top — the
57
- // padding above the bubble ends up scrolled off-screen.
58
- const targetTop =
59
- computeOffsetTop(targetEl, scrollEl) + paddingTop - topOffset;
60
- scrollEl.scrollTo({ top: Math.max(0, targetTop), behavior: "smooth" });
61
- });
62
-
63
- // Shrink-only ResizeObserver: as the assistant response grows below the
64
- // anchored user message, collapse the spacer by the same amount so total
65
- // scrollable space below the bubble stays constant (and the bubble stays
66
- // pinned). Never grow the spacer after initial sizing.
67
- const ro = new ResizeObserver(() => {
68
- if (!contentEl || !spacerEl || !scrollEl) return;
69
- const contentHeight = contentEl.getBoundingClientRect().height;
70
- const targetOffsetWithinContent = computeOffsetTop(targetEl, contentEl);
71
- const consumedBelow =
72
- contentHeight - targetOffsetWithinContent - userMessageHeight;
73
- const remaining = Math.max(0, spacerHeight - consumedBelow);
74
- if (remaining < currentSpacerHeightRef.current) {
75
- spacerEl.style.height = `${remaining}px`;
76
- currentSpacerHeightRef.current = remaining;
77
- }
78
- });
79
- ro.observe(contentEl);
80
-
81
- return () => {
82
- cancelAnimationFrame(raf);
83
- ro.disconnect();
84
- };
85
- }, [id, sendNonce, scrollRef, contentRef, spacerRef, topOffset]);
86
- }
87
-
88
- // Compute the offset of el relative to stopAt, accounting for stopAt's current scrollTop.
89
- // Uses getBoundingClientRect so it works regardless of CSS positioning (including position:static).
90
- function computeOffsetTop(el: HTMLElement, stopAt: HTMLElement): number {
91
- const elRect = el.getBoundingClientRect();
92
- const stopRect = stopAt.getBoundingClientRect();
93
- return elRect.top - stopRect.top + stopAt.scrollTop;
94
- }
@@ -1,72 +0,0 @@
1
- import { ActivityMessage } from "@ag-ui/core";
2
- import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
3
- import { useCopilotKit, useCopilotChatConfiguration } from "../providers";
4
- import { useCallback, useMemo } from "react";
5
- import { ReactActivityMessageRenderer } from "../types";
6
-
7
- export function useRenderActivityMessage() {
8
- const { copilotkit } = useCopilotKit();
9
- const agentId = useCopilotChatConfiguration()?.agentId ?? DEFAULT_AGENT_ID;
10
-
11
- const renderers = copilotkit.renderActivityMessages;
12
-
13
- // Find the renderer for a given activity type
14
- const findRenderer = useCallback(
15
- (activityType: string): ReactActivityMessageRenderer<unknown> | null => {
16
- if (!renderers.length) {
17
- return null;
18
- }
19
-
20
- const matches = renderers.filter(
21
- (renderer) => renderer.activityType === activityType,
22
- );
23
-
24
- return (
25
- matches.find((candidate) => candidate.agentId === agentId) ??
26
- matches.find((candidate) => candidate.agentId === undefined) ??
27
- renderers.find((candidate) => candidate.activityType === "*") ??
28
- null
29
- );
30
- },
31
- [agentId, renderers],
32
- );
33
-
34
- const renderActivityMessage = useCallback(
35
- (message: ActivityMessage): React.ReactElement | null => {
36
- const renderer = findRenderer(message.activityType);
37
-
38
- if (!renderer) {
39
- return null;
40
- }
41
-
42
- const parseResult = renderer.content.safeParse(message.content);
43
-
44
- if (!parseResult.success) {
45
- console.warn(
46
- `Failed to parse content for activity message '${message.activityType}':`,
47
- parseResult.error,
48
- );
49
- return null;
50
- }
51
-
52
- const Component = renderer.render;
53
- const agent = copilotkit.getAgent(agentId);
54
-
55
- return (
56
- <Component
57
- key={message.id}
58
- activityType={message.activityType}
59
- content={parseResult.data}
60
- message={message}
61
- agent={agent}
62
- />
63
- );
64
- },
65
- [agentId, copilotkit, findRenderer],
66
- );
67
-
68
- return useMemo(
69
- () => ({ renderActivityMessage, findRenderer }),
70
- [renderActivityMessage, findRenderer],
71
- );
72
- }
@@ -1,93 +0,0 @@
1
- import { useCopilotChatConfiguration, useCopilotKit } from "../providers";
2
- import { ReactCustomMessageRendererPosition } from "../types/react-custom-message-renderer";
3
- import { Message } from "@ag-ui/core";
4
-
5
- interface UseRenderCustomMessagesParams {
6
- message: Message;
7
- position: ReactCustomMessageRendererPosition;
8
- }
9
-
10
- export function useRenderCustomMessages() {
11
- const { copilotkit } = useCopilotKit();
12
- const config = useCopilotChatConfiguration();
13
-
14
- if (!config) {
15
- return null;
16
- }
17
-
18
- const { agentId, threadId } = config;
19
-
20
- const customMessageRenderers = copilotkit.renderCustomMessages
21
- .filter(
22
- (renderer) =>
23
- renderer.agentId === undefined || renderer.agentId === agentId,
24
- )
25
- .sort((a, b) => {
26
- const aHasAgent = a.agentId !== undefined;
27
- const bHasAgent = b.agentId !== undefined;
28
- if (aHasAgent === bHasAgent) return 0;
29
- return aHasAgent ? -1 : 1;
30
- });
31
-
32
- return function (params: UseRenderCustomMessagesParams) {
33
- if (!customMessageRenderers.length) {
34
- return null;
35
- }
36
- const { message, position } = params;
37
- const resolvedRunId =
38
- copilotkit.getRunIdForMessage(agentId, threadId, message.id) ??
39
- copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
40
- const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
41
- const agent = copilotkit.getAgent(agentId);
42
- if (!agent) {
43
- return null;
44
- }
45
-
46
- const messagesIdsInRun = resolvedRunId
47
- ? agent.messages
48
- .filter(
49
- (msg) =>
50
- copilotkit.getRunIdForMessage(agentId, threadId, msg.id) ===
51
- resolvedRunId,
52
- )
53
- .map((msg) => msg.id)
54
- : [message.id];
55
-
56
- const rawMessageIndex = agent.messages.findIndex(
57
- (msg) => msg.id === message.id,
58
- );
59
- const messageIndex = rawMessageIndex >= 0 ? rawMessageIndex : 0;
60
- const messageIndexInRun = resolvedRunId
61
- ? Math.max(messagesIdsInRun.indexOf(message.id), 0)
62
- : 0;
63
- const numberOfMessagesInRun = resolvedRunId ? messagesIdsInRun.length : 1;
64
- const stateSnapshot = resolvedRunId
65
- ? copilotkit.getStateByRun(agentId, threadId, resolvedRunId)
66
- : undefined;
67
-
68
- let result = null;
69
- for (const renderer of customMessageRenderers) {
70
- if (!renderer.render) {
71
- continue;
72
- }
73
- const Component = renderer.render;
74
- result = (
75
- <Component
76
- key={`${runId}-${message.id}-${position}`}
77
- message={message}
78
- position={position}
79
- runId={runId}
80
- messageIndex={messageIndex}
81
- messageIndexInRun={messageIndexInRun}
82
- numberOfMessagesInRun={numberOfMessagesInRun}
83
- agentId={agentId}
84
- stateSnapshot={stateSnapshot}
85
- />
86
- );
87
- if (result) {
88
- break;
89
- }
90
- }
91
- return result;
92
- };
93
- }
@@ -1,208 +0,0 @@
1
- import React, { useCallback, useMemo, useSyncExternalStore } from "react";
2
- import { ToolCall, ToolMessage } from "@ag-ui/core";
3
- import { ToolCallStatus } from "@copilotkit/core";
4
- import { useCopilotKit } from "../context";
5
- import { useCopilotChatConfiguration } from "../providers/CopilotChatConfigurationProvider";
6
- import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
7
- import { partialJSONParse } from "@copilotkit/shared";
8
- import { ReactToolCallRenderer } from "../types/react-tool-call-renderer";
9
- import { DefaultToolCallRenderer } from "./use-default-render-tool";
10
-
11
- export interface UseRenderToolCallProps {
12
- toolCall: ToolCall;
13
- toolMessage?: ToolMessage;
14
- }
15
-
16
- /**
17
- * Props for the memoized ToolCallRenderer component
18
- */
19
- interface ToolCallRendererProps {
20
- toolCall: ToolCall;
21
- toolMessage?: ToolMessage;
22
- RenderComponent: ReactToolCallRenderer<unknown>["render"];
23
- isExecuting: boolean;
24
- }
25
-
26
- /**
27
- * Memoized component that renders a single tool call.
28
- * This prevents unnecessary re-renders when parent components update
29
- * but the tool call data hasn't changed.
30
- */
31
- const ToolCallRenderer = React.memo(
32
- function ToolCallRenderer({
33
- toolCall,
34
- toolMessage,
35
- RenderComponent,
36
- isExecuting,
37
- }: ToolCallRendererProps) {
38
- // Memoize args based on the arguments string to maintain stable reference
39
- const args = useMemo(
40
- () => partialJSONParse(toolCall.function.arguments),
41
- [toolCall.function.arguments],
42
- );
43
-
44
- const toolName = toolCall.function.name;
45
-
46
- // Render based on status to preserve discriminated union type inference
47
- if (toolMessage) {
48
- return (
49
- <RenderComponent
50
- name={toolName}
51
- toolCallId={toolCall.id}
52
- args={args}
53
- status={ToolCallStatus.Complete}
54
- result={toolMessage.content}
55
- />
56
- );
57
- } else if (isExecuting) {
58
- return (
59
- <RenderComponent
60
- name={toolName}
61
- toolCallId={toolCall.id}
62
- args={args}
63
- status={ToolCallStatus.Executing}
64
- result={undefined}
65
- />
66
- );
67
- } else {
68
- return (
69
- <RenderComponent
70
- name={toolName}
71
- toolCallId={toolCall.id}
72
- args={args}
73
- status={ToolCallStatus.InProgress}
74
- result={undefined}
75
- />
76
- );
77
- }
78
- },
79
- // Custom comparison function to prevent re-renders when tool call data hasn't changed
80
- (prevProps, nextProps) => {
81
- // Compare tool call identity and content
82
- if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
83
- if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name)
84
- return false;
85
- if (
86
- prevProps.toolCall.function.arguments !==
87
- nextProps.toolCall.function.arguments
88
- )
89
- return false;
90
-
91
- // Compare tool message (result)
92
- const prevResult = prevProps.toolMessage?.content;
93
- const nextResult = nextProps.toolMessage?.content;
94
- if (prevResult !== nextResult) return false;
95
-
96
- // Compare executing state
97
- if (prevProps.isExecuting !== nextProps.isExecuting) return false;
98
-
99
- // Compare render component reference
100
- if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
101
-
102
- return true;
103
- },
104
- );
105
-
106
- /**
107
- * Hook that returns a function to render tool calls based on the render functions
108
- * defined in CopilotKitProvider.
109
- *
110
- * @returns A function that takes a tool call and optional tool message and returns the rendered component
111
- */
112
- export function useRenderToolCall() {
113
- const { copilotkit, executingToolCallIds } = useCopilotKit();
114
- const config = useCopilotChatConfiguration();
115
- const agentId = config?.agentId ?? DEFAULT_AGENT_ID;
116
-
117
- // Subscribe to render tool calls changes using useSyncExternalStore
118
- // This ensures we always have the latest value, even if subscriptions run in any order
119
- const renderToolCalls = useSyncExternalStore(
120
- (callback) => {
121
- return copilotkit.subscribe({
122
- onRenderToolCallsChanged: callback,
123
- }).unsubscribe;
124
- },
125
- () => copilotkit.renderToolCalls,
126
- () => copilotkit.renderToolCalls,
127
- );
128
-
129
- // Note: executingToolCallIds is now provided by CopilotKitProvider context.
130
- // This is critical for HITL reconnection: when connecting to a thread with
131
- // pending tool calls, the onToolExecutionStart event fires before child components
132
- // mount. By tracking at the provider level, the executing state is already
133
- // available when this hook first runs.
134
-
135
- const renderToolCall = useCallback(
136
- ({
137
- toolCall,
138
- toolMessage,
139
- }: UseRenderToolCallProps): React.ReactElement | null => {
140
- // Find the render config for this tool call by name
141
- // For rendering, we show all tool calls regardless of agentId
142
- // The agentId scoping only affects handler execution (in core)
143
- // Priority order:
144
- // 1. Exact match by name (prefer agent-specific if multiple exist)
145
- // 2. Wildcard (*) renderer
146
- const exactMatches = renderToolCalls.filter(
147
- (rc) => rc.name === toolCall.function.name,
148
- );
149
-
150
- // If multiple renderers with same name exist, prefer the one matching our agentId
151
- const renderConfig =
152
- exactMatches.find((rc) => rc.agentId === agentId) ||
153
- exactMatches.find((rc) => !rc.agentId) ||
154
- exactMatches[0] ||
155
- renderToolCalls.find((rc) => rc.name === "*");
156
-
157
- // Fall back to the framework's built-in default tool-call renderer
158
- // when neither a per-tool nor a wildcard renderer has been
159
- // registered. This makes "zero custom renderers" demos paint tool
160
- // calls out-of-the-box instead of going invisible.
161
- const RenderComponent = (renderConfig?.render ??
162
- defaultToolCallRenderAdapter) as ReactToolCallRenderer<unknown>["render"];
163
- const isExecuting = executingToolCallIds.has(toolCall.id);
164
-
165
- // Use the memoized ToolCallRenderer component to prevent unnecessary re-renders
166
- return (
167
- <ToolCallRenderer
168
- key={toolCall.id}
169
- toolCall={toolCall}
170
- toolMessage={toolMessage}
171
- RenderComponent={RenderComponent}
172
- isExecuting={isExecuting}
173
- />
174
- );
175
- },
176
- [renderToolCalls, executingToolCallIds, agentId],
177
- );
178
-
179
- return renderToolCall;
180
- }
181
-
182
- // Adapter that bridges the ReactToolCallRenderer signature
183
- // (`{ name, args, status, result, toolCallId }`) to the
184
- // `DefaultToolCallRenderer` signature (`{ name, parameters, status,
185
- // result }`) so the latter can be used as a zero-config fallback when
186
- // no `*` renderer is registered.
187
- function defaultToolCallRenderAdapter(props: {
188
- name: string;
189
- args: unknown;
190
- status: ToolCallStatus;
191
- result: string | undefined;
192
- toolCallId: string;
193
- }): React.ReactElement {
194
- const status =
195
- props.status === ToolCallStatus.Complete
196
- ? "complete"
197
- : props.status === ToolCallStatus.Executing
198
- ? "executing"
199
- : "inProgress";
200
- return (
201
- <DefaultToolCallRenderer
202
- name={props.name}
203
- parameters={props.args}
204
- status={status}
205
- result={props.result}
206
- />
207
- );
208
- }