skybridge 0.0.0-dev.b138e06 → 0.0.0-dev.b17d0b9
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 +153 -0
- package/bin/run.js +0 -4
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/run-command.d.ts +1 -1
- package/dist/cli/run-command.js +4 -3
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +3 -2
- package/dist/cli/use-execute-steps.js +5 -4
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -0
- package/dist/cli/use-nodemon.js +64 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +97 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +8 -0
- package/dist/cli/use-typescript-check.js +59 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.js +29 -10
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +5 -1
- package/dist/commands/dev.js +38 -9
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +31 -15
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +10 -0
- package/dist/server/asset-base-url-transform-plugin.js +33 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +55 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- 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.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +15 -0
- package/dist/server/express.js +77 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +289 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +5 -3
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +137 -65
- package/dist/server/server.js +379 -87
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -5
- package/dist/server/templates/development.hbs +3 -57
- package/dist/server/templates/production.hbs +2 -3
- 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 +13 -21
- package/dist/test/utils.js +42 -37
- 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/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +24 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +87 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
- package/dist/web/bridges/{apps-sdk-bridge.js → apps-sdk/bridge.js} +2 -2
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/web/bridges/apps-sdk/types.d.ts +126 -0
- package/dist/web/bridges/apps-sdk/types.js +10 -0
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/{hooks/use-apps-sdk-bridge.js → apps-sdk/use-apps-sdk-context.js} +3 -3
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -4
- package/dist/web/bridges/index.js +5 -4
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +48 -0
- package/dist/web/bridges/mcp-app/adaptor.js +268 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
- package/dist/web/bridges/mcp-app/bridge.js +102 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +79 -27
- package/dist/web/bridges/use-host-context.d.ts +2 -0
- package/dist/web/bridges/use-host-context.js +8 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +4 -0
- package/dist/web/components/modal-provider.js +45 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.js +21 -8
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +113 -52
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.js +5 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +131 -65
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -19
- 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/helpers/state.js +13 -8
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -2
- package/dist/web/hooks/index.js +1 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +8 -2
- package/dist/web/hooks/test/utils.js +37 -13
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +3 -2
- package/dist/web/hooks/use-call-tool.js +2 -2
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +3 -3
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +3 -3
- package/dist/web/hooks/use-display-mode.js +3 -4
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +3 -6
- package/dist/web/hooks/use-files.js +5 -2
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +28 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -2
- package/dist/web/hooks/use-layout.js +4 -4
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +7 -6
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +3 -1
- package/dist/web/hooks/use-open-external.js +3 -3
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +27 -12
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.d.ts +2 -2
- package/dist/web/hooks/use-request-modal.js +9 -7
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-send-follow-up-message.js +2 -2
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- package/dist/web/hooks/use-tool-info.js +4 -4
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +5 -5
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +1 -1
- package/dist/web/hooks/use-user.js +20 -4
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +33 -4
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-widget-state.js +10 -10
- package/dist/web/hooks/use-widget-state.js.map +1 -1
- package/dist/web/hooks/use-widget-state.test.js +123 -7
- package/dist/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-widget.js +9 -1
- package/dist/web/mount-widget.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +4 -1
- package/dist/web/plugin/plugin.js +120 -18
- 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/transform-data-llm.js +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- 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/dist/web/proxy.js +0 -1
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +0 -133
- package/dist/web/types.js +0 -9
- package/dist/web/types.js.map +1 -1
- package/package.json +41 -26
- package/tsconfig.base.json +33 -0
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -47
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -234
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/bridges/adaptors/apps-sdk-adaptor.d.ts +0 -13
- package/dist/web/bridges/adaptors/apps-sdk-adaptor.js +0 -33
- package/dist/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
- package/dist/web/bridges/adaptors/mcp-app-adaptor.d.ts +0 -16
- package/dist/web/bridges/adaptors/mcp-app-adaptor.js +0 -120
- package/dist/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
- package/dist/web/bridges/apps-sdk-bridge.d.ts +0 -10
- package/dist/web/bridges/apps-sdk-bridge.js.map +0 -1
- package/dist/web/bridges/hooks/use-adaptor.d.ts +0 -2
- package/dist/web/bridges/hooks/use-adaptor.js +0 -8
- package/dist/web/bridges/hooks/use-adaptor.js.map +0 -1
- package/dist/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
- package/dist/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
- package/dist/web/bridges/hooks/use-bridge.d.ts +0 -2
- package/dist/web/bridges/hooks/use-bridge.js +0 -8
- package/dist/web/bridges/hooks/use-bridge.js.map +0 -1
- package/dist/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
- package/dist/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
- package/dist/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
- package/dist/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -62
- package/dist/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
- package/dist/web/bridges/mcp-app-bridge.d.ts +0 -49
- package/dist/web/bridges/mcp-app-bridge.js +0 -256
- package/dist/web/bridges/mcp-app-bridge.js.map +0 -1
- package/dist/web/hooks/use-openai-global.d.ts +0 -3
- package/dist/web/hooks/use-openai-global.js +0 -6
- package/dist/web/hooks/use-openai-global.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{web/bridges/hooks/use-mcp-app-bridge.test.d.ts → server/content-helpers.test.d.ts} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { InferTools, ToolInput, ToolOutput, ToolResponseMetadata } from "../server/index.js";
|
|
2
|
+
import type { CallToolResponse } from "./bridges/types.js";
|
|
2
3
|
import { type CallToolAsyncFn, type CallToolFn, type CallToolState } from "./hooks/use-call-tool.js";
|
|
3
4
|
import { type ToolState } from "./hooks/use-tool-info.js";
|
|
4
|
-
import type {
|
|
5
|
+
import type { Objectify, Prettify } from "./types.js";
|
|
5
6
|
type TypedCallToolResponse<TOutput> = CallToolResponse & {
|
|
6
7
|
structuredContent: TOutput;
|
|
7
8
|
};
|
|
@@ -14,7 +15,7 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
14
15
|
* Creates typed versions of skybridge hooks with full type inference
|
|
15
16
|
* for tool names, inputs, and outputs.
|
|
16
17
|
*
|
|
17
|
-
* This is the recommended way to use skybridge hooks in your
|
|
18
|
+
* This is the recommended way to use skybridge hooks in your views.
|
|
18
19
|
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
19
20
|
*
|
|
20
21
|
* @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
|
|
@@ -23,11 +24,13 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* ```typescript
|
|
26
|
-
* //
|
|
27
|
+
* // src/server.ts
|
|
27
28
|
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
28
|
-
* .
|
|
29
|
+
* .registerTool({
|
|
30
|
+
* name: "search-trip",
|
|
29
31
|
* inputSchema: { destination: z.string() },
|
|
30
32
|
* outputSchema: { results: z.array(z.string()) },
|
|
33
|
+
* view: { component: "search-trip", description: "Search trips" },
|
|
31
34
|
* }, async ({ destination }) => {
|
|
32
35
|
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
33
36
|
* });
|
|
@@ -37,8 +40,8 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
37
40
|
*
|
|
38
41
|
* @example
|
|
39
42
|
* ```typescript
|
|
40
|
-
* //
|
|
41
|
-
* import type { AppType } from "
|
|
43
|
+
* // src/helpers.ts (one-time setup)
|
|
44
|
+
* import type { AppType } from "./server";
|
|
42
45
|
* import { generateHelpers } from "skybridge/web";
|
|
43
46
|
*
|
|
44
47
|
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
@@ -46,19 +49,19 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
|
|
|
46
49
|
*
|
|
47
50
|
* @example
|
|
48
51
|
* ```typescript
|
|
49
|
-
* //
|
|
50
|
-
* import { useCallTool, useToolInfo } from "../
|
|
52
|
+
* // src/views/search.tsx (usage)
|
|
53
|
+
* import { useCallTool, useToolInfo } from "../helpers";
|
|
51
54
|
*
|
|
52
|
-
* export function
|
|
53
|
-
* const { callTool, data } = useCallTool("search-
|
|
55
|
+
* export function SearchView() {
|
|
56
|
+
* const { callTool, data } = useCallTool("search-trip");
|
|
54
57
|
* // ^ autocomplete for tool names
|
|
55
58
|
* callTool({ destination: "Spain" });
|
|
56
59
|
* // ^ autocomplete for input fields
|
|
57
60
|
*
|
|
58
|
-
* const toolInfo = useToolInfo<"search-
|
|
59
|
-
* // ^ autocomplete for
|
|
60
|
-
* // toolInfo.input is typed based on
|
|
61
|
-
* // 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
|
|
62
65
|
* }
|
|
63
66
|
* ```
|
|
64
67
|
*/
|
|
@@ -67,12 +70,12 @@ export declare function generateHelpers<ServerType = never>(): {
|
|
|
67
70
|
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
68
71
|
* and type inference for inputs and outputs.
|
|
69
72
|
*
|
|
70
|
-
* @param name - The name of the
|
|
73
|
+
* @param name - The name of the tool to call. Autocompletes based on your server's tool registry.
|
|
71
74
|
* @returns A hook with typed `callTool` function and `data` property.
|
|
72
75
|
*
|
|
73
76
|
* @example
|
|
74
77
|
* ```typescript
|
|
75
|
-
* const { callTool, data, isPending } = useCallTool("search-
|
|
78
|
+
* const { callTool, data, isPending } = useCallTool("search-trip");
|
|
76
79
|
* // TypeScript knows callTool expects { destination: string }
|
|
77
80
|
* callTool({ destination: "Spain" });
|
|
78
81
|
*
|
|
@@ -84,15 +87,15 @@ export declare function generateHelpers<ServerType = never>(): {
|
|
|
84
87
|
*/
|
|
85
88
|
useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
|
|
86
89
|
/**
|
|
87
|
-
* Typed version of `useToolInfo` that provides autocomplete for
|
|
90
|
+
* Typed version of `useToolInfo` that provides autocomplete for tool names
|
|
88
91
|
* and type inference for inputs, outputs, and responseMetadata.
|
|
89
92
|
*
|
|
90
|
-
* @typeParam K - The name of the
|
|
93
|
+
* @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.
|
|
91
94
|
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
92
95
|
*
|
|
93
96
|
* @example
|
|
94
97
|
* ```typescript
|
|
95
|
-
* const toolInfo = useToolInfo<"search-
|
|
98
|
+
* const toolInfo = useToolInfo<"search-trip">();
|
|
96
99
|
* // toolInfo.input is typed as { destination: string; ... }
|
|
97
100
|
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
98
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":"
|
|
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","s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AE,CAAC;IAChE,YAAY,EAAkC,CAAC,UAAU,EAAE,CAAC;AAC9D,CAAC,CAAC,CAAC;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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import superjson, {} from "superjson";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
2
3
|
import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
|
|
3
4
|
export function filterWidgetContext(state) {
|
|
4
5
|
if (state === null || state === undefined) {
|
|
@@ -11,13 +12,15 @@ export function injectWidgetContext(newState) {
|
|
|
11
12
|
if (newState === null) {
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const currentState = getAdaptor()
|
|
16
|
+
.getHostContextStore("widgetState")
|
|
17
|
+
.getSnapshot();
|
|
18
|
+
if (currentState !== null &&
|
|
19
|
+
currentState !== undefined &&
|
|
20
|
+
WIDGET_CONTEXT_KEY in currentState) {
|
|
18
21
|
return {
|
|
19
22
|
...newState,
|
|
20
|
-
[WIDGET_CONTEXT_KEY]:
|
|
23
|
+
[WIDGET_CONTEXT_KEY]: currentState[WIDGET_CONTEXT_KEY],
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
return newState;
|
|
@@ -29,9 +32,11 @@ export function deserializeState(value) {
|
|
|
29
32
|
return superjson.deserialize(value);
|
|
30
33
|
}
|
|
31
34
|
export function getInitialState(defaultState) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const widgetState = getAdaptor()
|
|
36
|
+
.getHostContextStore("widgetState")
|
|
37
|
+
.getSnapshot();
|
|
38
|
+
if (widgetState !== null && widgetState !== undefined) {
|
|
39
|
+
return filterWidgetContext(widgetState);
|
|
35
40
|
}
|
|
36
41
|
return typeof defaultState === "function"
|
|
37
42
|
? defaultState()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/web/helpers/state.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAwB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,UAAU,mBAAmB,CACjC,KAAgB;IAEhB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,KAErD,CAAC;IAEF,OAAO,aAAkB,CAAC;AAC5B,CAAC;AA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ED,MAAM,UAAU,gBAAgB,CAAC,KAAsB;IACrD,OAAO,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,YAAoC;IAEpC,MAAM,WAAW,GAAG,UAAU,EAAE;SAC7B,mBAAmB,CAAC,aAAa,CAAC;SAClC,WAAW,EAAkB,CAAC;IAEjC,IAAI,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,OAAO,YAAY,KAAK,UAAU;QACvC,CAAC,CAAC,YAAY,EAAE;QAChB,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -2,10 +2,10 @@ export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEff
|
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
3
|
export { useFiles } from "./use-files.js";
|
|
4
4
|
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
5
|
-
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
5
|
+
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
|
7
6
|
export { useRequestModal } from "./use-request-modal.js";
|
|
8
7
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
9
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
10
|
export { type UserState, useUser } from "./use-user.js";
|
|
11
11
|
export { useWidgetState } from "./use-widget-state.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -3,9 +3,9 @@ export { useDisplayMode } from "./use-display-mode.js";
|
|
|
3
3
|
export { useFiles } from "./use-files.js";
|
|
4
4
|
export { useLayout } from "./use-layout.js";
|
|
5
5
|
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
7
6
|
export { useRequestModal } from "./use-request-modal.js";
|
|
8
7
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
9
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
10
|
export { useUser } from "./use-user.js";
|
|
11
11
|
export { useWidgetState } from "./use-widget-state.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type { McpUiHostContext,
|
|
2
|
-
export declare
|
|
1
|
+
import type { McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
export declare class MockResizeObserver {
|
|
3
|
+
observe(): void;
|
|
4
|
+
unobserve(): void;
|
|
5
|
+
disconnect(): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext) => import("vitest").Mock<(message: {
|
|
8
|
+
method: string;
|
|
3
9
|
id: number;
|
|
4
10
|
}) => void>;
|
|
5
11
|
export declare const fireToolInputNotification: (args: Record<string, unknown>) => void;
|
|
@@ -1,24 +1,47 @@
|
|
|
1
1
|
import { fireEvent } from "@testing-library/react";
|
|
2
2
|
import { act } from "react";
|
|
3
3
|
import { vi } from "vitest";
|
|
4
|
+
export class MockResizeObserver {
|
|
5
|
+
observe() { }
|
|
6
|
+
unobserve() { }
|
|
7
|
+
disconnect() { }
|
|
8
|
+
}
|
|
4
9
|
const DEFAULT_CONTEXT = {};
|
|
5
10
|
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
switch (message.method) {
|
|
12
|
+
case "ui/initialize": {
|
|
13
|
+
const result = {
|
|
14
|
+
protocolVersion: "2025-06-18",
|
|
15
|
+
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
16
|
+
hostCapabilities: {},
|
|
17
|
+
hostContext: initialContext,
|
|
18
|
+
};
|
|
19
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
20
|
+
source: window.parent,
|
|
21
|
+
data: {
|
|
22
|
+
jsonrpc: "2.0",
|
|
23
|
+
id: message.id,
|
|
24
|
+
result,
|
|
25
|
+
},
|
|
26
|
+
})));
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "ui/update-model-context": {
|
|
30
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
31
|
+
source: window.parent,
|
|
32
|
+
data: {
|
|
33
|
+
jsonrpc: "2.0",
|
|
34
|
+
id: message.id,
|
|
35
|
+
result: {},
|
|
36
|
+
},
|
|
37
|
+
})));
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
19
41
|
});
|
|
20
42
|
export const fireToolInputNotification = (args) => {
|
|
21
43
|
fireEvent(window, new MessageEvent("message", {
|
|
44
|
+
source: window.parent,
|
|
22
45
|
data: {
|
|
23
46
|
jsonrpc: "2.0",
|
|
24
47
|
method: "ui/notifications/tool-input",
|
|
@@ -30,6 +53,7 @@ export const fireToolInputNotification = (args) => {
|
|
|
30
53
|
};
|
|
31
54
|
export const fireToolResultNotification = (params) => {
|
|
32
55
|
fireEvent(window, new MessageEvent("message", {
|
|
56
|
+
source: window.parent,
|
|
33
57
|
data: {
|
|
34
58
|
jsonrpc: "2.0",
|
|
35
59
|
method: "ui/notifications/tool-result",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,OAAO,kBAAkB;IAC7B,OAAO,KAAU,CAAC;IAClB,SAAS,KAAU,CAAC;IACpB,UAAU,KAAU,CAAC;CACtB;A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OAAO,EAAE,KAAK;YACd,MAAM,EAAE,6BAA6B;YACrC,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CallToolArgs, type CallToolResponse } from "../bridges/index.js";
|
|
2
|
+
import type { HasRequiredKeys } from "../types.js";
|
|
2
3
|
type CallToolIdleState = {
|
|
3
4
|
status: "idle";
|
|
4
5
|
isIdle: true;
|
|
@@ -55,7 +56,7 @@ export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends tr
|
|
|
55
56
|
(): Promise<TResponse>;
|
|
56
57
|
(args: TArgs): Promise<TResponse>;
|
|
57
58
|
} : (args: TArgs) => Promise<TResponse>;
|
|
58
|
-
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "
|
|
59
|
+
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
|
|
59
60
|
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
|
|
60
61
|
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
61
62
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { getAdaptor, } from "../bridges/index.js";
|
|
3
3
|
export const useCallTool = (name) => {
|
|
4
4
|
const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
|
|
5
5
|
const callIdRef = useRef(0);
|
|
6
|
-
const adaptor =
|
|
6
|
+
const adaptor = getAdaptor();
|
|
7
7
|
const execute = async (toolArgs) => {
|
|
8
8
|
const callId = ++callIdRef.current;
|
|
9
9
|
setCallToolState({ status: "pending", data: undefined, error: undefined });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA2F7B,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAK1D,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,MAAM,OAAO,GAAG,KAAK,EACnB,QAAkB,EACiB,EAAE;QACrC,MAAM,MAAM,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC;QACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAE3E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C;QAED,OAAO,CAAC,QAAQ,CAAC;aACd,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACzC,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,WAAW,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACxC,WAAW,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAmD,CAAC;IAErD,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -48,7 +48,7 @@ test("callToolAsync returns correctly typed promise", () => {
|
|
|
48
48
|
const { callToolAsync } = useCallTool("test-tool");
|
|
49
49
|
const promise = callToolAsync({ name: "test" });
|
|
50
50
|
expectTypeOf(promise).resolves.toHaveProperty("structuredContent");
|
|
51
|
-
expectTypeOf(promise).resolves.toHaveProperty("
|
|
51
|
+
expectTypeOf(promise).resolves.toHaveProperty("meta");
|
|
52
52
|
});
|
|
53
53
|
test("state narrowing works correctly with status", () => {
|
|
54
54
|
const result = useCallTool("test-tool");
|