@copilotkit/react-core 1.56.1 → 1.56.2-canary.test-welcome-screen

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 (57) hide show
  1. package/dist/{copilotkit-CSJw5BG8.cjs → copilotkit-By2G6-Zx.cjs} +250 -63
  2. package/dist/copilotkit-By2G6-Zx.cjs.map +1 -0
  3. package/dist/{copilotkit-CCbxm6JM.d.mts → copilotkit-DFaI4j2r.d.mts} +64 -18
  4. package/dist/copilotkit-DFaI4j2r.d.mts.map +1 -0
  5. package/dist/{copilotkit-BtP7w7cT.d.cts → copilotkit-Dg4r4Gi_.d.cts} +64 -18
  6. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +1 -0
  7. package/dist/{copilotkit-Cj2ZIxVr.mjs → copilotkit-PzJlPKcU.mjs} +251 -64
  8. package/dist/copilotkit-PzJlPKcU.mjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +2 -1
  11. package/dist/index.d.cts.map +1 -1
  12. package/dist/index.d.mts +2 -1
  13. package/dist/index.d.mts.map +1 -1
  14. package/dist/index.mjs +1 -1
  15. package/dist/index.umd.js +31 -44
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/index.cjs +1 -1
  18. package/dist/v2/index.css +1 -1
  19. package/dist/v2/index.d.cts +2 -2
  20. package/dist/v2/index.d.mts +2 -2
  21. package/dist/v2/index.mjs +1 -1
  22. package/dist/v2/index.umd.js +249 -66
  23. package/dist/v2/index.umd.js.map +1 -1
  24. package/package.json +6 -6
  25. package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +107 -0
  26. package/src/components/copilot-provider/copilotkit.tsx +6 -1
  27. package/src/context/__tests__/threads-context.test.tsx +116 -3
  28. package/src/context/threads-context.tsx +18 -1
  29. package/src/v2/components/chat/CopilotChat.tsx +91 -4
  30. package/src/v2/components/chat/CopilotChatInput.tsx +22 -0
  31. package/src/v2/components/chat/CopilotChatView.tsx +206 -11
  32. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +66 -0
  33. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +186 -0
  34. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +300 -2
  35. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +56 -0
  36. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +94 -0
  37. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -1
  38. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +37 -0
  39. package/src/v2/components/chat/index.ts +2 -0
  40. package/src/v2/components/chat/last-user-message-context.ts +21 -0
  41. package/src/v2/components/chat/normalize-auto-scroll.ts +17 -0
  42. package/src/v2/components/license-warning-banner.tsx +20 -1
  43. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +6 -0
  44. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +6 -0
  45. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +76 -50
  46. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +219 -0
  47. package/src/v2/hooks/__tests__/use-threads.test.tsx +68 -0
  48. package/src/v2/hooks/use-agent.tsx +34 -77
  49. package/src/v2/hooks/use-pin-to-send.ts +94 -0
  50. package/src/v2/hooks/use-threads.tsx +55 -12
  51. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +29 -1
  52. package/src/v2/providers/CopilotKitProvider.tsx +2 -11
  53. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +106 -0
  54. package/dist/copilotkit-BtP7w7cT.d.cts.map +0 -1
  55. package/dist/copilotkit-CCbxm6JM.d.mts.map +0 -1
  56. package/dist/copilotkit-CSJw5BG8.cjs.map +0 -1
  57. package/dist/copilotkit-Cj2ZIxVr.mjs.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
- import { fireEvent, screen, waitFor } from "@testing-library/react";
2
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
3
3
  import { z } from "zod";
