{"version":3,"file":"app-frame.mjs","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":["_a"],"mappings":";;;;AAEA,MAAM,kBAAkB,CAAC,UACvB,0BAA0B,SAAS,KAA8B,IAAI,QAAiC;AAcxG,MAAM,WAAW,CAAC,MAAc,SAAkB,QAA2C,CAAA,OAC1F,EAAE,UAAU,qBAAqB,SAAS,GAAG,MAAM,SAAS,GAAG,MAAM;AACxE,MAAM,YAAY,CAAC,UAA6C;AAC1D,MAAA,CAAC,SAAS,OAAO,UAAU;AAAiB,WAAA;AAChD,QAAM,IAAI;AACV,SAAO,EAAE,aAAa,uBAAuB,EAAE,YAAY,KAAK,OAAO,EAAE,SAAS,YAAY,CAAC,CAAC,EAAE,WAAW,OAAO,EAAE,YAAY;AACpI;AACO,MAAM,aAAa;AAAA,EAMxB,YAAoB,SAQjB;AARiB,SAAA,UAAA;AALZ,SAAA,QAAA;AACR,SAAA,eAAyB;AACjB,SAAA,8BAAc;AACtB,SAAQ,WAAW,CAAC,UAAwB,KAAK,QAAQ,KAAK;AAC9D,SAAQ,QAAkB;AAW1B,SAAQ,aAAa;AAFT,WAAA,iBAAiB,WAAW,KA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