@copilotkit/react-core 1.57.0 → 1.57.1-canary.1778272612

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 (86) hide show
  1. package/dist/{copilotkit-CPe2-340.mjs → copilotkit-3XTEoVQO.mjs} +1367 -1200
  2. package/dist/copilotkit-3XTEoVQO.mjs.map +1 -0
  3. package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BCJ2yvV6.d.mts} +68 -8
  4. package/dist/copilotkit-BCJ2yvV6.d.mts.map +1 -0
  5. package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-CBbSvze0.d.cts} +68 -8
  6. package/dist/copilotkit-CBbSvze0.d.cts.map +1 -0
  7. package/dist/{copilotkit-DGbvw8n2.cjs → copilotkit-Dnj9pi4m.cjs} +1369 -1196
  8. package/dist/copilotkit-Dnj9pi4m.cjs.map +1 -0
  9. package/dist/index.cjs +2 -5
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +2 -5
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +733 -610
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/context.cjs +135 -0
  18. package/dist/v2/context.cjs.map +1 -0
  19. package/dist/v2/context.d.cts +148 -0
  20. package/dist/v2/context.d.cts.map +1 -0
  21. package/dist/v2/context.d.mts +148 -0
  22. package/dist/v2/context.d.mts.map +1 -0
  23. package/dist/v2/context.mjs +129 -0
  24. package/dist/v2/context.mjs.map +1 -0
  25. package/dist/v2/headless.cjs +1043 -0
  26. package/dist/v2/headless.cjs.map +1 -0
  27. package/dist/v2/headless.d.cts +605 -0
  28. package/dist/v2/headless.d.cts.map +1 -0
  29. package/dist/v2/headless.d.mts +512 -0
  30. package/dist/v2/headless.d.mts.map +1 -0
  31. package/dist/v2/headless.mjs +997 -0
  32. package/dist/v2/headless.mjs.map +1 -0
  33. package/dist/v2/index.cjs +2 -1
  34. package/dist/v2/index.css +1 -1
  35. package/dist/v2/index.d.cts +2 -2
  36. package/dist/v2/index.d.mts +2 -2
  37. package/dist/v2/index.mjs +2 -2
  38. package/dist/v2/index.umd.js +1385 -1204
  39. package/dist/v2/index.umd.js.map +1 -1
  40. package/package.json +14 -6
  41. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
  42. package/src/hooks/use-copilot-chat_internal.ts +0 -1
  43. package/src/v2/components/chat/CopilotChat.tsx +2 -1
  44. package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
  45. package/src/v2/components/chat/CopilotChatView.tsx +2 -2
  46. package/src/v2/components/chat/CopilotSidebar.tsx +5 -1
  47. package/src/v2/components/chat/CopilotSidebarView.tsx +24 -10
  48. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
  49. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
  50. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +159 -0
  51. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
  52. package/src/v2/components/index.ts +1 -0
  53. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
  54. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
  55. package/src/v2/components/intelligence-indicator/index.ts +2 -0
  56. package/src/v2/context.ts +62 -0
  57. package/src/v2/headless.ts +42 -0
  58. package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
  59. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
  60. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
  61. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
  62. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
  63. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
  64. package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
  65. package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
  66. package/src/v2/hooks/use-agent-context.tsx +1 -1
  67. package/src/v2/hooks/use-agent.tsx +9 -118
  68. package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
  69. package/src/v2/hooks/use-default-render-tool.tsx +18 -1
  70. package/src/v2/hooks/use-frontend-tool.tsx +2 -2
  71. package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
  72. package/src/v2/hooks/use-interrupt.tsx +1 -1
  73. package/src/v2/hooks/use-render-activity-message.tsx +3 -11
  74. package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
  75. package/src/v2/hooks/use-render-tool-call.tsx +36 -6
  76. package/src/v2/hooks/use-render-tool.tsx +2 -2
  77. package/src/v2/hooks/use-suggestions.tsx +1 -1
  78. package/src/v2/hooks/use-threads.tsx +1 -1
  79. package/src/v2/providers/CopilotKitProvider.tsx +19 -59
  80. package/src/v2/styles/globals.css +118 -0
  81. package/tsdown.config.ts +75 -0
  82. package/dist/copilotkit-CPe2-340.mjs.map +0 -1
  83. package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
  84. package/dist/copilotkit-DGbvw8n2.cjs.map +0 -1
  85. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
  86. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-core",
