@copilotkit/vue 1.69.1 → 1.69.3

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 (54) hide show
  1. package/PARITY.md +1 -1
  2. package/README.md +7 -0
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.mjs +14 -14
  6. package/dist/use-render-activity-message-DMY6Krn-.cjs +85 -0
  7. package/dist/use-render-activity-message-DMY6Krn-.cjs.map +1 -0
  8. package/dist/{use-render-activity-message-CADUB--8.js → use-render-activity-message-W2lbqLZH.js} +4000 -4285
  9. package/dist/use-render-activity-message-W2lbqLZH.js.map +1 -0
  10. package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -1
  11. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -1
  12. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
  13. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +0 -18
  14. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -1
  15. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -1
  16. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
  17. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
  18. package/dist/v2/components/icons/index.d.ts +1 -1
  19. package/dist/v2/components/icons/index.d.ts.map +1 -1
  20. package/dist/v2/index.cjs +1 -1
  21. package/dist/v2/index.mjs +1 -1
  22. package/dist/v2/providers/CopilotKitProvider.types.d.ts +10 -9
  23. package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
  24. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +1 -1
  25. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
  26. package/dist/v2/providers/keys.d.ts +1 -27
  27. package/dist/v2/providers/keys.d.ts.map +1 -1
  28. package/dist/v2/providers/types.d.ts +0 -3
  29. package/dist/v2/providers/types.d.ts.map +1 -1
  30. package/package.json +5 -5
  31. package/src/v2/__tests__/mocks/web-inspector.ts +32 -1
  32. package/src/v2/components/CopilotKitInspector.vue +34 -14
  33. package/src/v2/components/OpenGenerativeUIRenderer.ts +1 -42
  34. package/src/v2/components/__tests__/CopilotKitInspector.test.ts +31 -6
  35. package/src/v2/components/chat/CopilotChatAssistantMessage.vue +1 -52
  36. package/src/v2/components/chat/CopilotChatMessageView.vue +23 -57
  37. package/src/v2/components/chat/CopilotChatReasoningMessage.vue +32 -68
  38. package/src/v2/components/chat/CopilotChatToolCallsView.vue +16 -70
  39. package/src/v2/components/icons/__tests__/icons.test.ts +0 -2
  40. package/src/v2/components/icons/index.ts +0 -1
  41. package/src/v2/providers/CopilotKitProvider.types.ts +10 -9
  42. package/src/v2/providers/CopilotKitProvider.vue +15 -73
  43. package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +148 -37
  44. package/src/v2/providers/keys.ts +1 -33
  45. package/src/v2/providers/types.ts +0 -3
  46. package/dist/use-render-activity-message-BtaJ2iQc.cjs +0 -97
  47. package/dist/use-render-activity-message-BtaJ2iQc.cjs.map +0 -1
  48. package/dist/use-render-activity-message-CADUB--8.js.map +0 -1
  49. package/dist/v2/components/chat/SaveSnippetBeside.vue.d.ts +0 -20
  50. package/dist/v2/components/chat/SaveSnippetBeside.vue.d.ts.map +0 -1
  51. package/dist/v2/components/chat/save-snippet-beside.d.ts +0 -20
  52. package/dist/v2/components/chat/save-snippet-beside.d.ts.map +0 -1
  53. package/src/v2/components/chat/SaveSnippetBeside.vue +0 -82
  54. package/src/v2/components/chat/save-snippet-beside.ts +0 -84
@@ -1,6 +1,15 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { render, waitFor } from "@testing-library/vue";
2
3
  import { mount } from "@vue/test-utils";
