{"version":3,"file":"SettingsPanelHost.mjs","names":[],"sources":["../../../src/web/components/SettingsPanelHost.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/web';\nimport { SettingsDescription, SettingsHeader, SettingsPage, SettingsTitle } from '@agimon-ai/po-web-components';\nimport {\n  browserTransport,\n  browserTransportForHost,\n  fetchWithStepUp,\n  fetchWithStepUpForHost,\n} from '@agimon-ai/po-web-security/browser';\nimport { useStore } from '@tanstack/react-store';\nimport { useCallback, useMemo } from 'react';\n\nimport { defaultHostId, splitHostId } from '../lib/hostIdentity';\nimport type { InstalledSettingsPanel } from '../lib/pluginRegistry';\nimport { liveSessionOptions } from '../lib/sessionRailModel';\nimport { sessionsStore } from '../stores/sessionsStore';\nimport { workspacesStore } from '../stores/workspacesStore';\n\n/**\n * The frame around a settings page a package draws itself.\n *\n * The host keeps the heading here rather than leaving it to the plugin, so a\n * self-drawn page carries the same label and detail the menu showed and the\n * reader does not have to trust each package to repeat them. Everything below\n * the heading belongs to the package.\n *\n * The transport is the host's for the same reason the repository panel's is:\n * only the host knows whether the page is being read over a tunnel, and a\n * plugin calling bare fetch would send plaintext to the relay.\n */\n\nconst requestThroughHost = (input: string, init?: RequestInit): Promise<Response> =>\n  browserTransport.fetch(input, init);\n\ninterface SettingsPanelHostProps {\n  panel: InstalledSettingsPanel;\n}\n\nexport function SettingsPanelHost({ panel }: SettingsPanelHostProps) {\n  const t = useT();\n  const Panel = panel.component;\n  const hostId = splitHostId(panel.pluginId)?.hostId ?? defaultHostId();\n  const owner = splitHostId(panel.pluginId)?.localId ?? panel.pluginId;\n  const request = useMemo(\n    () => (hostId === undefined ? requestThroughHost : browserTransportForHost(hostId).fetch),\n    [hostId],\n  );\n  const requestWithStepUp = useMemo(\n    () => (hostId === undefined ? fetchWithStepUp : fetchWithStepUpForHost(hostId)),\n    [hostId],\n  );\n  const order = useStore(sessionsStore, (state) => state.order);\n  const byId = useStore(sessionsStore, (state) => state.byId);\n  const activeSessionId = useStore(sessionsStore, (state) => state.activeId);\n  const workspaces = useStore(workspacesStore, (state) => state.byId);\n  // A new function whenever the list changes, so a panel that reads it renders the change.\n  const listSessions = useCallback(\n    () => liveSessionOptions({ order, byId }, workspaces, null, undefined, Date.now()),\n    [order, byId, workspaces],\n  );\n  return (\n    <SettingsPage data-testid={`settings-panel-${panel.id}`}>\n      <SettingsHeader>\n        <SettingsTitle>{t(`plugin.${owner}.settingsPanels.${panel.id}.label`, panel.label)}</SettingsTitle>\n        {panel.detail ? (\n          <SettingsDescription>\n            {t(`plugin.${owner}.settingsPanels.${panel.id}.detail`, panel.detail)}\n          </SettingsDescription>\n        ) : null}\n      </SettingsHeader>\n      <Panel\n        key={hostId ?? 'local'}\n        request={request}\n        requestWithStepUp={requestWithStepUp}\n        listSessions={listSessions}\n        activeSessionId={activeSessionId}\n      />\n    </SettingsPage>\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,sBAAsB,OAAe,SACzC,iBAAiB,MAAM,OAAO,IAAI;AAMpC,SAAgB,kBAAkB,EAAE,SAAiC;CACnE,MAAM,IAAI,KAAK;CACf,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,YAAY,MAAM,QAAQ,CAAC,EAAE,UAAU,cAAc;CACpE,MAAM,QAAQ,YAAY,MAAM,QAAQ,CAAC,EAAE,WAAW,MAAM;CAC5D,MAAM,UAAU,cACP,WAAW,KAAA,IAAY,qBAAqB,wBAAwB,MAAM,CAAC,CAAC,OACnF,CAAC,MAAM,CACT;CACA,MAAM,oBAAoB,cACjB,WAAW,KAAA,IAAY,kBAAkB,uBAAuB,MAAM,GAC7E,CAAC,MAAM,CACT;CACA,MAAM,QAAQ,SAAS,gBAAgB,UAAU,MAAM,KAAK;CAC5D,MAAM,OAAO,SAAS,gBAAgB,UAAU,MAAM,IAAI;CAC1D,MAAM,kBAAkB,SAAS,gBAAgB,UAAU,MAAM,QAAQ;CACzE,MAAM,aAAa,SAAS,kBAAkB,UAAU,MAAM,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