@copilotkit/react-core 1.55.0-next.9 → 1.55.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 (81) hide show
  1. package/CHANGELOG.md +36 -6
  2. package/dist/{copilotkit-DeOzjPsb.mjs → copilotkit-BY5S1-0P.mjs} +2402 -552
  3. package/dist/copilotkit-BY5S1-0P.mjs.map +1 -0
  4. package/dist/{copilotkit-BqcyhQjT.d.mts → copilotkit-BuhSUZHb.d.mts} +228 -17
  5. package/dist/copilotkit-BuhSUZHb.d.mts.map +1 -0
  6. package/dist/{copilotkit-BDNjFNmk.cjs → copilotkit-Bz5-ImDl.cjs} +2421 -541
  7. package/dist/copilotkit-Bz5-ImDl.cjs.map +1 -0
  8. package/dist/{copilotkit-l-IBF4Xp.d.cts → copilotkit-dwDWYpya.d.cts} +228 -17
  9. package/dist/copilotkit-dwDWYpya.d.cts.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +1 -1
  14. package/dist/index.umd.js +1400 -238
  15. package/dist/index.umd.js.map +1 -1
  16. package/dist/v2/index.cjs +13 -1
  17. package/dist/v2/index.css +1 -1
  18. package/dist/v2/index.d.cts +3 -3
  19. package/dist/v2/index.d.mts +3 -3
  20. package/dist/v2/index.mjs +3 -2
  21. package/dist/v2/index.umd.js +2442 -552
  22. package/dist/v2/index.umd.js.map +1 -1
  23. package/package.json +62 -54
  24. package/scripts/scope-preflight.mjs +1 -2
  25. package/src/components/CopilotListeners.tsx +41 -8
  26. package/src/components/copilot-provider/copilotkit-props.tsx +4 -2
  27. package/src/components/toast/toast-provider.tsx +269 -194
  28. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +86 -22
  29. package/src/v2/__tests__/utils/test-helpers.tsx +67 -0
  30. package/src/v2/a2ui/A2UICatalogContext.tsx +79 -0
  31. package/src/v2/a2ui/A2UIMessageRenderer.tsx +125 -37
  32. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +290 -0
  33. package/src/v2/components/CopilotKitInspector.tsx +2 -0
  34. package/src/v2/components/OpenGenerativeUIRenderer.tsx +598 -0
  35. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +665 -0
  36. package/src/v2/components/chat/CopilotChat.tsx +193 -50
  37. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +17 -2
  38. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +481 -0
  39. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +139 -0
  40. package/src/v2/components/chat/CopilotChatInput.tsx +146 -77
  41. package/src/v2/components/chat/CopilotChatMessageView.tsx +253 -149
  42. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +1 -0
  43. package/src/v2/components/chat/CopilotChatUserMessage.tsx +54 -0
  44. package/src/v2/components/chat/CopilotChatView.tsx +179 -66
  45. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +168 -0
  46. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +63 -2
  47. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +544 -1
  48. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +268 -0
  49. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +249 -0
  50. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +43 -2
  51. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +138 -0
  52. package/src/v2/components/chat/index.ts +9 -0
  53. package/src/v2/components/chat/scroll-element-context.ts +13 -0
  54. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +1003 -0
  55. package/src/v2/hooks/__tests__/use-attachments.test.tsx +169 -0
  56. package/src/v2/hooks/__tests__/use-threads.test.tsx +54 -0
  57. package/src/v2/hooks/index.ts +5 -0
  58. package/src/v2/hooks/use-agent.tsx +95 -10
  59. package/src/v2/hooks/use-attachments.tsx +269 -0
  60. package/src/v2/hooks/use-frontend-tool.tsx +5 -2
  61. package/src/v2/hooks/use-render-activity-message.tsx +9 -2
  62. package/src/v2/hooks/use-threads.tsx +35 -15
  63. package/src/v2/index.ts +5 -1
  64. package/src/v2/lib/__tests__/processPartialHtml.test.ts +112 -0
  65. package/src/v2/lib/__tests__/slots.test.ts +56 -0
  66. package/src/v2/lib/processPartialHtml.ts +45 -0
  67. package/src/v2/lib/slots.tsx +42 -1
  68. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +9 -3
  69. package/src/v2/providers/CopilotKitProvider.tsx +268 -32
  70. package/src/v2/providers/SandboxFunctionsContext.ts +10 -0
  71. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +198 -0
  72. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +71 -0
  73. package/src/v2/providers/index.ts +7 -0
  74. package/src/v2/styles/globals.css +2 -1
  75. package/src/v2/types/index.ts +1 -0
  76. package/src/v2/types/sandbox-function.ts +11 -0
  77. package/dist/copilotkit-BDNjFNmk.cjs.map +0 -1
  78. package/dist/copilotkit-BqcyhQjT.d.mts.map +0 -1
  79. package/dist/copilotkit-DeOzjPsb.mjs.map +0 -1
  80. package/dist/copilotkit-l-IBF4Xp.d.cts.map +0 -1
  81. package/src/v2/components/__tests__/license-warning-banner.test.tsx +0 -46
