@copilotkit/react-core 1.54.1-next.6 → 1.55.0-next.7
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/CHANGELOG.md +121 -106
- package/dist/copilotkit-B3Mb1yVE.cjs +7975 -0
- package/dist/copilotkit-B3Mb1yVE.cjs.map +1 -0
- package/dist/copilotkit-DBzgOMby.d.cts +2182 -0
- package/dist/copilotkit-DBzgOMby.d.cts.map +1 -0
- package/dist/copilotkit-DNYSFuz5.mjs +7562 -0
- package/dist/copilotkit-DNYSFuz5.mjs.map +1 -0
- package/dist/copilotkit-Dy5w3qEV.d.mts +2182 -0
- package/dist/copilotkit-Dy5w3qEV.d.mts.map +1 -0
- package/dist/index.cjs +27 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -5
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1941 -35
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +77 -7
- package/dist/v2/index.css +1 -2
- package/dist/v2/index.d.cts +6 -4
- package/dist/v2/index.d.mts +6 -4
- package/dist/v2/index.mjs +7 -4
- package/dist/v2/index.umd.js +5725 -24
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +35 -7
- package/scripts/scope-preflight.mjs +101 -0
- package/src/components/CopilotListeners.tsx +2 -6
- package/src/components/copilot-provider/copilot-messages.tsx +1 -1
- package/src/components/copilot-provider/copilotkit-props.tsx +1 -1
- package/src/components/copilot-provider/copilotkit.tsx +4 -4
- package/src/context/copilot-messages-context.tsx +1 -1
- package/src/hooks/__tests__/use-coagent-config.test.ts +2 -2
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +2 -2
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +3 -7
- package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +1 -1
- package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +4 -4
- package/src/hooks/use-agent-nodename.ts +1 -1
- package/src/hooks/use-coagent-state-render-bridge.tsx +1 -4
- package/src/hooks/use-coagent.ts +1 -1
- package/src/hooks/use-configure-chat-suggestions.tsx +2 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +2 -2
- package/src/hooks/use-copilot-chat_internal.ts +2 -2
- package/src/hooks/use-copilot-readable.ts +1 -1
- package/src/hooks/use-frontend-tool.ts +2 -2
- package/src/hooks/use-human-in-the-loop.ts +2 -2
- package/src/hooks/use-langgraph-interrupt.ts +2 -5
- package/src/hooks/use-lazy-tool-renderer.tsx +1 -1
- package/src/hooks/use-render-tool-call.ts +1 -1
- package/src/lib/copilot-task.ts +1 -1
- package/src/setupTests.ts +18 -14
- package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +176 -0
- package/src/v2/__tests__/globalSetup.ts +14 -0
- package/src/v2/__tests__/setup.ts +93 -0
- package/src/v2/__tests__/utils/test-helpers.tsx +470 -0
- package/src/v2/a2ui/A2UIMessageRenderer.tsx +206 -0
- package/src/v2/components/CopilotKitInspector.tsx +50 -0
- package/src/v2/components/MCPAppsActivityRenderer.tsx +785 -0
- package/src/v2/components/WildcardToolCallRender.tsx +86 -0
- package/src/v2/components/__tests__/license-warning-banner.test.tsx +46 -0
- package/src/v2/components/chat/CopilotChat.tsx +431 -0
- package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +375 -0
- package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +350 -0
- package/src/v2/components/chat/CopilotChatInput.tsx +1302 -0
- package/src/v2/components/chat/CopilotChatMessageView.tsx +556 -0
- package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +252 -0
- package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +59 -0
- package/src/v2/components/chat/CopilotChatSuggestionView.tsx +133 -0
- package/src/v2/components/chat/CopilotChatToggleButton.tsx +171 -0
- package/src/v2/components/chat/CopilotChatToolCallsView.tsx +40 -0
- package/src/v2/components/chat/CopilotChatUserMessage.tsx +388 -0
- package/src/v2/components/chat/CopilotChatView.tsx +598 -0
- package/src/v2/components/chat/CopilotModalHeader.tsx +129 -0
- package/src/v2/components/chat/CopilotPopup.tsx +81 -0
- package/src/v2/components/chat/CopilotPopupView.tsx +317 -0
- package/src/v2/components/chat/CopilotSidebar.tsx +76 -0
- package/src/v2/components/chat/CopilotSidebarView.tsx +255 -0
- package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +1113 -0
- package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +73 -0
- package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +432 -0
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +150 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +624 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +702 -0
- package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +107 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +929 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +986 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +1004 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +169 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +530 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +782 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +2413 -0
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +621 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +853 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +1050 -0
- package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +484 -0
- package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +612 -0
- package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +502 -0
- package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +1011 -0
- package/src/v2/components/chat/__tests__/setup.ts +1 -0
- package/src/v2/components/chat/index.ts +79 -0
- package/src/v2/components/index.ts +7 -0
- package/src/v2/components/license-warning-banner.tsx +198 -0
- package/src/v2/components/ui/button.tsx +123 -0
- package/src/v2/components/ui/dropdown-menu.tsx +258 -0
- package/src/v2/components/ui/tooltip.tsx +60 -0
- package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +152 -0
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +282 -0
- package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +132 -0
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +401 -0
- package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +44 -0
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +205 -0
- package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +148 -0
- package/src/v2/hooks/__tests__/use-component.test.tsx +123 -0
- package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +696 -0
- package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +153 -0
- package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +167 -0
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +2129 -0
- package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +1261 -0
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +397 -0
- package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +56 -0
- package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +192 -0
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +259 -0
- package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +524 -0
- package/src/v2/hooks/__tests__/use-threads.test.tsx +433 -0
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +311 -0
- package/src/v2/hooks/index.ts +18 -0
- package/src/v2/hooks/use-agent-context.tsx +45 -0
- package/src/v2/hooks/use-agent.tsx +155 -0
- package/src/v2/hooks/use-component.tsx +89 -0
- package/src/v2/hooks/use-configure-suggestions.tsx +187 -0
- package/src/v2/hooks/use-default-render-tool.tsx +254 -0
- package/src/v2/hooks/use-frontend-tool.tsx +43 -0
- package/src/v2/hooks/use-human-in-the-loop.tsx +81 -0
- package/src/v2/hooks/use-interrupt.tsx +305 -0
- package/src/v2/hooks/use-keyboard-height.tsx +67 -0
- package/src/v2/hooks/use-render-activity-message.tsx +73 -0
- package/src/v2/hooks/use-render-custom-messages.tsx +93 -0
- package/src/v2/hooks/use-render-tool-call.tsx +175 -0
- package/src/v2/hooks/use-render-tool.tsx +181 -0
- package/src/v2/hooks/use-suggestions.tsx +91 -0
- package/src/v2/hooks/use-threads.tsx +256 -0
- package/src/v2/hooks/useKatexStyles.ts +27 -0
- package/src/v2/index.css +1 -1
- package/src/v2/index.ts +18 -2
- package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +495 -0
- package/src/v2/lib/__tests__/renderSlot.test.tsx +588 -0
- package/src/v2/lib/react-core.ts +156 -0
- package/src/v2/lib/slots.tsx +143 -0
- package/src/v2/lib/transcription-client.ts +184 -0
- package/src/v2/lib/utils.ts +8 -0
- package/src/v2/providers/CopilotChatConfigurationProvider.tsx +162 -0
- package/src/v2/providers/CopilotKitProvider.tsx +600 -0
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +546 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +101 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +69 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +881 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +740 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +642 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +294 -0
- package/src/v2/providers/index.ts +14 -0
- package/src/v2/styles/globals.css +230 -0
- package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +525 -0
- package/src/v2/types/defineToolCallRenderer.ts +65 -0
- package/src/v2/types/frontend-tool.ts +8 -0
- package/src/v2/types/human-in-the-loop.ts +33 -0
- package/src/v2/types/index.ts +7 -0
- package/src/v2/types/interrupt.ts +15 -0
- package/src/v2/types/react-activity-message-renderer.ts +27 -0
- package/src/v2/types/react-custom-message-renderer.ts +17 -0
- package/src/v2/types/react-tool-call-renderer.ts +32 -0
- package/tsdown.config.ts +34 -10
- package/vitest.config.mjs +4 -3
- package/LICENSE +0 -21
- package/dist/copilotkit-BRPQ2sqS.d.cts +0 -670
- package/dist/copilotkit-BRPQ2sqS.d.cts.map +0 -1
- package/dist/copilotkit-C94ayZbs.cjs +0 -2161
- package/dist/copilotkit-C94ayZbs.cjs.map +0 -1
- package/dist/copilotkit-CwZMFmSK.d.mts +0 -670
- package/dist/copilotkit-CwZMFmSK.d.mts.map +0 -1
- package/dist/copilotkit-Yh_Ld_FX.mjs +0 -2031
- package/dist/copilotkit-Yh_Ld_FX.mjs.map +0 -1
- package/dist/v2/index.css.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, it, expect, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
MockStepwiseAgent,
|
|
5
|
+
renderWithCopilotKit,
|
|
6
|
+
} from "../../../__tests__/utils/test-helpers";
|
|
7
|
+
import { CopilotChat } from "../CopilotChat";
|
|
8
|
+
import { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
9
|
+
import { type BaseEvent, type RunAgentInput } from "@ag-ui/client";
|
|
10
|
+
import { Observable, EMPTY } from "rxjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Mock agent whose connect() always fails
|
|
14
|
+
*/
|
|
15
|
+
class FailingConnectAgent extends MockStepwiseAgent {
|
|
16
|
+
run(input: RunAgentInput): Observable<BaseEvent> {
|
|
17
|
+
return super.run(input);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
connect(_input: RunAgentInput): Observable<BaseEvent> {
|
|
21
|
+
return new Observable((subscriber) => {
|
|
22
|
+
subscriber.error(new Error("connect failed"));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Mock agent whose connect() succeeds (returns empty observable)
|
|
29
|
+
*/
|
|
30
|
+
class HealthyConnectAgent extends MockStepwiseAgent {
|
|
31
|
+
run(input: RunAgentInput): Observable<BaseEvent> {
|
|
32
|
+
return super.run(input);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
connect(_input: RunAgentInput): Observable<BaseEvent> {
|
|
36
|
+
return EMPTY;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("CopilotChat onError", () => {
|
|
41
|
+
it("connectAgent failure fires onError on CopilotChat and does not crash", async () => {
|
|
42
|
+
const agent = new FailingConnectAgent();
|
|
43
|
+
const chatOnError = vi.fn();
|
|
44
|
+
|
|
45
|
+
renderWithCopilotKit({
|
|
46
|
+
agent,
|
|
47
|
+
children: <CopilotChat welcomeScreen={false} onError={chatOnError} />,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Wait for the connectAgent error to propagate
|
|
51
|
+
await vi.waitFor(() => {
|
|
52
|
+
expect(chatOnError).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Check that AGENT_CONNECT_FAILED is among the errors
|
|
56
|
+
const allCodes = chatOnError.mock.calls.map((c: any) => c[0].code);
|
|
57
|
+
expect(allCodes).toContain(CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("onError on CopilotChat does not fire for a healthy agent", async () => {
|
|
61
|
+
const agent = new HealthyConnectAgent();
|
|
62
|
+
const chatOnError = vi.fn();
|
|
63
|
+
|
|
64
|
+
renderWithCopilotKit({
|
|
65
|
+
agent,
|
|
66
|
+
children: <CopilotChat welcomeScreen={false} onError={chatOnError} />,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// No errors should fire for a healthy agent
|
|
70
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
71
|
+
expect(chatOnError).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
import { CopilotChat } from "../CopilotChat";
|
|
5
|
+
import { CopilotChatView } from "../CopilotChatView";
|
|
6
|
+
import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
|
|
7
|
+
import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
|
|
8
|
+
import { MockStepwiseAgent } from "../../../__tests__/utils/test-helpers";
|
|
9
|
+
|
|
10
|
+
// Create a mock agent for testing
|
|
11
|
+
const createMockAgent = () => new MockStepwiseAgent();
|
|
12
|
+
|
|
13
|
+
// Wrapper to provide required context with mock agent
|
|
14
|
+
const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
15
|
+
const mockAgent = createMockAgent();
|
|
16
|
+
return (
|
|
17
|
+
<CopilotKitProvider agents__unsafe_dev_only={{ default: mockAgent }}>
|
|
18
|
+
<CopilotChatConfigurationProvider threadId="test-thread">
|
|
19
|
+
{children}
|
|
20
|
+
</CopilotChatConfigurationProvider>
|
|
21
|
+
</CopilotKitProvider>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe("CopilotChat Slot System E2E Tests", () => {
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// 1. TAILWIND CLASS TESTS - CHATVIEW SLOT
|
|
28
|
+
// ============================================================================
|
|
29
|
+
describe("1. Tailwind Class Slot Override - chatView Slot", () => {
|
|
30
|
+
describe("chatView slot", () => {
|
|
31
|
+
it("should apply tailwind class string to chatView", () => {
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<TestWrapper>
|
|
34
|
+
<CopilotChat chatView="bg-gradient-to-b from-white to-gray-50 rounded-xl shadow-2xl" />
|
|
35
|
+
</TestWrapper>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const chatView = container.querySelector(".bg-gradient-to-b");
|
|
39
|
+
expect(chatView).toBeDefined();
|
|
40
|
+
expect(chatView?.classList.contains("rounded-xl")).toBe(true);
|
|
41
|
+
expect(chatView?.classList.contains("shadow-2xl")).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should apply custom background color via tailwind class", () => {
|
|
45
|
+
const { container } = render(
|
|
46
|
+
<TestWrapper>
|
|
47
|
+
<CopilotChat chatView="bg-blue-50" />
|
|
48
|
+
</TestWrapper>,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const chatView = container.querySelector(".bg-blue-50");
|
|
52
|
+
expect(chatView).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// 2. PROPERTY PASSING TESTS - CHATVIEW SLOT
|
|
59
|
+
// ============================================================================
|
|
60
|
+
describe("2. Property Passing - chatView Slot", () => {
|
|
61
|
+
describe("chatView slot", () => {
|
|
62
|
+
it("should pass custom props to chatView", () => {
|
|
63
|
+
render(
|
|
64
|
+
<TestWrapper>
|
|
65
|
+
<CopilotChat chatView={{ "data-testid": "custom-chat-view" }} />
|
|
66
|
+
</TestWrapper>,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const chatView = screen.queryByTestId("custom-chat-view");
|
|
70
|
+
expect(chatView).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should pass className through props object", () => {
|
|
74
|
+
const { container } = render(
|
|
75
|
+
<TestWrapper>
|
|
76
|
+
<CopilotChat chatView={{ className: "custom-class-from-props" }} />
|
|
77
|
+
</TestWrapper>,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const chatView = container.querySelector(".custom-class-from-props");
|
|
81
|
+
expect(chatView).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ============================================================================
|
|
87
|
+
// 3. CUSTOM COMPONENT TESTS - CHATVIEW SLOT
|
|
88
|
+
// ============================================================================
|
|
89
|
+
describe("3. Custom Component - chatView Slot", () => {
|
|
90
|
+
it("should allow custom component for chatView", () => {
|
|
91
|
+
const CustomChatView: React.FC<any> = ({
|
|
92
|
+
messages,
|
|
93
|
+
isRunning,
|
|
94
|
+
...props
|
|
95
|
+
}) => (
|
|
96
|
+
<div data-testid="custom-chat-view-component" {...props}>
|
|
97
|
+
<div className="custom-header">Custom Chat Interface</div>
|
|
98
|
+
<div className="messages-area">
|
|
99
|
+
{messages?.map((m: any) => (
|
|
100
|
+
<div key={m.id} className="message">
|
|
101
|
+
{m.content}
|
|
102
|
+
</div>
|
|
103
|
+
))}
|
|
104
|
+
</div>
|
|
105
|
+
<div className="custom-footer">
|
|
106
|
+
{isRunning ? "Processing..." : "Ready"}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
render(
|
|
112
|
+
<TestWrapper>
|
|
113
|
+
<CopilotChat chatView={CustomChatView as any} />
|
|
114
|
+
</TestWrapper>,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const custom = screen.queryByTestId("custom-chat-view-component");
|
|
118
|
+
expect(custom).toBeDefined();
|
|
119
|
+
expect(custom?.textContent).toContain("Custom Chat Interface");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should pass messages to custom chatView component", () => {
|
|
123
|
+
const receivedProps: any[] = [];
|
|
124
|
+
const CustomChatView: React.FC<any> = (props) => {
|
|
125
|
+
receivedProps.push(props);
|
|
126
|
+
return (
|
|
127
|
+
<div data-testid="custom-view">
|
|
128
|
+
Messages: {props.messages?.length ?? 0}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
render(
|
|
134
|
+
<TestWrapper>
|
|
135
|
+
<CopilotChat chatView={CustomChatView as any} />
|
|
136
|
+
</TestWrapper>,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(receivedProps.length).toBeGreaterThan(0);
|
|
140
|
+
expect(receivedProps[0]).toHaveProperty("messages");
|
|
141
|
+
expect(receivedProps[0]).toHaveProperty("isRunning");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should pass all CopilotChatView props to custom component", () => {
|
|
145
|
+
const receivedProps: any[] = [];
|
|
146
|
+
const CustomChatView: React.FC<any> = (props) => {
|
|
147
|
+
receivedProps.push(props);
|
|
148
|
+
return <div data-testid="custom-view" />;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
render(
|
|
152
|
+
<TestWrapper>
|
|
153
|
+
<CopilotChat chatView={CustomChatView as any} />
|
|
154
|
+
</TestWrapper>,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(receivedProps.length).toBeGreaterThan(0);
|
|
158
|
+
const props = receivedProps[0];
|
|
159
|
+
// Check that standard CopilotChatViewProps are passed
|
|
160
|
+
expect(props).toHaveProperty("messages");
|
|
161
|
+
expect(props).toHaveProperty("isRunning");
|
|
162
|
+
expect(props).toHaveProperty("onSubmitMessage");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ============================================================================
|
|
167
|
+
// 4. DRILL-DOWN INTO CHATVIEW SUB-SLOTS VIA PROPS OBJECT
|
|
168
|
+
// ============================================================================
|
|
169
|
+
describe("4. Drill-down into CopilotChatView Sub-slots via Props Object", () => {
|
|
170
|
+
it("should allow customizing nested messageView slot via props", () => {
|
|
171
|
+
const { container } = render(
|
|
172
|
+
<TestWrapper>
|
|
173
|
+
<CopilotChat
|
|
174
|
+
chatView={{
|
|
175
|
+
messageView: "custom-message-view-class",
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
</TestWrapper>,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const messageView = container.querySelector(".custom-message-view-class");
|
|
182
|
+
expect(messageView).toBeDefined();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should allow customizing nested input slot via props", () => {
|
|
186
|
+
const { container } = render(
|
|
187
|
+
<TestWrapper>
|
|
188
|
+
<CopilotChat
|
|
189
|
+
chatView={{
|
|
190
|
+
input: "custom-input-class border-2 border-green-400",
|
|
191
|
+
}}
|
|
192
|
+
/>
|
|
193
|
+
</TestWrapper>,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const input = container.querySelector(".custom-input-class");
|
|
197
|
+
expect(input).toBeDefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should allow customizing nested scrollView slot via props", () => {
|
|
201
|
+
const { container } = render(
|
|
202
|
+
<TestWrapper>
|
|
203
|
+
<CopilotChat
|
|
204
|
+
chatView={{
|
|
205
|
+
scrollView: "custom-scroll-view",
|
|
206
|
+
}}
|
|
207
|
+
/>
|
|
208
|
+
</TestWrapper>,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const scrollView = container.querySelector(".custom-scroll-view");
|
|
212
|
+
expect(scrollView).toBeDefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("should allow customizing nested input slot via props", () => {
|
|
216
|
+
const { container } = render(
|
|
217
|
+
<TestWrapper>
|
|
218
|
+
<CopilotChat
|
|
219
|
+
chatView={{
|
|
220
|
+
input: "custom-input bg-slate-100",
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
</TestWrapper>,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const input = container.querySelector(".custom-input");
|
|
227
|
+
expect(input).toBeDefined();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// ============================================================================
|
|
232
|
+
// 5. CUSTOM CHATVIEW COMPONENT
|
|
233
|
+
// ============================================================================
|
|
234
|
+
describe("5. Custom ChatView Component for Complex Customization", () => {
|
|
235
|
+
it("should allow custom chatView component with full control", () => {
|
|
236
|
+
const CustomChatView: React.FC<any> = (props) => (
|
|
237
|
+
<div data-testid="fully-custom-chat" className="custom-chat-layout">
|
|
238
|
+
<CopilotChatView
|
|
239
|
+
{...props}
|
|
240
|
+
messageView="custom-message-from-wrapper"
|
|
241
|
+
input="custom-input-from-wrapper"
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const { container } = render(
|
|
247
|
+
<TestWrapper>
|
|
248
|
+
<CopilotChat chatView={CustomChatView as any} />
|
|
249
|
+
</TestWrapper>,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
expect(screen.queryByTestId("fully-custom-chat")).toBeDefined();
|
|
253
|
+
expect(container.querySelector(".custom-chat-layout")).toBeDefined();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// ============================================================================
|
|
258
|
+
// 6. CLASSNAME OVERRIDE TESTS
|
|
259
|
+
// ============================================================================
|
|
260
|
+
describe("6. className Override with Tailwind Strings", () => {
|
|
261
|
+
it("should apply tailwind string to chatView as className", () => {
|
|
262
|
+
const { container } = render(
|
|
263
|
+
<TestWrapper>
|
|
264
|
+
<CopilotChat chatView="h-full min-h-0 flex flex-col" />
|
|
265
|
+
</TestWrapper>,
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const chatView = container.querySelector(".h-full");
|
|
269
|
+
expect(chatView).toBeDefined();
|
|
270
|
+
expect(chatView?.classList.contains("min-h-0")).toBe(true);
|
|
271
|
+
expect(chatView?.classList.contains("flex-col")).toBe(true);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("should merge chatView tailwind classes with CopilotChatView defaults", () => {
|
|
275
|
+
const { container } = render(
|
|
276
|
+
<TestWrapper>
|
|
277
|
+
<CopilotChat chatView="custom-override-class" />
|
|
278
|
+
</TestWrapper>,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const chatView = container.querySelector(".custom-override-class");
|
|
282
|
+
expect(chatView).toBeDefined();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// 7. COPILOTCHAT-SPECIFIC PROPS
|
|
288
|
+
// ============================================================================
|
|
289
|
+
describe("7. CopilotChat-specific Props", () => {
|
|
290
|
+
it("should support agentId prop", () => {
|
|
291
|
+
// Create wrapper with the custom-agent registered
|
|
292
|
+
const customAgent = createMockAgent();
|
|
293
|
+
const { container } = render(
|
|
294
|
+
<CopilotKitProvider
|
|
295
|
+
agents__unsafe_dev_only={{
|
|
296
|
+
default: createMockAgent(),
|
|
297
|
+
"custom-agent": customAgent,
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
<CopilotChatConfigurationProvider threadId="test-thread">
|
|
301
|
+
<CopilotChat agentId="custom-agent" />
|
|
302
|
+
</CopilotChatConfigurationProvider>
|
|
303
|
+
</CopilotKitProvider>,
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
// Component should render without errors
|
|
307
|
+
expect(container.firstChild).toBeDefined();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("should support threadId prop", () => {
|
|
311
|
+
const { container } = render(
|
|
312
|
+
<TestWrapper>
|
|
313
|
+
<CopilotChat threadId="custom-thread-123" />
|
|
314
|
+
</TestWrapper>,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
expect(container.firstChild).toBeDefined();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("should support labels prop for customization", () => {
|
|
321
|
+
render(
|
|
322
|
+
<TestWrapper>
|
|
323
|
+
<CopilotChat
|
|
324
|
+
labels={{
|
|
325
|
+
chatInputPlaceholder: "Custom placeholder text...",
|
|
326
|
+
}}
|
|
327
|
+
/>
|
|
328
|
+
</TestWrapper>,
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const input = screen.queryByPlaceholderText("Custom placeholder text...");
|
|
332
|
+
expect(input).toBeDefined();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// ============================================================================
|
|
337
|
+
// 8. INTEGRATION TESTS
|
|
338
|
+
// ============================================================================
|
|
339
|
+
describe("8. Integration Tests", () => {
|
|
340
|
+
it("should render CopilotChat with all default components", () => {
|
|
341
|
+
const { container } = render(
|
|
342
|
+
<TestWrapper>
|
|
343
|
+
<CopilotChat />
|
|
344
|
+
</TestWrapper>,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// Should render the chat interface
|
|
348
|
+
expect(container.firstChild).toBeDefined();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("should combine chatView customization with nested slot customization via props", () => {
|
|
352
|
+
const { container } = render(
|
|
353
|
+
<TestWrapper>
|
|
354
|
+
<CopilotChat
|
|
355
|
+
chatView={{
|
|
356
|
+
className: "root-chat-view",
|
|
357
|
+
messageView: "custom-messages",
|
|
358
|
+
input: "custom-input",
|
|
359
|
+
scrollView: "custom-scroll",
|
|
360
|
+
}}
|
|
361
|
+
/>
|
|
362
|
+
</TestWrapper>,
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
expect(container.querySelector(".root-chat-view")).toBeDefined();
|
|
366
|
+
expect(container.querySelector(".custom-messages")).toBeDefined();
|
|
367
|
+
expect(container.querySelector(".custom-input")).toBeDefined();
|
|
368
|
+
expect(container.querySelector(".custom-scroll")).toBeDefined();
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("should work with mixed props and tailwind classes", () => {
|
|
372
|
+
const { container } = render(
|
|
373
|
+
<TestWrapper>
|
|
374
|
+
<CopilotChat
|
|
375
|
+
chatView={{
|
|
376
|
+
className: "mixed-class",
|
|
377
|
+
}}
|
|
378
|
+
/>
|
|
379
|
+
</TestWrapper>,
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
const chatView = container.querySelector(".mixed-class");
|
|
383
|
+
expect(chatView).toBeDefined();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("should handle transcription-related props", () => {
|
|
387
|
+
const { container } = render(
|
|
388
|
+
<TestWrapper>
|
|
389
|
+
<CopilotChat />
|
|
390
|
+
</TestWrapper>,
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
// Component should render without errors even with transcription features
|
|
394
|
+
expect(container.firstChild).toBeDefined();
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// ============================================================================
|
|
399
|
+
// 9. CALLBACK AND HANDLER TESTS
|
|
400
|
+
// ============================================================================
|
|
401
|
+
describe("9. Callback and Handler Tests", () => {
|
|
402
|
+
it("should render CopilotChat and allow callback customization via custom component", () => {
|
|
403
|
+
const onSubmitMessage = vi.fn();
|
|
404
|
+
const CustomChatView: React.FC<any> = (props) => {
|
|
405
|
+
// Use the provided onSubmitMessage or our custom one
|
|
406
|
+
return <CopilotChatView {...props} onSubmitMessage={onSubmitMessage} />;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
render(
|
|
410
|
+
<TestWrapper>
|
|
411
|
+
<CopilotChat chatView={CustomChatView as any} />
|
|
412
|
+
</TestWrapper>,
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// The component should render without errors
|
|
416
|
+
expect(onSubmitMessage).not.toHaveBeenCalled();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it("should support suggestions rendering", () => {
|
|
420
|
+
// Note: CopilotChat manages suggestions internally via useAutoSuggestions
|
|
421
|
+
// We test that the chatView slot receives and renders suggestions
|
|
422
|
+
render(
|
|
423
|
+
<TestWrapper>
|
|
424
|
+
<CopilotChat />
|
|
425
|
+
</TestWrapper>,
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
// CopilotChat should render without errors
|
|
429
|
+
// Actual suggestion rendering depends on agent state
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import {
|
|
5
|
+
MockStepwiseAgent,
|
|
6
|
+
activitySnapshotEvent,
|
|
7
|
+
renderWithCopilotKit,
|
|
8
|
+
runFinishedEvent,
|
|
9
|
+
runStartedEvent,
|
|
10
|
+
testId,
|
|
11
|
+
} from "../../../__tests__/utils/test-helpers";
|
|
12
|
+
import { ReactActivityMessageRenderer } from "../../../types";
|
|
13
|
+
import { useCopilotKit } from "../../../providers";
|
|
14
|
+
|
|
15
|
+
describe("CopilotChat activity message rendering", () => {
|
|
16
|
+
it("renders custom components for activity snapshots", async () => {
|
|
17
|
+
const agent = new MockStepwiseAgent();
|
|
18
|
+
const agentId = "search-agent";
|
|
19
|
+
agent.agentId = agentId;
|
|
20
|
+
|
|
21
|
+
const activityRenderer: ReactActivityMessageRenderer<{
|
|
22
|
+
status: string;
|
|
23
|
+
percent: number;
|
|
24
|
+
}> = {
|
|
25
|
+
activityType: "search-progress",
|
|
26
|
+
content: z.object({ status: z.string(), percent: z.number() }),
|
|
27
|
+
render: ({ content, agent }) => (
|
|
28
|
+
<div data-testid="activity-card">
|
|
29
|
+
{content.status} · {content.percent}% · {agent?.agentId}
|
|
30
|
+
</div>
|
|
31
|
+
),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
renderWithCopilotKit({
|
|
35
|
+
agents: { [agentId]: agent },
|
|
36
|
+
agentId,
|
|
37
|
+
renderActivityMessages: [activityRenderer],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const input = await screen.findByRole("textbox");
|
|
41
|
+
fireEvent.change(input, { target: { value: "Start search" } });
|
|
42
|
+
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
43
|
+
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(screen.getByText("Start search")).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const activityMessageId = testId("activity");
|
|
49
|
+
agent.emit(runStartedEvent());
|
|
50
|
+
agent.emit(
|
|
51
|
+
activitySnapshotEvent({
|
|
52
|
+
messageId: activityMessageId,
|
|
53
|
+
activityType: "search-progress",
|
|
54
|
+
content: { status: "Fetching", percent: 30 },
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
agent.emit(runFinishedEvent());
|
|
58
|
+
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
const textContent = screen.getByTestId("activity-card").textContent ?? "";
|
|
61
|
+
expect(textContent).toContain("Fetching");
|
|
62
|
+
expect(textContent).toContain(agentId);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("skips unmatched activity types when no renderer exists", async () => {
|
|
67
|
+
const agent = new MockStepwiseAgent();
|
|
68
|
+
|
|
69
|
+
renderWithCopilotKit({
|
|
70
|
+
agent,
|
|
71
|
+
renderActivityMessages: [],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const input = await screen.findByRole("textbox");
|
|
75
|
+
fireEvent.change(input, { target: { value: "Start search" } });
|
|
76
|
+
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
77
|
+
|
|
78
|
+
await waitFor(() => {
|
|
79
|
+
expect(screen.getByText("Start search")).toBeDefined();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const activityMessageId = testId("activity-unmatched");
|
|
83
|
+
agent.emit(runStartedEvent());
|
|
84
|
+
agent.emit(
|
|
85
|
+
activitySnapshotEvent({
|
|
86
|
+
messageId: activityMessageId,
|
|
87
|
+
activityType: "unknown",
|
|
88
|
+
content: { note: "no-op" },
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
agent.emit(runFinishedEvent());
|
|
92
|
+
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(screen.queryByTestId("activity-card")).toBeNull();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("useCopilotKit provides valid copilotkit instance inside activity message renderer", async () => {
|
|
99
|
+
const agent = new MockStepwiseAgent();
|
|
100
|
+
const agentId = "test-agent";
|
|
101
|
+
agent.agentId = agentId;
|
|
102
|
+
|
|
103
|
+
let capturedCopilotkit: any = "not-called";
|
|
104
|
+
|
|
105
|
+
// Matches real-world pattern: inline arrow function with hooks
|
|
106
|
+
const activityRenderer: ReactActivityMessageRenderer<{ message: string }> =
|
|
107
|
+
{
|
|
108
|
+
activityType: "test-activity",
|
|
109
|
+
content: z.object({ message: z.string() }),
|
|
110
|
+
render: ({ content }) => {
|
|
111
|
+
const { copilotkit } = useCopilotKit();
|
|
112
|
+
capturedCopilotkit = copilotkit;
|
|
113
|
+
return <div data-testid="activity-render">{content.message}</div>;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
renderWithCopilotKit({
|
|
118
|
+
agents: { [agentId]: agent },
|
|
119
|
+
agentId,
|
|
120
|
+
renderActivityMessages: [activityRenderer],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Trigger user message and activity event
|
|
124
|
+
const input = await screen.findByRole("textbox");
|
|
125
|
+
fireEvent.change(input, { target: { value: "Test message" } });
|
|
126
|
+
fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
|
|
127
|
+
|
|
128
|
+
await waitFor(() => {
|
|
129
|
+
expect(screen.getByText("Test message")).toBeDefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
agent.emit(runStartedEvent());
|
|
133
|
+
agent.emit(
|
|
134
|
+
activitySnapshotEvent({
|
|
135
|
+
messageId: testId("activity"),
|
|
136
|
+
activityType: "test-activity",
|
|
137
|
+
content: { message: "Rendered content" },
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
agent.emit(runFinishedEvent());
|
|
141
|
+
|
|
142
|
+
await waitFor(() => {
|
|
143
|
+
expect(screen.getByTestId("activity-render")).toBeDefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Verify context is properly propagated - copilotkit should NOT be null
|
|
147
|
+
expect(capturedCopilotkit).not.toBeNull();
|
|
148
|
+
expect(capturedCopilotkit).toBeDefined();
|
|
149
|
+
});
|
|
150
|
+
});
|