@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,702 +0,0 @@
1
- import React from "react";
2
- import { render, screen, fireEvent, waitFor } from "@testing-library/react";
3
- import { vi } from "vitest";
4
- import { CopilotChatAssistantMessage } from "../CopilotChatAssistantMessage";
5
- import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
6
- import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
7
- import { AssistantMessage } from "@ag-ui/core";
8
-
9
- // No mocks needed - Vitest handles ES modules natively!
10
-
11
- // Mock navigator.clipboard
12
- const mockWriteText = vi.fn();
13
- Object.assign(navigator, {
14
- clipboard: {
15
- writeText: mockWriteText,
16
- },
17
- });
18
-
19
- // Mock callback functions
20
- const mockOnThumbsUp = vi.fn();
21
- const mockOnThumbsDown = vi.fn();
22
- const mockOnReadAloud = vi.fn();
23
- const mockOnRegenerate = vi.fn();
24
-
25
- // Helper to render components with context providers
26
- const TEST_THREAD_ID = "test-thread";
27
-
28
- const renderWithProvider = (component: React.ReactElement) => {
29
- return render(
30
- <CopilotKitProvider>
31
- <CopilotChatConfigurationProvider threadId={TEST_THREAD_ID}>
32
- {component}
33
- </CopilotChatConfigurationProvider>
34
- </CopilotKitProvider>,
35
- );
36
- };
37
-
38
- // Clear mocks before each test
39
- beforeEach(() => {
40
- mockWriteText.mockClear();
41
- mockOnThumbsUp.mockClear();
42
- mockOnThumbsDown.mockClear();
43
- mockOnReadAloud.mockClear();
44
- mockOnRegenerate.mockClear();
45
- });
46
-
47
- describe("CopilotChatAssistantMessage", () => {
48
- const basicMessage: AssistantMessage = {
49
- role: "assistant",
50
- content: "Hello, this is a test message from the assistant.",
51
- id: "test-message-1",
52
- };
53
-
54
- describe("Basic rendering", () => {
55
- it("renders with default components and styling", () => {
56
- renderWithProvider(
57
- <CopilotChatAssistantMessage message={basicMessage} />,
58
- );
59
-
60
- // Check if elements exist (getBy throws if not found, so this is sufficient)
61
- // Note: Since markdown may not render in test environment, let's check the component structure
62
- const copyButton = screen.getByRole("button", { name: /copy/i });
63
- expect(copyButton).toBeDefined();
64
- });
65
-
66
- it("renders empty message gracefully", () => {
67
- const emptyMessage: AssistantMessage = {
68
- role: "assistant",
69
- content: "",
70
- id: "empty-message",
71
- };
72
-
73
- renderWithProvider(
74
- <CopilotChatAssistantMessage message={emptyMessage} />,
75
- );
76
-
77
- // Should render the component structure but NOT show toolbar for empty content
78
- const container = document.querySelector(
79
- '[data-message-id="empty-message"]',
80
- );
81
- expect(container).toBeDefined();
82
-
83
- // Should NOT have a copy button since there's no content to copy
84
- expect(screen.queryByRole("button", { name: /copy/i })).toBeNull();
85
- });
86
- });
87
-
88
- describe("Callback functionality", () => {
89
- it("renders only copy button when no callbacks provided", () => {
90
- renderWithProvider(
91
- <CopilotChatAssistantMessage message={basicMessage} />,
92
- );
93
-
94
- expect(screen.getByRole("button", { name: /copy/i })).toBeDefined();
95
- expect(screen.queryByRole("button", { name: /thumbs up/i })).toBeNull();
96
- expect(screen.queryByRole("button", { name: /thumbs down/i })).toBeNull();
97
- expect(screen.queryByRole("button", { name: /read aloud/i })).toBeNull();
98
- expect(screen.queryByRole("button", { name: /regenerate/i })).toBeNull();
99
- });
100
-
101
- it("renders all buttons when all callbacks provided", () => {
102
- renderWithProvider(
103
- <CopilotChatAssistantMessage
104
- message={basicMessage}
105
- onThumbsUp={mockOnThumbsUp}
106
- onThumbsDown={mockOnThumbsDown}
107
- onReadAloud={mockOnReadAloud}
108
- onRegenerate={mockOnRegenerate}
109
- />,
110
- );
111
-
112
- expect(screen.getByRole("button", { name: /copy/i })).toBeDefined();
113
- expect(
114
- screen.getByRole("button", { name: /good response/i }),
115
- ).toBeDefined();
116
- expect(
117
- screen.getByRole("button", { name: /bad response/i }),
118
- ).toBeDefined();
119
- expect(screen.getByRole("button", { name: /read aloud/i })).toBeDefined();
120
- expect(screen.getByRole("button", { name: /regenerate/i })).toBeDefined();
121
- });
122
-
123
- it("calls copy functionality when copy button clicked", async () => {
124
- renderWithProvider(
125
- <CopilotChatAssistantMessage message={basicMessage} />,
126
- );
127
-
128
- const copyButton = screen.getByRole("button", { name: /copy/i });
129
- fireEvent.click(copyButton);
130
-
131
- await waitFor(() => {
132
- expect(mockWriteText).toHaveBeenCalledWith(basicMessage.content!);
133
- });
134
- });
135
-
136
- it("calls thumbs up callback when thumbs up button clicked", () => {
137
- renderWithProvider(
138
- <CopilotChatAssistantMessage
139
- message={basicMessage}
140
- onThumbsUp={mockOnThumbsUp}
141
- />,
142
- );
143
-
144
- const thumbsUpButton = screen.getByRole("button", {
145
- name: /good response/i,
146
- });
147
- fireEvent.click(thumbsUpButton);
148
-
149
- expect(mockOnThumbsUp).toHaveBeenCalledTimes(1);
150
- });
151
-
152
- it("calls thumbs down callback when thumbs down button clicked", () => {
153
- renderWithProvider(
154
- <CopilotChatAssistantMessage
155
- message={basicMessage}
156
- onThumbsDown={mockOnThumbsDown}
157
- />,
158
- );
159
-
160
- const thumbsDownButton = screen.getByRole("button", {
161
- name: /bad response/i,
162
- });
163
- fireEvent.click(thumbsDownButton);
164
-
165
- expect(mockOnThumbsDown).toHaveBeenCalledTimes(1);
166
- });
167
-
168
- it("calls read aloud callback when read aloud button clicked", () => {
169
- renderWithProvider(
170
- <CopilotChatAssistantMessage
171
- message={basicMessage}
172
- onReadAloud={mockOnReadAloud}
173
- />,
174
- );
175
-
176
- const readAloudButton = screen.getByRole("button", {
177
- name: /read aloud/i,
178
- });
179
- fireEvent.click(readAloudButton);
180
-
181
- expect(mockOnReadAloud).toHaveBeenCalledTimes(1);
182
- });
183
-
184
- it("calls regenerate callback when regenerate button clicked", () => {
185
- renderWithProvider(
186
- <CopilotChatAssistantMessage
187
- message={basicMessage}
188
- onRegenerate={mockOnRegenerate}
189
- />,
190
- );
191
-
192
- const regenerateButton = screen.getByRole("button", {
193
- name: /regenerate/i,
194
- });
195
- fireEvent.click(regenerateButton);
196
-
197
- expect(mockOnRegenerate).toHaveBeenCalledTimes(1);
198
- });
199
- });
200
-
201
- describe("Additional toolbar items", () => {
202
- it("renders additional toolbar items", () => {
203
- const additionalItems = (
204
- <button data-testid="custom-toolbar-item">Custom Action</button>
205
- );
206
-
207
- renderWithProvider(
208
- <CopilotChatAssistantMessage
209
- message={basicMessage}
210
- additionalToolbarItems={additionalItems}
211
- />,
212
- );
213
-
214
- expect(screen.getByTestId("custom-toolbar-item")).toBeDefined();
215
- });
216
- });
217
-
218
- describe("Slot functionality - Custom Components", () => {
219
- it("accepts custom MarkdownRenderer component", () => {
220
- const CustomMarkdownRenderer = ({ content }: { content: string }) => (
221
- <div data-testid="custom-markdown">{content.toUpperCase()}</div>
222
- );
223
-
224
- renderWithProvider(
225
- <CopilotChatAssistantMessage
226
- message={basicMessage}
227
- markdownRenderer={CustomMarkdownRenderer}
228
- />,
229
- );
230
-
231
- expect(screen.getByTestId("custom-markdown")).toBeDefined();
232
- expect(
233
- screen
234
- .getByTestId("custom-markdown")
235
- .textContent?.includes(basicMessage.content!.toUpperCase()),
236
- ).toBe(true);
237
- });
238
-
239
- it("accepts custom Toolbar component", () => {
240
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
241
- const CustomToolbar = ({ children, ...props }: any) => (
242
- <div data-testid="custom-toolbar" {...props}>
243
- Custom Toolbar: {children}
244
- </div>
245
- );
246
-
247
- renderWithProvider(
248
- <CopilotChatAssistantMessage
249
- message={basicMessage}
250
- toolbar={CustomToolbar}
251
- />,
252
- );
253
-
254
- expect(screen.getByTestId("custom-toolbar")).toBeDefined();
255
- expect(
256
- screen
257
- .getByTestId("custom-toolbar")
258
- .textContent?.includes("Custom Toolbar:"),
259
- ).toBe(true);
260
- });
261
-
262
- it("accepts custom CopyButton component", () => {
263
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
- const CustomCopyButton = (props: any) => (
265
- <button data-testid="custom-copy-button" {...props}>
266
- Custom Copy
267
- </button>
268
- );
269
-
270
- renderWithProvider(
271
- <CopilotChatAssistantMessage
272
- message={basicMessage}
273
- copyButton={CustomCopyButton}
274
- />,
275
- );
276
-
277
- expect(screen.getByTestId("custom-copy-button")).toBeDefined();
278
- expect(
279
- screen
280
- .getByTestId("custom-copy-button")
281
- .textContent?.includes("Custom Copy"),
282
- ).toBe(true);
283
- });
284
-
285
- it("accepts custom ThumbsUpButton component", () => {
286
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
287
- const CustomThumbsUpButton = (props: any) => (
288
- <button data-testid="custom-thumbs-up" {...props}>
289
- Custom Like
290
- </button>
291
- );
292
-
293
- renderWithProvider(
294
- <CopilotChatAssistantMessage
295
- message={basicMessage}
296
- onThumbsUp={mockOnThumbsUp}
297
- thumbsUpButton={CustomThumbsUpButton}
298
- />,
299
- );
300
-
301
- expect(screen.getByTestId("custom-thumbs-up")).toBeDefined();
302
- expect(
303
- screen
304
- .getByTestId("custom-thumbs-up")
305
- .textContent?.includes("Custom Like"),
306
- ).toBe(true);
307
- });
308
-
309
- it("accepts custom ThumbsDownButton component", () => {
310
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
311
- const CustomThumbsDownButton = (props: any) => (
312
- <button data-testid="custom-thumbs-down" {...props}>
313
- Custom Dislike
314
- </button>
315
- );
316
-
317
- renderWithProvider(
318
- <CopilotChatAssistantMessage
319
- message={basicMessage}
320
- onThumbsDown={mockOnThumbsDown}
321
- thumbsDownButton={CustomThumbsDownButton}
322
- />,
323
- );
324
-
325
- expect(screen.getByTestId("custom-thumbs-down")).toBeDefined();
326
- expect(
327
- screen
328
- .getByTestId("custom-thumbs-down")
329
- .textContent?.includes("Custom Dislike"),
330
- ).toBe(true);
331
- });
332
-
333
- it("accepts custom ReadAloudButton component", () => {
334
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
335
- const CustomReadAloudButton = (props: any) => (
336
- <button data-testid="custom-read-aloud" {...props}>
337
- Custom Speak
338
- </button>
339
- );
340
-
341
- renderWithProvider(
342
- <CopilotChatAssistantMessage
343
- message={basicMessage}
344
- onReadAloud={mockOnReadAloud}
345
- readAloudButton={CustomReadAloudButton}
346
- />,
347
- );
348
-
349
- expect(screen.getByTestId("custom-read-aloud")).toBeDefined();
350
- expect(
351
- screen
352
- .getByTestId("custom-read-aloud")
353
- .textContent?.includes("Custom Speak"),
354
- ).toBe(true);
355
- });
356
-
357
- it("accepts custom RegenerateButton component", () => {
358
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
359
- const CustomRegenerateButton = (props: any) => (
360
- <button data-testid="custom-regenerate" {...props}>
361
- Custom Retry
362
- </button>
363
- );
364
-
365
- renderWithProvider(
366
- <CopilotChatAssistantMessage
367
- message={basicMessage}
368
- onRegenerate={mockOnRegenerate}
369
- regenerateButton={CustomRegenerateButton}
370
- />,
371
- );
372
-
373
- expect(screen.getByTestId("custom-regenerate")).toBeDefined();
374
- expect(
375
- screen
376
- .getByTestId("custom-regenerate")
377
- .textContent?.includes("Custom Retry"),
378
- ).toBe(true);
379
- });
380
- });
381
-
382
- describe("Slot functionality - Custom Classes", () => {
383
- it("applies custom className to component", () => {
384
- const { container } = renderWithProvider(
385
- <CopilotChatAssistantMessage
386
- message={basicMessage}
387
- className="custom-container-class"
388
- />,
389
- );
390
-
391
- const containerElement = container.querySelector(
392
- ".custom-container-class",
393
- );
394
- expect(containerElement).toBeDefined();
395
- });
396
-
397
- it("applies custom className to MarkdownRenderer slot", () => {
398
- const { container } = renderWithProvider(
399
- <CopilotChatAssistantMessage
400
- message={basicMessage}
401
- markdownRenderer="custom-markdown-class"
402
- />,
403
- );
404
-
405
- const markdownElement = container.querySelector(".custom-markdown-class");
406
- expect(markdownElement).toBeDefined();
407
- });
408
-
409
- it("applies custom className to Toolbar slot", () => {
410
- const { container } = renderWithProvider(
411
- <CopilotChatAssistantMessage
412
- message={basicMessage}
413
- toolbar="custom-toolbar-class"
414
- />,
415
- );
416
-
417
- const toolbarElement = container.querySelector(".custom-toolbar-class");
418
- expect(toolbarElement).toBeDefined();
419
- });
420
-
421
- it("applies custom className to CopyButton slot", () => {
422
- const { container } = renderWithProvider(
423
- <CopilotChatAssistantMessage
424
- message={basicMessage}
425
- copyButton="custom-copy-button-class"
426
- />,
427
- );
428
-
429
- const copyButtonElement = container.querySelector(
430
- ".custom-copy-button-class",
431
- );
432
- expect(copyButtonElement).toBeDefined();
433
- });
434
- });
435
-
436
- describe("Children render prop functionality", () => {
437
- it("supports custom layout via children render prop", () => {
438
- renderWithProvider(
439
- <CopilotChatAssistantMessage message={basicMessage}>
440
- {({
441
- markdownRenderer: MarkdownRenderer,
442
- toolbar: Toolbar,
443
- message,
444
- }) => (
445
- <div data-testid="custom-layout">
446
- <h2>Custom Layout for: {message.id}</h2>
447
- {MarkdownRenderer}
448
- <div data-testid="custom-toolbar-wrapper">{Toolbar}</div>
449
- </div>
450
- )}
451
- </CopilotChatAssistantMessage>,
452
- );
453
-
454
- expect(screen.getByTestId("custom-layout")).toBeDefined();
455
- expect(
456
- screen.getByText(`Custom Layout for: ${basicMessage.id}`),
457
- ).toBeDefined();
458
- expect(screen.getByTestId("custom-toolbar-wrapper")).toBeDefined();
459
- // Note: Markdown content may not render in test environment, check toolbar instead
460
- expect(screen.getByTestId("custom-toolbar-wrapper")).toBeDefined();
461
- });
462
-
463
- it("provides all slot components to children render prop", () => {
464
- renderWithProvider(
465
- <CopilotChatAssistantMessage
466
- message={basicMessage}
467
- onThumbsUp={mockOnThumbsUp}
468
- onThumbsDown={mockOnThumbsDown}
469
- onReadAloud={mockOnReadAloud}
470
- onRegenerate={mockOnRegenerate}
471
- >
472
- {({
473
- markdownRenderer: MarkdownRenderer,
474
- toolbar: Toolbar,
475
- copyButton: CopyButton,
476
- thumbsUpButton: ThumbsUpButton,
477
- thumbsDownButton: ThumbsDownButton,
478
- readAloudButton: ReadAloudButton,
479
- regenerateButton: RegenerateButton,
480
- }) => (
481
- <div data-testid="all-slots-layout">
482
- {MarkdownRenderer}
483
- {Toolbar}
484
- <div data-testid="individual-buttons">
485
- {CopyButton}
486
- {ThumbsUpButton}
487
- {ThumbsDownButton}
488
- {ReadAloudButton}
489
- {RegenerateButton}
490
- </div>
491
- </div>
492
- )}
493
- </CopilotChatAssistantMessage>,
494
- );
495
-
496
- expect(screen.getByTestId("all-slots-layout")).toBeDefined();
497
- expect(screen.getByTestId("individual-buttons")).toBeDefined();
498
-
499
- // Verify all buttons are rendered
500
- const buttons = screen.getAllByRole("button");
501
- expect(buttons.length).toBeGreaterThanOrEqual(5); // At least copy, thumbs up, thumbs down, read aloud, regenerate
502
- });
503
-
504
- it("provides callback props to children render prop", () => {
505
- renderWithProvider(
506
- <CopilotChatAssistantMessage
507
- message={basicMessage}
508
- onThumbsUp={mockOnThumbsUp}
509
- onThumbsDown={mockOnThumbsDown}
510
- onReadAloud={mockOnReadAloud}
511
- onRegenerate={mockOnRegenerate}
512
- >
513
- {({ onThumbsUp, onThumbsDown, onReadAloud, onRegenerate }) => (
514
- <div data-testid="callback-test">
515
- <button
516
- onClick={() => onThumbsUp?.(basicMessage)}
517
- data-testid="custom-thumbs-up"
518
- >
519
- Custom Thumbs Up
520
- </button>
521
- <button
522
- onClick={() => onThumbsDown?.(basicMessage)}
523
- data-testid="custom-thumbs-down"
524
- >
525
- Custom Thumbs Down
526
- </button>
527
- <button
528
- onClick={() => onReadAloud?.(basicMessage)}
529
- data-testid="custom-read-aloud"
530
- >
531
- Custom Read Aloud
532
- </button>
533
- <button
534
- onClick={() => onRegenerate?.(basicMessage)}
535
- data-testid="custom-regenerate"
536
- >
537
- Custom Regenerate
538
- </button>
539
- </div>
540
- )}
541
- </CopilotChatAssistantMessage>,
542
- );
543
-
544
- fireEvent.click(screen.getByTestId("custom-thumbs-up"));
545
- fireEvent.click(screen.getByTestId("custom-thumbs-down"));
546
- fireEvent.click(screen.getByTestId("custom-read-aloud"));
547
- fireEvent.click(screen.getByTestId("custom-regenerate"));
548
-
549
- expect(mockOnThumbsUp).toHaveBeenCalledTimes(1);
550
- expect(mockOnThumbsDown).toHaveBeenCalledTimes(1);
551
- expect(mockOnReadAloud).toHaveBeenCalledTimes(1);
552
- expect(mockOnRegenerate).toHaveBeenCalledTimes(1);
553
- });
554
- });
555
-
556
- describe("Toolbar visibility functionality", () => {
557
- it("shows toolbar by default (toolbarVisible = true by default)", () => {
558
- renderWithProvider(
559
- <CopilotChatAssistantMessage message={basicMessage} />,
560
- );
561
-
562
- expect(screen.getByRole("button", { name: /copy/i })).toBeDefined();
563
- });
564
-
565
- it("shows toolbar when toolbarVisible is explicitly true", () => {
566
- renderWithProvider(
567
- <CopilotChatAssistantMessage
568
- message={basicMessage}
569
- toolbarVisible={true}
570
- />,
571
- );
572
-
573
- expect(screen.getByRole("button", { name: /copy/i })).toBeDefined();
574
- });
575
-
576
- it("hides toolbar when toolbarVisible is false", () => {
577
- renderWithProvider(
578
- <CopilotChatAssistantMessage
579
- message={basicMessage}
580
- toolbarVisible={false}
581
- />,
582
- );
583
-
584
- expect(screen.queryByRole("button", { name: /copy/i })).toBeNull();
585
- });
586
-
587
- it("always passes toolbar and toolbarVisible to children render prop", () => {
588
- const childrenSpy = vi.fn(() => <div data-testid="children-render" />);
589
-
590
- renderWithProvider(
591
- <CopilotChatAssistantMessage
592
- message={basicMessage}
593
- toolbarVisible={false}
594
- >
595
- {childrenSpy}
596
- </CopilotChatAssistantMessage>,
597
- );
598
-
599
- expect(childrenSpy).toHaveBeenCalledWith(
600
- expect.objectContaining({
601
- toolbar: expect.anything(),
602
- toolbarVisible: false,
603
- message: basicMessage,
604
- }),
605
- );
606
- expect(screen.getByTestId("children-render")).toBeDefined();
607
- });
608
-
609
- it("passes toolbarVisible true to children render prop by default", () => {
610
- const childrenSpy = vi.fn(() => <div data-testid="children-render" />);
611
-
612
- renderWithProvider(
613
- <CopilotChatAssistantMessage message={basicMessage}>
614
- {childrenSpy}
615
- </CopilotChatAssistantMessage>,
616
- );
617
-
618
- expect(childrenSpy).toHaveBeenCalledWith(
619
- expect.objectContaining({
620
- toolbar: expect.anything(),
621
- toolbarVisible: true,
622
- message: basicMessage,
623
- }),
624
- );
625
- });
626
-
627
- it("children can use toolbarVisible to conditionally render toolbar", () => {
628
- renderWithProvider(
629
- <CopilotChatAssistantMessage
630
- message={basicMessage}
631
- toolbarVisible={false}
632
- >
633
- {({ toolbar, toolbarVisible }) => (
634
- <div data-testid="custom-layout">
635
- <div data-testid="content">Custom content</div>
636
- {toolbarVisible && (
637
- <div data-testid="conditional-toolbar">{toolbar}</div>
638
- )}
639
- {!toolbarVisible && (
640
- <div data-testid="no-toolbar">No toolbar</div>
641
- )}
642
- </div>
643
- )}
644
- </CopilotChatAssistantMessage>,
645
- );
646
-
647
- expect(screen.getByTestId("custom-layout")).toBeDefined();
648
- expect(screen.getByTestId("content")).toBeDefined();
649
- expect(screen.queryByTestId("conditional-toolbar")).toBeNull();
650
- expect(screen.getByTestId("no-toolbar")).toBeDefined();
651
- });
652
- });
653
-
654
- describe("Error handling", () => {
655
- it("handles copy errors gracefully", async () => {
656
- // Mock clipboard to throw an error
657
- mockWriteText.mockRejectedValueOnce(new Error("Clipboard error"));
658
-
659
- const consoleSpy = vi
660
- .spyOn(console, "error")
661
- .mockImplementation(() => {});
662
-
663
- renderWithProvider(
664
- <CopilotChatAssistantMessage message={basicMessage} />,
665
- );
666
-
667
- const copyButton = screen.getByRole("button", { name: /copy/i });
668
- fireEvent.click(copyButton);
669
-
670
- await waitFor(() => {
671
- expect(consoleSpy).toHaveBeenCalledWith(
672
- "Failed to copy to clipboard:",
673
- expect.any(Error),
674
- );
675
- });
676
-
677
- consoleSpy.mockRestore();
678
- });
679
-
680
- it("handles null message content gracefully", () => {
681
- const nullContentMessage: AssistantMessage = {
682
- role: "assistant",
683
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
684
- content: null as any,
685
- id: "null-content",
686
- };
687
-
688
- renderWithProvider(
689
- <CopilotChatAssistantMessage message={nullContentMessage} />,
690
- );
691
-
692
- // Should render the component structure but NOT show toolbar for empty content
693
- const container = document.querySelector(
694
- '[data-message-id="null-content"]',
695
- );
696
- expect(container).toBeDefined();
697
-
698
- // Should NOT have a copy button since there's no content to copy
699
- expect(screen.queryByRole("button", { name: /copy/i })).toBeNull();
700
- });
701
- });
702
- });