{"version":3,"file":"useNewSessionActions.mjs","names":[],"sources":["../../../../src/web/features/sessions/useNewSessionActions.ts"],"sourcesContent":["import { t, type LaunchProfileCatalog, type LaunchSelection } from '@agimon-ai/po-core/web';\nimport { useNavigate } from '@tanstack/react-router';\n\nimport { listLaunchProfiles } from '../../lib/hubApi';\nimport { createGeneralSession, createPlainSession } from '../../stores/newSessionStore';\nimport { waitForSession } from '../../stores/sessionsStore';\n\n/**\n * Shared ways to finish a new-session dialog: create a plain session in the\n * workspace root, or open one another package created. Both resolve an error\n * message to show, or undefined once the dialog closed and the session is open.\n * `createPlain` takes the launcher's profile choice when its caller holds one;\n * without it the dialog's own draft decides. A workspace-free session has no\n * profile list to offer, so `loadProfiles` exists only for a workspace.\n */\nexport function useNewSessionActions(workspaceId: string | null, onClose: () => void, hostId?: string) {\n  const navigate = useNavigate();\n\n  const openCreated = async (sessionId: string): Promise<string | undefined> => {\n    if (!(await waitForSession(sessionId)))\n      return t(\n        'webDashboard.newSession.notYetVisible',\n        'The session was created but has not appeared yet; it will show up in the rail.',\n      );\n    onClose();\n    await navigate({ to: '/session/$sessionId', params: { sessionId } });\n    return undefined;\n  };\n\n  const createPlain = async (name?: string, selection?: LaunchSelection): Promise<string | undefined> => {\n    const outcome =\n      workspaceId === null\n        ? await createGeneralSession(name, hostId, selection)\n        : await createPlainSession(workspaceId, name, selection);\n    if (!('sessionId' in outcome)) return outcome.error;\n    onClose();\n    await navigate({ to: '/session/$sessionId', params: { sessionId: outcome.sessionId } });\n    return undefined;\n  };\n\n  const loadProfiles =\n    workspaceId === null\n      ? undefined\n      : (signal?: AbortSignal): Promise<LaunchProfileCatalog> => listLaunchProfiles(workspaceId, signal);\n\n  return { createPlain, openCreated, ...(loadProfiles === undefined ? {} : { loadProfiles }) };\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,qBAAqB,aAA4B,SAAqB,QAAiB;CACrG,MAAM,WAAW,YAAY;CAE7B,MAAM,cAAc,OAAO,cAAmD;EAC5E,IAAI,CAAE,MAAM,eAAe,SAAS,GAClC,OAAO,EACL,yCACA,gFACF;EACF,QAAQ;EACR,MAAM,SAAS;GAAE,IAAI;GAAuB,QAAQ,EAAE,UAAU;EAAE,CAAC;CAErE;CAEA,MAAM,cAAc,OAAO,MAAe,cAA6D;EACrG,MAAM,UACJ,gBAAgB,OACZ,MAAM,qBAAqB,MAAM,QAAQ,SAAS,IAClD,MAAM,mBAAmB,aAAa,MAAM,SAAS;EAC3D,IAAI,EAAE,eAAe,UAAU,OAAO,QAAQ;EAC9C,QAAQ;EACR,MAAM,SAAS;GAAE,IAAI;GAAuB,QAAQ,EAAE,WAAW,QAAQ,UAAU;EAAE,CAAC;CAExF;CAEA,MAAM,eACJ,gBAAgB,OACZ,KAAA,KACC,WAAwD,mBAAmB,aAAa,MAAM;CAErG,OAAO;EAAE;EAAa;EAAa,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;CAAG;AAC7F"}