@copilotkit/vue 1.75.2 → 1.76.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 (38) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.mjs +272 -157
  3. package/dist/index.mjs.map +1 -1
  4. package/dist/use-render-activity-message-BTKmd3f3.cjs +110 -0
  5. package/dist/use-render-activity-message-BTKmd3f3.cjs.map +1 -0
  6. package/dist/use-render-activity-message-Eu6R2vGT.js +12801 -0
  7. package/dist/use-render-activity-message-Eu6R2vGT.js.map +1 -0
  8. package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
  9. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +8 -152
  10. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
  11. package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -1
  12. package/dist/v2/hooks/use-agent.d.ts.map +1 -1
  13. package/dist/v2/index.cjs +1 -1
  14. package/dist/v2/index.d.cts +2 -0
  15. package/dist/v2/index.d.mts +2 -0
  16. package/dist/v2/index.d.ts +2 -0
  17. package/dist/v2/index.d.ts.map +1 -1
  18. package/dist/v2/index.mjs +187 -72
  19. package/dist/v2/index.mjs.map +1 -1
  20. package/package.json +7 -7
  21. package/src/v2/__tests__/utils/test-helpers.ts +26 -6
  22. package/src/v2/components/chat/CopilotChat.vue +100 -20
  23. package/src/v2/components/chat/__tests__/CopilotChat.clearOnFresh.test.ts +130 -2
  24. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.ts +6 -1
  25. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.ts +22 -40
  26. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.ts +12 -24
  27. package/src/v2/components/chat/copilotChatToolCallItemRender.ts +3 -2
  28. package/src/v2/hooks/__tests__/use-agent-headers.test.ts +83 -0
  29. package/src/v2/hooks/__tests__/use-agent-stability.test.ts +2 -0
  30. package/src/v2/hooks/__tests__/use-agent.e2e.test.ts +5 -3
  31. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +2 -2
  32. package/src/v2/hooks/use-agent.ts +3 -3
  33. package/src/v2/index.ts +5 -0
  34. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.ts +6 -4
  35. package/dist/use-render-activity-message-CGdS03Xj.cjs +0 -85
  36. package/dist/use-render-activity-message-CGdS03Xj.cjs.map +0 -1
  37. package/dist/use-render-activity-message-XmuT9fKy.js +0 -9799
  38. package/dist/use-render-activity-message-XmuT9fKy.js.map +0 -1