4
4
  import {
5
+ MockReconnectableAgent,
5
6
  MockStepwiseAgent,
6
7
  activitySnapshotEvent,
7
8
  renderWithCopilotKit,
@@ -10,9 +11,48 @@ import {
10
11
  testId,
11
12
  } from "../../../__tests__/utils/test-helpers";
12
13
  import { ReactActivityMessageRenderer } from "../../../types";
13
- import { useCopilotKit } from "../../../providers";
14
+ import {
15
+ CopilotChatConfigurationProvider,
16
+ CopilotKitProvider,
17
+ useCopilotKit,
18
+ } from "../../../providers";
14
19
  import { AbstractAgent } from "@ag-ui/client";
20
+ import { IntelligenceAgent } from "@copilotkit/core";
15
21
  import { getThreadClone } from "../../../hooks/use-agent";
22
+ import { createA2UIMessageRenderer } from "../../../a2ui/A2UIMessageRenderer";
23
+ import type { Theme } from "@copilotkit/a2ui-renderer";
24
+ import { CopilotChat } from "..";
25
+
26
+ const { mockWebsandboxCreate, mockWebsandboxDestroy } = vi.hoisted(() => {
27
+ const mockDestroy = vi.fn();
28
+ const mockCreate = vi.fn(() => ({
29
+ iframe: document.createElement("iframe"),
30
+ promise: Promise.resolve(),
31
+ run: vi.fn().mockResolvedValue(undefined),
32
+ destroy: mockDestroy,
33
+ }));
34
+
35
+ return {
36
+ mockWebsandboxCreate: mockCreate,
37
+ mockWebsandboxDestroy: mockDestroy,
38
+ };
39
+ });
40
+
41
+ vi.mock("@jetbrains/websandbox", () => ({
42
+ default: {
43
+ create: (...args: unknown[]) => mockWebsandboxCreate(...args),
44
+ },
45
+ }));
46
+
47
+ function jsonResponse(body: unknown, status = 200): Response {
48
+ return {
49
+ ok: status >= 200 && status < 300,
50
+ status,
51
+ statusText: status === 200 ? "OK" : "Error",
52
+ json: async () => body,
53
+ text: async () => JSON.stringify(body),
54
+ } as Response;
55
+ }
16
56
 
17
57
  describe("CopilotChat activity message rendering", () => {
18
58
  it("renders custom components for activity snapshots", async () => {
@@ -208,4 +248,262 @@ describe("CopilotChat activity message rendering", () => {
208
248
  expect(capturedAgent).toBe(clone);
209
249
  expect(capturedAgent).not.toBe(agent); // must NOT be the registry agent
210
250
  });
251
+
252
+ it("restores a completed A2UI surface after reconnect from an event-native baseline", async () => {
253
+ const agent = new MockReconnectableAgent();
254
+ const threadId = testId("a2ui-thread");
255
+ const surfaceId = testId("surface");
256
+ const a2uiRenderer = createA2UIMessageRenderer({
257
+ theme: {} as Theme,
258
+ });
259
+
260
+ const { unmount } = renderWithCopilotKit({
261
+ agent,
262
+ threadId,
263
+ renderActivityMessages: [a2uiRenderer],
264
+ });
265
+
266
+ const input = await screen.findByRole("textbox");
267
+ fireEvent.change(input, { target: { value: "Show me the restored UI" } });
268
+ fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
269
+
270
+ await waitFor(() => {
271
+ expect(screen.getByText("Show me the restored UI")).toBeDefined();
272
+ });
273
+
274
+ agent.emit(runStartedEvent());
275
+ agent.emit(
276
+ activitySnapshotEvent({
277
+ messageId: testId("a2ui-activity"),
278
+ activityType: "a2ui-surface",
279
+ content: {
280
+ a2ui_operations: [
281
+ {
282
+ version: "v0.9",
283
+ createSurface: {
284
+ surfaceId,
285
+ catalogId:
286
+ "https://a2ui.org/specification/v0_9/basic_catalog.json",
287
+ },
288
+ },
289
+ {
290
+ version: "v0.9",
291
+ updateComponents: {
292
+ surfaceId,
293
+ components: [
294
+ {
295
+ id: "root",
296
+ component: "Text",
297
+ text: "Restored dashboard",
298
+ variant: "body",
299
+ },
300
+ ],
301
+ },
302
+ },
303
+ ],
304
+ },
305
+ }),
306
+ );
307
+ agent.emit(runFinishedEvent());
308
+ agent.complete();
309
+
310
+ await waitFor(() => {
311
+ expect(
312
+ document.querySelector(`[data-surface-id='${surfaceId}']`),
313
+ ).not.toBeNull();
314
+ });
315
+
316
+ unmount();
317
+ agent.reset();
318
+
319
+ renderWithCopilotKit({
320
+ agent,
321
+ threadId,
322
+ renderActivityMessages: [a2uiRenderer],
323
+ });
324
+
325
+ await waitFor(() => {
326
+ expect(
327
+ document.querySelector(`[data-surface-id='${surfaceId}']`),
328
+ ).not.toBeNull();
329
+ });
330
+ });
331
+
332
+ it("restores a completed A2UI surface from an IntelligenceAgent /connect bootstrap plan", async () => {
333
+ const threadId = testId("intelligence-connect-thread");
334
+ const surfaceId = testId("intelligence-connect-surface");
335
+ const fetchMock = vi.fn().mockResolvedValueOnce(
336
+ jsonResponse({
337
+ mode: "bootstrap",
338
+ latestEventId: "event-3",
339
+ events: [
340
+ {
341
+ type: "RUN_STARTED",
342
+ threadId,
343
+ run_id: "backend-run-1",
344
+ input: {
345
+ messages: [
346
+ {
347
+ id: testId("connect-user-message"),
348
+ role: "user",
349
+ content: "show me the restored ui",
350
+ },
351
+ ],
352
+ },
353
+ },
354
+ {
355
+ type: "ACTIVITY_SNAPSHOT",
356
+ messageId: testId("connect-a2ui-activity"),
357
+ activityType: "a2ui-surface",
358
+ content: {
359
+ a2ui_operations: [
360
+ {
361
+ version: "v0.9",
362
+ createSurface: {
363
+ surfaceId,
364
+ catalogId:
365
+ "https://a2ui.org/specification/v0_9/basic_catalog.json",
366
+ },
367
+ },
368
+ {
369
+ version: "v0.9",
370
+ updateComponents: {
371
+ surfaceId,
372
+ components: [
373
+ {
374
+ id: "root",
375
+ component: "Text",
376
+ text: "Restored dashboard",
377
+ variant: "body",
378
+ },
379
+ ],
380
+ },
381
+ },
382
+ ],
383
+ },
384
+ },
385
+ {
386
+ type: "RUN_FINISHED",
387
+ },
388
+ ],
389
+ }),
390
+ );
391
+ vi.stubGlobal("fetch", fetchMock);
392
+
393
+ const agent = new IntelligenceAgent({
394
+ url: "ws://localhost:4000/client",
395
+ runtimeUrl: "http://localhost:4000",
396
+ agentId: "my-agent",
397
+ });
398
+ const a2uiRenderer = createA2UIMessageRenderer({
399
+ theme: {} as Theme,
400
+ });
401
+
402
+ try {
403
+ renderWithCopilotKit({
404
+ agent,
405
+ threadId,
406
+ renderActivityMessages: [a2uiRenderer],
407
+ });
408
+
409
+ await waitFor(() => {
410
+ expect(fetchMock).toHaveBeenCalledTimes(1);
411
+ });
412
+ await waitFor(() => {
413
+ expect(screen.getByText("show me the restored ui")).toBeDefined();
414
+ });
415
+ await waitFor(() => {
416
+ expect(
417
+ document.querySelector(`[data-surface-id='${surfaceId}']`),
418
+ ).not.toBeNull();
419
+ });
420
+
421
+ const [url, options] = fetchMock.mock.calls[0] as [string, RequestInit];
422
+ expect(url).toContain("/agent/my-agent/connect");
423
+ expect(options.method).toBe("POST");
424
+
425
+ const requestBody = JSON.parse(String(options.body)) as {
426
+ threadId: string;
427
+ lastSeenEventId: string | null;
428
+ messages: unknown[];
429
+ };
430
+ expect(requestBody.threadId).toBe(threadId);
431
+ expect(requestBody.lastSeenEventId).toBeNull();
432
+ expect(requestBody.messages).toEqual([]);
433
+ } finally {
434
+ vi.unstubAllGlobals();
435
+ }
436
+ });
437
+
438
+ it("restores a completed Open Generative UI activity after reconnect from an event-native baseline", async () => {
439
+ mockWebsandboxCreate.mockClear();
440
+ mockWebsandboxDestroy.mockClear();
441
+
442
+ const agent = new MockReconnectableAgent();
443
+ const threadId = testId("open-generative-ui-thread");
444
+ const restoredHtml =
445
+ "<head></head><body><div>Restored open generative UI</div></body>";
446
+
447
+ const renderOpenGenerativeUIChat = () =>
448
+ render(
449
+ <CopilotKitProvider
450
+ agents__unsafe_dev_only={{ default: agent }}
451
+ openGenerativeUI={{}}
452
+ >
453
+ <CopilotChatConfigurationProvider threadId={threadId}>
454
+ <div style={{ height: 400 }}>
455
+ <CopilotChat welcomeScreen={false} />
456
+ </div>
457
+ </CopilotChatConfigurationProvider>
458
+ </CopilotKitProvider>,
459
+ );
460
+
461
+ const { unmount } = renderOpenGenerativeUIChat();
462
+
463
+ const input = await screen.findByRole("textbox");
464
+ fireEvent.change(input, { target: { value: "Show me the restored app" } });
465
+ fireEvent.keyDown(input, { key: "Enter", code: "Enter" });
466
+
467
+ await waitFor(() => {
468
+ expect(screen.getByText("Show me the restored app")).toBeDefined();
469
+ });
470
+
471
+ agent.emit(runStartedEvent());
472
+ agent.emit(
473
+ activitySnapshotEvent({
474
+ messageId: testId("open-generative-ui-activity"),
475
+ activityType: "open-generative-ui",
476
+ content: {
477
+ initialHeight: 180,
478
+ generating: false,
479
+ html: [restoredHtml],
480
+ htmlComplete: true,
481
+ },
482
+ }),
483
+ );
484
+ agent.emit(runFinishedEvent());
485
+ agent.complete();
486
+
487
+ await waitFor(() => {
488
+ expect(mockWebsandboxCreate).toHaveBeenCalledTimes(1);
489
+ });
490
+ expect(mockWebsandboxCreate.mock.calls[0]?.[1]).toMatchObject({
491
+ frameContent: restoredHtml,
492
+ });
493
+
494
+ unmount();
495
+
496
+ agent.reset();
497
+
498
+ renderOpenGenerativeUIChat();
499
+
500
+ await waitFor(() => {
501
+ expect(mockWebsandboxCreate).toHaveBeenCalledTimes(2);
502
+ });
503
+ expect(mockWebsandboxCreate.mock.calls[1]?.[1]).toMatchObject({
504
+ frameContent: restoredHtml,
505
+ });
506
+
507
+ expect(mockWebsandboxDestroy).toHaveBeenCalledTimes(1);
508
+ });
211
509
  });
@@ -0,0 +1,56 @@
1
+ import React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { describe, it, expect } from "vitest";
4
+ import { CopilotChatView } from "../CopilotChatView";
5
+ import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
6
+ import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
7
+
8
+ // Minimal provider wrapper. No agent registry is required because these tests
9
+ // only exercise local render decisions (welcome-screen suppression) that
10
+ // don't touch the agent runtime.
11
+ const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
12
+ <CopilotKitProvider>
13
+ <CopilotChatConfigurationProvider threadId="test-thread">
14
+ <div style={{ height: 400 }}>{children}</div>
15
+ </CopilotChatConfigurationProvider>
16
+ </CopilotKitProvider>
17
+ );
18
+
19
+ describe("CopilotChatView connect-gating", () => {
20
+ it("suppresses the welcome screen while isConnecting=true", () => {
21
+ render(
22
+ <TestWrapper>
23
+ <CopilotChatView messages={[]} isConnecting />
24
+ </TestWrapper>,
25
+ );
26
+
27
+ // Switching threads would otherwise flash the welcome greeting before
28
+ // bootstrap messages arrive.
29
+ expect(screen.queryByTestId("copilot-welcome-screen")).toBeNull();
30
+ });
31
+
32
+ it("suppresses the welcome screen when hasExplicitThreadId=true", () => {
33
+ render(
34
+ <TestWrapper>
35
+ <CopilotChatView messages={[]} hasExplicitThreadId />
36
+ </TestWrapper>,
37
+ );
38
+
39
+ // A caller-managed thread (threadId prop / config provider) should never
40
+ // display the generic "start a new chat" welcome — even when the thread
41
+ // has no messages yet.
42
+ expect(screen.queryByTestId("copilot-welcome-screen")).toBeNull();
43
+ });
44
+
45
+ it("shows the welcome screen by default for a fresh empty chat", () => {
46
+ render(
47
+ <TestWrapper>
48
+ <CopilotChatView messages={[]} />
49
+ </TestWrapper>,
50
+ );
51
+
52
+ // Positive control: with no threadId supplied and no connect in flight,
53
+ // an empty chat should still render the welcome screen.
54
+ expect(screen.getByTestId("copilot-welcome-screen")).toBeDefined();
55
+ });
56
+ });
@@ -0,0 +1,94 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { render } from "@testing-library/react";
3
+ import React from "react";
4
+ import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
5
+ import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
6
+ import { CopilotChatView } from "../CopilotChatView";
7
+ import { LastUserMessageContext } from "../last-user-message-context";
8
+
9
+ beforeEach(() => {
10
+ HTMLElement.prototype.scrollTo = vi.fn();
11
+ });
12
+
13
+ // Wrapper to provide required context (same pattern as CopilotChatView.slots.e2e.test.tsx)
14
+ const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
15
+ <CopilotKitProvider>
16
+ <CopilotChatConfigurationProvider threadId="test-thread">
17
+ <div style={{ height: 400 }}>{children}</div>
18
+ </CopilotChatConfigurationProvider>
19
+ </CopilotKitProvider>
20
+ );
21
+
22
+ const sampleMessages = [
23
+ { id: "1", role: "user" as const, content: "Hello" },
24
+ { id: "2", role: "assistant" as const, content: "Hi there!" },
25
+ ];
26
+
27
+ // Wait for the ScrollView's `hasMounted` useEffect to flip — the pre-mount
28
+ // fallback render does not include the message list, so a findBy on the
29
+ // message list is a reliable "mount is done" signal. Without this gate,
30
+ // absence assertions pass vacuously against the pre-mount render.
31
+ async function waitForMount(screen: {
32
+ findByTestId: (id: string) => Promise<HTMLElement>;
33
+ }) {
34
+ await screen.findByTestId("copilot-message-list");
35
+ }
36
+
37
+ describe("CopilotChatView pin-to-send mode", () => {
38
+ it("renders the pin-to-send spacer element when autoScroll='pin-to-send'", async () => {
39
+ const screen = render(
40
+ <TestWrapper>
41
+ <LastUserMessageContext.Provider value={{ id: null, sendNonce: 0 }}>
42
+ <CopilotChatView autoScroll="pin-to-send" messages={sampleMessages} />
43
+ </LastUserMessageContext.Provider>
44
+ </TestWrapper>,
45
+ );
46
+ await waitForMount(screen);
47
+ const spacer = screen.container.querySelector("[data-pin-to-send-spacer]");
48
+ expect(spacer).not.toBeNull();
49
+ });
50
+
51
+ it("does not render the spacer when autoScroll='pin-to-bottom'", async () => {
52
+ const screen = render(
53
+ <TestWrapper>
54
+ <CopilotChatView autoScroll="pin-to-bottom" messages={sampleMessages} />
55
+ </TestWrapper>,
56
+ );
57
+ await waitForMount(screen);
58
+ const spacer = screen.container.querySelector("[data-pin-to-send-spacer]");
59
+ expect(spacer).toBeNull();
60
+ });
61
+
62
+ it("does not render the spacer when autoScroll='none'", async () => {
63
+ const screen = render(
64
+ <TestWrapper>
65
+ <CopilotChatView autoScroll="none" messages={sampleMessages} />
66
+ </TestWrapper>,
67
+ );
68
+ await waitForMount(screen);
69
+ const spacer = screen.container.querySelector("[data-pin-to-send-spacer]");
70
+ expect(spacer).toBeNull();
71
+ });
72
+
73
+ it("boolean true still maps to pin-to-bottom (back-compat)", async () => {
74
+ const screen = render(
75
+ <TestWrapper>
76
+ <CopilotChatView autoScroll={true} messages={sampleMessages} />
77
+ </TestWrapper>,
78
+ );
79
+ await waitForMount(screen);
80
+ const spacer = screen.container.querySelector("[data-pin-to-send-spacer]");
81
+ expect(spacer).toBeNull();
82
+ });
83
+
84
+ it("boolean false still maps to none (back-compat)", async () => {
85
+ const screen = render(
86
+ <TestWrapper>
87
+ <CopilotChatView autoScroll={false} messages={sampleMessages} />
88
+ </TestWrapper>,
89
+ );
90
+ await waitForMount(screen);
91
+ const spacer = screen.container.querySelector("[data-pin-to-send-spacer]");
92
+ expect(spacer).toBeNull();
93
+ });
94
+ });
@@ -4,7 +4,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
4
4
  import { CopilotChat } from "../CopilotChat";
5
5
  import { useAgent } from "../../../hooks/use-agent";
6
6
  import { useCopilotKit } from "../../../providers/CopilotKitProvider";
7
- import { useCopilotChatConfiguration } from "../../../providers/CopilotChatConfigurationProvider";
8
7
  import { MockStepwiseAgent } from "../../../__tests__/utils/test-helpers";
9
8
  import { CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
10
9
 
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ normalizeAutoScroll,
4
+ type AutoScrollMode,
5
+ } from "../normalize-auto-scroll";
6
+
7
+ describe("normalizeAutoScroll", () => {
8
+ it("returns 'pin-to-bottom' for undefined (default)", () => {
9
+ expect(normalizeAutoScroll(undefined)).toBe("pin-to-bottom");
10
+ });
11
+
12
+ it("maps true -> 'pin-to-bottom'", () => {
13
+ expect(normalizeAutoScroll(true)).toBe("pin-to-bottom");
14
+ });
15
+
16
+ it("maps false -> 'none'", () => {
17
+ expect(normalizeAutoScroll(false)).toBe("none");
18
+ });
19
+
20
+ it("passes 'pin-to-bottom' through", () => {
21
+ expect(normalizeAutoScroll("pin-to-bottom")).toBe("pin-to-bottom");
22
+ });
23
+
24
+ it("passes 'pin-to-send' through", () => {
25
+ expect(normalizeAutoScroll("pin-to-send")).toBe("pin-to-send");
26
+ });
27
+
28
+ it("passes 'none' through", () => {
29
+ expect(normalizeAutoScroll("none")).toBe("none");
30
+ });
31
+
32
+ it("falls back to 'pin-to-bottom' for unknown strings", () => {
33
+ expect(normalizeAutoScroll("bogus" as AutoScrollMode)).toBe(
34
+ "pin-to-bottom",
35
+ );
36
+ });
37
+ });
@@ -86,3 +86,5 @@ export type {
86
86
  AttachmentsConfig,
87
87
  AttachmentModality,
88
88
  } from "@copilotkit/shared";
89
+
90
+ export type { AutoScrollMode } from "./normalize-auto-scroll";
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * Context used by `CopilotChatView` to announce the latest user message
5
+ * to descendants (notably `usePinToSend`), so scroll logic can anchor
6
+ * the viewport to the most recent user turn in "pin-to-send" mode.
7
+ *
8
+ * `sendNonce` increments on each new send so repeated IDs (e.g., message
9
+ * edits that preserve the ID) still trigger dependent effects.
10
+ */
11
+ export type LastUserMessageState = {
12
+ id: string | null;
13
+ sendNonce: number;
14
+ };
15
+
16
+ export const LastUserMessageContext = React.createContext<LastUserMessageState>(
17
+ {
18
+ id: null,
19
+ sendNonce: 0,
20
+ },
21
+ );
@@ -0,0 +1,17 @@
1
+ export type AutoScrollMode = "pin-to-bottom" | "pin-to-send" | "none";
2
+
3
+ const VALID: readonly AutoScrollMode[] = [
4
+ "pin-to-bottom",
5
+ "pin-to-send",
6
+ "none",
7
+ ];
8
+
9
+ export function normalizeAutoScroll(
10
+ value: AutoScrollMode | boolean | undefined,
11
+ ): AutoScrollMode {
12
+ if (value === undefined) return "pin-to-bottom";
13
+ if (value === true) return "pin-to-bottom";
14
+ if (value === false) return "none";
15
+ if ((VALID as readonly string[]).includes(value)) return value;
16
+ return "pin-to-bottom";
17
+ }
@@ -1,4 +1,9 @@
1
- import React from "react";
1
+ import React, { useEffect } from "react";
2
+
3
+ // Total reserved vertical space for the fixed license banner: banner height
4
+ // (~36px) + bottom offset (8px) + visual gap above the chat input (~8px).
5
+ const LICENSE_BANNER_OFFSET_PX = 52;
6
+ const LICENSE_BANNER_OFFSET_VAR = "--copilotkit-license-banner-offset";
2
7
 
3
8
  interface LicenseWarningBannerProps {
4
9
  type:
@@ -72,6 +77,20 @@ function BannerShell({
72
77
  actionUrl: string;
73
78
  onDismiss?: () => void;
74
79
  }) {
80
+ // Publish the banner's reserved bottom offset so the chat input can lift
81
+ // itself above it via padding-bottom: var(--copilotkit-license-banner-offset).
82
+ useEffect(() => {
83
+ if (typeof document === "undefined") return;
84
+ const root = document.documentElement;
85
+ root.style.setProperty(
86
+ LICENSE_BANNER_OFFSET_VAR,
87
+ `${LICENSE_BANNER_OFFSET_PX}px`,
88
+ );
89
+ return () => {
90
+ root.style.removeProperty(LICENSE_BANNER_OFFSET_VAR);
91
+ };
92
+ }, []);
93
+
75
94
  return (
76
95
  <div style={{ ...BANNER_STYLES.base, ...getSeverityStyle(severity) }}>
77
96
  <span>{message}</span>
@@ -29,6 +29,10 @@ describe("useAgent stability during runtime connection", () => {
29
29
  runtimeTransport: string;
30
30
  headers: Record<string, string>;
31
31
  agents: Record<string, AbstractAgent>;
32
+ subscribeToAgentWithOptions: (
33
+ agent: AbstractAgent,
34
+ subscriber: any,
35
+ ) => { unsubscribe: () => void };
32
36
  };
33
37
 
34
38
  beforeEach(() => {
@@ -40,6 +44,8 @@ describe("useAgent stability during runtime connection", () => {
40
44
  runtimeTransport: "rest",
41
45
  headers: {},
42
46
  agents: {},
47
+ subscribeToAgentWithOptions: (agent, subscriber) =>
48
+ agent.subscribe(subscriber),
43
49
  };
44
50
 
45
51
  mockUseCopilotKit.mockReturnValue({
@@ -47,6 +47,10 @@ describe("useAgent thread isolation", () => {
47
47
  runtimeTransport: string;
48
48
  headers: Record<string, string>;
49
49
  agents: Record<string, AbstractAgent>;
50
+ subscribeToAgentWithOptions: (
51
+ agent: AbstractAgent,
52
+ subscriber: any,
53
+ ) => { unsubscribe: () => void };
50
54
  };
51
55
 
52
56
  let registeredAgent: CloneableAgent;
@@ -64,6 +68,8 @@ describe("useAgent thread isolation", () => {
64
68
  runtimeTransport: "rest",
65
69
  headers: {},
66
70
  agents: { "my-agent": registeredAgent },
71
+ subscribeToAgentWithOptions: (agent, subscriber) =>
72
+ agent.subscribe(subscriber),
67
73
  };
68
74
 
69
75
  mockUseCopilotKit.mockReturnValue({