skybridge 0.0.0-dev.dc1bd07 → 0.0.0-dev.dc576c4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/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/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.js +1 -16
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.js +16 -0
- package/dist/commands/dev.js.map +1 -1
- 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/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/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/server.d.ts +152 -0
- package/dist/server/server.js +142 -57
- package/dist/server/server.js.map +1 -1
- package/dist/test/view.test.js +45 -0
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +48 -0
- package/dist/web/bridges/adaptor.js +308 -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 +205 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js +3 -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 +9 -0
- package/dist/web/bridges/get-adaptor.js +27 -5
- 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 +48 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/host-context-stores.d.ts +27 -0
- package/dist/web/bridges/host-context-stores.js +73 -0
- package/dist/web/bridges/host-context-stores.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.js +1 -3
- 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 +21 -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/types.d.ts +62 -0
- 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.js +4 -3
- 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 +7 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +33 -0
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +8 -5
- 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/hooks/use-call-tool.d.ts +45 -0
- 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 +36 -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 +55 -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 +19 -5
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- 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 +34 -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 +33 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +37 -27
- 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 -0
- 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 +1 -1
- 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,5 +1,6 @@
|
|
|
1
1
|
import type { Bridge, Subscribe } from "../types.js";
|
|
2
2
|
import { type AppsSdkContext } from "./types.js";
|
|
3
|
+
/** @internal Singleton bridge over `window.openai` events. Used by `HostAdaptor`. */
|
|
3
4
|
export declare class AppsSdkBridge implements Bridge<AppsSdkContext> {
|
|
4
5
|
private static instance;
|
|
5
6
|
static getInstance(): AppsSdkBridge;
|
|
@@ -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();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB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AC;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","sourcesContent":["import type { Bridge, 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"]}
|
|
@@ -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,11 @@
|
|
|
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;
|
|
10
|
+
/** @internal Test-only. */
|
|
11
|
+
export declare const _resetAdaptor: () => void;
|
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { HostAdaptor } from "./adaptor.js";
|
|
2
|
+
let cached = null;
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* Resolve the single host {@link Adaptor} instance. Prefer the documented
|
|
6
|
+
* hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;
|
|
7
|
+
* it's the escape hatch used by the hooks themselves and by advanced
|
|
8
|
+
* integrations.
|
|
9
|
+
*/
|
|
3
10
|
export const getAdaptor = () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached;
|
|
13
|
+
}
|
|
14
|
+
const hostType = typeof window !== "undefined" ? window.skybridge?.hostType : undefined;
|
|
15
|
+
const hasOai = typeof window !== "undefined" && window.openai !== undefined;
|
|
16
|
+
if (hostType === "mcp-app" && hasOai) {
|
|
17
|
+
console.warn("[skybridge] hostType is 'mcp-app' but window.openai is present; trusting the probe.");
|
|
18
|
+
}
|
|
19
|
+
else if (hostType === "apps-sdk" && !hasOai) {
|
|
20
|
+
console.warn("[skybridge] hostType is 'apps-sdk' but window.openai is absent; trusting the probe.");
|
|
21
|
+
}
|
|
22
|
+
cached = new HostAdaptor();
|
|
23
|
+
return cached;
|
|
24
|
+
};
|
|
25
|
+
/** @internal Test-only. */
|
|
26
|
+
export const _resetAdaptor = () => {
|
|
27
|
+
cached?.cleanup();
|
|
28
|
+
cached = null;
|
|
7
29
|
};
|
|
8
30
|
//# 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,IAAI,MAAM,GAAuB,IAAI,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE;IACtC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,QAAQ,GACZ,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC;IAE5E,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CACV,qFAAqF,CACtF,CAAC;IACJ,CAAC;SAAM,IAAI,QAAQ,KAAK,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,CAAC,IAAI,CACV,qFAAqF,CACtF,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,2BAA2B;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG,GAAS,EAAE;IACtC,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { HostAdaptor } from \"./adaptor.js\";\nimport type { Adaptor } from \"./types.js\";\n\nlet cached: HostAdaptor | null = null;\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 => {\n if (cached) {\n return cached;\n }\n\n const hostType =\n typeof window !== \"undefined\" ? window.skybridge?.hostType : undefined;\n const hasOai = typeof window !== \"undefined\" && window.openai !== undefined;\n\n if (hostType === \"mcp-app\" && hasOai) {\n console.warn(\n \"[skybridge] hostType is 'mcp-app' but window.openai is present; trusting the probe.\",\n );\n } else if (hostType === \"apps-sdk\" && !hasOai) {\n console.warn(\n \"[skybridge] hostType is 'apps-sdk' but window.openai is absent; trusting the probe.\",\n );\n }\n\n cached = new HostAdaptor();\n return cached;\n};\n\n/** @internal Test-only. */\nexport const _resetAdaptor = (): void => {\n cached?.cleanup();\n cached = null;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { _resetAdaptor, getAdaptor } from "./get-adaptor.js";
|
|
5
|
+
import { McpAppBridge } from "./mcp-app/bridge.js";
|
|
6
|
+
describe("getAdaptor", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
_resetAdaptor();
|
|
9
|
+
McpAppBridge.resetInstance();
|
|
10
|
+
AppsSdkBridge.resetInstance();
|
|
11
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
_resetAdaptor();
|
|
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
|
+
it("logs a warning when hostType disagrees with probe", () => {
|
|
32
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
33
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
34
|
+
vi.stubGlobal("openai", { view: { mode: "inline" } });
|
|
35
|
+
getAdaptor();
|
|
36
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("hostType"));
|
|
37
|
+
warn.mockRestore();
|
|
38
|
+
});
|
|
39
|
+
it("does not warn when hostType matches probe", () => {
|
|
40
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
41
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
42
|
+
vi.stubGlobal("openai", { view: { mode: "inline" } });
|
|
43
|
+
getAdaptor();
|
|
44
|
+
expect(warn).not.toHaveBeenCalled();
|
|
45
|
+
warn.mockRestore();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=get-adaptor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-adaptor.test.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.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,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,UAAU,CAAC,GAAG,EAAE;QACd,aAAa,EAAE,CAAC;QAChB,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CAAC,aAAa,EAAE,CAAC;QAC9B,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,aAAa,EAAE,CAAC;QAChB,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CA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,EAAE;QACnD,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACpE,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtD,UAAU,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACpC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,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 { _resetAdaptor, getAdaptor } from \"./get-adaptor.js\";\nimport { McpAppBridge } from \"./mcp-app/bridge.js\";\n\ndescribe(\"getAdaptor\", () => {\n beforeEach(() => {\n _resetAdaptor();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n _resetAdaptor();\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 it(\"logs a warning when hostType disagrees with probe\", () => {\n const warn = vi.spyOn(console, \"warn\").mockImplementation(() => {});\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n getAdaptor();\n expect(warn).toHaveBeenCalledWith(expect.stringContaining(\"hostType\"));\n warn.mockRestore();\n });\n\n it(\"does not warn when hostType matches probe\", () => {\n const warn = vi.spyOn(console, \"warn\").mockImplementation(() => {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n getAdaptor();\n expect(warn).not.toHaveBeenCalled();\n warn.mockRestore();\n });\n});\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { McpAppBridge } from "./mcp-app/bridge.js";
|
|
2
|
+
import type { HostContextStore } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build the host-context store map sourced from the MCP App bridge.
|
|
5
|
+
* `display` and `viewState` are *not* included here; those are handled
|
|
6
|
+
* by the adaptor itself because they have transport-specific overlays
|
|
7
|
+
* and additional state (polyfill modal state, localStorage hydration).
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildMcpContextStores(bridge: McpAppBridge): {
|
|
10
|
+
theme: HostContextStore<"theme">;
|
|
11
|
+
locale: HostContextStore<"locale">;
|
|
12
|
+
safeArea: HostContextStore<"safeArea">;
|
|
13
|
+
displayMode: HostContextStore<"displayMode">;
|
|
14
|
+
maxHeight: HostContextStore<"maxHeight">;
|
|
15
|
+
userAgent: HostContextStore<"userAgent">;
|
|
16
|
+
toolInput: HostContextStore<"toolInput">;
|
|
17
|
+
toolOutput: HostContextStore<"toolOutput">;
|
|
18
|
+
toolResponseMetadata: HostContextStore<"toolResponseMetadata">;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
|
|
22
|
+
* Used by `HostAdaptor` only when `window.openai` is present.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildAppsSdkOverlayStores(bridge: import("./apps-sdk/bridge.js").AppsSdkBridge): {
|
|
25
|
+
display: HostContextStore<"display">;
|
|
26
|
+
viewState: HostContextStore<"viewState">;
|
|
27
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { dequal } from "dequal/lite";
|
|
2
|
+
/**
|
|
3
|
+
* Build a memoized {@link HostContextStore} backed by one or more
|
|
4
|
+
* `McpAppBridge` context keys. Recomputed values are deep-compared via
|
|
5
|
+
* `dequal` so unchanged snapshots return the cached reference.
|
|
6
|
+
*/
|
|
7
|
+
function createMcpStore(bridge, keys, computeSnapshot) {
|
|
8
|
+
let cachedValue;
|
|
9
|
+
return {
|
|
10
|
+
subscribe: bridge.subscribe(keys),
|
|
11
|
+
getSnapshot: () => {
|
|
12
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
13
|
+
const newValue = computeSnapshot(context);
|
|
14
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
15
|
+
return cachedValue;
|
|
16
|
+
}
|
|
17
|
+
cachedValue = newValue;
|
|
18
|
+
return newValue;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build the host-context store map sourced from the MCP App bridge.
|
|
24
|
+
* `display` and `viewState` are *not* included here; those are handled
|
|
25
|
+
* by the adaptor itself because they have transport-specific overlays
|
|
26
|
+
* and additional state (polyfill modal state, localStorage hydration).
|
|
27
|
+
*/
|
|
28
|
+
export function buildMcpContextStores(bridge) {
|
|
29
|
+
return {
|
|
30
|
+
theme: createMcpStore(bridge, ["theme"], ({ theme }) => theme ?? "light"),
|
|
31
|
+
locale: createMcpStore(bridge, ["locale"], ({ locale }) => locale ?? "en-US"),
|
|
32
|
+
safeArea: createMcpStore(bridge, ["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
33
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
34
|
+
})),
|
|
35
|
+
displayMode: createMcpStore(bridge, ["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
36
|
+
maxHeight: createMcpStore(bridge, ["containerDimensions"], ({ containerDimensions }) => {
|
|
37
|
+
if (containerDimensions && "maxHeight" in containerDimensions) {
|
|
38
|
+
return containerDimensions.maxHeight;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}),
|
|
42
|
+
userAgent: createMcpStore(bridge, ["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
43
|
+
device: {
|
|
44
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
45
|
+
},
|
|
46
|
+
capabilities: {
|
|
47
|
+
hover: true,
|
|
48
|
+
touch: true,
|
|
49
|
+
...deviceCapabilities,
|
|
50
|
+
},
|
|
51
|
+
})),
|
|
52
|
+
toolInput: createMcpStore(bridge, ["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
53
|
+
toolOutput: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
54
|
+
toolResponseMetadata: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
|
|
59
|
+
* Used by `HostAdaptor` only when `window.openai` is present.
|
|
60
|
+
*/
|
|
61
|
+
export function buildAppsSdkOverlayStores(bridge) {
|
|
62
|
+
return {
|
|
63
|
+
display: {
|
|
64
|
+
subscribe: bridge.subscribe("view"),
|
|
65
|
+
getSnapshot: () => bridge.getSnapshot("view"),
|
|
66
|
+
},
|
|
67
|
+
viewState: {
|
|
68
|
+
subscribe: bridge.subscribe("widgetState"),
|
|
69
|
+
getSnapshot: () => bridge.getSnapshot("widgetState")?.modelContent ?? null,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=host-context-stores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-context-stores.js","sourceRoot":"","sources":["../../../src/web/bridges/host-context-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;GAIG;AACH,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;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAoB;IAWxD,OAAO;QACL,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,OAAO,CAAC;QACzE,MAAM,EAAE,cAAc,CACpB,MAAM,EACN,CAAC,QAAQ,CAAC,EACV,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAClC;QACD,QAAQ,EAAE,cAAc,CACtB,MAAM,EACN,CAAC,gBAAgB,CAAC,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IAAI,IAAI,CAC1D;QACD,oBAAoB,EAAE,cAAc,CAClC,MAAM,EACN,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,CAC9C;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAoD;IAKpD,OAAO;QACL,OAAO,EAAE;YACP,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACnC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;SAC9C;QACD,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC;YAC1C,WAAW,EAAE,GAAG,EAAE,CAChB,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;SAC1D;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type { McpAppBridge } from \"./mcp-app/bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./mcp-app/types.js\";\nimport type { HostContextStore } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\n/**\n * Build a memoized {@link HostContextStore} backed by one or more\n * `McpAppBridge` context keys. Recomputed values are deep-compared via\n * `dequal` so unchanged snapshots return the cached reference.\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/**\n * Build the host-context store map sourced from the MCP App bridge.\n * `display` and `viewState` are *not* included here; those are handled\n * by the adaptor itself because they have transport-specific overlays\n * and additional state (polyfill modal state, localStorage hydration).\n */\nexport function buildMcpContextStores(bridge: McpAppBridge): {\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(bridge, [\"theme\"], ({ theme }) => theme ?? \"light\"),\n locale: createMcpStore(\n bridge,\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: createMcpStore(\n bridge,\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: createMcpStore(\n bridge,\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: createMcpStore(\n bridge,\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n return undefined;\n },\n ),\n userAgent: createMcpStore(\n bridge,\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 bridge,\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n };\n}\n\n/**\n * Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).\n * Used by `HostAdaptor` only when `window.openai` is present.\n */\nexport function buildAppsSdkOverlayStores(\n bridge: import(\"./apps-sdk/bridge.js\").AppsSdkBridge,\n): {\n display: HostContextStore<\"display\">;\n viewState: HostContextStore<\"viewState\">;\n} {\n return {\n display: {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n },\n viewState: {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n },\n };\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { App } from "@modelcontextprotocol/ext-apps";
|
|
|
2
2
|
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
3
3
|
import type { Bridge, Subscribe } 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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
|
|
2
3
|
export class McpAppBridge {
|
|
3
4
|
static instance = null;
|
|
4
5
|
context = {
|
|
@@ -45,9 +46,6 @@ export class McpAppBridge {
|
|
|
45
46
|
return this.app;
|
|
46
47
|
}
|
|
47
48
|
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
49
|
if (McpAppBridge.instance && options) {
|
|
52
50
|
console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
|
|
53
51
|
}
|
|
@@ -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,CAAC;QAC5D,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;YACjC,IAAI,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,CAAC,MAAM,EAAE,EAAE;YACpC,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,C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AQ,CAAC,CAAC;gBAC5C,CAAC;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,CAAgC,GAAM;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,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\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);\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 (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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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 when hostType is apps-sdk", () => {
|
|
13
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
14
|
+
expect(() => McpAppBridge.getInstance()).not.toThrow();
|
|
15
|
+
});
|
|
16
|
+
it("instantiates when hostType is mcp-app", () => {
|
|
17
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
18
|
+
expect(() => McpAppBridge.getInstance()).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# 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,wCAAwC,EAAE,GAAG,EAAE;QAChD,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;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,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 when hostType is apps-sdk\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n\n it(\"instantiates when hostType is mcp-app\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\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"]}
|