@apollo/client-ai-apps 0.2.0 → 0.2.1
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.
|
@@ -6,13 +6,14 @@ export type ApplicationManifest = {
|
|
|
6
6
|
hash: string;
|
|
7
7
|
resource: string;
|
|
8
8
|
operations: ManifestOperation[];
|
|
9
|
+
csp: ManifestCsp;
|
|
9
10
|
};
|
|
10
11
|
export type ManifestOperation = {
|
|
11
12
|
id: string;
|
|
12
13
|
name: string;
|
|
13
14
|
type: "query" | "mutation";
|
|
14
15
|
body: string;
|
|
15
|
-
variables
|
|
16
|
+
variables?: Record<string, string | undefined>;
|
|
16
17
|
prefetch: boolean;
|
|
17
18
|
prefetchID?: string;
|
|
18
19
|
tools: ManifestTool[];
|
|
@@ -27,3 +28,7 @@ export type ManifestExtraInput = {
|
|
|
27
28
|
description: string;
|
|
28
29
|
type: "string" | "boolean" | "number";
|
|
29
30
|
};
|
|
31
|
+
export type ManifestCsp = {
|
|
32
|
+
connectDomains: string[];
|
|
33
|
+
resourceDomains: string[];
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { expect, test, vi } from "vitest";
|
|
2
|
+
import { useSendFollowUpMessage } from "./useSendFollowUpMessage";
|
|
3
|
+
|
|
4
|
+
test("Should set display mode when returned function is called", async () => {
|
|
5
|
+
vi.stubGlobal("openai", {
|
|
6
|
+
sendFollowUpMessage: vi.fn(async (args: { prompt: string }) => {}),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const sendFollowUpMessage = useSendFollowUpMessage();
|
|
10
|
+
await sendFollowUpMessage("Do a cool thing!");
|
|
11
|
+
|
|
12
|
+
expect(window.openai.sendFollowUpMessage).toBeCalledWith({ prompt: "Do a cool thing!" });
|
|
13
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { expect, test, vi } from "vitest";
|
|
2
|
+
import { useToolEffect, ToolUseProvider } from "./useToolEffect";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
test("Should trigger effect when tool name matches toolResponseMetadata", async () => {
|
|
6
|
+
vi.stubGlobal("openai", {
|
|
7
|
+
toolResponseMetadata: { toolName: "my-app--my-tool" },
|
|
8
|
+
});
|
|
9
|
+
const navigate = vi.fn();
|
|
10
|
+
const wrapper = ({ children }: { children: any }) => <ToolUseProvider appName="my-app">{children}</ToolUseProvider>;
|
|
11
|
+
|
|
12
|
+
renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]), { wrapper });
|
|
13
|
+
|
|
14
|
+
expect(navigate).toBeCalled();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("Should trigger effect when one of multiple tool name matches toolResponseMetadata", async () => {
|
|
18
|
+
vi.stubGlobal("openai", {
|
|
19
|
+
toolResponseMetadata: { toolName: "my-app--my-tool" },
|
|
20
|
+
});
|
|
21
|
+
const navigate = vi.fn();
|
|
22
|
+
const wrapper = ({ children }: { children: any }) => <ToolUseProvider appName="my-app">{children}</ToolUseProvider>;
|
|
23
|
+
|
|
24
|
+
renderHook(() => useToolEffect(["my-tool", "my-similar-tool"], () => navigate(), [navigate]), { wrapper });
|
|
25
|
+
|
|
26
|
+
expect(navigate).toBeCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("Should not trigger effect when tool name does not match toolResponseMetadata", async () => {
|
|
30
|
+
vi.stubGlobal("openai", {
|
|
31
|
+
toolResponseMetadata: { toolName: "my-app--my-other-tool" },
|
|
32
|
+
});
|
|
33
|
+
const navigate = vi.fn();
|
|
34
|
+
const wrapper = ({ children }: { children: any }) => <ToolUseProvider appName="my-app">{children}</ToolUseProvider>;
|
|
35
|
+
|
|
36
|
+
renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]), { wrapper });
|
|
37
|
+
|
|
38
|
+
expect(navigate).not.toBeCalled();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Should throw an error when used outside of a ToolUseProvider", async () => {
|
|
42
|
+
vi.stubGlobal("openai", {
|
|
43
|
+
toolResponseMetadata: { toolName: "my-app--my-other-tool" },
|
|
44
|
+
});
|
|
45
|
+
const navigate = vi.fn();
|
|
46
|
+
|
|
47
|
+
expect(() => renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]))).toThrowError(
|
|
48
|
+
"useToolEffect must be used within ToolUseProvider"
|
|
49
|
+
);
|
|
50
|
+
});
|
|
@@ -6,6 +6,7 @@ export type ApplicationManifest = {
|
|
|
6
6
|
hash: string;
|
|
7
7
|
resource: string;
|
|
8
8
|
operations: ManifestOperation[];
|
|
9
|
+
csp: ManifestCsp;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
export type ManifestOperation = {
|
|
@@ -13,7 +14,7 @@ export type ManifestOperation = {
|
|
|
13
14
|
name: string;
|
|
14
15
|
type: "query" | "mutation";
|
|
15
16
|
body: string;
|
|
16
|
-
variables
|
|
17
|
+
variables?: Record<string, string | undefined>;
|
|
17
18
|
prefetch: boolean;
|
|
18
19
|
prefetchID?: string;
|
|
19
20
|
tools: ManifestTool[];
|
|
@@ -30,3 +31,8 @@ export type ManifestExtraInput = {
|
|
|
30
31
|
description: string;
|
|
31
32
|
type: "string" | "boolean" | "number";
|
|
32
33
|
};
|
|
34
|
+
|
|
35
|
+
export type ManifestCsp = {
|
|
36
|
+
connectDomains: string[];
|
|
37
|
+
resourceDomains: string[];
|
|
38
|
+
};
|