@@ -0,0 +1,138 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
4
+ import { CopilotChat } from "../CopilotChat";
5
+ import { useAgent } from "../../../hooks/use-agent";
6
+ import { useCopilotKit } from "../../../providers/CopilotKitProvider";
7
+ import { useCopilotChatConfiguration } from "../../../providers/CopilotChatConfigurationProvider";
8
+ import { MockStepwiseAgent } from "../../../__tests__/utils/test-helpers";
9
+ import { CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
10
+
11
+ // Mock useAgent to inspect the props it receives
12
+ vi.mock("../../../hooks/use-agent", () => ({
13
+ useAgent: vi.fn(() => ({
14
+ agent: new MockStepwiseAgent(),
15
+ })),
16
+ }));
17
+
18
+ vi.mock("../../../providers/CopilotKitProvider", () => ({
19
+ useCopilotKit: vi.fn(),
20
+ useLicenseContext: vi.fn(() => ({
21
+ checkFeature: () => true,
22
+ })),
23
+ }));
24
+
25
+ vi.mock(
26
+ "../../../providers/CopilotChatConfigurationProvider",
27
+ async (importOriginal) => {
28
+ const actual =
29
+ await importOriginal<
30
+ typeof import("../../../providers/CopilotChatConfigurationProvider")
31
+ >();
32
+ return {
33
+ ...actual,
34
+ useCopilotChatConfiguration: vi.fn(() => undefined),
35
+ CopilotChatConfigurationProvider: ({
36
+ children,
37
+ }: {
38
+ children: React.ReactNode;
39
+ }) => <>{children}</>,
40
+ };
41
+ },
42
+ );
43
+
44
+ // Mock suggestions hook
45
+ vi.mock("../../../hooks/use-suggestions", () => ({
46
+ useSuggestions: vi.fn(() => ({ suggestions: [] })),
47
+ }));
48
+
49
+ // Mock attachments hook
50
+ vi.mock("../../../hooks/use-attachments", () => ({
51
+ useAttachments: vi.fn(() => ({
52
+ attachments: [],
53
+ enabled: false,
54
+ dragOver: false,
55
+ fileInputRef: { current: null },
56
+ containerRef: { current: null },
57
+ handleFileUpload: vi.fn(),
58
+ handleDragOver: vi.fn(),
59
+ handleDragLeave: vi.fn(),
60
+ handleDrop: vi.fn(),
61
+ removeAttachment: vi.fn(),
62
+ consumeAttachments: vi.fn(() => []),
63
+ })),
64
+ }));
65
+
66
+ const mockUseAgent = useAgent as ReturnType<typeof vi.fn>;
67
+ const mockUseCopilotKit = useCopilotKit as ReturnType<typeof vi.fn>;
68
+
69
+ /** Factory for the mock return value of useCopilotKit in CopilotChat tests */
70
+ function createMockChatContext(agent: MockStepwiseAgent) {
71
+ return {
72
+ copilotkit: {
73
+ getAgent: () => agent,
74
+ runtimeUrl: "http://localhost:3000/api/copilot",
75
+ runtimeConnectionStatus: CopilotKitCoreRuntimeConnectionStatus.Connected,
76
+ runtimeTransport: "rest",
77
+ headers: {},
78
+ agents: { [String(agent.agentId)]: agent },
79
+ connectAgent: vi.fn().mockResolvedValue(undefined),
80
+ subscribe: vi.fn(() => ({ unsubscribe: vi.fn() })),
81
+ audioFileTranscriptionEnabled: false,
82
+ },
83
+ executingToolCallIds: new Set(),
84
+ };
85
+ }
86
+
87
+ describe("CopilotChat throttleMs prop", () => {
88
+ let mockAgent: MockStepwiseAgent;
89
+
90
+ beforeEach(() => {
91
+ mockAgent = new MockStepwiseAgent();
92
+ mockAgent.agentId = "default";
93
+
94
+ mockUseAgent.mockReturnValue({ agent: mockAgent });
95
+ mockUseCopilotKit.mockReturnValue(createMockChatContext(mockAgent));
96
+ });
97
+
98
+ afterEach(() => {
99
+ vi.restoreAllMocks();
100
+ });
101
+
102
+ it("passes throttleMs prop to useAgent", () => {
103
+ render(<CopilotChat throttleMs={500} />);
104
+
105
+ expect(mockUseAgent).toHaveBeenCalledWith(
106
+ expect.objectContaining({
107
+ throttleMs: 500,
108
+ }),
109
+ );
110
+ });
111
+
112
+ it("passes undefined throttleMs when prop is not set", () => {
113
+ render(<CopilotChat />);
114
+
115
+ expect(mockUseAgent).toHaveBeenCalledWith(
116
+ expect.objectContaining({
117
+ throttleMs: undefined,
118
+ }),
119
+ );
120
+ });
121
+ });
122
+
123
+ describe("throttleMs type inheritance", () => {
124
+ it("CopilotSidebarProps includes throttleMs via CopilotChatProps", () => {
125
+ // Type-level assertion — if this compiles, the type includes throttleMs.
126
+ const sidebarProps: import("../CopilotSidebar").CopilotSidebarProps = {
127
+ throttleMs: 1000,
128
+ };
129
+ expect(sidebarProps.throttleMs).toBe(1000);
130
+ });
131
+
132
+ it("CopilotPopupProps includes throttleMs via CopilotChatProps", () => {
133
+ const popupProps: import("../CopilotPopup").CopilotPopupProps = {
134
+ throttleMs: 2000,
135
+ };
136
+ expect(popupProps.throttleMs).toBe(2000);
137
+ });
138
+ });
@@ -77,3 +77,12 @@ export {
77
77
  export { CopilotSidebar, type CopilotSidebarProps } from "./CopilotSidebar";
78
78
 
79
79
  export { CopilotPopup, type CopilotPopupProps } from "./CopilotPopup";
80
+
81
+ export { CopilotChatAttachmentQueue } from "./CopilotChatAttachmentQueue";
82
+ export { CopilotChatAttachmentRenderer } from "./CopilotChatAttachmentRenderer";
83
+
84
+ export type {
85
+ Attachment,
86
+ AttachmentsConfig,
87
+ AttachmentModality,
88
+ } from "@copilotkit/shared";
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * Provides the scroll container element to child components that need it for
5
+ * virtualization. Set by CopilotChatView.ScrollView; consumed by
6
+ * CopilotChatMessageView to feed useVirtualizer's getScrollElement.
7
+ *
8
+ * Carries the element itself (not a ref) so that context consumers re-render
9
+ * reactively when the scroll container is first mounted.
10
+ */
11
+ export const ScrollElementContext = React.createContext<HTMLElement | null>(
12
+ null,
13
+ );