openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.06 kB
JavaScript
import{h as readRuntimeConfig}from"./runtime-snapshot-Bg5K4JNu.mjs";import{r as parseInboundMediaUri}from"./inbound-media-uri-COqbYFEq.mjs";import{r as resolveRequestedSessionAgentId}from"./session-request-agent-DmeXmT1P.mjs";import"./config-DkZ8y8Gv.mjs";import{t as loadGatewaySessionEntryReadOnlyInWorker}from"./session-utils-store-worker-43BDHG7V.mjs";import{l as readMediaBuffer}from"./store-wPqhY4JR.mjs";import"./media-reference-CVYMjRlF.mjs";import{l as readManagedOutgoingImageThumbnail,s as parseManagedOutgoingRoute}from"./managed-image-attachments-CDCJnrtW.mjs";import{n as MANAGED_OUTGOING_IMAGE_ARTIFACT_ID_PREFIX}from"./managed-outgoing-artifact-id-DA2vgwrY.mjs";import{n as decodeTuiImageData,r as prepareTuiImage,t as TUI_IMAGE_MAX_BYTES}from"./tui-image-data-vKfeGSc1.mjs";
//!src/tui/embedded-image-loader.ts
async function loadEmbeddedImage(e){const{signal:t}=e;t.throwIfAborted();const n=decodeTuiImageData(e.source);if(n)return await prepareTuiImage(n,t);const r=resolveRequestedSessionAgentId(readRuntimeConfig(),e.sessionKey,e.agentId);if(!r.ok)throw new Error(r.error.message);const{canonicalKey:i,agentId:a,entry:o}=await loadGatewaySessionEntryReadOnlyInWorker({cfg:readRuntimeConfig(),key:e.sessionKey,agentId:r.agentId});if(!o?.sessionId)throw new Error(`Image session is unavailable`);const s=parseInboundMediaUri(e.source);if(s){const{buffer:e}=await readMediaBuffer(s.id,`inbound`,TUI_IMAGE_MAX_BYTES);return await prepareTuiImage(e,t)}const c=e.source.startsWith(`/api/chat/media/outgoing/`)?parseManagedOutgoingRoute(e.source):null;if(!c||c.sessionKey!==i)throw new Error(`Image source is not managed by this session`);const l=`${MANAGED_OUTGOING_IMAGE_ARTIFACT_ID_PREFIX}${c.attachmentId}`;if(e.artifactId&&e.artifactId!==l)throw new Error(`Image artifact does not match its source`);const u=await readManagedOutgoingImageThumbnail({sessionKey:i,agentId:a,artifactId:l,maxBytes:TUI_IMAGE_MAX_BYTES,signal:t});if(!u)throw new Error(`Image artifact is unavailable`);return await prepareTuiImage(u,t)}export{loadEmbeddedImage};