@copilotkit/vue 1.69.2 → 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.
- package/PARITY.md +1 -1
- package/README.md +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/use-render-activity-message-DMY6Krn-.cjs +85 -0
- package/dist/use-render-activity-message-DMY6Krn-.cjs.map +1 -0
- package/dist/{use-render-activity-message-Db2rOZkW.js → use-render-activity-message-W2lbqLZH.js} +2844 -2828
- package/dist/use-render-activity-message-W2lbqLZH.js.map +1 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts +2 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/providers/CopilotKitProvider.types.d.ts +10 -9
- package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/keys.d.ts +10 -0
- package/dist/v2/providers/keys.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/v2/__tests__/mocks/web-inspector.ts +32 -1
- package/src/v2/components/CopilotKitInspector.vue +41 -3
- package/src/v2/components/__tests__/CopilotKitInspector.test.ts +31 -6
- package/src/v2/providers/CopilotKitProvider.types.ts +10 -9
- package/src/v2/providers/CopilotKitProvider.vue +25 -23
- package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +148 -37
- package/src/v2/providers/keys.ts +15 -0
- package/dist/use-render-activity-message-CIlNtfvE.cjs +0 -85
- package/dist/use-render-activity-message-CIlNtfvE.cjs.map +0 -1
- package/dist/use-render-activity-message-Db2rOZkW.js.map +0 -1
|
@@ -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 {
|
|
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
|
-
|
|
543
|
-
|
|
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
|
-
|
|
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("
|
|
562
|
-
const
|
|
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
|
-
|
|
566
|
-
},
|
|
567
|
-
slots: {
|
|
568
|
-
default: () => h("div", "test"),
|
|
603
|
+
enableInspector: false,
|
|
569
604
|
},
|
|
605
|
+
slots: { default: "child" },
|
|
570
606
|
});
|
|
571
607
|
|
|
572
|
-
await
|
|
573
|
-
|
|
574
|
-
|
|
608
|
+
await settleInspectorLoad();
|
|
609
|
+
expect(view.container.querySelector("cpk-web-inspector")).toBeNull();
|
|
610
|
+
expect(defineWebInspector).not.toHaveBeenCalled();
|
|
611
|
+
view.unmount();
|
|
612
|
+
});
|
|
575
613
|
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
581
|
-
|
|
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
|
|
586
|
-
const
|
|
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
|
-
|
|
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
|
|
597
|
-
|
|
598
|
-
|
|
657
|
+
await settleInspectorLoad();
|
|
658
|
+
expect(view.container.querySelector("cpk-web-inspector")).toBeNull();
|
|
659
|
+
expect(defineWebInspector).not.toHaveBeenCalled();
|
|
660
|
+
view.unmount();
|
|
661
|
+
});
|
|
599
662
|
|
|
600
|
-
|
|
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
|
});
|
package/src/v2/providers/keys.ts
CHANGED
|
@@ -23,3 +23,18 @@ export const CopilotChatConfigurationKey: InjectionKey<
|
|
|
23
23
|
export const SandboxFunctionsKey: InjectionKey<
|
|
24
24
|
Ref<readonly SandboxFunction[]>
|
|
25
25
|
> = Symbol("SandboxFunctions");
|
|
26
|
+
|
|
27
|
+
export type VueInspectorOpenRequest = {
|
|
28
|
+
messageId: string;
|
|
29
|
+
threadId?: string;
|
|
30
|
+
agentId?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type VueInspectorContextValue = {
|
|
34
|
+
isInspectorEnabled: ComputedRef<boolean>;
|
|
35
|
+
openInspector: (request: VueInspectorOpenRequest) => void;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const InspectorKey: InjectionKey<VueInspectorContextValue> = Symbol(
|
|
39
|
+
"CopilotKitInspector",
|
|
40
|
+
);
|