@dudko.dev/agent-web-ui 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +254 -2
- package/dist/canvas.cjs +266 -0
- package/dist/canvas.cjs.map +1 -0
- package/dist/canvas.d.cts +105 -0
- package/dist/canvas.d.ts +105 -0
- package/dist/canvas.js +200 -0
- package/dist/canvas.js.map +1 -0
- package/dist/chunk-4EHUITGU.js +342 -0
- package/dist/chunk-4EHUITGU.js.map +1 -0
- package/dist/chunk-7O64ZI6Z.js +125 -0
- package/dist/chunk-7O64ZI6Z.js.map +1 -0
- package/dist/chunk-A55Q377T.js +342 -0
- package/dist/chunk-A55Q377T.js.map +1 -0
- package/dist/chunk-EL2YCROY.js +127 -0
- package/dist/chunk-EL2YCROY.js.map +1 -0
- package/dist/chunk-GB7RZJMG.js +98 -0
- package/dist/chunk-GB7RZJMG.js.map +1 -0
- package/dist/chunk-KZQB35LS.js +22 -0
- package/dist/chunk-KZQB35LS.js.map +1 -0
- package/dist/chunk-P2F2P3JC.js +400 -0
- package/dist/chunk-P2F2P3JC.js.map +1 -0
- package/dist/chunk-TPK25QGK.js +342 -0
- package/dist/chunk-TPK25QGK.js.map +1 -0
- package/dist/en-CcNUz2tN.d.cts +342 -0
- package/dist/en-CcNUz2tN.d.ts +342 -0
- package/dist/index.cjs +4143 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +919 -0
- package/dist/index.d.ts +919 -0
- package/dist/index.js +3771 -0
- package/dist/index.js.map +1 -0
- package/dist/labels-B5xpIGf_.d.cts +25 -0
- package/dist/labels-B5xpIGf_.d.ts +25 -0
- package/dist/labels-D5BrHct4.d.cts +1208 -0
- package/dist/labels-UuWI7wPo.d.ts +1208 -0
- package/dist/locales/be.cjs +794 -0
- package/dist/locales/be.cjs.map +1 -0
- package/dist/locales/be.d.cts +14 -0
- package/dist/locales/be.d.ts +14 -0
- package/dist/locales/be.js +374 -0
- package/dist/locales/be.js.map +1 -0
- package/dist/locales/bg.cjs +747 -0
- package/dist/locales/bg.cjs.map +1 -0
- package/dist/locales/bg.d.cts +14 -0
- package/dist/locales/bg.d.ts +14 -0
- package/dist/locales/bg.js +327 -0
- package/dist/locales/bg.js.map +1 -0
- package/dist/locales/ca.cjs +773 -0
- package/dist/locales/ca.cjs.map +1 -0
- package/dist/locales/ca.d.cts +14 -0
- package/dist/locales/ca.d.ts +14 -0
- package/dist/locales/ca.js +353 -0
- package/dist/locales/ca.js.map +1 -0
- package/dist/locales/cs.cjs +794 -0
- package/dist/locales/cs.cjs.map +1 -0
- package/dist/locales/cs.d.cts +14 -0
- package/dist/locales/cs.d.ts +14 -0
- package/dist/locales/cs.js +374 -0
- package/dist/locales/cs.js.map +1 -0
- package/dist/locales/da.cjs +747 -0
- package/dist/locales/da.cjs.map +1 -0
- package/dist/locales/da.d.cts +14 -0
- package/dist/locales/da.d.ts +14 -0
- package/dist/locales/da.js +327 -0
- package/dist/locales/da.js.map +1 -0
- package/dist/locales/de.cjs +756 -0
- package/dist/locales/de.cjs.map +1 -0
- package/dist/locales/de.d.cts +14 -0
- package/dist/locales/de.d.ts +14 -0
- package/dist/locales/de.js +336 -0
- package/dist/locales/de.js.map +1 -0
- package/dist/locales/el.cjs +756 -0
- package/dist/locales/el.cjs.map +1 -0
- package/dist/locales/el.d.cts +14 -0
- package/dist/locales/el.d.ts +14 -0
- package/dist/locales/el.js +336 -0
- package/dist/locales/el.js.map +1 -0
- package/dist/locales/en.cjs +753 -0
- package/dist/locales/en.cjs.map +1 -0
- package/dist/locales/en.d.cts +10 -0
- package/dist/locales/en.d.ts +10 -0
- package/dist/locales/en.js +333 -0
- package/dist/locales/en.js.map +1 -0
- package/dist/locales/es-419.cjs +778 -0
- package/dist/locales/es-419.cjs.map +1 -0
- package/dist/locales/es-419.d.cts +16 -0
- package/dist/locales/es-419.d.ts +16 -0
- package/dist/locales/es-419.js +23 -0
- package/dist/locales/es-419.js.map +1 -0
- package/dist/locales/es.cjs +769 -0
- package/dist/locales/es.cjs.map +1 -0
- package/dist/locales/es.d.cts +14 -0
- package/dist/locales/es.d.ts +14 -0
- package/dist/locales/es.js +14 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/locales/fi.cjs +753 -0
- package/dist/locales/fi.cjs.map +1 -0
- package/dist/locales/fi.d.cts +14 -0
- package/dist/locales/fi.d.ts +14 -0
- package/dist/locales/fi.js +333 -0
- package/dist/locales/fi.js.map +1 -0
- package/dist/locales/fr-CA.cjs +777 -0
- package/dist/locales/fr-CA.cjs.map +1 -0
- package/dist/locales/fr-CA.d.cts +17 -0
- package/dist/locales/fr-CA.d.ts +17 -0
- package/dist/locales/fr-CA.js +22 -0
- package/dist/locales/fr-CA.js.map +1 -0
- package/dist/locales/fr.cjs +769 -0
- package/dist/locales/fr.cjs.map +1 -0
- package/dist/locales/fr.d.cts +14 -0
- package/dist/locales/fr.d.ts +14 -0
- package/dist/locales/fr.js +14 -0
- package/dist/locales/fr.js.map +1 -0
- package/dist/locales/gn.cjs +750 -0
- package/dist/locales/gn.cjs.map +1 -0
- package/dist/locales/gn.d.cts +16 -0
- package/dist/locales/gn.d.ts +16 -0
- package/dist/locales/gn.js +330 -0
- package/dist/locales/gn.js.map +1 -0
- package/dist/locales/hr.cjs +769 -0
- package/dist/locales/hr.cjs.map +1 -0
- package/dist/locales/hr.d.cts +14 -0
- package/dist/locales/hr.d.ts +14 -0
- package/dist/locales/hr.js +349 -0
- package/dist/locales/hr.js.map +1 -0
- package/dist/locales/ht.cjs +750 -0
- package/dist/locales/ht.cjs.map +1 -0
- package/dist/locales/ht.d.cts +16 -0
- package/dist/locales/ht.d.ts +16 -0
- package/dist/locales/ht.js +330 -0
- package/dist/locales/ht.js.map +1 -0
- package/dist/locales/hu.cjs +753 -0
- package/dist/locales/hu.cjs.map +1 -0
- package/dist/locales/hu.d.cts +14 -0
- package/dist/locales/hu.d.ts +14 -0
- package/dist/locales/hu.js +333 -0
- package/dist/locales/hu.js.map +1 -0
- package/dist/locales/index.cjs +537 -0
- package/dist/locales/index.cjs.map +1 -0
- package/dist/locales/index.d.cts +38 -0
- package/dist/locales/index.d.ts +38 -0
- package/dist/locales/index.js +105 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/it.cjs +777 -0
- package/dist/locales/it.cjs.map +1 -0
- package/dist/locales/it.d.cts +14 -0
- package/dist/locales/it.d.ts +14 -0
- package/dist/locales/it.js +357 -0
- package/dist/locales/it.js.map +1 -0
- package/dist/locales/nb.cjs +747 -0
- package/dist/locales/nb.cjs.map +1 -0
- package/dist/locales/nb.d.cts +14 -0
- package/dist/locales/nb.d.ts +14 -0
- package/dist/locales/nb.js +327 -0
- package/dist/locales/nb.js.map +1 -0
- package/dist/locales/nl.cjs +753 -0
- package/dist/locales/nl.cjs.map +1 -0
- package/dist/locales/nl.d.cts +14 -0
- package/dist/locales/nl.d.ts +14 -0
- package/dist/locales/nl.js +333 -0
- package/dist/locales/nl.js.map +1 -0
- package/dist/locales/pl.cjs +794 -0
- package/dist/locales/pl.cjs.map +1 -0
- package/dist/locales/pl.d.cts +14 -0
- package/dist/locales/pl.d.ts +14 -0
- package/dist/locales/pl.js +374 -0
- package/dist/locales/pl.js.map +1 -0
- package/dist/locales/pt-BR.cjs +773 -0
- package/dist/locales/pt-BR.cjs.map +1 -0
- package/dist/locales/pt-BR.d.cts +14 -0
- package/dist/locales/pt-BR.d.ts +14 -0
- package/dist/locales/pt-BR.js +353 -0
- package/dist/locales/pt-BR.js.map +1 -0
- package/dist/locales/pt.cjs +777 -0
- package/dist/locales/pt.cjs.map +1 -0
- package/dist/locales/pt.d.cts +14 -0
- package/dist/locales/pt.d.ts +14 -0
- package/dist/locales/pt.js +357 -0
- package/dist/locales/pt.js.map +1 -0
- package/dist/locales/qu.cjs +756 -0
- package/dist/locales/qu.cjs.map +1 -0
- package/dist/locales/qu.d.cts +16 -0
- package/dist/locales/qu.d.ts +16 -0
- package/dist/locales/qu.js +336 -0
- package/dist/locales/qu.js.map +1 -0
- package/dist/locales/ro.cjs +769 -0
- package/dist/locales/ro.cjs.map +1 -0
- package/dist/locales/ro.d.cts +14 -0
- package/dist/locales/ro.d.ts +14 -0
- package/dist/locales/ro.js +349 -0
- package/dist/locales/ro.js.map +1 -0
- package/dist/locales/ru.cjs +789 -0
- package/dist/locales/ru.cjs.map +1 -0
- package/dist/locales/ru.d.cts +14 -0
- package/dist/locales/ru.d.ts +14 -0
- package/dist/locales/ru.js +369 -0
- package/dist/locales/ru.js.map +1 -0
- package/dist/locales/sk.cjs +794 -0
- package/dist/locales/sk.cjs.map +1 -0
- package/dist/locales/sk.d.cts +14 -0
- package/dist/locales/sk.d.ts +14 -0
- package/dist/locales/sk.js +374 -0
- package/dist/locales/sk.js.map +1 -0
- package/dist/locales/sq.cjs +753 -0
- package/dist/locales/sq.cjs.map +1 -0
- package/dist/locales/sq.d.cts +14 -0
- package/dist/locales/sq.d.ts +14 -0
- package/dist/locales/sq.js +333 -0
- package/dist/locales/sq.js.map +1 -0
- package/dist/locales/sr-Latn.cjs +841 -0
- package/dist/locales/sr-Latn.cjs.map +1 -0
- package/dist/locales/sr-Latn.d.cts +17 -0
- package/dist/locales/sr-Latn.d.ts +17 -0
- package/dist/locales/sr-Latn.js +86 -0
- package/dist/locales/sr-Latn.js.map +1 -0
- package/dist/locales/sr.cjs +769 -0
- package/dist/locales/sr.cjs.map +1 -0
- package/dist/locales/sr.d.cts +14 -0
- package/dist/locales/sr.d.ts +14 -0
- package/dist/locales/sr.js +14 -0
- package/dist/locales/sr.js.map +1 -0
- package/dist/locales/sv.cjs +753 -0
- package/dist/locales/sv.cjs.map +1 -0
- package/dist/locales/sv.d.cts +14 -0
- package/dist/locales/sv.d.ts +14 -0
- package/dist/locales/sv.js +333 -0
- package/dist/locales/sv.js.map +1 -0
- package/dist/locales/tr.cjs +750 -0
- package/dist/locales/tr.cjs.map +1 -0
- package/dist/locales/tr.d.cts +14 -0
- package/dist/locales/tr.d.ts +14 -0
- package/dist/locales/tr.js +330 -0
- package/dist/locales/tr.js.map +1 -0
- package/dist/locales/uk.cjs +794 -0
- package/dist/locales/uk.cjs.map +1 -0
- package/dist/locales/uk.d.cts +14 -0
- package/dist/locales/uk.d.ts +14 -0
- package/dist/locales/uk.js +374 -0
- package/dist/locales/uk.js.map +1 -0
- package/dist/markdown.cjs +620 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.cts +153 -0
- package/dist/markdown.d.ts +153 -0
- package/dist/markdown.js +573 -0
- package/dist/markdown.js.map +1 -0
- package/dist/mcp-app-entry-BA-Ca39z.d.ts +1480 -0
- package/dist/mcp-app-entry-tybABaHg.d.cts +1480 -0
- package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
- package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
- package/dist/mcp-app-sandbox.cjs +323 -0
- package/dist/mcp-app-sandbox.cjs.map +1 -0
- package/dist/mcp-app-sandbox.d.cts +70 -0
- package/dist/mcp-app-sandbox.d.ts +70 -0
- package/dist/mcp-app-sandbox.js +209 -0
- package/dist/mcp-app-sandbox.js.map +1 -0
- package/dist/mcp-app.cjs +980 -0
- package/dist/mcp-app.cjs.map +1 -0
- package/dist/mcp-app.d.cts +3 -0
- package/dist/mcp-app.d.ts +3 -0
- package/dist/mcp-app.js +816 -0
- package/dist/mcp-app.js.map +1 -0
- package/dist/pipeline.cjs +845 -0
- package/dist/pipeline.cjs.map +1 -0
- package/dist/pipeline.css +1407 -0
- package/dist/pipeline.d.cts +348 -0
- package/dist/pipeline.d.ts +348 -0
- package/dist/pipeline.js +778 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/styles.css +4109 -0
- package/dist/types-BmvgYUzF.d.cts +19 -0
- package/dist/types-Cr5gmUts.d.ts +19 -0
- package/package.json +182 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp-app.ts"],"sourcesContent":["import { mcpAppOrigin, type McpAppCsp } from '@dudko.dev/agent-web'\nimport { cspMetaTag, escapeAttribute, withPolicyFirst } from './html-preview.js'\nimport {\n isMcpAppSandboxMessage,\n MCP_APP_SANDBOX_PROXY_READY,\n MCP_APP_SANDBOX_RESOURCE_READY,\n MCP_APP_SCHEME_PARAM,\n mcpAppColorScheme,\n mcpAppPolicy,\n mcpAppPolicyToken,\n type McpAppColorScheme,\n} from './mcp-app-policy.js'\nimport type { AppView, ApprovalView } from './types.js'\n\n/**\n * MCP Apps, the host's side: the security core of `<McpAppFrame>`, as pure code - no React, no\n * DOM - so every guard is unit-tested (`tests/apps.test.ts`) and proved in a real browser\n * (`e2e/apps.spec.ts`).\n *\n * The frame: an app is third-party HTML WITH scripts that must talk to the page, so it gets the\n * HTML preview's boundary (`html-preview.ts`) and one addition, a relay:\n *\n * 1. The outer `<iframe sandbox=\"allow-scripts\">` (never `allow-same-origin`): an opaque origin,\n * no access to the page's DOM, storage, IndexedDB (the key vault) or cookies; no top\n * navigation, popups, forms, modals, downloads. No `allow` attribute: no camera, microphone,\n * geolocation or clipboard, whatever the app asked for.\n * 2. It holds a SHELL of ours (`buildMcpAppDocument`): the policy built from the resource's\n * declared origins and nothing else (`mcpAppCsp`), one inner frame - the app, also\n * `sandbox=\"allow-scripts\"`, with the same policy first in its own document - and a relay\n * script. The shell's `frame-src 'none'` is what stops the app navigating itself (a frame\n * may always navigate itself; only the EMBEDDING document's policy decides where to).\n * 3. The relay forwards messages between the page and the app, and nothing else: from the\n * app's window to the page, from the page to the app's window, never the\n * `ui/notifications/sandbox-*` messages the specification reserves. The app talks to\n * `window.parent` as the extension's SDK does; the page accepts messages only from the outer\n * frame (`event.source`), so the app writing to `window.top` directly is ignored.\n * 4. The bridge (`McpAppBridge`) answers the app: a method allow-list, checked parameters, a\n * cap on requests in flight, and every request that DOES something (a tool call, a link, a\n * message) handed to the host, which asks the user.\n *\n * That is the default. Opt-in, the app runs on an origin of its own instead, behind a sandbox\n * page the host serves on another origin (the specification's \"sandbox proxy\"): 1 - 3 change\n * (see \"An app on an origin of its own\" below and `mcp-app-policy.ts`), 4 does not.\n */\n\n/** The revision of the extension this host speaks. */\nexport const MCP_APP_PROTOCOL_VERSION = '2026-01-26'\n\n/** An app's frame height, before it says how tall it is. */\nexport const APP_DEFAULT_HEIGHT = 360\n/**\n * The frame's height is the host's: the app's wish, clamped to `APP_MIN_HEIGHT` .. the cap. The\n * cap is `appHeightCap` of the chat's visible height - a few screens, never less than\n * `APP_MAX_HEIGHT` - so an app as tall as its content has no scroller of its own inside the\n * transcript (one scroller: the chat's), and an app that grows forever stops there.\n */\nexport const APP_MIN_HEIGHT = 120\n/** The least the cap is (and the cap where nothing says how tall the chat is). */\nexport const APP_MAX_HEIGHT = 800\n/** The cap is this many of the chat's visible heights. */\nexport const APP_HEIGHT_SCREENS = 3\n/** ... and never more than this, whatever the screen. */\nexport const APP_HEIGHT_CEILING = 6000\n\n/**\n * The tallest an inline app's frame is drawn, for a chat body (or viewport) `viewHeight` px tall:\n * `APP_HEIGHT_SCREENS` of it, rounded down to 100 px (the app is told it in\n * `containerDimensions.maxHeight`, and a resize of a few pixels must not tell it again), at least\n * `APP_MAX_HEIGHT`, at most `APP_HEIGHT_CEILING`.\n */\nexport const appHeightCap = (viewHeight: number | undefined): number => {\n if (typeof viewHeight !== 'number' || !Number.isFinite(viewHeight) || viewHeight <= 0) {\n return APP_MAX_HEIGHT\n }\n const screens = Math.floor((viewHeight * APP_HEIGHT_SCREENS) / 100) * 100\n return Math.min(APP_HEIGHT_CEILING, Math.max(APP_MAX_HEIGHT, screens))\n}\n\n/**\n * The cap of a frame that is already drawn, when the chat's height changes: `appHeightCap` of the\n * new height, but never less than the cap the frame had (`current`) - a rotation, a keyboard\n * resizing the page or a relayout for a touch screen must not give an app that was drawn whole a\n * scroller of its own. The cap only grows while the frame is shown (at most\n * `APP_HEIGHT_CEILING`); a new frame starts from the cap of its moment.\n */\nexport const nextAppHeightCap = (current: number, viewHeight: number | undefined): number => {\n const now = appHeightCap(viewHeight)\n return Number.isFinite(current) && current > now ? Math.min(APP_HEIGHT_CEILING, current) : now\n}\n\n/** At most this many requests of one app wait at once (tool calls, links, messages). */\nexport const MCP_APP_MAX_IN_FLIGHT = 3\n/** A message an app puts in the chat: at most this many characters. */\nexport const MCP_APP_MAX_MESSAGE_CHARS = 4000\n/** A link an app asks to open: at most this many characters. */\nexport const MCP_APP_MAX_URL_CHARS = 2048\n/** The arguments of a tool call an app makes: at most this many characters as JSON. */\nexport const MCP_APP_MAX_ARGS_CHARS = 64_000\n\n/** An app's wish for a height, as the frame draws it: within `APP_MIN_HEIGHT` .. `max` (the cap). */\nexport const clampAppHeight = (height: number, max: number = APP_MAX_HEIGHT): number =>\n Math.min(\n Math.max(\n APP_MIN_HEIGHT,\n Math.min(APP_HEIGHT_CEILING, Number.isFinite(max) ? max : APP_MAX_HEIGHT),\n ),\n Math.max(APP_MIN_HEIGHT, Math.round(Number.isFinite(height) ? height : APP_DEFAULT_HEIGHT)),\n )\n\n/** The declared origins of a list that are origins (re-checked here: whoever built the object). */\nconst origins = (list: readonly string[] | undefined): string[] => {\n const out: string[] = []\n for (const entry of list ?? []) {\n const origin = mcpAppOrigin(entry)\n if (origin && !out.includes(origin)) out.push(origin)\n }\n return out\n}\n\n/**\n * The policy of an app's document: scripts and styles inline, `data:` / `blob:` media, and the\n * network ONLY where the resource declared it - `connectDomains` for `fetch` / XHR / WebSocket,\n * `resourceDomains` for scripts, styles, images, fonts and media. Nothing declared, nothing\n * reached. Nested frames, workers, plugins, forms and `<base>` are refused whatever was declared\n * (`frameDomains` / `baseUriDomains` are not granted: a frame the app may embed would also be a\n * place it may navigate itself to). Each entry is checked again with the core's `mcpAppOrigin`.\n */\nexport const mcpAppCsp = (csp?: Partial<McpAppCsp>): string =>\n mcpAppPolicy({ connect: origins(csp?.connectDomains), resources: origins(csp?.resourceDomains) })\n\n/** The origins the policy actually grants: what the app is told in `hostCapabilities.sandbox`. */\nexport const grantedAppCsp = (\n csp?: Partial<McpAppCsp>,\n): { connectDomains: string[]; resourceDomains: string[] } => ({\n connectDomains: origins(csp?.connectDomains),\n resourceDomains: origins(csp?.resourceDomains),\n})\n\n/**\n * The relay of the shell: the app's messages to the page, the page's to the app - matched by\n * `event.source`, never by anything the message says - and not the reserved\n * `ui/notifications/sandbox-*` ones. It reads nothing else and runs nothing it is sent.\n */\nexport const MCP_APP_RELAY =\n \"(function(){var f=document.getElementById('app');\" +\n \"function reserved(d){return !!d&&typeof d.method==='string'&&d.method.indexOf('ui/notifications/sandbox-')===0}\" +\n \"addEventListener('message',function(e){var w=f&&f.contentWindow;if(!w||reserved(e.data))return;\" +\n \"if(e.source===w){parent.postMessage(e.data,'*')}else if(e.source===parent){w.postMessage(e.data,'*')}})})()\"\n\n/**\n * What a document of ours between the page and the app says about its colour scheme: the\n * `color-scheme` meta and the same on `:root` and on its frame element, so the document, its\n * frame and (for an app that declares the same) the app agree and no canvas is painted opaque\n * between them. Nothing for anything but `light` / `dark`.\n */\nconst schemeMeta = (scheme: McpAppColorScheme | undefined): string =>\n scheme ? `<meta name=\"color-scheme\" content=\"${scheme}\">` : ''\nconst schemeCss = (scheme: McpAppColorScheme | undefined): string =>\n scheme ? `:root{color-scheme:${scheme}}` : ''\nconst schemeOfFrame = (scheme: McpAppColorScheme | undefined): string =>\n scheme ? `;color-scheme:${scheme}` : ''\n\n/**\n * What goes into the OUTER frame's `srcdoc`: the shell (the app's policy first, one inner frame\n * that fills it, the relay) carrying the app, escaped, as the inner frame's `srcdoc` - with the\n * same policy first in it. Give the outer `<iframe>` `sandbox=\"allow-scripts\"` and nothing else.\n * `scheme` (the theme the app is told) is declared by the shell and its inner frame; give the\n * outer `<iframe>` the same `color-scheme`. Only `light` / `dark` are declared.\n */\nexport const buildMcpAppDocument = (\n html: string,\n csp?: Partial<McpAppCsp>,\n scheme?: McpAppColorScheme,\n): string => {\n const policy = mcpAppCsp(csp)\n const s = mcpAppColorScheme(scheme)\n return (\n '<!doctype html><html><head>' +\n `<meta http-equiv=\"Content-Security-Policy\" content=\"${escapeAttribute(policy)}\">` +\n schemeMeta(s) +\n `<style>${schemeCss(s)}html,body{margin:0;height:100%;overflow:hidden;background:transparent}` +\n `iframe{display:block;border:0;width:100%;height:100%${schemeOfFrame(s)}}</style></head><body>` +\n `<iframe id=\"app\" sandbox=\"allow-scripts\" referrerpolicy=\"no-referrer\" ` +\n `srcdoc=\"${escapeAttribute(withPolicyFirst(html, policy))}\"></iframe>` +\n `<script>${MCP_APP_RELAY}</script></body></html>`\n )\n}\n\n/** A link an app asks to open, taken apart for the prompt: the host is what the user checks. */\nexport interface AppLink {\n /** The normalised URL (what is opened). */\n href: string\n /** `https://` */\n scheme: string\n /** The host (and port), as the browser will go there - an internationalised name in punycode. */\n host: string\n /** Everything after the host. */\n rest: string\n}\n\n/** An `http(s)` URL with a host and no credentials, at most `MCP_APP_MAX_URL_CHARS`; else none. */\nexport const appLinkOf = (value: unknown): AppLink | undefined => {\n if (typeof value !== 'string' || value.length > MCP_APP_MAX_URL_CHARS) return undefined\n let url: URL\n try {\n url = new URL(value)\n } catch {\n return undefined\n }\n if (url.protocol !== 'https:' && url.protocol !== 'http:') return undefined\n if (url.username || url.password || !url.hostname) return undefined\n const scheme = `${url.protocol}//`\n return {\n href: url.href,\n scheme,\n host: url.host,\n rest: url.href.slice(scheme.length + url.host.length),\n }\n}\n\n// Characters that change how text reads without being seen (bidirectional overrides,\n// zero-width) and control characters other than line breaks and tabs.\n// eslint-disable-next-line no-control-regex\nconst HIDDEN = /[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f---]/g\n\n/**\n * The text of a `ui/message` an app sends: text blocks only (one, or a list of at most 20),\n * joined, without invisible characters, at most `MCP_APP_MAX_MESSAGE_CHARS`. Anything else -\n * an image, a resource, an empty or a longer text - is refused (`undefined`).\n */\nexport const appMessageTextOf = (content: unknown): string | undefined => {\n const blocks = Array.isArray(content) ? content : content === undefined ? [] : [content]\n if (blocks.length === 0 || blocks.length > 20) return undefined\n const texts: string[] = []\n for (const block of blocks) {\n if (!isObject(block) || block.type !== 'text' || typeof block.text !== 'string') {\n return undefined\n }\n texts.push(block.text)\n }\n const text = texts.join('\\n\\n').replace(HIDDEN, '').trim()\n return text && text.length <= MCP_APP_MAX_MESSAGE_CHARS ? text : undefined\n}\n\ntype Obj = Record<string, unknown>\nconst isObject = (value: unknown): value is Obj =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** A JSON-RPC message as the bridge sends it. */\nexport type McpAppRpcMessage =\n | { jsonrpc: '2.0'; id: string | number; method: string; params?: unknown }\n | { jsonrpc: '2.0'; method: string; params?: unknown }\n | { jsonrpc: '2.0'; id: string | number; result: unknown }\n | { jsonrpc: '2.0'; id: string | number; error: { code: number; message: string } }\n\n/** The requests an app may make of this host. Any other is answered \"method not found\". */\nexport const MCP_APP_REQUESTS = [\n 'ui/initialize',\n 'ping',\n 'tools/call',\n 'ui/open-link',\n 'ui/message',\n 'ui/request-display-mode',\n] as const\n/**\n * Requests answered only when the host turned the feature on (`downloadFile` / `sampling` in\n * `hostCapabilities`, a handler given to the bridge); otherwise \"method not found\", as before.\n */\nexport const MCP_APP_OPTIONAL_REQUESTS = ['ui/download-file', 'sampling/createMessage'] as const\n/** The notifications this host reads. Any other is dropped. */\nexport const MCP_APP_NOTIFICATIONS = [\n 'ui/notifications/initialized',\n 'ui/notifications/size-changed',\n] as const\n\n/** An error the bridge answers with: a JSON-RPC code and a message for the app. */\nexport class McpAppRpcError extends Error {\n constructor(\n readonly code: number,\n message: string,\n ) {\n super(message)\n this.name = 'McpAppRpcError'\n }\n}\n\nconst METHOD_NOT_FOUND = -32601\nconst INVALID_PARAMS = -32602\nconst INVALID_REQUEST = -32600\n/** The host refused: the user said no, too many requests, not initialized. */\nexport const MCP_APP_REFUSED = -32000\n\n/** How an app is shown (`hostContext.displayMode`). This host offers `inline` and `fullscreen`. */\nexport type McpAppDisplayMode = 'inline' | 'fullscreen' | 'pip'\n/** The modes the extension names (a request for any other is invalid). */\nexport const MCP_APP_DISPLAY_MODES: readonly McpAppDisplayMode[] = ['inline', 'fullscreen', 'pip']\n\n/** A file an app asks the host to save (`ui/download-file`), as checked by `appDownloadOf`. */\nexport type AppDownload =\n | {\n kind: 'embedded'\n /** The file name, sanitized (`appFileNameOf`): what it is saved as. */\n name: string\n /** The type the app declared, if it is a MIME type at all. */\n mimeType?: string\n bytes: Uint8Array\n }\n | {\n /** A `resource_link`: read with `resources/read` on the app's own server, never fetched. */\n kind: 'link'\n uri: string\n name: string\n mimeType?: string\n }\n\n/** What the host does for an app (the user is asked inside these, never by the bridge). */\nexport interface McpAppBridgeHandlers {\n /** A `tools/call`: resolves with the result the app is given; throws when refused. */\n callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>\n /** A link (already checked): resolves true when it was opened, false when the user said no. */\n openLink: (link: AppLink) => Promise<boolean>\n /** A message (already cleaned): resolves true when it was accepted, false when not. */\n message: (text: string) => Promise<boolean>\n /** The app's wish for a height (the caller clamps it). */\n resize: (height: number) => void\n /**\n * `ui/request-display-mode` for a mode the host offers and the app declared (or `inline`):\n * the mode the app is in afterwards - the host may say no and answer the current one.\n * Without it, an app stays where it is.\n */\n displayMode?: (mode: McpAppDisplayMode) => McpAppDisplayMode | Promise<McpAppDisplayMode>\n /**\n * `ui/download-file` (already checked): true once the file was saved, false when the user said\n * no. Without it the method is not offered (`hostCapabilities.downloadFile` absent).\n */\n downloadFile?: (file: AppDownload) => Promise<boolean>\n /**\n * `sampling/createMessage`: the result for the app; throws (an `McpAppRpcError`) when refused.\n * Without it the method is not offered (`hostCapabilities.sampling` absent).\n */\n sample?: (params: Record<string, unknown>) => Promise<unknown>\n}\n\nexport interface McpAppBridgeOptions {\n /** Send a message to the app (the page posts it to the outer frame). */\n post: (message: McpAppRpcMessage) => void\n handlers: McpAppBridgeHandlers\n hostInfo: { name: string; version: string }\n hostCapabilities: Record<string, unknown>\n hostContext: Record<string, unknown>\n /** The tool call's arguments: sent once the app says it is initialized. */\n toolInput: Record<string, unknown>\n /** Its result; `undefined` = the app is told the call was cancelled (`reason`). */\n toolResult?: unknown\n cancelledReason?: string\n maxInFlight?: number\n}\n\nconst validId = (id: unknown): id is string | number =>\n (typeof id === 'string' && id.length > 0 && id.length <= 100) ||\n (typeof id === 'number' && Number.isFinite(id))\n\n/**\n * One app's conversation with the host (the extension's JSON-RPC over `postMessage`). It never\n * touches the DOM: `receive` is given what arrived - from the right frame, the caller checked\n * `event.source` - and `post` sends. Requests outside the allow-list get \"method not found\";\n * before `ui/initialize`, only `ping` is answered; parameters are checked before a handler sees\n * them; at most `maxInFlight` requests run at once. The tool's input and result are sent once,\n * after the app's `ui/notifications/initialized`, as the specification requires.\n */\nexport class McpAppBridge {\n private readonly o: McpAppBridgeOptions\n private initializeSeen = false\n private delivered = false\n private inFlight = 0\n private closed = false\n private seq = 0\n // The display modes the app declared at `ui/initialize` (undefined: none declared).\n private appModes: McpAppDisplayMode[] | undefined\n\n constructor(options: McpAppBridgeOptions) {\n this.o = options\n }\n\n /** The app said it is ready, and was given the tool's input and result. */\n get initialized(): boolean {\n return this.delivered\n }\n\n /** Stop answering: the frame is gone or was reloaded. */\n close(): void {\n this.closed = true\n }\n\n /** Tell the app it is being torn down (not waited for: the frame goes anyway). */\n teardown(reason: string): void {\n if (!this.delivered || this.closed) return\n this.seq += 1\n this.send({\n jsonrpc: '2.0',\n id: `host-teardown-${this.seq}`,\n method: 'ui/resource-teardown',\n params: { reason },\n })\n }\n\n /** The display modes the app declared at `ui/initialize` (undefined: none, or not yet). */\n get appDisplayModes(): readonly McpAppDisplayMode[] | undefined {\n return this.appModes ? [...this.appModes] : undefined\n }\n\n /** How the app is shown now (`hostContext.displayMode`). */\n get displayMode(): McpAppDisplayMode {\n const mode = this.o.hostContext.displayMode\n return MCP_APP_DISPLAY_MODES.includes(mode as McpAppDisplayMode)\n ? (mode as McpAppDisplayMode)\n : 'inline'\n }\n\n /** Tell an initialized app that part of the host context changed (the theme). */\n updateContext(patch: Record<string, unknown>): void {\n Object.assign(this.o.hostContext, patch)\n if (this.delivered && !this.closed) {\n this.send({ jsonrpc: '2.0', method: 'ui/notifications/host-context-changed', params: patch })\n }\n }\n\n /** One message from the app's frame. */\n receive(data: unknown): void {\n if (this.closed || !isObject(data) || data.jsonrpc !== '2.0') return\n const method = data.method\n const id = data.id\n if (method === undefined) return // a response to a request of ours: nothing waits for it\n if (typeof method !== 'string' || method.length === 0 || method.length > 100) {\n if (validId(id)) this.error(id, INVALID_REQUEST, 'Invalid request')\n return\n }\n if (id === undefined) {\n this.notification(method, data.params)\n return\n }\n if (!validId(id)) return\n if (data.params !== undefined && !isObject(data.params)) {\n this.error(id, INVALID_PARAMS, 'params must be an object')\n return\n }\n void this.request(id, method, (data.params ?? {}) as Obj)\n }\n\n private send(message: McpAppRpcMessage): void {\n if (!this.closed) this.o.post(message)\n }\n\n private error(id: string | number, code: number, message: string): void {\n this.send({ jsonrpc: '2.0', id, error: { code, message } })\n }\n\n private notification(method: string, params: unknown): void {\n const p = isObject(params) ? params : {}\n if (method === 'ui/notifications/initialized') {\n if (!this.initializeSeen || this.delivered) return\n this.delivered = true\n this.send({\n jsonrpc: '2.0',\n method: 'ui/notifications/tool-input',\n params: { arguments: this.o.toolInput },\n })\n this.send(\n this.o.toolResult === undefined\n ? {\n jsonrpc: '2.0',\n method: 'ui/notifications/tool-cancelled',\n params: { reason: this.o.cancelledReason ?? 'no result' },\n }\n : { jsonrpc: '2.0', method: 'ui/notifications/tool-result', params: this.o.toolResult },\n )\n return\n }\n if (method === 'ui/notifications/size-changed') {\n if (typeof p.height === 'number' && Number.isFinite(p.height) && p.height > 0) {\n this.o.handlers.resize(p.height)\n }\n }\n // Anything else (a log line, a teardown wish, an unknown one) is dropped.\n }\n\n private async request(id: string | number, method: string, params: Obj): Promise<void> {\n const h = this.o.handlers\n const offered =\n (MCP_APP_REQUESTS as readonly string[]).includes(method) ||\n (method === 'ui/download-file' && typeof h.downloadFile === 'function') ||\n (method === 'sampling/createMessage' && typeof h.sample === 'function')\n if (!offered) {\n this.error(id, METHOD_NOT_FOUND, `Method not found: ${method.slice(0, 60)}`)\n return\n }\n if (method === 'ping') {\n this.send({ jsonrpc: '2.0', id, result: {} })\n return\n }\n if (method === 'ui/initialize') {\n this.initializeSeen = true\n const caps = isObject(params.appCapabilities) ? params.appCapabilities : {}\n this.appModes = Array.isArray(caps.availableDisplayModes)\n ? caps.availableDisplayModes.filter((m): m is McpAppDisplayMode =>\n MCP_APP_DISPLAY_MODES.includes(m as McpAppDisplayMode),\n )\n : undefined\n this.send({\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: MCP_APP_PROTOCOL_VERSION,\n hostInfo: this.o.hostInfo,\n hostCapabilities: this.o.hostCapabilities,\n hostContext: this.o.hostContext,\n },\n })\n return\n }\n if (!this.initializeSeen) {\n this.error(id, MCP_APP_REFUSED, 'The app is not initialized (send ui/initialize first)')\n return\n }\n if (method === 'ui/request-display-mode') {\n const requested = params.mode\n if (!MCP_APP_DISPLAY_MODES.includes(requested as McpAppDisplayMode)) {\n this.error(id, INVALID_PARAMS, 'mode must be \"inline\", \"fullscreen\" or \"pip\"')\n return\n }\n // The host decides where an app is shown, and answers the mode it is in afterwards.\n const current = this.displayMode\n const host = Array.isArray(this.o.hostContext.availableDisplayModes)\n ? (this.o.hostContext.availableDisplayModes as McpAppDisplayMode[])\n : ['inline' as const]\n let mode: McpAppDisplayMode = current\n if (\n h.displayMode &&\n appDisplayModeAllowed({\n requested: requested as McpAppDisplayMode,\n current,\n host,\n app: this.appModes,\n })\n ) {\n try {\n const next = await h.displayMode(requested as McpAppDisplayMode)\n mode = MCP_APP_DISPLAY_MODES.includes(next) ? next : current\n } catch {\n mode = this.displayMode\n }\n }\n this.send({ jsonrpc: '2.0', id, result: { mode } })\n return\n }\n // What remains does something the user is asked about: capped, then handed over.\n let run: (() => Promise<unknown>) | undefined\n if (method === 'tools/call') {\n const name = params.name\n const args = params.arguments === undefined ? {} : params.arguments\n if (typeof name !== 'string' || name.length === 0 || name.length > 128) {\n this.error(id, INVALID_PARAMS, 'tools/call needs the name of a tool')\n return\n }\n if (!isObject(args)) {\n this.error(id, INVALID_PARAMS, 'tools/call arguments must be an object')\n return\n }\n let size = Infinity\n try {\n size = JSON.stringify(args).length\n } catch {\n // not serialisable: refused below\n }\n if (size > MCP_APP_MAX_ARGS_CHARS) {\n this.error(id, INVALID_PARAMS, 'tools/call arguments are too large')\n return\n }\n run = () => this.o.handlers.callTool(name, args)\n } else if (method === 'ui/download-file') {\n const file = appDownloadOf(params)\n if (typeof file === 'string') {\n this.error(id, INVALID_PARAMS, file)\n return\n }\n const save = h.downloadFile!\n // Denied (or not saved): a result with `isError`, as the extension's SDK expects.\n run = async () => ((await save(file)) ? {} : { isError: true })\n } else if (method === 'sampling/createMessage') {\n const sample = h.sample!\n run = () => sample(params)\n } else if (method === 'ui/open-link') {\n const link = appLinkOf(params.url)\n if (!link) {\n this.error(id, INVALID_PARAMS, 'Invalid URL: only http(s) links without credentials')\n return\n }\n run = async () => {\n if (!(await this.o.handlers.openLink(link))) {\n throw new McpAppRpcError(MCP_APP_REFUSED, 'Link opening denied by user')\n }\n return {}\n }\n } else {\n const text = params.role === 'user' ? appMessageTextOf(params.content) : undefined\n if (text === undefined) {\n this.error(\n id,\n INVALID_PARAMS,\n 'Invalid message format: one user text, not empty, not too long',\n )\n return\n }\n run = async () => {\n if (!(await this.o.handlers.message(text))) {\n throw new McpAppRpcError(MCP_APP_REFUSED, 'Message sending denied')\n }\n return {}\n }\n }\n const cap = this.o.maxInFlight ?? MCP_APP_MAX_IN_FLIGHT\n if (this.inFlight >= cap) {\n this.error(id, MCP_APP_REFUSED, 'Too many requests of this app are waiting')\n return\n }\n this.inFlight += 1\n try {\n const result = await run()\n this.send({ jsonrpc: '2.0', id, result })\n } catch (err) {\n const code = err instanceof McpAppRpcError ? err.code : MCP_APP_REFUSED\n const message = (err instanceof Error ? err.message : String(err)).slice(0, 300)\n this.error(id, code, message)\n } finally {\n this.inFlight -= 1\n }\n }\n}\n\n/**\n * What this host tells an app it can do (`hostCapabilities` of `ui/initialize`): only what it\n * does. `downloadFile` and `sampling` (never `sampling.tools`) only when the host turned them on.\n */\nexport const mcpAppHostCapabilities = (\n csp?: Partial<McpAppCsp>,\n features: { downloadFile?: boolean; sampling?: boolean } = {},\n): Record<string, unknown> => ({\n openLinks: {},\n serverTools: {},\n message: { text: {} },\n ...(features.downloadFile ? { downloadFile: {} } : {}),\n ...(features.sampling ? { sampling: {} } : {}),\n // What the frame grants: the declared origins it kept; no permission at all.\n sandbox: { permissions: {}, csp: grantedAppCsp(csp) },\n})\n\n// ── Display modes ───────────────────────────────────────────────────────────────────────────\n\n/**\n * Whether a display mode an app asks for may be given: `inline` always (the way back needs no\n * permission); any other only when the host offers it AND the app declared it in\n * `appCapabilities.availableDisplayModes` - an app that declared nothing stays inline (the\n * specification lets a host decline it).\n */\nexport const appDisplayModeAllowed = (o: {\n requested: McpAppDisplayMode\n current: McpAppDisplayMode\n host: readonly McpAppDisplayMode[]\n app: readonly McpAppDisplayMode[] | undefined\n}): boolean =>\n o.requested === o.current ||\n o.requested === 'inline' ||\n (o.host.includes(o.requested) && (o.app?.includes(o.requested) ?? false))\n\n/**\n * Whether the user just acted INSIDE the app's frame: the page's frame element has the focus\n * (a click or a key in a frame focuses it) and the page has transient user activation (an\n * activation in a frame reaches every page above it, for a few seconds). Where the browser has\n * no `navigator.userActivation`, the focus alone.\n */\nexport const appGestureOf = (o: { focused: boolean; activation: boolean | undefined }): boolean =>\n o.focused && o.activation !== false\n\n// ── Downloads: a file the app hands the host to save ────────────────────────────────────────\n\n/** A file an app asks to save: at most this many bytes. */\nexport const MCP_APP_MAX_DOWNLOAD_BYTES = 20 * 1024 * 1024\n/** A saved file's name: at most this many characters (the extension kept). */\nexport const MCP_APP_MAX_FILE_NAME_CHARS = 100\n\n/**\n * Extensions this host never saves: programs, scripts, installers, shortcuts, disk images - and\n * documents a browser runs scripts in when they are opened (HTML, SVG, XML).\n */\nexport const MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS: readonly string[] = [\n 'exe',\n 'com',\n 'bat',\n 'cmd',\n 'scr',\n 'pif',\n 'msi',\n 'msp',\n 'mst',\n 'msc',\n 'cpl',\n 'dll',\n 'sys',\n 'ps1',\n 'psm1',\n 'psd1',\n 'vbs',\n 'vbe',\n 'js',\n 'jse',\n 'mjs',\n 'cjs',\n 'wsf',\n 'wsh',\n 'ws',\n 'hta',\n 'jar',\n 'jnlp',\n 'lnk',\n 'reg',\n 'inf',\n 'scf',\n 'url',\n 'website',\n 'application',\n 'gadget',\n 'sh',\n 'bash',\n 'zsh',\n 'csh',\n 'ksh',\n 'command',\n 'tool',\n 'app',\n 'pkg',\n 'mpkg',\n 'dmg',\n 'deb',\n 'rpm',\n 'apk',\n 'xapk',\n 'appimage',\n 'run',\n 'bin',\n 'elf',\n 'out',\n 'py',\n 'pyw',\n 'pyz',\n 'pl',\n 'rb',\n 'php',\n 'html',\n 'htm',\n 'xhtml',\n 'xht',\n 'shtml',\n 'mht',\n 'mhtml',\n 'svg',\n 'svgz',\n 'xml',\n 'xsl',\n 'xslt',\n 'webloc',\n 'desktop',\n 'iso',\n 'img',\n 'vhd',\n 'vhdx',\n 'library-ms',\n 'settingcontent-ms',\n]\n\n/** Types this host never saves (the same kinds), and any `…+xml`. */\nexport const MCP_APP_REFUSED_DOWNLOAD_TYPES: readonly string[] = [\n 'text/html',\n 'application/xhtml+xml',\n 'image/svg+xml',\n 'application/xml',\n 'text/xml',\n 'text/javascript',\n 'application/javascript',\n 'application/ecmascript',\n 'application/x-javascript',\n 'application/x-msdownload',\n 'application/x-msdos-program',\n 'application/x-msi',\n 'application/x-ms-installer',\n 'application/vnd.microsoft.portable-executable',\n 'application/x-executable',\n 'application/x-elf',\n 'application/x-sh',\n 'application/x-shellscript',\n 'application/x-csh',\n 'application/java-archive',\n 'application/x-java-jnlp-file',\n 'application/hta',\n 'application/x-apple-diskimage',\n 'application/vnd.android.package-archive',\n 'application/x-python-code',\n 'text/x-python',\n 'application/x-httpd-php',\n]\n\nconst MIME = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/\n\n/** A declared type as a bare MIME type (`text/plain`), or undefined when it is not one. */\nexport const appMimeTypeOf = (value: unknown): string | undefined => {\n if (typeof value !== 'string') return undefined\n const type = value.split(';')[0]!.trim().toLowerCase()\n return MIME.test(type) ? type : undefined\n}\n\n// Device names Windows will not let a file be called (with any extension).\nconst RESERVED_NAME = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\\..*)?$/i\n\n/**\n * The name a file is saved under: the last segment of a path or URI (`file:///x/report.json` →\n * `report.json`; percent-encoding decoded, and split again), without what cannot be seen or\n * reserved characters (`<>:\"/\\|?*`, controls), no leading dots (a hidden file) or trailing dots\n * and spaces, not a Windows device name, at most `MCP_APP_MAX_FILE_NAME_CHARS` with the extension\n * kept; `download` when nothing is left.\n */\nexport const appFileNameOf = (value: unknown): string => {\n let name = typeof value === 'string' ? value.slice(0, 2048) : ''\n name = name.replace(/[?#].*$/s, '')\n name = name.split(/[\\\\/]/).pop() ?? ''\n try {\n name = decodeURIComponent(name)\n } catch {\n // not percent-encoded: as it is\n }\n name = (name.split(/[\\\\/]/).pop() ?? '')\n .replace(HIDDEN, '')\n // eslint-disable-next-line no-control-regex\n .replace(/[<>:\"|?*\\u0000-\\u001f\\u007f]/g, '_')\n .replace(/\\s+/g, ' ')\n .replace(/^[.\\s]+/, '')\n .replace(/[.\\s]+$/, '')\n if (RESERVED_NAME.test(name)) name = `_${name}`\n if (name.length > MCP_APP_MAX_FILE_NAME_CHARS) {\n const dot = name.lastIndexOf('.')\n const ext = dot > 0 && name.length - dot <= 16 ? name.slice(dot) : ''\n name = name.slice(0, MCP_APP_MAX_FILE_NAME_CHARS - ext.length).replace(/[.\\s]+$/, '') + ext\n }\n return name || 'download'\n}\n\n/** The extension of a (sanitized) file name, lowercased, without the dot; '' when none. */\nexport const appFileExtensionOf = (name: string): string => {\n const dot = name.lastIndexOf('.')\n return dot > 0 ? name.slice(dot + 1).toLowerCase() : ''\n}\n\n/**\n * Why a file may not be saved, or undefined when it may: an extension or a type of the refused\n * lists (a program, a script, a page a browser would run), checked on the sanitized name and\n * the declared type both.\n */\nexport const appDownloadRefusal = (name: string, mimeType?: string): string | undefined => {\n const ext = appFileExtensionOf(name)\n if (MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS.includes(ext)) return `“.${ext}” files are not saved`\n const type = appMimeTypeOf(mimeType)\n if (type && (MCP_APP_REFUSED_DOWNLOAD_TYPES.includes(type) || type.endsWith('+xml'))) {\n return `${type} files are not saved`\n }\n return undefined\n}\n\nconst URI_LINE = /^[^\\u0000-\\u001f\\u007f\\s]{1,2048}$/\n\nconst bytesOfBase64 = (blob: string, maxBytes: number): Uint8Array | string => {\n if (blob.length > Math.ceil((maxBytes * 4) / 3) + 4)\n return `the file is larger than ${maxBytes} bytes`\n if (!/^[A-Za-z0-9+/\\s]*={0,2}\\s*$/.test(blob)) return 'blob must be base64'\n try {\n const binary = atob(blob.replace(/\\s+/g, ''))\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i)\n return bytes\n } catch {\n return 'blob must be base64'\n }\n}\n\n/**\n * What `ui/download-file` asks for, checked - or why not (a message for the app): ONE item of\n * `contents` (one file per request, one prompt); an `EmbeddedResource` (`resource.uri` names\n * it, `text` as UTF-8 or base64 `blob`, at most `maxBytes`) or a `ResourceLink` (a one-line URI,\n * read later from the app's own server: the name is its last segment, else its `name`); the\n * name sanitized and the name and type not refused (`appDownloadRefusal`).\n */\nexport const appDownloadOf = (\n params: unknown,\n maxBytes: number = MCP_APP_MAX_DOWNLOAD_BYTES,\n): AppDownload | string => {\n const contents = isObject(params) ? params.contents : undefined\n if (!Array.isArray(contents) || contents.length === 0) return 'contents must list the file'\n if (contents.length > 1) return 'One file per request'\n const item = contents[0]\n if (!isObject(item)) return 'Invalid content'\n if (item.type === 'resource') {\n const r = item.resource\n if (!isObject(r) || typeof r.uri !== 'string' || !URI_LINE.test(r.uri)) {\n return 'Invalid content: resource.uri names the file'\n }\n const name = appFileNameOf(r.uri)\n const mimeType = appMimeTypeOf(r.mimeType)\n const refused = appDownloadRefusal(name, mimeType)\n if (refused) return `Policy violation: ${refused}`\n let bytes: Uint8Array | string\n if (typeof r.text === 'string') {\n bytes =\n r.text.length > maxBytes\n ? `the file is larger than ${maxBytes} bytes`\n : new TextEncoder().encode(r.text)\n } else if (typeof r.blob === 'string') {\n bytes = bytesOfBase64(r.blob, maxBytes)\n } else {\n return 'Invalid content: text or blob'\n }\n if (typeof bytes === 'string') return `Invalid content: ${bytes}`\n if (bytes.length > maxBytes) return `Invalid content: the file is larger than ${maxBytes} bytes`\n return { kind: 'embedded', name, ...(mimeType ? { mimeType } : {}), bytes }\n }\n if (item.type === 'resource_link') {\n if (typeof item.uri !== 'string' || !URI_LINE.test(item.uri)) {\n return 'Invalid content: a resource_link needs a URI'\n }\n const fromUri = appFileNameOf(item.uri)\n const name =\n fromUri !== 'download' || typeof item.name !== 'string' ? fromUri : appFileNameOf(item.name)\n const mimeType = appMimeTypeOf(item.mimeType)\n const refused = appDownloadRefusal(name, mimeType)\n if (refused) return `Policy violation: ${refused}`\n return { kind: 'link', uri: item.uri, name, ...(mimeType ? { mimeType } : {}) }\n }\n return 'Invalid content: a resource or a resource_link'\n}\n\n/** A file ready to be put to the user: its name, type, bytes, and where the bytes came from. */\nexport interface AppReadyDownload {\n name: string\n mimeType?: string\n bytes: Uint8Array\n source: 'embedded' | 'link'\n}\n\n/** How a linked file is read: `resources/read` on the app's OWN server (the connection's). */\nexport type AppResourceReader = (\n server: string,\n uri: string,\n options: { signal?: AbortSignal; maxBytes: number },\n) => Promise<{ mimeType?: string; bytes: Uint8Array }>\n\n/**\n * The bytes of a checked file: an embedded one as it came; a linked one read from `server` -\n * the app's own - through `read` (never a fetch of its URI), at most `maxBytes`, and the type the\n * SERVER gives it judged again (an app cannot pass a page off as a text file through a link).\n * Throws an `McpAppRpcError` for the app: no reader, a failed read, a refused type, too large.\n */\nexport const resolveAppDownload = async (\n file: AppDownload,\n server: string,\n read: AppResourceReader | undefined,\n signal?: AbortSignal,\n maxBytes: number = MCP_APP_MAX_DOWNLOAD_BYTES,\n): Promise<AppReadyDownload> => {\n if (file.kind === 'embedded') {\n return {\n name: file.name,\n ...(file.mimeType ? { mimeType: file.mimeType } : {}),\n bytes: file.bytes,\n source: 'embedded',\n }\n }\n if (!read) throw new McpAppRpcError(MCP_APP_REFUSED, 'This host cannot read a linked file')\n let got: { mimeType?: string; bytes: Uint8Array }\n try {\n got = await read(server, file.uri, { ...(signal ? { signal } : {}), maxBytes })\n } catch (err) {\n const why = err instanceof Error ? err.message : String(err)\n throw new McpAppRpcError(MCP_APP_REFUSED, `Invalid content: ${why.slice(0, 200)}`)\n }\n if (!(got?.bytes instanceof Uint8Array)) {\n throw new McpAppRpcError(MCP_APP_REFUSED, 'Invalid content: no bytes')\n }\n if (got.bytes.length > maxBytes) {\n throw new McpAppRpcError(INVALID_PARAMS, `Invalid content: larger than ${maxBytes} bytes`)\n }\n const mimeType = appMimeTypeOf(got.mimeType) ?? file.mimeType\n const refused = appDownloadRefusal(file.name, mimeType)\n if (refused) throw new McpAppRpcError(INVALID_PARAMS, `Policy violation: ${refused}`)\n return { name: file.name, ...(mimeType ? { mimeType } : {}), bytes: got.bytes, source: 'link' }\n}\n\n/**\n * The error an app is told when the agent did not answer its sampling request: the core's\n * `AppSamplingError` carries its JSON-RPC code (`-1`: the user said no, `-32602`: not a request\n * this host takes, `-32000`: too many); anything else is a refusal.\n */\nexport const appSamplingErrorOf = (err: unknown): McpAppRpcError => {\n if (err instanceof McpAppRpcError) return err\n const rpc = (err as { rpcCode?: unknown } | null)?.rpcCode\n const message = (err instanceof Error ? err.message : String(err)).slice(0, 300)\n return err instanceof Error && err.name === 'AppSamplingError' && typeof rpc === 'number'\n ? new McpAppRpcError(rpc, message)\n : new McpAppRpcError(MCP_APP_REFUSED, message)\n}\n\n/** What `saveAppFile` uses of the page (passed in: this module touches no DOM by itself). */\nexport interface AppFileSaverEnv {\n document: { createElement: (tag: 'a') => HTMLAnchorElement; body: { append: (n: Node) => void } }\n URL: { createObjectURL: (blob: Blob) => string; revokeObjectURL: (url: string) => void }\n setTimeout: (fn: () => void, ms: number) => unknown\n}\n\n/**\n * Save a checked file the user agreed to: a `Blob` of type `application/octet-stream` (the\n * browser never renders or sniffs it as a page), a `blob:` URL of THIS page, an `<a download>`\n * made here and clicked once. No navigation, no `data:` or `javascript:` URL, nothing of the app\n * in the page; the URL is revoked a minute later.\n */\nexport const saveAppFile = (\n file: { name: string; bytes: Uint8Array },\n env: AppFileSaverEnv,\n): void => {\n const blob = new Blob([file.bytes as BlobPart], { type: 'application/octet-stream' })\n const url = env.URL.createObjectURL(blob)\n const a = env.document.createElement('a')\n a.href = url\n a.download = appFileNameOf(file.name)\n a.rel = 'noopener'\n a.style.display = 'none'\n env.document.body.append(a)\n a.click()\n a.remove()\n env.setTimeout(() => env.URL.revokeObjectURL(url), 60_000)\n}\n\n// ── An app on an origin of its own: the sandbox proxy (opt-in) ──────────────────────────────\n//\n// The specification's web-host model: the app is not framed by a `srcdoc` of ours but by a page\n// the host serves on ANOTHER origin (`./mcp-app-sandbox`), so the app gets that origin - storage,\n// cookies, a real `Origin` on its requests - and never the page's. From the page down:\n//\n// your page ── <iframe sandbox=\"allow-scripts allow-same-origin\" srcdoc=SHELL> (your origin)\n// SHELL: no script (`script-src 'none'`); `frame-src` = the proxy's exact URL\n// └─ <iframe sandbox=\"allow-scripts allow-same-origin\" src=PROXY> (the sandbox origin)\n// PROXY: the app's policy as a header; relays messages\n// └─ the app, written into a frame of the proxy (the sandbox origin)\n//\n// The app is same-origin with the proxy and can reach into it - make it navigate, run code in it.\n// So the guards are what the app cannot reach: the frames' sandbox flags (drawn on YOUR side,\n// cross-origin to the app), the shell's `frame-src`, which pins the proxy's frame to its one URL\n// (any other navigation of it is refused, so nothing leaves for an origin the app did not\n// declare), the policy in that URL's PATH (which the pin covers; a query would not be), and the\n// page's checks below: messages only from the proxy's window AND the sandbox origin, posted to\n// that origin only, one handshake. A second `sandbox-proxy-ready` means the proxy was loaded again\n// - by the app - and the app is stopped. Without a sandbox URL, or when its page does not answer,\n// the app runs in the opaque frame above: the stricter of the two.\n\n/** `<AgentChat appSandbox>` / `useMcpAppHost({ sandbox })`. */\nexport interface McpAppSandboxOptions {\n /**\n * The sandbox page's base URL on another origin you serve (`mcpAppSandboxResponse` of the\n * `./mcp-app-sandbox` entry), e.g. `https://apps.example.com/sandbox/v1`; an app's frame loads\n * `<url>/<policy>`. `{server}` in the host name gives each server an origin of its own\n * (`https://{server}.apps.example.com/sandbox/v1`; the server's name must be a DNS label - it\n * needs a wildcard certificate). `https://` only; `http://` on `localhost` / `127.0.0.1`.\n */\n url: string\n /** How long a frame waits for the page's handshake before it falls back (default 5000 ms). */\n timeoutMs?: number\n}\n\n/** Why an app runs in the opaque frame although a sandbox URL is set. */\nexport type McpAppSandboxReason =\n | 'invalid'\n | 'insecure'\n | 'same-origin'\n | 'no-page-origin'\n | 'server-name'\n | 'too-many-origins'\n | 'no-answer'\n\nexport type McpAppSandboxTarget =\n { ok: true; origin: string; base: string } | { ok: false; reason: McpAppSandboxReason }\n\n/** The placeholder for the server's name in `McpAppSandboxOptions.url`. */\nexport const MCP_APP_SANDBOX_SERVER = '{server}'\nexport const MCP_APP_SANDBOX_TIMEOUT_MS = 5000\n/** After the shell has loaded (the proxy loaded or failed), the handshake gets this much longer. */\nexport const MCP_APP_SANDBOX_GRACE_MS = 1000\n/**\n * The sandbox flags of the shell's frame and of the proxy's: scripts and an origin - the shell\n * must keep YOUR origin (else the proxy below it would get an opaque one) and runs no script; the\n * proxy is on the sandbox origin. Nothing else: no navigation, popup, form, modal, download.\n */\nexport const MCP_APP_SANDBOX_FRAME_TOKENS = 'allow-scripts allow-same-origin'\n\nconst DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/\n// CSP cannot name an IPv6 literal (`[::1]`): the proxy's frame could not be pinned.\nconst LOOPBACK_HOSTS = ['localhost', '127.0.0.1']\n// What a `frame-src` source expression's path may hold, and a URL keeps as it is.\nconst SAFE_PATH = /^\\/[A-Za-z0-9\\-._~/%]*$/\n\nconst no = (reason: McpAppSandboxReason): McpAppSandboxTarget => ({ ok: false, reason })\n\n/**\n * Where an app of `server` runs, for a page on `pageOrigin`: the sandbox's origin and base URL,\n * or why not. Refused: not a URL; credentials, a query or a fragment; not `https://` (`http://`\n * only on `localhost` / `127.0.0.1`); a path a policy cannot name; `{server}` anywhere but the\n * host name, more than once, or a server name that is not a lowercase DNS label; a page without\n * an origin; and the sandbox on the PAGE'S OWN origin - `allow-same-origin` there would hand the\n * app your storage and the key vault.\n */\nexport const mcpAppSandboxTarget = (\n options: McpAppSandboxOptions | undefined,\n server: string,\n pageOrigin: string | undefined,\n): McpAppSandboxTarget => {\n const template = options?.url\n if (typeof template !== 'string' || template.length === 0 || template.length > 2048) {\n return no('invalid')\n }\n const parts = template.split(MCP_APP_SANDBOX_SERVER)\n if (parts.length > 2) return no('invalid')\n let raw = template\n if (parts.length === 2) {\n const authority = /^[a-z][a-z0-9+.-]*:\\/\\/([^/?#]*)/i.exec(template)?.[1] ?? ''\n if (!authority.replace(/:\\d*$/, '').includes(MCP_APP_SANDBOX_SERVER)) return no('invalid')\n if (typeof server !== 'string' || !DNS_LABEL.test(server)) return no('server-name')\n raw = template.replace(MCP_APP_SANDBOX_SERVER, server)\n }\n if (/[?#\\s]/.test(raw)) return no('invalid')\n let url: URL\n try {\n url = new URL(raw)\n } catch {\n return no('invalid')\n }\n const loopback = LOOPBACK_HOSTS.includes(url.hostname)\n if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) return no('insecure')\n if (url.username || url.password || !url.hostname) return no('invalid')\n if (!url.hostname.split('.').every((label) => DNS_LABEL.test(label))) {\n return no(parts.length === 2 ? 'server-name' : 'invalid')\n }\n if (!SAFE_PATH.test(url.pathname)) return no('invalid')\n if (!pageOrigin || pageOrigin === 'null') return no('no-page-origin')\n if (url.origin === pageOrigin) return no('same-origin')\n return { ok: true, origin: url.origin, base: `${url.origin}${url.pathname.replace(/\\/+$/, '')}` }\n}\n\n/** The proxy page's URL for an app's declared origins (`<base>/<policy>`), or none if too long. */\nexport const mcpAppSandboxProxyUrl = (\n base: string,\n csp?: Partial<McpAppCsp>,\n): string | undefined => {\n const granted = grantedAppCsp(csp)\n const token = mcpAppPolicyToken({\n connect: granted.connectDomains,\n resources: granted.resourceDomains,\n })\n return token ? `${base}/${token}` : undefined\n}\n\nconst PROXY_URL = /^https?:\\/\\/[A-Za-z0-9.-]+(?::\\d{1,5})?\\/[A-Za-z0-9\\-._~/%]*$/\n\n/**\n * The policy of the shell: no script at all, and frames from the proxy's exact URL only - a\n * `frame-src` with a path matches that path and nothing else (the query is not part of the\n * match), so the proxy's frame can never be navigated anywhere else.\n */\nexport const mcpAppSandboxShellCsp = (proxyUrl: string): string =>\n [\n \"default-src 'none'\",\n \"script-src 'none'\",\n \"style-src 'unsafe-inline'\",\n `frame-src ${proxyUrl}`,\n \"child-src 'none'\",\n \"worker-src 'none'\",\n \"object-src 'none'\",\n \"form-action 'none'\",\n \"base-uri 'none'\",\n ].join('; ')\n\n/**\n * What goes into the OUTER frame's `srcdoc` in sandbox mode: the shell - its policy first, one\n * frame of the proxy page, no script, nothing of the app. Give the outer `<iframe>`\n * `sandbox={MCP_APP_SANDBOX_FRAME_TOKENS}` and nothing else. Throws on a URL that is not a proxy\n * URL this package builds (`mcpAppSandboxProxyUrl`). `scheme` is declared by the shell and its\n * frame, and handed to the proxy page as `?scheme=` on its frame's `src` ONLY: the shell's\n * `frame-src` stays the path (a source expression carries no query, and a path source ignores\n * one), so the pin is the same with or without it.\n */\nexport const buildMcpAppSandboxShell = (proxyUrl: string, scheme?: McpAppColorScheme): string => {\n if (!PROXY_URL.test(proxyUrl)) throw new Error('not a sandbox proxy URL')\n const s = mcpAppColorScheme(scheme)\n const src = s ? `${proxyUrl}?${MCP_APP_SCHEME_PARAM}=${s}` : proxyUrl\n return (\n '<!doctype html><html><head>' +\n cspMetaTag(mcpAppSandboxShellCsp(proxyUrl)) +\n schemeMeta(s) +\n `<style>${schemeCss(s)}html,body{margin:0;height:100%;overflow:hidden;background:transparent}` +\n `iframe{display:block;border:0;width:100%;height:100%${schemeOfFrame(s)}}</style></head><body>` +\n `<iframe id=\"proxy\" sandbox=\"${MCP_APP_SANDBOX_FRAME_TOKENS}\" referrerpolicy=\"no-referrer\" ` +\n `src=\"${escapeAttribute(src)}\"></iframe></body></html>`\n )\n}\n\n/** What one message from the proxy's frame is, for the page (`McpAppSandboxLink.receive`). */\nexport type McpAppSandboxInput = 'drop' | 'ready' | 'broken' | 'app'\n\nexport interface McpAppSandboxLinkOptions {\n /** The sandbox origin (`mcpAppSandboxTarget(…).origin`). */\n origin: string\n /** The app, as read from its server: sent once, on the proxy's first ready. */\n html: string\n csp?: Partial<McpAppCsp>\n /** Post to the proxy's window. Always called with the sandbox origin as the target - never `*`. */\n post: (message: unknown, targetOrigin: string) => void\n}\n\n/**\n * The page's side of the sandbox proxy, without the DOM: which messages are the proxy's, the\n * handshake, and every post to the sandbox origin. A message is the proxy's only when it comes\n * from the proxy's window (`event.source`) AND from the sandbox origin (`event.origin`). The\n * first `sandbox-proxy-ready` is answered with the app (`sandbox-resource-ready`); another one\n * means the proxy page was loaded again - by the app - and the link breaks (`'broken'`: stop the\n * app). Every other `ui/notifications/sandbox-*` message is dropped; nothing reaches the bridge\n * (`'app'`) before the app was handed over.\n */\nexport class McpAppSandboxLink {\n private readonly o: McpAppSandboxLinkOptions\n private state: 'waiting' | 'loaded' | 'broken' | 'closed' = 'waiting'\n\n constructor(options: McpAppSandboxLinkOptions) {\n this.o = options\n }\n\n /** The proxy answered and was given the app. */\n get ready(): boolean {\n return this.state === 'loaded'\n }\n\n /** The proxy page was loaded a second time: the app must be stopped. */\n get broken(): boolean {\n return this.state === 'broken'\n }\n\n /** Whether a message event is the proxy's: its window, and the sandbox origin. */\n accepts(event: { source: unknown; origin: string }, proxy: unknown): boolean {\n return (\n proxy !== null &&\n proxy !== undefined &&\n event.source === proxy &&\n event.origin === this.o.origin\n )\n }\n\n receive(\n event: { source: unknown; origin: string; data: unknown },\n proxy: unknown,\n ): McpAppSandboxInput {\n if (this.state === 'broken' || this.state === 'closed' || !this.accepts(event, proxy)) {\n return 'drop'\n }\n const data = event.data\n if (isMcpAppSandboxMessage(data)) {\n const d = data as { jsonrpc?: unknown; method: string }\n if (d.jsonrpc !== '2.0' || d.method !== MCP_APP_SANDBOX_PROXY_READY) return 'drop'\n if (this.state === 'loaded') {\n this.state = 'broken'\n return 'broken'\n }\n this.state = 'loaded'\n const granted = grantedAppCsp(this.o.csp)\n this.o.post(\n {\n jsonrpc: '2.0',\n method: MCP_APP_SANDBOX_RESOURCE_READY,\n params: { html: this.o.html, csp: granted },\n },\n this.o.origin,\n )\n return 'ready'\n }\n return this.state === 'loaded' ? 'app' : 'drop'\n }\n\n /** Send a message to the app, through the proxy, to the sandbox origin. Nothing once broken. */\n post(message: unknown): void {\n if (this.state === 'loaded') this.o.post(message, this.o.origin)\n }\n\n close(): void {\n if (this.state !== 'broken') this.state = 'closed'\n }\n}\n\n/**\n * A pending consent request of THIS frame (`ApprovalView.app.frame`, set by `useAgent`); for a\n * request that names no frame (a host's own gate), one of this app's server and resource.\n */\nexport const isApprovalOfApp = (approval: ApprovalView, app: AppView): boolean =>\n approval.status === 'pending' &&\n approval.app !== undefined &&\n (approval.app.frame !== undefined\n ? approval.app.frame === app.id\n : approval.app.server === app.server && approval.app.resourceUri === app.resourceUri)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,oBAAoC;AA8CtC,IAAM,2BAA2B;AAGjC,IAAM,qBAAqB;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