diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21da2047..a741761b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -370,7 +370,7 @@ Local builds retain the `development` telemetry environment. Public releases use Claude's server shows Mobile Dev in a browser beside the chat; in the Claude desktop app's Code tab that is its built-in browser pane. The terminal advertises no MCP Apps support, but the Code tab does (Claude Code runs there with `CLAUDE_CODE_MCP_APPS_HOST=1`) -and would render the panel inline. So Claude's server passes `createPanel({ inline: false })`, +and would render the panel inline. So Claude's server passes `createPanel({ placement: "browser" })`, whose opening tools carry no `ui.resourceUri` for a host to render and name their page under `mobile-dev/panel` instead, and `browserPanel({ always: true })`, which links the page for every host. Opening a recording in the workspace is left out there; recordings stay chat diff --git a/apps/claude/server/server.ts b/apps/claude/server/server.ts index 5a634cf5..4a0f2b68 100644 --- a/apps/claude/server/server.ts +++ b/apps/claude/server/server.ts @@ -18,4 +18,4 @@ if (pinned !== undefined) { const download = downloadedPanelRuntime(release); usePanelRuntime(download.ensure); } -await runStdioServer({ panel: createPanel({ inline: false }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] }); +await runStdioServer({ panel: createPanel({ placement: "browser" }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] }); diff --git a/apps/codex-plugin/server/index.ts b/apps/codex-plugin/server/index.ts index f001293b..482f3ab2 100644 --- a/apps/codex-plugin/server/index.ts +++ b/apps/codex-plugin/server/index.ts @@ -19,7 +19,7 @@ if (!process.env.MOBILE_DEV_E2E_RUNTIME?.trim()) { const release = panelRuntimeReleaseSchema.parse(metadata); useDownloadedTestingRuntime(release); } -const inline = panelPlacement("inline") === "inline"; -const panelContext = inline ? panelSelection : browserPanel({ always: true }); +const placement = panelPlacement("inline") === "browser" ? "browser" : "sidebar"; +const panelContext = placement === "sidebar" ? panelSelection : browserPanel({ always: true }); const features = [agentDeviceTools(readAgentDeviceCatalog()), codexUpdates, panelContext]; -await runStdioServer({ panel: createPanel({ inline }), features }); +await runStdioServer({ panel: createPanel({ placement }), features }); diff --git a/apps/codex-plugin/test/display-mode-control.test.ts b/apps/codex-plugin/test/display-mode-control.test.ts index ef4e5238..3b10f7f2 100644 --- a/apps/codex-plugin/test/display-mode-control.test.ts +++ b/apps/codex-plugin/test/display-mode-control.test.ts @@ -4,8 +4,7 @@ import { setTimeout } from "node:timers/promises"; import { build } from "esbuild"; import { JSDOM } from "jsdom"; -// Both hosts advertise inline and fullscreen. Claude has no control of its own to -// leave the expanded view, so the shared panel offers one; Codex has its own. +// The shared panel can return to chat. Codex closes its sidebar through the host tab. for (const [host, entry, shown] of [ ["shared MCP Apps panel", "packages/mcp-app/src/main.tsx", true], ["Codex panel", "apps/codex-plugin/ui/main.tsx", false], @@ -14,7 +13,8 @@ for (const [host, entry, shown] of [ entryPoints: [entry], bundle: true, write: false, format: "iife", platform: "browser", jsx: "automatic", loader: { ".css": "empty", ".woff2": "empty", ".woff": "empty" }, define: { "process.env.NODE_ENV": '"production"' }, }); - const dom = new JSDOM('
', { + const placement = shown ? "" : "data-sidebar-only"; + const dom = new JSDOM(`
`, { pretendToBeVisual: true, runScripts: "outside-only", url: "https://mobile-dev.test/", }); const window = dom.window; @@ -23,17 +23,20 @@ for (const [host, entry, shown] of [ window.HTMLCanvasElement.prototype.getContext = () => ({ drawImage() {} }); Object.defineProperty(window.HTMLElement.prototype, "clientWidth", { get: () => 400 }); Object.defineProperty(window.HTMLElement.prototype, "clientHeight", { get: () => 800 }); + let advertisedModes: string[] | undefined; let initialized = false; let tornDown = false; function send(message: object) { window.dispatchEvent(new window.MessageEvent("message", { data: { jsonrpc: "2.0", ...message }, source: window })); } window.postMessage = message => { - if (message.method === "ui/initialize") send({ id: message.id, result: { - protocolVersion: "2026-01-26", hostInfo: { name: "test", version: "1" }, hostCapabilities: { serverTools: {}, serverResources: {} }, - hostContext: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] }, - } }); - else if (message.method === "ui/notifications/initialized") initialized = true; + if (message.method === "ui/initialize") { + advertisedModes = message.params.appCapabilities.availableDisplayModes; + send({ id: message.id, result: { + protocolVersion: "2026-01-26", hostInfo: { name: "test", version: "1" }, hostCapabilities: { serverTools: {}, serverResources: {} }, + hostContext: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] }, + } }); + } else if (message.method === "ui/notifications/initialized") initialized = true; else if (message.id === "teardown") tornDown = true; else if (message.id !== undefined) send({ id: message.id, result: { content: [] } }); }; @@ -48,6 +51,7 @@ for (const [host, entry, shown] of [ }); window.eval(built.outputFiles[0].text); await until(() => initialized); + assert.deepEqual(Array.from(advertisedModes ?? []), shown ? ["inline", "fullscreen"] : ["fullscreen"]); await until(() => window.document.querySelector(".workspace-toolbar") !== null); // Hosts follow the handshake with context changes; the control reacts to those. send({ method: "ui/notifications/host-context-changed", params: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] } }); diff --git a/docs/architecture.md b/docs/architecture.md index aad7b08a..c0b80e68 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -22,7 +22,7 @@ A host adds to the shared pieces without changing them: and the native device form. Codex, Cursor's shared entry and the Mac app pass it. Codex and Cursor add agent-device's commands, and Codex the self-updater, which installs through Codex's marketplace; the Mac app, which has no agent, adds its page - resource. Claude's entry (`apps/claude/server`) passes the panel with `inline: false`, + resource. Claude's entry (`apps/claude/server`) passes the panel with `placement: "browser"`, so even MCP Apps hosts such as the desktop app's Code tab render none in the chat, and the browser panel feature with `always: true`, which shows it beside the chat in a browser; it adds agent-device's commands. `MOBILE_DEV_PANEL=browser` diff --git a/docs/devices.md b/docs/devices.md index af7cf8d0..ab6ace48 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -16,7 +16,7 @@ Android tools look for the SDK in `ANDROID_HOME`, `ANDROID_SDK_ROOT`, and the de ## Device panel -Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual device selections replace the opening choice. +Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. In Codex, the live device stays in the sidebar. Closing its tab leaves the chat entry collapsed. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual device selections replace the opening choice. Choose **+ Add device** in a tab strip and select the screens to display. The menu groups devices into iOS and Android columns. Choosing a device closes the menu. Open **+ Add device** again to choose another. Selecting a stopped simulator or emulator starts it. Each screen has its own Home, App Switcher, Screenshot, and Select controls. Each new device opens as a tab in that group. Drag a tab to the left, right, top, or bottom edge of a view to split it. Drop it in the center to join that group or on the tab strip to reorder it. Drag a divider to resize the views. Drag the empty part of a tab strip to move the whole group. Each group streams its selected tab. Deselecting a device closes its screen and leaves the device running. The panel uses Apple’s device bezel and screen mask from the installed DeviceKit assets, with a simple frame as a fallback when assets are unavailable. Use the settings button at the bottom right for appearance, text size, location, and the device frame. iOS also offers contrast; Android offers rotation. The menu shows only settings supported by the bundled backend. Click the screen to type or drag. Closing the panel closes its stream. diff --git a/package-lock.json b/package-lock.json index a9b06b11..e420d897 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mobile-dev", - "version": "0.1.197", + "version": "0.1.198", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mobile-dev", - "version": "0.1.197", + "version": "0.1.198", "workspaces": [ "packages/shared", "packages/core", diff --git a/package.json b/package.json index a5390c47..01b62a4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobile-dev", - "version": "0.1.197", + "version": "0.1.198", "private": true, "workspaces": [ "packages/shared", diff --git a/packages/core/src/browser-panel.ts b/packages/core/src/browser-panel.ts index 753c2838..f90ac4b4 100644 --- a/packages/core/src/browser-panel.ts +++ b/packages/core/src/browser-panel.ts @@ -39,7 +39,7 @@ export type BrowserPanelOptions = { template?: URL; /** * Offers the page to every host, also those that render MCP Apps in the chat, for a - * server whose panel does not render inline (see createPanel's `inline`). + * server using browser placement. */ always?: boolean; }; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index cce9f8e5..4101d260 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,5 +7,5 @@ import { panelPlacement } from "./panel-placement.ts"; // The shared server with Mobile Dev's panel and agent-device's commands, as Cursor and other // MCP hosts run it. Hosts that render no MCP Apps panel can show it in a browser beside the chat. -const inline = panelPlacement("inline") === "inline"; -await runStdioServer({ panel: createPanel({ inline }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: !inline })] }); +const placement = panelPlacement("inline"); +await runStdioServer({ panel: createPanel({ placement }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: placement === "browser" })] }); diff --git a/packages/core/src/panel-tools.ts b/packages/core/src/panel-tools.ts index 98bea29d..19aaac35 100644 --- a/packages/core/src/panel-tools.ts +++ b/packages/core/src/panel-tools.ts @@ -10,7 +10,7 @@ import { PLUGIN_VERSION } from "@mobile-dev/shared/version.ts"; import { SENTRY_ORIGIN } from "@mobile-dev/shared/telemetry.ts"; import { errorMessage, streamMessageSchema, udidSchema } from "@mobile-dev/shared/protocol.ts"; import type { Status } from "@mobile-dev/shared/protocol.ts"; -import { PANEL_PAGE_META, panelTargetSchema } from "@mobile-dev/shared/panel-target.ts"; +import { PANEL_PAGE_META, panelDisplayModes, panelTargetSchema } from "@mobile-dev/shared/panel-target.ts"; import type { PanelTarget } from "@mobile-dev/shared/panel-target.ts"; import type { PanelOpener } from "./server-feature.ts"; import { captureServerError } from "./telemetry.ts"; @@ -81,8 +81,7 @@ const INSTRUCTIONS = "Use mobile_open_simulator before the first device launch o /** Mobile Dev's own device views, which a host adds to the server it runs (see createPanel). */ export type Panel = { - /** Whether the panel renders in the chat, where it can also open recordings in the workspace. */ - readonly inline: boolean; + readonly placement: "inline" | "sidebar" | "browser"; instructions: string; simulatorForeground: SimulatorForeground; register(server: McpServer, shared: PanelShared): () => Promise; @@ -109,12 +108,8 @@ export type PanelOptions = { simulatorInput?: SimulatorInput; copyScreenshot?: typeof copyPNGToClipboard; resourceSaving?: ResourceSaving; - /** - * Whether MCP Apps hosts render the panel in the chat from its opening tools. A host that - * shows it beside the chat instead, in a browser, passes false: the tools then name their - * page under PANEL_PAGE_META, which hosts ignore and the browser panel reads. - */ - inline?: boolean; + /** Native tool results may open inline or only in the sidebar. Browser placement uses a separate page. */ + placement?: Panel["placement"]; }; /** @@ -124,19 +119,19 @@ export type PanelOptions = { * the workspace and asking for devices in a native form. Hosts that show devices * themselves, such as Claude, leave it out. */ -export function createPanel({ baguette = new Baguette(), simulatorInput, copyScreenshot = copyPNGToClipboard, resourceSaving = new ResourceSaving(), inline = true }: PanelOptions = {}): Panel { +export function createPanel({ baguette = new Baguette(), simulatorInput, copyScreenshot = copyPNGToClipboard, resourceSaving = new ResourceSaving(), placement = "inline" }: PanelOptions = {}): Panel { return { - inline, + placement, instructions: INSTRUCTIONS, simulatorForeground: foregroundSimulatorPid, register: (server, shared) => registerPanel(server, shared, { - baguette, copyScreenshot, resourceSaving, inline, simulatorInput: simulatorInput ?? new SimulatorInputService(udid => baguette.repairInput(udid)), + baguette, copyScreenshot, resourceSaving, placement, simulatorInput: simulatorInput ?? new SimulatorInputService(udid => baguette.repairInput(udid)), }), }; } function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, showRecording, opened, reopenNotice }: PanelShared, - { baguette, simulatorInput, copyScreenshot, resourceSaving, inline }: Required) { + { baguette, simulatorInput, copyScreenshot, resourceSaving, placement }: Required) { const streams = new StreamSessions(baguette); const closeIosMirror = registerIosMirrorTools(server, APP_URI); const closeInspection = registerInspectionTools(server, baguette, android); @@ -148,9 +143,10 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh const closeDeviceSettings = registerDeviceSettingsTools(server, baguette, android); registerResourceSavingTools(server, baguette, android, resourceSaving); registerPanelAppControlTools(server, drivers); - // Opening a recording renders the workspace in the chat; beside the chat, recordings stay cards. - if (inline) registerOpenRecordingTool(server, showRecording, WORKSPACE_URI); + // Native panels can open a saved recording in the workspace. Browser panels keep recordings in cards. + if (placement !== "browser") registerOpenRecordingTool(server, showRecording, WORKSPACE_URI); + const availableDisplayModes = panelDisplayModes(placement === "sidebar"); const readApp = async (uri: URL): Promise => { const content = await page(); return { contents: [{ @@ -159,7 +155,7 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh : content, _meta: { ui: { permissions: { clipboardWrite: {} }, csp: { connectDomains: [SENTRY_ORIGIN], resourceDomains: [] } }, - "openai/ui": { preferredDisplayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] }, + "openai/ui": { preferredDisplayMode: "fullscreen", availableDisplayModes }, }, }] }; }; @@ -251,14 +247,13 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh return response; }); - // Inline, the host renders each opening tool's page in the chat; otherwise the tool only - // names it, and a host feature such as the browser panel shows it. + // Native hosts open the tool's UI resource. Browser placement gives the page URI only to the browser panel. const openingTool = (name: string, config: { description: string; resourceUri: string; entrypoint: "global" | "thread"; defaults?: Partial; startBackend?: boolean }) => { const definition = { title: "Mobile Dev", description: config.description, inputSchema: panelTargetSchema, outputSchema: { ...statusOutput, panelTarget: panelTargetSchema, browserPanel: browserPanelOutput }, annotations: write, }; - if (inline === false) { + if (placement === "browser") { server.registerTool(name, { ...definition, _meta: { [PANEL_PAGE_META]: { resourceUri: config.resourceUri } } }, openPanel(name, config.defaults, config.startBackend)); return; } diff --git a/packages/core/src/plugin.ts b/packages/core/src/plugin.ts index 7c3e677e..30fce80a 100644 --- a/packages/core/src/plugin.ts +++ b/packages/core/src/plugin.ts @@ -147,7 +147,15 @@ export async function createPlugin(html: string | (() => Promise), o registerTestingAgentTools(server, testingDevices, testingRecordings); const resource = async () => typeof html === "string" ? { html } : await html(); - const page = async () => configureUI((await resource()).html); + function configurePanelPage(content: string) { + const configured = configureUI(content); + if (panel?.placement === "sidebar") return configured.replace('data-view="panel"', 'data-sidebar-only data-view="panel"'); + return configured; + } + const page = async () => { + const current = await resource(); + return configurePanelPage(current.html); + }; server.registerResource("mobile-dev-live", new ResourceTemplate(`${LIVE_UI_URI}?after={revision}`, { list: undefined }), { mimeType: "application/json", description: "Read a changed local development UI through MCP. Unchanged reads omit the HTML.", @@ -155,12 +163,15 @@ export async function createPlugin(html: string | (() => Promise), o const { html: content, liveRevision: revision } = await resource(); return { contents: [{ uri: uri.href, mimeType: "application/json", text: JSON.stringify({ revision, - html: revision && revision !== uri.searchParams.get("after") ? configureUI(content) : undefined, + html: revision && revision !== uri.searchParams.get("after") ? configurePanelPage(content) : undefined, }) }] }; }); const readCard = (view: string) => async (uri: URL) => { // Cards from a server whose panel opens recordings in the workspace can open them there. - const content = (await page()).replace('data-view="panel"', `data-view="${view}"${panel?.inline ? " data-workspace" : ""}`); + const current = await resource(); + const html = configureUI(current.html); + const workspace = panel && panel.placement !== "browser" ? " data-workspace" : ""; + const content = html.replace('data-view="panel"', `data-view="${view}"${workspace}`); return { contents: [{ uri: uri.href, mimeType: RESOURCE_MIME_TYPE, text: content, _meta: { ui: { prefersBorder: true, permissions: { clipboardWrite: {} }, csp: { connectDomains: [SENTRY_ORIGIN], resourceDomains: [] } }, "openai/ui": { preferredDisplayMode: "inline", availableDisplayModes: ["inline", "fullscreen"] }, diff --git a/packages/core/test/browser-panel.test.ts b/packages/core/test/browser-panel.test.ts index 0edc8cf7..355eedfe 100644 --- a/packages/core/test/browser-panel.test.ts +++ b/packages/core/test/browser-panel.test.ts @@ -169,7 +169,7 @@ test("a panel that never renders inline links the browser page for MCP Apps host t.after(() => fake.close()); const [hostSide, serverSide] = InMemoryTransport.createLinkedPair(); const shared = new SharedTransport(serverSide); - const panel = createPanel({ baguette: new Baguette(fake.url), simulatorInput: fakeSimulatorInput(), inline: false }); + const panel = createPanel({ baguette: new Baguette(fake.url), simulatorInput: fakeSimulatorInput(), placement: "browser" }); const plugin = await createTestPlugin("", { panel, features: [browserPanel({ template: pathToFileURL(page), always: true })], connections: shared }); // The desktop app's Code tab renders MCP Apps. const host = new Client({ name: "claude-code", version: "1" }, { capabilities: { extensions: { [EXTENSION_ID]: { mimeTypes: [RESOURCE_MIME_TYPE] } } } as ClientCapabilities }); diff --git a/packages/core/test/plugin.test.ts b/packages/core/test/plugin.test.ts index b0fc5e5a..3a382dcd 100644 --- a/packages/core/test/plugin.test.ts +++ b/packages/core/test/plugin.test.ts @@ -269,7 +269,7 @@ test("MCP tools expose native entrypoints and complete the simulator workflow", // Cards from a server with the workspace can open recordings there. assert.match(recordingResource.contents[0].text as string, /data-view="recording" data-workspace/); // A panel beside the chat opens no recordings, so its cards offer no workspace. - const besideChat = await createTestPlugin('', { panel: createPanel({ inline: false }) }); + const besideChat = await createTestPlugin('', { panel: createPanel({ placement: "browser" }) }); const [besideChatClientTransport, besideChatServerTransport] = InMemoryTransport.createLinkedPair(); const besideChatClient = new Client({ name: "browser-panel-host", version: "1" }); t.after(async () => { await besideChatClient.close(); await besideChat.close(); }); diff --git a/packages/mcp-app/src/workspace-app.tsx b/packages/mcp-app/src/workspace-app.tsx index 5c21890e..1395c6b0 100644 --- a/packages/mcp-app/src/workspace-app.tsx +++ b/packages/mcp-app/src/workspace-app.tsx @@ -10,7 +10,7 @@ import { flushSync } from "react-dom"; import { Workspace } from "./components/workspace"; import { DisplayModeButton } from "./components/display-mode-button"; import { ContextAttachments } from "./components/context-attachments"; -import { panelTargetSchema } from "@mobile-dev/shared/panel-target.ts"; +import { panelDisplayModes, panelTargetSchema } from "@mobile-dev/shared/panel-target.ts"; import { DeviceWorkspace } from "@mobile-dev/ui/device-workspace.ts"; import { WorkspaceTools } from "@mobile-dev/ui/workspace-tools.ts"; import type { ToolName } from "@mobile-dev/ui/workspace-tools.ts"; @@ -23,7 +23,9 @@ import { applyHostStyles } from "./host-styles.ts"; /** Starts the device workspace: the panel MCP Apps hosts open beside the chat. */ export function startWorkspaceApp(options: WorkspaceOptions = {}) { - const app = new App({ name: "mobile-dev-ui", version: PLUGIN_VERSION }, { availableDisplayModes: ["inline", "fullscreen"] }, { autoResize: false }); + const sidebarOnly = document.documentElement.hasAttribute("data-sidebar-only"); + const availableDisplayModes = panelDisplayModes(sidebarOnly); + const app = new App({ name: "mobile-dev-ui", version: PLUGIN_VERSION }, { availableDisplayModes }, { autoResize: false }); startUiTelemetry(app); const extensions = new OpenAIExtensions(app); // Codex shows context as composer attachments through OpenAI's extension. diff --git a/packages/shared/src/panel-target.ts b/packages/shared/src/panel-target.ts index 62e5315d..f03cf9f3 100644 --- a/packages/shared/src/panel-target.ts +++ b/packages/shared/src/panel-target.ts @@ -31,6 +31,10 @@ export function isRecordableDevice(device?: SimulatorDevice): boolean { return device.platform === "android" ? device.kind === "emulator" : device.platform === "ios" || device.platform === undefined; } +export function panelDisplayModes(sidebarOnly: boolean): ("inline" | "fullscreen")[] { + return sidebarOnly ? ["fullscreen"] : ["inline", "fullscreen"]; +} + export type PanelTarget = z.infer; export function panelTargetPlatform(target: PanelTarget): "ios" | "android" | undefined { diff --git a/packages/shared/src/version.ts b/packages/shared/src/version.ts index c0490b2c..5faf38e7 100644 --- a/packages/shared/src/version.ts +++ b/packages/shared/src/version.ts @@ -1 +1 @@ -export const PLUGIN_VERSION = "0.1.197"; +export const PLUGIN_VERSION = "0.1.198"; diff --git a/tooling/hosts/device-dock.spec.ts b/tooling/hosts/device-dock.spec.ts index 709c8cde..1f5c889d 100644 --- a/tooling/hosts/device-dock.spec.ts +++ b/tooling/hosts/device-dock.spec.ts @@ -35,7 +35,7 @@ async function drag(page: Page, source: Locator, destination: Locator, x: number for (const theme of ["light", "dark"] as const) { test(`mixed device tab groups in ${theme} @visual`, async ({ page, openView, pageErrors }) => { - const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, displayMode: "inline", theme, width: 900, inventory }); + const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, theme, width: 900, inventory }); await selectAndroid(view); const pane = view.locator("[data-device-pane]:visible"); await expect(pane).toHaveCount(1); @@ -52,7 +52,7 @@ for (const theme of ["light", "dark"] as const) { test("rounded dock overlays do not resize a device that fits", async ({ openView, server }) => { test.skip(hasPanel(server) === false, "This target opens the workspace in a separate browser tab."); - const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, displayMode: "inline", width: 720, inventory }); + const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, width: 720, inventory }); const dock = view.locator("#simulator-panels"); await dock.getByRole("tab", { name: iphone.name }).waitFor(); await dock.evaluate(element => { element.style.width = "706.67px"; }); @@ -74,7 +74,7 @@ test("rounded dock overlays do not resize a device that fits", async ({ openView test("choosing a device dismisses the picker and keeps Add device centered in narrow groups", async ({ page, openView, server }) => { test.skip(hasPanel(server) === false, "This target opens the workspace in a separate browser tab."); - const { view } = await openView("mobile_open_simulator", { displayMode: "inline", width: 360, inventory }); + const { view } = await openView("mobile_open_simulator", { width: 360, inventory }); await view.getByRole("button", { name: "Add device" }).click(); const picker = view.getByRole("dialog"); await picker.getByRole("button", { name: /Pixel 9/ }).press("Enter"); @@ -102,7 +102,7 @@ test("choosing a device dismisses the picker and keeps Add device centered in na test("devices split at every edge, nest, rejoin and reorder without replacing their canvases", async ({ page, openView, pageErrors, server }) => { test.skip(hasPanel(server) === false, "This target opens the workspace in a separate browser tab."); - const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, displayMode: "inline", width: 1000, inventory }); + const { view } = await openView("mobile_open_simulator", { arguments: { deviceId: iphone.udid }, width: 1000, inventory }); await selectAndroid(view); const dock = view.locator("#simulator-panels"); const tab = (name: string) => dock.getByRole("tab", { name, exact: true }); diff --git a/tooling/hosts/fixtures.ts b/tooling/hosts/fixtures.ts index 84687e5e..f0b2abee 100644 --- a/tooling/hosts/fixtures.ts +++ b/tooling/hosts/fixtures.ts @@ -2,6 +2,7 @@ import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { test as base, expect, type FrameLocator, type Page } from "@playwright/test"; +import { OpenAIUiResourceMetadataSchema } from "@openai/mcp-extensions/server"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import type { CallToolResult, JSONRPCMessage, Tool } from "@modelcontextprotocol/sdk/types.js"; @@ -112,7 +113,7 @@ export const test = base.extend({ } return server.client.callTool(params); }); - await use(async (name, { arguments: args = {}, theme = "light", displayMode = "fullscreen", width, initiallyHidden, inventory: devices } = {}) => { + await use(async (name, { arguments: args = {}, theme = "light", displayMode, width, initiallyHidden, inventory: devices } = {}) => { inventory = devices; const tool = server.tools.find(candidate => candidate.name === name); const uri = (tool?._meta?.ui as { resourceUri?: string } | undefined)?.resourceUri; @@ -122,7 +123,13 @@ export const test = base.extend({ const html = (resource.contents[0] as { text: string }).text; await page.emulateMedia({ colorScheme: theme }); if (width !== undefined) await page.setViewportSize({ width, height: page.viewportSize()!.height }); - const context = host.context(theme, displayMode); + const metadata = OpenAIUiResourceMetadataSchema.parse(resource.contents[0]._meta?.["openai/ui"]); + const mode = displayMode ?? metadata.preferredDisplayMode; + if (mode !== "inline" && mode !== "fullscreen") throw new Error(`Unsupported display mode for ${name}: ${mode}`); + const context = host.context(theme, mode); + const supported = context.availableDisplayModes?.filter(value => metadata.availableDisplayModes?.includes(value)); + if (!supported?.includes(mode)) throw new Error(`${name} cannot open in ${mode}`); + context.availableDisplayModes = supported; context.containerDimensions = { ...page.viewportSize()! }; await page.goto(`${HOST_ORIGIN}/host.html`); await page.evaluate(options => window.harness.open(options), { diff --git a/tooling/hosts/hosts.spec.ts b/tooling/hosts/hosts.spec.ts index 50b5eae5..42d4d65a 100644 --- a/tooling/hosts/hosts.spec.ts +++ b/tooling/hosts/hosts.spec.ts @@ -1,5 +1,6 @@ import { existsSync, readFileSync } from "node:fs"; import { join } from "node:path"; +import { getToolUiResourceUri } from "@modelcontextprotocol/ext-apps/app-bridge"; import Ajv2020 from "ajv/dist/2020.js"; import { codexToolBudget } from "../../apps/codex-plugin/tooling/codex-tool-limits.mjs"; import { oversizedFiles, PANEL_PARTS } from "../host-runtime.mjs"; @@ -189,11 +190,11 @@ test.describe("MCP Apps hosts", () => { // This asks for the row itself rather than for `split`, which is false outside the fullscreen // workspace — the mirror then kept the 60% default meant for a tool stacked under it, and the // preview and the steps were left sharing the height below it. - for (const displayMode of ["fullscreen", "inline"] as const) { + for (const entrypoint of ["mobile_open_workspace", "mobile_open_simulator"]) { await page.setViewportSize({ width: 1280, height: 800 }); const device = { udid: "phone", name: "iPhone", runtime: "iOS", state: "Shutdown" }; const inventory = { ios: [device], android: [] }; - const { view } = await openView("mobile_open_workspace", { displayMode, inventory, arguments: { deviceId: device.udid } }); + const { view } = await openView(entrypoint, { inventory, arguments: { deviceId: device.udid } }); await view.locator("#tool-select").click(); await view.getByRole("option", { name: "Testing" }).click(); await view.locator("[data-testing-recorder-workspace]").waitFor(); @@ -203,9 +204,9 @@ test.describe("MCP Apps hosts", () => { }; // The panel's own padding and the gaps between the panes come off the two that are read, so // the shares are 25/45/30 of the pane area and a little under that of the window. - expect(await share("#simulators-resizable"), `the mirror in ${displayMode}`).toBe(25); - expect(await share("#testing-preview-resizable"), `the preview in ${displayMode}`).toBeGreaterThan(40); - expect(await share("#testing-steps-resizable"), `the steps in ${displayMode}`).toBeGreaterThan(26); + expect(await share("#simulators-resizable"), `the mirror in ${entrypoint}`).toBe(25); + expect(await share("#testing-preview-resizable"), `the preview in ${entrypoint}`).toBeGreaterThan(40); + expect(await share("#testing-steps-resizable"), `the steps in ${entrypoint}`).toBeGreaterThan(26); // And in that order, left to right: the mirror leads, because it is what is acted on. const mirror = await view.locator("#simulators-resizable").boundingBox(); const preview = await view.locator("#testing-preview-resizable").boundingBox(); @@ -241,9 +242,31 @@ test.describe("MCP Apps hosts", () => { await expect(view.getByRole("button", { name: "Back to chat" })).toHaveCount(target === "codex" ? 0 : 1); }); - test("the panel beside the chat opens inline", async ({ openView, pageErrors, server }) => { + test("Codex offers only the sidebar for live devices and keeps chat cards inline", async ({ server, target }) => { + test.skip(target !== "codex"); + for (const name of ["mobile_open_simulator", "mobile_open_workspace", "mobile_render_performance_recording", "mobile_compare_performance_recordings", "mobile_analyze_profile"]) { + const tool = server.tools.find(candidate => candidate.name === name); + if (!tool) throw new Error(`Missing tool ${name}`); + const uri = getToolUiResourceUri(tool); + if (!uri) throw new Error(`Missing UI resource for ${name}`); + const live = name === "mobile_open_simulator" || name === "mobile_open_workspace"; + const expected = live + ? { preferredDisplayMode: "fullscreen", availableDisplayModes: ["fullscreen"] } + : { preferredDisplayMode: "inline", availableDisplayModes: ["inline", "fullscreen"] }; + const oldUri = uri.replace(/\/\d+\.\d+\.\d+\//, "/0.1.194/"); + for (const address of [uri, oldUri]) { + const resource = await server.client.readResource({ uri: address }); + const [content] = resource.contents; + expect(content._meta?.["openai/ui"], address).toEqual(expected); + const sidebarPage = typeof content.text === "string" && /]*data-sidebar-only\b/.test(content.text); + expect(sidebarPage, address).toBe(live); + } + } + }); + + test("the panel opens beside the chat", async ({ openView, pageErrors, server }) => { test.skip(hasPanel(server) === false, "This target's server renders no panel in the chat."); - const { view } = await openView("mobile_open_simulator", { displayMode: "inline" }); + const { view } = await openView("mobile_open_simulator"); await expect(view.getByRole("button", { name: "Add device" })).toBeAttached(); expect(pageErrors).toEqual([]); }); @@ -251,7 +274,7 @@ test.describe("MCP Apps hosts", () => { test("a targeted panel initialized while hidden shows the device picker and keeps tools collapsed", async ({ openView, page, pageErrors, target }) => { test.skip(target !== "codex", "Codex retains inactive panels before displaying them."); const { view } = await openView("mobile_open_simulator", { - arguments: { platform: "android" }, displayMode: "inline", initiallyHidden: true, + arguments: { platform: "android" }, initiallyHidden: true, }); const empty = view.locator('[role="status"]').filter({ hasText: "Requested Android device unavailable" }); await expect(empty).toBeAttached(); diff --git a/tooling/hosts/visual.spec.ts b/tooling/hosts/visual.spec.ts index 4ca15bef..d6379ccc 100644 --- a/tooling/hosts/visual.spec.ts +++ b/tooling/hosts/visual.spec.ts @@ -40,7 +40,7 @@ for (const theme of themes) test.describe(`${theme}`, { tag: "@visual" }, () => ios: [{ ...device, name: "iPhone 17 Pro", udid: "iphone" }, { ...device, name: "iPad Air", udid: "ipad" }], android: [{ ...device, name: "Pixel 9", udid: "avd:Pixel_9", runtime: "Android" }], }; - const { view } = await openView("mobile_open_simulator", { theme, displayMode: "inline", width: 480, inventory }); + const { view } = await openView("mobile_open_simulator", { theme, width: 480, inventory }); await view.getByRole("button", { name: "Add device" }).click(); const picker = view.getByRole("dialog", { name: "Choose devices" }); await expect(picker.getByText("iPhone 17 Pro")).toBeVisible(); @@ -140,7 +140,7 @@ for (const theme of themes) test.describe(`${theme}`, { tag: "@visual" }, () => }); test(`panel beside the chat`, async ({ openView }) => { - const { view } = await openView("mobile_open_simulator", { theme, displayMode: "inline", width: 480, arguments: { platform: "ios" } }); + const { view } = await openView("mobile_open_simulator", { theme, width: 480, arguments: { platform: "ios" } }); await expect(view.getByText("Requested iOS device unavailable.", { exact: false })).toBeVisible(); await expect.soft(view.locator("body")).toHaveScreenshot(`panel-${theme}.png`); });