{"version":3,"file":"pluginCompositions.mjs","names":[],"sources":["../../../src/web/lib/pluginCompositions.ts"],"sourcesContent":["import type { WebPluginMount } from '@agimon-ai/po-core/web';\nimport { Store } from '@tanstack/store';\n\nimport { traceStore } from './uiTrace';\n\nexport type WebPluginCompositionPhase = 'idle' | 'loading' | 'ready' | 'error';\nexport interface WebPluginMountState {\n  phase: WebPluginCompositionPhase;\n  error?: string;\n}\n/** The server's launch-context template choice; it survives navigation and reconnects. */\nexport interface WebTemplateDecision {\n  id?: string;\n  /** `web.backdrop`: `none` or `<pluginId>/<fillId>`; unset means Po's default background. */\n  backdrop?: string;\n  mount: Extract<WebPluginMount, { scope: 'host' | 'workspace' }>;\n}\nexport interface WebPluginCompositionState extends WebPluginMountState {\n  mounts: Record<string, WebPluginMountState>;\n  template?: WebTemplateDecision;\n  templateError?: string;\n}\n\n/** Readiness belongs to the verified host, not a mounted dashboard. */\nexport const webPluginCompositionStore = traceStore(\n  'pluginCompositions',\n  new Store<WebPluginCompositionState>({ phase: 'idle', mounts: {} }),\n);\n\nlet refresh: (() => Promise<void>) | undefined;\nlet retry: (() => Promise<void>) | undefined;\nlet focusWorkspace: ((workspaceId: string | null) => Promise<void>) | undefined;\nlet reloadTemplate: (() => Promise<void>) | undefined;\n\n/** The client binds its verified composition loader once at bootstrap. */\nexport function bindWebPluginCompositions(actions: {\n  refresh: () => Promise<void>;\n  retry: () => Promise<void>;\n  focusWorkspace: (workspaceId: string | null) => Promise<void>;\n  reloadTemplate: () => Promise<void>;\n}): void {\n  refresh = actions.refresh;\n  retry = actions.retry;\n  focusWorkspace = actions.focusWorkspace;\n  reloadTemplate = actions.reloadTemplate;\n}\n\nexport function refreshWebPluginCompositions(): Promise<void> {\n  return refresh?.() ?? Promise.reject(new Error('The dashboard runtime has not started.'));\n}\n\nexport function retryWebPluginCompositions(): Promise<void> {\n  return retry?.() ?? Promise.reject(new Error('The dashboard runtime has not started.'));\n}\n\nexport function focusWorkspaceWebPlugins(workspaceId: string | null): Promise<void> {\n  return focusWorkspace?.(workspaceId) ?? Promise.reject(new Error('The dashboard runtime has not started.'));\n}\n\n/** Only explicit Settings actions re-read the server's launch-context choice. */\nexport function reloadWebTemplateDecision(): Promise<void> {\n  return reloadTemplate?.() ?? Promise.reject(new Error('The dashboard runtime has not started.'));\n}\n\nexport function webPluginMountState(\n  mount: WebPluginMount,\n  state: WebPluginCompositionState = webPluginCompositionStore.state,\n): WebPluginMountState {\n  const host = state.mounts.host ?? { phase: state.phase, error: state.error };\n  if (mount.scope === 'host' || host.phase !== 'ready') return host;\n  const workspace = state.mounts[`workspace:${mount.workspaceId}`];\n  if (workspace === undefined) {\n    if (state.phase === 'idle' || state.phase === 'loading') return { phase: 'loading' };\n    return { phase: 'error', error: `No synchronized web composition exists for workspace:${mount.workspaceId}.` };\n  }\n  if (mount.scope === 'workspace' || workspace.phase !== 'ready') return workspace;\n  return state.mounts[`session:${mount.sessionId}`] ?? { phase: 'loading' };\n}\n"],"mappings":";;;;AAwBA,MAAa,4BAA4B,WACvC,sBACA,IAAI,MAAiC;CAAE,OAAO;CAAQ,QAAQ,CAAC;AAAE,CAAC,CACpE;AAEA,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;;AAGJ,SAAgB,0BAA0B,SAKjC;CACP,UAAU,QAAQ;CAClB,QAAQ,QAAQ;CAChB,iBAAiB,QAAQ;CACzB,iBAAiB,QAAQ;AAC3B;AAEA,SAAgB,+BAA8C;CAC5D,OAAO,UAAU,KAAK,QAAQ,uBAAO,IAAI,MAAM,wCAAwC,CAAC;AAC1F;AAEA,SAAgB,6BAA4C;CAC1D,OAAO,QAAQ,KAAK,QAAQ,uBAAO,IAAI,MAAM,wCAAwC,CAAC;AACxF;AAEA,SAAgB,yBAAyB,aAA2C;CAClF,OAAO,iBAAiB,WAAW,KAAK,QAAQ,uBAAO,IAAI,MAAM,wCAAwC,CAAC;AAC5G;;AAGA,SAAgB,4BAA2C;CACzD,OAAO,iBAAiB,KAAK,QAAQ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