3
- "version": "1.57.0",
3
+ "version": "1.57.1-canary.1778272612",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -46,6 +46,14 @@
46
46
  "require": "./dist/v2/index.cjs"
47
47
  },
48
48
  "./package.json": "./package.json",
49
+ "./v2/context": {
50
+ "import": "./dist/v2/context.mjs",
51
+ "require": "./dist/v2/context.cjs"
52
+ },
53
+ "./v2/headless": {
54
+ "import": "./dist/v2/headless.mjs",
55
+ "require": "./dist/v2/headless.cjs"
56
+ },
49
57
  "./v2/styles.css": "./dist/v2/index.css"
50
58
  },
51
59
  "publishConfig": {
@@ -73,11 +81,11 @@
73
81
  "untruncate-json": "^0.0.1",
74
82
  "use-stick-to-bottom": "^1.1.1",
75
83
  "zod-to-json-schema": "^3.24.5",
76
- "@copilotkit/core": "1.57.0",
77
- "@copilotkit/shared": "1.57.0",
78
- "@copilotkit/a2ui-renderer": "1.57.0",
79
- "@copilotkit/runtime-client-gql": "1.57.0",
80
- "@copilotkit/web-inspector": "1.57.0"
84
+ "@copilotkit/a2ui-renderer": "1.57.1-canary.1778272612",
85
+ "@copilotkit/runtime-client-gql": "1.57.1-canary.1778272612",
86
+ "@copilotkit/core": "1.57.1-canary.1778272612",
87
+ "@copilotkit/shared": "1.57.1-canary.1778272612",
88
+ "@copilotkit/web-inspector": "1.57.1-canary.1778272612"
81
89
  },
