{"version":3,"file":"SessionRailDialogs.mjs","names":["HOST_SLOTS"],"sources":["../../../../src/web/features/sessions/SessionRailDialogs.tsx"],"sourcesContent":["import { useT, type WebPluginSlotProps } from '@agimon-ai/po-core/web';\nimport { useProfileCatalog } from '@agimon-ai/po-web-components';\nimport { fetchWithStepUp } from '@agimon-ai/po-web-security/browser';\nimport { useStore } from '@tanstack/react-store';\nimport { createElement, type ComponentType, useState } from 'react';\n\nimport { listLaunchProfiles } from '../../lib/hubApi';\nimport { HOST_SLOTS, workspaceSlotFills } from '../../lib/pluginRegistry';\nimport { botCoordinatorBlocked, sessionMoveTarget } from '../../lib/sessionRailModel';\nimport { closeNewSession, newSessionStore } from '../../stores/newSessionStore';\nimport {\n  closeMoveSessionDialog,\n  moveDashboardSession,\n  closeCoordinatorProfile,\n  closeResumeDialog,\n  closeSessionSharing,\n  createBotWithProfile,\n  railDialogStore,\n  setBotActAsCoordinator,\n  setCoordinatorProfile,\n  setCoordinatorProfileForm,\n  updateCoordinatorProfileDraft,\n  saveCoordinatorProfile,\n  type RailDialogState,\n} from '../../stores/railDialogStore';\nimport { sessionsStore } from '../../stores/sessionsStore';\nimport { usePluginSlotProps } from '../../stores/usePluginSlotProps';\nimport { useWebPluginRegistry } from '../../stores/useWebPluginRegistry';\nimport { workspacesStore } from '../../stores/workspacesStore';\nimport { SessionSharing } from '../session/SessionSharing';\nimport { CoordinatorProfileDialog } from './CoordinatorProfileDialog';\nimport { MoveSessionDialog } from './MoveSessionDialog';\nimport { NewSessionDialog } from './NewSessionDialog';\nimport { ResumeSessionDialog } from './ResumeSessionDialog';\nimport { useNewSessionActions } from './useNewSessionActions';\n\n/** A workspace plugin's replacement for the new-session dialog, handed the host's create helpers. */\nfunction PluginNewSessionDialog({\n  component,\n  workspaceId,\n  workspaceRoot,\n}: {\n  component: ComponentType<WebPluginSlotProps>;\n  workspaceId: string;\n  workspaceRoot: string;\n}) {\n  const props = usePluginSlotProps(null);\n  const actions = useNewSessionActions(workspaceId, closeNewSession);\n  return createElement(component, {\n    ...props,\n    newSession: { workspaceId, workspaceRoot, close: closeNewSession, requestWithStepUp: fetchWithStepUp, ...actions },\n  });\n}\n\nfunction CoordinatorProfilePrompt({ draft }: { draft: NonNullable<RailDialogState['coordinator']> }) {\n  const t = useT();\n  const [attempt, setAttempt] = useState(0);\n  const catalog = useProfileCatalog(\n    JSON.stringify([draft.workspaceId, draft.hostId, attempt, draft.profileRevision]),\n    (signal) => listLaunchProfiles(draft.workspaceId, signal, draft.hostId),\n  );\n  const workspacesById = useStore(workspacesStore, (state) => state.byId);\n  const workspace = draft.workspaceId === undefined ? undefined : workspacesById[draft.workspaceId];\n  const blocked = useStore(sessionsStore, (state) =>\n    botCoordinatorBlocked(\n      draft,\n      workspacesById,\n      Object.values(state.byId).map(({ summary }) => summary),\n    ),\n  );\n  return (\n    <CoordinatorProfileDialog\n      profiles={catalog?.profiles ?? []}\n      status={catalog?.status ?? 'unavailable'}\n      profile={draft.profile}\n      workspaceName={\n        draft.workspaceId === undefined\n          ? undefined\n          : (workspace?.name ??\n            workspace?.root.split('/').pop() ??\n            t('webDashboard.common.thisWorkspace', 'this workspace'))\n      }\n      actAsCoordinator={draft.actAsCoordinator === true}\n      coordinatorBlocked={blocked}\n      pending={draft.pending}\n      error={draft.error}\n      savedProfile={draft.profileRevision ? draft.profile : undefined}\n      profileForm={\n        draft.editingProfile && draft.profileDraft\n          ? {\n              value: draft.profileDraft,\n              onChange: updateCoordinatorProfileDraft,\n              onBack: () => setCoordinatorProfileForm(false),\n              onSave: () => {\n                void saveCoordinatorProfile();\n              },\n            }\n          : undefined\n      }\n      onProfile={setCoordinatorProfile}\n      onActAsCoordinator={setBotActAsCoordinator}\n      onNewProfile={() => setCoordinatorProfileForm(true)}\n      onCreate={() => {\n        void createBotWithProfile(blocked);\n      }}\n      onRetry={() => setAttempt((value) => value + 1)}\n      onClose={closeCoordinatorProfile}\n    />\n  );\n}\n/**\n * The rail's dialogs that call their own APIs. Rendered beside the template, not\n * inside it, so they open even while a drawer template has its rail closed.\n * Adding a workspace is the template's own dialog. A workspace plugin's\n * `new-session` fill stands in for the host's new-session dialog.\n */\nexport function SessionRailDialogs() {\n  const t = useT();\n  useWebPluginRegistry();\n  const creating = useStore(newSessionStore, (state) => state);\n  const workspacesById = useStore(workspacesStore, (state) => state.byId);\n  const resume = useStore(railDialogStore, (state) => state.resume);\n  const move = useStore(railDialogStore, (state) => state.move);\n  const sharing = useStore(railDialogStore, (state) => state.sharing);\n  const session = useStore(sessionsStore, (state) => (move ? state.byId[move.sessionId]?.summary : undefined));\n  const workspaceOrder = useStore(workspacesStore, (state) => state.order);\n  const moveTarget = session ? sessionMoveTarget(session, workspacesById, workspaceOrder) : undefined;\n  const coordinator = useStore(railDialogStore, (state) => state.coordinator);\n  const targetWorkspace = creating.workspaceId === null ? undefined : workspacesById[creating.workspaceId];\n  const replacement =\n    targetWorkspace === undefined\n      ? undefined\n      : workspaceSlotFills(targetWorkspace.id, HOST_SLOTS.newSession).find((fill) => fill.component !== undefined);\n  return (\n    <>\n      {sharing ? <SessionSharing key={sharing} sessionId={sharing} onClose={closeSessionSharing} /> : null}\n      {move && session ? (\n        <MoveSessionDialog\n          key={move.sessionId}\n          name={session.name}\n          workspaceName={moveTarget?.workspaceName ?? t('webDashboard.common.thisWorkspace', 'this workspace')}\n          destinations={moveTarget?.destinations ?? []}\n          blocked={!moveTarget || moveTarget.blocked}\n          moving={move.pending}\n          error={move.error}\n          onClose={closeMoveSessionDialog}\n          onMove={(workspaceId) => {\n            if (\n              moveTarget &&\n              !moveTarget.blocked &&\n              moveTarget.destinations.some((workspace) => workspace.id === workspaceId)\n            )\n              void moveDashboardSession(workspaceId);\n          }}\n        />\n      ) : null}\n      {creating.open && creating.kind === 'general' ? (\n        <NewSessionDialog key={`general:${creating.hostId ?? ''}`} hostId={creating.hostId} onClose={closeNewSession} />\n      ) : creating.open && targetWorkspace !== undefined ? (\n        replacement?.component !== undefined ? (\n          <PluginNewSessionDialog\n            key={`${replacement.pluginId}:${replacement.id}`}\n            component={replacement.component}\n            workspaceId={targetWorkspace.id}\n            workspaceRoot={targetWorkspace.root}\n          />\n        ) : (\n          <NewSessionDialog\n            workspaceId={targetWorkspace.id}\n            workspaceRoot={targetWorkspace.root}\n            onClose={closeNewSession}\n          />\n        )\n      ) : null}\n      {coordinator === null ? null : (\n        <CoordinatorProfilePrompt\n          key={JSON.stringify([coordinator.workspaceId, coordinator.hostId])}\n          draft={coordinator}\n        />\n      )}\n      {resume === null ? null : 'sessionId' in resume ? (\n        <ResumeSessionDialog sessionId={resume.sessionId} onClose={closeResumeDialog} />\n      ) : (\n        <ResumeSessionDialog workspaceId={resume.workspaceId} onClose={closeResumeDialog} />\n      )}\n    </>\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAS,uBAAuB,EAC9B,WACA,aACA,iBAKC;CACD,MAAM,QAAQ,mBAAmB,IAAI;CACrC,MAAM,UAAU,qBAAqB,aAAa,eAAe;CACjE,OAAO,cAAc,WAAW;EAC9B,GAAG;EACH,YAAY;GAAE;GAAa;GAAe,OAAO;GAAiB,mBAAmB;GAAiB,GAAG;EAAQ;CACnH,CAAC;AACH;AAEA,SAAS,yBAAyB,EAAE,SAAiE;CACnG,MAAM,IAAI,KAAK;CACf,MAAM,CAAC,SAAS,cAAc,SAAS,CAAC;CACxC,MAAM,UAAU,kBACd,KAAK,UAAU;EAAC,MAAM;EAAa,MAAM;EAAQ;EAAS,MAAM;CAAe,CAAC,IAC/E,WAAW,mBAAmB,MAAM,aAAa,QAAQ,MAAM,MAAM,CACxE;CACA,MAAM,iBAAiB,SAAS,kBAAkB,UAAU,MAAM,IAAI;CACtE,MAAM,YAAY,MAAM,gBAAgB,KAAA,IAAY,KAAA,IAAY,eAAe,MAAM;CACrF,MAAM,UAAU,SAAS,gBAAgB,UACvC,sBACE,OACA,gBACA,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,cAAc,OAAO,C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