{"version":3,"file":"app-frame.cjs","sources":["../src/app-frame.ts"],"sourcesContent":["import { isOpenRequest, isTransferableRef, isTransferableSession, readContentHints, readSelectDialogResult, systemOpenUrl, SELECT_DIALOG_PATH, SystemDialogError, SYSTEM_DIALOG_ERROR_CODES, type ContentHints, type ContentOpenTarget, type OpenRequest, type SelectDialogParams, type SelectDialogResult, type SystemDialogErrorCode, type TransferableContentRef, type TransferableSessionContext } from './content'\nexport type SystemDialogReply = { ok: true; result: unknown } | { ok: false; code: SystemDialogErrorCode }\nconst dialogErrorCode = (value: unknown): SystemDialogErrorCode =>\n  SYSTEM_DIALOG_ERROR_CODES.includes(value as SystemDialogErrorCode) ? value as SystemDialogErrorCode : 'protocol'\nexport interface AppFrameMessage<T extends string = string, P = unknown> {\n  protocol: 'buckyos.app-frame'; version: 1; type: T; id?: string; replyTo?: string; payload: P\n}\nexport interface FrameInit {\n  nonce: string\n  windowId: string\n  formFactor: 'desktop' | 'mobile'\n  theme: { mode: 'light' | 'dark'; accent?: string }\n  locale: string\n  launch?: OpenRequest\n  shellCapabilities: string[]\n}\nexport type CloseDecision = 'allow' | 'deny' | 'pending'\nconst envelope = (type: string, payload: unknown, extra: { id?: string; replyTo?: string } = {}): AppFrameMessage =>\n  ({ protocol: 'buckyos.app-frame', version: 1, type, payload, ...extra })\nconst isMessage = (value: unknown): value is AppFrameMessage => {\n  if (!value || typeof value !== 'object') return false\n  const v = value as AppFrameMessage\n  return v.protocol === 'buckyos.app-frame' && v.version === 1 && typeof v.type === 'string' && !!v.payload && typeof v.payload === 'object'\n}\nexport class AppFrameHost {\n  ready = false\n  capabilities: string[] = []\n  private pending = new Map<string, { resolve: (v: unknown) => void; reject: (e: Error) => void; timer: ReturnType<typeof setTimeout>; type: string }>()\n  private listener = (event: MessageEvent) => this.receive(event)\n  private opens: number[] = []\n  constructor(private options: {\n    target: () => Window | null; origin: string; init: FrameInit\n    onReady?: () => void\n    onTitle?: (title: string, dirty: boolean) => void\n    onRequestClose?: () => void\n    onContentOpen?: (request: OpenRequest, target: ContentOpenTarget, options: { newWindow: boolean; hints: ContentHints }) => void\n    /** Shows a system dialog the App asked for (`sysdlg.open`). `params` is untrusted input: validate it. */\n    onSystemDialog?: (path: string, params: unknown) => Promise<SystemDialogReply>\n  }) { window.addEventListener('message', this.listener) }\n  private focused?: boolean\n  private dialogOpen = false\n  private async systemDialog(id: string, path: unknown, params: unknown): Promise<void> {\n    const reply = (payload: SystemDialogReply) => { if (this.ready) this.options.target()?.postMessage(envelope('sysdlg.openResult', payload, { replyTo: id }), this.options.origin) }\n    if (!this.options.onSystemDialog || typeof path !== 'string') return reply({ ok: false, code: 'unsupported' })\n    if (this.dialogOpen) return reply({ ok: false, code: 'busy' })\n    this.dialogOpen = true\n    try { reply(await this.options.onSystemDialog(path, params)) }\n    catch (error) { reply({ ok: false, code: error instanceof SystemDialogError ? error.code : 'closed' }) }\n    finally { this.dialogOpen = false }\n  }\n  private receive(event: MessageEvent): void {\n    if (event.source !== this.options.target() || event.origin !== this.options.origin || !isMessage(event.data)) return\n    const m = event.data\n    const p = m.payload as Record<string, unknown>\n    if (m.type === 'frame.hello') {\n      if (p.nonce !== this.options.init.nonce || !Array.isArray(p.appCapabilities)) return\n      this.ready = true\n      this.capabilities = p.appCapabilities.filter((c): c is string => typeof c === 'string')\n      this.send('frame.init', this.options.init)\n      if (this.focused !== undefined) this.send('frame.focusChanged', { focused: this.focused })\n      this.options.onReady?.()\n      return\n    }\n    if (!this.ready) return\n    if (m.replyTo) {\n      const pending = this.pending.get(m.replyTo)\n      if (pending && m.type === pending.type + 'Result') {\n        clearTimeout(pending.timer); this.pending.delete(m.replyTo); pending.resolve(m.payload)\n      }\n      return\n    }\n    if (m.type === 'window.setTitle' && typeof p.title === 'string') this.options.onTitle?.(p.title.slice(0, 256), p.dirty === true)\n    if (m.type === 'window.requestClose') this.options.onRequestClose?.()\n    if (m.type === 'sysdlg.open' && typeof m.id === 'string') void this.systemDialog(m.id, p.path, p.params)\n    if (m.type === 'content.open' && (p.target === 'default' || p.target === 'preview' || p.target === 'chooser')) {\n      const request = { ...(p.request as object), requestId: crypto.randomUUID() }\n      if (!isOpenRequest(request)) return\n      this.opens = this.opens.filter(t => t > Date.now() - 10000)\n      if (this.opens.length >= 5) return\n      this.opens.push(Date.now())\n      this.options.onContentOpen?.(request, p.target, { newWindow: p.newWindow === true, hints: readContentHints(p.hints) })\n    }\n  }\n  update(init: Partial<FrameInit>): void { this.options.init = { ...this.options.init, ...init } }\n  /** Reports whether the App's window is the focused one; only a change is sent. */\n  setFocused(focused: boolean): void {\n    if (this.focused === focused) return\n    this.focused = focused\n    this.send('frame.focusChanged', { focused })\n  }\n  send(type: string, payload: unknown): void {\n    if (this.ready) this.options.target()?.postMessage(envelope(type, payload), this.options.origin)\n  }\n  request(type: string, payload: unknown, timeout = 3000): Promise<unknown> {\n    if (!this.ready) return Promise.reject(new Error('App frame is not ready'))\n    const id = crypto.randomUUID()\n    return new Promise((resolve, reject) => {\n      const timer = setTimeout(() => { this.pending.delete(id); reject(new Error('App frame timed out')) }, timeout)\n      this.pending.set(id, { resolve, reject, timer, type })\n      this.options.target()?.postMessage(envelope(type, payload, { id }), this.options.origin)\n    })\n  }\n  async open(request: OpenRequest): Promise<{ accepted: boolean; fallback?: 'preview' }> {\n    if (!this.capabilities.includes('open')) return { accepted: false }\n    return await this.request('frame.open', { request }) as { accepted: boolean; fallback?: 'preview' }\n  }\n  async beforeClose(reason: 'user' | 'logout' | 'shell' = 'user'): Promise<CloseDecision> {\n    if (!this.ready || !this.capabilities.includes('beforeClose')) return 'allow'\n    const r = await this.request('frame.beforeClose', { reason }) as { decision?: CloseDecision }\n    return r.decision === 'allow' || r.decision === 'pending' ? r.decision : 'deny'\n  }\n  async back(): Promise<boolean> {\n    if (!this.capabilities.includes('back')) return false\n    return (await this.request('frame.back', {}) as { handled?: boolean }).handled === true\n  }\n  dispose(): void {\n    window.removeEventListener('message', this.listener)\n    this.pending.forEach(p => { clearTimeout(p.timer); p.reject(new Error('App frame disposed')) })\n    this.pending.clear(); this.ready = false\n  }\n}\n/**\n * Origin of the window embedding this page, when `accept` admits it. `location.ancestorOrigins` names the real\n * parent even after the frame navigated through other pages (a sign-in round trip); the referrer is the fallback.\n */\nexport function embedderOrigin(accept: (origin: string) => boolean): string | null {\n  if (window.parent === window) return null\n  const candidates = [window.location.ancestorOrigins?.[0], document.referrer]\n  for (const candidate of candidates) {\n    if (!candidate) continue\n    try {\n      const origin = new URL(candidate).origin\n      if (accept(origin)) return origin\n    } catch {}\n  }\n  return null\n}\nexport const originInZone = (origin: string, zoneHost: string): boolean => {\n  try {\n    const url = new URL(origin)\n    return url.protocol === window.location.protocol && (url.hostname === zoneHost || url.hostname.endsWith(`.${zoneHost}`))\n  } catch { return false }\n}\nexport class AppFrameClient {\n  init?: FrameInit\n  private title?: string\n  private focused?: boolean\n  private helloTimer?: ReturnType<typeof setInterval>\n  private helloDeadline?: ReturnType<typeof setTimeout>\n  private readonly nonce: string | null\n  private readonly origin: string\n  private readonly listener = (event: MessageEvent) => { void this.receive(event) }\n  private dialogs = new Map<string, { resolve: (result: SelectDialogResult) => void; reject: (error: Error) => void; allowLocal: boolean }>()\n  private embedAbort?: AbortController\n  constructor(private options: {\n    shellOrigin: string\n    /** The Zone's system entry (its root origin): where content is opened when this page is not embedded in the shell. */\n    systemOrigin?: string\n    /** This App's id, so the system does not offer the content back to it. */\n    appId?: string\n    onInit?: (init: FrameInit) => void\n    onOpen?: (request: OpenRequest) => Promise<{ accepted: boolean; fallback?: 'preview' }> | { accepted: boolean; fallback?: 'preview' }\n    onBeforeClose?: (reason: 'user' | 'logout' | 'shell') => Promise<CloseDecision> | CloseDecision\n    onBack?: () => Promise<boolean> | boolean\n    onTheme?: (theme: FrameInit['theme']) => void\n    onLocale?: (locale: string) => void\n    onFocus?: (focused: boolean) => void\n  }) {\n    this.origin = new URL(options.shellOrigin).origin\n    this.nonce = new URLSearchParams(window.location.hash.slice(1)).get('bfp')\n    window.addEventListener('message', this.listener)\n    if (window.parent !== window && this.nonce) {\n      const hello = () => window.parent.postMessage(envelope('frame.hello', { nonce: this.nonce, appCapabilities: [\n        ...options.onOpen ? ['open'] : [], ...options.onBeforeClose ? ['beforeClose'] : [], ...options.onBack ? ['back'] : [],\n      ] }), this.origin)\n      hello()\n      this.helloTimer = setInterval(hello, 250)\n      this.helloDeadline = setTimeout(() => clearInterval(this.helloTimer), 1500)\n    }\n  }\n  private async receive(event: MessageEvent): Promise<void> {\n    if (event.source !== window.parent || event.origin !== this.origin || !isMessage(event.data)) return\n    const m = event.data\n    const p = m.payload as Record<string, unknown>\n    if (m.type === 'frame.init') {\n      if (!this.nonce || p.nonce !== this.nonce || typeof p.locale !== 'string' || !p.theme || typeof p.windowId !== 'string' || p.launch && !isOpenRequest(p.launch)) return\n      clearInterval(this.helloTimer); clearTimeout(this.helloDeadline)\n      this.init = p as unknown as FrameInit\n      this.title = undefined; this.focused = undefined\n      this.options.onInit?.(this.init)\n      return\n    }\n    if (!this.init) return\n    if (m.type === 'sysdlg.openResult') {\n      const pending = m.replyTo ? this.dialogs.get(m.replyTo) : undefined\n      if (!pending) return\n      this.dialogs.delete(m.replyTo!)\n      if (p.ok !== true) return pending.reject(new SystemDialogError(dialogErrorCode(p.code)))\n      const result = readSelectDialogResult(p.result, { allowLocal: pending.allowLocal })\n      if (result) pending.resolve(result)\n      else pending.reject(new SystemDialogError('protocol'))\n      return\n    }\n    const reply = (payload: unknown) => window.parent.postMessage(envelope(m.type + 'Result', payload, { replyTo: m.id }), this.origin)\n    try {\n      if (m.type === 'frame.open' && isOpenRequest(p.request)) reply(await this.options.onOpen?.(p.request) ?? { accepted: false })\n      if (m.type === 'frame.beforeClose') reply({ decision: await this.options.onBeforeClose?.(p.reason as 'user') ?? 'allow' })\n      if (m.type === 'frame.back') reply({ handled: await this.options.onBack?.() ?? false })\n      if (m.type === 'frame.themeChanged' && (p.mode === 'dark' || p.mode === 'light')) this.options.onTheme?.(p as FrameInit['theme'])\n      if (m.type === 'frame.localeChanged' && typeof p.locale === 'string') this.options.onLocale?.(p.locale)\n      if (m.type === 'frame.focusChanged' && this.focused !== (p.focused === true)) { this.focused = p.focused === true; this.options.onFocus?.(this.focused) }\n    } catch {\n      if (m.type === 'frame.open') reply({ accepted: false, fallback: 'preview' })\n      if (m.type === 'frame.beforeClose') reply({ decision: 'deny' })\n    }\n  }\n  send(type: string, payload: unknown): void {\n    if (this.init) window.parent.postMessage(envelope(type, payload), this.origin)\n  }\n  setTitle(title: string, dirty = false): void {\n    const key = JSON.stringify([title, dirty])\n    if (!this.init || key === this.title) return\n    this.title = key\n    this.send('window.setTitle', { title, dirty })\n  }\n  requestClose(): void { this.send('window.requestClose', {}) }\n  /**\n   * Asks the system to open content: with its default app, in Preview, or by letting the user choose (`chooser`).\n   * Embedded in the shell the request goes over the frame; in a standalone tab it opens the Zone's system entry\n   * (`systemOrigin`) in a new tab. Returns false when neither is available.\n   */\n  openContent(request: Omit<OpenRequest, 'requestId'>, target: ContentOpenTarget = 'default', options: { newWindow?: boolean; hints?: ContentHints } = {}): boolean {\n    const hints = options.hints ?? {}\n    if (this.init) { this.send('content.open', { request, target, newWindow: options.newWindow === true, hints }); return true }\n    if (!this.options.systemOrigin) return false\n    window.open(systemOpenUrl(this.options.systemOrigin, { request, target, hints, from: this.options.appId }), '_blank', 'noopener')\n    return true\n  }\n  /**\n   * Shows the system file picker (`sysdlg/select`) and resolves with what the user chose; cancelling resolves with\n   * `{ action: 'cancelled' }`. Embedded in the shell the shell draws the dialog over this App's window; in a\n   * standalone tab the picker page of the Zone's system entry (`systemOrigin`) is framed over this page. Rejects\n   * with a `SystemDialogError` when no picker is available or the request did not complete.\n   */\n  selectContent(params: SelectDialogParams = {}, options: { signal?: AbortSignal; theme?: 'light' | 'dark'; locale?: string } = {}): Promise<SelectDialogResult> {\n    if (this.init) {\n      if (!this.init.shellCapabilities.includes(SELECT_DIALOG_PATH)) return Promise.reject(new SystemDialogError('unsupported'))\n      if (this.dialogs.size) return Promise.reject(new SystemDialogError('busy'))\n      const id = crypto.randomUUID()\n      return new Promise((resolve, reject) => {\n        this.dialogs.set(id, { resolve, reject, allowLocal: params.allowLocal === true })\n        window.parent.postMessage(envelope('sysdlg.open', { path: SELECT_DIALOG_PATH, params }, { id }), this.origin)\n      })\n    }\n    if (!this.options.systemOrigin) return Promise.reject(new SystemDialogError('unsupported'))\n    const abort = this.embedAbort = new AbortController()\n    options.signal?.addEventListener('abort', () => abort.abort(), { once: true })\n    if (options.signal?.aborted) abort.abort()\n    return openSelectEmbed(this.options.systemOrigin, params, { ...options, signal: abort.signal })\n  }\n  dispose(): void {\n    clearInterval(this.helloTimer); clearTimeout(this.helloDeadline); window.removeEventListener('message', this.listener)\n    this.dialogs.forEach(pending => pending.reject(new SystemDialogError('closed')))\n    this.dialogs.clear(); this.embedAbort?.abort()\n  }\n}\n\n/**\n * Preview embed protocol (`buckyos.preview-embed` v1): an App shows the system Preview component inside its own UI.\n * The App frames `<systemOrigin>/embed/preview` (component only, no shell) and hands it a content reference; the\n * system page reads the content with its own Zone-root session, so no token crosses origins. Open With goes back\n * through the App to the shell (`AppFrameClient.openContent(…, 'chooser')`).\n */\nexport type PreviewEmbedSource = TransferableContentRef | { kind: 'blob'; blob: Blob; name: string }\nexport interface PreviewEmbedInit {\n  nonce: string\n  source: PreviewEmbedSource\n  session?: TransferableSessionContext\n  theme: 'light' | 'dark'\n  locale: string\n}\nexport interface PreviewEmbedState {\n  status: 'loading' | 'ready' | 'error'\n  /** Preview error kind (`unsupported`, `not-found`, `permission-denied`, `timeout`, `error`, …) and code. */\n  error?: { kind: string; code: string }\n  title?: string\n  mediaType?: string\n}\nexport interface PreviewEmbedOpenWith { request: Omit<OpenRequest, 'requestId'>; hints: ContentHints }\nconst PREVIEW_EMBED = 'buckyos.preview-embed'\nconst embedEnvelope = (type: string, payload: unknown, protocol = PREVIEW_EMBED) => ({ protocol, version: 1, type, payload })\nconst isEmbedMessage = (value: unknown, protocol = PREVIEW_EMBED): value is { type: string; payload: Record<string, unknown> } => {\n  const v = value as { protocol?: unknown; version?: unknown; type?: unknown; payload?: unknown } | null\n  return !!v && v.protocol === protocol && v.version === 1 && typeof v.type === 'string' && !!v.payload && typeof v.payload === 'object'\n}\nconst isEmbedSource = (value: unknown): value is PreviewEmbedSource =>\n  isTransferableRef(value) || (!!value && typeof value === 'object' && (value as { kind?: unknown }).kind === 'blob' &&\n    typeof Blob !== 'undefined' && (value as { blob?: unknown }).blob instanceof Blob && typeof (value as { name?: unknown }).name === 'string')\nexport const PREVIEW_EMBED_PATH = '/embed/preview'\n\n/** App side: owns the iframe that shows the system Preview. */\nexport class PreviewEmbed {\n  readonly url: string\n  private readonly nonce = crypto.randomUUID()\n  private readonly origin: string\n  private readonly listener = (event: MessageEvent) => this.receive(event)\n  private init: Omit<PreviewEmbedInit, 'nonce'>\n  private ready = false\n  constructor(private options: {\n    systemOrigin: string\n    frame: () => HTMLIFrameElement | null\n    init: Omit<PreviewEmbedInit, 'nonce'>\n    onState?: (state: PreviewEmbedState) => void\n    onOpenWith?: (open: PreviewEmbedOpenWith) => void\n    onExit?: () => void\n  }) {\n    this.origin = new URL(options.systemOrigin).origin\n    this.init = options.init\n    this.url = `${this.origin}${PREVIEW_EMBED_PATH}#bpe=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`\n    window.addEventListener('message', this.listener)\n  }\n  private post(type: string, payload: unknown): void {\n    this.options.frame()?.contentWindow?.postMessage(embedEnvelope(type, payload), this.origin)\n  }\n  private receive(event: MessageEvent): void {\n    if (event.origin !== this.origin || event.source !== this.options.frame()?.contentWindow || !isEmbedMessage(event.data)) return\n    const { type, payload: p } = event.data\n    if (type === 'embed.hello') { if (p.nonce === this.nonce) { this.ready = true; this.post('embed.init', { ...this.init, nonce: this.nonce }) } return }\n    if (type === 'embed.state' && (p.status === 'loading' || p.status === 'ready' || p.status === 'error')) {\n      const error = p.error as { kind?: unknown; code?: unknown } | undefined\n      this.options.onState?.({ status: p.status,\n        error: error && typeof error.kind === 'string' && typeof error.code === 'string' ? { kind: error.kind, code: error.code } : undefined,\n        title: typeof p.title === 'string' ? p.title.slice(0, 256) : undefined, mediaType: typeof p.mediaType === 'string' ? p.mediaType.slice(0, 128) : undefined })\n    }\n    if (type === 'embed.openWith') {\n      const request = p.request as Omit<OpenRequest, 'requestId'> | undefined\n      if (request && isTransferableRef(request.source) && (request.session === undefined || isTransferableSession(request.session))) {\n        this.options.onOpenWith?.({ request: { source: request.source, session: request.session }, hints: readContentHints(p.hints) })\n      }\n    }\n    if (type === 'embed.exit') this.options.onExit?.()\n  }\n  update(patch: Partial<Pick<PreviewEmbedInit, 'theme' | 'locale'>>): void {\n    this.init = { ...this.init, ...patch }\n    // Before the handshake the frame still holds its initial about:blank (this App's origin, so the browser rejects\n    // the target origin); `embed.init` carries the patch.\n    if (this.ready) this.post('embed.update', patch)\n  }\n  dispose(): void { window.removeEventListener('message', this.listener) }\n}\n\n/** System side: the component-only page at `PREVIEW_EMBED_PATH`. Accepts one embedding App whose origin `accept` admits. */\nexport class PreviewEmbedHost {\n  readonly parentOrigin: string | null\n  private readonly nonce: string | null\n  private ready = false\n  private readonly hello?: ReturnType<typeof setInterval>\n  private readonly listener = (event: MessageEvent) => this.receive(event)\n  constructor(private options: {\n    accept: (origin: string) => boolean\n    onInit: (init: PreviewEmbedInit) => void\n    onUpdate?: (patch: Partial<Pick<PreviewEmbedInit, 'theme' | 'locale'>>) => void\n  }) {\n    const params = new URLSearchParams(window.location.hash.slice(1))\n    this.nonce = params.get('bpe')\n    let parentOrigin: string | null = null\n    try { parentOrigin = new URL(params.get('po') ?? '').origin } catch {}\n    this.parentOrigin = window.parent !== window && this.nonce && parentOrigin && options.accept(parentOrigin) ? parentOrigin : null\n    if (!this.parentOrigin) return\n    window.addEventListener('message', this.listener)\n    const hello = () => window.parent.postMessage(embedEnvelope('embed.hello', { nonce: this.nonce }), this.parentOrigin!)\n    hello()\n    this.hello = setInterval(() => { if (!this.ready) hello() }, 250)\n  }\n  private receive(event: MessageEvent): void {\n    if (event.source !== window.parent || event.origin !== this.parentOrigin || !isEmbedMessage(event.data)) return\n    const { type, payload: p } = event.data\n    if (type === 'embed.init') {\n      if (p.nonce !== this.nonce || !isEmbedSource(p.source) || (p.session !== undefined && !isTransferableSession(p.session)) || typeof p.locale !== 'string') return\n      this.ready = true; clearInterval(this.hello)\n      this.options.onInit({ nonce: String(p.nonce), source: p.source, session: p.session as TransferableSessionContext | undefined, theme: p.theme === 'dark' ? 'dark' : 'light', locale: p.locale })\n      return\n    }\n    if (type === 'embed.update' && this.ready) {\n      const patch: Partial<Pick<PreviewEmbedInit, 'theme' | 'locale'>> = {}\n      if (p.theme === 'dark' || p.theme === 'light') patch.theme = p.theme\n      if (typeof p.locale === 'string') patch.locale = p.locale\n      this.options.onUpdate?.(patch)\n    }\n  }\n  private post(type: string, payload: unknown): void {\n    if (this.ready && this.parentOrigin) window.parent.postMessage(embedEnvelope(type, payload), this.parentOrigin)\n  }\n  state(state: PreviewEmbedState): void { this.post('embed.state', state) }\n  openWith(open: PreviewEmbedOpenWith): void { this.post('embed.openWith', open) }\n  exit(): void { this.post('embed.exit', {}) }\n  dispose(): void { clearInterval(this.hello); window.removeEventListener('message', this.listener) }\n}\n\n/**\n * System dialog embed protocol (`buckyos.sysdlg-embed` v1): a standalone App page (no shell) shows the system file\n * picker by framing `<systemOrigin>/embed/sysdlg/select` over itself. The handshake is the Preview embed's\n * (`embed.hello` → `embed.init`); the system page browses with its own Zone-root session and answers with\n * `embed.result`. No token crosses origins, and every message names its exact target origin.\n */\nconst SYSDLG_EMBED = 'buckyos.sysdlg-embed'\nexport const SELECT_EMBED_PATH = '/embed/sysdlg/select'\nexport interface SelectEmbedInit { nonce: string; params: unknown; theme: 'light' | 'dark'; locale: string }\nlet selectEmbedOpen = false\n\n/** App side of `buckyos.sysdlg-embed`: the full-page layer that frames the picker. One at a time per page. */\nexport function openSelectEmbed(systemOrigin: string, params: SelectDialogParams, options: { signal?: AbortSignal; theme?: 'light' | 'dark'; locale?: string } = {}): Promise<SelectDialogResult> {\n  if (options.signal?.aborted) return Promise.reject(new SystemDialogError('closed'))\n  if (selectEmbedOpen) return Promise.reject(new SystemDialogError('busy'))\n  selectEmbedOpen = true\n  const origin = new URL(systemOrigin).origin\n  const locale = options.locale ?? navigator.language ?? 'en'\n  const theme = options.theme ?? (window.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n  const zh = locale.toLowerCase().startsWith('zh')\n  return new Promise((resolve, reject) => {\n    const body = document.body\n    const html = document.documentElement\n    const focused = document.activeElement instanceof HTMLElement ? document.activeElement : null\n    const scroll = { x: window.scrollX, y: window.scrollY }\n    const saved = { body: body.getAttribute('style'), html: html.getAttribute('style') }\n    const siblings = Array.from(body.children).filter((el): el is HTMLElement => el instanceof HTMLElement)\n      .map(el => ({ el, inert: el.inert, hidden: el.getAttribute('aria-hidden') }))\n    const root = document.createElement('div')\n    root.setAttribute('data-buckyos-sysdlg', 'select')\n    root.setAttribute('role', 'dialog'); root.setAttribute('aria-modal', 'true')\n    root.setAttribute('aria-label', zh ? '文件选择器' : 'File picker')\n    root.style.cssText = 'position:fixed;inset:0;height:100vh;height:100dvh;z-index:2147483647;background:rgba(0,0,0,.32);display:flex;align-items:center;justify-content:center'\n    let frame: HTMLIFrameElement | undefined\n    let nonce = ''\n    let timer: ReturnType<typeof setTimeout> | undefined\n    let done = false\n    const block = (event: Event) => { if (!root.contains(event.target as Node)) { event.stopPropagation(); event.preventDefault() } }\n    const blocked = ['keydown', 'pointerdown', 'mousedown', 'touchstart', 'wheel'] as const\n    const cleanup = () => {\n      if (done) return false\n      done = true; selectEmbedOpen = false\n      clearTimeout(timer)\n      window.removeEventListener('message', receive)\n      options.signal?.removeEventListener('abort', abort)\n      if (!('inert' in HTMLElement.prototype)) blocked.forEach(type => document.removeEventListener(type, block, true))\n      root.remove()\n      siblings.forEach(({ el, inert, hidden }) => { el.inert = inert; if (hidden === null) el.removeAttribute('aria-hidden'); else el.setAttribute('aria-hidden', hidden) })\n      if (saved.body === null) body.removeAttribute('style'); else body.setAttribute('style', saved.body)\n      if (saved.html === null) html.removeAttribute('style'); else html.setAttribute('style', saved.html)\n      window.scrollTo(scroll.x, scroll.y)\n      focused?.focus({ preventScroll: true })\n      return true\n    }\n    const finish = (result: SelectDialogResult) => { if (cleanup()) resolve(result) }\n    const fail = (code: SystemDialogErrorCode) => { if (cleanup()) reject(new SystemDialogError(code)) }\n    const abort = () => fail('closed')\n    const showFailure = () => {\n      frame?.remove(); frame = undefined\n      const panel = document.createElement('div')\n      panel.setAttribute('role', 'alert')\n      panel.style.cssText = `max-width:22rem;margin:1rem;padding:1.25rem;border-radius:16px;font:14px/1.6 system-ui,sans-serif;background:${theme === 'dark' ? '#1f2329' : '#fff'};color:${theme === 'dark' ? '#f2f3f5' : '#1f2329'};box-shadow:0 24px 64px rgba(0,0,0,.24)`\n      const text = document.createElement('p')\n      text.style.margin = '0 0 1rem'\n      text.textContent = zh ? '无法加载文件选择器' : 'Unable to load the file picker'\n      const actions = document.createElement('div')\n      actions.style.cssText = 'display:flex;gap:.5rem;justify-content:flex-end'\n      const button = (label: string, action: () => void) => {\n        const el = document.createElement('button')\n        el.type = 'button'; el.textContent = label\n        el.style.cssText = 'min-height:2.25rem;padding:0 1rem;font:inherit;border-radius:999px;border:1px solid currentColor;background:transparent;color:inherit;cursor:pointer'\n        el.addEventListener('click', action); actions.append(el); return el\n      }\n      button(zh ? '取消' : 'Cancel', () => fail('load_failed'))\n      const retry = button(zh ? '重试' : 'Retry', () => { panel.remove(); load() })\n      panel.append(text, actions); root.append(panel); retry.focus()\n    }\n    const load = () => {\n      nonce = crypto.randomUUID()\n      frame = document.createElement('iframe')\n      frame.title = zh ? '文件选择器' : 'File picker'\n      frame.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal'\n      frame.setAttribute('allowtransparency', 'true')\n      frame.addEventListener('error', showFailure)\n      frame.src = `${origin}${SELECT_EMBED_PATH}#bse=${nonce}&po=${encodeURIComponent(window.location.origin)}`\n      root.append(frame)\n      timer = setTimeout(showFailure, 10000)\n    }\n    const receive = (event: MessageEvent) => {\n      if (!frame || event.origin !== origin || event.source !== frame.contentWindow || !isEmbedMessage(event.data, SYSDLG_EMBED)) return\n      const { type, payload: p } = event.data\n      if (type === 'embed.hello') {\n        if (p.nonce !== nonce) return\n        clearTimeout(timer)\n        frame.contentWindow?.postMessage(embedEnvelope('embed.init', { nonce, params, theme, locale } satisfies SelectEmbedInit, SYSDLG_EMBED), origin)\n        frame.focus()\n      }\n      if (type === 'embed.error') fail(dialogErrorCode(p.code))\n      if (type === 'embed.result') {\n        const result = readSelectDialogResult(p.result, { allowLocal: params.allowLocal === true })\n        if (result) finish(result)\n        else fail('protocol')\n      }\n    }\n    window.addEventListener('message', receive)\n    options.signal?.addEventListener('abort', abort, { once: true })\n    if ('inert' in HTMLElement.prototype) siblings.forEach(({ el }) => { el.inert = true })\n    else { siblings.forEach(({ el }) => el.setAttribute('aria-hidden', 'true')); blocked.forEach(type => document.addEventListener(type, block, true)) }\n    // `overflow: hidden` alone does not stop the page behind from scrolling on iOS; pinning the body does.\n    html.style.overflow = 'hidden'\n    body.style.position = 'fixed'; body.style.top = `${-scroll.y}px`; body.style.left = `${-scroll.x}px`; body.style.right = '0'; body.style.overflow = 'hidden'\n    body.append(root)\n    load()\n  })\n}\n\n/** System side: the picker page at `SELECT_EMBED_PATH`. Works only for an embedding page whose origin `accept` admits. */\nexport class SelectEmbedHost {\n  readonly parentOrigin: string | null\n  private readonly nonce: string | null\n  private ready = false\n  private readonly hello?: ReturnType<typeof setInterval>\n  private readonly listener = (event: MessageEvent) => this.receive(event)\n  constructor(private options: { accept: (origin: string) => boolean; onInit: (init: SelectEmbedInit) => void }) {\n    const params = new URLSearchParams(window.location.hash.slice(1))\n    this.nonce = params.get('bse')\n    let parentOrigin: string | null = null\n    try { parentOrigin = new URL(params.get('po') ?? '').origin } catch {}\n    this.parentOrigin = window.parent !== window && this.nonce && parentOrigin && options.accept(parentOrigin) ? parentOrigin : null\n    if (!this.parentOrigin) return\n    window.addEventListener('message', this.listener)\n    const hello = () => window.parent.postMessage(embedEnvelope('embed.hello', { nonce: this.nonce }, SYSDLG_EMBED), this.parentOrigin!)\n    hello()\n    this.hello = setInterval(() => { if (!this.ready) hello() }, 250)\n  }\n  private receive(event: MessageEvent): void {\n    if (event.source !== window.parent || event.origin !== this.parentOrigin || !isEmbedMessage(event.data, SYSDLG_EMBED)) return\n    const { type, payload: p } = event.data\n    if (type !== 'embed.init' || this.ready || p.nonce !== this.nonce || typeof p.locale !== 'string') return\n    this.ready = true; clearInterval(this.hello)\n    this.options.onInit({ nonce: String(p.nonce), params: p.params, theme: p.theme === 'dark' ? 'dark' : 'light', locale: p.locale })\n  }\n  private post(type: string, payload: unknown): void {\n    if (this.ready && this.parentOrigin) window.parent.postMessage(embedEnvelope(type, payload, SYSDLG_EMBED), this.parentOrigin)\n  }\n  result(result: SelectDialogResult): void { this.post('embed.result', { result }) }\n  error(code: SystemDialogErrorCode): void { this.post('embed.error', { code }) }\n  dispose(): void { clearInterval(this.hello); window.removeEventListener('message', this.listener) }\n}\n\n/**\n * Conversation embed protocol (`buckyos.conversation-embed` v1): an App shows a conversation of the user with an\n * Agent inside its own layout, rendered by the system conversation component. The App frames\n * `<systemOrigin>/embed/conversation` (component only, no shell); the handshake is the Preview embed's\n * (`embed.hello` → `embed.init`). The system page works with its own Zone-root session and derives the App from the\n * embedder's origin, never from anything the App says: no token crosses origins, and message contents never travel\n * back to the App (it reads them with its own session if it needs them).\n */\nconst CONVERSATION_EMBED = 'buckyos.conversation-embed'\nexport const CONVERSATION_EMBED_PATH = '/embed/conversation'\n/**\n * `agent`: the conversation with this Agent (the owner's default Agent when `agentDid` is left out) that this App\n * started; without one, the first message starts it. `session`: an existing conversation, when the system allows\n * this App to open it.\n */\nexport type ConversationEmbedTarget = { kind: 'agent'; agentDid?: string } | { kind: 'session'; sessionId: string }\nexport interface ConversationEmbedInit {\n  nonce: string\n  target: ConversationEmbedTarget\n  theme: 'light' | 'dark'\n  locale: string\n  /** The composer's placeholder. */\n  placeholder?: string\n}\n/** What the system page receives: `target` is untrusted input it validates itself. */\nexport type ConversationEmbedHostInit = Omit<ConversationEmbedInit, 'target'> & { target: unknown }\n/** A message the App sends in the user's name; `attachments` are content the user can read in the Zone. */\nexport interface ConversationEmbedSend { text: string; attachments?: TransferableContentRef[] }\nexport interface ConversationEmbedState {\n  status: 'loading' | 'ready' | 'error'\n  /** The conversation shown, once there is one. */\n  sessionId?: string\n  error?: string\n}\n/**\n * What the conversation in front is doing: `idle`; `running` while the Agent handles the message in front,\n * `interrupted` after a restart in the middle of it, `paused`; `answer` while a question of the Agent waits for the\n * user's answer.\n */\nexport type ConversationEmbedTurnMode = 'idle' | 'running' | 'interrupted' | 'paused' | 'answer'\nexport const CONVERSATION_EMBED_ERROR_CODES = ['invalid_params', 'not_found', 'denied'] as const\nexport type ConversationEmbedErrorCode = typeof CONVERSATION_EMBED_ERROR_CODES[number]\nconst TURN_MODES: readonly ConversationEmbedTurnMode[] = ['idle', 'running', 'interrupted', 'paused', 'answer']\nconst MAX_EMBED_TEXT = 64 * 1024\nconst MAX_EMBED_ATTACHMENTS = 32\nconst readEmbedSend = (p: Record<string, unknown>): ConversationEmbedSend | null => {\n  if (typeof p.text !== 'string' || p.text.length > MAX_EMBED_TEXT) return null\n  if (p.attachments === undefined) return { text: p.text }\n  if (!Array.isArray(p.attachments) || p.attachments.length > MAX_EMBED_ATTACHMENTS || !p.attachments.every(isTransferableRef)) return null\n  return { text: p.text, attachments: p.attachments as TransferableContentRef[] }\n}\n\n/** App side: owns the iframe that shows the system conversation. */\nexport class ConversationEmbed {\n  readonly url: string\n  private readonly nonce = crypto.randomUUID()\n  private readonly origin: string\n  private readonly listener = (event: MessageEvent) => this.receive(event)\n  private init: Omit<ConversationEmbedInit, 'nonce'>\n  private ready = false\n  private outbox: ConversationEmbedSend[] = []\n  constructor(private options: {\n    systemOrigin: string\n    frame: () => HTMLIFrameElement | null\n    init: Omit<ConversationEmbedInit, 'nonce'>\n    onState?: (state: ConversationEmbedState) => void\n    onTurn?: (mode: ConversationEmbedTurnMode) => void\n    onError?: (code: ConversationEmbedErrorCode) => void\n  }) {\n    this.origin = new URL(options.systemOrigin).origin\n    this.init = options.init\n    this.url = `${this.origin}${CONVERSATION_EMBED_PATH}#bce=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`\n    window.addEventListener('message', this.listener)\n  }\n  private post(type: string, payload: unknown): void {\n    this.options.frame()?.contentWindow?.postMessage(embedEnvelope(type, payload, CONVERSATION_EMBED), this.origin)\n  }\n  private receive(event: MessageEvent): void {\n    if (event.origin !== this.origin || event.source !== this.options.frame()?.contentWindow || !isEmbedMessage(event.data, CONVERSATION_EMBED)) return\n    const { type, payload: p } = event.data\n    if (type === 'embed.hello') {\n      if (p.nonce !== this.nonce) return\n      this.ready = true\n      this.post('embed.init', { ...this.init, nonce: this.nonce })\n      const queued = this.outbox\n      this.outbox = []\n      queued.forEach(message => this.post('embed.send', message))\n      return\n    }\n    if (type === 'embed.state' && (p.status === 'loading' || p.status === 'ready' || p.status === 'error')) {\n      this.options.onState?.({ status: p.status,\n        sessionId: typeof p.sessionId === 'string' ? p.sessionId.slice(0, 512) : undefined,\n        error: typeof p.error === 'string' ? p.error.slice(0, 128) : undefined })\n    }\n    if (type === 'embed.turn' && TURN_MODES.includes(p.mode as ConversationEmbedTurnMode)) this.options.onTurn?.(p.mode as ConversationEmbedTurnMode)\n    if (type === 'embed.error' && CONVERSATION_EMBED_ERROR_CODES.includes(p.code as ConversationEmbedErrorCode)) this.options.onError?.(p.code as ConversationEmbedErrorCode)\n  }\n  update(patch: Partial<Pick<ConversationEmbedInit, 'theme' | 'locale'>>): void {\n    this.init = { ...this.init, ...patch }\n    if (this.ready) this.post('embed.update', patch)\n  }\n  /** Sends a message in the user's name. Before the handshake it waits and goes out right after `embed.init`. */\n  send(message: ConversationEmbedSend): void {\n    const payload: ConversationEmbedSend = { text: message.text, ...(message.attachments?.length ? { attachments: message.attachments } : {}) }\n    if (this.ready) this.post('embed.send', payload)\n    else this.outbox.push(payload)\n  }\n  dispose(): void { window.removeEventListener('message', this.listener); this.outbox = [] }\n}\n\n/** System side: the component-only page at `CONVERSATION_EMBED_PATH`. Accepts one embedding App whose origin `accept` admits. */\nexport class ConversationEmbedHost {\n  readonly parentOrigin: string | null\n  private readonly nonce: string | null\n  private ready = false\n  private readonly hello?: ReturnType<typeof setInterval>\n  private readonly listener = (event: MessageEvent) => this.receive(event)\n  constructor(private options: {\n    accept: (origin: string) => boolean\n    onInit: (init: ConversationEmbedHostInit) => void\n    onUpdate?: (patch: Partial<Pick<ConversationEmbedInit, 'theme' | 'locale'>>) => void\n    onSend?: (message: ConversationEmbedSend) => void\n  }) {\n    const params = new URLSearchParams(window.location.hash.slice(1))\n    this.nonce = params.get('bce')\n    let parentOrigin: string | null = null\n    try { parentOrigin = new URL(params.get('po') ?? '').origin } catch {}\n    this.parentOrigin = window.parent !== window && this.nonce && parentOrigin && options.accept(parentOrigin) ? parentOrigin : null\n    if (!this.parentOrigin) return\n    window.addEventListener('message', this.listener)\n    const hello = () => window.parent.postMessage(embedEnvelope('embed.hello', { nonce: this.nonce }, CONVERSATION_EMBED), this.parentOrigin!)\n    hello()\n    this.hello = setInterval(() => { if (!this.ready) hello() }, 250)\n  }\n  private receive(event: MessageEvent): void {\n    if (event.source !== window.parent || event.origin !== this.parentOrigin || !isEmbedMessage(event.data, CONVERSATION_EMBED)) return\n    const { type, payload: p } = event.data\n    if (type === 'embed.init') {\n      if (this.ready || p.nonce !== this.nonce || typeof p.locale !== 'string') return\n      this.ready = true; clearInterval(this.hello)\n      this.options.onInit({ nonce: String(p.nonce), target: p.target, theme: p.theme === 'dark' ? 'dark' : 'light', locale: p.locale,\n        ...(typeof p.placeholder === 'string' ? { placeholder: p.placeholder.slice(0, 200) } : {}) })\n      return\n    }\n    if (!this.ready) return\n    if (type === 'embed.update') {\n      const patch: Partial<Pick<ConversationEmbedInit, 'theme' | 'locale'>> = {}\n      if (p.theme === 'dark' || p.theme === 'light') patch.theme = p.theme\n      if (typeof p.locale === 'string') patch.locale = p.locale\n      this.options.onUpdate?.(patch)\n    }\n    if (type === 'embed.send') {\n      const message = readEmbedSend(p)\n      if (message) this.options.onSend?.(message)\n      else this.error('invalid_params')\n    }\n  }\n  private post(type: string, payload: unknown): void {\n    if (this.ready && this.parentOrigin) window.parent.postMessage(embedEnvelope(type, payload, CONVERSATION_EMBED), this.parentOrigin)\n  }\n  state(state: ConversationEmbedState): void { this.post('embed.state', state) }\n  turn(mode: ConversationEmbedTurnMode): void { this.post('embed.turn', { mode }) }\n  error(code: ConversationEmbedErrorCode): void { this.post('embed.error', { code }) }\n  dispose(): void { clearInterval(this.hello); window.removeEventListener('message', this.listener) }\n}\n"],"names":["dialogErrorCode","value","SYSTEM_DIALOG_ERROR_CODES","includes","envelope","type","payload","extra","protocol","version","isMessage","v","PREVIEW_EMBED","embedEnvelope","isEmbedMessage","PREVIEW_EMBED_PATH","SYSDLG_EMBED","SELECT_EMBED_PATH","selectEmbedOpen","openSelectEmbed","systemOrigin","params","options","_a","signal","aborted","Promise","reject","SystemDialogError","origin","URL","locale","navigator","language","theme","_b","window","matchMedia","call","matches","zh","toLowerCase","startsWith","resolve","body","document","html","documentElement","focused","activeElement","HTMLElement","scroll","x","scrollX","y","scrollY","saved","getAttribute","siblings","Array","from","children","filter","el","map","inert","hidden","root","createElement","frame","setAttribute","style","cssText","timer","nonce","done","block","event","contains","target","stopPropagation","preventDefault","blocked","cleanup","clearTimeout","removeEventListener","receive","abort","prototype","forEach","remove","removeAttribute","scrollTo","focus","preventScroll","fail","code","showFailure","panel","text","margin","textContent","actions","button","label","action","addEventListener","append","retry","load","crypto","randomUUID","title","src","encodeURIComponent","location","setTimeout","source","contentWindow","data","p","postMessage","result","readSelectDialogResult","allowLocal","finish","once","overflow","position","top","left","right","CONVERSATION_EMBED","CONVERSATION_EMBED_PATH","CONVERSATION_EMBED_ERROR_CODES","TURN_MODES","constructor","this","listener","dialogs","Map","shellOrigin","URLSearchParams","hash","slice","get","parent","hello","appCapabilities","onOpen","onBeforeClose","onBack","helloTimer","setInterval","helloDeadline","clearInterval","m","windowId","launch","isOpenRequest","init","onInit","pending","replyTo","delete","ok","reply","id","request","_d","_c","accepted","decision","_f","_e","reason","handled","_h","_g","mode","_j","_i","onTheme","_l","_k","onLocale","_n","_m","onFocus","fallback","send","setTitle","dirty","key","JSON","stringify","requestClose","openContent","hints","newWindow","open","systemOpenUrl","appId","selectContent","shellCapabilities","SELECT_DIALOG_PATH","size","set","path","embedAbort","AbortController","dispose","clear","ready","capabilities","opens","dialogOpen","systemDialog","onSystemDialog","error","isArray","c","onReady","onTitle","onRequestClose","requestId","t","Date","now","length","push","onContentOpen","readContentHints","update","setFocused","timeout","Error","beforeClose","r","back","outbox","url","post","queued","message","status","onState","sessionId","onTurn","onError","patch","attachments","parentOrigin","accept","String","placeholder","onUpdate","every","isTransferableRef","readEmbedSend","onSend","state","turn","kind","mediaType","session","isTransferableSession","onOpenWith","onExit","Blob","blob","name","openWith","exit","candidates","ancestorOrigins","referrer","candidate","zoneHost","hostname","endsWith"],"mappings":"8NAEA,MAAMA,EAAmBC,GACvBC,4BAA0BC,SAASF,GAAkCA,EAAiC,WAclGG,EAAW,CAACC,EAAcC,EAAkBC,EAA2C,CAAA,KAAA,CACxFC,SAAU,oBAAqBC,QAAS,EAAGJ,OAAMC,aAAYC,IAC5DG,EAAaT,IACb,IAACA,GAA0B,iBAAVA,EAA2B,OAAA,EAChD,MAAMU,EAAIV,EACV,MAAsB,sBAAfU,EAAEH,UAAkD,IAAdG,EAAEF,SAAmC,iBAAXE,EAAEN,QAAuBM,EAAEL,SAAgC,iBAAdK,EAAEL,OAAY,EA2QpI,MAAMM,EAAgB,wBAChBC,EAAgB,CAACR,EAAcC,EAAkBE,EAAWI,KA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