openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.18 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Uu as t,li as n,oi as r}from"./_4____________________________.js";import{gf as i,hf as a,im as o,mf as s,nm as c,rm as l}from"./_2_____________________________.js";import{Aa as u,Oa as d}from"./control-ui-boot-chat-styles-DMRbEm40.js";import{n as f,t as p}from"./_0___________________.js";function m(e){return t(t(e)?.__openclaw)?.truncated===!0}function h(e){if(e.role!==`assistant`||!Array.isArray(e.content))return!1;let n=new Set;for(let r of e.content){let e=t(r);e&&l(e.type)&&typeof e.text==`string`&&e.text.trim()&&n.add(o(e)?.phase)}return n.size>1}async function g({client:e,sessionKey:r,sessionId:o,agentId:s,isCurrent:c},l){let u=[],f=new Map,p=new Map,g=(t,n=1e3)=>e.request(`chat.history`,{sessionKey:r,agentId:s,limit:n,maxChars:5e5,offset:t}),_=async(a,o)=>{let l=i(a);if(!l||!o.sessionId||o.messages?.some(e=>e!==a&&i(e)===l))throw Error(n(`chat.historyUnavailableTitle`));let u=f.get(l);if(u)return u;let p=await e.request(`chat.message.get`,{sessionKey:r,sessionId:o.sessionId,agentId:s,messageId:l,maxChars:d});if(!c())throw Error(n(`sessionsView.copyTranscriptChanged`));let g=t(p.message);if(!p.ok||!g||m(g)||h(g))throw Error(n(`chat.historyUnavailableTitle`));return f.set(l,g),g},v=0,y;for(;;){let e=await g(v);if(!c()||o&&e.sessionId!==o||y&&(e.sessionId!==y.sessionId||e.totalMessages!==y.totalMessages))throw Error(n(`sessionsView.copyTranscriptChanged`));y??=e;let t=new Map,r=[];for(let n of e.messages??[]){let i=m(n)&&l(n)?await _(n,e):n,o=a(i);if(o){let e=(t.get(o)??0)+1;if(t.set(o,e),e<=(p.get(o)??0))continue}r.push(i)}for(let[e,n]of t)p.set(e,Math.max(n,p.get(e)??0));if(u.push(r),!e.hasMore)break;if(e.nextOffset===void 0||e.nextOffset<=v)throw Error(n(`sessionsView.copyTranscriptChanged`));v=e.nextOffset}if(u.length>1||f.size>0){let e=await g(0,1);if(!c()||e.sessionId!==y.sessionId||e.totalMessages!==y.totalMessages||e.deltaCursor!==y.deltaCursor||e.sessionInfo?.activeLeafEntryId!==y.sessionInfo?.activeLeafEntryId)throw Error(n(`sessionsView.copyTranscriptChanged`))}return u.toReversed().flat()}function _(){return(_=e((()=>{u(),c(),r(),p(),s(),f()})))()}export{g as n,_ as t};