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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SET_GLOBALS_EVENT_TYPE, } from "./types.js";
|
|
2
|
+
/** @internal Singleton bridge over `window.openai` events. Used by `HostAdaptor`. */
|
|
2
3
|
export class AppsSdkBridge {
|
|
3
4
|
static instance = null;
|
|
4
5
|
static getInstance() {
|
|
5
|
-
if (window.
|
|
6
|
-
window.openai
|
|
7
|
-
throw new Error("Apps SDK Bridge can only be used in the apps-sdk runtime");
|
|
6
|
+
if (window.openai === undefined) {
|
|
7
|
+
throw new Error("Apps SDK Bridge requires window.openai (Apps SDK runtime).");
|
|
8
8
|
}
|
|
9
9
|
if (AppsSdkBridge.instance === null) {
|
|
10
10
|
AppsSdkBridge.instance = new AppsSdkBridge();
|
|
@@ -42,5 +42,17 @@ export class AppsSdkBridge {
|
|
|
42
42
|
}
|
|
43
43
|
return window.openai[key];
|
|
44
44
|
};
|
|
45
|
+
createOverlayStores() {
|
|
46
|
+
return {
|
|
47
|
+
display: {
|
|
48
|
+
subscribe: this.subscribe("view"),
|
|
49
|
+
getSnapshot: () => this.getSnapshot("view"),
|
|
50
|
+
},
|
|
51
|
+
viewState: {
|
|
52
|
+
subscribe: this.subscribe("widgetState"),
|
|
53
|
+
getSnapshot: () => this.getSnapshot("widgetState")?.modelContent ?? null,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
45
57
|
}
|
|
46
58
|
//# sourceMappingURL=bridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AAEpB,qFAAqF;AACrF,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC3B,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC;IAIM,SAAS,CACd,SAAmE;QAEnE,MAAM,IAAI,GAAsC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACtE,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChB,OAAO,CAAC,QAAoB,EAAE,EAAE;YAC9B,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;gBACjD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CACjC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CACjD,CAAC;gBACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBACD,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;gBAC/D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;YACtE,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,GAAG,CAAiC,GAAM,EAAE,EAAE;QAC9D,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,+EAA+E,GAAG,8CAA8C,CACjI,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEK,mBAAmB;QAIxB,OAAO;YACL,OAAO,EAAE;gBACP,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBACjC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;aAC5C;YACD,SAAS,EAAE;gBACT,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;gBACxC,WAAW,EAAE,GAAG,EAAE,CAChB,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;aACxD;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Bridge, HostContextStore, Subscribe } from \"../types.js\";\nimport {\n type AppsSdkContext,\n SET_GLOBALS_EVENT_TYPE,\n type SetGlobalsEvent,\n} from \"./types.js\";\n\n/** @internal Singleton bridge over `window.openai` events. Used by `HostAdaptor`. */\nexport class AppsSdkBridge implements Bridge<AppsSdkContext> {\n private static instance: AppsSdkBridge | null = null;\n\n public static getInstance(): AppsSdkBridge {\n if (window.openai === undefined) {\n throw new Error(\n \"Apps SDK Bridge requires window.openai (Apps SDK runtime).\",\n );\n }\n if (AppsSdkBridge.instance === null) {\n AppsSdkBridge.instance = new AppsSdkBridge();\n }\n return AppsSdkBridge.instance;\n }\n\n public static resetInstance(): void {\n if (AppsSdkBridge.instance) {\n AppsSdkBridge.instance = null;\n }\n }\n\n public subscribe(key: keyof AppsSdkContext): Subscribe;\n public subscribe(keys: readonly (keyof AppsSdkContext)[]): Subscribe;\n public subscribe(\n keyOrKeys: keyof AppsSdkContext | readonly (keyof AppsSdkContext)[],\n ): Subscribe {\n const keys: readonly (keyof AppsSdkContext)[] = Array.isArray(keyOrKeys)\n ? keyOrKeys\n : [keyOrKeys];\n return (onChange: () => void) => {\n const handleSetGlobal = (event: SetGlobalsEvent) => {\n const hasRelevantChange = keys.some(\n (key) => event.detail.globals[key] !== undefined,\n );\n if (!hasRelevantChange) {\n return;\n }\n onChange();\n };\n\n window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);\n };\n };\n }\n\n public getSnapshot = <K extends keyof AppsSdkContext>(key: K) => {\n if (window.openai === undefined) {\n throw new Error(\n `window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`,\n );\n }\n\n return window.openai[key];\n };\n\n public createOverlayStores(): {\n display: HostContextStore<\"display\">;\n viewState: HostContextStore<\"viewState\">;\n } {\n return {\n display: {\n subscribe: this.subscribe(\"view\"),\n getSnapshot: () => this.getSnapshot(\"view\"),\n },\n viewState: {\n subscribe: this.subscribe(\"widgetState\"),\n getSnapshot: () =>\n this.getSnapshot(\"widgetState\")?.modelContent ?? null,\n },\n };\n }\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { AppsSdkAdaptor } from "./adaptor.js";
|
|
2
1
|
export { AppsSdkBridge } from "./bridge.js";
|
|
3
2
|
export type { AppsSdkContext, AppsSdkMethods, AppsSdkWidgetState, ToolResponseEvent, } from "./types.js";
|
|
4
3
|
export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, TOOL_RESPONSE_EVENT_TYPE, } from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { AppsSdkBridge } from \"./bridge.js\";\nexport type {\n AppsSdkContext,\n AppsSdkMethods,\n AppsSdkWidgetState,\n ToolResponseEvent,\n} from \"./types.js\";\nexport {\n SET_GLOBALS_EVENT_TYPE,\n SetGlobalsEvent,\n TOOL_RESPONSE_EVENT_TYPE,\n} from \"./types.js\";\nexport { useAppsSdkContext } from \"./use-apps-sdk-context.js\";\n"]}
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import type { AppsSdkContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read a single key from the raw Apps SDK (`window.openai`) context.
|
|
4
|
+
*
|
|
5
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,
|
|
6
|
+
* `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
|
|
7
|
+
* this when you need ChatGPT-only fields not surfaced by the public hooks.
|
|
8
|
+
*
|
|
9
|
+
* Throws if called outside the Apps SDK runtime.
|
|
10
|
+
*
|
|
11
|
+
* @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context
|
|
12
|
+
*/
|
|
2
13
|
export declare function useAppsSdkContext<K extends keyof AppsSdkContext>(key: K): AppsSdkContext[K];
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { AppsSdkBridge } from "./bridge.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read a single key from the raw Apps SDK (`window.openai`) context.
|
|
5
|
+
*
|
|
6
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,
|
|
7
|
+
* `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
|
|
8
|
+
* this when you need ChatGPT-only fields not surfaced by the public hooks.
|
|
9
|
+
*
|
|
10
|
+
* Throws if called outside the Apps SDK runtime.
|
|
11
|
+
*
|
|
12
|
+
* @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context
|
|
13
|
+
*/
|
|
3
14
|
export function useAppsSdkContext(key) {
|
|
4
15
|
const bridge = AppsSdkBridge.getInstance();
|
|
5
16
|
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-apps-sdk-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/use-apps-sdk-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,UAAU,iBAAiB,CAC/B,GAAM;IAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC3C,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkContext } from \"./types.js\";\n\nexport function useAppsSdkContext<K extends keyof AppsSdkContext>(\n key: K,\n): AppsSdkContext[K] {\n const bridge = AppsSdkBridge.getInstance();\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-apps-sdk-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/use-apps-sdk-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAM;IAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC3C,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkContext } from \"./types.js\";\n\n/**\n * Read a single key from the raw Apps SDK (`window.openai`) context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for\n * this when you need ChatGPT-only fields not surfaced by the public hooks.\n *\n * Throws if called outside the Apps SDK runtime.\n *\n * @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context\n */\nexport function useAppsSdkContext<K extends keyof AppsSdkContext>(\n key: K,\n): AppsSdkContext[K] {\n const bridge = AppsSdkBridge.getInstance();\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { Adaptor } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Resolve the single host {@link Adaptor} instance. Prefer the documented
|
|
5
|
+
* hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;
|
|
6
|
+
* it's the escape hatch used by the hooks themselves and by advanced
|
|
7
|
+
* integrations.
|
|
8
|
+
*/
|
|
2
9
|
export declare const getAdaptor: () => Adaptor;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { HostAdaptor } from "./adaptor.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Resolve the single host {@link Adaptor} instance. Prefer the documented
|
|
5
|
+
* hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;
|
|
6
|
+
* it's the escape hatch used by the hooks themselves and by advanced
|
|
7
|
+
* integrations.
|
|
8
|
+
*/
|
|
9
|
+
export const getAdaptor = () => HostAdaptor.getInstance();
|
|
8
10
|
//# sourceMappingURL=get-adaptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-adaptor.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"get-adaptor.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import { HostAdaptor } from \"./adaptor.js\";\nimport type { Adaptor } from \"./types.js\";\n\n/**\n * @internal\n * Resolve the single host {@link Adaptor} instance. Prefer the documented\n * hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;\n * it's the escape hatch used by the hooks themselves and by advanced\n * integrations.\n */\nexport const getAdaptor = (): Adaptor => HostAdaptor.getInstance();\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { HostAdaptor } from "./adaptor.js";
|
|
3
|
+
import { AppsSdkBridge } from "./apps-sdk/bridge.js";
|
|
4
|
+
import { getAdaptor } from "./get-adaptor.js";
|
|
5
|
+
import { McpAppBridge } from "./mcp-app/bridge.js";
|
|
6
|
+
describe("getAdaptor", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
HostAdaptor.resetInstance();
|
|
9
|
+
McpAppBridge.resetInstance();
|
|
10
|
+
AppsSdkBridge.resetInstance();
|
|
11
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
HostAdaptor.resetInstance();
|
|
16
|
+
McpAppBridge.resetInstance();
|
|
17
|
+
AppsSdkBridge.resetInstance();
|
|
18
|
+
});
|
|
19
|
+
it("returns a HostAdaptor instance", () => {
|
|
20
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
21
|
+
vi.stubGlobal("openai", undefined);
|
|
22
|
+
expect(getAdaptor()).toBeInstanceOf(HostAdaptor);
|
|
23
|
+
});
|
|
24
|
+
it("memoizes the instance", () => {
|
|
25
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
26
|
+
vi.stubGlobal("openai", undefined);
|
|
27
|
+
const a = getAdaptor();
|
|
28
|
+
const b = getAdaptor();
|
|
29
|
+
expect(a).toBe(b);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=get-adaptor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-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/B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"./adaptor.js\";\nimport { AppsSdkBridge } from \"./apps-sdk/bridge.js\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport { McpAppBridge } from \"./mcp-app/bridge.js\";\n\ndescribe(\"getAdaptor\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"returns a HostAdaptor instance\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n expect(getAdaptor()).toBeInstanceOf(HostAdaptor);\n });\n\n it(\"memoizes the instance\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n const a = getAdaptor();\n const b = getAdaptor();\n expect(a).toBe(b);\n });\n});\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
-
import type
|
|
3
|
-
import type { Bridge, Subscribe } from "../types.js";
|
|
2
|
+
import { type Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { AnyViewToolHandler, Bridge, HostContextStore, Subscribe, ViewToolConfig } from "../types.js";
|
|
4
4
|
import type { McpAppContext, McpAppContextKey } from "./types.js";
|
|
5
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
|
|
5
6
|
export declare class McpAppBridge implements Bridge<McpAppContext> {
|
|
6
7
|
private static instance;
|
|
7
8
|
context: McpAppContext;
|
|
@@ -13,12 +14,24 @@ export declare class McpAppBridge implements Bridge<McpAppContext> {
|
|
|
13
14
|
});
|
|
14
15
|
private connect;
|
|
15
16
|
getApp(): Promise<App>;
|
|
17
|
+
registerViewTool(config: ViewToolConfig, handler: AnyViewToolHandler): () => void;
|
|
16
18
|
static getInstance(options?: Partial<{
|
|
17
19
|
appInfo: Implementation;
|
|
18
20
|
}>): McpAppBridge;
|
|
19
21
|
subscribe(key: McpAppContextKey): Subscribe;
|
|
20
22
|
subscribe(keys: readonly McpAppContextKey[]): Subscribe;
|
|
21
23
|
getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
|
|
24
|
+
createContextStores(): {
|
|
25
|
+
theme: HostContextStore<"theme">;
|
|
26
|
+
locale: HostContextStore<"locale">;
|
|
27
|
+
safeArea: HostContextStore<"safeArea">;
|
|
28
|
+
displayMode: HostContextStore<"displayMode">;
|
|
29
|
+
maxHeight: HostContextStore<"maxHeight">;
|
|
30
|
+
userAgent: HostContextStore<"userAgent">;
|
|
31
|
+
toolInput: HostContextStore<"toolInput">;
|
|
32
|
+
toolOutput: HostContextStore<"toolOutput">;
|
|
33
|
+
toolResponseMetadata: HostContextStore<"toolResponseMetadata">;
|
|
34
|
+
};
|
|
22
35
|
cleanup: () => void;
|
|
23
36
|
static resetInstance(): void;
|
|
24
37
|
private emit;
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { dequal } from "dequal/lite";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
function createMcpStore(bridge, keys, computeSnapshot) {
|
|
6
|
+
let cachedValue;
|
|
7
|
+
return {
|
|
8
|
+
subscribe: bridge.subscribe(keys),
|
|
9
|
+
getSnapshot: () => {
|
|
10
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
11
|
+
const newValue = computeSnapshot(context);
|
|
12
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
13
|
+
return cachedValue;
|
|
14
|
+
}
|
|
15
|
+
cachedValue = newValue;
|
|
16
|
+
return newValue;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
|
|
2
21
|
export class McpAppBridge {
|
|
3
22
|
static instance = null;
|
|
4
23
|
context = {
|
|
@@ -10,7 +29,10 @@ export class McpAppBridge {
|
|
|
10
29
|
app;
|
|
11
30
|
connectPromise;
|
|
12
31
|
constructor(options) {
|
|
13
|
-
this.app = new App(options.appInfo);
|
|
32
|
+
this.app = new App(options.appInfo, { tools: { listChanged: true } });
|
|
33
|
+
this.app.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
34
|
+
tools: [],
|
|
35
|
+
}));
|
|
14
36
|
this.app.ontoolinput = (params) => {
|
|
15
37
|
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
16
38
|
};
|
|
@@ -44,10 +66,23 @@ export class McpAppBridge {
|
|
|
44
66
|
await this.connectPromise;
|
|
45
67
|
return this.app;
|
|
46
68
|
}
|
|
69
|
+
registerViewTool(config, handler) {
|
|
70
|
+
const inputSchema = config.inputSchema
|
|
71
|
+
? z.object(config.inputSchema)
|
|
72
|
+
: z.object({});
|
|
73
|
+
const registered = this.app.registerTool(config.name, {
|
|
74
|
+
...(config.title !== undefined ? { title: config.title } : {}),
|
|
75
|
+
...(config.description !== undefined
|
|
76
|
+
? { description: config.description }
|
|
77
|
+
: {}),
|
|
78
|
+
inputSchema,
|
|
79
|
+
...(config.annotations ? { annotations: config.annotations } : {}),
|
|
80
|
+
}, handler);
|
|
81
|
+
return () => {
|
|
82
|
+
registered.remove();
|
|
83
|
+
};
|
|
84
|
+
}
|
|
47
85
|
static getInstance(options) {
|
|
48
|
-
if (window.skybridge.hostType !== "mcp-app") {
|
|
49
|
-
throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
|
|
50
|
-
}
|
|
51
86
|
if (McpAppBridge.instance && options) {
|
|
52
87
|
console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
|
|
53
88
|
}
|
|
@@ -78,6 +113,35 @@ export class McpAppBridge {
|
|
|
78
113
|
getSnapshot(key) {
|
|
79
114
|
return this.context[key];
|
|
80
115
|
}
|
|
116
|
+
createContextStores() {
|
|
117
|
+
return {
|
|
118
|
+
theme: createMcpStore(this, ["theme"], ({ theme }) => theme ?? "light"),
|
|
119
|
+
locale: createMcpStore(this, ["locale"], ({ locale }) => locale ?? "en-US"),
|
|
120
|
+
safeArea: createMcpStore(this, ["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
121
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
122
|
+
})),
|
|
123
|
+
displayMode: createMcpStore(this, ["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
124
|
+
maxHeight: createMcpStore(this, ["containerDimensions"], ({ containerDimensions }) => {
|
|
125
|
+
if (containerDimensions && "maxHeight" in containerDimensions) {
|
|
126
|
+
return containerDimensions.maxHeight;
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}),
|
|
130
|
+
userAgent: createMcpStore(this, ["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
131
|
+
device: {
|
|
132
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
133
|
+
},
|
|
134
|
+
capabilities: {
|
|
135
|
+
hover: true,
|
|
136
|
+
touch: true,
|
|
137
|
+
...deviceCapabilities,
|
|
138
|
+
},
|
|
139
|
+
})),
|
|
140
|
+
toolInput: createMcpStore(this, ["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
141
|
+
toolOutput: createMcpStore(this, ["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
142
|
+
toolResponseMetadata: createMcpStore(this, ["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
81
145
|
cleanup = () => {
|
|
82
146
|
this.listeners.clear();
|
|
83
147
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,GAAG,CAAM;IACT,cAAc,CAAgB;IAEtC,YAAY,OAAoC;QAC9C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;YAChC,IAAI,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,kBAAkB,GAAG,CAAC,MAAM,EAAE,EAAE;YACvC,IAAI,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC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,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo);\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AACrD,OAAO,EAEL,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAczB,SAAS,cAAc,CACrB,MAAoB,EACpB,IAAU,EACV,eAAkD;IAElD,IAAI,WAA0B,CAAC;IAC/B,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QACjC,WAAW,EAAE,GAAG,EAAE;YAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;YACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAC/D,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,WAAW,GAAG,QAAQ,CAAC;YACvB,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,qGAAqG;AACrG,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,GAAG,CAAM;IACT,cAAc,CAAgB;IAEtC,YAAY,OAAo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ACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport {\n type Implementation,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { dequal } from \"dequal/lite\";\nimport * as z from \"zod\";\nimport type {\n AnyViewToolHandler,\n Bridge,\n HostContextStore,\n Subscribe,\n ViewToolConfig,\n} from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nfunction createMcpStore<const Keys extends readonly McpAppContextKey[], R>(\n bridge: McpAppBridge,\n keys: Keys,\n computeSnapshot: (context: PickContext<Keys>) => R,\n) {\n let cachedValue: R | undefined;\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n cachedValue = newValue;\n return newValue;\n },\n };\n}\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo, { tools: { listChanged: true } });\n\n this.app.setRequestHandler(ListToolsRequestSchema, async () => ({\n tools: [],\n }));\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void {\n const inputSchema = config.inputSchema\n ? z.object(config.inputSchema)\n : z.object({});\n\n const registered = this.app.registerTool(\n config.name,\n {\n ...(config.title !== undefined ? { title: config.title } : {}),\n ...(config.description !== undefined\n ? { description: config.description }\n : {}),\n inputSchema,\n ...(config.annotations ? { annotations: config.annotations } : {}),\n },\n handler,\n );\n\n return () => {\n registered.remove();\n };\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public createContextStores(): {\n theme: HostContextStore<\"theme\">;\n locale: HostContextStore<\"locale\">;\n safeArea: HostContextStore<\"safeArea\">;\n displayMode: HostContextStore<\"displayMode\">;\n maxHeight: HostContextStore<\"maxHeight\">;\n userAgent: HostContextStore<\"userAgent\">;\n toolInput: HostContextStore<\"toolInput\">;\n toolOutput: HostContextStore<\"toolOutput\">;\n toolResponseMetadata: HostContextStore<\"toolResponseMetadata\">;\n } {\n return {\n theme: createMcpStore(this, [\"theme\"], ({ theme }) => theme ?? \"light\"),\n locale: createMcpStore(\n this,\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: createMcpStore(\n this,\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: createMcpStore(\n this,\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: createMcpStore(\n this,\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n return undefined;\n },\n ),\n userAgent: createMcpStore(\n this,\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: createMcpStore(\n this,\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: createMcpStore(\n this,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: createMcpStore(\n this,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n };\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { McpAppBridge } from "./bridge.js";
|
|
3
|
+
describe("McpAppBridge.getInstance", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
McpAppBridge.resetInstance();
|
|
6
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.unstubAllGlobals();
|
|
10
|
+
McpAppBridge.resetInstance();
|
|
11
|
+
});
|
|
12
|
+
it("instantiates regardless of injected hostType", () => {
|
|
13
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
14
|
+
expect(() => McpAppBridge.getInstance()).not.toThrow();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=bridge.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ndescribe(\"McpAppBridge.getInstance\", () => {\n beforeEach(() => {\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n McpAppBridge.resetInstance();\n });\n\n it(\"instantiates regardless of injected hostType\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
|
|
@@ -3,5 +3,17 @@ import type { McpAppContext } from "./types.js";
|
|
|
3
3
|
type McpAppInitializationOptions = {
|
|
4
4
|
appInfo: Implementation;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
8
|
+
*
|
|
9
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
10
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
11
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
12
|
+
*
|
|
13
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
14
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
17
|
+
*/
|
|
6
18
|
export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
|
|
7
19
|
export {};
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { McpAppBridge } from "./bridge.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
5
|
+
*
|
|
6
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
7
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
8
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
9
|
+
*
|
|
10
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
11
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
14
|
+
*/
|
|
3
15
|
export function useMcpAppContext(key, options) {
|
|
4
16
|
const bridge = McpAppBridge.getInstance(options);
|
|
5
17
|
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { waitFor } from "@testing-library/react";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
import { MockResizeObserver } from "../../hooks/test/utils.js";
|
|
6
|
+
import { HostAdaptor } from "../adaptor.js";
|
|
7
|
+
import { McpAppBridge } from "./bridge.js";
|
|
8
|
+
const outgoing = [];
|
|
9
|
+
/**
|
|
10
|
+
* Stand-in MCP Apps host: replies to `ui/initialize` and records every message
|
|
11
|
+
* the app posts so tests can assert on responses and notifications.
|
|
12
|
+
*/
|
|
13
|
+
function installHostMock() {
|
|
14
|
+
outgoing.length = 0;
|
|
15
|
+
const postMessage = vi.fn((message) => {
|
|
16
|
+
outgoing.push(message);
|
|
17
|
+
if (message.method === "ui/initialize" && message.id !== undefined) {
|
|
18
|
+
act(() => {
|
|
19
|
+
window.dispatchEvent(new MessageEvent("message", {
|
|
20
|
+
source: window.parent,
|
|
21
|
+
data: {
|
|
22
|
+
jsonrpc: "2.0",
|
|
23
|
+
id: message.id,
|
|
24
|
+
result: {
|
|
25
|
+
protocolVersion: "2025-06-18",
|
|
26
|
+
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
27
|
+
hostCapabilities: {},
|
|
28
|
+
hostContext: {},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
vi.stubGlobal("parent", { postMessage });
|
|
36
|
+
}
|
|
37
|
+
let nextId = 1000;
|
|
38
|
+
/** Send a host → app JSON-RPC request and resolve with the full response (result or error). */
|
|
39
|
+
async function callHost(method, params = {}) {
|
|
40
|
+
const id = ++nextId;
|
|
41
|
+
act(() => {
|
|
42
|
+
window.dispatchEvent(new MessageEvent("message", {
|
|
43
|
+
source: window.parent,
|
|
44
|
+
data: { jsonrpc: "2.0", id, method, params },
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
await waitFor(() => {
|
|
48
|
+
expect(outgoing.some((m) => m.id === id)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
return outgoing.find((m) => m.id === id);
|
|
51
|
+
}
|
|
52
|
+
describe("McpApp view tools", () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
55
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
56
|
+
McpAppBridge.resetInstance();
|
|
57
|
+
installHostMock();
|
|
58
|
+
});
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
vi.unstubAllGlobals();
|
|
61
|
+
vi.clearAllMocks();
|
|
62
|
+
});
|
|
63
|
+
it("advertises the tools capability during ui/initialize", async () => {
|
|
64
|
+
await McpAppBridge.getInstance().getApp();
|
|
65
|
+
const init = outgoing.find((m) => m.method === "ui/initialize");
|
|
66
|
+
expect(init?.params?.appCapabilities).toMatchObject({
|
|
67
|
+
tools: { listChanged: true },
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it("lists a registered view tool with its input schema", async () => {
|
|
71
|
+
const adaptor = new HostAdaptor();
|
|
72
|
+
await McpAppBridge.getInstance().getApp();
|
|
73
|
+
adaptor.registerViewTool({
|
|
74
|
+
name: "chess_make_move",
|
|
75
|
+
description: "Play a move",
|
|
76
|
+
inputSchema: { san: z.string() },
|
|
77
|
+
annotations: { readOnlyHint: false },
|
|
78
|
+
}, () => ({ content: [{ type: "text", text: "ok" }] }));
|
|
79
|
+
const response = await callHost("tools/list");
|
|
80
|
+
const tools = response?.result?.tools;
|
|
81
|
+
expect(tools).toHaveLength(1);
|
|
82
|
+
const [tool] = tools;
|
|
83
|
+
expect(tool?.name).toBe("chess_make_move");
|
|
84
|
+
expect(tool?.description).toBe("Play a move");
|
|
85
|
+
expect(tool?.inputSchema.properties).toHaveProperty("san");
|
|
86
|
+
expect(tool?.annotations?.readOnlyHint).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
it("invokes the handler with validated args and returns its result", async () => {
|
|
89
|
+
const adaptor = new HostAdaptor();
|
|
90
|
+
await McpAppBridge.getInstance().getApp();
|
|
91
|
+
const handler = vi.fn(({ san }) => ({
|
|
92
|
+
content: [{ type: "text", text: `played ${san}` }],
|
|
93
|
+
structuredContent: { lastMove: san },
|
|
94
|
+
}));
|
|
95
|
+
adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
|
|
96
|
+
const response = await callHost("tools/call", {
|
|
97
|
+
name: "chess_make_move",
|
|
98
|
+
arguments: { san: "e4" },
|
|
99
|
+
});
|
|
100
|
+
const result = response?.result;
|
|
101
|
+
// ext-apps invokes the callback as `(args, extra)`; assert on the args only.
|
|
102
|
+
expect(handler.mock.calls[0]?.[0]).toEqual({ san: "e4" });
|
|
103
|
+
expect(result?.structuredContent).toEqual({ lastMove: "e4" });
|
|
104
|
+
expect(result?.isError).toBeFalsy();
|
|
105
|
+
expect(result?.content).toEqual([{ type: "text", text: "played e4" }]);
|
|
106
|
+
});
|
|
107
|
+
it("rejects the call without invoking the handler when args are invalid", async () => {
|
|
108
|
+
const adaptor = new HostAdaptor();
|
|
109
|
+
await McpAppBridge.getInstance().getApp();
|
|
110
|
+
const handler = vi.fn(() => ({ content: [] }));
|
|
111
|
+
adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
|
|
112
|
+
// ext-apps validates input against the schema and rejects with a JSON-RPC
|
|
113
|
+
// error before the handler runs.
|
|
114
|
+
const response = await callHost("tools/call", {
|
|
115
|
+
name: "chess_make_move",
|
|
116
|
+
arguments: { san: 42 },
|
|
117
|
+
});
|
|
118
|
+
expect(handler).not.toHaveBeenCalled();
|
|
119
|
+
expect(response?.error).toBeDefined();
|
|
120
|
+
});
|
|
121
|
+
it("rejects a call to an unknown tool", async () => {
|
|
122
|
+
await McpAppBridge.getInstance().getApp();
|
|
123
|
+
const response = await callHost("tools/call", {
|
|
124
|
+
name: "nope",
|
|
125
|
+
arguments: {},
|
|
126
|
+
});
|
|
127
|
+
expect(response?.error).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
it("removes the tool and notifies the host when unregistered", async () => {
|
|
130
|
+
const adaptor = new HostAdaptor();
|
|
131
|
+
await McpAppBridge.getInstance().getApp();
|
|
132
|
+
const unregister = adaptor.registerViewTool({ name: "chess_reset" }, () => ({ content: [{ type: "text", text: "reset" }] }));
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(outgoing.some((m) => m.method === "notifications/tools/list_changed")).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
let listed = await callHost("tools/list");
|
|
137
|
+
expect(listed?.result?.tools).toHaveLength(1);
|
|
138
|
+
unregister();
|
|
139
|
+
listed = await callHost("tools/list");
|
|
140
|
+
expect(listed?.result?.tools).toHaveLength(0);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=view-tools.test.js.map
|