UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.7 kB
import{c as withReadySessionRows}from"./session-row-prepared-read-B7-BN1nJ.mjs";import{c as publicSessionMessageText,s as publicSessionMessageEntry}from"./control-ui-public-session-attachments-DyRHqlMl.mjs";import{r as readPublicSessionShare,t as isPublicSessionShareActive}from"./control-ui-public-session-read-GjholTr_.mjs";import{n as publicSessionTitle}from"./control-ui-public-session-render-ms4LiI4b.mjs";import{createHash}from"node:crypto"; //!src/gateway/control-ui-public-session-card-response.ts async function servePublicSessionCardRepresentation(e){const{res:t,config:n,gate:r,locator:i,projection:a,card:o}=e;const s=await r.run({kind:`card`,publicationKey:i.shareId,sessionKey:i.sessionKey,config:n,requestKey:JSON.stringify([`card`,createHash(`sha256`).update(e.token).digest(`base64url`),e.host]),work:async()=>{const t=await readPublicSessionShare(n,i,{projection:a,card:true,pullRequests:o.pullRequests});if(!t)return null;const r=t.messages.map(e=>{const t=publicSessionMessageEntry(e);return t?.role===`user`?publicSessionMessageText(t):void 0}).find(e=>e);return o.render({...t.cardFacts,title:publicSessionTitle(t.title),quote:r,messageCount:t.totalMessages,host:e.host})},consume:e=>withReadySessionRows(a,()=>[{key:i.sessionKey,agentId:i.agentId}],()=>{if(!e||!Buffer.isBuffer(e.body)||!isPublicSessionShareActive(n,i,a))return`fallback`;if(!e.isCurrent())return false;const r=e.body;t.statusCode=200;t.setHeader(`Cache-Control`,`public, max-age=300`);t.setHeader(`Content-Type`,`image/png`);t.setHeader(`Content-Length`,r.byteLength);t.end(r);return`served`})});if(s.kind!==`ok`||s.value===`fallback`)await o.fallback();return true}export{servePublicSessionCardRepresentation};