skybridge 0.0.0-dev.bc64418 → 0.0.0-dev.bcab395
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/dist/cli/tunnel-control-server.d.ts +9 -0
- package/dist/cli/tunnel-control-server.js +31 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.d.ts +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/use-nodemon.js +2 -2
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-tunnel.d.ts +1 -1
- package/dist/cli/use-tunnel.js +102 -68
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/commands/build.js +28 -7
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.js +26 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +2 -7
- package/dist/commands/start.js.map +1 -1
- package/dist/server/content-helpers.d.ts +27 -0
- package/dist/server/content-helpers.js +46 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.js +21 -3
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +98 -2
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.test.js +12 -9
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/server.d.ts +95 -72
- package/dist/server/server.js +191 -72
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -5
- package/dist/server/templates/development.hbs +2 -2
- package/dist/server/templates/production.hbs +1 -1
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +8 -20
- package/dist/test/utils.js +39 -35
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +523 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +2 -2
- package/dist/web/generate-helpers.d.ts +20 -18
- package/dist/web/generate-helpers.js +20 -18
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +20 -20
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +4 -1
- package/dist/web/plugin/plugin.js +112 -25
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +8 -0
- package/dist/web/plugin/scan-views.js +70 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +67 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/web/plugin/validate-view.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- package/package.json +14 -11
- package/tsconfig.base.json +2 -0
- package/dist/server/widgetsDevServer.d.ts +0 -13
- package/dist/server/widgetsDevServer.js +0 -52
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -334
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/plugin/validate-widget.d.ts +0 -5
- package/dist/web/plugin/validate-widget.js +0 -27
- package/dist/web/plugin/validate-widget.js.map +0 -1
- package/dist/web/plugin/validate-widget.test.js +0 -42
- package/dist/web/plugin/validate-widget.test.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-widget.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
|
@@ -15,7 +15,7 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
15
15
|
* Creates typed versions of skybridge hooks with full type inference
|
|
16
16
|
* for tool names, inputs, and outputs.
|
|
17
17
|
*
|
|
18
|
-
* This is the recommended way to use skybridge hooks in your
|
|
18
|
+
* This is the recommended way to use skybridge hooks in your views.
|
|
19
19
|
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
20
20
|
*
|
|
21
21
|
* @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
|
|
@@ -24,11 +24,13 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
* //
|
|
27
|
+
* // src/server.ts
|
|
28
28
|
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
29
|
-
* .
|
|
29
|
+
* .registerTool({
|
|
30
|
+
* name: "search-trip",
|
|
30
31
|
* inputSchema: { destination: z.string() },
|
|
31
32
|
* outputSchema: { results: z.array(z.string()) },
|
|
33
|
+
* view: { component: "search-trip", description: "Search trips" },
|
|
32
34
|
* }, async ({ destination }) => {
|
|
33
35
|
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
34
36
|
* });
|
|
@@ -38,8 +40,8 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
38
40
|
*
|
|
39
41
|
* @example
|
|
40
42
|
* ```typescript
|
|
41
|
-
* //
|
|
42
|
-
* import type { AppType } from "
|
|
43
|
+
* // src/helpers.ts (one-time setup)
|
|
44
|
+
* import type { AppType } from "./server";
|
|
43
45
|
* import { generateHelpers } from "skybridge/web";
|
|
44
46
|
*
|
|
45
47
|
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
@@ -47,19 +49,19 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
47
49
|
*
|
|
48
50
|
* @example
|
|
49
51
|
* ```typescript
|
|
50
|
-
* //
|
|
51
|
-
* import { useCallTool, useToolInfo } from "../
|
|
52
|
+
* // src/views/search.tsx (usage)
|
|
53
|
+
* import { useCallTool, useToolInfo } from "../helpers";
|
|
52
54
|
*
|
|
53
|
-
* export function
|
|
54
|
-
* const { callTool, data } = useCallTool("search-
|
|
55
|
+
* export function SearchView() {
|
|
56
|
+
* const { callTool, data } = useCallTool("search-trip");
|
|
55
57
|
* // ^ autocomplete for tool names
|
|
56
58
|
* callTool({ destination: "Spain" });
|
|
57
59
|
* // ^ autocomplete for input fields
|
|
58
60
|
*
|
|
59
|
-
* const toolInfo = useToolInfo<"search-
|
|
60
|
-
* // ^ autocomplete for
|
|
61
|
-
* // toolInfo.input is typed based on
|
|
62
|
-
* // toolInfo.output.structuredContent is typed based on
|
|
61
|
+
* const toolInfo = useToolInfo<"search-trip">();
|
|
62
|
+
* // ^ autocomplete for view names
|
|
63
|
+
* // toolInfo.input is typed based on view input schema
|
|
64
|
+
* // toolInfo.output.structuredContent is typed based on view output schema
|
|
63
65
|
* }
|
|
64
66
|
* ```
|
|
65
67
|
*/
|
|
@@ -68,12 +70,12 @@ export declare function generateHelpers<ServerType = never>(): {
|
|
|
68
70
|
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
69
71
|
* and type inference for inputs and outputs.
|
|
70
72
|
*
|
|
71
|
-
* @param name - The name of the
|
|
73
|
+
* @param name - The name of the tool to call. Autocompletes based on your server's tool registry.
|
|
72
74
|
* @returns A hook with typed `callTool` function and `data` property.
|
|
73
75
|
*
|
|
74
76
|
* @example
|
|
75
77
|
* ```typescript
|
|
76
|
-
* const { callTool, data, isPending } = useCallTool("search-
|
|
78
|
+
* const { callTool, data, isPending } = useCallTool("search-trip");
|
|
77
79
|
* // TypeScript knows callTool expects { destination: string }
|
|
78
80
|
* callTool({ destination: "Spain" });
|
|
79
81
|
*
|
|
@@ -85,15 +87,15 @@ export declare function generateHelpers<ServerType = never>(): {
|
|
|
85
87
|
*/
|
|
86
88
|
useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
|
|
87
89
|
/**
|
|
88
|
-
* Typed version of `useToolInfo` that provides autocomplete for
|
|
90
|
+
* Typed version of `useToolInfo` that provides autocomplete for tool names
|
|
89
91
|
* and type inference for inputs, outputs, and responseMetadata.
|
|
90
92
|
*
|
|
91
|
-
* @typeParam K - The name of the
|
|
93
|
+
* @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.
|
|
92
94
|
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
93
95
|
*
|
|
94
96
|
* @example
|
|
95
97
|
* ```typescript
|
|
96
|
-
* const toolInfo = useToolInfo<"search-
|
|
98
|
+
* const toolInfo = useToolInfo<"search-trip">();
|
|
97
99
|
* // toolInfo.input is typed as { destination: string; ... }
|
|
98
100
|
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
99
101
|
* // toolInfo.responseMetadata is typed based on _meta in callback return
|
|
@@ -4,7 +4,7 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
4
4
|
* Creates typed versions of skybridge hooks with full type inference
|
|
5
5
|
* for tool names, inputs, and outputs.
|
|
6
6
|
*
|
|
7
|
-
* This is the recommended way to use skybridge hooks in your
|
|
7
|
+
* This is the recommended way to use skybridge hooks in your views.
|
|
8
8
|
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
9
9
|
*
|
|
10
10
|
* @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
|
|
@@ -13,11 +13,13 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* //
|
|
16
|
+
* // src/server.ts
|
|
17
17
|
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
18
|
-
* .
|
|
18
|
+
* .registerTool({
|
|
19
|
+
* name: "search-trip",
|
|
19
20
|
* inputSchema: { destination: z.string() },
|
|
20
21
|
* outputSchema: { results: z.array(z.string()) },
|
|
22
|
+
* view: { component: "search-trip", description: "Search trips" },
|
|
21
23
|
* }, async ({ destination }) => {
|
|
22
24
|
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
23
25
|
* });
|
|
@@ -27,8 +29,8 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
27
29
|
*
|
|
28
30
|
* @example
|
|
29
31
|
* ```typescript
|
|
30
|
-
* //
|
|
31
|
-
* import type { AppType } from "
|
|
32
|
+
* // src/helpers.ts (one-time setup)
|
|
33
|
+
* import type { AppType } from "./server";
|
|
32
34
|
* import { generateHelpers } from "skybridge/web";
|
|
33
35
|
*
|
|
34
36
|
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
@@ -36,19 +38,19 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* ```typescript
|
|
39
|
-
* //
|
|
40
|
-
* import { useCallTool, useToolInfo } from "../
|
|
41
|
+
* // src/views/search.tsx (usage)
|
|
42
|
+
* import { useCallTool, useToolInfo } from "../helpers";
|
|
41
43
|
*
|
|
42
|
-
* export function
|
|
43
|
-
* const { callTool, data } = useCallTool("search-
|
|
44
|
+
* export function SearchView() {
|
|
45
|
+
* const { callTool, data } = useCallTool("search-trip");
|
|
44
46
|
* // ^ autocomplete for tool names
|
|
45
47
|
* callTool({ destination: "Spain" });
|
|
46
48
|
* // ^ autocomplete for input fields
|
|
47
49
|
*
|
|
48
|
-
* const toolInfo = useToolInfo<"search-
|
|
49
|
-
* // ^ autocomplete for
|
|
50
|
-
* // toolInfo.input is typed based on
|
|
51
|
-
* // toolInfo.output.structuredContent is typed based on
|
|
50
|
+
* const toolInfo = useToolInfo<"search-trip">();
|
|
51
|
+
* // ^ autocomplete for view names
|
|
52
|
+
* // toolInfo.input is typed based on view input schema
|
|
53
|
+
* // toolInfo.output.structuredContent is typed based on view output schema
|
|
52
54
|
* }
|
|
53
55
|
* ```
|
|
54
56
|
*/
|
|
@@ -58,12 +60,12 @@ export function generateHelpers() {
|
|
|
58
60
|
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
59
61
|
* and type inference for inputs and outputs.
|
|
60
62
|
*
|
|
61
|
-
* @param name - The name of the
|
|
63
|
+
* @param name - The name of the tool to call. Autocompletes based on your server's tool registry.
|
|
62
64
|
* @returns A hook with typed `callTool` function and `data` property.
|
|
63
65
|
*
|
|
64
66
|
* @example
|
|
65
67
|
* ```typescript
|
|
66
|
-
* const { callTool, data, isPending } = useCallTool("search-
|
|
68
|
+
* const { callTool, data, isPending } = useCallTool("search-trip");
|
|
67
69
|
* // TypeScript knows callTool expects { destination: string }
|
|
68
70
|
* callTool({ destination: "Spain" });
|
|
69
71
|
*
|
|
@@ -77,15 +79,15 @@ export function generateHelpers() {
|
|
|
77
79
|
return useCallTool(name);
|
|
78
80
|
},
|
|
79
81
|
/**
|
|
80
|
-
* Typed version of `useToolInfo` that provides autocomplete for
|
|
82
|
+
* Typed version of `useToolInfo` that provides autocomplete for tool names
|
|
81
83
|
* and type inference for inputs, outputs, and responseMetadata.
|
|
82
84
|
*
|
|
83
|
-
* @typeParam K - The name of the
|
|
85
|
+
* @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.
|
|
84
86
|
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
85
87
|
*
|
|
86
88
|
* @example
|
|
87
89
|
* ```typescript
|
|
88
|
-
* const toolInfo = useToolInfo<"search-
|
|
90
|
+
* const toolInfo = useToolInfo<"search-trip">();
|
|
89
91
|
* // toolInfo.input is typed as { destination: string; ... }
|
|
90
92
|
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
91
93
|
* // toolInfo.responseMetadata is typed based on _meta in callback return
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE
|
|
1
|
+
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAId,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAIjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -4,15 +4,15 @@ import { generateHelpers } from "./generate-helpers.js";
|
|
|
4
4
|
const server = createTestServer();
|
|
5
5
|
const interfaceServer = createInterfaceTestServer();
|
|
6
6
|
test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
|
|
7
|
-
expectTypeOf().toHaveProperty("search-
|
|
7
|
+
expectTypeOf().toHaveProperty("search-trip");
|
|
8
8
|
expectTypeOf().toHaveProperty("get-trip-details");
|
|
9
|
-
expectTypeOf().toHaveProperty("no-input-
|
|
9
|
+
expectTypeOf().toHaveProperty("no-input-view");
|
|
10
10
|
expectTypeOf().toHaveProperty("calculate-price");
|
|
11
|
-
expectTypeOf().toHaveProperty("inferred-output-
|
|
11
|
+
expectTypeOf().toHaveProperty("inferred-output-view");
|
|
12
12
|
expectTypeOf().toHaveProperty("inferred-tool");
|
|
13
|
-
expectTypeOf().toHaveProperty("
|
|
13
|
+
expectTypeOf().toHaveProperty("view-with-metadata");
|
|
14
14
|
expectTypeOf().toHaveProperty("tool-with-metadata");
|
|
15
|
-
expectTypeOf().toHaveProperty("
|
|
15
|
+
expectTypeOf().toHaveProperty("view-with-mixed-returns");
|
|
16
16
|
});
|
|
17
17
|
test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
|
|
18
18
|
expectTypeOf().toEqualTypeOf();
|
|
@@ -34,21 +34,21 @@ test("ToolOutput extracts the correct output type from callback (inferred)", ()
|
|
|
34
34
|
});
|
|
35
35
|
test("generateHelpers provides autocomplete for tool names (widgets + registerTool)", () => {
|
|
36
36
|
const { useCallTool } = generateHelpers();
|
|
37
|
-
useCallTool("search-
|
|
37
|
+
useCallTool("search-trip");
|
|
38
38
|
useCallTool("get-trip-details");
|
|
39
|
-
useCallTool("no-input-
|
|
39
|
+
useCallTool("no-input-view");
|
|
40
40
|
useCallTool("calculate-price");
|
|
41
|
-
useCallTool("inferred-output-
|
|
41
|
+
useCallTool("inferred-output-view");
|
|
42
42
|
useCallTool("inferred-tool");
|
|
43
|
-
useCallTool("
|
|
43
|
+
useCallTool("view-with-metadata");
|
|
44
44
|
useCallTool("tool-with-metadata");
|
|
45
|
-
useCallTool("
|
|
45
|
+
useCallTool("view-with-mixed-returns");
|
|
46
46
|
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
47
47
|
useCallTool("invalid-name");
|
|
48
48
|
});
|
|
49
49
|
test("useCallTool returns correctly typed callTool function", () => {
|
|
50
50
|
const { useCallTool } = generateHelpers();
|
|
51
|
-
const { callTool } = useCallTool("search-
|
|
51
|
+
const { callTool } = useCallTool("search-trip");
|
|
52
52
|
callTool({ destination: "Spain" });
|
|
53
53
|
callTool({ destination: "France", departureDate: "2024-06-01" });
|
|
54
54
|
callTool({ destination: "Italy", maxPrice: 1000 });
|
|
@@ -57,7 +57,7 @@ test("useCallTool returns correctly typed callTool function", () => {
|
|
|
57
57
|
});
|
|
58
58
|
test("callTool can be called without args for tools with no required inputs", () => {
|
|
59
59
|
const { useCallTool } = generateHelpers();
|
|
60
|
-
const { callTool, callToolAsync } = useCallTool("no-input-
|
|
60
|
+
const { callTool, callToolAsync } = useCallTool("no-input-view");
|
|
61
61
|
callTool();
|
|
62
62
|
callTool({});
|
|
63
63
|
callToolAsync();
|
|
@@ -65,7 +65,7 @@ test("callTool can be called without args for tools with no required inputs", ()
|
|
|
65
65
|
});
|
|
66
66
|
test("callTool requires args for tools with required inputs", () => {
|
|
67
67
|
const { useCallTool } = generateHelpers();
|
|
68
|
-
const { callTool } = useCallTool("search-
|
|
68
|
+
const { callTool } = useCallTool("search-trip");
|
|
69
69
|
// @ts-expect-error - "destination" is required
|
|
70
70
|
callTool();
|
|
71
71
|
// @ts-expect-error - "destination" is required
|
|
@@ -75,7 +75,7 @@ test("callTool requires args for tools with required inputs", () => {
|
|
|
75
75
|
});
|
|
76
76
|
test("callTool supports sideEffects for tools with required inputs", () => {
|
|
77
77
|
const { useCallTool } = generateHelpers();
|
|
78
|
-
const { callTool } = useCallTool("search-
|
|
78
|
+
const { callTool } = useCallTool("search-trip");
|
|
79
79
|
callTool({ destination: "Spain" }, {
|
|
80
80
|
onSuccess: (response, args) => {
|
|
81
81
|
expectTypeOf(response.structuredContent.results).toBeArray();
|
|
@@ -96,7 +96,7 @@ test("callTool supports sideEffects for tools with required inputs", () => {
|
|
|
96
96
|
});
|
|
97
97
|
test("callTool supports sideEffects for tools with no required inputs", () => {
|
|
98
98
|
const { useCallTool } = generateHelpers();
|
|
99
|
-
const { callTool } = useCallTool("no-input-
|
|
99
|
+
const { callTool } = useCallTool("no-input-view");
|
|
100
100
|
callTool({
|
|
101
101
|
onSuccess: (response) => {
|
|
102
102
|
expectTypeOf(response).toHaveProperty("structuredContent");
|
|
@@ -110,16 +110,16 @@ test("callTool supports sideEffects for tools with no required inputs", () => {
|
|
|
110
110
|
});
|
|
111
111
|
test("callToolAsync returns correctly typed promise", () => {
|
|
112
112
|
const { useCallTool } = generateHelpers();
|
|
113
|
-
const { callToolAsync: searchAsync } = useCallTool("search-
|
|
113
|
+
const { callToolAsync: searchAsync } = useCallTool("search-trip");
|
|
114
114
|
const searchPromise = searchAsync({ destination: "Spain" });
|
|
115
115
|
expectTypeOf(searchPromise).resolves.toHaveProperty("structuredContent");
|
|
116
|
-
const { callToolAsync: noInputAsync } = useCallTool("no-input-
|
|
116
|
+
const { callToolAsync: noInputAsync } = useCallTool("no-input-view");
|
|
117
117
|
const noInputPromise = noInputAsync();
|
|
118
118
|
expectTypeOf(noInputPromise).resolves.toHaveProperty("structuredContent");
|
|
119
119
|
});
|
|
120
120
|
test("useCallTool returns correctly typed data", () => {
|
|
121
121
|
const { useCallTool } = generateHelpers();
|
|
122
|
-
const { data } = useCallTool("search-
|
|
122
|
+
const { data } = useCallTool("search-trip");
|
|
123
123
|
if (data) {
|
|
124
124
|
expectTypeOf(data.structuredContent).toExtend();
|
|
125
125
|
expectTypeOf(data.structuredContent.results).toBeArray();
|
|
@@ -128,7 +128,7 @@ test("useCallTool returns correctly typed data", () => {
|
|
|
128
128
|
});
|
|
129
129
|
test("useCallTool returns correctly typed data for callback-inferred outputs", () => {
|
|
130
130
|
const { useCallTool } = generateHelpers();
|
|
131
|
-
const { data: widgetData } = useCallTool("inferred-output-
|
|
131
|
+
const { data: widgetData } = useCallTool("inferred-output-view");
|
|
132
132
|
if (widgetData) {
|
|
133
133
|
expectTypeOf(widgetData.structuredContent).toExtend();
|
|
134
134
|
}
|
|
@@ -193,7 +193,7 @@ test("ToolResponseMetadata extracts correct type when using interface declaratio
|
|
|
193
193
|
});
|
|
194
194
|
test("generateHelpers works with interface-typed server", () => {
|
|
195
195
|
const { useCallTool, useToolInfo } = generateHelpers();
|
|
196
|
-
const { data } = useCallTool("interface-
|
|
196
|
+
const { data } = useCallTool("interface-view");
|
|
197
197
|
if (data) {
|
|
198
198
|
expectTypeOf(data.structuredContent.itemName).toBeString();
|
|
199
199
|
expectTypeOf(data.structuredContent.quantity).toBeNumber();
|
|
@@ -1 +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;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAGlC,MAAM,eAAe,GAAG,yBAAyB,EAAE,CAAC;AAGpD,IAAI,CAAC,qEAAqE,EAAE,GAAG,EAAE;IAG/E,YAAY,EAAS,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,E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AAEH,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;IAC7D,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,eAAe,EAAuB,CAAC;IAE5E,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAC/C,IAAI,IAAI,EAAE,CAAC;QACT,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QAC3D,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,EAAoB,CAAC;IACjD,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACvB,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from "./data-llm.js";
|
|
|
4
4
|
export { generateHelpers } from "./generate-helpers.js";
|
|
5
5
|
export * from "./hooks/index.js";
|
|
6
6
|
export { mountWidget } from "./mount-widget.js";
|
|
7
|
+
export type { SkybridgePluginOptions } from "./plugin/plugin.js";
|
|
7
8
|
export { skybridge } from "./plugin/plugin.js";
|
|
8
9
|
export * from "./types.js";
|
package/dist/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,cAAc,YAAY,CAAC"}
|
|
@@ -1,29 +1,51 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import { discoverViewsSync, writeViewsDts, } from "./scan-views.js";
|
|
1
3
|
import { transform as dataLlmTransform } from "./transform-data-llm.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
import { hasDefaultExport } from "./validate-view.js";
|
|
5
|
+
const VIRTUAL_PREFIX = "/_skybridge/view/";
|
|
6
|
+
const VIRTUAL_MODULE_PREFIX = "\0skybridge:view:";
|
|
7
|
+
function buildVirtualEntry(viewFilePath) {
|
|
8
|
+
const normalized = viewFilePath.replace(/\\/g, "/");
|
|
9
|
+
return [
|
|
10
|
+
`import { mountWidget } from "skybridge/web";`,
|
|
11
|
+
`import Component from "${normalized}";`,
|
|
12
|
+
`import { createElement } from "react";`,
|
|
13
|
+
`mountWidget(createElement(Component));`,
|
|
14
|
+
].join("\n");
|
|
15
|
+
}
|
|
16
|
+
function getViewEntryPattern(viewsDir) {
|
|
17
|
+
const escaped = viewsDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
return new RegExp(`${escaped}\\/(?:[^/]+\\.(?:jsx|tsx)|[^/]+\\/index\\.(?:tsx|jsx))(?:\\?.*)?$`);
|
|
19
|
+
}
|
|
20
|
+
export function skybridge(options) {
|
|
21
|
+
const rawViewsDir = options?.viewsDir ?? "src/views";
|
|
22
|
+
let resolvedViewsDir;
|
|
23
|
+
let projectRoot;
|
|
24
|
+
let viewMap = new Map();
|
|
25
|
+
let viewEntryPattern;
|
|
6
26
|
return {
|
|
7
27
|
name: "skybridge",
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
enforce: "pre",
|
|
29
|
+
// Read by `skybridge build` to resolve viewsDir before `tsc -b` runs.
|
|
30
|
+
api: { viewsDir: rawViewsDir },
|
|
31
|
+
config(config) {
|
|
32
|
+
projectRoot = config.root || process.cwd();
|
|
33
|
+
resolvedViewsDir = isAbsolute(rawViewsDir)
|
|
34
|
+
? rawViewsDir
|
|
35
|
+
: resolve(projectRoot, rawViewsDir);
|
|
36
|
+
viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
|
|
37
|
+
const views = discoverViewsSync(resolvedViewsDir);
|
|
38
|
+
viewMap = new Map(views.map((v) => [v.name, v]));
|
|
39
|
+
writeViewsDts(projectRoot, views);
|
|
40
|
+
const input = {};
|
|
41
|
+
for (const view of views) {
|
|
42
|
+
input[view.name] = `${VIRTUAL_PREFIX}${view.name}`;
|
|
43
|
+
}
|
|
24
44
|
return {
|
|
25
45
|
base: "/assets",
|
|
26
46
|
build: {
|
|
47
|
+
outDir: "dist/assets",
|
|
48
|
+
emptyOutDir: true,
|
|
27
49
|
manifest: true,
|
|
28
50
|
minify: true,
|
|
29
51
|
cssCodeSplit: false,
|
|
@@ -31,6 +53,27 @@ export function skybridge() {
|
|
|
31
53
|
input,
|
|
32
54
|
},
|
|
33
55
|
},
|
|
56
|
+
// Pre-bundle view deps at startup so the first tool invocation
|
|
57
|
+
// doesn't hit Vite's on-demand re-optimization path (which sends
|
|
58
|
+
// `full-reload` over HMR — in our iframe flow the parent host
|
|
59
|
+
// can't honour a reload, and the view silently never mounts).
|
|
60
|
+
optimizeDeps: {
|
|
61
|
+
// Scan view files so transitive user deps (zod, tailwind, etc.)
|
|
62
|
+
// get pre-bundled at startup.
|
|
63
|
+
entries: [
|
|
64
|
+
`${resolvedViewsDir}/*.{tsx,jsx}`,
|
|
65
|
+
`${resolvedViewsDir}/*/index.{tsx,jsx}`,
|
|
66
|
+
],
|
|
67
|
+
// Framework deps imported by the synthesized virtual entry.
|
|
68
|
+
// The scanner can't see the virtual module source, so we must
|
|
69
|
+
// list these explicitly.
|
|
70
|
+
include: [
|
|
71
|
+
"react",
|
|
72
|
+
"react-dom/client",
|
|
73
|
+
"react/jsx-runtime",
|
|
74
|
+
"skybridge/web",
|
|
75
|
+
],
|
|
76
|
+
},
|
|
34
77
|
experimental: {
|
|
35
78
|
renderBuiltUrl: (filename) => {
|
|
36
79
|
return {
|
|
@@ -40,12 +83,56 @@ export function skybridge() {
|
|
|
40
83
|
},
|
|
41
84
|
};
|
|
42
85
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
86
|
+
resolveId(id) {
|
|
87
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
88
|
+
const name = id.slice(VIRTUAL_PREFIX.length);
|
|
89
|
+
if (viewMap.has(name)) {
|
|
90
|
+
return `${VIRTUAL_MODULE_PREFIX}${name}`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
95
|
+
load(id) {
|
|
96
|
+
if (id.startsWith(VIRTUAL_MODULE_PREFIX)) {
|
|
97
|
+
const name = id.slice(VIRTUAL_MODULE_PREFIX.length);
|
|
98
|
+
const view = viewMap.get(name);
|
|
99
|
+
if (view) {
|
|
100
|
+
return buildVirtualEntry(view.filePath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
},
|
|
105
|
+
configureServer(server) {
|
|
106
|
+
if (!resolvedViewsDir) {
|
|
107
|
+
const root = server.config.root || process.cwd();
|
|
108
|
+
resolvedViewsDir = isAbsolute(rawViewsDir)
|
|
109
|
+
? rawViewsDir
|
|
110
|
+
: resolve(root, rawViewsDir);
|
|
111
|
+
projectRoot = root;
|
|
112
|
+
viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
|
|
113
|
+
}
|
|
114
|
+
server.watcher.add(resolvedViewsDir);
|
|
115
|
+
const rescan = () => {
|
|
116
|
+
try {
|
|
117
|
+
const views = discoverViewsSync(resolvedViewsDir);
|
|
118
|
+
viewMap = new Map(views.map((v) => [v.name, v]));
|
|
119
|
+
writeViewsDts(projectRoot, views);
|
|
48
120
|
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
// discoverViewsSync throws on duplicate view names. Catch so
|
|
123
|
+
// chokidar's listener chain doesn't surface it as unhandled and
|
|
124
|
+
// crash the dev server — previous viewMap stays active until
|
|
125
|
+
// the user fixes the conflict.
|
|
126
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
127
|
+
server.config.logger.error(`[skybridge] view rescan failed: ${message}`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
server.watcher.on("add", rescan);
|
|
131
|
+
server.watcher.on("unlink", rescan);
|
|
132
|
+
},
|
|
133
|
+
async transform(code, id) {
|
|
134
|
+
if (viewEntryPattern?.test(id) && !hasDefaultExport(code, id)) {
|
|
135
|
+
this.warn(`View file "${id.split("/").pop()}" is missing a default export.`);
|
|
49
136
|
}
|
|
50
137
|
return await dataLlmTransform(code, id);
|
|
51
138
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAEL,iBAAiB,EACjB,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAMlD,SAAS,iBAAiB,CAAC,YAAoB;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO;QACL,8CAA8C;QAC9C,0BAA0B,UAAU,IAAI;QACxC,wCAAwC;QACxC,wCAAwC;KACzC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAChE,OAAO,IAAI,MAAM,CACf,GAAG,OAAO,mEAAmE,CAC9E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAgC;IACxD,MAAM,WAAW,GAAG,OAAO,EAAE,QAAQ,IAAI,WAAW,CAAC;IACrD,IAAI,gBAAwB,CAAC;IAC7B,IAAI,WAAmB,CAAC;IACxB,IAAI,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAChD,IAAI,gBAAwB,CAAC;IAE7B,OAAO;QACL,IAAI,EAAE,WAAW;Q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AAE,CAAC;gBAC9D,IAAI,CAAC,IAAI,CACP,cAAc,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,gCAAgC,CAClE,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface DiscoveredView {
|
|
2
|
+
name: string;
|
|
3
|
+
filePath: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function discoverViewsSync(viewsDir: string): DiscoveredView[];
|
|
6
|
+
export declare function generateViewsDts(views: DiscoveredView[]): string;
|
|
7
|
+
export declare function writeViewsDts(projectRoot: string, views: DiscoveredView[]): void;
|
|
8
|
+
export declare function scanAndWriteViewsDts(projectRoot?: string, viewsDir?: string): void;
|