openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
32 lines • 6.98 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Eo as t,Ic as n,Io as r,Lc as i,Nu as a,Pu as o,eu as s,ju as c,kl as l,zl as u,zu as d}from"./control-ui-core-CBJ5efDh.js";import{ca as f,sa as p}from"./control-ui-core-DtLivg_r.js";import{G as m,J as h,W as g,Z as _,at as v,rt as y}from"./lit-runtime-IOnANfcZ.js";import{Jr as b,Lr as x,Ma as S,Zr as C,ja as w,zr as T}from"./control-ui-boot-shared-UG5ko-VG.js";import{Zr as E,wa as D}from"./ui-CmSP4d14.js";import{D as O,T as k}from"./control-ui-boot-shared-VLPz5vN2.js";import{bt as A,vt as j}from"./control-ui-boot-shared-XreXSF7h.js";import{_c as M,vc as N}from"./control-ui-boot-shared-dOnP4mAA.js";import{n as P}from"./agent-avatar-DPLn2tSe.js";import{L as F,R as I,h as L,v as R}from"./control-ui-boot-chat-CmENwCKi.js";import"./control-ui-boot-chat-styles-BcslGtWC.js";var z;function B(){return(B=e((()=>{g(),_(),k(),P(),f(),j(),I(),L(),o(),C(),x(),S(),t(),l(),a(),i(),M(),z=class extends c{constructor(){super(),this.session=null,this.gateway=null,this.presented=!1,this.agents=[],this.agentIdentity=null,this.avatarAgentIds=new Set,this.history=null,this.loading=!1,this.error=!1,this.requestKey=``,this.requestGateway=null,this.generation=0,this.pending=!1,this.dirty=!1,this.progress=new F(this,{gateway:()=>this.presented?this.gateway:void 0,target:()=>this.presented?this.session:void 0}),this.retry=()=>{this.dirty=!0,this.progress.retry(),this.requestUpdate()},new n(this).watchStore(()=>this.presented?this.agentIdentity:null).watchStore(()=>this.presented?this.gateway:null,e=>{e===this.gateway&&this.synchronizeHistory()}).effect(()=>this.presented?this.gateway:null,e=>e.subscribeEvents(t=>{if(t.event!==`sessions.changed`&&t.event!==`session.message`)return;let n=r(t.payload),i=this.session;n&&i&&this.presented&&s({...e.snapshot,sessionKey:i.sessionKey,assistantAgentId:i.agentId??e.snapshot.assistantAgentId},n.key,n.agentId)&&(this.dirty=!0,this.requestUpdate())}))}willUpdate(){this.synchronizeHistory()}synchronizeHistory(){let e=this.gateway?.snapshot,t=e?.phase===`connected`?e.client:null,n=this.session,r=this.presented&&this.isConnected&&t&&n?JSON.stringify([n.sessionKey,n.agentId,this.gateway?.connectionRevision]):``;if((r!==this.requestKey||t!==this.requestClient||this.gateway!==this.requestGateway)&&(this.requestGateway=this.gateway,this.requestKey=r,this.requestClient=t,++this.generation,this.pending=!1,this.dirty=!!r,this.history=null,this.error=!1,this.loading=!!r),!r||!t||!n||this.pending||!this.dirty)return;this.dirty=!1,this.pending=!0,this.error=!1;let i=this.generation,a=this.gateway,o=a?.connectionRevision,s=()=>i===this.generation&&this.isConnected&&this.presented&&this.gateway===a&&a?.snapshot.phase===`connected`&&a.snapshot.client===t&&a.connectionRevision===o&&this.session?.sessionKey===n.sessionKey&&this.session?.agentId===n.agentId;t.request(`chat.history`,{...n,toolResultMaxChars:2e3,limit:20,maxChars:12e3}).then(e=>{s()&&(this.history=e)}).catch(()=>{s()&&(this.error=!0)}).finally(()=>{s()&&(this.pending=!1,this.loading=!1,this.dirty&&this.requestUpdate())})}disconnectedCallback(){++this.generation,this.requestKey=``,this.requestClient=void 0,super.disconnectedCallback()}updated(){this.presented&&this.isConnected&&this.agentIdentity?.ensure([...this.avatarAgentIds])}render(){if(this.avatarAgentIds.clear(),!this.presented)return m;if(this.gateway?.snapshot.phase!==`connected`)return h`<p role="status">${d(`pluginUi.sessionHistoryUnavailable`)}</p>`;let e=this.progress.card,t=this.history?.sessionInfo,n=(this.history?.messages??[]).slice(-20).flatMap(e=>{if(!D(e)||e.role!==`user`&&e.role!==`assistant`)return[];let t=b(e);if(!t)return[];let n=T({role:e.role,content:t}).content.flatMap(e=>e.type===`text`&&e.text?[e.text]:[]).join(`
`);if(!n)return[];let r=T(e),i=r.sender,a=r.senderSession?.agentId??u(r.senderSession?.sessionKey)?.agentId,o=r.senderSession?a:e.role===`assistant`?this.session?.agentId??u(this.session?.sessionKey)?.agentId:void 0,s=o?this.agents.find(e=>e.id===o):void 0,c=w(i)??s?.name??s?.identity?.name??(o||d(e.role===`user`?`sessionsView.user`:`sessionsView.assistant`));!i&&o&&this.avatarAgentIds.add(o);let l=i?N(i):o?h`<openclaw-agent-avatar
.option=${{value:o,label:c,agent:s??{id:o}}}
.identity=${this.agentIdentity?.get(o)??null}
></openclaw-agent-avatar>`:h`<span class="plugin-session-summary__unknown" aria-hidden="true"
>${e.role===`user`?p.users:p.bot}</span
>`,f=typeof e.timestamp==`number`&&Number.isFinite(e.timestamp)?new Date(e.timestamp):null;return[{text:n,label:c,avatar:l,time:f&&Number.isFinite(f.getTime())?f:null}]});return h`<div class="plugin-session-summary">
${this.progress.error||this.progress.loading||e?h`<section class="plugin-session-summary__progress">
${this.progress.error?h`<p role="alert">${d(`sessionProgressCard.widgetUnavailable`)}</p>`:this.progress.loading?h`<p>${d(`sessionProgressCard.widgetLoading`)}</p>`:e?R(e,`board`,void 0,t?.status,t?.startedAt,t?.endedAt,t?.hasActiveRun===!0):m}
</section>`:m}
<section
class="plugin-session-summary__history"
aria-label=${d(`pluginUi.sessionRecentMessages`)}
>
<h3>${d(`pluginUi.sessionRecentMessages`)}</h3>
${this.loading||!this.history&&!this.error?h`<p>${d(`common.loading`)}</p>`:this.error?h`<p role="alert">${d(`pluginUi.sessionHistoryUnavailable`)}</p>`:n.length?n.map(e=>h`<article class="plugin-session-summary__message">
<header class="plugin-session-summary__message-header">
<span class="plugin-session-summary__avatar">${e.avatar}</span>
<strong class="plugin-session-summary__role">${e.label}</strong>
${e.time?h`<time
datetime=${e.time.toISOString()}
title=${e.time.toLocaleString()}
>${e.time.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})}</time
>`:m}
</header>
<div class="sidebar-markdown">
${O(A(e.text))}
</div>
</article>`):h`<p>${d(`pluginUi.sessionHistoryEmpty`)}</p>`}
</section>
${this.error||this.progress.error?h`<button class="btn" =${this.retry}>${d(`common.retry`)}</button>`:m}
</div>`}},E([v({attribute:!1})],z.prototype,`session`,void 0),E([v({attribute:!1})],z.prototype,`gateway`,void 0),E([v({attribute:!1})],z.prototype,`presented`,void 0),E([v({attribute:!1})],z.prototype,`agents`,void 0),E([v({attribute:!1})],z.prototype,`agentIdentity`,void 0),E([y()],z.prototype,`history`,void 0),E([y()],z.prototype,`loading`,void 0),E([y()],z.prototype,`error`,void 0),customElements.get(`openclaw-plugin-session-summary`)||customElements.define(`openclaw-plugin-session-summary`,z)})))()}B();