UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

59 lines (58 loc) • 2.12 kB
import { s as withReadySessionRows } from "./session-row-prepared-read-B4U_T7SO.mjs"; import { c as publicSessionMessageText, s as publicSessionMessageEntry } from "./control-ui-public-session-attachments-DauqtHb5.mjs"; import { r as readPublicSessionShare, t as isPublicSessionShareActive } from "./control-ui-public-session-read-CDIuuINn.mjs"; import { n as publicSessionTitle } from "./control-ui-public-session-render-7lgjVbUW.mjs"; import { createHash } from "node:crypto"; //#region src/gateway/control-ui-public-session-card-response.ts /** Uses the document's admission/cache owner to retain the rendered PNG bytes. */ 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; } //#endregion export { servePublicSessionCardRepresentation };