skybridge 0.6.0 → 0.8.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.
- package/README.md +173 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/inferUtilityTypes.d.ts +48 -0
- package/dist/src/server/inferUtilityTypes.js +2 -0
- package/dist/src/server/inferUtilityTypes.js.map +1 -0
- package/dist/src/server/server.d.ts +31 -9
- package/dist/src/server/server.js +5 -0
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/test/utils.d.ts +61 -0
- package/dist/src/test/utils.js +122 -1
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/web/data-llm.d.ts +13 -0
- package/dist/src/web/data-llm.js +67 -0
- package/dist/src/web/data-llm.js.map +1 -0
- package/dist/src/web/data-llm.test.d.ts +1 -0
- package/dist/src/web/data-llm.test.js +76 -0
- package/dist/src/web/data-llm.test.js.map +1 -0
- package/dist/src/web/generate-helpers.d.ts +112 -0
- package/dist/src/web/generate-helpers.js +107 -0
- package/dist/src/web/generate-helpers.js.map +1 -0
- package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/src/web/generate-helpers.test-d.js +90 -0
- package/dist/src/web/generate-helpers.test-d.js.map +1 -0
- package/dist/src/web/generate-helpers.test.d.ts +1 -0
- package/dist/src/web/generate-helpers.test.js +17 -0
- package/dist/src/web/generate-helpers.test.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +37 -0
- package/dist/src/web/hooks/use-call-tool.test.js +17 -9
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +3 -3
- package/dist/src/web/hooks/use-widget-state.js +30 -6
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/index.d.ts +3 -1
- package/dist/src/web/index.js +3 -1
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/data-llm.test.js +81 -0
- package/dist/src/web/plugin/data-llm.test.js.map +1 -0
- package/dist/src/web/{plugin.js → plugin/plugin.js} +5 -0
- package/dist/src/web/plugin/plugin.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/src/web/plugin/transform-data-llm.js +93 -0
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
- package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/src/web/types.d.ts +10 -0
- package/dist/src/web/types.js +1 -0
- package/dist/src/web/types.js.map +1 -1
- package/package.json +4 -2
- package/dist/src/web/plugin.js.map +0 -1
- /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
4
|
+
import { DataLLM } from "./data-llm.js";
|
|
5
|
+
describe("DataLLM", () => {
|
|
6
|
+
let OpenaiMock;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
OpenaiMock = {
|
|
9
|
+
widgetState: {},
|
|
10
|
+
setWidgetState: vi.fn(),
|
|
11
|
+
};
|
|
12
|
+
// Use Object.defineProperty to ensure it persists
|
|
13
|
+
Object.defineProperty(globalThis, "openai", {
|
|
14
|
+
value: OpenaiMock,
|
|
15
|
+
writable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
});
|
|
18
|
+
// Also set on window for browser-like environment
|
|
19
|
+
if (typeof window !== "undefined") {
|
|
20
|
+
Object.defineProperty(window, "openai", {
|
|
21
|
+
value: OpenaiMock,
|
|
22
|
+
writable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
vi.resetAllMocks();
|
|
30
|
+
// Keep the mock available for React cleanup, but reset it
|
|
31
|
+
if (typeof window !== "undefined" && window.openai) {
|
|
32
|
+
window.openai.setWidgetState = vi.fn();
|
|
33
|
+
window.openai.widgetState = {};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it("should register a node with content and call setWidgetState", () => {
|
|
37
|
+
render(_jsx(DataLLM, { content: "Test content", children: _jsx("div", { children: "Child" }) }));
|
|
38
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalled();
|
|
39
|
+
const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];
|
|
40
|
+
expect(callArgs).toHaveProperty("__widget_context");
|
|
41
|
+
expect(callArgs?.__widget_context).toContain("- Test content");
|
|
42
|
+
});
|
|
43
|
+
it("should preserve existing widgetState when updating context", () => {
|
|
44
|
+
OpenaiMock.widgetState = { existingKey: "existingValue" };
|
|
45
|
+
render(_jsx(DataLLM, { content: "Test content", children: _jsx("div", { children: "Child" }) }));
|
|
46
|
+
const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];
|
|
47
|
+
expect(callArgs).toHaveProperty("existingKey", "existingValue");
|
|
48
|
+
expect(callArgs).toHaveProperty("__widget_context");
|
|
49
|
+
});
|
|
50
|
+
it("should handle deeply nested DataLLM components", () => {
|
|
51
|
+
render(_jsxs(DataLLM, { content: "Level 1", children: [_jsx(DataLLM, { content: "Level 2A" }), _jsx(DataLLM, { content: "Level 2B", children: _jsx(DataLLM, { content: "Level 3", children: _jsx("div", { children: "Content" }) }) })] }));
|
|
52
|
+
const callArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
|
|
53
|
+
const context = callArgs?.__widget_context;
|
|
54
|
+
expect(context).toContain("- Level 1");
|
|
55
|
+
expect(context).toContain(" - Level 2A");
|
|
56
|
+
expect(context).toContain(" - Level 2B");
|
|
57
|
+
expect(context).toContain(" - Level 3");
|
|
58
|
+
});
|
|
59
|
+
it("should update context when content changes", () => {
|
|
60
|
+
const { rerender } = render(_jsx(DataLLM, { content: "Initial content", children: _jsx("div", { children: "Child" }) }));
|
|
61
|
+
const initialCalls = OpenaiMock.setWidgetState.mock.calls.length;
|
|
62
|
+
rerender(_jsx(DataLLM, { content: "Updated content", children: _jsx("div", { children: "Child" }) }));
|
|
63
|
+
expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(initialCalls);
|
|
64
|
+
const lastCallArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
|
|
65
|
+
expect(lastCallArgs?.__widget_context).toContain("- Updated content");
|
|
66
|
+
});
|
|
67
|
+
it("should remove node and update context when component unmounts", () => {
|
|
68
|
+
const { unmount } = render(_jsx(DataLLM, { content: "Content to remove", children: _jsx("div", { children: "Child" }) }));
|
|
69
|
+
const callsBeforeUnmount = OpenaiMock.setWidgetState.mock.calls.length;
|
|
70
|
+
unmount();
|
|
71
|
+
expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(callsBeforeUnmount);
|
|
72
|
+
const lastCallArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
|
|
73
|
+
expect(lastCallArgs?.__widget_context).not.toContain("Content to remove");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=data-llm.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../../src/web/data-llm.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,GAEH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,OAAO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,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAEvE,OAAO,EAAE,CAAC;QAEV,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,eAAe,CACjE,kBAAkB,CACnB,CAAC;QACF,MAAM,YAAY,GAChB,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAClC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAChD,EAAE,CAAC,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type CallToolState } from "./hooks/use-call-tool.js";
|
|
2
|
+
import { type ToolState } from "./hooks/use-tool-info.js";
|
|
3
|
+
import type { McpServer, InferTools, AnyToolRegistry, ToolInput, ToolOutput } from "../server/index.js";
|
|
4
|
+
import type { CallToolResponse, Prettify, Objectify } from "./types.js";
|
|
5
|
+
type TypedCallToolReturn<TInput, TOutput> = Prettify<CallToolState<CallToolResponse & {
|
|
6
|
+
structuredContent: TOutput;
|
|
7
|
+
}> & {
|
|
8
|
+
callTool: (args: TInput) => void;
|
|
9
|
+
callToolAsync: (args: TInput) => Promise<CallToolResponse & {
|
|
10
|
+
structuredContent: TOutput;
|
|
11
|
+
}>;
|
|
12
|
+
}>;
|
|
13
|
+
type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objectify<TOutput>, Objectify<{}>>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates typed versions of skybridge hooks with full type inference
|
|
16
|
+
* for tool names, inputs, and outputs.
|
|
17
|
+
*
|
|
18
|
+
* This is the recommended way to use skybridge hooks in your widgets.
|
|
19
|
+
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam ServerType - The type of your McpServer instance. Use `typeof server`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // server/src/index.ts
|
|
26
|
+
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
27
|
+
* .widget("search-voyage", {}, {
|
|
28
|
+
* inputSchema: { destination: z.string() },
|
|
29
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
30
|
+
* }, async ({ destination }) => {
|
|
31
|
+
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* export type AppType = typeof server;
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // web/src/skybridge.ts (one-time setup)
|
|
40
|
+
* import type { AppType } from "../server";
|
|
41
|
+
* import { generateHelpers } from "skybridge/web";
|
|
42
|
+
*
|
|
43
|
+
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // web/src/widgets/search.tsx (usage)
|
|
49
|
+
* import { useCallTool, useToolInfo } from "../skybridge";
|
|
50
|
+
*
|
|
51
|
+
* export function SearchWidget() {
|
|
52
|
+
* const { callTool, data } = useCallTool("search-voyage");
|
|
53
|
+
* // ^ autocomplete for tool names
|
|
54
|
+
* callTool({ destination: "Spain" });
|
|
55
|
+
* // ^ autocomplete for input fields
|
|
56
|
+
*
|
|
57
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
58
|
+
* // ^ autocomplete for widget names
|
|
59
|
+
* // toolInfo.input is typed based on widget input schema
|
|
60
|
+
* // toolInfo.output is typed based on widget output schema
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateHelpers<ServerType extends McpServer<AnyToolRegistry>>(): {
|
|
65
|
+
/**
|
|
66
|
+
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
67
|
+
* and type inference for inputs and outputs.
|
|
68
|
+
*
|
|
69
|
+
* @param name - The name of the widget to call. Autocompletes based on your server's widget registry.
|
|
70
|
+
* @returns A hook with typed `callTool` function and `data` property.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
75
|
+
* // TypeScript knows callTool expects { destination: string }
|
|
76
|
+
* callTool({ destination: "Spain" });
|
|
77
|
+
*
|
|
78
|
+
* // data.structuredContent is typed based on your outputSchema
|
|
79
|
+
* if (data) {
|
|
80
|
+
* console.log(data.structuredContent.results);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
|
|
85
|
+
/**
|
|
86
|
+
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
87
|
+
* and type inference for inputs, outputs, and responseMetadata.
|
|
88
|
+
*
|
|
89
|
+
* @typeParam K - The name of the widget. Autocompletes based on your server's widget registry.
|
|
90
|
+
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
95
|
+
* // toolInfo.input is typed as { destination: string; ... }
|
|
96
|
+
* // toolInfo.output is typed as { results: Array<...>; ... } | undefined
|
|
97
|
+
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
98
|
+
*
|
|
99
|
+
* if (toolInfo.isPending) {
|
|
100
|
+
* // TypeScript knows output is undefined here
|
|
101
|
+
* console.log(toolInfo.input.destination);
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* if (toolInfo.isSuccess) {
|
|
105
|
+
* // TypeScript knows output is defined here
|
|
106
|
+
* console.log(toolInfo.output.results);
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
useToolInfo: <ToolName extends keyof InferTools<ServerType> & string>() => TypedToolInfoReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
|
|
111
|
+
};
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useCallTool } from "./hooks/use-call-tool.js";
|
|
2
|
+
import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates typed versions of skybridge hooks with full type inference
|
|
5
|
+
* for tool names, inputs, and outputs.
|
|
6
|
+
*
|
|
7
|
+
* This is the recommended way to use skybridge hooks in your widgets.
|
|
8
|
+
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam ServerType - The type of your McpServer instance. Use `typeof server`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // server/src/index.ts
|
|
15
|
+
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
16
|
+
* .widget("search-voyage", {}, {
|
|
17
|
+
* inputSchema: { destination: z.string() },
|
|
18
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
19
|
+
* }, async ({ destination }) => {
|
|
20
|
+
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* export type AppType = typeof server;
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // web/src/skybridge.ts (one-time setup)
|
|
29
|
+
* import type { AppType } from "../server";
|
|
30
|
+
* import { generateHelpers } from "skybridge/web";
|
|
31
|
+
*
|
|
32
|
+
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // web/src/widgets/search.tsx (usage)
|
|
38
|
+
* import { useCallTool, useToolInfo } from "../skybridge";
|
|
39
|
+
*
|
|
40
|
+
* export function SearchWidget() {
|
|
41
|
+
* const { callTool, data } = useCallTool("search-voyage");
|
|
42
|
+
* // ^ autocomplete for tool names
|
|
43
|
+
* callTool({ destination: "Spain" });
|
|
44
|
+
* // ^ autocomplete for input fields
|
|
45
|
+
*
|
|
46
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
47
|
+
* // ^ autocomplete for widget names
|
|
48
|
+
* // toolInfo.input is typed based on widget input schema
|
|
49
|
+
* // toolInfo.output is typed based on widget output schema
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function generateHelpers() {
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
57
|
+
* and type inference for inputs and outputs.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The name of the widget to call. Autocompletes based on your server's widget registry.
|
|
60
|
+
* @returns A hook with typed `callTool` function and `data` property.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
65
|
+
* // TypeScript knows callTool expects { destination: string }
|
|
66
|
+
* callTool({ destination: "Spain" });
|
|
67
|
+
*
|
|
68
|
+
* // data.structuredContent is typed based on your outputSchema
|
|
69
|
+
* if (data) {
|
|
70
|
+
* console.log(data.structuredContent.results);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
useCallTool: (name) => {
|
|
75
|
+
return useCallTool(name);
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
79
|
+
* and type inference for inputs, outputs, and responseMetadata.
|
|
80
|
+
*
|
|
81
|
+
* @typeParam K - The name of the widget. Autocompletes based on your server's widget registry.
|
|
82
|
+
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
87
|
+
* // toolInfo.input is typed as { destination: string; ... }
|
|
88
|
+
* // toolInfo.output is typed as { results: Array<...>; ... } | undefined
|
|
89
|
+
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
90
|
+
*
|
|
91
|
+
* if (toolInfo.isPending) {
|
|
92
|
+
* // TypeScript knows output is undefined here
|
|
93
|
+
* console.log(toolInfo.input.destination);
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* if (toolInfo.isSuccess) {
|
|
97
|
+
* // TypeScript knows output is defined here
|
|
98
|
+
* console.log(toolInfo.output.results);
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
useToolInfo: () => {
|
|
103
|
+
return useToolInfo();
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=generate-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAC;AAuBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAC0E,EAAE;YAC1F,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;WAwBG;QACH,WAAW,EAAE,GAGX,EAAE;YACF,OAAO,WAAW,EAGjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { generateHelpers } from "./generate-helpers.js";
|
|
3
|
+
import { createTestServer } from "../test/utils.js";
|
|
4
|
+
const server = createTestServer();
|
|
5
|
+
test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
|
|
6
|
+
expectTypeOf().toHaveProperty("search-voyage");
|
|
7
|
+
expectTypeOf().toHaveProperty("get-trip-details");
|
|
8
|
+
expectTypeOf().toHaveProperty("no-input-widget");
|
|
9
|
+
expectTypeOf().toHaveProperty("calculate-price");
|
|
10
|
+
expectTypeOf().toHaveProperty("inferred-output-widget");
|
|
11
|
+
expectTypeOf().toHaveProperty("inferred-tool");
|
|
12
|
+
});
|
|
13
|
+
test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
|
|
14
|
+
expectTypeOf().toEqualTypeOf();
|
|
15
|
+
});
|
|
16
|
+
test("ToolInput extracts the correct input type from Zod schema", () => {
|
|
17
|
+
expectTypeOf().toEqualTypeOf();
|
|
18
|
+
expectTypeOf().toEqualTypeOf();
|
|
19
|
+
expectTypeOf().toEqualTypeOf();
|
|
20
|
+
});
|
|
21
|
+
test("ToolOutput extracts the correct output type from callback's structuredContent", () => {
|
|
22
|
+
expectTypeOf().toEqualTypeOf();
|
|
23
|
+
expectTypeOf().toEqualTypeOf();
|
|
24
|
+
expectTypeOf().toEqualTypeOf();
|
|
25
|
+
expectTypeOf().toEqualTypeOf();
|
|
26
|
+
});
|
|
27
|
+
test("ToolOutput extracts the correct output type from callback (inferred)", () => {
|
|
28
|
+
expectTypeOf().toEqualTypeOf();
|
|
29
|
+
expectTypeOf().toEqualTypeOf();
|
|
30
|
+
});
|
|
31
|
+
test("generateHelpers provides autocomplete for tool names (widgets + registerTool)", () => {
|
|
32
|
+
const { useCallTool } = generateHelpers();
|
|
33
|
+
useCallTool("search-voyage");
|
|
34
|
+
useCallTool("get-trip-details");
|
|
35
|
+
useCallTool("no-input-widget");
|
|
36
|
+
useCallTool("calculate-price");
|
|
37
|
+
useCallTool("inferred-output-widget");
|
|
38
|
+
useCallTool("inferred-tool");
|
|
39
|
+
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
40
|
+
useCallTool("invalid-name");
|
|
41
|
+
});
|
|
42
|
+
test("useCallTool returns correctly typed callTool function", () => {
|
|
43
|
+
const { useCallTool } = generateHelpers();
|
|
44
|
+
const { callTool } = useCallTool("search-voyage");
|
|
45
|
+
callTool({ destination: "Spain" });
|
|
46
|
+
callTool({ destination: "France", departureDate: "2024-06-01" });
|
|
47
|
+
callTool({ destination: "Italy", maxPrice: 1000 });
|
|
48
|
+
const { callTool: calculateTool } = useCallTool("calculate-price");
|
|
49
|
+
calculateTool({ tripId: "123", passengers: 2 });
|
|
50
|
+
});
|
|
51
|
+
test("useCallTool returns correctly typed data", () => {
|
|
52
|
+
const { useCallTool } = generateHelpers();
|
|
53
|
+
const { data } = useCallTool("search-voyage");
|
|
54
|
+
if (data) {
|
|
55
|
+
expectTypeOf(data.structuredContent).toExtend();
|
|
56
|
+
expectTypeOf(data.structuredContent.results).toBeArray();
|
|
57
|
+
expectTypeOf(data.structuredContent.totalCount).toBeNumber();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
test("useCallTool returns correctly typed data for callback-inferred outputs", () => {
|
|
61
|
+
const { useCallTool } = generateHelpers();
|
|
62
|
+
const { data: widgetData } = useCallTool("inferred-output-widget");
|
|
63
|
+
if (widgetData) {
|
|
64
|
+
expectTypeOf(widgetData.structuredContent).toExtend();
|
|
65
|
+
}
|
|
66
|
+
const { data: toolData } = useCallTool("inferred-tool");
|
|
67
|
+
if (toolData) {
|
|
68
|
+
expectTypeOf(toolData.structuredContent).toExtend();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
test("generateHelpers provides autocomplete for tool names in useToolInfo (widgets + registerTool)", () => {
|
|
72
|
+
const { useToolInfo } = generateHelpers();
|
|
73
|
+
useToolInfo();
|
|
74
|
+
useToolInfo();
|
|
75
|
+
useToolInfo();
|
|
76
|
+
useToolInfo();
|
|
77
|
+
useToolInfo();
|
|
78
|
+
useToolInfo();
|
|
79
|
+
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
80
|
+
useToolInfo();
|
|
81
|
+
});
|
|
82
|
+
test("useToolInfo infers input and output types", () => {
|
|
83
|
+
const { useToolInfo } = generateHelpers();
|
|
84
|
+
const toolInfo = useToolInfo();
|
|
85
|
+
expectTypeOf(toolInfo.input).toExtend();
|
|
86
|
+
if (toolInfo.status === "success") {
|
|
87
|
+
expectTypeOf(toolInfo.output).toExtend();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=generate-helpers.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAGlC,IAAI,CAAC,qEAAqE,EAAE,GAAG,EAAE;IAG/E,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACzD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACxD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACxD,YA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C,wBAAwB,CAAC,CAAC;IACnE,IAAI,UAAU,EAAE,CAAC;QACf,YAAY,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAG/C,CAAC;IACP,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;IACxD,IAAI,QAAQ,EAAE,CAAC;QACb,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAG7C,CAAC;IACP,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8FAA8F,EAAE,GAAG,EAAE;IACxG,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,EAAc,CAAC;IAEtD,WAAW,EAAmB,CAAC;IAC/B,WAAW,EAAsB,CAAC;IAClC,WAAW,EAAqB,CAAC;IACjC,WAAW,EAAqB,CAAC;IACjC,WAAW,EAA4B,CAAC;IACxC,WAAW,EAAmB,CAAC;IAE/B,6DAA6D;IAC7D,WAAW,EAAkB,CAAC;AAChC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACrD,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,EAAc,CAAC;IACtD,MAAM,QAAQ,GAAG,WAAW,EAAmB,CAAC;IAEhD,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAA0C,CAAC;IAEhF,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAClC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAA2C,CAAC;IACpF,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { generateHelpers } from "./generate-helpers.js";
|
|
3
|
+
import { createMinimalTestServer } from "../test/utils.js";
|
|
4
|
+
const server = createMinimalTestServer();
|
|
5
|
+
describe("generateHelpers", () => {
|
|
6
|
+
it("should return an object with useCallTool hook", () => {
|
|
7
|
+
const hooks = generateHelpers();
|
|
8
|
+
expect(hooks).toHaveProperty("useCallTool");
|
|
9
|
+
expect(typeof hooks.useCallTool).toBe("function");
|
|
10
|
+
});
|
|
11
|
+
it("should return an object with useToolInfo hook", () => {
|
|
12
|
+
const hooks = generateHelpers();
|
|
13
|
+
expect(hooks).toHaveProperty("useToolInfo");
|
|
14
|
+
expect(typeof hooks.useToolInfo).toBe("function");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=generate-helpers.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;AAGzC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
import type { CallToolArgs, CallToolResponse } from "../types.js";
|
|
2
|
+
type CallToolIdleState = {
|
|
3
|
+
status: "idle";
|
|
4
|
+
isIdle: true;
|
|
5
|
+
isPending: false;
|
|
6
|
+
isSuccess: false;
|
|
7
|
+
isError: false;
|
|
8
|
+
data: undefined;
|
|
9
|
+
error: undefined;
|
|
10
|
+
};
|
|
11
|
+
type CallToolPendingState = {
|
|
12
|
+
status: "pending";
|
|
13
|
+
isIdle: false;
|
|
14
|
+
isPending: true;
|
|
15
|
+
isSuccess: false;
|
|
16
|
+
isError: false;
|
|
17
|
+
data: undefined;
|
|
18
|
+
error: undefined;
|
|
19
|
+
};
|
|
20
|
+
type CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {
|
|
21
|
+
status: "success";
|
|
22
|
+
isIdle: false;
|
|
23
|
+
isPending: false;
|
|
24
|
+
isSuccess: true;
|
|
25
|
+
isError: false;
|
|
26
|
+
data: TData;
|
|
27
|
+
error: undefined;
|
|
28
|
+
};
|
|
29
|
+
type CallToolErrorState = {
|
|
30
|
+
status: "error";
|
|
31
|
+
isIdle: false;
|
|
32
|
+
isPending: false;
|
|
33
|
+
isSuccess: false;
|
|
34
|
+
isError: true;
|
|
35
|
+
data: undefined;
|
|
36
|
+
error: unknown;
|
|
37
|
+
};
|
|
38
|
+
export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
|
|
2
39
|
type SideEffects<ToolArgs, ToolResponse> = {
|
|
3
40
|
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
4
41
|
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
@@ -25,7 +25,7 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
25
25
|
const error = new Error("test error");
|
|
26
26
|
it("should call window.openai.callTool with correct arguments", async () => {
|
|
27
27
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
28
|
-
act(() => {
|
|
28
|
+
await act(async () => {
|
|
29
29
|
result.current.callTool(args);
|
|
30
30
|
});
|
|
31
31
|
expect(OpenaiMock.callTool).toHaveBeenCalledWith(toolName, args);
|
|
@@ -113,7 +113,7 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
113
113
|
vi.unstubAllGlobals();
|
|
114
114
|
vi.resetAllMocks();
|
|
115
115
|
});
|
|
116
|
-
it("should have correct return types when ToolArgs is null and ToolResponse is specified", () => {
|
|
116
|
+
it("should have correct return types when ToolArgs is null and ToolResponse is specified", async () => {
|
|
117
117
|
const { result } = renderHook(() => useCallTool("test-tool"));
|
|
118
118
|
const data = {
|
|
119
119
|
content: [{ type: "text", text: "test" }],
|
|
@@ -123,7 +123,7 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
123
123
|
meta: { id: 123 },
|
|
124
124
|
};
|
|
125
125
|
OpenaiMock.callTool.mockResolvedValueOnce(data);
|
|
126
|
-
act(() => {
|
|
126
|
+
await act(async () => {
|
|
127
127
|
result.current.callTool();
|
|
128
128
|
});
|
|
129
129
|
expect(OpenaiMock.callTool).toHaveBeenCalledWith("test-tool", null);
|
|
@@ -140,9 +140,13 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
140
140
|
meta: {},
|
|
141
141
|
};
|
|
142
142
|
OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
let promise;
|
|
144
|
+
let resolvedValue;
|
|
145
|
+
await act(async () => {
|
|
146
|
+
promise = result.current.callToolAsync(testArgs);
|
|
147
|
+
expectTypeOf(promise);
|
|
148
|
+
resolvedValue = await promise;
|
|
149
|
+
});
|
|
146
150
|
expect(resolvedValue).toEqual(mockResponse);
|
|
147
151
|
});
|
|
148
152
|
it("should correctly type callToolAsync when ToolArgs is null", async () => {
|
|
@@ -154,9 +158,13 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
154
158
|
result: "data",
|
|
155
159
|
};
|
|
156
160
|
OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
let promise;
|
|
162
|
+
let resolvedValue;
|
|
163
|
+
await act(async () => {
|
|
164
|
+
promise = result.current.callToolAsync();
|
|
165
|
+
expectTypeOf(promise);
|
|
166
|
+
resolvedValue = await promise;
|
|
167
|
+
});
|
|
160
168
|
expect(resolvedValue).toEqual(mockResponse);
|
|
161
169
|
});
|
|
162
170
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,EAEF,YAAY,GACb,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,UAA8B,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE;SAClB,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,WAAW,CAAC;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,GAAG,EAAE,CACjC,WAAW,CAAqB,WAAW,CAAC,CAC7C,CAAC;QAEF,MAAM,YAAY,GAId;YACF,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAClD,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,MAAM;SACf,CAAC;QAEF,UAAU,CAAC,QAAQ,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,OAAqC,CAAC;QAC1C,IAAI,aAAkC,CAAC;QACvC,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YACzC,YAAY,CAA+B,OAAO,CAAC,CAAC;YACpD,aAAa,GAAG,MAAM,OAAO,CAAC;QAChC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,aAAc,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UnknownObject } from "../types.js";
|
|
2
|
-
type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
2
|
+
export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
3
3
|
status: "pending";
|
|
4
4
|
isPending: true;
|
|
5
5
|
isSuccess: false;
|
|
@@ -7,7 +7,7 @@ type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
|
7
7
|
output: undefined;
|
|
8
8
|
responseMetadata: undefined;
|
|
9
9
|
};
|
|
10
|
-
type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
10
|
+
export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
11
11
|
status: "success";
|
|
12
12
|
isPending: false;
|
|
13
13
|
isSuccess: true;
|
|
@@ -15,7 +15,7 @@ type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends Unknow
|
|
|
15
15
|
output: ToolOutput;
|
|
16
16
|
responseMetadata: ToolResponseMetadata;
|
|
17
17
|
};
|
|
18
|
-
type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
18
|
+
export type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
19
19
|
type ToolSignature = {
|
|
20
20
|
input: UnknownObject;
|
|
21
21
|
output: UnknownObject;
|