@@ -0,0 +1,83 @@
1
+ import { AbstractAgent, HttpAgent } from "@ag-ui/client";
2
+ import { defineComponent, h, nextTick } from "vue";
3
+ import { describe, expect, it } from "vitest";
4
+ import { mountWithProvider } from "../../__tests__/utils/mount";
5
+ import { useAgent } from "../use-agent";
6
+
7
+ // Models an HttpAgent from another installed copy of @ag-ui/client.
8
+ class ForeignHttpAgent extends AbstractAgent {
9
+ url = "https://agent.example";
10
+ headers: Record<string, string> = {
11
+ Authorization: "Bearer agent-token",
12
+ "X-Agent": "agent",
13
+ };
14
+ abortController = new AbortController();
15
+
16
+ run(): never {
17
+ throw new Error("This test does not run the agent");
18
+ }
19
+ }
20
+
21
+ describe("useAgent headers (Vue-specific semantics)", () => {
22
+ it.each([
23
+ [
24
+ "HttpAgent",
25
+ () =>
26
+ new HttpAgent({
27
+ url: "https://agent.example",
28
+ headers: { Authorization: "Bearer agent-token", "X-Agent": "agent" },
29
+ }),
30
+ ],
31
+ ["foreign HttpAgent", () => new ForeignHttpAgent()],
32
+ ] as const)(
33
+ "preserves %s headers when the provider changes headers",
34
+ async (_name, createAgent) => {
35
+ const agent = createAgent();
36
+ let headersAfterHook: Record<string, string> | undefined;
37
+ const Child = defineComponent({
38
+ setup() {
39
+ useAgent();
40
+ headersAfterHook = { ...agent.headers };
41
+ return () => null;
42
+ },
43
+ });
44
+ const { wrapper } = mountWithProvider(() => h(Child), {
45
+ runtimeUrl: undefined,
46
+ agents__unsafe_dev_only: { default: agent },
47
+ headers: { "X-Core": "initial" },
48
+ });
49
+
50
+ try {
51
+ expect(headersAfterHook).toEqual({
52
+ Authorization: "Bearer agent-token",
53
+ "X-Agent": "agent",
54
+ "X-Core": "initial",
55
+ });
56
+ expect(agent.headers).toEqual({
57
+ Authorization: "Bearer agent-token",
58
+ "X-Agent": "agent",
59
+ "X-Core": "initial",
60
+ });
61
+
62
+ await wrapper.setProps({
63
+ headers: { Authorization: "Bearer core-token", "X-Core": "updated" },
64
+ });
65
+ await nextTick();
66
+ expect(agent.headers).toEqual({
67
+ Authorization: "Bearer core-token",
68
+ "X-Agent": "agent",
69
+ "X-Core": "updated",
70
+ });
71
+
72
+ await wrapper.setProps({ headers: {} });
73
+ await nextTick();
74
+ expect(agent.headers).toEqual({
75
+ Authorization: "Bearer agent-token",
76
+ "X-Agent": "agent",
77
+ });
78
+ } finally {
79
+ wrapper.unmount();
80
+ }
81
+ },
82
+ );
83
+ });
@@ -34,6 +34,7 @@ describe("useAgent stability during runtime connection", () => {
34
34
  // need a no-op subscription object here; stability/ref-identity behavior
35
35
  // is orthogonal to subscribe internals.
36
36
  subscribeToAgentWithOptions: ReturnType<typeof vi.fn>;
37
+ applyHeadersToAgent: ReturnType<typeof vi.fn>;
37
38
  };
38
39
 
39
40
  let mockCopilotkit: MockCopilotkit;
@@ -49,6 +50,7 @@ describe("useAgent stability during runtime connection", () => {
49
50
  headers: {},
50
51
  agents: {},
51
52
  subscribeToAgentWithOptions: vi.fn(() => ({ unsubscribe: vi.fn() })),
53
+ applyHeadersToAgent: vi.fn(),
52
54
  });
53
55
  mockCopilotkit = copilotkitRef.value;
54
56
 
@@ -2,7 +2,7 @@ import { defineComponent } from "vue";
2
2
  import { screen, fireEvent, waitFor, cleanup } from "@testing-library/vue";
3
3
  import { afterEach, describe, expect, it } from "vitest";
4
4
  import { EventType } from "@ag-ui/client";
5
- import type { BaseEvent, RunAgentInput } from "@ag-ui/client";
5
+ import type { BaseEvent, RunAgentInput, RunErrorEvent } from "@ag-ui/client";
6
6
  import type { Observable } from "rxjs";
7
7
  import {
8
8
  MockStepwiseAgent,
@@ -174,9 +174,11 @@ describe("useAgent e2e", () => {
174
174
  expect(screen.getByTestId("status").textContent).toBe("running");
175
175
  });
176
176
 
177
- await agent.emit({
177
+ const errorEvent: RunErrorEvent = {
178
178
  type: EventType.RUN_ERROR,
179
- } as BaseEvent);
179
+ message: "The agent run failed",
180
+ };
181
+ await agent.emit(errorEvent);
180
182
  await agent.complete();
181
183
 
182
184
  await waitFor(() => {
@@ -665,7 +665,7 @@ describe("useFrontendTool E2E - Dynamic Registration", () => {
665
665
  const messageId = testId(`m-${this.runCount}`);
666
666
  const toolCallId = testId(`tc-${this.runCount}`);
667
667
  const valueArg = this.runCount === 1 ? "first call" : "second call";
668
- observer.next({ type: EventType.RUN_STARTED } as BaseEvent);
668
+ observer.next(runStartedEvent(_input));
669
669
  observer.next({
670
670
  type: EventType.TOOL_CALL_CHUNK,
671
671
  toolCallId,
@@ -673,7 +673,7 @@ describe("useFrontendTool E2E - Dynamic Registration", () => {
673
673
  parentMessageId: messageId,
674
674
  delta: JSON.stringify({ value: valueArg }),
675
675
  } as BaseEvent);
676
- observer.next({ type: EventType.RUN_FINISHED } as BaseEvent);
676
+ observer.next(runFinishedEvent(_input));
677
677
  observer.complete();
678
678
  return () => {};
679
679
  });
@@ -1,11 +1,11 @@
1
1
  import { computed, shallowRef, toValue, triggerRef, watch } from "vue";
2
2
  import type { MaybeRefOrGetter } from "vue";
3
3
  import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
4
- import { HttpAgent } from "@ag-ui/client";
5
4
  import type { AbstractAgent } from "@ag-ui/client";
6
5
  import {
7
6
  ProxiedCopilotRuntimeAgent,
8
7
  CopilotKitCoreRuntimeConnectionStatus,
8
+ ɵisHttpAgent,
9
9
  } from "@copilotkit/core";
10
10
  import type {
11
11
  CopilotRuntimeTransport,
@@ -392,8 +392,8 @@ export function useAgent(props: UseAgentProps = {}) {
392
392
  ),
393
393
  ],
394
394
  ([currentAgent]) => {
395
- if (currentAgent instanceof HttpAgent) {
396
- currentAgent.headers = { ...copilotkit.value.headers };
395
+ if (ɵisHttpAgent(currentAgent)) {
396
+ copilotkit.value.applyHeadersToAgent(currentAgent);
397
397
  }
398
398
  },
399
399
  { immediate: true },
package/src/v2/index.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  // Re-export core (framework-agnostic)
2
2
  export * from "@copilotkit/core";
3
3
  export * from "@ag-ui/client";
4
+ // AG-UI 1.0 moved the zod validators from `@ag-ui/client` to this subpath.
5
+ // Re-export them so existing imports keep working. Both modules export
6
+ // PROTOCOL_VERSION, so name it once to keep it from being ambiguous.
7
+ export * from "@ag-ui/core/schemas";
8
+ export { PROTOCOL_VERSION } from "@ag-ui/client";
4
9
 
5
10
  // Local V2 vue code
6
11
  export * from "./components";
@@ -138,6 +138,8 @@ describe("CopilotKitProvider custom message renderers E2E", () => {
138
138
 
139
139
  it("renders stored state snapshots for sequential runs", async () => {
140
140
  const agent = new MockStepwiseAgent();
141
+ const firstRun = { threadId: agent.threadId, runId: "first-run" };
142
+ const secondRun = { threadId: agent.threadId, runId: "second-run" };
141
143
  const history: number[] = [];
142
144
 
143
145
  const emitSnapshot = async (count: number) => {
@@ -153,12 +155,12 @@ describe("CopilotKitProvider custom message renderers E2E", () => {
153
155
  const firstAssistantId = testId("assistant-message");
154
156
  await submitMessage("First question");
155
157
 
156
- await agent.emit(runStartedEvent());
158
+ await agent.emit(runStartedEvent(firstRun));
157
159
  await emitSnapshot(1);
158
160
  await agent.emit(textMessageStartEvent(firstAssistantId));
159
161
  await agent.emit(textMessageContentEvent(firstAssistantId, "First answer"));
160
162
  await agent.emit(textMessageEndEvent(firstAssistantId));
161
- await agent.emit(runFinishedEvent());
163
+ await agent.emit(runFinishedEvent(firstRun));
162
164
 
163
165
  await waitFor(() => {
164
166
  expect(
@@ -173,14 +175,14 @@ describe("CopilotKitProvider custom message renderers E2E", () => {
173
175
  const secondAssistantId = testId("assistant-message");
174
176
  await submitMessage("Second question");
175
177
 
176
- await agent.emit(runStartedEvent());
178
+ await agent.emit(runStartedEvent(secondRun));
177
179
  await emitSnapshot(2);
178
180
  await agent.emit(textMessageStartEvent(secondAssistantId));
179
181
  await agent.emit(
180
182
  textMessageContentEvent(secondAssistantId, "Second answer"),
181
183
  );
182
184
  await agent.emit(textMessageEndEvent(secondAssistantId));
183
- await agent.emit(runFinishedEvent());
185
+ await agent.emit(runFinishedEvent(secondRun));
184
186
  agent.complete();
185
187
 
186
188
  await waitFor(() => {