82
90
  "devDependencies": {
83
91
  "@tailwindcss/cli": "^4.1.11",
@@ -179,10 +179,9 @@ describe("useCopilotChatInternal – connectAgent guard", () => {
179
179
  });
180
180
 
181
181
  it("does not call connectAgent when threadId matches (same agent instance, no re-render)", async () => {
182
- // useAgent now returns a per-thread clone, so the wrapper guards via
183
- // lastConnectedAgentRef: connect fires once per agent instance, not once
184
- // per render. After the first connect, further re-renders with the same
185
- // agent do not trigger another connect.
182
+ // The wrapper guards via lastConnectedAgentRef: connect fires once per
183
+ // agent instance, not once per render. After the first connect, further
184
+ // re-renders with the same agent do not trigger another connect.
186
185
  mockRuntimeConnectionStatus =
187
186
  CopilotKitCoreRuntimeConnectionStatus.Connected;
188
187
  mockAgent.threadId = "config-thread-id";
@@ -230,13 +229,13 @@ describe("useCopilotChatInternal – connectAgent guard", () => {
230
229
  });
231
230
  });
232
231
 
233
- it("passes config threadId to useAgent", () => {
232
+ it("passes resolved agentId to useAgent", () => {
234
233
  applyMocks();
235
234
 
236
235
  renderHook(() => useCopilotChatInternal(), { wrapper: createWrapper() });
237
236
 
238
237
  expect(vi.mocked(useAgent)).toHaveBeenCalledWith(
239
- expect.objectContaining({ threadId: "config-thread-id" }),
238
+ expect.objectContaining({ agentId: "test-agent" }),
240
239
  );
241
240
  });
242
241
  });
@@ -339,7 +339,6 @@ export function useCopilotChatInternal({
339
339
  const resolvedAgentId = existingConfig?.agentId ?? "default";
340
340
  const { agent } = useAgent({
341
341
  agentId: resolvedAgentId,
342
- threadId: existingConfig?.threadId,
343
342
  });
344
343
 
345
344
  // Track the last agent instance we called connect() on. Without this,
@@ -118,7 +118,6 @@ export function CopilotChat({
118
118
 
119
119
  const { agent } = useAgent({
120
120
  agentId: resolvedAgentId,
121
- threadId: resolvedThreadId,
122
121
  throttleMs,
123
122
  });
124
123
  const { copilotkit } = useCopilotKit();
@@ -235,6 +234,8 @@ export function CopilotChat({
235
234
  agent.abortController = connectAbortController;
236
235
  }
237
236
 
237
+ agent.threadId = resolvedThreadId;
238
+
238
239
  const connect = async (agent: AbstractAgent) => {
239
240
  try {
240
241
  await copilotkit.connectAgent({ agent });
@@ -8,11 +8,12 @@ import React, {
8
8
  } from "react";
9
9
  import { useVirtualizer } from "@tanstack/react-virtual";
10
10
  import { ScrollElementContext } from "./scroll-element-context";
11
- import { WithSlots, renderSlot, isReactComponentType } from "../../lib/slots";
11
+ import type { WithSlots } from "../../lib/slots";
12
+ import { renderSlot, isReactComponentType } from "../../lib/slots";
12
13
  import CopilotChatAssistantMessage from "./CopilotChatAssistantMessage";
13
14
  import CopilotChatUserMessage from "./CopilotChatUserMessage";
14
15
  import CopilotChatReasoningMessage from "./CopilotChatReasoningMessage";
15
- import {
16
+ import type {
16
17
  ActivityMessage,
17
18
  AssistantMessage,
18
19
  Message,
@@ -22,9 +23,10 @@ import {
22
23
  } from "@ag-ui/core";
23
24
  import { twMerge } from "tailwind-merge";
24
25
  import { useRenderActivityMessage, useRenderCustomMessages } from "../../hooks";
25
- import { getThreadClone } from "../../hooks/use-agent";
26
26
  import { useCopilotKit } from "../../providers/CopilotKitProvider";
27
27
  import { useCopilotChatConfiguration } from "../../providers/CopilotChatConfigurationProvider";
28
+ import { IntelligenceIndicator } from "../intelligence-indicator";
29
+ import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
28
30
 
29
31
  /**
30
32
  * Resolves a slot value into a { Component, slotProps } pair, handling the three
@@ -392,18 +394,14 @@ export function CopilotChatMessageView({
392
394
  // Subscribe to state changes so custom message renderers re-render when state updates.
393
395
  useEffect(() => {
394
396
  if (!config?.agentId) return;
395
- const registryAgent = copilotkit.getAgent(config.agentId);
396
- // Prefer the per-thread clone so that state changes from the running agent
397
- // (which is the clone, not the registry) trigger re-renders.
398
- const agent =
399
- getThreadClone(registryAgent, config.threadId) ?? registryAgent;
397
+ const agent = copilotkit.getAgent(config.agentId);
400
398
  if (!agent) return;
401
399
 
402
400
  const subscription = agent.subscribe({
403
401
  onStateChanged: forceUpdate,
404
402
  });
405
403
  return () => subscription.unsubscribe();
406
- }, [config?.agentId, config?.threadId, copilotkit, forceUpdate]);
404
+ }, [config?.agentId, copilotkit, forceUpdate]);
407
405
 
408
406
  // Subscribe to interrupt element changes for in-chat rendering.
409
407
  const [interruptElement, setInterruptElement] =
@@ -608,6 +606,23 @@ export function CopilotChatMessageView({
608
606
  );
609
607
  }
610
608
 
609
+ // Auto-mount the IntelligenceIndicator on assistant message slots
610
+ // when the runtime is in intelligence mode. The component self-gates
611
+ // further (latest matching-assistant slot, pending tool-call grace
612
+ // window) so only one pill renders at a time — mounting only for
613
+ // assistant messages avoids the per-slot `useAgent` subscription
614
+ // and four effects on user/reasoning/activity slots that would just
615
+ // return null at the role gate anyway.
616
+ if (copilotkit.intelligence !== undefined && message.role === "assistant") {
617
+ elements.push(
618
+ <IntelligenceIndicator
619
+ key={`${message.id}-intelligence`}
620
+ message={message}
621
+ agentId={config?.agentId ?? DEFAULT_AGENT_ID}
622
+ />,
623
+ );
624
+ }
625
+
611
626
  return elements.filter(Boolean) as React.ReactElement[];
612
627
  };
613
628
 
@@ -89,8 +89,8 @@ export type CopilotChatViewProps = WithSlots<
89
89
  /**
90
90
  * When `true`, suppresses the welcome screen while a thread's initial
91
91
  * connect is in flight. Prevents the "How can I help you today?" flash
92
- * that would otherwise appear between mounting an empty cloned agent and
93
- * the bootstrap messages arriving from /connect.
92
+ * that would otherwise appear between mounting an empty agent instance
93
+ * and the bootstrap messages arriving from /connect.
94
94
  */
95
95
  isConnecting?: boolean;
96
96
  /**
@@ -14,6 +14,7 @@ export type CopilotSidebarProps = Omit<CopilotChatProps, "chatView"> & {
14
14
  toggleButton?: CopilotSidebarViewProps["toggleButton"];
15
15
  defaultOpen?: boolean;
16
16
  width?: number | string;
17
+ position?: CopilotSidebarViewProps["position"];
17
18
  };
18
19
 
19
20
  export function CopilotSidebar({
@@ -21,6 +22,7 @@ export function CopilotSidebar({
21
22
  toggleButton,
22
23
  defaultOpen,
23
24
  width,
25
+ position,
24
26
  ...chatProps
25
27
  }: CopilotSidebarProps) {
26
28
  const { checkFeature } = useLicenseContext();
@@ -41,6 +43,7 @@ export function CopilotSidebar({
41
43
  toggleButton: viewToggleButton,
42
44
  width: viewWidth,
43
45
  defaultOpen: viewDefaultOpen,
46
+ position: viewPosition,
44
47
  ...restProps
45
48
  } = viewProps as CopilotSidebarViewProps;
46
49
 
@@ -51,12 +54,13 @@ export function CopilotSidebar({
51
54
  toggleButton={toggleButton ?? viewToggleButton}
52
55
  width={width ?? viewWidth}
53
56
  defaultOpen={defaultOpen ?? viewDefaultOpen}
57
+ position={position ?? viewPosition}
54
58
  />
55
59
  );
56
60
  };
57
61
 
58
62
  return Object.assign(Component, CopilotChatView);
59
- }, [header, toggleButton, width, defaultOpen]);
63
+ }, [header, toggleButton, width, defaultOpen, position]);
60
64
 
61
65
  return (
62
66
  <>
@@ -21,6 +21,7 @@ export type CopilotSidebarViewProps = CopilotChatViewProps & {
21
21
  toggleButton?: SlotValue<typeof CopilotChatToggleButton>;
22
22
  width?: number | string;
23
23
  defaultOpen?: boolean;
24
+ position?: "left" | "right";
24
25
  };
25
26
 
26
27
  export function CopilotSidebarView({
@@ -28,6 +29,7 @@ export function CopilotSidebarView({
28
29
  toggleButton,
29
30
  width,
30
31
  defaultOpen = true,
32
+ position = "right",
31
33
  ...props
32
34
  }: CopilotSidebarViewProps) {
33
35
  return (
@@ -36,6 +38,7 @@ export function CopilotSidebarView({
36
38
  header={header}
37
39
  toggleButton={toggleButton}
38
40
  width={width}
41
+ position={position}
39
42
  {...props}
40
43
  />
41
44
  </CopilotChatConfigurationProvider>
@@ -46,6 +49,7 @@ function CopilotSidebarViewInternal({
46
49
  header,
47
50
  toggleButton,
48
51
  width,
52
+ position = "right",
49
53
  ...props
50
54
  }: Omit<CopilotSidebarViewProps, "defaultOpen">) {
51
55
  const configuration = useCopilotChatConfiguration();
@@ -118,29 +122,34 @@ function CopilotSidebarViewInternal({
118
122
  return;
119
123
  if (!window.matchMedia("(min-width: 768px)").matches) return;
120
124
 
125
+ const marginStyleProp =
126
+ position === "left" ? "marginInlineStart" : "marginInlineEnd";
127
+ const transitionCssProp =
128
+ position === "left" ? "margin-inline-start" : "margin-inline-end";
129
+
121
130
  if (isSidebarOpen) {
122
131
  if (hasMounted.current) {
123
- document.body.style.transition = `margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease`;
132
+ document.body.style.transition = `${transitionCssProp} ${SIDEBAR_TRANSITION_MS}ms ease`;
124
133
  }
125
- document.body.style.marginInlineEnd = widthToMargin(sidebarWidth);
134
+ document.body.style[marginStyleProp] = widthToMargin(sidebarWidth);
126
135
  } else if (hasMounted.current) {
127
- document.body.style.transition = `margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease`;
128
- document.body.style.marginInlineEnd = "";
136
+ document.body.style.transition = `${transitionCssProp} ${SIDEBAR_TRANSITION_MS}ms ease`;
137
+ document.body.style[marginStyleProp] = "";
129
138
  }
130
139
 
131
140
  hasMounted.current = true;
132
141
 
133
142
  return () => {
134
- document.body.style.marginInlineEnd = "";
143
+ document.body.style[marginStyleProp] = "";
135
144
  document.body.style.transition = "";
136
145
  };
137
- }, [isSidebarOpen, sidebarWidth]);
146
+ }, [isSidebarOpen, sidebarWidth, position]);
138
147
 
139
148
  const headerElement = renderSlot(header, CopilotModalHeader, {});
140
149
  const toggleButtonElement = renderSlot(
141
150
  toggleButton,
142
151
  CopilotChatToggleButton,
143
- {},
152
+ position === "left" ? { className: "cpk:left-6 cpk:right-auto" } : {},
144
153
  );
145
154
 
146
155
  return (
@@ -151,18 +160,23 @@ function CopilotSidebarViewInternal({
151
160
  data-copilotkit
152
161
  data-testid="copilot-sidebar"
153
162
  data-copilot-sidebar
163
+ data-position={position}
154
164
  className={cn(
155
165
  "copilotKitSidebar copilotKitWindow",
156
- "cpk:fixed cpk:right-0 cpk:top-0 cpk:z-[1200] cpk:flex",
166
+ "cpk:fixed cpk:top-0 cpk:z-[1200] cpk:flex",
167
+ position === "left" ? "cpk:left-0" : "cpk:right-0",
157
168
  // Height with dvh fallback and safe area support
158
169
  "cpk:h-[100vh] cpk:h-[100dvh] cpk:max-h-screen",
159
170
  // Responsive width: full on mobile, custom on desktop
160
171
  "cpk:w-full",
161
- "cpk:border-l cpk:border-border cpk:bg-background cpk:text-foreground cpk:shadow-xl",
172
+ position === "left" ? "cpk:border-r" : "cpk:border-l",
173
+ "cpk:border-border cpk:bg-background cpk:text-foreground cpk:shadow-xl",
162
174
  "cpk:transition-transform cpk:duration-300 cpk:ease-out",
163
175
  isSidebarOpen
164
176
  ? "cpk:translate-x-0"
165
- : "cpk:translate-x-full cpk:pointer-events-none",
177
+ : position === "left"
178
+ ? "cpk:-translate-x-full cpk:pointer-events-none"
179
+ : "cpk:translate-x-full cpk:pointer-events-none",
166
180
  )}
167
181
  style={
168
182
  {
@@ -9,8 +9,7 @@ import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
9
9
 
10
10
  /**
11
11
  * Mock agent that records every connectAgent() invocation and resolves
12
- * immediately with an empty run result. Tracking lives on the class so
13
- * per-thread clones (from useAgent's WeakMap) share the counter.
12
+ * immediately with an empty run result.
14
13
  */
15
14
  class TrackingAgent extends MockStepwiseAgent {
16
15
  static connectCalls: Array<{
@@ -107,7 +106,6 @@ describe("CopilotChat welcome / connect integration", () => {
107
106
  expect(TrackingAgent.connectCalls.length).toBeGreaterThan(0);
108
107
  });
109
108
 
110
- // The per-thread clone carries threadId; agentId is the default.
111
109
  expect(
112
110
  TrackingAgent.connectCalls.some((c) => c.threadId === "real-thread"),
113
111
  ).toBe(true);
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
3
3
  import { z } from "zod";
4
+ import type { AbstractAgent } from "@ag-ui/client";
4
5
  import { EventType } from "@ag-ui/client";
5
6
  import {
6
7
  MockReconnectableAgent,
@@ -17,9 +18,7 @@ import {
17
18
  CopilotKitProvider,
18
19
  useCopilotKit,
19
20
  } from "../../../providers";
20
- import type { AbstractAgent } from "@ag-ui/client";
21
21
  import { IntelligenceAgent } from "@copilotkit/core";
22
- import { getThreadClone } from "../../../hooks/use-agent";
23
22
  import { createA2UIMessageRenderer } from "../../../a2ui/A2UIMessageRenderer";
24
23
  import type { Theme } from "@copilotkit/a2ui-renderer";
25
24
  import { CopilotChat } from "..";
@@ -306,18 +305,28 @@ describe("CopilotChat activity message rendering", () => {
306
305
  expect(capturedCopilotkit).toBeDefined();
307
306
  });
308
307
 
309
- it("passes the per-thread clone (not the registry agent) to activity message renderers", async () => {
310
- // Regression test for: A2UI button clicks firing runAgent on the registry
311
- // agent instead of the per-thread clone that CopilotChat renders from.
312
- // Caused by useRenderActivityMessage calling copilotkit.getAgent() directly
313
- // instead of getThreadClone(registryAgent, threadId) ?? registryAgent.
314
- const agent = new MockStepwiseAgent();
315
- const agentId = "action-agent";
316
- agent.agentId = agentId;
317
- const threadId = "thread-for-action-test";
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";
318
328
 
319
329
  let capturedAgent: AbstractAgent | undefined;
320
-
321
330
  const activityRenderer: ReactActivityMessageRenderer<{ label: string }> = {
322
331
  activityType: "button-action",
323
332
  content: z.object({ label: z.string() }),
@@ -328,9 +337,9 @@ describe("CopilotChat activity message rendering", () => {
328
337
  };
329
338
 
330
339
  renderWithCopilotKit({
331
- agents: { [agentId]: agent },
332
- agentId,
333
- threadId,
340
+ agents: { "chat-1": localAgent, default: otherAgent },
341
+ agentId: "chat-1",
342
+ threadId: "thread-for-action-test",
334
343
  renderActivityMessages: [activityRenderer],
335
344
  });
336
345
 
@@ -342,27 +351,22 @@ describe("CopilotChat activity message rendering", () => {
342
351
  expect(screen.getByText("show me buttons")).toBeDefined();
343
352
  });
344
353
 
345
- agent.emit(runStartedEvent());
346
- agent.emit(
354
+ localAgent.emit(runStartedEvent());
355
+ localAgent.emit(
347
356
  activitySnapshotEvent({
348
357
  messageId: testId("activity-action"),
349
358
  activityType: "button-action",
350
359
  content: { label: "Click Me" },
351
360
  }),
352
361
  );
353
- agent.emit(runFinishedEvent());
362
+ localAgent.emit(runFinishedEvent());
354
363
 
355
364
  await waitFor(() => {
356
365
  expect(screen.getByTestId("action-button")).toBeDefined();
357
366
  });
358
367
 
359
- // CopilotChat creates a per-thread clone via useAgent. The activity renderer
360
- // must receive that clone so that handleAction → runAgent targets the same
361
- // instance chat is rendering from.
362
- const clone = getThreadClone(agent, threadId);
363
- expect(clone).toBeDefined();
364
- expect(capturedAgent).toBe(clone);
365
- expect(capturedAgent).not.toBe(agent); // must NOT be the registry agent
368
+ expect(capturedAgent).toBe(localAgent);
369
+ expect(capturedAgent).not.toBe(otherAgent);
366
370
  });
367
371
 
368
372
  it("restores a completed A2UI surface after reconnect from an event-native baseline", async () => {
@@ -0,0 +1,159 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, it, expect } from "vitest";
4
+ import { CopilotSidebarView } from "../CopilotSidebarView";
5
+ import { CopilotSidebar } from "../CopilotSidebar";
6
+ import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
7
+ import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
8
+ import {
9
+ MockStepwiseAgent,
10
+ renderWithCopilotKit,
11
+ } from "../../../__tests__/utils/test-helpers";
12
+
13
+ const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
14
+ <CopilotKitProvider>
15
+ <CopilotChatConfigurationProvider threadId="test-thread">
16
+ {children}
17
+ </CopilotChatConfigurationProvider>
18
+ </CopilotKitProvider>
19
+ );
20
+
21
+ const sampleMessages = [{ id: "1", role: "user" as const, content: "Hello" }];
22
+
23
+ function getSidebarAside(container: HTMLElement) {
24
+ const sidebar = container.querySelector("[data-copilot-sidebar]");
25
+ if (!sidebar) throw new Error("sidebar aside not found");
26
+ return sidebar;
27
+ }
28
+
29
+ describe("CopilotSidebarView position prop", () => {
30
+ describe("CopilotSidebarView", () => {
31
+ it("defaults to right-anchored when position is omitted", () => {
32
+ const { container } = render(
33
+ <TestWrapper>
34
+ <CopilotSidebarView messages={sampleMessages} />
35
+ </TestWrapper>,
36
+ );
37
+
38
+ const aside = getSidebarAside(container);
39
+ expect(aside.classList.contains("cpk:right-0")).toBe(true);
40
+ expect(aside.classList.contains("cpk:border-l")).toBe(true);
41
+ expect(aside.classList.contains("cpk:left-0")).toBe(false);
42
+ expect(aside.classList.contains("cpk:border-r")).toBe(false);
43
+ });
44
+
45
+ it('renders right-anchored when position="right" explicitly', () => {
46
+ const { container } = render(
47
+ <TestWrapper>
48
+ <CopilotSidebarView messages={sampleMessages} position="right" />
49
+ </TestWrapper>,
50
+ );
51
+
52
+ const aside = getSidebarAside(container);
53
+ expect(aside.classList.contains("cpk:right-0")).toBe(true);
54
+ expect(aside.classList.contains("cpk:border-l")).toBe(true);
55
+ expect(aside.classList.contains("cpk:left-0")).toBe(false);
56
+ expect(aside.classList.contains("cpk:border-r")).toBe(false);
57
+ });
58
+
59
+ it('renders left-anchored when position="left"', () => {
60
+ const { container } = render(
61
+ <TestWrapper>
62
+ <CopilotSidebarView messages={sampleMessages} position="left" />
63
+ </TestWrapper>,
64
+ );
65
+
66
+ const aside = getSidebarAside(container);
67
+ expect(aside.classList.contains("cpk:left-0")).toBe(true);
68
+ expect(aside.classList.contains("cpk:border-r")).toBe(true);
69
+ expect(aside.classList.contains("cpk:right-0")).toBe(false);
70
+ expect(aside.classList.contains("cpk:border-l")).toBe(false);
71
+ });
72
+
73
+ it('translates off-screen to the right when closed and position="right"', () => {
74
+ const { container } = render(
75
+ <TestWrapper>
76
+ <CopilotSidebarView
77
+ messages={sampleMessages}
78
+ defaultOpen={false}
79
+ position="right"
80
+ />
81
+ </TestWrapper>,
82
+ );
83
+
84
+ const aside = getSidebarAside(container);
85
+ expect(aside.classList.contains("cpk:translate-x-full")).toBe(true);
86
+ expect(aside.classList.contains("cpk:-translate-x-full")).toBe(false);
87
+ });
88
+
89
+ it('translates off-screen to the left when closed and position="left"', () => {
90
+ const { container } = render(
91
+ <TestWrapper>
92
+ <CopilotSidebarView
93
+ messages={sampleMessages}
94
+ defaultOpen={false}
95
+ position="left"
96
+ />
97
+ </TestWrapper>,
98
+ );
99
+
100
+ const aside = getSidebarAside(container);
101
+ expect(aside.classList.contains("cpk:-translate-x-full")).toBe(true);
102
+ expect(aside.classList.contains("cpk:translate-x-full")).toBe(false);
103
+ });
104
+
105
+ it('anchors the toggle button to the left when position="left"', () => {
106
+ const { container } = render(
107
+ <TestWrapper>
108
+ <CopilotSidebarView messages={sampleMessages} position="left" />
109
+ </TestWrapper>,
110
+ );
111
+
112
+ const toggle = container.querySelector(
113
+ '[data-slot="chat-toggle-button"]',
114
+ );
115
+ if (!toggle) throw new Error("toggle button not found");
116
+ expect(toggle.classList.contains("cpk:left-6")).toBe(true);
117
+ expect(toggle.classList.contains("cpk:right-auto")).toBe(true);
118
+ });
119
+
120
+ it("keeps the toggle button right-anchored by default", () => {
121
+ const { container } = render(
122
+ <TestWrapper>
123
+ <CopilotSidebarView messages={sampleMessages} />
124
+ </TestWrapper>,
125
+ );
126
+
127
+ const toggle = container.querySelector(
128
+ '[data-slot="chat-toggle-button"]',
129
+ );
130
+ if (!toggle) throw new Error("toggle button not found");
131
+ expect(toggle.classList.contains("cpk:right-6")).toBe(true);
132
+ expect(toggle.classList.contains("cpk:left-6")).toBe(false);
133
+ });
134
+ });
135
+
136
+ describe("CopilotSidebar wrapper", () => {
137
+ it('forwards position="left" through to CopilotSidebarView', () => {
138
+ const { container } = renderWithCopilotKit({
139
+ agent: new MockStepwiseAgent(),
140
+ children: <CopilotSidebar position="left" />,
141
+ });
142
+
143
+ const aside = getSidebarAside(container);
144
+ expect(aside.classList.contains("cpk:left-0")).toBe(true);
145
+ expect(aside.classList.contains("cpk:border-r")).toBe(true);
146
+ });
147
+
148
+ it("defaults to right-anchored when position is omitted", () => {
149
+ const { container } = renderWithCopilotKit({
150
+ agent: new MockStepwiseAgent(),
151
+ children: <CopilotSidebar />,
152
+ });
153
+
154
+ const aside = getSidebarAside(container);
155
+ expect(aside.classList.contains("cpk:right-0")).toBe(true);
156
+ expect(aside.classList.contains("cpk:border-l")).toBe(true);
157
+ });
158
+ });
159
+ });