{"version":3,"file":"sessionAsset.cjs","names":["browserTransport","sessionFileUrl","sessionApiPath"],"sources":["../../../src/web/lib/sessionAsset.ts"],"sourcesContent":["import { sessionApiPath } from '@agimon-ai/po-core/web';\nimport { browserTransport } from '@agimon-ai/po-web-security/browser';\n\nimport { sessionFileUrl } from '../../types/media';\n\nexport interface SessionAsset {\n  url: string;\n  contentType: string;\n  dispose(): void;\n}\n\n/** Fetches a session file or explicit artifact through the sealed channel and owns its short-lived browser URL. */\nexport async function loadSessionAsset(sessionId: string, relativePath: string): Promise<SessionAsset> {\n  const response = await browserTransport.fetch(sessionFileUrl(sessionId, relativePath), {\n    cache: 'no-store',\n    credentials: 'same-origin',\n  });\n  if (!response.ok) throw new Error(`The session file could not be loaded (${String(response.status)}).`);\n\n  const blob = await response.blob();\n  const url = URL.createObjectURL(blob);\n  let disposed = false;\n  return {\n    url,\n    contentType: (response.headers.get('content-type') ?? blob.type).split(';', 1)[0]?.toLowerCase() ?? '',\n    dispose() {\n      if (disposed) return;\n      disposed = true;\n      URL.revokeObjectURL(url);\n    },\n  };\n}\n\n/** Participant pictures never use a raw URL, including on a sealed remote host. */\nexport async function loadParticipantAvatar(sessionId: string, profileId: string): Promise<SessionAsset | null> {\n  const response = await browserTransport.fetch(\n    `${sessionApiPath(sessionId)}/plugins/profile/person/${encodeURIComponent(profileId)}/avatar`,\n    { cache: 'no-store', credentials: 'same-origin' },\n  );\n  if (response.status === 404) return null;\n  if (!response.ok) throw new Error(`The participant avatar could not be loaded (${String(response.status)}).`);\n  const contentType = (response.headers.get('content-type') ?? '').split(';', 1)[0]?.toLowerCase() ?? '';\n  if (!['image/png', 'image/jpeg', 'image/gif', 'image/webp'].includes(contentType)) return null;\n  const url = URL.createObjectURL(await response.blob());\n  let disposed = false;\n  return {\n    url,\n    contentType,\n    dispose() {\n      if (!disposed) URL.revokeObjectURL(url);\n      disposed = true;\n    },\n  };\n}\n\nexport interface StoredSessionAttachment {\n  path: string;\n  mimeType: string;\n  size: number;\n}\n\n/** Stores one composer file on the host through the sealed HTTP channel, so a tool can be handed its path. */\nexport async function uploadSessionAttachment(sessionId: string, file: File): Promise<StoredSessionAttachment> {\n  const response = await browserTransport.fetch(\n    `${sessionApiPath(sessionId)}/attachments?name=${encodeURIComponent(file.name)}`,\n    {\n      method: 'POST',\n      body: file,\n      credentials: 'same-origin',\n      headers: { 'content-type': file.type || 'application/octet-stream' },\n    },\n  );\n  if (!response.ok) throw new Error(`The attachment could not be uploaded (${String(response.status)}).`);\n  const { path, mimeType, size } = (await response.json()) as StoredSessionAttachment;\n  return { path, mimeType, size };\n}\n"],"mappings":";;;;;AAYA,eAAsB,iBAAiB,WAAmB,cAA6C;CACrG,MAAM,WAAW,MAAMA,mCAAAA,iBAAiB,MAAMC,cAAAA,eAAe,WAAW,YAAY,GAAG;EACrF,OAAO;EACP,aAAa;CACf,CAAC;CACD,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,yCAAyC,OAAO,SAAS,MAAM,EAAE,GAAG;CAEtG,MAAM,OAAO,MAAM,SAAS,KAAK;CACjC,MAAM,MAAM,IAAI,gBAAgB,IAAI;CACpC,IAAI,WAAW;CACf,OAAO;EACL;EACA,cAAc,SAAS,QAAQ,IAAI,cAAc,KAAK,KAAK,KAAA,CAAM,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,YAAY,KAAK;EACpG,UAAU;GACR,IAAI,UAAU;GACd,WAAW;GACX,IAAI,gBAAgB,GAAG;EACzB;CACF;AACF;;AAGA,eAAsB,sBAAsB,WAAmB,WAAiD;CAC9G,MAAM,WAAW,MAAMD,mCAAAA,iBAAiB,MACtC,IAAA,GAAGE,uBAAAA,eAAAA,CAAe,SAAS,EAAE,0BAA0B,mBAAmB,SAAS,EAAE,UACrF;EAAE,OAAO;EAAY,aAAa;CAAc,CAClD;CACA,IAAI,SAAS,WAAW,KAAK,OAAO;CACpC,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,+CAA+C,OAAO,S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