3
- import { defineComponent, h, nextTick, ref, watchEffect } from "vue";
4
+ import {
5
+ createSSRApp,
6
+ defineComponent,
7
+ h,
8
+ nextTick,
9
+ ref,
10
+ watchEffect,
11
+ } from "vue";
12
+ import { renderToString } from "vue/server-renderer";
4
13
  import type {
5
14
  CopilotKitCoreSubscriber,
6
15
  FrontendToolHandlerContext,
@@ -39,6 +48,8 @@ describe("CopilotKitProvider", () => {
39
48
  afterEach(() => {
40
49
  consoleErrorSpy.mockRestore();
41
50
  consoleWarnSpy.mockRestore();
51
+ vi.unstubAllEnvs();
52
+ vi.unstubAllGlobals();
42
53
  });
43
54
 
44
55
  describe("Basic functionality", () => {
@@ -538,66 +549,166 @@ describe("CopilotKitProvider", () => {
538
549
  const tool = getCore().getTool({ toolName: "followUpTool" });
539
550
  expect(tool?.followUp).toBe(false);
540
551
  });
552
+ });
541
553
 
542
- it("renders inspector when showDevConsole is true", async () => {
543
- const wrapper = mount(CopilotKitProvider, {
544
- props: {
545
- runtimeUrl: "/api/copilotkit",
546
- showDevConsole: true,
547
- },
548
- slots: {
549
- default: () => h("div", "test"),
550
- },
551
- });
552
-
553
- await nextTick();
554
+ describe("inspector visibility", () => {
555
+ async function settleInspectorLoad(): Promise<void> {
554
556
  await vi.dynamicImportSettled();
557
+ await new Promise((resolve) => setTimeout(resolve, 50));
555
558
  await nextTick();
559
+ }
556
560
 
557
- expect(wrapper.find("cpk-web-inspector").exists()).toBe(true);
561
+ beforeEach(() => {
562
+ vi.stubEnv("NODE_ENV", "development");
563
+ });
564
+
565
+ it("renders by default on any development host and passes the provider core before connection", async () => {
566
+ let providerCore: CopilotKitCoreContextValue | null = null;
567
+ const Probe = defineComponent({
568
+ setup() {
569
+ providerCore = useCopilotKit().copilotkit.value;
570
+ return () => null;
571
+ },
572
+ });
573
+ const view = render(CopilotKitProvider, {
574
+ props: { runtimeUrl: "/api/copilotkit" },
575
+ slots: { default: Probe },
576
+ });
577
+
578
+ await waitFor(() => {
579
+ expect(
580
+ view.container.querySelector("cpk-web-inspector"),
581
+ ).not.toBeNull();
582
+ });
583
+ const inspector = view.container.querySelector(
584
+ "cpk-web-inspector",
585
+ ) as HTMLElement & {
586
+ autoAttachCore?: boolean;
587
+ autoAttachCoreAtConnection?: boolean;
588
+ core?: unknown;
589
+ coreAtConnection?: unknown;
590
+ };
591
+ expect(inspector.core).toBe(providerCore);
592
+ expect(inspector.autoAttachCore).toBe(false);
593
+ expect(inspector.coreAtConnection).toBe(providerCore);
594
+ expect(inspector.autoAttachCoreAtConnection).toBe(false);
558
595
  expect(defineWebInspector).toHaveBeenCalledTimes(1);
596
+ view.unmount();
559
597
  });
560
598
 
561
- it("renders inspector on localhost when showDevConsole is auto", async () => {
562
- const wrapper = mount(CopilotKitProvider, {
599
+ it("does not render or load when explicitly disabled in development", async () => {
600
+ const view = render(CopilotKitProvider, {
563
601
  props: {
564
602
  runtimeUrl: "/api/copilotkit",
565
- showDevConsole: "auto",
566
- },
567
- slots: {
568
- default: () => h("div", "test"),
603
+ enableInspector: false,
569
604
  },
605
+ slots: { default: "child" },
570
606
  });
571
607
 
572
- await nextTick();
573
- await vi.dynamicImportSettled();
574
- await nextTick();
608
+ await settleInspectorLoad();
609
+ expect(view.container.querySelector("cpk-web-inspector")).toBeNull();
610
+ expect(defineWebInspector).not.toHaveBeenCalled();
611
+ view.unmount();
612
+ });
575
613
 
576
- const shouldRenderOnThisHost = new Set(["localhost", "127.0.0.1"]).has(
577
- window.location.hostname,
578
- );
614
+ it("never renders or loads in production, even when explicitly enabled", async () => {
615
+ vi.stubEnv("NODE_ENV", "production");
616
+ const view = render(CopilotKitProvider, {
617
+ props: {
618
+ runtimeUrl: "/api/copilotkit",
619
+ enableInspector: true,
620
+ },
621
+ slots: { default: "child" },
622
+ });
579
623
 
580
- expect(wrapper.find("cpk-web-inspector").exists()).toBe(
581
- shouldRenderOnThisHost,
582
- );
624
+ await settleInspectorLoad();
625
+ expect(view.container.querySelector("cpk-web-inspector")).toBeNull();
626
+ expect(defineWebInspector).not.toHaveBeenCalled();
627
+ view.unmount();
583
628
  });
584
629
 
585
- it("does not render inspector when showDevConsole is false", async () => {
586
- const wrapper = mount(CopilotKitProvider, {
630
+ it("does not let legacy showDevConsole disable the development Inspector", async () => {
631
+ const view = render(CopilotKitProvider, {
587
632
  props: {
588
633
  runtimeUrl: "/api/copilotkit",
589
634
  showDevConsole: false,
590
635
  },
591
- slots: {
592
- default: () => h("div", "test"),
636
+ slots: { default: "child" },
637
+ });
638
+
639
+ await waitFor(() => {
640
+ expect(
641
+ view.container.querySelector("cpk-web-inspector"),
642
+ ).not.toBeNull();
643
+ });
644
+ view.unmount();
645
+ });
646
+
647
+ it("does not let legacy showDevConsole enable the production Inspector", async () => {
648
+ vi.stubEnv("NODE_ENV", "production");
649
+ const view = render(CopilotKitProvider, {
650
+ props: {
651
+ runtimeUrl: "/api/copilotkit",
652
+ showDevConsole: "auto",
593
653
  },
654
+ slots: { default: "child" },
594
655
  });
595
656
 
596
- await nextTick();
597
- await vi.dynamicImportSettled();
598
- await nextTick();
657
+ await settleInspectorLoad();
658
+ expect(view.container.querySelector("cpk-web-inspector")).toBeNull();
659
+ expect(defineWebInspector).not.toHaveBeenCalled();
660
+ view.unmount();
661
+ });
599
662
 
600
- expect(wrapper.find("cpk-web-inspector").exists()).toBe(false);
663
+ it("does not render or load the inspector during SSR", async () => {
664
+ vi.stubGlobal("window", undefined);
665
+ const html = await renderToString(
666
+ createSSRApp(CopilotKitProvider, {
667
+ runtimeUrl: "/api/copilotkit",
668
+ enableInspector: true,
669
+ }),
670
+ );
671
+ await settleInspectorLoad();
672
+ expect(html).not.toContain("cpk-web-inspector");
673
+ expect(defineWebInspector).not.toHaveBeenCalled();
674
+ });
675
+
676
+ it("hydrates development markup before mounting the Inspector", async () => {
677
+ const props = {
678
+ runtimeUrl: "/api/copilotkit",
679
+ enableInspector: true,
680
+ };
681
+ const container = document.createElement("div");
682
+ document.body.appendChild(container);
683
+ const browserWindow = window;
684
+
685
+ vi.stubGlobal("window", undefined);
686
+ container.innerHTML = await renderToString(
687
+ createSSRApp(CopilotKitProvider, props),
688
+ );
689
+ vi.stubGlobal("window", browserWindow);
690
+
691
+ expect(container.innerHTML).not.toContain("cpk-web-inspector");
692
+ expect(defineWebInspector).not.toHaveBeenCalled();
693
+
694
+ const app = createSSRApp(CopilotKitProvider, props);
695
+ app.mount(container);
696
+
697
+ try {
698
+ await waitFor(() => {
699
+ expect(container.querySelector("cpk-web-inspector")).not.toBeNull();
700
+ });
701
+ const hydrationOutput = [
702
+ ...consoleWarnSpy.mock.calls,
703
+ ...consoleErrorSpy.mock.calls,
704
+ ]
705
+ .flat()
706
+ .join(" ");
707
+ expect(hydrationOutput).not.toContain("Hydration");
708
+ } finally {
709
+ app.unmount();
710
+ container.remove();
711
+ }
601
712
  });
602
713
  });
603
714
  });
@@ -28,43 +28,11 @@ export type VueInspectorOpenRequest = {
28
28
  messageId: string;
29
29
  threadId?: string;
30
30
  agentId?: string;
31
- menu?: "event-snippets";
32
- snippetId?: string;
33
31
  };
34
32
 
35
- export type VueInspectorSaveRequest = {
36
- threadId?: string;
37
- agentId?: string;
38
- } & (
39
- | {
40
- kind: "text";
41
- messageId: string;
42
- content: string;
43
- }
44
- | {
45
- kind: "reasoning";
46
- messageId: string;
47
- content: string;
48
- }
49
- | {
50
- kind: "tool-call";
51
- messageId: string;
52
- toolCallId: string;
53
- toolName: string;
54
- argsJson: string | Record<string, unknown>;
55
- }
56
- | {
57
- kind: "activity";
58
- messageId: string;
59
- activityType: string;
60
- content: unknown;
61
- }
62
- );
63
-
64
33
  export type VueInspectorContextValue = {
65
- isLocalInspectorEnabled: ComputedRef<boolean>;
34
+ isInspectorEnabled: ComputedRef<boolean>;
66
35
  openInspector: (request: VueInspectorOpenRequest) => void;
67
- saveEventSnippet: (request: VueInspectorSaveRequest) => Promise<void>;
68
36
  };
69
37
 
70
38
  export const InspectorKey: InjectionKey<VueInspectorContextValue> = Symbol(
@@ -8,9 +8,6 @@ export const CopilotChatDefaultLabels = {
8
8
  assistantMessageToolbarCopyCodeLabel: "Copy",
9
9
  assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
10
10
  assistantMessageToolbarCopyMessageLabel: "Copy",
11
- assistantMessageToolbarInspectorLabel: "View in Inspector",
12
- assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
13
- assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
14
11
  assistantMessageToolbarThumbsUpLabel: "Good response",
15
12
  assistantMessageToolbarThumbsDownLabel: "Bad response",
16
13
  assistantMessageToolbarReadAloudLabel: "Read aloud",