skybridge 0.0.0-dev.6e31b21 → 0.0.0-dev.6f1dfd8
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/LICENSE +21 -674
- package/bin/run.js +9 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +10 -0
- package/dist/cli/use-execute-steps.js +31 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +44 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.js +20 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +33 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.d.ts +64 -0
- package/dist/server/inferUtilityTypes.js +2 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/server.d.ts +99 -0
- package/dist/server/server.js +138 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +3 -0
- package/dist/{src/server → server}/templateHelper.js +5 -4
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +66 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -0
- package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
- package/dist/{src/server → server}/widgetsDevServer.js +13 -5
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +135 -0
- package/dist/test/utils.js +242 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.js +255 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +14 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +39 -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 +46 -0
- 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/{src/web → web/bridges/apps-sdk}/types.d.ts +50 -45
- 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/apps-sdk/use-apps-sdk-context.js +7 -0
- 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 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/adaptor.d.ts +19 -0
- package/dist/web/bridges/mcp-app/adaptor.js +145 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
- package/dist/web/bridges/mcp-app/bridge.js +255 -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 +5 -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.js +66 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +74 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.js.map +1 -0
- 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/create-store.d.ts +3 -0
- package/dist/web/create-store.js +24 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +126 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +14 -0
- package/dist/web/data-llm.js +72 -0
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +139 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/web/generate-helpers.d.ts +116 -0
- package/dist/web/generate-helpers.js +111 -0
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.js +209 -0
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.js +17 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/web/helpers/state.d.ts +7 -0
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +10 -0
- package/dist/web/hooks/index.js +11 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +60 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/web/hooks/use-call-tool.d.ts +101 -0
- package/dist/web/hooks/use-call-tool.js +68 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js +104 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +41 -15
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +10 -0
- package/dist/web/hooks/use-files.js +7 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/web/hooks/use-files.test.d.ts +1 -0
- package/dist/web/hooks/use-files.test.js +29 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.js +8 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/web/hooks/use-open-external.test.js +50 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +14 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/web/hooks/use-request-modal.test.js +57 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/web/hooks/use-tool-info.d.ts +36 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test-d.js +109 -0
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +19 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +94 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-widget-state.js +32 -0
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.test.js +3 -2
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/web/index.d.ts +8 -0
- package/dist/web/index.js +9 -0
- package/dist/web/index.js.map +1 -0
- package/dist/{src/web → web}/mount-widget.js +5 -0
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js +81 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.js +39 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/web/plugin/transform-data-llm.js +96 -0
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/web/plugin/transform-data-llm.test.js +81 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/web/proxy.d.ts +1 -0
- package/dist/web/proxy.js +53 -0
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +54 -31
- package/README.md +0 -198
- package/dist/src/server/index.d.ts +0 -2
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -13
- package/dist/src/server/server.js +0 -57
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -28
- package/dist/src/test/utils.js +0 -43
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -90
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/hooks/index.d.ts +0 -13
- package/dist/src/web/hooks/index.js +0 -14
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.d.ts +0 -61
- package/dist/src/web/hooks/use-call-tool.js +0 -66
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -23
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -5
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +0 -23
- package/dist/src/web/hooks/use-tool-info.js +0 -22
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -134
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-output.js +0 -9
- package/dist/src/web/hooks/use-tool-output.js.map +0 -1
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.js +0 -30
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.d.ts +0 -4
- package/dist/src/web/index.js +0 -5
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin.js +0 -28
- package/dist/src/web/plugin.js.map +0 -1
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/server → server}/index.js +0 -0
- /package/dist/{src/test → test}/widget.test.d.ts +0 -0
- /package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → web/data-llm.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web/plugin}/plugin.d.ts +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
* Must be a server instance created with method chaining.
|
|
12
|
+
* TypeScript will validate that tools can be inferred from this type.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // server/src/index.ts
|
|
17
|
+
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
18
|
+
* .widget("search-voyage", {}, {
|
|
19
|
+
* inputSchema: { destination: z.string() },
|
|
20
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
21
|
+
* }, async ({ destination }) => {
|
|
22
|
+
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* export type AppType = typeof server;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // web/src/helpers.ts (one-time setup)
|
|
31
|
+
* import type { AppType } from "../server";
|
|
32
|
+
* import { generateHelpers } from "skybridge/web";
|
|
33
|
+
*
|
|
34
|
+
* export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // web/src/widgets/search.tsx (usage)
|
|
40
|
+
* import { useCallTool, useToolInfo } from "../skybridge";
|
|
41
|
+
*
|
|
42
|
+
* export function SearchWidget() {
|
|
43
|
+
* const { callTool, data } = useCallTool("search-voyage");
|
|
44
|
+
* // ^ autocomplete for tool names
|
|
45
|
+
* callTool({ destination: "Spain" });
|
|
46
|
+
* // ^ autocomplete for input fields
|
|
47
|
+
*
|
|
48
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
49
|
+
* // ^ autocomplete for widget names
|
|
50
|
+
* // toolInfo.input is typed based on widget input schema
|
|
51
|
+
* // toolInfo.output.structuredContent is typed based on widget output schema
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function generateHelpers() {
|
|
56
|
+
return {
|
|
57
|
+
/**
|
|
58
|
+
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
59
|
+
* and type inference for inputs and outputs.
|
|
60
|
+
*
|
|
61
|
+
* @param name - The name of the widget to call. Autocompletes based on your server's widget registry.
|
|
62
|
+
* @returns A hook with typed `callTool` function and `data` property.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
67
|
+
* // TypeScript knows callTool expects { destination: string }
|
|
68
|
+
* callTool({ destination: "Spain" });
|
|
69
|
+
*
|
|
70
|
+
* // data.structuredContent is typed based on your outputSchema
|
|
71
|
+
* if (data) {
|
|
72
|
+
* console.log(data.structuredContent.results);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
useCallTool: (name) => {
|
|
77
|
+
return useCallTool(name);
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
81
|
+
* and type inference for inputs, outputs, and responseMetadata.
|
|
82
|
+
*
|
|
83
|
+
* @typeParam K - The name of the widget. Autocompletes based on your server's widget registry.
|
|
84
|
+
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
89
|
+
* // toolInfo.input is typed as { destination: string; ... }
|
|
90
|
+
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
91
|
+
* // toolInfo.responseMetadata is typed based on _meta in callback return
|
|
92
|
+
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
93
|
+
*
|
|
94
|
+
* if (toolInfo.isPending) {
|
|
95
|
+
* // TypeScript knows output and responseMetadata are undefined here
|
|
96
|
+
* console.log(toolInfo.input.destination);
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* if (toolInfo.isSuccess) {
|
|
100
|
+
* // TypeScript knows output and responseMetadata are defined here
|
|
101
|
+
* console.log(toolInfo.output.results);
|
|
102
|
+
* console.log(toolInfo.responseMetadata);
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
useToolInfo: () => {
|
|
107
|
+
return useToolInfo();
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=generate-helpers.js.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;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"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { createInterfaceTestServer, createTestServer } from "../test/utils.js";
|
|
3
|
+
import { generateHelpers } from "./generate-helpers.js";
|
|
4
|
+
const server = createTestServer();
|
|
5
|
+
const interfaceServer = createInterfaceTestServer();
|
|
6
|
+
test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
|
|
7
|
+
expectTypeOf().toHaveProperty("search-voyage");
|
|
8
|
+
expectTypeOf().toHaveProperty("get-trip-details");
|
|
9
|
+
expectTypeOf().toHaveProperty("no-input-widget");
|
|
10
|
+
expectTypeOf().toHaveProperty("calculate-price");
|
|
11
|
+
expectTypeOf().toHaveProperty("inferred-output-widget");
|
|
12
|
+
expectTypeOf().toHaveProperty("inferred-tool");
|
|
13
|
+
expectTypeOf().toHaveProperty("widget-with-metadata");
|
|
14
|
+
expectTypeOf().toHaveProperty("tool-with-metadata");
|
|
15
|
+
expectTypeOf().toHaveProperty("widget-with-mixed-returns");
|
|
16
|
+
});
|
|
17
|
+
test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
|
|
18
|
+
expectTypeOf().toEqualTypeOf();
|
|
19
|
+
});
|
|
20
|
+
test("ToolInput extracts the correct input type from Zod schema", () => {
|
|
21
|
+
expectTypeOf().toEqualTypeOf();
|
|
22
|
+
expectTypeOf().toEqualTypeOf();
|
|
23
|
+
expectTypeOf().toEqualTypeOf();
|
|
24
|
+
});
|
|
25
|
+
test("ToolOutput extracts the correct output type from callback's structuredContent", () => {
|
|
26
|
+
expectTypeOf().toEqualTypeOf();
|
|
27
|
+
expectTypeOf().toEqualTypeOf();
|
|
28
|
+
expectTypeOf().toEqualTypeOf();
|
|
29
|
+
expectTypeOf().toEqualTypeOf();
|
|
30
|
+
});
|
|
31
|
+
test("ToolOutput extracts the correct output type from callback (inferred)", () => {
|
|
32
|
+
expectTypeOf().toEqualTypeOf();
|
|
33
|
+
expectTypeOf().toEqualTypeOf();
|
|
34
|
+
});
|
|
35
|
+
test("generateHelpers provides autocomplete for tool names (widgets + registerTool)", () => {
|
|
36
|
+
const { useCallTool } = generateHelpers();
|
|
37
|
+
useCallTool("search-voyage");
|
|
38
|
+
useCallTool("get-trip-details");
|
|
39
|
+
useCallTool("no-input-widget");
|
|
40
|
+
useCallTool("calculate-price");
|
|
41
|
+
useCallTool("inferred-output-widget");
|
|
42
|
+
useCallTool("inferred-tool");
|
|
43
|
+
useCallTool("widget-with-metadata");
|
|
44
|
+
useCallTool("tool-with-metadata");
|
|
45
|
+
useCallTool("widget-with-mixed-returns");
|
|
46
|
+
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
47
|
+
useCallTool("invalid-name");
|
|
48
|
+
});
|
|
49
|
+
test("useCallTool returns correctly typed callTool function", () => {
|
|
50
|
+
const { useCallTool } = generateHelpers();
|
|
51
|
+
const { callTool } = useCallTool("search-voyage");
|
|
52
|
+
callTool({ destination: "Spain" });
|
|
53
|
+
callTool({ destination: "France", departureDate: "2024-06-01" });
|
|
54
|
+
callTool({ destination: "Italy", maxPrice: 1000 });
|
|
55
|
+
const { callTool: calculateTool } = useCallTool("calculate-price");
|
|
56
|
+
calculateTool({ tripId: "123", passengers: 2 });
|
|
57
|
+
});
|
|
58
|
+
test("callTool can be called without args for tools with no required inputs", () => {
|
|
59
|
+
const { useCallTool } = generateHelpers();
|
|
60
|
+
const { callTool, callToolAsync } = useCallTool("no-input-widget");
|
|
61
|
+
callTool();
|
|
62
|
+
callTool({});
|
|
63
|
+
callToolAsync();
|
|
64
|
+
callToolAsync({});
|
|
65
|
+
});
|
|
66
|
+
test("callTool requires args for tools with required inputs", () => {
|
|
67
|
+
const { useCallTool } = generateHelpers();
|
|
68
|
+
const { callTool } = useCallTool("search-voyage");
|
|
69
|
+
// @ts-expect-error - "destination" is required
|
|
70
|
+
callTool();
|
|
71
|
+
// @ts-expect-error - "destination" is required
|
|
72
|
+
callTool({});
|
|
73
|
+
// This should work
|
|
74
|
+
callTool({ destination: "Spain" });
|
|
75
|
+
});
|
|
76
|
+
test("callTool supports sideEffects for tools with required inputs", () => {
|
|
77
|
+
const { useCallTool } = generateHelpers();
|
|
78
|
+
const { callTool } = useCallTool("search-voyage");
|
|
79
|
+
callTool({ destination: "Spain" }, {
|
|
80
|
+
onSuccess: (response, args) => {
|
|
81
|
+
expectTypeOf(response.structuredContent.results).toBeArray();
|
|
82
|
+
expectTypeOf(args.destination).toBeString();
|
|
83
|
+
},
|
|
84
|
+
onError: (error, args) => {
|
|
85
|
+
expectTypeOf(error).toBeUnknown();
|
|
86
|
+
expectTypeOf(args.destination).toBeString();
|
|
87
|
+
},
|
|
88
|
+
onSettled: (response, error, args) => {
|
|
89
|
+
if (response) {
|
|
90
|
+
expectTypeOf(response.structuredContent.totalCount).toBeNumber();
|
|
91
|
+
}
|
|
92
|
+
expectTypeOf(error).toBeUnknown();
|
|
93
|
+
expectTypeOf(args.destination).toBeString();
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
test("callTool supports sideEffects for tools with no required inputs", () => {
|
|
98
|
+
const { useCallTool } = generateHelpers();
|
|
99
|
+
const { callTool } = useCallTool("no-input-widget");
|
|
100
|
+
callTool({
|
|
101
|
+
onSuccess: (response) => {
|
|
102
|
+
expectTypeOf(response).toHaveProperty("structuredContent");
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
callTool({}, {
|
|
106
|
+
onSuccess: (response) => {
|
|
107
|
+
expectTypeOf(response).toHaveProperty("structuredContent");
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
test("callToolAsync returns correctly typed promise", () => {
|
|
112
|
+
const { useCallTool } = generateHelpers();
|
|
113
|
+
const { callToolAsync: searchAsync } = useCallTool("search-voyage");
|
|
114
|
+
const searchPromise = searchAsync({ destination: "Spain" });
|
|
115
|
+
expectTypeOf(searchPromise).resolves.toHaveProperty("structuredContent");
|
|
116
|
+
const { callToolAsync: noInputAsync } = useCallTool("no-input-widget");
|
|
117
|
+
const noInputPromise = noInputAsync();
|
|
118
|
+
expectTypeOf(noInputPromise).resolves.toHaveProperty("structuredContent");
|
|
119
|
+
});
|
|
120
|
+
test("useCallTool returns correctly typed data", () => {
|
|
121
|
+
const { useCallTool } = generateHelpers();
|
|
122
|
+
const { data } = useCallTool("search-voyage");
|
|
123
|
+
if (data) {
|
|
124
|
+
expectTypeOf(data.structuredContent).toExtend();
|
|
125
|
+
expectTypeOf(data.structuredContent.results).toBeArray();
|
|
126
|
+
expectTypeOf(data.structuredContent.totalCount).toBeNumber();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
test("useCallTool returns correctly typed data for callback-inferred outputs", () => {
|
|
130
|
+
const { useCallTool } = generateHelpers();
|
|
131
|
+
const { data: widgetData } = useCallTool("inferred-output-widget");
|
|
132
|
+
if (widgetData) {
|
|
133
|
+
expectTypeOf(widgetData.structuredContent).toExtend();
|
|
134
|
+
}
|
|
135
|
+
const { data: toolData } = useCallTool("inferred-tool");
|
|
136
|
+
if (toolData) {
|
|
137
|
+
expectTypeOf(toolData.structuredContent).toExtend();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
test("generateHelpers provides autocomplete for tool names in useToolInfo (widgets + registerTool)", () => {
|
|
141
|
+
const { useToolInfo } = generateHelpers();
|
|
142
|
+
useToolInfo();
|
|
143
|
+
useToolInfo();
|
|
144
|
+
useToolInfo();
|
|
145
|
+
useToolInfo();
|
|
146
|
+
useToolInfo();
|
|
147
|
+
useToolInfo();
|
|
148
|
+
useToolInfo();
|
|
149
|
+
useToolInfo();
|
|
150
|
+
useToolInfo();
|
|
151
|
+
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
152
|
+
useToolInfo();
|
|
153
|
+
});
|
|
154
|
+
test("useToolInfo infers input and output types", () => {
|
|
155
|
+
const { useToolInfo } = generateHelpers();
|
|
156
|
+
const toolInfo = useToolInfo();
|
|
157
|
+
// Input is only available when not in idle state
|
|
158
|
+
if (!(toolInfo.status === "idle")) {
|
|
159
|
+
expectTypeOf(toolInfo.input).toExtend();
|
|
160
|
+
}
|
|
161
|
+
if (toolInfo.status === "success") {
|
|
162
|
+
expectTypeOf(toolInfo.output).toExtend();
|
|
163
|
+
expectTypeOf(toolInfo.output.results).toBeArray();
|
|
164
|
+
expectTypeOf(toolInfo.output.totalCount).toBeNumber();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
test("ToolResponseMetadata extracts _meta type from callback", () => {
|
|
168
|
+
expectTypeOf().toEqualTypeOf();
|
|
169
|
+
expectTypeOf().toEqualTypeOf();
|
|
170
|
+
expectTypeOf().toBeUnknown();
|
|
171
|
+
});
|
|
172
|
+
test("useToolInfo infers responseMetadata type from generateHelpers", () => {
|
|
173
|
+
const { useToolInfo } = generateHelpers();
|
|
174
|
+
const toolInfo = useToolInfo();
|
|
175
|
+
if (toolInfo.isSuccess) {
|
|
176
|
+
expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();
|
|
177
|
+
expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();
|
|
178
|
+
expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
test("ToolResponseMetadata extracts _meta from mixed return paths", () => {
|
|
182
|
+
expectTypeOf().toEqualTypeOf();
|
|
183
|
+
});
|
|
184
|
+
test("ToolOutput extracts correct type when using interface declaration", () => {
|
|
185
|
+
expectTypeOf().toHaveProperty("itemName");
|
|
186
|
+
expectTypeOf().toBeString();
|
|
187
|
+
expectTypeOf().toBeNumber();
|
|
188
|
+
});
|
|
189
|
+
test("ToolResponseMetadata extracts correct type when using interface declaration", () => {
|
|
190
|
+
expectTypeOf().toHaveProperty("processedBy");
|
|
191
|
+
expectTypeOf().toBeString();
|
|
192
|
+
expectTypeOf().toBeNumber();
|
|
193
|
+
});
|
|
194
|
+
test("generateHelpers works with interface-typed server", () => {
|
|
195
|
+
const { useCallTool, useToolInfo } = generateHelpers();
|
|
196
|
+
const { data } = useCallTool("interface-widget");
|
|
197
|
+
if (data) {
|
|
198
|
+
expectTypeOf(data.structuredContent.itemName).toBeString();
|
|
199
|
+
expectTypeOf(data.structuredContent.quantity).toBeNumber();
|
|
200
|
+
}
|
|
201
|
+
const toolInfo = useToolInfo();
|
|
202
|
+
if (toolInfo.isSuccess) {
|
|
203
|
+
expectTypeOf(toolInfo.output.itemName).toBeString();
|
|
204
|
+
expectTypeOf(toolInfo.output.quantity).toBeNumber();
|
|
205
|
+
expectTypeOf(toolInfo.responseMetadata.processedBy).toBeString();
|
|
206
|
+
expectTypeOf(toolInfo.responseMetadata.version).toBeNumber();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
//# 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;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,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,YAAY,EAAS,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;IAC/D,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAC7D,YAAY,EAAS,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;IAC3D,YAAY,EAAS,CAAC,cAAc,CAAC,2BAA2B,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0EAA0E,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
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMinimalTestServer } from "../test/utils.js";
|
|
3
|
+
import { generateHelpers } from "./generate-helpers.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,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SuperJSONResult } from "superjson";
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
|
+
export declare function filterWidgetContext<T extends UnknownObject>(state?: T | null): T | null;
|
|
4
|
+
export declare function injectWidgetContext<T extends UnknownObject>(newState: T | null): T | null;
|
|
5
|
+
export declare function serializeState(value: UnknownObject): unknown;
|
|
6
|
+
export declare function deserializeState(value: SuperJSONResult): unknown;
|
|
7
|
+
export declare function getInitialState<State extends UnknownObject>(defaultState?: State | (() => State)): State | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import superjson, {} from "superjson";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
|
|
4
|
+
export function filterWidgetContext(state) {
|
|
5
|
+
if (state === null || state === undefined) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const { [WIDGET_CONTEXT_KEY]: _, ...filteredState } = state;
|
|
9
|
+
return filteredState;
|
|
10
|
+
}
|
|
11
|
+
export function injectWidgetContext(newState) {
|
|
12
|
+
if (newState === null) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const currentState = getAdaptor()
|
|
16
|
+
.getHostContextStore("widgetState")
|
|
17
|
+
.getSnapshot();
|
|
18
|
+
if (currentState !== null &&
|
|
19
|
+
currentState !== undefined &&
|
|
20
|
+
WIDGET_CONTEXT_KEY in currentState) {
|
|
21
|
+
return {
|
|
22
|
+
...newState,
|
|
23
|
+
[WIDGET_CONTEXT_KEY]: currentState[WIDGET_CONTEXT_KEY],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return newState;
|
|
27
|
+
}
|
|
28
|
+
export function serializeState(value) {
|
|
29
|
+
return superjson.parse(superjson.stringify(value)); // Strips functions
|
|
30
|
+
}
|
|
31
|
+
export function deserializeState(value) {
|
|
32
|
+
return superjson.deserialize(value);
|
|
33
|
+
}
|
|
34
|
+
export function getInitialState(defaultState) {
|
|
35
|
+
const widgetState = getAdaptor()
|
|
36
|
+
.getHostContextStore("widgetState")
|
|
37
|
+
.getSnapshot();
|
|
38
|
+
if (widgetState !== null && widgetState !== undefined) {
|
|
39
|
+
return filterWidgetContext(widgetState);
|
|
40
|
+
}
|
|
41
|
+
return typeof defaultState === "function"
|
|
42
|
+
? defaultState()
|
|
43
|
+
: (defaultState ?? null);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +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,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,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;AAED,MAAM,UAAU,mBAAmB,CACjC,QAAkB;IAElB,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,YAAY,GAAG,UAAU,EAAE;SAC9B,mBAAmB,CAAC,aAAa,CAAC;SAClC,WAAW,EAAqD,CAAC;IAEpE,IACE,YAAY,KAAK,IAAI;QACrB,YAAY,KAAK,SAAS;QAC1B,kBAAkB,IAAI,YAAY,EAClC,CAAC;QACD,OAAO;YACL,GAAG,QAAQ;YACX,CAAC,kBAAkB,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAAC;SAClD,CAAC;IACT,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAoB;IACjD,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB;AACzE,CAAC;AAED,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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
|
|
3
|
+
import { filterWidgetContext, serializeState } from "./state.js";
|
|
4
|
+
describe("state helpers", () => {
|
|
5
|
+
describe("filterWidgetContext", () => {
|
|
6
|
+
it("should return null when state is null", () => {
|
|
7
|
+
expect(filterWidgetContext(null)).toBe(null);
|
|
8
|
+
});
|
|
9
|
+
it("should return null when state is undefined", () => {
|
|
10
|
+
expect(filterWidgetContext(undefined)).toBe(null);
|
|
11
|
+
});
|
|
12
|
+
it("should correctly filter WIDGET_CONTEXT_KEY and preserve other properties", () => {
|
|
13
|
+
const stateWithContextAndOthers = {
|
|
14
|
+
a: 1,
|
|
15
|
+
b: "two",
|
|
16
|
+
c: { nested: true },
|
|
17
|
+
[WIDGET_CONTEXT_KEY]: "context",
|
|
18
|
+
};
|
|
19
|
+
const filteredWithContextAndOthers = filterWidgetContext(stateWithContextAndOthers);
|
|
20
|
+
expect(filteredWithContextAndOthers).toEqual({
|
|
21
|
+
a: 1,
|
|
22
|
+
b: "two",
|
|
23
|
+
c: { nested: true },
|
|
24
|
+
});
|
|
25
|
+
const stateNoContext = { count: 5, name: "test" };
|
|
26
|
+
const filteredNoContext = filterWidgetContext(stateNoContext);
|
|
27
|
+
expect(filteredNoContext).toEqual(stateNoContext);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("serializeState", () => {
|
|
31
|
+
it("should serialize plain objects", () => {
|
|
32
|
+
const array = [1, "two", { three: 3 }];
|
|
33
|
+
const date = new Date("2023-01-01T00:00:00Z");
|
|
34
|
+
const object = {
|
|
35
|
+
a: 1,
|
|
36
|
+
b: "test",
|
|
37
|
+
c: true,
|
|
38
|
+
array,
|
|
39
|
+
date,
|
|
40
|
+
function: () => "test",
|
|
41
|
+
};
|
|
42
|
+
const result = serializeState(object);
|
|
43
|
+
expect(result).toEqual({
|
|
44
|
+
a: 1,
|
|
45
|
+
b: "test",
|
|
46
|
+
c: true,
|
|
47
|
+
array: [1, "two", { three: 3 }],
|
|
48
|
+
date: new Date("2023-01-01T00:00:00.000Z"),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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,cAAc,CAAC,CAAC;YAC9D,MAAM,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YACvC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG;gBACb,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK;gBACL,IAAI;gBACJ,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;aACvB,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAC/B,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useFiles } from "./use-files.js";
|
|
4
|
+
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
5
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
9
|
+
export { type UserState, useUser } from "./use-user.js";
|
|
10
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { useCallTool, } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useFiles } from "./use-files.js";
|
|
4
|
+
export { useLayout } from "./use-layout.js";
|
|
5
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
9
|
+
export { useUser } from "./use-user.js";
|
|
10
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
9
|
+
id: number;
|
|
10
|
+
}) => void>;
|
|
11
|
+
export declare const fireToolInputNotification: (args: Record<string, unknown>) => void;
|
|
12
|
+
export declare const fireToolResultNotification: (params: {
|
|
13
|
+
content: McpUiToolResultNotification["params"]["content"];
|
|
14
|
+
structuredContent: Record<string, unknown>;
|
|
15
|
+
_meta?: Record<string, unknown>;
|
|
16
|
+
}) => void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fireEvent } from "@testing-library/react";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
export class MockResizeObserver {
|
|
5
|
+
observe() { }
|
|
6
|
+
unobserve() { }
|
|
7
|
+
disconnect() { }
|
|
8
|
+
}
|
|
9
|
+
const DEFAULT_CONTEXT = {};
|
|
10
|
+
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
|
|
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
|
+
data: {
|
|
21
|
+
jsonrpc: "2.0",
|
|
22
|
+
id: message.id,
|
|
23
|
+
result,
|
|
24
|
+
},
|
|
25
|
+
})));
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case "ui/update-model-context": {
|
|
29
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
30
|
+
data: {
|
|
31
|
+
jsonrpc: "2.0",
|
|
32
|
+
id: message.id,
|
|
33
|
+
result: {},
|
|
34
|
+
},
|
|
35
|
+
})));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
export const fireToolInputNotification = (args) => {
|
|
41
|
+
fireEvent(window, new MessageEvent("message", {
|
|
42
|
+
data: {
|
|
43
|
+
jsonrpc: "2.0",
|
|
44
|
+
method: "ui/notifications/tool-input",
|
|
45
|
+
params: {
|
|
46
|
+
arguments: args,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
export const fireToolResultNotification = (params) => {
|
|
52
|
+
fireEvent(window, new MessageEvent("message", {
|
|
53
|
+
data: {
|
|
54
|
+
jsonrpc: "2.0",
|
|
55
|
+
method: "ui/notifications/tool-result",
|
|
56
|
+
params,
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAED,MAAM,eAAe,GAAqB,EAAE,CAAC;AAE7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,iBAAmC,eAAe,EAClD,EAAE,CAC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