UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.09 kB
import{i as e}from"./transcript-record-coerce-CPLgmAk9.mjs";import{a as t}from"./transcript-string-coerce-DTk-8HSr.mjs";import{n}from"./transcript-json-utf8-bytes-CWHhKtrl.mjs";import{o as r}from"./transcript-chat-display-projection.core-B2Q8dHzN.mjs";async function projectChatHistoryWithReplies(t,r){let i=[],a=t.map(t=>{let n=e(e(t.__openclaw)?.replyToMessage),r=e(n?.message);return r?{reply:n,index:i.push(r)-1}:void 0}),o=await r([...t,...i]),s=o.slice(0,t.length);for(let[r,i]of s.entries()){let c=a[r];if(!c)continue;let l=o[t.length+c.index];s[r]={...i,__openclaw:{...e(i.__openclaw),replyToMessage:n(l)>8192?{ok:!1,unavailableReason:`oversized`}:{...c.reply,message:l}}}}return s}function readChatHistoryReplyMessageId(n){let r=e(n);return t(e(r?.__openclaw)?.replyToId)??(r?.role===`assistant`?t(e(r.openclawDelivery)?.replyToId):void 0)}async function attachChatHistoryReplyMessages(t,i,a){let o=/* @__PURE__ */ new Map,s=[];for(let c of t){let t=e(c),l=e(t?.__openclaw),u=readChatHistoryReplyMessageId(c);if(!t||!u||!i.sessionId){s.push(c);continue}let d=o.get(u);if(!d&&u.startsWith(`pending:`)&&(d={ok:!1,unavailableReason:`not_found`}),!d){let e=await a.readers.readSessionMessageByIdAsync({agentId:i.sessionAgentId,sessionId:i.sessionId,sessionKey:i.canonicalKey,storePath:i.storePath,sessionEntry:i.entry},u,{allowResetArchiveFallback:!0,historyVisibility:{sessionStartedAt:i.entry?.sessionStartedAt}}),t=e.message?r(e.message,{maxChars:500,includePluginSteering:i.includePluginSteering,subagentCoordination:a.readers.subagentCoordination,resolveCronJobName:a.resolveCronJobName,...a.deferProfileDisplay?{}:{resolveCurrentUserProfileDisplay:a.resolveCurrentUserProfileDisplay}}):void 0,s=t?{...t}:void 0;s&&(delete s.provider,delete s.model),d=e.oversized||s&&n(s)>8192?{ok:!1,unavailableReason:`oversized`}:s?{ok:!0,message:s}:{ok:!1,unavailableReason:e.found?`not_visible`:`not_found`},o.set(u,d)}s.push({...t,__openclaw:{...l,replyToMessage:d}})}return s}export{projectChatHistoryWithReplies as n,readChatHistoryReplyMessageId as r,attachChatHistoryReplyMessages as t};