skybridge 2.0.0-alpha.71beea9 → 2.0.0-alpha.bdeba1f
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/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/types.d.ts +2 -2
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -2
- package/dist/web/hooks/index.js +2 -2
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/{use-host-info.d.ts → use-host.d.ts} +2 -2
- package/dist/web/hooks/{use-host-info.js → use-host.js} +3 -3
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/{use-host-info.test.js → use-host.test.js} +6 -6
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +3 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +10 -30
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/package.json +1 -1
- package/dist/web/hooks/use-host-info.js.map +0 -1
- package/dist/web/hooks/use-host-info.test.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js.map +0 -1
- /package/dist/web/hooks/{use-host-info.test.d.ts → use-host.test.d.ts} +0 -0
- /package/dist/web/hooks/{use-layout.test.d.ts → use-viewport.test.d.ts} +0 -0
|
@@ -2,7 +2,7 @@ import type { AppsSdkContext } from "./types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Read a single key from the raw Apps SDK (`window.openai`) context.
|
|
4
4
|
*
|
|
5
|
-
* Advanced escape hatch — prefer the cross-host hooks (`
|
|
5
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useViewport`, `useUser`,
|
|
6
6
|
* `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
|
|
7
7
|
* this when you need ChatGPT-only fields not surfaced by the public hooks.
|
|
8
8
|
*
|
|
@@ -3,7 +3,7 @@ import { AppsSdkBridge } from "./bridge.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Read a single key from the raw Apps SDK (`window.openai`) context.
|
|
5
5
|
*
|
|
6
|
-
* Advanced escape hatch — prefer the cross-host hooks (`
|
|
6
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useViewport`, `useUser`,
|
|
7
7
|
* `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
|
|
8
8
|
* this when you need ChatGPT-only fields not surfaced by the public hooks.
|
|
9
9
|
*
|
|
@@ -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;;;;;;;;;;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 (`
|
|
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 (`useViewport`, `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"]}
|
|
@@ -7,7 +7,7 @@ type McpAppInitializationOptions = {
|
|
|
7
7
|
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
8
8
|
*
|
|
9
9
|
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
10
|
-
* `
|
|
10
|
+
* `useViewport`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
11
11
|
* when you need protocol-level fields not surfaced by the public hooks.
|
|
12
12
|
*
|
|
13
13
|
* `options.appInfo` is honored only on the first call that creates the
|
|
@@ -4,7 +4,7 @@ import { McpAppBridge } from "./bridge.js";
|
|
|
4
4
|
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
5
5
|
*
|
|
6
6
|
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
7
|
-
* `
|
|
7
|
+
* `useViewport`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
8
8
|
* when you need protocol-level fields not surfaced by the public hooks.
|
|
9
9
|
*
|
|
10
10
|
* `options.appInfo` is honored only on the first call that creates the
|
|
@@ -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;;;;;;;;;;;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 * `
|
|
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 * `useViewport`, 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"]}
|
|
@@ -48,7 +48,7 @@ export type SafeAreaInsets = {
|
|
|
48
48
|
bottom: number;
|
|
49
49
|
left: number;
|
|
50
50
|
};
|
|
51
|
-
/** Wrapper around {@link SafeAreaInsets} exposed via {@link
|
|
51
|
+
/** Wrapper around {@link SafeAreaInsets} exposed via {@link useViewport}. */
|
|
52
52
|
export type SafeArea = {
|
|
53
53
|
insets: SafeAreaInsets;
|
|
54
54
|
};
|
|
@@ -64,7 +64,7 @@ export type UserAgent = {
|
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
66
|
* Full snapshot of state the host exposes to the view. Most fields are
|
|
67
|
-
* better accessed through their dedicated hooks (`
|
|
67
|
+
* better accessed through their dedicated hooks (`useViewport`, `useUser`,
|
|
68
68
|
* `useToolInfo`, etc.) — read this directly only for advanced cases.
|
|
69
69
|
*/
|
|
70
70
|
export interface HostContext {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"AAsQA;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAExB;IACA;IAFlB,YACkB,MAAc,EACd,MAAe;QAE/B,KAAK,CACH,GAAG,MAAM,oCAAoC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3E,CAAC;QALc,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAS;QAK/B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ZodType } from \"zod\";\nimport type { ViewHostType } from \"../../server/server.js\";\nimport type { InferSchemaOutput } from \"../../standard-schema.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"AAsQA;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAExB;IACA;IAFlB,YACkB,MAAc,EACd,MAAe;QAE/B,KAAK,CACH,GAAG,MAAM,oCAAoC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3E,CAAC;QALc,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAS;QAK/B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ZodType } from \"zod\";\nimport type { ViewHostType } from \"../../server/server.js\";\nimport type { InferSchemaOutput } from \"../../standard-schema.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link useViewport}. */\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\n/** Device and input-capability hints exposed via {@link useUser}. */\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\n/**\n * Full snapshot of state the host exposes to the view. Most fields are\n * better accessed through their dedicated hooks (`useViewport`, `useUser`,\n * `useToolInfo`, etc.) — read this directly only for advanced cases.\n */\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\n/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\n/** @internal Bridge contract implemented by per-host bridge classes. */\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\n/** @internal Per-key snapshot store backing {@link useHostContext}. */\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\n/** Persisted view state shape (a plain object). See {@link useViewState}. */\nexport type ViewState = Record<string, unknown>;\n\n/** Updater form accepted when writing to view state. */\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\n/** Reference to a host-managed file (returned by {@link useFiles}). */\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\n/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */\nexport type UploadFileOptions = { library?: boolean };\n\n/** Options for {@link useRequestModal}'s `open` call. */\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\n/**\n * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the\n * host not to append its `?redirectUrl=…` tracking query parameter when\n * opening allowlisted targets.\n */\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\n/** Options for {@link useSendFollowUpMessage}. */\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\n/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\n/**\n * Shape of a view tool's `inputSchema`: a map of zod schemas. Narrower than\n * the server's `RawInputShape` because the MCP Apps bridge validates with\n * `z.object()` at runtime — other Standard Schema libraries would type-check\n * but throw on the first call.\n */\nexport type ViewToolInputShape = Record<string, ZodType>;\n\n/**\n * Args passed to a {@link ViewToolHandler}, inferred from the tool's\n * `inputSchema` (optionality preserved). Mirrors the server's `registerTool`.\n */\nexport type InferViewToolArgs<Shape extends ViewToolInputShape> = {\n [K in keyof Shape as undefined extends InferSchemaOutput<Shape[K]>\n ? never\n : K]: InferSchemaOutput<Shape[K]>;\n} & {\n [K in keyof Shape as undefined extends InferSchemaOutput<Shape[K]>\n ? K\n : never]?: InferSchemaOutput<Shape[K]>;\n};\n\n/**\n * Declares a tool the view exposes to the host/model (the MCP Apps\n * \"app-provided tools\" feature). Mirrors the server-side `registerTool` config.\n * Namespace `name` (e.g. `chess_make_move`) to avoid clashing with server tools.\n */\nexport type ViewToolConfig<\n TInput extends ViewToolInputShape = ViewToolInputShape,\n> = {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: TInput;\n annotations?: ToolAnnotations;\n};\n\n/**\n * Value a {@link ViewToolHandler} returns — a standard MCP `CallToolResult`\n * (`content` blocks plus optional `structuredContent` / `isError` / `_meta`),\n * exactly as `ext-apps`' app tool callbacks return it.\n */\nexport type ViewToolResult = CallToolResult;\n\n/** Handler run when the host calls a view tool. Receives validated, typed args. */\nexport type ViewToolHandler<\n TInput extends ViewToolInputShape = ViewToolInputShape,\n> = (\n args: InferViewToolArgs<TInput>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/** @internal Untyped handler signature stored by the adaptor/bridge after type erasure. */\nexport type AnyViewToolHandler = (\n args: Record<string, unknown>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/**\n * @internal\n * Low-level interface every host bridge implements. End-user code should use\n * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than\n * calling this directly.\n */\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n closeModal(): void;\n registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void;\n}\n\n/**\n * Thrown when a host bridge method is called in a runtime that doesn't\n * support it (e.g. `uploadFile` outside the Apps SDK runtime).\n */\nexport class NotSupportedError extends Error {\n constructor(\n public readonly method: string,\n public readonly reason?: string,\n ) {\n super(\n `${method} is not supported in this runtime${reason ? `: ${reason}` : \"\"}`,\n );\n this.name = \"NotSupportedError\";\n }\n}\n"]}
|
|
@@ -2,8 +2,7 @@ export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEff
|
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
3
|
export { type DownloadFn, useDownload } from "./use-download.js";
|
|
4
4
|
export { useFiles } from "./use-files.js";
|
|
5
|
-
export { type Host, type HostInfo,
|
|
6
|
-
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
5
|
+
export { type Host, type HostInfo, useHost } from "./use-host.js";
|
|
7
6
|
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
|
8
7
|
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
9
8
|
export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
|
|
@@ -14,3 +13,4 @@ export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
|
14
13
|
export { useToolInfo } from "./use-tool-info.js";
|
|
15
14
|
export { type UserState, useUser } from "./use-user.js";
|
|
16
15
|
export { useViewState } from "./use-view-state.js";
|
|
16
|
+
export { useViewport, type ViewportState } from "./use-viewport.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -2,8 +2,7 @@ export { useCallTool, } from "./use-call-tool.js";
|
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
3
|
export { useDownload } from "./use-download.js";
|
|
4
4
|
export { useFiles } from "./use-files.js";
|
|
5
|
-
export {
|
|
6
|
-
export { useLayout } from "./use-layout.js";
|
|
5
|
+
export { useHost } from "./use-host.js";
|
|
7
6
|
export { useOpenExternal } from "./use-open-external.js";
|
|
8
7
|
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
9
8
|
export { useRequestClose } from "./use-request-close.js";
|
|
@@ -14,4 +13,5 @@ export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
|
14
13
|
export { useToolInfo } from "./use-tool-info.js";
|
|
15
14
|
export { useUser } from "./use-user.js";
|
|
16
15
|
export { useViewState } from "./use-view-state.js";
|
|
16
|
+
export { useViewport } from "./use-viewport.js";
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAA4B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAA4B,OAAO,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type Host, type HostInfo, useHost } from \"./use-host.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { useRegisterViewTool } from \"./use-register-view-tool.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\nexport { useViewport, type ViewportState } from \"./use-viewport.js\";\n"]}
|
|
@@ -9,7 +9,7 @@ import type { RequestDisplayMode } from "../bridges/types.js";
|
|
|
9
9
|
*
|
|
10
10
|
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
11
11
|
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
12
|
-
* pair with {@link
|
|
12
|
+
* pair with {@link useViewport}.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
@@ -10,7 +10,7 @@ import { getAdaptor, useHostContext } from "../bridges/index.js";
|
|
|
10
10
|
*
|
|
11
11
|
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
12
12
|
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
13
|
-
* pair with {@link
|
|
13
|
+
* pair with {@link useViewport}.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link
|
|
1
|
+
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useViewport}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
|
|
@@ -15,8 +15,8 @@ export type HostInfo = {
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```tsx
|
|
18
|
-
* const { name } =
|
|
18
|
+
* const { name } = useHost();
|
|
19
19
|
* if (name === "claude") return <ClaudeLayout />;
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function useHost(): HostInfo;
|
|
@@ -15,11 +15,11 @@ const HOST_BY_REPORTED_NAME = {
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```tsx
|
|
18
|
-
* const { name } =
|
|
18
|
+
* const { name } = useHost();
|
|
19
19
|
* if (name === "claude") return <ClaudeLayout />;
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export function
|
|
22
|
+
export function useHost() {
|
|
23
23
|
const hostInfo = useMcpAppContext("hostInfo");
|
|
24
24
|
const name = hostInfo?.name;
|
|
25
25
|
return {
|
|
@@ -27,4 +27,4 @@ export function useHostInfo() {
|
|
|
27
27
|
version: hostInfo?.version,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
//# sourceMappingURL=use-host
|
|
30
|
+
//# sourceMappingURL=use-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-host.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAcvD,MAAM,qBAAqB,GAAyB;IAClD,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE,OAAO;IACtB,SAAS,EAAE,cAAc;IACzB,kBAAkB,EAAE,OAAO;CAC5B,CAAC;AAOF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC;IAE5B,OAAO;QACL,IAAI,EACF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,OAAO,EAAE,QAAQ,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import { useMcpAppContext } from \"../bridges/index.js\";\n\n/**\n * Known host applications, as normalized slugs. Unrecognized hosts surface\n * their raw `hostInfo.name` string instead.\n */\nexport type Host =\n | \"chatgpt\"\n | \"claude\"\n | \"cursor\"\n | \"goose\"\n | \"mistral-vibe\"\n | \"alpic\";\n\nconst HOST_BY_REPORTED_NAME: Record<string, Host> = {\n chatgpt: \"chatgpt\",\n Claude: \"claude\",\n Cursor: \"cursor\",\n \"MCP-UI Host\": \"goose\",\n \"Le Chat\": \"mistral-vibe\",\n \"alpic-playground\": \"alpic\",\n};\n\nexport type HostInfo = {\n name: Host | (string & {}) | undefined;\n version: string | undefined;\n};\n\n/**\n * Identity of the host application rendering the view, from the MCP Apps\n * `ui/initialize` handshake. `name` is normalized to a {@link Host} slug when\n * recognized, otherwise the raw string; both fields are `undefined` until the\n * handshake resolves (the view renders first and re-renders once it lands).\n *\n * @example\n * ```tsx\n * const { name } = useHost();\n * if (name === \"claude\") return <ClaudeLayout />;\n * ```\n */\nexport function useHost(): HostInfo {\n const hostInfo = useMcpAppContext(\"hostInfo\");\n const name = hostInfo?.name;\n\n return {\n name:\n name !== undefined ? (HOST_BY_REPORTED_NAME[name] ?? name) : undefined,\n version: hostInfo?.version,\n };\n}\n"]}
|
|
@@ -3,13 +3,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
3
3
|
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
4
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
5
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useHost } from "./use-host.js";
|
|
7
7
|
const stubHost = (hostInfo) => {
|
|
8
8
|
vi.stubGlobal("parent", {
|
|
9
9
|
postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
describe("
|
|
12
|
+
describe("useHost", () => {
|
|
13
13
|
beforeEach(() => {
|
|
14
14
|
HostAdaptor.resetInstance();
|
|
15
15
|
McpAppBridge.resetInstance();
|
|
@@ -25,7 +25,7 @@ describe("useHostInfo", () => {
|
|
|
25
25
|
});
|
|
26
26
|
it("is undefined before the handshake resolves, then populated after", async () => {
|
|
27
27
|
stubHost({ name: "Claude", version: "1.2.3" });
|
|
28
|
-
const { result } = renderHook(() =>
|
|
28
|
+
const { result } = renderHook(() => useHost());
|
|
29
29
|
expect(result.current.name).toBeUndefined();
|
|
30
30
|
expect(result.current.version).toBeUndefined();
|
|
31
31
|
await waitFor(() => {
|
|
@@ -42,18 +42,18 @@ describe("useHostInfo", () => {
|
|
|
42
42
|
["alpic-playground", "alpic"],
|
|
43
43
|
])("normalizes reported name %j to slug %j", async (reported, slug) => {
|
|
44
44
|
stubHost({ name: reported, version: "1.0.0" });
|
|
45
|
-
const { result } = renderHook(() =>
|
|
45
|
+
const { result } = renderHook(() => useHost());
|
|
46
46
|
await waitFor(() => {
|
|
47
47
|
expect(result.current.name).toBe(slug);
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
it("preserves an unrecognized reported name as-is", async () => {
|
|
51
51
|
stubHost({ name: "Some Future Host", version: "9.9.9" });
|
|
52
|
-
const { result } = renderHook(() =>
|
|
52
|
+
const { result } = renderHook(() => useHost());
|
|
53
53
|
await waitFor(() => {
|
|
54
54
|
expect(result.current.name).toBe("Some Future Host");
|
|
55
55
|
expect(result.current.version).toBe("9.9.9");
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
|
-
//# sourceMappingURL=use-host
|
|
59
|
+
//# sourceMappingURL=use-host.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-host.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAa,OAAO,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,QAAQ,GAAG,CAAC,QAA4C,EAAE,EAAE;IAChE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;QACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;KAC5D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACp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,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACpE,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { type Host, useHost } from \"./use-host.js\";\n\nconst stubHost = (hostInfo?: { name: string; version: string }) => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),\n });\n};\n\ndescribe(\"useHost\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"is undefined before the handshake resolves, then populated after\", async () => {\n stubHost({ name: \"Claude\", version: \"1.2.3\" });\n const { result } = renderHook(() => useHost());\n\n expect(result.current.name).toBeUndefined();\n expect(result.current.version).toBeUndefined();\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"claude\");\n expect(result.current.version).toBe(\"1.2.3\");\n });\n });\n\n it.each<[string, Host]>([\n [\"chatgpt\", \"chatgpt\"],\n [\"Claude\", \"claude\"],\n [\"Cursor\", \"cursor\"],\n [\"MCP-UI Host\", \"goose\"],\n [\"Le Chat\", \"mistral-vibe\"],\n [\"alpic-playground\", \"alpic\"],\n ])(\"normalizes reported name %j to slug %j\", async (reported, slug) => {\n stubHost({ name: reported, version: \"1.0.0\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(slug);\n });\n });\n\n it(\"preserves an unrecognized reported name as-is\", async () => {\n stubHost({ name: \"Some Future Host\", version: \"9.9.9\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"Some Future Host\");\n expect(result.current.version).toBe(\"9.9.9\");\n });\n });\n});\n"]}
|
|
@@ -3,7 +3,7 @@ import type { RequestSizeOptions } from "../bridges/types.js";
|
|
|
3
3
|
export type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;
|
|
4
4
|
/**
|
|
5
5
|
* Ask the host to resize the view iframe. The applied size is host-driven —
|
|
6
|
-
* the host decides whether and how to honor the request, and {@link
|
|
6
|
+
* the host decides whether and how to honor the request, and {@link useViewport}
|
|
7
7
|
* still reports the final `maxHeight` it allows.
|
|
8
8
|
*
|
|
9
9
|
* Pair with a `ResizeObserver` on your root element to react to content size
|
|
@@ -2,7 +2,7 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { getAdaptor } from "../bridges/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Ask the host to resize the view iframe. The applied size is host-driven —
|
|
5
|
-
* the host decides whether and how to honor the request, and {@link
|
|
5
|
+
* the host decides whether and how to honor the request, and {@link useViewport}
|
|
6
6
|
* still reports the final `maxHeight` it allows.
|
|
7
7
|
*
|
|
8
8
|
* Pair with a `ResizeObserver` on your root element to react to content size
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-size.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EACvD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { RequestSizeOptions } from \"../bridges/types.js\";\n\n/** Function that asks the host to resize the view, returned by {@link useRequestSize}. */\nexport type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;\n\n/**\n * Ask the host to resize the view iframe. The applied size is host-driven —\n * the host decides whether and how to honor the request, and {@link
|
|
1
|
+
{"version":3,"file":"use-request-size.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EACvD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { RequestSizeOptions } from \"../bridges/types.js\";\n\n/** Function that asks the host to resize the view, returned by {@link useRequestSize}. */\nexport type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;\n\n/**\n * Ask the host to resize the view iframe. The applied size is host-driven —\n * the host decides whether and how to honor the request, and {@link useViewport}\n * still reports the final `maxHeight` it allows.\n *\n * Pair with a `ResizeObserver` on your root element to react to content size\n * changes without hard-coded values.\n *\n * @example\n * ```tsx\n * const requestSize = useRequestSize();\n * useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-size\n */\nexport function useRequestSize(): RequestSizeFn {\n const adaptor = getAdaptor();\n const requestSize = useCallback(\n (size: RequestSizeOptions) => adaptor.requestSize(size),\n [adaptor],\n );\n\n return requestSize;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type UserAgent } from "../bridges/index.js";
|
|
1
|
+
import { type Theme, type UserAgent } from "../bridges/index.js";
|
|
2
2
|
export type UserState = {
|
|
3
3
|
locale: string;
|
|
4
|
+
theme: Theme;
|
|
4
5
|
userAgent: UserAgent;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
@@ -9,7 +10,7 @@ export type UserState = {
|
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```tsx
|
|
12
|
-
* const { locale, userAgent } = useUser();
|
|
13
|
+
* const { locale, theme, userAgent } = useUser();
|
|
13
14
|
*
|
|
14
15
|
* // Access device type
|
|
15
16
|
* const isMobile = userAgent.device.type === "mobile";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useHostContext } from "../bridges/index.js";
|
|
1
|
+
import { useHostContext, } from "../bridges/index.js";
|
|
2
2
|
const DEFAULT_LOCALE = "en-US";
|
|
3
3
|
/**
|
|
4
4
|
* Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.
|
|
@@ -21,7 +21,7 @@ function normalizeLocale(locale) {
|
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```tsx
|
|
24
|
-
* const { locale, userAgent } = useUser();
|
|
24
|
+
* const { locale, theme, userAgent } = useUser();
|
|
25
25
|
*
|
|
26
26
|
* // Access device type
|
|
27
27
|
* const isMobile = userAgent.device.type === "mobile";
|
|
@@ -31,7 +31,8 @@ function normalizeLocale(locale) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function useUser() {
|
|
33
33
|
const rawLocale = useHostContext("locale");
|
|
34
|
+
const theme = useHostContext("theme");
|
|
34
35
|
const userAgent = useHostContext("userAgent");
|
|
35
|
-
return { locale: normalizeLocale(rawLocale), userAgent };
|
|
36
|
+
return { locale: normalizeLocale(rawLocale), theme, userAgent };
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=use-user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,GACf,MAAM,qBAAqB,CAAC;AAQ7B,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAClE,CAAC","sourcesContent":["import {\n type Theme,\n type UserAgent,\n useHostContext,\n} from \"../bridges/index.js\";\n\nexport type UserState = {\n locale: string;\n theme: Theme;\n userAgent: UserAgent;\n};\n\nconst DEFAULT_LOCALE = \"en-US\";\n\n/**\n * Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.\n *\n * Handles underscored identifiers returned by the ChatGPT mobile app (e.g. \"fr_FR\" → \"fr-FR\"),\n * incorrect casing (e.g. \"en-us\" → \"en-US\"), and complex subtags (e.g. \"zh_Hans_CN\" → \"zh-Hans-CN\").\n * Falls back to \"en-US\" if the locale is invalid.\n */\nfunction normalizeLocale(locale: string): string {\n try {\n return new Intl.Locale(locale.replace(/_/g, \"-\")).toString();\n } catch {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Hook for accessing session-stable user information.\n * These values are set once at initialization and do not change during the session.\n *\n * @example\n * ```tsx\n * const { locale, theme, userAgent } = useUser();\n *\n * // Access device type\n * const isMobile = userAgent.device.type === \"mobile\";\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-user\n */\nexport function useUser(): UserState {\n const rawLocale = useHostContext(\"locale\");\n const theme = useHostContext(\"theme\");\n const userAgent = useHostContext(\"userAgent\");\n\n return { locale: normalizeLocale(rawLocale), theme, userAgent };\n}\n"]}
|
|
@@ -19,10 +19,11 @@ describe("useUser", () => {
|
|
|
19
19
|
McpAppBridge.resetInstance();
|
|
20
20
|
HostAdaptor.resetInstance();
|
|
21
21
|
});
|
|
22
|
-
it("should return locale and userAgent from mcp host context", async () => {
|
|
22
|
+
it("should return locale, theme and userAgent from mcp host context", async () => {
|
|
23
23
|
vi.stubGlobal("parent", {
|
|
24
24
|
postMessage: getMcpAppHostPostMessageMock({
|
|
25
25
|
locale: "en-US",
|
|
26
|
+
theme: "dark",
|
|
26
27
|
platform: "web",
|
|
27
28
|
deviceCapabilities: { hover: true, touch: false },
|
|
28
29
|
}),
|
|
@@ -30,6 +31,7 @@ describe("useUser", () => {
|
|
|
30
31
|
const { result } = renderHook(() => useUser());
|
|
31
32
|
await waitFor(() => {
|
|
32
33
|
expect(result.current.locale).toBe("en-US");
|
|
34
|
+
expect(result.current.theme).toBe("dark");
|
|
33
35
|
expect(result.current.userAgent).toEqual({
|
|
34
36
|
device: { type: "desktop" },
|
|
35
37
|
capabilities: { hover: true, touch: false },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBA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AAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;YACzF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,WAAW,EAAE,4BAA4B,CAAC;oBACxC,MAAM,EAAE,OAAO;oBACf,QAAQ,EAAE,KAAK;oBACf,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;iBAClD,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAEzD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YAElD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", { locale: \"en-US\" });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"mobile\",\n deviceCapabilities: { hover: false, touch: true },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n });\n\n it(\"should return different locale when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"es-ES\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"es-ES\");\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should canonicalize locale casing\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-us\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n it(\"should fall back to en-US for invalid locale\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"not-a-locale-!!\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,UAAU,CAAC,GAAG,EAAE;YACd,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAC7C,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;YACrD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACtD,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K,EAAE,KAAK,EAAE;iBAClD,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAEzD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YAElD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", { locale: \"en-US\" });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale, theme and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n theme: \"dark\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.theme).toBe(\"dark\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"mobile\",\n deviceCapabilities: { hover: false, touch: true },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n });\n\n it(\"should return different locale when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"es-ES\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"es-ES\");\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should canonicalize locale casing\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-us\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n it(\"should fall back to en-US for invalid locale\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"not-a-locale-!!\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type SafeArea } from "../bridges/index.js";
|
|
2
|
+
export type ViewportState = {
|
|
3
|
+
maxHeight: number | undefined;
|
|
4
|
+
safeArea: SafeArea;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook for accessing the live viewport geometry the host grants the view.
|
|
8
|
+
* These values change on resize, so consumers re-render with them by design.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { maxHeight, safeArea } = useViewport();
|
|
13
|
+
*
|
|
14
|
+
* // Respect safe area insets
|
|
15
|
+
* const paddingTop = safeArea.insets.top;
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-viewport
|
|
19
|
+
*/
|
|
20
|
+
export declare function useViewport(): ViewportState;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing the live viewport geometry the host grants the view.
|
|
4
|
+
* These values change on resize, so consumers re-render with them by design.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const { maxHeight, safeArea } = useViewport();
|
|
9
|
+
*
|
|
10
|
+
* // Respect safe area insets
|
|
11
|
+
* const paddingTop = safeArea.insets.top;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-viewport
|
|
15
|
+
*/
|
|
16
|
+
export function useViewport() {
|
|
17
|
+
const maxHeight = useHostContext("maxHeight");
|
|
18
|
+
const safeArea = useHostContext("safeArea");
|
|
19
|
+
return { maxHeight, safeArea };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-viewport.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOpE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { type SafeArea, useHostContext } from \"../bridges/index.js\";\n\nexport type ViewportState = {\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing the live viewport geometry the host grants the view.\n * These values change on resize, so consumers re-render with them by design.\n *\n * @example\n * ```tsx\n * const { maxHeight, safeArea } = useViewport();\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-viewport\n */\nexport function useViewport(): ViewportState {\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { maxHeight, safeArea };\n}\n"]}
|
|
@@ -3,8 +3,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
3
3
|
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
4
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
5
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
-
import {
|
|
7
|
-
describe("
|
|
6
|
+
import { useViewport } from "./use-viewport.js";
|
|
7
|
+
describe("useViewport", () => {
|
|
8
8
|
describe("apps-sdk host type", () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
HostAdaptor.resetInstance();
|
|
@@ -19,45 +19,29 @@ describe("useLayout", () => {
|
|
|
19
19
|
McpAppBridge.resetInstance();
|
|
20
20
|
HostAdaptor.resetInstance();
|
|
21
21
|
});
|
|
22
|
-
it("should return
|
|
22
|
+
it("should return maxHeight and safeArea from mcp host context", async () => {
|
|
23
23
|
vi.stubGlobal("parent", {
|
|
24
24
|
postMessage: getMcpAppHostPostMessageMock({
|
|
25
|
-
theme: "light",
|
|
26
25
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
27
26
|
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
28
27
|
}),
|
|
29
28
|
});
|
|
30
|
-
const { result } = renderHook(() =>
|
|
29
|
+
const { result } = renderHook(() => useViewport());
|
|
31
30
|
await waitFor(() => {
|
|
32
|
-
expect(result.current.theme).toBe("light");
|
|
33
31
|
expect(result.current.maxHeight).toBe(500);
|
|
34
32
|
expect(result.current.safeArea).toEqual({
|
|
35
33
|
insets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
36
34
|
});
|
|
37
35
|
});
|
|
38
36
|
});
|
|
39
|
-
it("should return dark theme when set to dark", async () => {
|
|
40
|
-
vi.stubGlobal("parent", {
|
|
41
|
-
postMessage: getMcpAppHostPostMessageMock({
|
|
42
|
-
theme: "dark",
|
|
43
|
-
containerDimensions: { maxHeight: 500, width: 400 },
|
|
44
|
-
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
45
|
-
}),
|
|
46
|
-
});
|
|
47
|
-
const { result } = renderHook(() => useLayout());
|
|
48
|
-
await waitFor(() => {
|
|
49
|
-
expect(result.current.theme).toBe("dark");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
37
|
it("should return different maxHeight when set", async () => {
|
|
53
38
|
vi.stubGlobal("parent", {
|
|
54
39
|
postMessage: getMcpAppHostPostMessageMock({
|
|
55
|
-
theme: "light",
|
|
56
40
|
containerDimensions: { maxHeight: 800, width: 400 },
|
|
57
41
|
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
58
42
|
}),
|
|
59
43
|
});
|
|
60
|
-
const { result } = renderHook(() =>
|
|
44
|
+
const { result } = renderHook(() => useViewport());
|
|
61
45
|
await waitFor(() => {
|
|
62
46
|
expect(result.current.maxHeight).toBe(800);
|
|
63
47
|
});
|
|
@@ -65,12 +49,11 @@ describe("useLayout", () => {
|
|
|
65
49
|
it("should return safeArea with insets when set", async () => {
|
|
66
50
|
vi.stubGlobal("parent", {
|
|
67
51
|
postMessage: getMcpAppHostPostMessageMock({
|
|
68
|
-
theme: "light",
|
|
69
52
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
70
53
|
safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },
|
|
71
54
|
}),
|
|
72
55
|
});
|
|
73
|
-
const { result } = renderHook(() =>
|
|
56
|
+
const { result } = renderHook(() => useViewport());
|
|
74
57
|
await waitFor(() => {
|
|
75
58
|
expect(result.current.safeArea.insets.top).toBe(44);
|
|
76
59
|
expect(result.current.safeArea.insets.bottom).toBe(34);
|
|
@@ -91,17 +74,15 @@ describe("useLayout", () => {
|
|
|
91
74
|
McpAppBridge.resetInstance();
|
|
92
75
|
HostAdaptor.resetInstance();
|
|
93
76
|
});
|
|
94
|
-
it("should return
|
|
77
|
+
it("should return maxHeight and safeArea from mcp host context", async () => {
|
|
95
78
|
vi.stubGlobal("parent", {
|
|
96
79
|
postMessage: getMcpAppHostPostMessageMock({
|
|
97
|
-
theme: "dark",
|
|
98
80
|
containerDimensions: { maxHeight: 800, width: 400 },
|
|
99
81
|
safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },
|
|
100
82
|
}),
|
|
101
83
|
});
|
|
102
|
-
const { result } = renderHook(() =>
|
|
84
|
+
const { result } = renderHook(() => useViewport());
|
|
103
85
|
await waitFor(() => {
|
|
104
|
-
expect(result.current.theme).toBe("dark");
|
|
105
86
|
expect(result.current.maxHeight).toBe(800);
|
|
106
87
|
expect(result.current.safeArea).toEqual({
|
|
107
88
|
insets: { top: 20, right: 0, bottom: 34, left: 0 },
|
|
@@ -111,12 +92,11 @@ describe("useLayout", () => {
|
|
|
111
92
|
it("should maintain safeArea referential stability when data has not changed", async () => {
|
|
112
93
|
vi.stubGlobal("parent", {
|
|
113
94
|
postMessage: getMcpAppHostPostMessageMock({
|
|
114
|
-
theme: "light",
|
|
115
95
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
116
96
|
safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },
|
|
117
97
|
}),
|
|
118
98
|
});
|
|
119
|
-
const { result, rerender } = renderHook(() =>
|
|
99
|
+
const { result, rerender } = renderHook(() => useViewport());
|
|
120
100
|
await waitFor(() => {
|
|
121
101
|
expect(result.current.safeArea).toBeDefined();
|
|
122
102
|
});
|
|
@@ -126,4 +106,4 @@ describe("useLayout", () => {
|
|
|
126
106
|
});
|
|
127
107
|
});
|
|
128
108
|
});
|
|
129
|
-
//# sourceMappingURL=use-
|
|
109
|
+
//# sourceMappingURL=use-viewport.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-viewport.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,UAAU,CAAC,GAAG,EAAE;YACd,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,U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AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useViewport } from \"./use-viewport.js\";\n\ndescribe(\"useViewport\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-host-info.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAcvD,MAAM,qBAAqB,GAAyB;IAClD,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE,OAAO;IACtB,SAAS,EAAE,cAAc;IACzB,kBAAkB,EAAE,OAAO;CAC5B,CAAC;AAOF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC;IAE5B,OAAO;QACL,IAAI,EACF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,OAAO,EAAE,QAAQ,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import { useMcpAppContext } from \"../bridges/index.js\";\n\n/**\n * Known host applications, as normalized slugs. Unrecognized hosts surface\n * their raw `hostInfo.name` string instead.\n */\nexport type Host =\n | \"chatgpt\"\n | \"claude\"\n | \"cursor\"\n | \"goose\"\n | \"mistral-vibe\"\n | \"alpic\";\n\nconst HOST_BY_REPORTED_NAME: Record<string, Host> = {\n chatgpt: \"chatgpt\",\n Claude: \"claude\",\n Cursor: \"cursor\",\n \"MCP-UI Host\": \"goose\",\n \"Le Chat\": \"mistral-vibe\",\n \"alpic-playground\": \"alpic\",\n};\n\nexport type HostInfo = {\n name: Host | (string & {}) | undefined;\n version: string | undefined;\n};\n\n/**\n * Identity of the host application rendering the view, from the MCP Apps\n * `ui/initialize` handshake. `name` is normalized to a {@link Host} slug when\n * recognized, otherwise the raw string; both fields are `undefined` until the\n * handshake resolves (the view renders first and re-renders once it lands).\n *\n * @example\n * ```tsx\n * const { name } = useHostInfo();\n * if (name === \"claude\") return <ClaudeLayout />;\n * ```\n */\nexport function useHostInfo(): HostInfo {\n const hostInfo = useMcpAppContext(\"hostInfo\");\n const name = hostInfo?.name;\n\n return {\n name:\n name !== undefined ? (HOST_BY_REPORTED_NAME[name] ?? name) : undefined,\n version: hostInfo?.version,\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-host-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAa,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAC,QAA4C,EAAE,EAAE;IAChE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;QACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;KAC5D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,SAAS,C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O,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAEnD,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAEnD,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { type Host, useHostInfo } from \"./use-host-info.js\";\n\nconst stubHost = (hostInfo?: { name: string; version: string }) => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),\n });\n};\n\ndescribe(\"useHostInfo\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"is undefined before the handshake resolves, then populated after\", async () => {\n stubHost({ name: \"Claude\", version: \"1.2.3\" });\n const { result } = renderHook(() => useHostInfo());\n\n expect(result.current.name).toBeUndefined();\n expect(result.current.version).toBeUndefined();\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"claude\");\n expect(result.current.version).toBe(\"1.2.3\");\n });\n });\n\n it.each<[string, Host]>([\n [\"chatgpt\", \"chatgpt\"],\n [\"Claude\", \"claude\"],\n [\"Cursor\", \"cursor\"],\n [\"MCP-UI Host\", \"goose\"],\n [\"Le Chat\", \"mistral-vibe\"],\n [\"alpic-playground\", \"alpic\"],\n ])(\"normalizes reported name %j to slug %j\", async (reported, slug) => {\n stubHost({ name: reported, version: \"1.0.0\" });\n const { result } = renderHook(() => useHostInfo());\n\n await waitFor(() => {\n expect(result.current.name).toBe(slug);\n });\n });\n\n it(\"preserves an unrecognized reported name as-is\", async () => {\n stubHost({ name: \"Some Future Host\", version: \"9.9.9\" });\n const { result } = renderHook(() => useHostInfo());\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"Some Future Host\");\n expect(result.current.version).toBe(\"9.9.9\");\n });\n });\n});\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type SafeArea, type Theme } from "../bridges/index.js";
|
|
2
|
-
export type LayoutState = {
|
|
3
|
-
theme: Theme;
|
|
4
|
-
maxHeight: number | undefined;
|
|
5
|
-
safeArea: SafeArea;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Hook for accessing layout and visual environment information.
|
|
9
|
-
* These values may change on resize or theme toggle.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* const { theme, maxHeight, safeArea } = useLayout();
|
|
14
|
-
*
|
|
15
|
-
* // Apply theme-aware styling
|
|
16
|
-
* const backgroundColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
|
|
17
|
-
*
|
|
18
|
-
* // Respect safe area insets
|
|
19
|
-
* const paddingTop = safeArea.insets.top;
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @see https://docs.skybridge.tech/api-reference/use-layout
|
|
23
|
-
*/
|
|
24
|
-
export declare function useLayout(): LayoutState;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useHostContext } from "../bridges/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Hook for accessing layout and visual environment information.
|
|
4
|
-
* These values may change on resize or theme toggle.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* const { theme, maxHeight, safeArea } = useLayout();
|
|
9
|
-
*
|
|
10
|
-
* // Apply theme-aware styling
|
|
11
|
-
* const backgroundColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
|
|
12
|
-
*
|
|
13
|
-
* // Respect safe area insets
|
|
14
|
-
* const paddingTop = safeArea.insets.top;
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @see https://docs.skybridge.tech/api-reference/use-layout
|
|
18
|
-
*/
|
|
19
|
-
export function useLayout() {
|
|
20
|
-
const theme = useHostContext("theme");
|
|
21
|
-
const maxHeight = useHostContext("maxHeight");
|
|
22
|
-
const safeArea = useHostContext("safeArea");
|
|
23
|
-
return { theme, maxHeight, safeArea };
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=use-layout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-layout.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQhF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { type SafeArea, type Theme, useHostContext } from \"../bridges/index.js\";\n\nexport type LayoutState = {\n theme: Theme;\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing layout and visual environment information.\n * These values may change on resize or theme toggle.\n *\n * @example\n * ```tsx\n * const { theme, maxHeight, safeArea } = useLayout();\n *\n * // Apply theme-aware styling\n * const backgroundColor = theme === \"dark\" ? \"#1a1a1a\" : \"#ffffff\";\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-layout\n */\nexport function useLayout(): LayoutState {\n const theme = useHostContext(\"theme\");\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { theme, maxHeight, safeArea };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-layout.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,G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;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useLayout } from \"./use-layout.js\";\n\ndescribe(\"useLayout\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"light\");\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return dark theme when set to dark\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}
|
|
File without changes
|
|
File without changes
|