@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.
- package/LICENSE +21 -0
- package/dist/{copilotkit-CtXcs1ea.cjs → copilotkit-B4ouY7qC.cjs} +14 -3
- package/dist/copilotkit-B4ouY7qC.cjs.map +1 -0
- package/dist/copilotkit-BK9CVq9A.d.cts.map +1 -1
- package/dist/{copilotkit-CC8DjOiC.mjs → copilotkit-L4mM_JqG.mjs} +14 -3
- package/dist/copilotkit-L4mM_JqG.mjs.map +1 -0
- package/dist/copilotkit-WlmeVijs.d.mts.map +1 -1
- package/dist/index.cjs +3 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -77
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +15 -78
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +11 -0
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +11 -0
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +13 -2
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -13
- package/skills/react-core/SKILL.md +108 -0
- package/skills/react-core/references/agent-access.md +288 -0
- package/skills/react-core/references/attachments.md +291 -0
- package/skills/react-core/references/capabilities.md +138 -0
- package/skills/react-core/references/chat-components.md +221 -0
- package/skills/react-core/references/client-side-tools.md +358 -0
- package/skills/react-core/references/custom-message-renderers.md +226 -0
- package/skills/react-core/references/debug-mode.md +153 -0
- package/skills/react-core/references/human-in-the-loop.md +312 -0
- package/skills/react-core/references/provider-setup.md +326 -0
- package/skills/react-core/references/rendering-activity-messages.md +207 -0
- package/skills/react-core/references/rendering-tool-calls.md +319 -0
- package/skills/react-core/references/suggestions.md +211 -0
- package/skills/react-core/references/switching-agents-recipes.md +160 -0
- package/skills/react-core/references/switching-agents.md +231 -0
- package/skills/react-core/references/threads.md +226 -0
- package/.attw.json +0 -3
- package/CHANGELOG.md +0 -5043
- package/dist/copilotkit-CC8DjOiC.mjs.map +0 -1
- package/dist/copilotkit-CtXcs1ea.cjs.map +0 -1
- package/scripts/scope-preflight.mjs +0 -100
- package/src/components/CopilotListeners.tsx +0 -137
- package/src/components/__tests__/CopilotListeners.test.tsx +0 -38
- package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +0 -92
- package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -77
- package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +0 -70
- package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +0 -107
- package/src/components/copilot-provider/copilot-messages.tsx +0 -314
- package/src/components/copilot-provider/copilotkit-props.tsx +0 -214
- package/src/components/copilot-provider/copilotkit.tsx +0 -853
- package/src/components/copilot-provider/index.ts +0 -3
- package/src/components/dev-console/console-trigger.tsx +0 -283
- package/src/components/dev-console/developer-console-modal.tsx +0 -1016
- package/src/components/dev-console/icons.tsx +0 -106
- package/src/components/error-boundary/error-boundary.tsx +0 -99
- package/src/components/error-boundary/error-utils.tsx +0 -105
- package/src/components/index.ts +0 -1
- package/src/components/toast/exclamation-mark-icon.tsx +0 -27
- package/src/components/toast/toast-provider.tsx +0 -448
- package/src/components/usage-banner.tsx +0 -266
- package/src/context/__tests__/threads-context.test.tsx +0 -141
- package/src/context/coagent-state-renders-context.tsx +0 -89
- package/src/context/copilot-context.tsx +0 -365
- package/src/context/copilot-messages-context.tsx +0 -35
- package/src/context/index.ts +0 -22
- package/src/context/threads-context.tsx +0 -69
- package/src/hooks/__tests__/use-coagent-config.test.ts +0 -352
- package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +0 -107
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +0 -1209
- package/src/hooks/__tests__/use-coagent-state-render.test.tsx +0 -356
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +0 -241
- package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -72
- package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +0 -102
- package/src/hooks/index.ts +0 -33
- package/src/hooks/use-agent-nodename.ts +0 -33
- package/src/hooks/use-coagent-state-render-bridge.helpers.ts +0 -345
- package/src/hooks/use-coagent-state-render-bridge.tsx +0 -222
- package/src/hooks/use-coagent-state-render-registry.ts +0 -230
- package/src/hooks/use-coagent-state-render.ts +0 -163
- package/src/hooks/use-coagent.ts +0 -377
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -96
- package/src/hooks/use-copilot-action.ts +0 -245
- package/src/hooks/use-copilot-additional-instructions.ts +0 -98
- package/src/hooks/use-copilot-authenticated-action.ts +0 -73
- package/src/hooks/use-copilot-chat-headless_c.ts +0 -264
- package/src/hooks/use-copilot-chat-suggestions.tsx +0 -134
- package/src/hooks/use-copilot-chat.ts +0 -132
- package/src/hooks/use-copilot-chat_internal.ts +0 -875
- package/src/hooks/use-copilot-readable.ts +0 -135
- package/src/hooks/use-copilot-runtime-client.ts +0 -178
- package/src/hooks/use-default-tool.ts +0 -13
- package/src/hooks/use-flat-category-store.ts +0 -109
- package/src/hooks/use-frontend-tool.ts +0 -113
- package/src/hooks/use-human-in-the-loop.ts +0 -138
- package/src/hooks/use-langgraph-interrupt.ts +0 -103
- package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
- package/src/hooks/use-make-copilot-document-readable.ts +0 -30
- package/src/hooks/use-render-tool-call.ts +0 -89
- package/src/hooks/use-tree.ts +0 -222
- package/src/index.tsx +0 -7
- package/src/lib/copilot-task.ts +0 -215
- package/src/lib/index.ts +0 -1
- package/src/lib/status-checker.ts +0 -67
- package/src/setupTests.ts +0 -37
- package/src/test-helpers/copilot-context.ts +0 -91
- package/src/types/chat-suggestion-configuration.ts +0 -23
- package/src/types/coagent-action.ts +0 -35
- package/src/types/coagent-state.ts +0 -13
- package/src/types/crew.ts +0 -89
- package/src/types/document-pointer.ts +0 -7
- package/src/types/frontend-action.ts +0 -213
- package/src/types/index.ts +0 -17
- package/src/types/interrupt-action.ts +0 -58
- package/src/types/system-message.ts +0 -4
- package/src/utils/dev-console.ts +0 -19
- package/src/utils/index.ts +0 -2
- package/src/utils/suggestions-constants.ts +0 -8
- package/src/utils/utils.test.ts +0 -7
- package/src/utils/utils.ts +0 -6
- package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +0 -240
- package/src/v2/__tests__/globalSetup.ts +0 -14
- package/src/v2/__tests__/setup.ts +0 -93
- package/src/v2/__tests__/utils/test-helpers.tsx +0 -570
- package/src/v2/a2ui/A2UICatalogContext.tsx +0 -79
- package/src/v2/a2ui/A2UIMessageRenderer.tsx +0 -294
- package/src/v2/a2ui/A2UIToolCallRenderer.tsx +0 -290
- package/src/v2/components/CopilotKitInspector.tsx +0 -52
- package/src/v2/components/MCPAppsActivityRenderer.tsx +0 -815
- package/src/v2/components/OpenGenerativeUIRenderer.tsx +0 -598
- package/src/v2/components/WildcardToolCallRender.tsx +0 -86
- package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +0 -665
- package/src/v2/components/chat/CopilotChat.tsx +0 -664
- package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +0 -393
- package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +0 -374
- package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +0 -159
- package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +0 -350
- package/src/v2/components/chat/CopilotChatInput.tsx +0 -1412
- package/src/v2/components/chat/CopilotChatMessageView.tsx +0 -716
- package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +0 -265
- package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +0 -59
- package/src/v2/components/chat/CopilotChatSuggestionView.tsx +0 -134
- package/src/v2/components/chat/CopilotChatToggleButton.tsx +0 -171
- package/src/v2/components/chat/CopilotChatToolCallsView.tsx +0 -40
- package/src/v2/components/chat/CopilotChatUserMessage.tsx +0 -445
- package/src/v2/components/chat/CopilotChatView.tsx +0 -890
- package/src/v2/components/chat/CopilotModalHeader.tsx +0 -129
- package/src/v2/components/chat/CopilotPopup.tsx +0 -81
- package/src/v2/components/chat/CopilotPopupView.tsx +0 -317
- package/src/v2/components/chat/CopilotSidebar.tsx +0 -80
- package/src/v2/components/chat/CopilotSidebarView.tsx +0 -269
- package/src/v2/components/chat/Lightbox.tsx +0 -103
- package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +0 -66
- package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +0 -168
- package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +0 -1239
- package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +0 -73
- package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +0 -432
- package/src/v2/components/chat/__tests__/CopilotChat.suggestionsAlways.test.tsx +0 -183
- package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +0 -184
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +0 -649
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +0 -624
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -702
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +0 -72
- package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +0 -241
- package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +0 -107
- package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +0 -929
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +0 -1567
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +0 -1004
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +0 -279
- package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +0 -336
- package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +0 -249
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +0 -530
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +0 -785
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +0 -2416
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +0 -621
- package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +0 -56
- package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.tsx +0 -264
- package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +0 -853
- package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +0 -94
- package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +0 -1050
- package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +0 -484
- package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +0 -612
- package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +0 -159
- package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +0 -502
- package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +0 -1068
- package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +0 -589
- package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +0 -403
- package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -137
- package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -37
- package/src/v2/components/chat/__tests__/setup.ts +0 -1
- package/src/v2/components/chat/index.ts +0 -90
- package/src/v2/components/chat/last-user-message-context.ts +0 -21
- package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
- package/src/v2/components/chat/scroll-element-context.ts +0 -13
- package/src/v2/components/index.ts +0 -8
- package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -286
- package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -464
- package/src/v2/components/intelligence-indicator/index.ts +0 -2
- package/src/v2/components/license-warning-banner.tsx +0 -217
- package/src/v2/components/ui/button.tsx +0 -124
- package/src/v2/components/ui/dropdown-menu.tsx +0 -258
- package/src/v2/components/ui/tooltip.tsx +0 -60
- package/src/v2/context.ts +0 -62
- package/src/v2/headless.ts +0 -64
- package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +0 -152
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +0 -282
- package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +0 -140
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +0 -401
- package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +0 -44
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +0 -211
- package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +0 -1029
- package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +0 -159
- package/src/v2/hooks/__tests__/use-attachments.test.tsx +0 -169
- package/src/v2/hooks/__tests__/use-capabilities.test.tsx +0 -76
- package/src/v2/hooks/__tests__/use-component.test.tsx +0 -126
- package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +0 -696
- package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +0 -153
- package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -167
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +0 -2148
- package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +0 -1261
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +0 -397
- package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +0 -56
- package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +0 -192
- package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +0 -219
- package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +0 -55
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +0 -259
- package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +0 -524
- package/src/v2/hooks/__tests__/use-threads.test.tsx +0 -757
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +0 -311
- package/src/v2/hooks/index.ts +0 -24
- package/src/v2/hooks/use-agent-context.tsx +0 -45
- package/src/v2/hooks/use-agent.tsx +0 -227
- package/src/v2/hooks/use-attachments.tsx +0 -269
- package/src/v2/hooks/use-capabilities.tsx +0 -25
- package/src/v2/hooks/use-component.tsx +0 -91
- package/src/v2/hooks/use-configure-suggestions.tsx +0 -236
- package/src/v2/hooks/use-default-render-tool.tsx +0 -271
- package/src/v2/hooks/use-frontend-tool.tsx +0 -46
- package/src/v2/hooks/use-human-in-the-loop.tsx +0 -81
- package/src/v2/hooks/use-interrupt.tsx +0 -305
- package/src/v2/hooks/use-keyboard-height.tsx +0 -67
- package/src/v2/hooks/use-pin-to-send.ts +0 -94
- package/src/v2/hooks/use-render-activity-message.tsx +0 -72
- package/src/v2/hooks/use-render-custom-messages.tsx +0 -93
- package/src/v2/hooks/use-render-tool-call.tsx +0 -208
- package/src/v2/hooks/use-render-tool.tsx +0 -184
- package/src/v2/hooks/use-suggestions.tsx +0 -91
- package/src/v2/hooks/use-threads.tsx +0 -325
- package/src/v2/hooks/useKatexStyles.ts +0 -27
- package/src/v2/index.css +0 -1
- package/src/v2/index.ts +0 -27
- package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +0 -495
- package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -112
- package/src/v2/lib/__tests__/renderSlot.test.tsx +0 -588
- package/src/v2/lib/__tests__/slots.test.ts +0 -56
- package/src/v2/lib/processPartialHtml.ts +0 -45
- package/src/v2/lib/react-core.ts +0 -156
- package/src/v2/lib/slots.tsx +0 -184
- package/src/v2/lib/transcription-client.ts +0 -184
- package/src/v2/lib/utils.ts +0 -8
- package/src/v2/providers/CopilotChatConfigurationProvider.tsx +0 -196
- package/src/v2/providers/CopilotKitProvider.tsx +0 -800
- package/src/v2/providers/SandboxFunctionsContext.ts +0 -10
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +0 -652
- package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +0 -101
- package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +0 -69
- package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +0 -881
- package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +0 -198
- package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +0 -740
- package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +0 -713
- package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -294
- package/src/v2/providers/index.ts +0 -21
- package/src/v2/styles/globals.css +0 -349
- package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +0 -525
- package/src/v2/types/defineToolCallRenderer.ts +0 -68
- package/src/v2/types/frontend-tool.ts +0 -8
- package/src/v2/types/human-in-the-loop.ts +0 -33
- package/src/v2/types/index.ts +0 -8
- package/src/v2/types/interrupt.ts +0 -15
- package/src/v2/types/react-activity-message-renderer.ts +0 -27
- package/src/v2/types/react-custom-message-renderer.ts +0 -17
- package/src/v2/types/react-tool-call-renderer.ts +0 -35
- package/src/v2/types/sandbox-function.ts +0 -11
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -193
- package/typedoc.json +0 -4
- package/vitest.config.mjs +0 -31
|
@@ -1,649 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import type { AbstractAgent } from "@ag-ui/client";
|
|
5
|
-
import { EventType } from "@ag-ui/client";
|
|
6
|
-
import {
|
|
7
|
-
MockReconnectableAgent,
|
|
8
|
-
MockStepwiseAgent,
|
|
9
|
-
activitySnapshotEvent,
|
|
10
|
-
renderWithCopilotKit,
|
|
11
|
-
runFinishedEvent,
|
|
12
|
-
runStartedEvent,
|
|
13
|
-
testId,
|
|
14
|
-
} from "../../../__tests__/utils/test-helpers";
|
|
15
|
-
import type { ReactActivityMessageRenderer } from "../../../types";
|
|
16
|
-
import {
|
|
17
|
-
CopilotChatConfigurationProvider,
|
|
18
|
-
CopilotKitProvider,
|
|
19
|
-
useCopilotKit,
|
|
20
|
-
} from "../../../providers";
|
|
21
|
-
import { IntelligenceAgent } from "@copilotkit/core";
|
|
22
|
-
import { createA2UIMessageRenderer } from "../../../a2ui/A2UIMessageRenderer";
|
|
23
|
-
import type { Theme } from "@copilotkit/a2ui-renderer";
|
|
24
|
-
import { CopilotChat } from "..";
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
mockWebsandboxCreate,
|
|
28
|
-
mockWebsandboxDestroy,
|
|
29
|
-
mockPhoenixSockets,
|
|
30
|
-
MockPhoenixSocket,
|
|
31
|
-
} = vi.hoisted(() => {
|
|
32
|
-
const mockDestroy = vi.fn();
|
|
33
|
-
const mockCreate = vi.fn((..._args: unknown[]) => ({
|
|
34
|
-
iframe: document.createElement("iframe"),
|
|
35
|
-
promise: Promise.resolve(),
|
|
36
|
-
run: vi.fn().mockResolvedValue(undefined),
|
|
37
|
-
destroy: mockDestroy,
|
|
38
|
-
}));
|
|
39
|
-
const mockSockets: MockPhoenixSocket[] = [];
|
|
40
|
-
|
|
41
|
-
class MockPhoenixPush {
|
|
42
|
-
private callbacks = new Map<string, (response?: unknown) => void>();
|
|
43
|
-
|
|
44
|
-
receive(
|
|
45
|
-
status: string,
|
|
46
|
-
callback: (response?: unknown) => void,
|
|
47
|
-
): MockPhoenixPush {
|
|
48
|
-
this.callbacks.set(status, callback);
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
trigger(status: string, response?: unknown): void {
|
|
53
|
-
this.callbacks.get(status)?.(response);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
class MockPhoenixChannel {
|
|
58
|
-
public topic: string;
|
|
59
|
-
public params: Record<string, unknown>;
|
|
60
|
-
public left = false;
|
|
61
|
-
|
|
62
|
-
private handlers = new Map<
|
|
63
|
-
string,
|
|
64
|
-
Array<{ ref: number; callback: (payload: unknown) => void }>
|
|
65
|
-
>();
|
|
66
|
-
private joinPush = new MockPhoenixPush();
|
|
67
|
-
private nextRef = 1;
|
|
68
|
-
|
|
69
|
-
constructor(topic: string, params: Record<string, unknown>) {
|
|
70
|
-
this.topic = topic;
|
|
71
|
-
this.params = params;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
on(event: string, callback: (payload: unknown) => void): number {
|
|
75
|
-
if (!this.handlers.has(event)) {
|
|
76
|
-
this.handlers.set(event, []);
|
|
77
|
-
}
|
|
78
|
-
const ref = this.nextRef;
|
|
79
|
-
this.nextRef += 1;
|
|
80
|
-
this.handlers.get(event)?.push({ ref, callback });
|
|
81
|
-
return ref;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
off(event: string, ref?: number): void {
|
|
85
|
-
if (ref === undefined) {
|
|
86
|
-
this.handlers.delete(event);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.handlers.set(
|
|
90
|
-
event,
|
|
91
|
-
(this.handlers.get(event) ?? []).filter(
|
|
92
|
-
(handler) => handler.ref !== ref,
|
|
93
|
-
),
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
join(): MockPhoenixPush {
|
|
98
|
-
return this.joinPush;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
leave(): void {
|
|
102
|
-
this.left = true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
triggerJoin(status: string, response?: unknown): void {
|
|
106
|
-
this.joinPush.trigger(status, response);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
serverPush(event: string, payload: unknown): void {
|
|
110
|
-
for (const { callback } of this.handlers.get(event) ?? []) {
|
|
111
|
-
callback(payload);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
class MockPhoenixSocket {
|
|
117
|
-
public channels: MockPhoenixChannel[] = [];
|
|
118
|
-
|
|
119
|
-
constructor(
|
|
120
|
-
public url: string,
|
|
121
|
-
public opts: Record<string, unknown>,
|
|
122
|
-
) {
|
|
123
|
-
mockSockets.push(this);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
connect(): void {}
|
|
127
|
-
|
|
128
|
-
disconnect(): void {}
|
|
129
|
-
|
|
130
|
-
onOpen(): void {}
|
|
131
|
-
|
|
132
|
-
onError(): void {}
|
|
133
|
-
|
|
134
|
-
channel(
|
|
135
|
-
topic: string,
|
|
136
|
-
params: Record<string, unknown>,
|
|
137
|
-
): MockPhoenixChannel {
|
|
138
|
-
const channel = new MockPhoenixChannel(topic, params);
|
|
139
|
-
this.channels.push(channel);
|
|
140
|
-
return channel;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
mockWebsandboxCreate: mockCreate,
|
|
146
|
-
mockWebsandboxDestroy: mockDestroy,
|
|
147
|
-
mockPhoenixSockets: mockSockets,
|
|
148
|
-
MockPhoenixSocket,
|
|
149
|
-
};
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
vi.mock("phoenix", () => ({
|
|
153
|
-
Socket: MockPhoenixSocket,
|
|
154
|
-
}));
|
|
155
|
-
|
|
156
|
-
vi.mock("@jetbrains/websandbox", () => ({
|
|
157
|
-
default: {
|
|
158
|
-
create: (...args: unknown[]) => mockWebsandboxCreate(...args),
|
|
159
|
-
},
|
|
160
|
-
}));
|
|
161
|
-
|
|
162
|
-
function jsonResponse(body: unknown, status = 200): Response {
|
|
163
|
-
return {
|
|
164
|
-
ok: status >= 200 && status < 300,
|
|
165
|
-
status,
|
|
166
|
-
statusText: status === 200 ? "OK" : "Error",
|
|
167
|
-
json: async () => body,
|
|
168
|
-
text: async () => JSON.stringify(body),
|
|
169
|
-
} as Response;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
describe("CopilotChat activity message rendering", () => {
|
|
173
|
-
it("renders custom components for activity snapshots", async () => {
|
|
174
|
-
const agent = new MockStepwiseAgent();
|
|
175
|
-
const agentId = "search-agent";
|
|
176
|
-
agent.agentId = agentId;
|
|
177
|
-
|
|
178
|
-
const activityRenderer: ReactActivityMessageRenderer<{
|
|
179
|
-
status: string;
|
|
180
|
-
percent: number;
|
|
181
|
-
}> = {
|
|
182
|
-
activityType: "search-progress",
|
|
183
|
-
content: z.object({ status: z.string(), percent: z.number() }),
|
|
184
|
-
render: ({ content, agent: rendererAgent }) => (
|
|
185
|
-
<div data-testid="activity-card">
|
|
186
|
-
{content.status} · {content.percent}% · {rendererAgent?.agentId}
|
|
187
|
-
</div>
|
|
188
|
-
),
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
renderWithCopilotKit({
|
|
192
|
-
agents: { [agentId]: agent },
|
|
193
|
-
agentId,
|
|
194
|
-
renderActivityMessages: [activityRenderer],
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const input = await screen.findByRole("textbox");
|
|
198
|
-
fireEvent.change(input, { target: { value: "Start search" } });
|
|
199
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
200
|
-
|
|
201
|
-
await waitFor(() => {
|
|
202
|
-
expect(screen.getByText("Start search")).toBeDefined();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const activityMessageId = testId("activity");
|
|
206
|
-
agent.emit(runStartedEvent());
|
|
207
|
-
agent.emit(
|
|
208
|
-
activitySnapshotEvent({
|
|
209
|
-
messageId: activityMessageId,
|
|
210
|
-
activityType: "search-progress",
|
|
211
|
-
content: { status: "Fetching", percent: 30 },
|
|
212
|
-
}),
|
|
213
|
-
);
|
|
214
|
-
agent.emit(runFinishedEvent());
|
|
215
|
-
|
|
216
|
-
await waitFor(() => {
|
|
217
|
-
const textContent = screen.getByTestId("activity-card").textContent ?? "";
|
|
218
|
-
expect(textContent).toContain("Fetching");
|
|
219
|
-
expect(textContent).toContain(agentId);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("skips unmatched activity types when no renderer exists", async () => {
|
|
224
|
-
const agent = new MockStepwiseAgent();
|
|
225
|
-
|
|
226
|
-
renderWithCopilotKit({
|
|
227
|
-
agent,
|
|
228
|
-
renderActivityMessages: [],
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const input = await screen.findByRole("textbox");
|
|
232
|
-
fireEvent.change(input, { target: { value: "Start search" } });
|
|
233
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
234
|
-
|
|
235
|
-
await waitFor(() => {
|
|
236
|
-
expect(screen.getByText("Start search")).toBeDefined();
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const activityMessageId = testId("activity-unmatched");
|
|
240
|
-
agent.emit(runStartedEvent());
|
|
241
|
-
agent.emit(
|
|
242
|
-
activitySnapshotEvent({
|
|
243
|
-
messageId: activityMessageId,
|
|
244
|
-
activityType: "unknown",
|
|
245
|
-
content: { note: "no-op" },
|
|
246
|
-
}),
|
|
247
|
-
);
|
|
248
|
-
agent.emit(runFinishedEvent());
|
|
249
|
-
|
|
250
|
-
await waitFor(() => {
|
|
251
|
-
expect(screen.queryByTestId("activity-card")).toBeNull();
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("useCopilotKit provides valid copilotkit instance inside activity message renderer", async () => {
|
|
256
|
-
const agent = new MockStepwiseAgent();
|
|
257
|
-
const agentId = "test-agent";
|
|
258
|
-
agent.agentId = agentId;
|
|
259
|
-
|
|
260
|
-
let capturedCopilotkit: any = "not-called";
|
|
261
|
-
|
|
262
|
-
// Matches real-world pattern: inline arrow function with hooks
|
|
263
|
-
const activityRenderer: ReactActivityMessageRenderer<{ message: string }> =
|
|
264
|
-
{
|
|
265
|
-
activityType: "test-activity",
|
|
266
|
-
content: z.object({ message: z.string() }),
|
|
267
|
-
render: ({ content }) => {
|
|
268
|
-
const { copilotkit } = useCopilotKit();
|
|
269
|
-
capturedCopilotkit = copilotkit;
|
|
270
|
-
return <div data-testid="activity-render">{content.message}</div>;
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
renderWithCopilotKit({
|
|
275
|
-
agents: { [agentId]: agent },
|
|
276
|
-
agentId,
|
|
277
|
-
renderActivityMessages: [activityRenderer],
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// Trigger user message and activity event
|
|
281
|
-
const input = await screen.findByRole("textbox");
|
|
282
|
-
fireEvent.change(input, { target: { value: "Test message" } });
|
|
283
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
284
|
-
|
|
285
|
-
await waitFor(() => {
|
|
286
|
-
expect(screen.getByText("Test message")).toBeDefined();
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
agent.emit(runStartedEvent());
|
|
290
|
-
agent.emit(
|
|
291
|
-
activitySnapshotEvent({
|
|
292
|
-
messageId: testId("activity"),
|
|
293
|
-
activityType: "test-activity",
|
|
294
|
-
content: { message: "Rendered content" },
|
|
295
|
-
}),
|
|
296
|
-
);
|
|
297
|
-
agent.emit(runFinishedEvent());
|
|
298
|
-
|
|
299
|
-
await waitFor(() => {
|
|
300
|
-
expect(screen.getByTestId("activity-render")).toBeDefined();
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
// Verify context is properly propagated - copilotkit should NOT be null
|
|
304
|
-
expect(capturedCopilotkit).not.toBeNull();
|
|
305
|
-
expect(capturedCopilotkit).toBeDefined();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("activity renderers receive the agent under the config agentId, not any other registered agent", async () => {
|
|
309
|
-
// Regression: the renderer's `agent` prop must come from
|
|
310
|
-
// `copilotkit.getAgent(config.agentId)` — the local registry id from
|
|
311
|
-
// CopilotChatConfigurationProvider — not from any other agent in the
|
|
312
|
-
// registry (e.g. a sibling chat's agent).
|
|
313
|
-
//
|
|
314
|
-
// The trap this catches is a refactor where the renderer pipeline keys
|
|
315
|
-
// on something other than `config.agentId` (e.g. for proxied
|
|
316
|
-
// registrations, accidentally keying on `proxy.runtimeAgentId`). The
|
|
317
|
-
// assertion shape — "two agents in the registry, the renderer must
|
|
318
|
-
// receive the one matching config.agentId" — is generic to that bug
|
|
319
|
-
// class. The proxy-routing-specific behavior (registering a
|
|
320
|
-
// ProxiedCopilotRuntimeAgent with `runtimeAgentId !== agentId` and
|
|
321
|
-
// verifying `getAgent(agentId)` returns the proxy, not the agent at
|
|
322
|
-
// runtimeAgentId) is covered by `core-register-proxied-agent.test.ts`
|
|
323
|
-
// at the registry level.
|
|
324
|
-
const localAgent = new MockStepwiseAgent();
|
|
325
|
-
localAgent.agentId = "chat-1";
|
|
326
|
-
const otherAgent = new MockStepwiseAgent();
|
|
327
|
-
otherAgent.agentId = "default";
|
|
328
|
-
|
|
329
|
-
let capturedAgent: AbstractAgent | undefined;
|
|
330
|
-
const activityRenderer: ReactActivityMessageRenderer<{ label: string }> = {
|
|
331
|
-
activityType: "button-action",
|
|
332
|
-
content: z.object({ label: z.string() }),
|
|
333
|
-
render: ({ content, agent: renderedAgent }) => {
|
|
334
|
-
capturedAgent = renderedAgent;
|
|
335
|
-
return <button data-testid="action-button">{content.label}</button>;
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
renderWithCopilotKit({
|
|
340
|
-
agents: { "chat-1": localAgent, default: otherAgent },
|
|
341
|
-
agentId: "chat-1",
|
|
342
|
-
threadId: "thread-for-action-test",
|
|
343
|
-
renderActivityMessages: [activityRenderer],
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
const input = await screen.findByRole("textbox");
|
|
347
|
-
fireEvent.change(input, { target: { value: "show me buttons" } });
|
|
348
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
349
|
-
|
|
350
|
-
await waitFor(() => {
|
|
351
|
-
expect(screen.getByText("show me buttons")).toBeDefined();
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
localAgent.emit(runStartedEvent());
|
|
355
|
-
localAgent.emit(
|
|
356
|
-
activitySnapshotEvent({
|
|
357
|
-
messageId: testId("activity-action"),
|
|
358
|
-
activityType: "button-action",
|
|
359
|
-
content: { label: "Click Me" },
|
|
360
|
-
}),
|
|
361
|
-
);
|
|
362
|
-
localAgent.emit(runFinishedEvent());
|
|
363
|
-
|
|
364
|
-
await waitFor(() => {
|
|
365
|
-
expect(screen.getByTestId("action-button")).toBeDefined();
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
expect(capturedAgent).toBe(localAgent);
|
|
369
|
-
expect(capturedAgent).not.toBe(otherAgent);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it("restores a completed A2UI surface after reconnect from an event-native baseline", async () => {
|
|
373
|
-
const agent = new MockReconnectableAgent();
|
|
374
|
-
const threadId = testId("a2ui-thread");
|
|
375
|
-
const surfaceId = testId("surface");
|
|
376
|
-
const a2uiRenderer = createA2UIMessageRenderer({
|
|
377
|
-
theme: {} as Theme,
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
const { unmount } = renderWithCopilotKit({
|
|
381
|
-
agent,
|
|
382
|
-
threadId,
|
|
383
|
-
renderActivityMessages: [a2uiRenderer],
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
const input = await screen.findByRole("textbox");
|
|
387
|
-
fireEvent.change(input, { target: { value: "Show me the restored UI" } });
|
|
388
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
389
|
-
|
|
390
|
-
await waitFor(() => {
|
|
391
|
-
expect(screen.getByText("Show me the restored UI")).toBeDefined();
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
agent.emit(runStartedEvent());
|
|
395
|
-
agent.emit(
|
|
396
|
-
activitySnapshotEvent({
|
|
397
|
-
messageId: testId("a2ui-activity"),
|
|
398
|
-
activityType: "a2ui-surface",
|
|
399
|
-
content: {
|
|
400
|
-
a2ui_operations: [
|
|
401
|
-
{
|
|
402
|
-
version: "v0.9",
|
|
403
|
-
createSurface: {
|
|
404
|
-
surfaceId,
|
|
405
|
-
catalogId:
|
|
406
|
-
"https://a2ui.org/specification/v0_9/basic_catalog.json",
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
version: "v0.9",
|
|
411
|
-
updateComponents: {
|
|
412
|
-
surfaceId,
|
|
413
|
-
components: [
|
|
414
|
-
{
|
|
415
|
-
id: "root",
|
|
416
|
-
component: "Text",
|
|
417
|
-
text: "Restored dashboard",
|
|
418
|
-
variant: "body",
|
|
419
|
-
},
|
|
420
|
-
],
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
},
|
|
425
|
-
}),
|
|
426
|
-
);
|
|
427
|
-
agent.emit(runFinishedEvent());
|
|
428
|
-
agent.complete();
|
|
429
|
-
|
|
430
|
-
await waitFor(() => {
|
|
431
|
-
expect(
|
|
432
|
-
document.querySelector(`[data-surface-id='${surfaceId}']`),
|
|
433
|
-
).not.toBeNull();
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
unmount();
|
|
437
|
-
agent.reset();
|
|
438
|
-
|
|
439
|
-
renderWithCopilotKit({
|
|
440
|
-
agent,
|
|
441
|
-
threadId,
|
|
442
|
-
renderActivityMessages: [a2uiRenderer],
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
await waitFor(() => {
|
|
446
|
-
expect(
|
|
447
|
-
document.querySelector(`[data-surface-id='${surfaceId}']`),
|
|
448
|
-
).not.toBeNull();
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
it("restores a completed A2UI surface from IntelligenceAgent /connect gateway replay", async () => {
|
|
453
|
-
const threadId = testId("intelligence-connect-thread");
|
|
454
|
-
const surfaceId = testId("intelligence-connect-surface");
|
|
455
|
-
const fetchMock = vi.fn().mockResolvedValueOnce(
|
|
456
|
-
jsonResponse({
|
|
457
|
-
threadId,
|
|
458
|
-
runId: null,
|
|
459
|
-
joinToken: "join-token-1",
|
|
460
|
-
realtime: {
|
|
461
|
-
clientUrl: "ws://localhost:4000/client",
|
|
462
|
-
topic: `thread:${threadId}`,
|
|
463
|
-
},
|
|
464
|
-
}),
|
|
465
|
-
);
|
|
466
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
467
|
-
mockPhoenixSockets.length = 0;
|
|
468
|
-
|
|
469
|
-
const agent = new IntelligenceAgent({
|
|
470
|
-
url: "ws://localhost:4000/client",
|
|
471
|
-
runtimeUrl: "http://localhost:4000",
|
|
472
|
-
agentId: "my-agent",
|
|
473
|
-
});
|
|
474
|
-
const a2uiRenderer = createA2UIMessageRenderer({
|
|
475
|
-
theme: {} as Theme,
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
renderWithCopilotKit({
|
|
480
|
-
agent,
|
|
481
|
-
threadId,
|
|
482
|
-
renderActivityMessages: [a2uiRenderer],
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
await waitFor(() => {
|
|
486
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
await waitFor(() => {
|
|
490
|
-
expect(mockPhoenixSockets).toHaveLength(1);
|
|
491
|
-
expect(mockPhoenixSockets[0]?.channels).toHaveLength(1);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
const channel = mockPhoenixSockets[0]!.channels[0]!;
|
|
495
|
-
expect(channel.topic).toBe(`thread:${threadId}`);
|
|
496
|
-
expect(channel.params).toEqual({
|
|
497
|
-
stream_mode: "connect",
|
|
498
|
-
last_seen_event_id: null,
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
channel.triggerJoin("ok");
|
|
502
|
-
channel.serverPush("ag_ui_event", {
|
|
503
|
-
type: EventType.RUN_STARTED,
|
|
504
|
-
threadId,
|
|
505
|
-
run_id: "backend-run-1",
|
|
506
|
-
input: {
|
|
507
|
-
messages: [
|
|
508
|
-
{
|
|
509
|
-
id: testId("connect-user-message"),
|
|
510
|
-
role: "user",
|
|
511
|
-
content: "show me the restored ui",
|
|
512
|
-
},
|
|
513
|
-
],
|
|
514
|
-
},
|
|
515
|
-
});
|
|
516
|
-
channel.serverPush("ag_ui_event", {
|
|
517
|
-
type: EventType.ACTIVITY_SNAPSHOT,
|
|
518
|
-
messageId: testId("connect-a2ui-activity"),
|
|
519
|
-
activityType: "a2ui-surface",
|
|
520
|
-
content: {
|
|
521
|
-
a2ui_operations: [
|
|
522
|
-
{
|
|
523
|
-
version: "v0.9",
|
|
524
|
-
createSurface: {
|
|
525
|
-
surfaceId,
|
|
526
|
-
catalogId:
|
|
527
|
-
"https://a2ui.org/specification/v0_9/basic_catalog.json",
|
|
528
|
-
},
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
version: "v0.9",
|
|
532
|
-
updateComponents: {
|
|
533
|
-
surfaceId,
|
|
534
|
-
components: [
|
|
535
|
-
{
|
|
536
|
-
id: "root",
|
|
537
|
-
component: "Text",
|
|
538
|
-
text: "Restored dashboard",
|
|
539
|
-
variant: "body",
|
|
540
|
-
},
|
|
541
|
-
],
|
|
542
|
-
},
|
|
543
|
-
},
|
|
544
|
-
],
|
|
545
|
-
},
|
|
546
|
-
});
|
|
547
|
-
channel.serverPush("ag_ui_event", {
|
|
548
|
-
type: EventType.RUN_FINISHED,
|
|
549
|
-
});
|
|
550
|
-
channel.serverPush("stream_idle", { latestEventId: "event-3" });
|
|
551
|
-
|
|
552
|
-
await waitFor(() => {
|
|
553
|
-
expect(screen.getByText("show me the restored ui")).toBeDefined();
|
|
554
|
-
});
|
|
555
|
-
await waitFor(() => {
|
|
556
|
-
expect(
|
|
557
|
-
document.querySelector(`[data-surface-id='${surfaceId}']`),
|
|
558
|
-
).not.toBeNull();
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
const [url, options] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
562
|
-
expect(url).toContain("/agent/my-agent/connect");
|
|
563
|
-
expect(options.method).toBe("POST");
|
|
564
|
-
|
|
565
|
-
const requestBody = JSON.parse(String(options.body)) as {
|
|
566
|
-
threadId: string;
|
|
567
|
-
lastSeenEventId: string | null;
|
|
568
|
-
messages: unknown[];
|
|
569
|
-
};
|
|
570
|
-
expect(requestBody.threadId).toBe(threadId);
|
|
571
|
-
expect(requestBody.lastSeenEventId).toBeNull();
|
|
572
|
-
expect(requestBody.messages).toEqual([]);
|
|
573
|
-
} finally {
|
|
574
|
-
vi.unstubAllGlobals();
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
it("restores a completed Open Generative UI activity after reconnect from an event-native baseline", async () => {
|
|
579
|
-
mockWebsandboxCreate.mockClear();
|
|
580
|
-
mockWebsandboxDestroy.mockClear();
|
|
581
|
-
|
|
582
|
-
const agent = new MockReconnectableAgent();
|
|
583
|
-
const threadId = testId("open-generative-ui-thread");
|
|
584
|
-
const restoredHtml =
|
|
585
|
-
"<head></head><body><div>Restored open generative UI</div></body>";
|
|
586
|
-
|
|
587
|
-
const renderOpenGenerativeUIChat = () =>
|
|
588
|
-
render(
|
|
589
|
-
<CopilotKitProvider
|
|
590
|
-
agents__unsafe_dev_only={{ default: agent }}
|
|
591
|
-
openGenerativeUI={{}}
|
|
592
|
-
>
|
|
593
|
-
<CopilotChatConfigurationProvider threadId={threadId}>
|
|
594
|
-
<div style={{ height: 400 }}>
|
|
595
|
-
<CopilotChat welcomeScreen={false} />
|
|
596
|
-
</div>
|
|
597
|
-
</CopilotChatConfigurationProvider>
|
|
598
|
-
</CopilotKitProvider>,
|
|
599
|
-
);
|
|
600
|
-
|
|
601
|
-
const { unmount } = renderOpenGenerativeUIChat();
|
|
602
|
-
|
|
603
|
-
const input = await screen.findByRole("textbox");
|
|
604
|
-
fireEvent.change(input, { target: { value: "Show me the restored app" } });
|
|
605
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
606
|
-
|
|
607
|
-
await waitFor(() => {
|
|
608
|
-
expect(screen.getByText("Show me the restored app")).toBeDefined();
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
agent.emit(runStartedEvent());
|
|
612
|
-
agent.emit(
|
|
613
|
-
activitySnapshotEvent({
|
|
614
|
-
messageId: testId("open-generative-ui-activity"),
|
|
615
|
-
activityType: "open-generative-ui",
|
|
616
|
-
content: {
|
|
617
|
-
initialHeight: 180,
|
|
618
|
-
generating: false,
|
|
619
|
-
html: [restoredHtml],
|
|
620
|
-
htmlComplete: true,
|
|
621
|
-
},
|
|
622
|
-
}),
|
|
623
|
-
);
|
|
624
|
-
agent.emit(runFinishedEvent());
|
|
625
|
-
agent.complete();
|
|
626
|
-
|
|
627
|
-
await waitFor(() => {
|
|
628
|
-
expect(mockWebsandboxCreate).toHaveBeenCalledTimes(1);
|
|
629
|
-
});
|
|
630
|
-
expect(mockWebsandboxCreate.mock.calls[0]?.[1]).toMatchObject({
|
|
631
|
-
frameContent: restoredHtml,
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
unmount();
|
|
635
|
-
|
|
636
|
-
agent.reset();
|
|
637
|
-
|
|
638
|
-
renderOpenGenerativeUIChat();
|
|
639
|
-
|
|
640
|
-
await waitFor(() => {
|
|
641
|
-
expect(mockWebsandboxCreate).toHaveBeenCalledTimes(2);
|
|
642
|
-
});
|
|
643
|
-
expect(mockWebsandboxCreate.mock.calls[1]?.[1]).toMatchObject({
|
|
644
|
-
frameContent: restoredHtml,
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
expect(mockWebsandboxDestroy).toHaveBeenCalledTimes(1);
|
|
648
|
-
});
|
|
649
|
-
});
|