skybridge 0.0.0-dev.e071d95 → 0.0.0-dev.e07ec67
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 +1 -0
- package/dist/cli/build-helpers.d.ts +10 -0
- package/dist/cli/build-helpers.js +93 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +89 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +68 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.d.ts +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +71 -60
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -73
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +49 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +32 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +18 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +18 -0
- package/dist/server/auth/providers/auth0.js +31 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +16 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +30 -0
- package/dist/server/auth/providers/custom.js +40 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +128 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +35 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +39 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.test.js +61 -0
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +20 -0
- package/dist/server/file-ref.js +19 -0
- package/dist/server/file-ref.js.map +1 -1
- package/dist/server/index.d.ts +9 -2
- package/dist/server/index.js +7 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +176 -5
- package/dist/server/server.js +250 -126
- package/dist/server/server.js.map +1 -1
- package/dist/server/templates.generated.d.ts +2 -2
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +171 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/view.test.js +70 -102
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +330 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +208 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -1
- package/dist/web/bridges/apps-sdk/bridge.js +15 -3
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +9 -7
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +68 -4
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +91 -1
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +5 -4
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +18 -6
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/hooks/index.d.ts +1 -0
- package/dist/web/hooks/index.js +1 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +56 -11
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +37 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +20 -0
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +11 -3
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.d.ts +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +14 -0
- package/dist/web/hooks/use-request-close.js +13 -0
- package/dist/web/hooks/use-request-close.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +17 -0
- package/dist/web/hooks/use-request-size.js +16 -0
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -32
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +6 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +26 -1
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +22 -19
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -27
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -112
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -51
- package/dist/web/bridges/mcp-app/adaptor.js +0 -279
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-tools.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/view-tools.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3C,MAAM,QAAQ,GAAqB,EAAE,CAAC;AAEtC;;;GAGG;AACH,SAAS,eAAe;IACtB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,OAAuB,EAAE,EAAE;QACpD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,MAAM,KAAK,eAAe,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YACnE,GAAG,CAAC,GAAG,EAAE;gBACP,MAAM,CAA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I,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAE9C,UAAU,EAAE,CAAC;QACb,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { waitFor } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport * as z from \"zod\";\nimport { MockResizeObserver } from \"../../hooks/test/utils.js\";\nimport { HostAdaptor } from \"../adaptor.js\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ntype JsonRpcMessage = {\n jsonrpc: \"2.0\";\n id?: number;\n method?: string;\n params?: Record<string, unknown>;\n result?: Record<string, unknown>;\n error?: { message: string };\n};\n\nconst outgoing: JsonRpcMessage[] = [];\n\n/**\n * Stand-in MCP Apps host: replies to `ui/initialize` and records every message\n * the app posts so tests can assert on responses and notifications.\n */\nfunction installHostMock() {\n outgoing.length = 0;\n const postMessage = vi.fn((message: JsonRpcMessage) => {\n outgoing.push(message);\n if (message.method === \"ui/initialize\" && message.id !== undefined) {\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: {},\n hostContext: {},\n },\n },\n }),\n );\n });\n }\n });\n vi.stubGlobal(\"parent\", { postMessage });\n}\n\nlet nextId = 1000;\n\n/** Send a host → app JSON-RPC request and resolve with the full response (result or error). */\nasync function callHost(method: string, params: Record<string, unknown> = {}) {\n const id = ++nextId;\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: { jsonrpc: \"2.0\", id, method, params },\n }),\n );\n });\n await waitFor(() => {\n expect(outgoing.some((m) => m.id === id)).toBe(true);\n });\n return outgoing.find((m) => m.id === id);\n}\n\ndescribe(\"McpApp view tools\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n installHostMock();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"advertises the tools capability during ui/initialize\", async () => {\n await McpAppBridge.getInstance().getApp();\n const init = outgoing.find((m) => m.method === \"ui/initialize\");\n expect(init?.params?.appCapabilities).toMatchObject({\n tools: { listChanged: true },\n });\n });\n\n it(\"lists a registered view tool with its input schema\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n adaptor.registerViewTool(\n {\n name: \"chess_make_move\",\n description: \"Play a move\",\n inputSchema: { san: z.string() },\n annotations: { readOnlyHint: false },\n },\n () => ({ content: [{ type: \"text\", text: \"ok\" }] }),\n );\n\n const response = await callHost(\"tools/list\");\n const tools = response?.result?.tools as Array<{\n name: string;\n description?: string;\n inputSchema: { properties?: Record<string, unknown> };\n annotations?: { readOnlyHint?: boolean };\n }>;\n expect(tools).toHaveLength(1);\n const [tool] = tools;\n expect(tool?.name).toBe(\"chess_make_move\");\n expect(tool?.description).toBe(\"Play a move\");\n expect(tool?.inputSchema.properties).toHaveProperty(\"san\");\n expect(tool?.annotations?.readOnlyHint).toBe(false);\n });\n\n it(\"invokes the handler with validated args and returns its result\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(({ san }: { san: string }) => ({\n content: [{ type: \"text\" as const, text: `played ${san}` }],\n structuredContent: { lastMove: san },\n }));\n\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: \"e4\" },\n });\n const result = response?.result;\n\n // ext-apps invokes the callback as `(args, extra)`; assert on the args only.\n expect(handler.mock.calls[0]?.[0]).toEqual({ san: \"e4\" });\n expect(result?.structuredContent).toEqual({ lastMove: \"e4\" });\n expect(result?.isError).toBeFalsy();\n expect(result?.content).toEqual([{ type: \"text\", text: \"played e4\" }]);\n });\n\n it(\"rejects the call without invoking the handler when args are invalid\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(() => ({ content: [] }));\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n // ext-apps validates input against the schema and rejects with a JSON-RPC\n // error before the handler runs.\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: 42 },\n });\n\n expect(handler).not.toHaveBeenCalled();\n expect(response?.error).toBeDefined();\n });\n\n it(\"rejects a call to an unknown tool\", async () => {\n await McpAppBridge.getInstance().getApp();\n const response = await callHost(\"tools/call\", {\n name: \"nope\",\n arguments: {},\n });\n expect(response?.error).toBeDefined();\n });\n\n it(\"removes the tool and notifies the host when unregistered\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const unregister = adaptor.registerViewTool(\n { name: \"chess_reset\" },\n () => ({ content: [{ type: \"text\", text: \"reset\" }] }),\n );\n\n await waitFor(() => {\n expect(\n outgoing.some((m) => m.method === \"notifications/tools/list_changed\"),\n ).toBe(true);\n });\n\n let listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(1);\n\n unregister();\n listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(0);\n });\n});\n"]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
2
|
+
import type { CallToolResult, EmbeddedResource, ResourceLink, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
2
3
|
import type { useSyncExternalStore } from "react";
|
|
3
4
|
import type { ViewHostType } from "../../server/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Globals injected on `window.skybridge` by the host. Tells the view which
|
|
7
|
+
* runtime it's running under and where to reach the MCP server.
|
|
8
|
+
*/
|
|
4
9
|
export type SkybridgeProperties = {
|
|
5
10
|
hostType: ViewHostType;
|
|
6
11
|
serverUrl: string;
|
|
@@ -10,26 +15,43 @@ declare global {
|
|
|
10
15
|
skybridge: SkybridgeProperties;
|
|
11
16
|
}
|
|
12
17
|
}
|
|
18
|
+
/** Arguments passed to a tool call. `null` for tools that take no input. */
|
|
13
19
|
export type CallToolArgs = Record<string, unknown> | null;
|
|
20
|
+
/**
|
|
21
|
+
* Result of a tool call as surfaced to the view: MCP `content` blocks plus
|
|
22
|
+
* the typed `structuredContent` and optional `meta`. `isError` is set when
|
|
23
|
+
* the server marks the call as failed.
|
|
24
|
+
*/
|
|
14
25
|
export type CallToolResponse = {
|
|
15
26
|
content: CallToolResult["content"];
|
|
16
27
|
structuredContent: NonNullable<CallToolResult["structuredContent"]>;
|
|
17
28
|
isError: NonNullable<CallToolResult["isError"]>;
|
|
18
29
|
meta?: CallToolResult["_meta"];
|
|
19
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* How the view is laid out by the host. `"modal"` is host-driven (see
|
|
33
|
+
* {@link useRequestModal}); `"pip"`, `"inline"`, and `"fullscreen"` are
|
|
34
|
+
* requestable via {@link useDisplayMode}.
|
|
35
|
+
*/
|
|
20
36
|
export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
|
|
37
|
+
/** Subset of {@link DisplayMode} that the view can request from the host. */
|
|
21
38
|
export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
|
|
39
|
+
/** Host theme. Mirror this in your view's styling for a native feel. */
|
|
22
40
|
export type Theme = "light" | "dark";
|
|
41
|
+
/** Coarse device class reported by the host. `"unknown"` when unavailable. */
|
|
23
42
|
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
43
|
+
/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */
|
|
24
44
|
export type SafeAreaInsets = {
|
|
25
45
|
top: number;
|
|
26
46
|
right: number;
|
|
27
47
|
bottom: number;
|
|
28
48
|
left: number;
|
|
29
49
|
};
|
|
50
|
+
/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */
|
|
30
51
|
export type SafeArea = {
|
|
31
52
|
insets: SafeAreaInsets;
|
|
32
53
|
};
|
|
54
|
+
/** Device and input-capability hints exposed via {@link useUser}. */
|
|
33
55
|
export type UserAgent = {
|
|
34
56
|
device: {
|
|
35
57
|
type: DeviceType;
|
|
@@ -39,6 +61,11 @@ export type UserAgent = {
|
|
|
39
61
|
touch: boolean;
|
|
40
62
|
};
|
|
41
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Full snapshot of state the host exposes to the view. Most fields are
|
|
66
|
+
* better accessed through their dedicated hooks (`useLayout`, `useUser`,
|
|
67
|
+
* `useToolInfo`, etc.) — read this directly only for advanced cases.
|
|
68
|
+
*/
|
|
42
69
|
export interface HostContext {
|
|
43
70
|
theme: Theme;
|
|
44
71
|
locale: string;
|
|
@@ -55,26 +82,34 @@ export interface HostContext {
|
|
|
55
82
|
};
|
|
56
83
|
viewState: Record<string, unknown> | null;
|
|
57
84
|
}
|
|
85
|
+
/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */
|
|
58
86
|
export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
|
|
87
|
+
/** @internal Bridge contract implemented by per-host bridge classes. */
|
|
59
88
|
export interface Bridge<Context> {
|
|
60
89
|
subscribe(key: keyof Context): Subscribe;
|
|
61
90
|
subscribe(keys: readonly (keyof Context)[]): Subscribe;
|
|
62
91
|
getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
|
|
63
92
|
}
|
|
93
|
+
/** @internal Per-key snapshot store backing {@link useHostContext}. */
|
|
64
94
|
export type HostContextStore<K extends keyof HostContext> = {
|
|
65
95
|
subscribe: Subscribe;
|
|
66
96
|
getSnapshot: () => HostContext[K];
|
|
67
97
|
};
|
|
98
|
+
/** Persisted view state shape (a plain object). See {@link useViewState}. */
|
|
68
99
|
export type ViewState = Record<string, unknown>;
|
|
100
|
+
/** Updater form accepted when writing to view state. */
|
|
69
101
|
export type SetViewStateAction = ViewState | ((prevState: ViewState | null) => ViewState);
|
|
102
|
+
/** Reference to a host-managed file (returned by {@link useFiles}). */
|
|
70
103
|
export type FileMetadata = {
|
|
71
104
|
fileId: string;
|
|
72
105
|
fileName?: string;
|
|
73
106
|
mimeType?: string;
|
|
74
107
|
};
|
|
108
|
+
/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */
|
|
75
109
|
export type UploadFileOptions = {
|
|
76
110
|
library?: boolean;
|
|
77
111
|
};
|
|
112
|
+
/** Options for {@link useRequestModal}'s `open` call. */
|
|
78
113
|
export type RequestModalOptions = {
|
|
79
114
|
title?: string;
|
|
80
115
|
params?: Record<string, unknown>;
|
|
@@ -86,12 +121,19 @@ export type RequestModalOptions = {
|
|
|
86
121
|
height?: number;
|
|
87
122
|
};
|
|
88
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the
|
|
126
|
+
* host not to append its `?redirectUrl=…` tracking query parameter when
|
|
127
|
+
* opening allowlisted targets.
|
|
128
|
+
*/
|
|
89
129
|
export type OpenExternalOptions = {
|
|
90
130
|
redirectUrl?: false;
|
|
91
131
|
};
|
|
132
|
+
/** Options for {@link useSendFollowUpMessage}. */
|
|
92
133
|
export type SendFollowUpMessageOptions = {
|
|
93
134
|
scrollToBottom?: boolean;
|
|
94
135
|
};
|
|
136
|
+
/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */
|
|
95
137
|
export type RequestSizeOptions = {
|
|
96
138
|
width?: number;
|
|
97
139
|
height?: number;
|
|
@@ -102,6 +144,43 @@ export type DownloadParams = {
|
|
|
102
144
|
export type DownloadResult = {
|
|
103
145
|
isError?: boolean;
|
|
104
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Args passed to a {@link ViewToolHandler}, inferred from the tool's
|
|
149
|
+
* `inputSchema` (optionality preserved). Mirrors the server's `registerTool`.
|
|
150
|
+
*/
|
|
151
|
+
export type InferViewToolArgs<Shape extends ZodRawShapeCompat> = {
|
|
152
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
153
|
+
} & {
|
|
154
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Declares a tool the view exposes to the host/model (the MCP Apps
|
|
158
|
+
* "app-provided tools" feature). Mirrors the server-side `registerTool` config.
|
|
159
|
+
* Namespace `name` (e.g. `chess_make_move`) to avoid clashing with server tools.
|
|
160
|
+
*/
|
|
161
|
+
export type ViewToolConfig<TInput extends ZodRawShapeCompat = ZodRawShapeCompat> = {
|
|
162
|
+
name: string;
|
|
163
|
+
title?: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
inputSchema?: TInput;
|
|
166
|
+
annotations?: ToolAnnotations;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Value a {@link ViewToolHandler} returns — a standard MCP `CallToolResult`
|
|
170
|
+
* (`content` blocks plus optional `structuredContent` / `isError` / `_meta`),
|
|
171
|
+
* exactly as `ext-apps`' app tool callbacks return it.
|
|
172
|
+
*/
|
|
173
|
+
export type ViewToolResult = CallToolResult;
|
|
174
|
+
/** Handler run when the host calls a view tool. Receives validated, typed args. */
|
|
175
|
+
export type ViewToolHandler<TInput extends ZodRawShapeCompat = ZodRawShapeCompat> = (args: InferViewToolArgs<TInput>) => ViewToolResult | Promise<ViewToolResult>;
|
|
176
|
+
/** @internal Untyped handler signature stored by the adaptor/bridge after type erasure. */
|
|
177
|
+
export type AnyViewToolHandler = (args: Record<string, unknown>) => ViewToolResult | Promise<ViewToolResult>;
|
|
178
|
+
/**
|
|
179
|
+
* @internal
|
|
180
|
+
* Low-level interface every host bridge implements. End-user code should use
|
|
181
|
+
* the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than
|
|
182
|
+
* calling this directly.
|
|
183
|
+
*/
|
|
105
184
|
export interface Adaptor {
|
|
106
185
|
getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
|
|
107
186
|
callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
|
|
@@ -121,4 +200,15 @@ export interface Adaptor {
|
|
|
121
200
|
selectFiles(): Promise<FileMetadata[]>;
|
|
122
201
|
openModal(options: RequestModalOptions): void;
|
|
123
202
|
setOpenInAppUrl(href: string): Promise<void>;
|
|
203
|
+
closeModal(): void;
|
|
204
|
+
registerViewTool(config: ViewToolConfig, handler: AnyViewToolHandler): () => void;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Thrown when a host bridge method is called in a runtime that doesn't
|
|
208
|
+
* support it (e.g. `uploadFile` outside the Apps SDK runtime).
|
|
209
|
+
*/
|
|
210
|
+
export declare class NotSupportedError extends Error {
|
|
211
|
+
readonly method: string;
|
|
212
|
+
readonly reason?: string | undefined;
|
|
213
|
+
constructor(method: string, reason?: string | undefined);
|
|
124
214
|
}
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a host bridge method is called in a runtime that doesn't
|
|
3
|
+
* support it (e.g. `uploadFile` outside the Apps SDK runtime).
|
|
4
|
+
*/
|
|
5
|
+
export class NotSupportedError extends Error {
|
|
6
|
+
method;
|
|
7
|
+
reason;
|
|
8
|
+
constructor(method, reason) {
|
|
9
|
+
super(`${method} is not supported in this runtime${reason ? `: ${reason}` : ""}`);
|
|
10
|
+
this.method = method;
|
|
11
|
+
this.reason = reason;
|
|
12
|
+
this.name = "NotSupportedError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
2
15
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\nexport type CallToolArgs = Record<string, unknown> | null;\n\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\nexport type Theme = \"light\" | \"dark\";\n\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\nexport type ViewState = Record<string, unknown>;\n\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\nexport type UploadFileOptions = { library?: boolean };\n\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"AAgQA;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAExB,MAAM;IACN,MAAM;IAFxB,YACkB,MAAc,EACd,MAAe;QAE/B,KAAK,CACH,GAAG,MAAM,oCAAoC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3E,CAAC;sBALc,MAAM;sBACN,MAAM;QAKtB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF","sourcesContent":["import type {\n SchemaOutput,\n ZodRawShapeCompat,\n} from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\n/** Device and input-capability hints exposed via {@link useUser}. */\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\n/**\n * Full snapshot of state the host exposes to the view. Most fields are\n * better accessed through their dedicated hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) — read this directly only for advanced cases.\n */\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\n/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\n/** @internal Bridge contract implemented by per-host bridge classes. */\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\n/** @internal Per-key snapshot store backing {@link useHostContext}. */\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\n/** Persisted view state shape (a plain object). See {@link useViewState}. */\nexport type ViewState = Record<string, unknown>;\n\n/** Updater form accepted when writing to view state. */\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\n/** Reference to a host-managed file (returned by {@link useFiles}). */\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\n/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */\nexport type UploadFileOptions = { library?: boolean };\n\n/** Options for {@link useRequestModal}'s `open` call. */\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\n/**\n * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the\n * host not to append its `?redirectUrl=…` tracking query parameter when\n * opening allowlisted targets.\n */\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\n/** Options for {@link useSendFollowUpMessage}. */\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\n/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\n/**\n * Args passed to a {@link ViewToolHandler}, inferred from the tool's\n * `inputSchema` (optionality preserved). Mirrors the server's `registerTool`.\n */\nexport type InferViewToolArgs<Shape extends ZodRawShapeCompat> = {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? never\n : K]: SchemaOutput<Shape[K]>;\n} & {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? K\n : never]?: SchemaOutput<Shape[K]>;\n};\n\n/**\n * Declares a tool the view exposes to the host/model (the MCP Apps\n * \"app-provided tools\" feature). Mirrors the server-side `registerTool` config.\n * Namespace `name` (e.g. `chess_make_move`) to avoid clashing with server tools.\n */\nexport type ViewToolConfig<\n TInput extends ZodRawShapeCompat = ZodRawShapeCompat,\n> = {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: TInput;\n annotations?: ToolAnnotations;\n};\n\n/**\n * Value a {@link ViewToolHandler} returns — a standard MCP `CallToolResult`\n * (`content` blocks plus optional `structuredContent` / `isError` / `_meta`),\n * exactly as `ext-apps`' app tool callbacks return it.\n */\nexport type ViewToolResult = CallToolResult;\n\n/** Handler run when the host calls a view tool. Receives validated, typed args. */\nexport type ViewToolHandler<\n TInput extends ZodRawShapeCompat = ZodRawShapeCompat,\n> = (\n args: InferViewToolArgs<TInput>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/** @internal Untyped handler signature stored by the adaptor/bridge after type erasure. */\nexport type AnyViewToolHandler = (\n args: Record<string, unknown>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/**\n * @internal\n * Low-level interface every host bridge implements. End-user code should use\n * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than\n * calling this directly.\n */\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n closeModal(): void;\n registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void;\n}\n\n/**\n * Thrown when a host bridge method is called in a runtime that doesn't\n * support it (e.g. `uploadFile` outside the Apps SDK runtime).\n */\nexport class NotSupportedError extends Error {\n constructor(\n public readonly method: string,\n public readonly reason?: string,\n ) {\n super(\n `${method} is not supported in this runtime${reason ? `: ${reason}` : \"\"}`,\n );\n this.name = \"NotSupportedError\";\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { NotSupportedError } from "./types.js";
|
|
3
|
+
describe("NotSupportedError", () => {
|
|
4
|
+
it("includes method name in message", () => {
|
|
5
|
+
const err = new NotSupportedError("uploadFile");
|
|
6
|
+
expect(err.message).toBe("uploadFile is not supported in this runtime");
|
|
7
|
+
expect(err.name).toBe("NotSupportedError");
|
|
8
|
+
expect(err.method).toBe("uploadFile");
|
|
9
|
+
});
|
|
10
|
+
it("includes reason when provided", () => {
|
|
11
|
+
const err = new NotSupportedError("callTool", "MCP transport unavailable");
|
|
12
|
+
expect(err.message).toBe("callTool is not supported in this runtime: MCP transport unavailable");
|
|
13
|
+
expect(err.reason).toBe("MCP transport unavailable");
|
|
14
|
+
});
|
|
15
|
+
it("is an instance of Error", () => {
|
|
16
|
+
expect(new NotSupportedError("x")).toBeInstanceOf(Error);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=types.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../../src/web/bridges/types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;QAC3E,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CACtB,sEAAsE,CACvE,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,CAAC,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { NotSupportedError } from \"./types.js\";\n\ndescribe(\"NotSupportedError\", () => {\n it(\"includes method name in message\", () => {\n const err = new NotSupportedError(\"uploadFile\");\n expect(err.message).toBe(\"uploadFile is not supported in this runtime\");\n expect(err.name).toBe(\"NotSupportedError\");\n expect(err.method).toBe(\"uploadFile\");\n });\n\n it(\"includes reason when provided\", () => {\n const err = new NotSupportedError(\"callTool\", \"MCP transport unavailable\");\n expect(err.message).toBe(\n \"callTool is not supported in this runtime: MCP transport unavailable\",\n );\n expect(err.reason).toBe(\"MCP transport unavailable\");\n });\n\n it(\"is an instance of Error\", () => {\n expect(new NotSupportedError(\"x\")).toBeInstanceOf(Error);\n });\n});\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { HostContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
|
|
5
|
+
* Used to build the higher-level hooks; prefer those for app code.
|
|
6
|
+
*/
|
|
2
7
|
export declare const useHostContext: <K extends keyof HostContext>(key: K) => HostContext[K];
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { getAdaptor } from "./get-adaptor.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
|
|
6
|
+
* Used to build the higher-level hooks; prefer those for app code.
|
|
7
|
+
*/
|
|
3
8
|
export const useHostContext = (key) => {
|
|
4
9
|
const adaptor = getAdaptor();
|
|
5
10
|
const store = adaptor.getHostContextStore(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\n/**\n * @internal\n * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.\n * Used to build the higher-level hooks; prefer those for app code.\n */\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
4
4
|
const modalStyles = `
|
|
5
5
|
.sb-modal-backdrop {
|
|
6
6
|
position: fixed;
|
|
@@ -20,8 +20,9 @@ const modalStyles = `
|
|
|
20
20
|
}
|
|
21
21
|
`;
|
|
22
22
|
export function ModalProvider({ children }) {
|
|
23
|
-
const adaptor =
|
|
24
|
-
const
|
|
23
|
+
const adaptor = getAdaptor();
|
|
24
|
+
const displayStore = adaptor.getHostContextStore("display");
|
|
25
|
+
const { mode } = useSyncExternalStore(displayStore.subscribe, displayStore.getSnapshot);
|
|
25
26
|
const isOpen = mode === "modal";
|
|
26
27
|
const handleBackdropClick = (e) => {
|
|
27
28
|
if (e.target === e.currentTarget) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-provider.js","sourceRoot":"","sources":["../../../src/web/components/modal-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"modal-provider.js","sourceRoot":"","sources":["../../../src/web/components/modal-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;CAiBnB,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAA2B;IACjE,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAoB,CACnC,YAAY,CAAC,SAAS,EACtB,YAAY,CAAC,WAAW,CACzB,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAEhC,MAAM,mBAAmB,GAAG,CAAC,CAAmB,EAAE,EAAE;QAClD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,CAAgB,EAAE,EAAE;YACnC,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACvB,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,8BACE,0BAAQ,WAAW,GAAS,EAC3B,MAAM,IAAI,CAET,cACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mBAAmB,EAC7B,OAAO,EAAE,mBAAmB,GAC5B,CACH,EACD,cAAK,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,YACtD,QAAQ,GACL,IACL,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useEffect, useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\nconst modalStyles = `\n.sb-modal-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n}\n.sb-modal-container {\n border-radius: 12px;\n position: fixed;\n inset: 0;\n margin: auto;\n width: fit-content;\n height: fit-content;\n background: white;\n z-index: 9999;\n}\n`;\n\nexport function ModalProvider({ children }: { children: ReactNode }) {\n const adaptor = getAdaptor();\n const displayStore = adaptor.getHostContextStore(\"display\");\n const { mode } = useSyncExternalStore(\n displayStore.subscribe,\n displayStore.getSnapshot,\n );\n const isOpen = mode === \"modal\";\n\n const handleBackdropClick = (e: React.MouseEvent) => {\n if (e.target === e.currentTarget) {\n adaptor.closeModal();\n }\n };\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const handler = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n adaptor.closeModal();\n }\n };\n document.addEventListener(\"keydown\", handler);\n return () => document.removeEventListener(\"keydown\", handler);\n }, [isOpen, adaptor]);\n\n return (\n <>\n <style>{modalStyles}</style>\n {isOpen && (\n // biome-ignore lint/a11y/useKeyWithClickEvents: backdrop isn't focusable\n <div\n role=\"dialog\"\n className=\"sb-modal-backdrop\"\n onClick={handleBackdropClick}\n />\n )}\n <div className={isOpen ? \"sb-modal-container\" : undefined}>\n {children}\n </div>\n </>\n );\n}\n"]}
|
|
@@ -1,3 +1,29 @@
|
|
|
1
1
|
import { type StateCreator } from "zustand";
|
|
2
2
|
import type { UnknownObject } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a Zustand store that is bidirectionally synced with the host's
|
|
5
|
+
* `viewState`. Local store updates persist to the host, and external host
|
|
6
|
+
* updates rehydrate the store — making the store the single source of truth
|
|
7
|
+
* for state that should survive view remounts.
|
|
8
|
+
*
|
|
9
|
+
* Use this when you outgrow {@link useViewState} and want first-class Zustand
|
|
10
|
+
* ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
|
|
11
|
+
*
|
|
12
|
+
* Skybridge-internal context fields (see {@link DataLLM}) are filtered out
|
|
13
|
+
* automatically before reaching your store.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam State - Shape of the store's state. Must be a plain object.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* export const useStore = createStore<{ count: number; inc: () => void }>(
|
|
20
|
+
* (set) => ({
|
|
21
|
+
* count: 0,
|
|
22
|
+
* inc: () => set((s) => ({ count: s.count + 1 })),
|
|
23
|
+
* }),
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see https://docs.skybridge.tech/api-reference/create-store
|
|
28
|
+
*/
|
|
3
29
|
export declare function createStore<State extends UnknownObject>(storeCreator: StateCreator<State, [], [], State>, defaultState?: State | (() => State)): import("zustand").UseBoundStore<import("zustand").StoreApi<State>>;
|
package/dist/web/create-store.js
CHANGED
|
@@ -2,6 +2,32 @@ import { dequal } from "dequal/lite";
|
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { getAdaptor } from "./bridges/index.js";
|
|
4
4
|
import { filterViewContext, getInitialState, injectViewContext, serializeState, } from "./helpers/state.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a Zustand store that is bidirectionally synced with the host's
|
|
7
|
+
* `viewState`. Local store updates persist to the host, and external host
|
|
8
|
+
* updates rehydrate the store — making the store the single source of truth
|
|
9
|
+
* for state that should survive view remounts.
|
|
10
|
+
*
|
|
11
|
+
* Use this when you outgrow {@link useViewState} and want first-class Zustand
|
|
12
|
+
* ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
|
|
13
|
+
*
|
|
14
|
+
* Skybridge-internal context fields (see {@link DataLLM}) are filtered out
|
|
15
|
+
* automatically before reaching your store.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam State - Shape of the store's state. Must be a plain object.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* export const useStore = createStore<{ count: number; inc: () => void }>(
|
|
22
|
+
* (set) => ({
|
|
23
|
+
* count: 0,
|
|
24
|
+
* inc: () => set((s) => ({ count: s.count + 1 })),
|
|
25
|
+
* }),
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see https://docs.skybridge.tech/api-reference/create-store
|
|
30
|
+
*/
|
|
5
31
|
export function createStore(storeCreator, defaultState) {
|
|
6
32
|
const initialState = getInitialState(defaultState);
|
|
7
33
|
const store = create()((...args) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,MAAM,UAAU,WAAW,CACzB,YAAgD,EAChD,YAAoC;IAEpC,MAAM,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAEnD,MAAM,KAAK,GAAG,MAAM,EAAS,CAC3B,CAAC,GAAG,IAAoD,EAAE,EAAE;QAC1D,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAExC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;QAC3C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,4EAA4E;IAC5E,qFAAqF;IACrF,KAAK,CAAC,SAAS,CAAC,CAAC,KAAY,EAAE,EAAE;QAC/B,MAAM,eAAe,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,eAAe,KAAK,IAAI,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAC9D,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAwB,CAAC,CAAC;YACnE,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;gBAC5B,UAAU,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,UAAU,EAAE,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrE,cAAc,CAAC,SAAS,CAAC,GAAG,EAAE;QAC5B,MAAM,aAAa,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,aAAa,CAAU,CAAC;YAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAU,CAAC;YAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;gBAC/B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport { create, type StateCreator } from \"zustand\";\nimport { getAdaptor } from \"./bridges/index.js\";\nimport {\n filterViewContext,\n getInitialState,\n injectViewContext,\n serializeState,\n} from \"./helpers/state.js\";\nimport type { UnknownObject } from \"./types.js\";\n\nexport function createStore<State extends UnknownObject>(\n storeCreator: StateCreator<State, [], [], State>,\n defaultState?: State | (() => State),\n) {\n const initialState = getInitialState(defaultState);\n\n const store = create<State>()(\n (...args: Parameters<StateCreator<State, [], [], State>>) => {\n const baseStore = storeCreator(...args);\n\n if (initialState !== null) {\n return { ...baseStore, ...initialState };\n }\n\n return baseStore;\n },\n );\n\n // Bidirectional sync between the Zustand store and the adaptor's viewState.\n // Store changes persist to the host; external viewState changes rehydrate the store.\n store.subscribe((state: State) => {\n const serializedState = serializeState(state);\n if (serializedState !== null && serializedState !== undefined) {\n const stateToPersist = injectViewContext(serializedState as State);\n if (stateToPersist !== null) {\n getAdaptor().setViewState(stateToPersist);\n }\n }\n });\n\n const viewStateStore = getAdaptor().getHostContextStore(\"viewState\");\n viewStateStore.subscribe(() => {\n const externalState = viewStateStore.getSnapshot();\n if (externalState !== null) {\n const filtered = filterViewContext(externalState) as State;\n const current = serializeState(store.getState()) as State;\n if (!dequal(filtered, current)) {\n store.setState(filtered);\n }\n }\n });\n\n return store;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,WAAW,CACzB,YAAgD,EAChD,YAAoC;IAEpC,MAAM,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAEnD,MAAM,KAAK,GAAG,MAAM,EAAS,CAC3B,CAAC,GAAG,IAAoD,EAAE,EAAE;QAC1D,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAExC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;QAC3C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,4EAA4E;IAC5E,qFAAqF;IACrF,KAAK,CAAC,SAAS,CAAC,CAAC,KAAY,EAAE,EAAE;QAC/B,MAAM,eAAe,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,eAAe,KAAK,IAAI,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAC9D,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAwB,CAAC,CAAC;YACnE,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;gBAC5B,UAAU,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,UAAU,EAAE,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrE,cAAc,CAAC,SAAS,CAAC,GAAG,EAAE;QAC5B,MAAM,aAAa,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,aAAa,CAAU,CAAC;YAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAU,CAAC;YAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;gBAC/B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport { create, type StateCreator } from \"zustand\";\nimport { getAdaptor } from \"./bridges/index.js\";\nimport {\n filterViewContext,\n getInitialState,\n injectViewContext,\n serializeState,\n} from \"./helpers/state.js\";\nimport type { UnknownObject } from \"./types.js\";\n\n/**\n * Create a Zustand store that is bidirectionally synced with the host's\n * `viewState`. Local store updates persist to the host, and external host\n * updates rehydrate the store — making the store the single source of truth\n * for state that should survive view remounts.\n *\n * Use this when you outgrow {@link useViewState} and want first-class Zustand\n * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.\n *\n * Skybridge-internal context fields (see {@link DataLLM}) are filtered out\n * automatically before reaching your store.\n *\n * @typeParam State - Shape of the store's state. Must be a plain object.\n *\n * @example\n * ```ts\n * export const useStore = createStore<{ count: number; inc: () => void }>(\n * (set) => ({\n * count: 0,\n * inc: () => set((s) => ({ count: s.count + 1 })),\n * }),\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/create-store\n */\nexport function createStore<State extends UnknownObject>(\n storeCreator: StateCreator<State, [], [], State>,\n defaultState?: State | (() => State),\n) {\n const initialState = getInitialState(defaultState);\n\n const store = create<State>()(\n (...args: Parameters<StateCreator<State, [], [], State>>) => {\n const baseStore = storeCreator(...args);\n\n if (initialState !== null) {\n return { ...baseStore, ...initialState };\n }\n\n return baseStore;\n },\n );\n\n // Bidirectional sync between the Zustand store and the adaptor's viewState.\n // Store changes persist to the host; external viewState changes rehydrate the store.\n store.subscribe((state: State) => {\n const serializedState = serializeState(state);\n if (serializedState !== null && serializedState !== undefined) {\n const stateToPersist = injectViewContext(serializedState as State);\n if (stateToPersist !== null) {\n getAdaptor().setViewState(stateToPersist);\n }\n }\n });\n\n const viewStateStore = getAdaptor().getHostContextStore(\"viewState\");\n viewStateStore.subscribe(() => {\n const externalState = viewStateStore.getSnapshot();\n if (externalState !== null) {\n const filtered = filterViewContext(externalState) as State;\n const current = serializeState(store.getState()) as State;\n if (!dequal(filtered, current)) {\n store.setState(filtered);\n }\n }\n });\n\n return store;\n}\n"]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { cleanup } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { HostAdaptor } from "./bridges/adaptor.js";
|
|
4
|
+
import { getAdaptor } from "./bridges/get-adaptor.js";
|
|
4
5
|
import { McpAppBridge } from "./bridges/mcp-app/bridge.js";
|
|
5
6
|
import { createStore } from "./create-store.js";
|
|
6
7
|
import { VIEW_CONTEXT_KEY } from "./data-llm.js";
|
|
7
8
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./hooks/test/utils.js";
|
|
8
9
|
describe("createStore", () => {
|
|
9
10
|
afterEach(() => {
|
|
11
|
+
HostAdaptor.resetInstance();
|
|
10
12
|
vi.unstubAllGlobals();
|
|
11
13
|
vi.resetAllMocks();
|
|
12
14
|
});
|
|
@@ -78,16 +80,17 @@ describe("createStore", () => {
|
|
|
78
80
|
});
|
|
79
81
|
describe("mcp-app mode", () => {
|
|
80
82
|
beforeEach(() => {
|
|
83
|
+
vi.stubGlobal("openai", undefined);
|
|
81
84
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
82
85
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
83
86
|
});
|
|
84
87
|
afterEach(async () => {
|
|
85
88
|
cleanup();
|
|
89
|
+
HostAdaptor.resetInstance();
|
|
86
90
|
McpAppBridge.resetInstance();
|
|
87
|
-
McpAppAdaptor.resetInstance();
|
|
88
91
|
});
|
|
89
92
|
it("should initialize with null viewState", () => {
|
|
90
|
-
const adaptor =
|
|
93
|
+
const adaptor = getAdaptor();
|
|
91
94
|
const viewState = adaptor.getHostContextStore("viewState").getSnapshot();
|
|
92
95
|
expect(viewState).toBeNull();
|
|
93
96
|
});
|
|
@@ -99,7 +102,7 @@ describe("createStore", () => {
|
|
|
99
102
|
expect(store.getState()).toEqual({ count: 0 });
|
|
100
103
|
});
|
|
101
104
|
it("should update in-memory state via setViewState", async () => {
|
|
102
|
-
const adaptor =
|
|
105
|
+
const adaptor = getAdaptor();
|
|
103
106
|
vi.spyOn(adaptor, "setViewState").mockResolvedValue(undefined);
|
|
104
107
|
const storeCreator = (set) => ({
|
|
105
108
|
count: 0,
|
|
@@ -114,7 +117,7 @@ describe("createStore", () => {
|
|
|
114
117
|
it("should notify listeners when view state changes", async () => {
|
|
115
118
|
const postMessageMock = getMcpAppHostPostMessageMock();
|
|
116
119
|
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
117
|
-
const adaptor =
|
|
120
|
+
const adaptor = getAdaptor();
|
|
118
121
|
const listener = vi.fn();
|
|
119
122
|
adaptor.getHostContextStore("viewState").subscribe(listener);
|
|
120
123
|
await adaptor.setViewState({ count: 42 });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C,gBAAgB,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,EAC9D,GAAG,CACJ,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,CAAC,gBAAgB,EAAE,CAAC;YACpC,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;gBACrE,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { cleanup } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport type { StateCreator } from \"zustand\";\nimport { McpAppAdaptor } from \"./bridges/mcp-app/adaptor.js\";\nimport { McpAppBridge } from \"./bridges/mcp-app/bridge.js\";\nimport { createStore } from \"./create-store.js\";\nimport { VIEW_CONTEXT_KEY } from \"./data-llm.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./hooks/test/utils.js\";\n\ndescribe(\"createStore\", () => {\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n describe(\"apps-sdk mode\", () => {\n let OpenaiMock: {\n widgetState: unknown;\n setWidgetState: Mock;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: null,\n setWidgetState: vi.fn().mockResolvedValue(undefined),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n it(\"should create a store without default state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should create a store with default state\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const defaultState = { count: 5, name: \"default\" };\n\n const store = createStore(storeCreator, defaultState);\n\n expect(store.getState()).toEqual({ count: 5, name: \"default\" });\n });\n\n it(\"should initialize from window.openai.widgetState when available\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const windowState = { count: 20, name: \"window\" };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 20, name: \"window\" });\n });\n\n it(\"should persist state changes to window.openai.setWidgetState\", async () => {\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(OpenaiMock.setWidgetState).toHaveBeenCalled();\n });\n\n const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];\n expect(callArgs).toEqual({\n modelContent: { count: 1 },\n privateContent: {},\n });\n });\n\n it(\"should filter view context from initial state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n const windowState = {\n count: 5,\n [VIEW_CONTEXT_KEY]: \"context-value\",\n };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 5 });\n expect(\n (store.getState() as Record<string, unknown>)[VIEW_CONTEXT_KEY],\n ).toBeUndefined();\n });\n });\n\n describe(\"mcp-app mode\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n cleanup();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should initialize with null viewState\", () => {\n const adaptor = McpAppAdaptor.getInstance();\n const viewState = adaptor.getHostContextStore(\"viewState\").getSnapshot();\n\n expect(viewState).toBeNull();\n });\n\n it(\"should create a store with default state when no persisted state exists\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should update in-memory state via setViewState\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n vi.spyOn(adaptor, \"setViewState\").mockResolvedValue(undefined);\n\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(adaptor.setViewState).toHaveBeenCalledWith({ count: 1 });\n });\n });\n\n it(\"should notify listeners when view state changes\", async () => {\n const postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const adaptor = McpAppAdaptor.getInstance();\n const listener = vi.fn();\n\n adaptor.getHostContextStore(\"viewState\").subscribe(listener);\n await adaptor.setViewState({ count: 42 });\n\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/update-model-context\" }),\n \"*\",\n );\n expect(listener).toHaveBeenCalled();\n expect(adaptor.getHostContextStore(\"viewState\").getSnapshot()).toEqual({\n count: 42,\n });\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"create-store.test.js","sourceRoot":"","sources":["../../src/web/create-store.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0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;gBACrE,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { cleanup } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport type { StateCreator } from \"zustand\";\nimport { HostAdaptor } from \"./bridges/adaptor.js\";\nimport { getAdaptor } from \"./bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"./bridges/mcp-app/bridge.js\";\nimport { createStore } from \"./create-store.js\";\nimport { VIEW_CONTEXT_KEY } from \"./data-llm.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./hooks/test/utils.js\";\n\ndescribe(\"createStore\", () => {\n afterEach(() => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n describe(\"apps-sdk mode\", () => {\n let OpenaiMock: {\n widgetState: unknown;\n setWidgetState: Mock;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: null,\n setWidgetState: vi.fn().mockResolvedValue(undefined),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n it(\"should create a store without default state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should create a store with default state\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const defaultState = { count: 5, name: \"default\" };\n\n const store = createStore(storeCreator, defaultState);\n\n expect(store.getState()).toEqual({ count: 5, name: \"default\" });\n });\n\n it(\"should initialize from window.openai.widgetState when available\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const windowState = { count: 20, name: \"window\" };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 20, name: \"window\" });\n });\n\n it(\"should persist state changes to window.openai.setWidgetState\", async () => {\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(OpenaiMock.setWidgetState).toHaveBeenCalled();\n });\n\n const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];\n expect(callArgs).toEqual({\n modelContent: { count: 1 },\n privateContent: {},\n });\n });\n\n it(\"should filter view context from initial state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n const windowState = {\n count: 5,\n [VIEW_CONTEXT_KEY]: \"context-value\",\n };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 5 });\n expect(\n (store.getState() as Record<string, unknown>)[VIEW_CONTEXT_KEY],\n ).toBeUndefined();\n });\n });\n\n describe(\"mcp-app mode\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n cleanup();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"should initialize with null viewState\", () => {\n const adaptor = getAdaptor();\n const viewState = adaptor.getHostContextStore(\"viewState\").getSnapshot();\n\n expect(viewState).toBeNull();\n });\n\n it(\"should create a store with default state when no persisted state exists\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should update in-memory state via setViewState\", async () => {\n const adaptor = getAdaptor();\n vi.spyOn(adaptor, \"setViewState\").mockResolvedValue(undefined);\n\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(adaptor.setViewState).toHaveBeenCalledWith({ count: 1 });\n });\n });\n\n it(\"should notify listeners when view state changes\", async () => {\n const postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const adaptor = getAdaptor();\n const listener = vi.fn();\n\n adaptor.getHostContextStore(\"viewState\").subscribe(listener);\n await adaptor.setViewState({ count: 42 });\n\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/update-model-context\" }),\n \"*\",\n );\n expect(listener).toHaveBeenCalled();\n expect(adaptor.getHostContextStore(\"viewState\").getSnapshot()).toEqual({\n count: 42,\n });\n });\n });\n});\n"]}
|
package/dist/web/data-llm.d.ts
CHANGED
|
@@ -1,14 +1,47 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
/** Text content surfaced to the model by a {@link DataLLM} component. */
|
|
2
3
|
export type DataLLMContent = string;
|
|
4
|
+
/**
|
|
5
|
+
* A node in the {@link DataLLM} tree. Nested `<DataLLM>` elements form a
|
|
6
|
+
* hierarchy that is serialized as an indented bullet list for the model.
|
|
7
|
+
*/
|
|
3
8
|
export interface DataLLMNode {
|
|
4
9
|
id: string;
|
|
5
10
|
parentId: string | null;
|
|
6
11
|
content: string | null;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Key under which the serialized {@link DataLLM} tree is persisted on the
|
|
15
|
+
* host's `viewState`. The host exposes the value to the model on subsequent
|
|
16
|
+
* turns.
|
|
17
|
+
*/
|
|
8
18
|
export declare const VIEW_CONTEXT_KEY: "__view_context";
|
|
9
19
|
interface DataLLMProps {
|
|
10
20
|
content: DataLLMContent | null | undefined;
|
|
11
21
|
children?: ReactNode;
|
|
12
22
|
}
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Surface in-view content to the LLM so it can reason about what the user is
|
|
25
|
+
* seeing without an extra tool call.
|
|
26
|
+
*
|
|
27
|
+
* Each `<DataLLM>` registers `content` as a node in a tree (parented by any
|
|
28
|
+
* enclosing `<DataLLM>`). The flattened tree is serialized as an indented
|
|
29
|
+
* bullet list and persisted on the host's `viewState` under
|
|
30
|
+
* {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of
|
|
31
|
+
* the next turn's context.
|
|
32
|
+
*
|
|
33
|
+
* Pass `null`/`undefined` for `content` to register only as a structural
|
|
34
|
+
* parent (useful for grouping).
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <DataLLM content="Active filters">
|
|
39
|
+
* <DataLLM content={`Sort: ${sort}`} />
|
|
40
|
+
* <DataLLM content={`Page: ${page}`} />
|
|
41
|
+
* </DataLLM>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see https://docs.skybridge.tech/api-reference/data-llm
|
|
45
|
+
*/
|
|
46
|
+
export declare function DataLLM({ content, children }: DataLLMProps): import("react").JSX.Element;
|
|
14
47
|
export {};
|