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K,SAAA,CAAU,KAAA,CAAM,SAAS,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DAAA,EAUS,kBAAkB,GAAI,CAAA;AAAA;AAAA,KAAA,CAAA;AAGhF,EAAA,OAAO,SAAA,CAAU;AAAA,IACf,UAAA,EAAY,2BAAA;AAAA,IACZ,OAAA,EAAS,IAAA;AAAA,IACT,KAAA,EAAO,CAAA,SAAA,EAAY,KAAA,CAAM,OAAO,CAAA,MAAA,CAAA;AAAA,IAChC,IAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;AAiBO,SAAS,qBAAqB,KAAA,EAAoC;AACvE,EAAA,MAAM,GAAA,GACJ,MAAM,GAAA,IACN,6EAAA;AACF,EAAA,MAAM,IAAA,GAAO;AAAA,MAAA,EACP,UAAA,CAAW,KAAA,CAAM,OAAO,CAAC,CAAA;AAAA,KAAA,EAC1B,UAAA,CAAW,KAAA,CAAM,OAAO,CAAC,CAAA;AAAA,EAAA,EAC5B,KAAA,CAAM,aAAa,CAAA,SAAA,EAAY,UAAA,CAAW,MAAM,UAAU,CAAC,gBAAgB,EAAE;AAAA,KAAA,EAC1E,UAAA,CAAW,GAAG,CAAC,CAAA;AAAA,EAAA,EAClB,KAAA,CAAM,UAAU,CAAA,KAAA,EAAQ,UAAA,CAAW,MAAM,OAAO,CAAC,WAAW,EAAE,CAAA,CAAA;AAChE,EAAA,OAAO,SAAA,CAAU,EAAE,KAAA,EAAO,CAAA,EAAG,MAAM,OAAO,CAAA,gBAAA,CAAA,EAAoB,MAAM,CAAA;AACtE","file":"app-ui-placeholder.mjs","sourcesContent":["/**\n * Self-contained HTML pages served in place of an installed app's real UI\n * bundle while it's building, or when it can never be served (missing file\n * with no `ui.build`, a failed build, a removed app dir). Both surfaces that\n * serve an app's UI as a PAGE — the `ui://app_ui_<id>/view` MCP resource\n * (app-ui-apps.ts) and `GET /apps/:appId/ui` (http-server.ts) — render\n * through here instead of ever putting raw `{\"error\":...}` JSON in a page\n * body. That JSON shape is kept exactly as-is for MCP TOOL callers (e.g.\n * `app_install`'s error result) — this module is for the two PAGE routes\n * only.\n *\n * Reload strategy — deliberately two different mechanisms for the two\n * hosts, because neither works everywhere:\n *\n *   - The VS Code webview panel (packages/vscode appPanel.ts) embeds this\n *     page as an inner `srcdoc` iframe of an outer document it fully\n *     controls (buildAppHostHtml). `srcdoc` has no URL, so a navigation\n *     inside it (meta-refresh) just re-parses the SAME string — it can\n *     never pick up new content on its own. The extension host is what can:\n *     appPanel.ts detects `BUILDING_STATUS_ATTR` on the returned html and\n *     re-issues `resources/read` on a timer, replacing `panel.webview.html`\n *     wholesale until the marker is gone (see appPanel.logic.ts's\n *     `isAppUiBuilding`).\n *   - `GET /apps/:appId/ui` (http-server.ts) IS a real navigation target.\n *     The page keeps a meta refresh as a no-script fallback and also calls\n *     `location.reload()` from its inline timer. VS Code's Simple Browser can\n *     leave a meta refresh parked in an embedded page; the explicit reload is\n *     what makes the already-open tab pick up the completed bundle reliably.\n *\n * Both mechanisms are outside this module's own script, which is\n * deliberate: the page also has to survive the strictest CSP either host\n * imposes — the VS Code outer document sets `default-src 'none'; script-src\n * 'unsafe-inline'; style-src 'unsafe-inline'` with NO `connect-src`, and the\n * srcdoc iframe inherits it verbatim, so nothing here may `fetch`, open a\n * `WebSocket`/`EventSource`, or load an external image/font. The one bit of\n * live JS this page does carry — the elapsed-time counter and an HTTP-page\n * reload timer — needs no `connect-src`. The reload is skipped for the\n * webview's `about:srcdoc`, whose extension host owns polling.\n */\n\n/** `data-agentproto-ui-status` value while a build is in flight (or about to\n *  start) — `appPanel.logic.ts`'s `isAppUiBuilding` matches on this exact\n *  attribute/value pair; keep the two in lockstep (same cross-package\n *  duplication the file's own `appUiToolId` already accepts, since a\n *  `ui://`-served page can't import back into `@agentproto/vscode`). */\nexport const APP_UI_BUILDING_STATUS_ATTR = 'data-agentproto-ui-status=\"building\"'\n\nconst REFRESH_SECONDS = 3\n\nfunction escapeHtml(text: string): string {\n  return text\n    .replace(/&/g, \"&amp;\")\n    .replace(/</g, \"&lt;\")\n    .replace(/>/g, \"&gt;\")\n    .replace(/\"/g, \"&quot;\")\n}\n\nfunction pageShell(opts: {\n  statusAttr?: string\n  refresh?: boolean\n  title: string\n  body: string\n  script?: string\n}): string {\n  return `<!DOCTYPE html>\n<html lang=\"en\"${opts.statusAttr ? ` ${opts.statusAttr}` : \"\"}>\n<head>\n<meta charset=\"UTF-8\">\n${opts.refresh ? `<meta http-equiv=\"refresh\" content=\"${REFRESH_SECONDS}\">` : \"\"}\n<title>${escapeHtml(opts.title)}</title>\n<style>\n  :root { color-scheme: light dark; }\n  html, body { height: 100%; }\n  body {\n    margin: 0; padding: 2rem; box-sizing: border-box;\n    display: flex; flex-direction: column; align-items: center; justify-content: center;\n    font: 14px -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n    color: #ccc; background: #1e1e1e; text-align: center;\n  }\n  h1 { font-size: 1rem; font-weight: 600; margin: 0 0 0.5rem; }\n  p { margin: 0.25rem 0; color: #999; max-width: 34rem; }\n  .spinner {\n    width: 22px; height: 22px; margin-bottom: 1rem;\n    border: 2px solid #444; border-top-color: #8ab4f8; border-radius: 50%;\n    animation: agentproto-spin 0.8s linear infinite;\n  }\n  @keyframes agentproto-spin { to { transform: rotate(360deg); } }\n  pre {\n    margin-top: 1rem; padding: 0.75rem; max-width: 42rem; width: 90%;\n    max-height: 12rem; overflow: auto; text-align: left; white-space: pre-wrap;\n    word-break: break-word; background: #111; border: 1px solid #333;\n    border-radius: 4px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #d99;\n  }\n  code { color: #ccc; }\n</style>\n</head>\n<body>\n${opts.body}\n${opts.script ? `<script>${opts.script}</script>` : \"\"}\n</body>\n</html>`\n}\n\nexport interface AppUiBuildingHtmlInput {\n  readonly appName: string\n  /** `Date.now()`-style epoch ms the build actually started — the elapsed\n   *  counter is computed client-side off this, not baked in as static text,\n   *  so it keeps ticking between reloads. */\n  readonly startedAt: number\n  /** Last lines of the app's ui-build log (`appUiBuildLogPath`), if cheap to read. */\n  readonly logTail?: string\n}\n\n/** The \"still building\" placeholder — see the module doc for the reload\n *  strategy. Never blocks on the build itself; the caller decides when to\n *  show this (app-ui-build.ts's `resolveAppUiBuildState`). */\nexport function renderAppUiBuildingHtml(input: AppUiBuildingHtmlInput): string {\n  const body = `\n  <div class=\"spinner\" role=\"status\" aria-label=\"Building\"></div>\n  <h1>Building ${escapeHtml(input.appName)} UI&hellip;</h1>\n  <p id=\"agentproto-elapsed\">elapsed 0s</p>\n  ${input.logTail ? `<pre>${escapeHtml(input.logTail)}</pre>` : \"\"}`\n  const script = `(function () {\n  var startedAt = ${JSON.stringify(input.startedAt)};\n  var el = document.getElementById(\"agentproto-elapsed\");\n  function tick() {\n    if (!el) return;\n    var secs = Math.max(0, Math.round((Date.now() - startedAt) / 1000));\n    el.textContent = \"elapsed \" + secs + \"s\";\n  }\n  tick();\n  setInterval(tick, 1000);\n  if (window.location.protocol === \"http:\" || window.location.protocol === \"https:\") {\n    setTimeout(function () { window.location.reload(); }, ${REFRESH_SECONDS * 1000});\n  }\n})();`\n  return pageShell({\n    statusAttr: APP_UI_BUILDING_STATUS_ATTR,\n    refresh: true,\n    title: `Building ${input.appName}…`,\n    body,\n    script,\n  })\n}\n\nexport interface AppUiErrorHtmlInput {\n  readonly appName: string\n  readonly message: string\n  /** A path worth showing verbatim (the missing file, the removed app dir,\n   *  the build log). */\n  readonly detailPath?: string\n  readonly logTail?: string\n  /** Defaults to the generic reinstall/APP.md pointer. */\n  readonly fix?: string\n}\n\n/** A readable terminal-failure page — never auto-reloads (unlike the\n *  building placeholder): the failure already happened, and refreshing a\n *  failed `ui.build` run on a timer would just re-run it forever. A human\n *  reloading the panel/tab gets a fresh attempt instead. */\nexport function renderAppUiErrorHtml(input: AppUiErrorHtmlInput): string {\n  const fix =\n    input.fix ??\n    \"Reinstall the app with `app_install <dir>`, or check its APP.md `ui` block.\"\n  const body = `\n  <h1>${escapeHtml(input.appName)} UI is unavailable</h1>\n  <p>${escapeHtml(input.message)}</p>\n  ${input.detailPath ? `<p><code>${escapeHtml(input.detailPath)}</code></p>` : \"\"}\n  <p>${escapeHtml(fix)}</p>\n  ${input.logTail ? `<pre>${escapeHtml(input.logTail)}</pre>` : \"\"}`\n  return pageShell({ title: `${input.appName}: UI unavailable`, body })\n}\n"]}