openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
207 lines • 129 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./svg-icon-rasterizer-BFsqBDlK.js","./theme-artwork-loader-CcbjvV2H.js","./gateway-runtime-5YzSCmfV.js","./control-ui-boot-shared-DBJri5ri.js","./plugin-contracts-runtime-CsJ0WpAd.js","./markdown-runtime-Hc-lvqnn.js","./config-runtime-CgOgfOrG.js","./control-ui-core-D-VUH4Gq.css","./transport.runtime-DEnmKmQK.js","./response-body-krIvH2yK.js"])))=>i.map(i=>d[i]);
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Bi as t,Fi as n,Hi as r,Ji as i,Oi as a,Pa as o,Ui as s,Vi as c,Vt as l,br as u,eo as d,et as f,hi as p,ii as m,li as h,ro as g,to as _,yr as v,zi as y,zt as b}from"./control-ui-foundation-ZY_Flbbd.js";import{An as ee,B as te,Bn as ne,Bs as x,Cn as re,Dl as ie,El as S,Eu as ae,Gl as C,Hn as oe,In as se,Jl as ce,Kl as le,L as ue,Mn as de,Nn as fe,Pn as w,R as pe,Rn as me,Tn as he,Tu as ge,Vn as _e,Xn as T,Yl as ve,Yn as ye,Zc as be,c as xe,cr as Se,dl as Ce,ei as we,gl as Te,hu as E,kn as Ee,la as De,nl as D,ql as Oe,s as O,sl as ke,ur as Ae,uu as k,wn as je,xl as Me,xn as Ne,zn as Pe}from"./control-ui-core-3P365fbR.js";import{F as Fe,M as Ie,N as Le,R as Re,T as ze,w as Be}from"./control-ui-boot-shared-JlZTSJEC.js";import{$r as Ve,Br as He,Gr as Ue,Sn as We,Wa as Ge,Xi as Ke,Yt as qe,Zi as Je,Zt as Ye,fn as Xe}from"./control-ui-core-CFW9Qtjn.js";import{$ as A,X as j,Y as Ze}from"./lit-runtime-P5vbNq6b.js";import{O as Qe,h as $e,k as et,m as tt}from"./control-ui-boot-shared-3SP_aL-Y.js";import{At as nt,B as rt,Bt as it,Ht as M,J as at,Mt as ot,O as st,Rt as ct,U as lt,Ut as N,Vt as P,Wt as ut,X as dt,Y as ft,g as pt,jt as mt,k as ht,lt as gt,m as _t,ut as vt,z as yt}from"./control-ui-boot-shared-Rs4iS2kF.js";import{Br as bt,El as xt,Fr as F,Fs as St,Gr as Ct,Hr as wt,Ir as Tt,Js as Et,Lc as Dt,Ms as Ot,Ol as kt,Rr as At,Rs as jt,Ur as Mt,Vr as Nt,Wn as Pt,Wr as Ft,d as It,dc as Lt,di as Rt,ec as I,f as zt,fi as Bt,gc as Vt,gt as Ht,ht as Ut,kl as Wt,ks as Gt,ni as Kt,qs as qt,rc as Jt,ri as Yt,si as Xt,tc as Zt,zc as Qt,zr as L}from"./control-ui-boot-shared-DoKu-5Ju.js";import{S as $t,_ as en,b as tn,v as nn}from"./control-ui-boot-shared-90V688bk.js";import{At as rn,Mt as an,Ot as on,_t as sn,b as cn,ni as ln,ti as un,x as dn}from"./control-ui-boot-shared-CG9HtEG-.js";import{$ as fn,$t as pn,B as mn,Cn as hn,Dn as gn,I as _n,In as vn,J as yn,L as bn,Nn as xn,On as Sn,Pn as Cn,Q as wn,Qt as Tn,Rn as En,X as Dn,Y as On,Z as kn,Zt as An,dn as jn,gn as Mn,sn as R,tn as Nn,un as Pn,yn as Fn,z as In}from"./control-ui-boot-shared-73R4ErOy.js";import{H as Ln,S as Rn,St as zn,V as Bn,b as z,gt as Vn,ht as Hn,it as Un,ot as Wn,v as Gn,x as Kn,y as qn}from"./control-ui-boot-shared-BykNRHBP.js";import{Hn as Jn,Hr as Yn,Vn as Xn}from"./control-ui-boot-shared-CcmBeh0v.js";import{D as Zn,L as Qn,M as $n,O as er,P as tr,S as nr,T as rr,b as ir,k as ar}from"./control-ui-boot-shared-BR12heUA.js";function or(e,t,n){let r=[],i=e.trim();i&&r.push({type:`text`,text:i});for(let e of t??[]){let t=n?xn(e):void 0;if(n===`complete`&&!t)return null;let i=t||Cn(e);if(!i)continue;if(e.mimeType.startsWith(`image/`)){r.push({type:`image`,url:i,...e.fileName?{fileName:e.fileName}:{},source:{type:`url`,url:i}});continue}let a=e.mimeType.trim().toLowerCase(),o=a.startsWith(`video/`)||(a===``||a===`application/octet-stream`)&&qt(e.fileName??``);r.push({type:`attachment`,attachment:{url:i,kind:e.mimeType.startsWith(`audio/`)?`audio`:o?`video`:`document`,label:e.fileName?.trim()||`Attached file`,mimeType:e.mimeType,...e.origin?{origin:e.origin}:{}}})}return r}function sr(e,t,n,r){let i=r?.trim(),a=i?cr({...t,runId:i},`available`):null;return a&&i?{kind:`initial`,sessionKey:e,owner:n,pendingRunId:i,message:a}:null}function cr(e,t){let n=or(e.text,e.attachments,t);if(!n?.length)return null;let{mentions:r}=kt(e.text,e.mentions);return{role:`user`,content:n,timestamp:e.createdAt,__openclaw:{...e.workContext?{workContext:{snapshot:e.workContext,text:e.text}}:{},...e.runId?{idempotencyKey:`${e.runId}:user`}:{},...e.pending?{kind:`pending-send`,id:e.pending.id,...e.pending.state?{state:e.pending.state}:{},...e.pending.error?{error:e.pending.error}:{}}:{},...e.replyToId?{replyToId:e.replyToId}:{},...r?{humanMentions:r}:{},...e.sender?.id?{senderId:e.sender.id}:{},...e.sender?.identity?{senderIdentity:e.sender.identity}:{},...e.sender?.name?{senderName:e.sender.name}:{},...e.sender?.username?{senderUsername:e.sender.username}:{},...e.sender?.profileAvatarUrl?{senderProfileAvatarUrl:e.sender.profileAvatarUrl}:{}}}}function lr(){return(lr=e((()=>{xt(),Et(),vn()})))()}function ur(e,t,n,r){return t&&e&&typeof e==`object`&&(br.set(e,{runId:t,...n?{afterBoundaryRunId:n}:{},...r?{disposition:r}:{}}),xr+=1),e}function dr(){return xr}function fr(e,t){return pr(e)===t}function pr(e){return e&&typeof e==`object`?br.get(e)?.runId??null:null}function mr(e){return e&&typeof e==`object`?br.get(e)?.afterBoundaryRunId??null:null}function hr(e){return e&&typeof e==`object`?br.get(e)?.disposition??null:null}function gr(e){let t=s(e.payload),n=N(t?.message,{messageId:t?.messageId}),r=n?.role===`assistant`&&!n.isImported?n.id:null;e.runIdBeforeApply&&e.matchesChat&&e.event.hasActiveRun!==!0&&r&&Sr.set(e.host,{historyApplied:!1,messageId:r,runId:e.event.clientRunId??e.event.runId??e.runIdBeforeApply,sessionKey:e.event.key})}function _r(e){let t=Sr.get(e.host),n=!!(t&&be(t.sessionKey,e.sessionKey)&&e.visibleMessages.some(e=>{let n=N(e);return n?.role===`assistant`&&!n.isImported&&n.id===t.messageId}));return!t||!n?e.previousMessages:(Sr.set(e.host,{...t,historyApplied:!0}),e.previousMessages.filter(e=>!fr(e,t.runId)))}function vr(e,t){let n=Sr.get(e);return n?.runId===t&&n.historyApplied}function yr(e){let t=s(e);if(!t||typeof t.role==`string`&&d(t.role)!==`assistant`||!(`content`in t)&&typeof t.text!=`string`)return null;let n=typeof t.role==`string`?t:{...t,role:`assistant`};return!Object.hasOwn(n,`content`)&&typeof n.text==`string`?{...n,content:[{type:`text`,text:n.text}]}:n}var br,xr,Sr;function Cr(){return(Cr=e((()=>{P(),D(),br=new WeakMap,xr=0,Sr=new WeakMap})))()}function wr(e,t){return JSON.stringify([e,t])}function Tr(e,t,n,r){if(!n)return;let i=r?wr(r,n):n;t.has(i)||(t.add(i),e.push({id:n,...r?{runId:r}:{}}))}function Er(e){return Le(e.type)||Fe(e.type)}function Dr(e){let t=s(e);if(!t)return[];let n=[],r=new Set,i=Array.isArray(t.content)?t.content.filter(e=>!!e&&typeof e==`object`):[],a=Re({...t,id:void 0}),o=N(t)?.runId??g(t.runId),c=t.role;(typeof c==`string`&&jt(c).toLowerCase()===`tool`||jr.some(e=>!!g(t[e]))||i.some(Er))&&Tr(n,r,a,o);for(let e of i)Er(e)&&Tr(n,r,Re(e)??a,g(e.runId)??o);return n}function Or(e){return Array.isArray(e.toolStreamOrder)?e.toolStreamOrder.filter(e=>typeof e==`string`&&!!e.trim()).map(t=>{let n=s(e.toolStreamById?.get(t)),r=s(n?.message),i=g(n?.toolCallId)??(r?Re(r):void 0)??t,a=g(n?.runId)??g(r?.runId);return a?{identity:t,id:i,runId:a}:{identity:t,id:i}}):[]}function kr(e,t){let n=t.filter(t=>t.id===e.id&&(!e.runId||!t.runId||t.runId===e.runId));return n.length===1?n[0]?.identity:void 0}function Ar(e,t){let n=Or(t),r=new Set;if(n.length===0)return r;let i=e.findLastIndex(e=>{let t=s(e)?.role;return typeof t==`string`&&jt(t).toLowerCase()===`user`});for(let t of e.slice(i+1))for(let e of Dr(t)){let t=kr(e,n);t&&r.add(t)}return r}var jr;function Mr(){return(Mr=e((()=>{P(),Ie(),St(),jr=[`toolName`,`tool_name`]})))()}function Nr(e){return e===void 0?void 0:Pr[e]}var Pr;function Fr(){return(Fr=e((()=>{Pr={main_session_restart_recovery:{icon:`cpu`,labelKey:`chat.systemNotice.restartRecovery.label`,summaryKey:`chat.systemNotice.restartRecovery.summary`,pendingSummaryKeys:{interrupted:`chat.systemNotice.restartRecovery.interrupted`,cancelled:`chat.systemNotice.restartRecovery.cancelled`}},"restart-sentinel":{icon:`cpu`,labelKey:`chat.systemNotice.gatewayRestarted.label`},cli_harness_context:{icon:`cpu`,labelKey:`chat.systemNotice.cliHarnessContext.label`,collapsedBody:!0,startsTurn:!1},claude_cli_task_notification:{icon:`cpu`,labelKey:`chat.systemNotice.claudeCliTaskNotification.label`,collapsedBody:!0,startsTurn:!1}}})))()}function B(e,t){if(!e.has(t))return;let n=e.get(t);return e.delete(t),e.set(t,n),n}function V(e,t,n){for(e.delete(t),e.set(t,n);e.size>20;){let t=e.keys().next().value;if(typeof t!=`string`)break;e.delete(t)}}function Ir(e,t,n){if(e.has(t))return B(e,t);let r=n();return V(e,t,r),r}function Lr(){return(Lr=e((()=>{})))()}function Rr(e){let t=e.chatHistoryCursor;if(t?.snapshotKey===T(e,{sessionKey:e.sessionKey})&&t.sessionId===(e.currentSessionId??null))return t.cursor;delete e.chatHistoryCursor}function zr(e,t){e.chatHistoryCursor=t===void 0?void 0:{cursor:t,snapshotKey:T(e,{sessionKey:e.sessionKey}),sessionId:e.currentSessionId??null}}function Br(e,t){si.set(e,t)}function Vr(e,t,n){e.delete(t),si.get(e)?.delete(t,n)}function Hr(e,t){tr(e,{type:`snapshotLoaded`,messages:t.messages},{scope:$n(e,{sessionId:t.sessionId,...Object.hasOwn(t,`displayedLeafEntryId`)?{activeLeafEntryId:t.displayedLeafEntryId}:{}})}),e.chatHistoryPagination=t.pagination,e.currentSessionId=t.sessionId,e.chatDisplayedLeafEntryId=t.displayedLeafEntryId,zr(e,t.deltaCursor)}function Ur(e,t,n,r,i){let a=T(t,n),o=B(e,a);if(!o)return;if(i){let t=oi.get(e);if(t||(t=new WeakSet,oi.set(e,t)),t.has(i))return;t.add(i)}let s=Qr(r);if(s===null){Vr(e,a,`cache-eviction`);return}let c=i?ot(nt({},o.snapshot.messages),{type:`messagePersisted`,message:r,envelope:i}).messages.slice():[...o.snapshot.messages,r],l={...o.snapshot,messages:c};if(i){Kr(e,t,n,l);return}let u=o.weight+s+ +(o.snapshot.messages.length>0);if(u>ri){Kr(e,t,n,l);return}V(e,a,{snapshot:l,weight:u}),ni(e),si.get(e)?.write(a,l)}function Wr(e,t,n){return qr(e,t,n)?.messages??[]}function Gr(e,t,n,r){Vr(e,T(t,n),r)}function Kr(e,t,n,r){let i=T(t,n),a=B(e,i);if(a?.snapshot.messages===r.messages&&a.snapshot.deltaCursor===r.deltaCursor&&a.snapshot.sessionId===r.sessionId&&a.snapshot.displayedLeafEntryId===r.displayedLeafEntryId&&ti(a.snapshot.pagination,r.pagination))return;if(r.messages.length===0&&r.sessionId===null&&!r.pagination.hasMore&&(r.pagination.totalMessages??0)===0&&r.pagination.completeSnapshot!==!0){Vr(e,i,`cache-eviction`);return}let o=Yr(r);if(!o){Vr(e,i,`cache-eviction`);return}V(e,i,o),ni(e),si.get(e)?.write(i,o.snapshot)}function qr(e,t,n){return B(e,T(t,n))?.snapshot??null}function Jr(e){let t=Xr(e.messages);return t?Zr(e,e.pagination,t.reduce((e,t)=>e+t,0),t.length):null}function Yr(e){let t=Xr(e.messages);if(!t)return null;let n=t.reduce((e,t)=>e+t,0),r=0;for(;;){let i=r===0?e.pagination:$r(e.pagination,e.messages,r);if(!i)return null;let a=Zr(e,i,n,t.length-r);if(a!==null&&a<=ri)return r===0?{snapshot:e,weight:a}:{snapshot:{...e,messages:e.messages.slice(r),pagination:{...i}},weight:a};if(r>=e.messages.length)return null;let o=ut(e.messages[r]);if(n-=t[r]??0,r+=1,o!==null)for(;r<e.messages.length&&ut(e.messages[r])===o;)n-=t[r]??0,r+=1}}function Xr(e){let t=[];for(let n of e){let e=Qr(n);if(e===null)return null;t.push(e)}return t}function Zr(e,t,n,r){let i=ei({...e,messages:[],pagination:t});return i===null?null:i+n+Math.max(0,r-1)}function Qr(e){if(e&&typeof e==`object`){let t=ai.get(e);if(t!==void 0)return t}try{let t=JSON.stringify([e]),n=t?Math.max(0,t.length-2):0;return e&&typeof e==`object`&&ai.set(e,n),n}catch{return null}}function $r(e,t,n=0){let r=e.totalMessages,i=null;for(let e=n;e<t.length&&(i=ut(t[e]),i===null);e+=1);if(typeof r!=`number`||i===null)return null;let a=r-i+1;return a<=0?null:i>1?{hasMore:!0,nextOffset:a,totalMessages:r}:{hasMore:!1,totalMessages:r}}function ei(e){try{return JSON.stringify(e)?.length??0}catch{return null}}function ti(e,t){return e.hasMore!==t.hasMore||e.totalMessages!==t.totalMessages?!1:e.hasMore&&t.hasMore?e.nextOffset===t.nextOffset:!e.hasMore&&!t.hasMore&&e.completeSnapshot===t.completeSnapshot}function ni(e){let t=0;for(let n of e.values())t+=n.weight;for(;t>ii;){let n=e.keys().next().value;if(typeof n!=`string`)break;t-=e.get(n)?.weight??0,e.delete(n)}}var ri,ii,ai,oi,si;function ci(){return(ci=e((()=>{mt(),P(),er(),Lr(),ye(),ri=12582912,ii=25165824,ai=new WeakMap,oi=new WeakMap,si=new WeakMap})))()}function li(){return(li=e((()=>{})))()}function ui(){return(ui=e((()=>{})))()}function di(){return(di=e((()=>{})))()}function fi(){return(fi=e((()=>{})))()}function pi(){return(pi=e((()=>{})))()}function mi(){return(mi=e((()=>{})))()}function hi(){return(hi=e((()=>{})))()}function gi(){return(gi=e((()=>{})))()}function _i(e,t,n){return[e.pluginId?t.pluginIconUrls[e.pluginId]:void 0,e.imageUrl?t.iconUrls[e.imageUrl]:void 0].find(e=>!(!e||n?.has(e)))??null}function vi(e){let t=0;for(let n of e)t=t*31+(n.codePointAt(0)??0)>>>0;return a(bi[t%bi.length],`plugin fallback gradient palette entry`)}function yi(e){let t=e.trim().split(/\s+/u).filter(Boolean);if(t.length===0)return``;let n=a(t[0],`plugin monogram first word`),r=t[1];return(r?`${ae(n,1)}${ae(r,1)}`:ae(n,2)).toLocaleUpperCase()}var bi;function xi(){return(xi=e((()=>{m(),ge(),bi=[[`#f59e0b`,`#ea580c`],[`#38bdf8`,`#1d4ed8`],[`#34d399`,`#047857`],[`#a855f7`,`#6b21a8`],[`#f472b6`,`#be185d`],[`#22d3ee`,`#0e7490`],[`#fbbf24`,`#b45309`],[`#818cf8`,`#4338ca`],[`#4ade80`,`#166534`],[`#fb7185`,`#9f1239`]]})))()}function Si(){return(Si=e((()=>{})))()}function Ci(e,t=e.length){for(let n=t-1;n>=0;--n)if(N(e[n])?.role===`user`)return n;return-1}function wi(e){let t=s(s(e)?.__openclaw);return g(t?.steerTargetRunId)??null}function Ti(e,t){let n=new Map,r=new Map;for(let[i,a]of e.entries()){let e=null,o=null;for(let n of t(a))if(e??=R(n),o??=wi(n),e&&o)break;if(e&&!n.has(e)&&n.set(e,i),o){let e=r.get(o)??[];e.push(i),r.set(o,e)}}let i=new Map,a=new Map;for(let[e,t]of r){let r=n.get(e);if(r!==void 0)for(let e of t)e<=r||(i.set(r,e),a.set(e,r),r=e)}return{continuationTurnIndexes:i,precedingContinuationTurnIndexes:a}}function Ei(e,t){for(let n=e.length-1;n>=0;--n){if(N(e[n])?.role!==`user`||wi(e[n])!==t)continue;let r=R(e[n]);if(r)return{index:n,runId:r}}return null}function Di(e){let t=e.chatStreamSegments??[];for(let e=t.length-1;e>=0;--e){let n=g(t[e]?.boundaryRunId);if(n)return n}}function H(e,t){let n=t.afterBoundaryRunId?e.findIndex(e=>R(e)===t.afterBoundaryRunId):-1,r=t.boundaryRunId?e.findIndex(e=>R(e)===t.boundaryRunId):-1;if(r>=0)return{start:n>=0?n+1:Ci(e,r)+1,end:r};let i=n>=0?n:t.runId?e.findIndex(e=>R(e)===t.runId):-1;if(i>=0){let t=e.findIndex((e,t)=>t>i&&N(e)?.role===`user`);return{start:i+1,end:t>=0?t:e.length}}let a=e.length;return{start:Ci(e,a)+1,end:a}}function Oi(e,t,n,r,i){for(let a=n;a<r;a++){let n=i(e[a]);if(n!=null&&n>t)return a}return r}function ki(e,t,n,r){let i=null;for(let n=t-1;n>=0&&(i=r(e[n]),i==null);--n);let a=null;for(let n=t;n<e.length&&(a=r(e[n]),a==null);n+=1);if(i!=null&&n<=i){let e=i+1;return a!=null&&e>=a?i+(a-i)/2:e}if(a!=null&&n>=a){let e=a-1;return i!=null&&e<=i?i+(a-i)/2:e}return n}function Ai(e,t,n,r=e.length,i){let a=-1;for(let o=0;o<r;o+=1){let r=e[o],s=N(r),c=M(r),l=c!==void 0&&(i===void 0||i.has(c.itemId)),u=s?.runId===n&&!l?Zt(r):null;if(s?.role===`assistant`&&u&&(t.startsWith(u)||u.startsWith(t))){a=o;break}}let o=a>=0?a:Ci(e,r)+1;return Mi(e.slice(o,r).map(e=>{let t=N(e),r=M(e),a=r!==void 0&&(i===void 0||i.has(r.itemId));return{text:t?.role===`assistant`&&(!t.runId||t.runId===n)&&!a?Zt(e):null,skipOnMismatch:r!==void 0}}),t)}function ji(e,t){return Mi(e.map(e=>({text:e,skipOnMismatch:!1})),t)}function Mi(e,t){let n=0;for(let{text:r,skipOnMismatch:i}of e){if(!r)continue;let e=t.slice(n);if(e.startsWith(r)){n+=r.length;continue}if(r.startsWith(e))return null;let a=n>0?/^\s+/u.exec(e)?.[0]:void 0;if(a&&e.slice(a.length).startsWith(r)){n+=a.length+r.length;continue}if(a&&r.startsWith(e.slice(a.length)))return null;if(!i&&n>0)break}return t.slice(n)}function Ni(e,t){let n=e.chatMessages,r=e.chatRunId;if(!Array.isArray(n)||!r)return null;let i=Ei(n,r);if(!i||i.index<=0)return null;let a=Ai(n,t,r,i.index);return a===t?null:{boundaryRunId:i.runId,prefix:a===null?t:t.slice(0,t.length-a.length)}}function Pi(e,t){if(Array.isArray(e.content)){let n=!1,r=e.content.flatMap(e=>{let r=s(e);return!r||r.type!==`text`&&r.type!==`input_text`&&r.type!==`output_text`||typeof r.text!=`string`?[e]:n?[]:(n=!0,[{...r,text:t}])});if(n)return{...e,content:r}}return typeof e.content==`string`?{...e,content:t}:typeof e.text==`string`?{...e,text:t}:e}function Fi(e,t){return!!(e?.boundaryRunId&&t.startsWith(e.prefix))}function Ii(e,t,n){let r=e.chatRunId;if(!r)return null;let i=e.chatMessages??[],a=H(i,{runId:r,...n?{afterBoundaryRunId:n.boundaryRunId}:{}});for(let o of(e.chatStreamSegments??[]).toReversed()){if(o.runId!==r||o.persisted!==!0||!o.retiredItemId||!L(o)||n&&!o.text.startsWith(n.prefix)||!t.startsWith(o.text))continue;let e=i.slice(a.start,a.end).find(e=>{let t=M(e);return t?.runId===r&&t.itemId===o.retiredItemId}),s=N(e);if(s?.id&&!s.isImported&&s.sequence!==null)return{prefix:o.text,afterSequence:s.sequence}}return null}function Li(e,t){let n=I(e);if(!n)return{kind:`none`};let r=null,i=[],a=null;for(let[e,n]of(t.chatStreamSegments??[]).entries()){if(L(n)&&typeof n.text==`string`){let t=Tt(r,n.text);t!==r&&i.push(e),r=t}let t=g(n.boundaryRunId);t&&r&&(a={boundaryRunId:t,prefix:r,segmentIndexes:[...i]})}let o=Ni(t,n),s=Fi(a,n)?a:Fi(o,n)?o:null,c=Ii(t,n,s),l=c??s;if(!l)return{kind:`none`};let u=n.slice(l.prefix.length),d=c?u:u.trimStart();return{kind:`split`,...s?{afterBoundaryRunId:s.boundaryRunId}:{},afterSequence:c?.afterSequence??N(t.chatMessages?.find(e=>R(e)===s?.boundaryRunId))?.sequence??null,...c?{preserveKeyedCommentary:!0}:{},replacedSegmentIndexes:s&&s===o&&a?a.segmentIndexes:[],tailMessage:d?Pi(e,d):null}}function Ri(e){let t=e.messages;if(!t)return;let n=t.findIndex(t=>R(t)===e.boundaryRunId),r=e.afterBoundaryRunId??e.runId,i=t.findIndex(e=>R(e)===r);if(!(i<0||n<=i))for(let e=i+1;e<n;e+=1){if(N(t[e])?.role!==`user`)continue;let n=R(t[e]);if(n)return n}}function zi(e,t){if(e.chatRunId!==t.runId)return;let n=e.chatStreamSegments??[],r=Di(e),i=typeof e.chatStream==`string`,a=i&&!!e.chatStream?.trim(),o=t.boundaryRunId?Ri({messages:e.chatMessages,runId:t.runId,boundaryRunId:t.boundaryRunId,afterBoundaryRunId:r})??t.boundaryRunId:void 0;if(o){let e=n.findLastIndex(e=>e.boundaryRunId);n=n.map((t,n)=>n<=e||t.boundaryRunId?t:{...t,boundaryRunId:o})}if(a&&(n=[...n,{text:e.chatStream??``,ts:e.chatStreamStartedAt??t.timestamp??Date.now(),runId:t.runId,...r?{afterBoundaryRunId:r}:{},...o?{boundaryRunId:o}:{},...t.toolCallId?{toolCallId:t.toolCallId}:{},...t.persisted?{persisted:!0}:{}}]),t.boundaryRunId&&!n.some(e=>e.boundaryRunId===t.boundaryRunId)){let i=o===t.boundaryRunId?r:o;n=[...n,{text:``,ts:e.chatStreamStartedAt??t.timestamp??Date.now(),runId:t.runId,boundaryRunId:t.boundaryRunId,boundaryMarker:!0,...i?{afterBoundaryRunId:i}:{}}]}e.chatStreamSegments=n,i&&(e.chatStream=null,e.chatStreamStartedAt=null)}function Bi(){return(Bi=e((()=>{P(),Jt(),Nn()})))()}function Vi(e){return!e||e.startsWith(`/`)||e.includes(`\0`)?!1:e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}function Hi(e){return Array.from(e).map(e=>{if(e===`\\`)return`\\\\`;let t=e.codePointAt(0);return t!==void 0&&(t<=31||t>=127&&t<=159)?`\\u{${t.toString(16).padStart(4,`0`)}}`:e}).join(``)}function Ui(e){let t=s(e);if(!t||!Array.isArray(t.paths)||t.paths.length===0)return;let n=t.paths.filter(e=>typeof e==`string`&&Vi(e));if(!(n.length!==t.paths.length||typeof t.stagedResultRef!=`string`||!/^refs\/openclaw\/worker-results\/[A-Za-z0-9-]+$/u.test(t.stagedResultRef)||t.totalCount!==void 0&&(!Number.isSafeInteger(t.totalCount)||t.totalCount<n.length)))return{paths:n,stagedResultRef:t.stagedResultRef,...t.totalCount===void 0?{}:{totalCount:t.totalCount}}}function Wi(e){if(e&&`workspaceResultConflict`in e)return Ui(e.workspaceResultConflict)}function Gi(e){let t=s(e);if(t?.role===`custom`&&t.customType===Xi)return Ui(t.details)}function Ki(e){return Math.max(e.paths.length,e.totalCount??e.paths.length)}function qi(e){let t=e.paths.slice(0,Zi);return{paths:t,remaining:Math.max(0,Ki(e)-t.length)}}function Ji(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Yi(e,t){let n=t===void 0?e.paths.find(e=>!tt(e)):e.paths.includes(t)&&!tt(t)?t:void 0;if(!n)return;let r=Ji(`${e.stagedResultRef}:${n}`),i=Ji(e.stagedResultRef),a=Ji(`:(top,literal)${n}`);return{inspect:`git show ${r}`,takeCloud:`git checkout ${i} -- ${a}`}}var Xi,Zi;function Qi(){return(Qi=e((()=>{$e(),Xi=`cloud-workspace-conflict`,Zi=5})))()}function $i(){return($i=e((()=>{})))()}function ea(e,t=`installed-plugins-card__status-notice`){let[n,r]=aa[e],i=E(n);return A`<span
class="${t} settings-status settings-status--${r}"
data-plugin-state=${e}
role="img"
aria-label=${i}
title=${i}
>
<span class="settings-status__dot" aria-hidden="true"></span>
</span>`}function ta(){return A`<span
class="plugin-official-badge"
role="img"
aria-label=${E(`pluginsPage.official`)}
title=${E(`pluginsPage.official`)}
>${Ke.badgeCheck}</span
>`}function na(e,t={}){if(!e)return j;let n=e.replace(/^@+/,``),r=`@${n}`;return t.linked?A`<a
class="plugin-card-author plugin-card-author--linked"
href=${`https://clawhub.ai/${encodeURIComponent(n)}`}
target="_blank"
rel="noopener noreferrer"
>${r}</a
>`:A`<span class="plugin-card-author">${r}</span>`}function ra(e){return A`<div class="installed-plugins-card__identity">
<div class="plugin-card-title-row">
<h3>${e.name}</h3>
${e.attribution.official?ta():j}
</div>
${na(e.attribution.author,{linked:e.linkedAuthor})}
</div>`}function ia(e){return A`<p class="installed-plugins-card__summary">${e}</p>`}var aa;function oa(){return(oa=e((()=>{Ze(),Je(),k(),Rt(),Bt(),aa={enabled:[`pluginsPage.enabled`,`ok`],disabled:[`pluginsPage.disabled`,`muted`],"needs-setup":[`pluginsPage.setupRequiredNotice`,`warn`],error:[`pluginsPage.needsAttention`,`danger`]}})))()}function sa(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()??``}function ca(e){e.bodyUsed||e.body?.cancel().catch(()=>void 0)}async function la(e,t,n=!1){if(!Ge(e.gatewayUrl))return null;let r=e.authCandidates??Ye(e.auth),i=r.length>0?r:[``];for(let r of i){let i={Accept:`image/avif,image/webp,image/png,image/jpeg,image/gif,image/svg+xml`};r&&(i.Authorization=`Bearer ${r}`);let a=await fetch(t,{method:`GET`,headers:i,credentials:`same-origin`,signal:e.signal});if(!a.ok){if(ca(a),a.status===401||a.status===403)continue;return null}let o=sa(a.headers.get(`content-type`));if(!ha.has(o)||n&&o!==`image/svg+xml`)return ca(a),null;let s=await a.blob(),c=o===`image/svg+xml`?await y(async()=>{let{rasterizeSvg:e}=await import(`./svg-icon-rasterizer-BFsqBDlK.js`);return{rasterizeSvg:e}},__vite__mapDeps([0]),import.meta.url).then(({rasterizeSvg:e})=>e(s)):s;return c?URL.createObjectURL(c):null}return null}function ua(e){return la(e,Be(`pluginIcon`,e.resourceBasePath,e.pluginId))}function da(e){let t=Be(`pluginActivityIcon`,e.resourceBasePath,e.pluginId);return la(e,e.tool?`${t}?tool=${encodeURIComponent(e.tool)}`:t,!0)}function fa(e){return la(e,Be(`catalogIcon`,e.resourceBasePath,e.iconUrl))}function pa(e){return la(e,Be(`linkFavicon`,e.resourceBasePath,e.hostname))}function ma(e){return y(async()=>{let{loadPluginThemeArtwork:e}=await import(`./theme-artwork-loader-CcbjvV2H.js`);return{loadPluginThemeArtwork:e}},__vite__mapDeps([1,2,3,4,5,6,7]),import.meta.url).then(({loadPluginThemeArtwork:t})=>t(e))}var ha;function ga(){return(ga=e((()=>{ze(),qe(),t(),ha=new Set([`image/png`,`image/svg+xml`,`image/x-icon`])})))()}function _a(e){return{resourceBasePath:e.resourceBasePath,gatewayUrl:e.gateway.connection.gatewayUrl,auth:{hello:e.gateway.snapshot.hello,settings:{token:e.gateway.connection.token},password:e.gateway.connection.password}}}var va;function ya(){return(ya=e((()=>{ga(),va=class{constructor(e){this.host=e,this.misses=new Set,this.requests=new Map,this.urls={}}syncCatalog(e,t=[],n){let r=new Set([...e.flatMap(e=>e.catalog.imageUrl?[e.catalog.imageUrl]:[]),...t]);this.reconcileKeys(r);for(let t of e)t.catalog.imageUrl&&(!n||n.has(t.id)||t.local.pluginId&&n.has(t.local.pluginId))&&this.load(t.catalog.imageUrl);for(let e of t)this.load(e)}isLoading(e){return this.requests.has(e)}reconcile(e){let t=new Set((e?.plugins??[]).filter(e=>e.hasIcon).map(e=>e.id));this.reconcileKeys(t)}reconcileKeys(e){let t={...this.urls},n=!1;for(let[r,i]of Object.entries(t))e.has(r)||(URL.revokeObjectURL(i),delete t[r],n=!0);n&&this.host.kind!==`catalog`&&this.publish(t);for(let[t,n]of this.requests)e.has(t)||(clearTimeout(n.timeout),n.controller.abort(),this.requests.delete(t),this.host.onLoadingChange?.());if(this.host.kind===`catalog`){n&&this.publish(t);return}for(let t of this.misses)e.has(t)||this.misses.delete(t)}reset(){for(let e of this.requests.values())clearTimeout(e.timeout),e.controller.abort();for(let e of Object.values(this.urls))URL.revokeObjectURL(e);this.requests.clear(),this.host.onLoadingChange?.(),this.misses.clear(),(this.host.kind!==`catalog`||Object.keys(this.urls).length>0)&&this.publish({})}sync(e,t){for(let n of e?.plugins??[])n.hasIcon&&t.has(n.id)&&this.load(n.id)}load(e){!this.urls[e]&&!this.misses.has(e)&&!this.requests.has(e)&&this.fetch(e)}handleError(e){this.invalidate(e),this.misses.add(e)}invalidate(e){let t=this.requests.get(e);t&&(clearTimeout(t.timeout),t.controller.abort(),this.requests.delete(e),this.host.onLoadingChange?.());let n=this.urls[e];n&&URL.revokeObjectURL(n);let r={...this.urls};delete r[e],this.publish(r),this.misses.delete(e)}publish(e){this.urls=e,this.host.onUrlsChange(e)}fetch(e){let t=new AbortController,n=this.host.kind===`catalog`?void 0:setTimeout(()=>t.abort(this.host.timeoutError?.()??new DOMException(`plugin icon fetch timed out`,`TimeoutError`)),1e4),r={controller:t,timeout:n};this.requests.set(e,r),this.host.onLoadingChange?.();let i=this.host.getFetchContext();(this.host.fetchIcon?this.host.fetchIcon(e,i,t.signal):this.host.kind===`catalog`?fa({iconUrl:e,...i,signal:t.signal}):ua({pluginId:e,...i,signal:t.signal})).then(t=>{if(this.requests.get(e)!==r||!this.host.isConnected(e)){t&&URL.revokeObjectURL(t);return}t?this.publish({...this.urls,[e]:t}):this.misses.add(e)}).catch(()=>{this.requests.get(e)===r&&(this.host.kind!==`catalog`||!t.signal.aborted)&&this.misses.add(e)}).finally(()=>{clearTimeout(n),this.requests.get(e)===r&&(this.requests.delete(e),this.host.onLoadingChange?.())})}}})))()}function ba(){return(ba=e((()=>{})))()}function xa(){return(xa=e((()=>{})))()}function Sa(){return(Sa=e((()=>{})))()}var Ca;function wa(){return(wa=e((()=>{Ca=`wa-dropdown.session-menu::part(menu){padding:var(--menu-padding);border:1px solid var(--overlay-border);border-radius:var(--menu-radius);background:var(--bg-elevated);box-shadow:var(--overlay-shadow)}:is(.session-menu wa-dropdown-item,.session-menu__item,.sidebar-session-sort-menu__item){font:inherit;font-size:calc(13px * var(--control-ui-text-scale))}.session-menu__item,.sidebar-session-sort-menu__item{box-sizing:border-box;width:100%;min-height:var(--menu-item-height);border-radius:var(--menu-item-radius);color:var(--text);text-align:left;background:0 0;border:none;align-items:center;gap:8px;padding:0 8px;display:flex}.row.session-menu__label{gap:8px}.session-menu__status{max-width:min(300px,100vw - 48px);color:var(--text);font-size:calc(13px * var(--control-ui-text-scale));align-items:baseline;gap:8px;padding:8px;display:flex}.session-menu__status .session-menu__text{white-space:normal}wa-dropdown-item.session-menu__item{--wa-color-neutral-fill-normal:var(--bg-hover);gap:0}wa-dropdown-item.session-menu__item::part(icon){align-items:center;display:flex}wa-dropdown-item.session-menu__item::part(submenu-icon){color:var(--muted);font-size:10px;inset-inline-end:8px}.session-menu__item[aria-expanded=true],.session-menu__item:focus-visible,.sidebar-session-sort-menu__item:focus-visible{background:var(--bg-hover)}@media (hover:hover){.session-menu__item:hover:not(:disabled):not([aria-disabled=true]),.sidebar-session-sort-menu__item:hover{background:var(--bg-hover)}}.session-menu__item:disabled,.session-menu__item[aria-disabled=true]{opacity:.42;cursor:not-allowed}.session-menu__item--destructive,.session-menu__item--destructive .session-menu__icon{color:var(--danger)}.sidebar-session-sort-menu__item::part(checkmark){display:none}.session-menu__icon,.session-menu__avatar,.session-menu__check{flex:none;justify-content:center;align-items:center;width:14px;height:14px;display:inline-flex}.session-menu__check{color:var(--accent)}.session-menu__icon{color:var(--muted)}.session-menu__avatar,.session-menu__avatar .viewer-avatar{width:24px;height:24px;font-size:10px}.session-menu__icon svg,.session-menu__check svg{stroke:currentColor;fill:none;stroke-width:1.7px;stroke-linecap:round;stroke-linejoin:round;width:14px;height:14px}wa-dropdown-item.session-menu__item:not([disabled]):not([aria-disabled=true]){cursor:var(--cursor-action)}wa-dropdown-item.session-menu__item[data-new-tab-action]:not([disabled],[aria-disabled=true]){cursor:pointer}@supports (corner-shape:superellipse(1.5)){wa-dropdown.session-menu{--menu-radius:calc(10px * var(--openclaw-corner-radius-scale));--menu-item-radius:calc(var(--menu-radius) - var(--menu-padding))}wa-dropdown.session-menu::part(menu){corner-shape:superellipse(1.5)}}.people-menu__search,.people-menu__pagination{z-index:1;background:var(--bg-elevated);padding:6px 8px;position:sticky}.people-menu__search{top:0}.people-menu__search input{box-sizing:border-box;border:1px solid var(--border);border-radius:var(--menu-item-radius);background:var(--bg);width:100%;min-width:0;color:var(--text);font:inherit;padding:6px 8px}.people-menu__pagination{color:var(--muted);align-items:center;gap:6px;font-size:11px;display:flex;bottom:0}.people-menu__pagination span{flex:1}wa-dropdown-item.people-menu__submenu::part(submenu){overscroll-behavior:contain;width:min(320px,100vw - 24px);max-height:min(420px,60vh);overflow-y:auto}`})))()}function Ta(e){let t=U.get(e);if(t)return U.delete(e),U.set(e,t),t;let n=new Map;for(U.set(e,n);U.size>Ha;){let e=U.keys().next().value;if(typeof e!=`string`)break;U.delete(e)}return n}function Ea(e,t){let n=Ta(e),r=B(n,t);if(r!==void 0)return r;for(let[e,r]of n)if(be(e,t))return n.delete(e),V(n,t,r),r}function Da(e,t,n){let r=Ta(e);for(let e of r.keys())be(e,t)&&r.delete(e);V(r,t,{scrollTop:Math.max(0,n.scrollTop),anchorToEnd:n.anchorToEnd})}function Oa(e){let t=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.min(Math.max(0,e.scrollTop),t);return{scrollTop:n,anchorToEnd:t-n<=8}}function ka(e){return!e.chatFollowLocked&&!W.get(e)?.manual}function Aa(e){W.get(e)?.cancel()}function ja(e,t){e.chatNewMessagesBelow!==t&&(e.chatNewMessagesBelow=t,e.renderLifecycle.invalidate())}function Ma(e,t,n,r){let i=e.chatScrollElement?.();if(!i)return;let a=i.scrollHeight-i.scrollTop-i.clientHeight,o=i.scrollHeight>(e.chatLastScrollHeight??0)+1,s=Math.abs(i.scrollHeight-(e.chatLastScrollHeight??0))>1;e.chatLastScrollHeight=i.scrollHeight;let c=r.contentChanged??r.source!==`resize`,l=r.source===`manual`,u=t&&!e.chatHasAutoScrolled;if(!(l||u||!e.chatFollowLocked&&(c&&s||r.source===`resize`||e.chatUserNearBottom||a<Va))){(c||r.source===`resize`&&o)&&ja(e,!0);return}let d=Pt(n?`smooth`:`auto`);e.chatScrollToEnd?.({behavior:d,source:l?`manual`:`auto`})&&(u&&(e.chatHasAutoScrolled=!0),e.chatFollowLocked=!1,e.chatUserNearBottom=!0,ja(e,!1),l&&a<=8&&za(e,i,`toward-end`))}function Na(e,t,n,r,i){if(r.source!==`manual`&&W.get(e)?.manual)return;Aa(e);let a=null,o,s={manual:r.source===`manual`,cancel:()=>{W.get(e)===s&&(W.delete(e),o?.(),a!==null&&cancelAnimationFrame(a))}};W.set(e,s);let c=i=>{let o=()=>{W.get(e)===s&&(W.delete(e),i?.(),Ma(e,t,n,r))};return a=requestAnimationFrame(()=>{s.manual&&n&&Pt()===`smooth`?a=requestAnimationFrame(o):o()}),s.cancel};i?c():o=e.renderLifecycle.afterCommit(c,s.cancel)}function Pa(e,t=!1,n=!1,r={}){Na(e,t,n,r,!0)}function Fa(e,t=!1,n=!1,r={}){Na(e,t,n,r,!1)}function Ia(e,t){let n=t.currentTarget;n&&za(e,n)}function La(e,t=!1){Aa(e);let n=e.chatScrollElement?.();n&&za(e,n,t?`toward-end`:`reader`)}function Ra(e){let t=!e.chatFollowLocked||e.chatUserNearBottom;Aa(e),e.chatHasAutoScrolled=!0,e.chatFollowLocked=!0,e.chatUserNearBottom=!1,e.chatCancelScroll?.(),t&&e.renderLifecycle.invalidate()}function za(e,t,n=!1){let r=Math.max(0,t.scrollTop),i=r-e.chatLastScrollTop;e.chatLastScrollTop=r,e.chatLastScrollHeight=t.scrollHeight;let a=n!==!1||i<0&&!e.chatIsMaintenanceScroll?.();if(e.chatIsProgrammaticScroll?.()&&!a)return;let o=t.scrollHeight-t.scrollTop-t.clientHeight,s=e.chatReadingHistory;a&&o>8?(e.chatHasAutoScrolled=!0,e.chatFollowLocked=!0,e.chatReadingHistory=!0):o<=8&&(i>0||n===`toward-end`)&&(e.chatFollowLocked=!1,e.chatReadingHistory=!1),e.chatReadingHistory!==s&&e.renderLifecycle.invalidate(),e.chatUserNearBottom=!e.chatFollowLocked&&o<Va,ja(e,t.scrollHeight-t.clientHeight>8&&o>8)}function Ba(e){Aa(e),e.chatHasAutoScrolled=!1,e.chatUserNearBottom=!0,e.chatFollowLocked=!1,e.chatReadingHistory=!1,e.chatLastScrollTop=0,e.chatLastScrollHeight=0,e.chatNewMessagesBelow=!1}var Va,Ha,U,W;function Ua(){return(Ua=e((()=>{D(),Lr(),Va=450,Ha=8,U=new Map,W=new WeakMap})))()}function Wa(e,t,n){e?.settingsAgentSelection.set(t),e?.navigate(`model-providers`,{search:`?provider=${encodeURIComponent(n)}`})}function Ga(){return(Ga=e((()=>{})))()}function Ka(e){return e.toolStreamById instanceof Map&&Array.isArray(e.toolStreamOrder)&&Array.isArray(e.chatToolMessages)&&Array.isArray(e.chatStreamSegments)}function qa(e){e.chatToolMessages=e.toolStreamOrder.map(t=>e.toolStreamById.get(t)?.message).filter(e=>!!e)}function Ja(e){e.toolStreamSyncTimer!=null&&(clearTimeout(e.toolStreamSyncTimer),e.toolStreamSyncTimer=null)}function Ya(e){Ja(e),e.toolStreamById.clear(),e.toolStreamOrder=[],e.activityEventSeqById?.clear(),e.chatToolMessages=[],e.chatStreamSegments=[],e.knownAgentRunIds?.clear(),e.waitingApprovalStatuses?.clear()}function Xa(e,t){Ja(e);let n=new Set;for(let r of e.toolStreamOrder)e.toolStreamById.get(r)?.runId===t&&n.add(r);for(let t of n)e.toolStreamById.delete(t);let r=`tool:[${JSON.stringify(t)},`;for(let n of e.activityEventSeqById?.keys()??[])(n.startsWith(r)||n.startsWith(`item:${t}:`))&&e.activityEventSeqById?.delete(n);e.toolStreamOrder=e.toolStreamOrder.filter(e=>!n.has(e)),qa(e),e.chatStreamSegments=e.chatStreamSegments.filter(e=>e.runId!==t),e.knownAgentRunIds?.delete(t);for(let[n,r]of e.waitingApprovalStatuses??[])r.runId===t&&e.waitingApprovalStatuses?.delete(n)}function Za(){return(Za=e((()=>{})))()}function Qa(e,t){e.lastError=t,e.chatError=t}function $a(e){return!!(e.chatSending||e.chatRunId)}function eo(e,t,n){if(e.chatRunStatus?.runId===t||e.lastLocalTerminalReconcile?.runId===t)return;let r=Zn(e).runs[t];if(r&&r.status!==`streaming`)return;tr(e,{type:`runDelta`,runId:t});let i=e.chatRunId===t,a=i&&typeof e.chatStream==`string`;i||(_o(e,{clearToolStreamForRun:!0,clearIndicators:!!e.chatRunId,clearRunStatus:!0,requestUpdate:!1}),e.chatRunError=null,e.providerPolicyNotice?.runId!==t&&(e.providerPolicyNotice=null)),e.chatRunId=t,Qn(e,t),a||(e.chatStream=``,e.chatStreamStartedAt=n)}function to(e,t,n,r){Qn(e,n),e.chatRunError={...r?{kind:r}:{},summary:ve(t.trim()),...n?{runId:n}:{}}}function no(e){return!!(e.chatRunId||e.sessionsResult?.sessions.some(t=>be(t.key,e.sessionKey)&&f(t)))}function ro(e){return no(e)||!!e.sessionsResult?.sessions.some(t=>be(t.key,e.sessionKey)&&t.hasActiveSubagentRun===!0)}function io(e){return wo.has(d(e.trim()))}function ao(e,t){let n=Te(e,e.sessionKey),r=e.chatQueue?.find(e=>e.sendState===`sending`&&e.sendRunId)?.sendRunId,i=e.chatRunId??r??null,a=e.lastLocalTerminalReconcile,o=a?Te(e,a.sessionKey,a.agentId):void 0,s=t.runId!==null&&i===null&&a?.runId===t.runId&&o?.sessionKey===t.conversation.sessionKey&&o.agentId===t.conversation.agentId;return e.client===t.sourceClient&&n.sessionKey===t.conversation.sessionKey&&n.agentId===t.conversation.agentId&&(i===t.runId||s)&&we(e,e.sessionKey).agentId===t.agentId}async function oo(e,t,n){if(ao(e,t)){if(n.ok)n.warning?(to(e,n.warning,t.runId??void 0),e.requestUpdate?.()):n.noActiveRun&&e.connected&&await e.refreshCurrentChat?.();else{let r=Xn(n.error);n.errorKind===`state_contention`?(Qa(e,null),to(e,r,t.runId??void 0,n.errorKind)):e.chatRunId?Qa(e,r):to(e,r,t.runId??void 0),e.requestUpdate?.()}}return n.ok}async function so(e,t,n){let r=e.client;if(!r||!e.connected)return!1;let i=t??kn(e,r),a=n?kn(e,r,n):i;return oo(e,i,await fn(r,a))}async function co(e){let t=e.pendingAbort,n=e.client;if(!t||!n||!e.connected)return!1;let r=e.hello?.auth?.recoveryScope??(n.recoveryScopeReady?n.recoveryScope:void 0);if(t.sourceClient!==n||r!==void 0&&t.recoveryScope!==r)return e.pendingAbort=null,!1;if(r===void 0)return!1;if(e.sessions?.deletionState?.(t.sessionKey,t.agentId,t.sessionId)===`confirmed`)return e.pendingAbort=null,!1;let i=Dn(e,t);if(t.sessionId&&i?.sessionId&&i.sessionId!==t.sessionId)return e.pendingAbort=null,!1;let a=On({client:n,hello:e.hello,phase:`connected`},!0,{session:i,sessionAbortable:t.sessionAbortable}).abort;return!a.allowed&&a.cause===`session-not-owned`&&!i?!1:(e.pendingAbort=null,a.allowed?so(e,t):(ao(e,t)&&Qa(e,a.reason),!1))}async function lo(e,t){let n=!e.connected&&e.client?kn(e,e.client):null,r=n?.runId&&n.recoveryScope?n:null;if(!e.connected&&!r){Qa(e,E(`chat.questions.disconnected`));return}if(t?.preserveDraft||(e.chatMessage=``,e.chatMentions=[],e.chatReplyTarget=null,nr(e)),r){e.pendingAbort=r;return}await so(e,void 0,t?.scope)}function uo(e){e!=null&&globalThis.clearTimeout(e)}function fo(e){uo(e.chatRunStatusClearTimer),e.chatRunStatusClearTimer=null,e.chatRunStatus=null}function po(e,t){uo(e.chatRunStatusClearTimer),e.chatRunStatusClearTimer=globalThis.setTimeout(()=>{let n=e.chatRunStatus;n?.phase===t.phase&&n.runId===t.runId&&n.sessionKey===t.sessionKey&&n.occurredAt===t.occurredAt&&(e.chatRunStatus=null,e.chatRunStatusClearTimer=null,xo(e)||e.requestUpdate?.())},Co)}function mo(e,t){t?e.knownAgentRunIds?.delete(t):e.knownAgentRunIds?.clear(),(!t||e.chatRunStartup?.runId===t)&&(e.chatRunStartup=null),(!t||e.compactionStatus?.runId===t)&&e.compactionStatus?.phase!==`complete`&&(uo(e.compactionClearTimer),e.compactionClearTimer=null,e.compactionStatus=null),uo(e.fallbackClearTimer),e.fallbackClearTimer=null,e.fallbackStatus&&=null;for(let[n,r]of e.waitingApprovalStatuses??[])(!t||!r.runId||r.runId===t)&&e.waitingApprovalStatuses?.delete(n)}function ho(e,t){let n=_(t.sessionKey)??e.sessionKey,r=new Set(n?[n]:[]);ie(e,`global`,n)&&r.add(`global`);for(let t of e.sessionsResult?.sessions??[])ie(e,t.key,n,t.agentId)&&r.add(t.key);for(let e of t.sessionKeys??[]){let t=_(e);t&&r.add(t)}return r}function go(e,t,n){if(!t.outcome&&!t.yielded)return;let r=ho(e,t);if(t.outcome&&r.size===0)return;let i=t.outcome?t.sessionStatus??(t.outcome===`done`?`done`:`killed`):`running`,a={sessionKeys:[...r],agentId:t.agentId,runId:t.runId??e.chatRunId??null,status:i,...t.outcome?{errorMessage:t.errorMessage}:{},endedAt:n};e.sessionsResult&&=Ae(e.sessionsResult,a),e.sessions?.reconcileRunTerminal?.(a)}function _o(e,t={}){let n=Date.now(),r=t.runId??e.chatRunId??null,i=_(t.sessionKey)??e.sessionKey,a=t.agentId??Me(e,i),o={...t,agentId:a};if((t.clearIndicators??!0)&&mo(e,r),t.clearChatStream&&(e.chatStream=null,e.chatStreamStartedAt=null),t.clearLocalRun&&(ar(e,void 0),e.chatRunId&&(e.chatRunLifecycleGeneration=(e.chatRunLifecycleGeneration??0)+1),e.chatRunId=null,e.chatRunSessionAbortable=void 0),Ka(e)&&(t.clearToolStream?Ya(e):t.clearToolStreamForRun&&r&&Xa(e,r)),t.outcome){let s={phase:t.outcome,runId:r,sessionKey:i,occurredAt:n};go(e,o,n),t.armLocalTerminalReconcile&&(e.lastLocalTerminalReconcile={sessionKey:i,agentId:a,runId:r,phase:t.outcome,sessionStatus:t.sessionStatus??(t.outcome===`done`?`done`:`killed`),errorMessage:t.errorMessage}),t.publishRunStatus!==!1&&(e.chatRunStatus=s,po(e,s))}else t.yielded?(go(e,o,n),e.lastLocalTerminalReconcile=null,fo(e)):t.clearRunStatus&&fo(e);t.requestUpdate!==!1&&e.requestUpdate?.()}function vo(e){return e.sessionsResult?.sessions.find(t=>ie(e,t.key,e.sessionKey,t.agentId))}function yo(e){let t=e.lastLocalTerminalReconcile;if(!t||t.sessionKey!==e.sessionKey||t.agentId!==void 0&&t.agentId!==Me(e))return!1;let n=vo(e);return!n||!f(n)?!1:t.runId==null||n.activeRunIds?.length!==1||n.activeRunIds[0]!==t.runId?(e.lastLocalTerminalReconcile=null,!1):(go(e,{outcome:t.phase,sessionStatus:t.sessionStatus,errorMessage:t.errorMessage,sessionKey:t.sessionKey,agentId:t.agentId,runId:t.runId},Date.now()),e.requestUpdate?.(),!0)}function bo(e,t={}){if(!e.chatRunId&&e.chatStream==null)return yo(e);let n=vo(e);return n?So(e,n,t):!1}function xo(e){if(e.chatRunId){let t=vo(e);if(t?.lastRunId===e.chatRunId)return So(e,t,{publishRunStatus:!1})}return e.lastLocalTerminalReconcile!=null&&!e.chatRunId&&e.chatStream==null&&bo(e,{publishRunStatus:!1})}function So(e,t,n={}){if(!ie(e,t.key,e.sessionKey,t.agentId)||!e.chatRunId&&e.chatStream==null||t.hasActiveRun===!0||f(t)||t.hasActiveRun!==!1&&t.status===`running`)return!1;let r=t.status!==void 0;if(t.hasActiveRun!==!1&&!r)return!1;let i=e.chatRunId;if(i&&t.lastRunId!==i&&(t.lastRunId||n.historyRun!==void 0)){let r=n.historyRun;return t.hasActiveRun!==!1||!r||r.runId!==i||r.sessionId!==t.sessionId||!r.isCurrent()?!1:(_o(e,{runId:i,clearLocalRun:!0,clearChatStream:!0,clearToolStreamForRun:!0,clearRunStatus:!0}),!0)}let a;return i&&t.lastRunId===i&&(t.status===`failed`||t.status===`timeout`)&&(a=e.chatRunError?.runId===i?e.chatRunError.summary:t.lastRunError?.trim()||E(t.status===`timeout`?`sessionsView.runErrorTimedOut`:`sessionsView.runErrorUnknown`),e.chatRunError?.runId!==i&&to(e,a,i)),_o(e,{outcome:t.status===`done`?`done`:`interrupted`,sessionStatus:t.status===`running`||t.status===void 0?`killed`:t.status,errorMessage:a,runId:i,sessionKey:e.sessionKey,sessionKeys:[t.key],clearLocalRun:!0,clearChatStream:!0,clearToolStreamForRun:!0,publishRunStatus:n.publishRunStatus,armLocalTerminalReconcile:!!(e.chatRunId&&t.lastRunId===e.chatRunId)}),!0}var Co,wo;function To(){return(To=e((()=>{k(),ce(),Se(),D(),wn(),yn(),Jn(),er(),ir(),Co=5e3,wo=new Set([`/stop`,`stop`,`esc`,`abort`,`wait`,`exit`])})))()}function Eo(){return{id:`side-panel-column`,side:`right`,panels:[],activePanelId:``,height:Uo,width:Ho,browserWidthPending:!0}}function Do(e){if(me(e,`dashboard`))return e.expanded||e.open!==!0?`expanded`:`split`}function Oo(e,t){let n=No(e,`dashboard`);if(t===`expanded`){let e=n.columns[0]?.panels.find(e=>e.slot===`dashboard`);e&&(n=Mo(n,e.id))}else _e(n)?.slot===`dashboard`&&(n=No(n,`conversation`));return Ro(n,t===`expanded`)}function ko(e,t){let n=new Set(e.columns.flatMap(e=>e.panels.map(e=>e.id)));if(!n.has(t))return t;let r=2;for(;n.has(`${t}-${r}`);)r+=1;return`${t}-${r}`}function Ao(e,t){for(let n of e.columns){let r=n.panels.findIndex(e=>e.id===t);if(r<0)continue;let i=n.panels.filter(t=>t.id!==e.mainPanelId).findIndex(e=>e.id===t);if(n.panels.splice(r,1),n.activePanelId===t){let t=n.panels.filter(t=>t.id!==e.mainPanelId);n.activePanelId=t[Math.min(i,t.length-1)]?.id??``}return}}function jo(e){let t=w(e),n=t.columns[0]??=Eo(),r=n.panels.find(e=>e.slot===`conversation`);return r||(r={id:ko(t,`conversation`),slot:`conversation`},n.panels.push(r)),t.mainPanelId=_e(t)?.id??r.id,n.activePanelId===t.mainPanelId&&(n.activePanelId=oe(t)[0]?.id??``),t}function Mo(e,t){if(!e.columns[0]?.panels.find(e=>e.id===t)||_e(e)?.id===t)return w(e);let n=jo(e),r=n.mainPanelId;return n.mainPanelId=t,n.columns[0].activePanelId=r,n.open=!0,n.expanded=!1,delete n.expandedSide,n}function No(e,t){let n=w(e);if((_e(n)?.slot??`conversation`)===t)return n.expandedSide?Ro(n,!1):n;let r=n.columns.find(e=>e.panels.some(e=>e.slot===t))??(n.columns[0]??=Eo()),i=r.panels.find(e=>e.slot===t);return i||(i={id:ko(n,t),slot:t},r.panels.push(i)),r.activePanelId=i.id,n.open=!0,n.expanded&&(n.expanded=!1,delete n.expandedSide),n}function Po(e,t){let n=w(e),r=n.columns.flatMap(e=>e.panels).find(e=>e.slot===t);if(r){if(n.expandedSide&&r.id===Pe(n)?.id&&(n=Ro(n,!1)),t===`conversation`)return r.id!==n.mainPanelId&&(n.open=!1),n;r.id===n.mainPanelId&&(n=jo(n),n.mainPanelId=n.columns[0].panels.find(e=>e.slot===`conversation`).id),Ao(n,r.id);let e=n.columns[0];e&&!Pe(n)&&(e.activePanelId=oe(n)[0]?.id??``),oe(n).length===0&&(n.open=!1)}return n.columns.length===0&&(n.open=!1),n}function Fo(e,t){let n=w(e),r=n.columns.find(e=>e.panels.some(e=>e.id===t));return r&&t!==n.mainPanelId&&(r.activePanelId=t,n.open=!0,n.expanded&&(n.expanded=!1,delete n.expandedSide)),n}function Io(e,t,n,r){let i=w(e),a=i.columns[0]?.panels;if(!a||t===n)return i;let o=a.findIndex(e=>e.id===t),s=a.findIndex(e=>e.id===n);if(o<0||s<0)return i;let[c]=a.splice(o,1),l=a.findIndex(e=>e.id===n);return a.splice(l+ +(r===`after`),0,c),i}function Lo(e,t){let n=w(e);return t&&(n.columns[0]??=Eo(),n.expanded&&(n.expanded=!1,delete n.expandedSide)),n.open=t,!t&&n.expandedSide&&(n.expanded=!1,delete n.expandedSide),n}function Ro(e,t){let n=w(e);return delete n.expandedSide,{...n,expanded:t,...t?{open:!0}:{}}}function zo(e,t){if(!oe(e).some(e=>e.id===t))return w(e);if(e.expanded&&e.expandedSide&&Pe(e)?.id===t)return Ro(e,!1);let n=Fo(jo(e),t);return n.expanded=!0,n.expandedSide=!0,n}function Bo(e,t){return{...w(e),dock:t}}function Vo(e,t,n){let r=w(e),i=r.columns.find(e=>e.id===t);return i&&Number.isFinite(n)&&(ne(r)===`bottom`?i.height=de(n):(i.width=fe(n),delete i.browserWidthPending)),r}var Ho,Uo,Wo;function Go(){return(Go=e((()=>{se(),ee(),Ho=480,Uo=360,Wo=`openclaw-sidebar-geometry-commit`})))()}function Ko(){return(Ko=e((()=>{})))()}function qo(e,t,n){if(e===t)return!0;let r=Ce(e);return!!(n&&ke(t)&&r?.rest===`global`&&o(r.agentId)===o(n))}function Jo(e,t,n){let r=e.presentation,i={id:e.id,request:{command:r.kind===`exec`?r.commandText:r.title,agentId:r.agentId??null,sessionKey:t,allowedDecisions:r.allowedDecisions},...n&&n!==t?{sourceSessionKey:n}:{},createdAtMs:e.createdAtMs,expiresAtMs:e.expiresAtMs};return r.kind===`exec`?{...i,kind:`exec`,request:{...i.request,host:r.host??null}}:r.kind===`plugin`?{...i,kind:`plugin`,pluginTitle:r.title,pluginDescription:r.description,pluginDetail:r.detail,pluginSeverity:r.severity,pluginId:r.pluginId??null}:{...i,kind:`system-agent`,pluginTitle:r.title,pluginDescription:r.description,proposalHash:r.proposalHash}}function Yo(e,t,n){if(!$t(ft,e))return[];let r=nn(ft,e);return qo(r.sessionKey,t,n)?r.approvals.filter(e=>e.status===`pending`).map(e=>Jo(e,t,e.sourceSessionKey)):[]}function Xo(e,t,n,r){if(!$t(at,t))return null;let i=nn(at,t),a=n??i.sessionKey;if(!qo(i.sessionKey,a,r))return null;if(i.phase===`terminal`)return e.filter(e=>e.id!==i.approval.id);let o=e.filter(e=>e.id!==i.approval.id);return o.push(Jo(i.approval,a,i.sourceSessionKey)),o.toSorted((e,t)=>e.createdAtMs-t.createdAtMs)}function Zo(){return(Zo=e((()=>{en(),dt(),D()})))()}function Qo(e){return Array.isArray(e.toolStreamOrder)?e.toolStreamOrder.filter(e=>g(e)!==void 0):[]}function $o(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n&&typeof n==`object`&&d(n.role)===`user`)return t}return-1}function es(e,t){if(!Ka(e))return;let n=t?.preserveStreamSegments?[...e.chatStreamSegments]:null;Ya(e),n&&(e.chatStreamSegments=n)}function ts(e,t){Ka(e)&&Xa(e,t)}function ns(e){Array.isArray(e.chatStreamSegments)&&(e.chatStreamSegments=[])}function rs(e){return s(s(e)?.openclawStreamFallback)}function is(e){let t=rs(e);return t&&!g(t.itemId)?t:null}function as(e,t,n){let r=N(t),i=(r?.role===`assistant`?r.runId:null)??pr(t),a=mr(t)??void 0;if(i)for(let t=e.length-1;t>=0;--t){let n=e[t],r=is(n);if(r&&g(r.runId)===i){a=g(r.afterBoundaryRunId)??a;break}}let o=H(e,{...i?{runId:i}:{},...a?{afterBoundaryRunId:a}:{}}),s=I(it(t))?.trim()??``,c=new Set,l=[],u=0;for(let t=o.start;t<o.end;t+=1){let r=e[t],i=rs(r);if(!i)continue;let a=I(r)?.trim();if(g(i.itemId)){!n?.preserveKeyedCommentary&&a&&a===s&&c.add(t);continue}if(i.source===`current`&&l.push(t),!a)continue;let o=s.slice(u),d=/^\s*/u.exec(o)?.[0].length??0;o.slice(d).startsWith(a)&&(c.add(t),u+=d+a.length)}let d=l[0];c.size===0&&l.length===1&&d!==void 0&&c.add(d);let f=[],p=null;for(let t=o.start;t<o.end;t+=1)c.has(t)?p??=f.length:f.push(e[t]);let m=p??f.length;return[...e.slice(0,o.start),...f.slice(0,m),t,...f.slice(m),...e.slice(o.end)]}function os(e,t){return!e?.trim()||t(e)?null:e}function G(e,t){let n=Or(e),r=[],i=null,a=Array.isArray(e.chatStreamSegments)?e.chatStreamSegments:[],o=0,s;for(let[e,c]of a.entries()){if(!c||typeof c.text!=`string`)continue;let a=typeof c.toolCallId==`string`&&c.toolCallId.trim()?c.toolCallId.trim():null,l=At(c),u=l&&typeof c.itemId==`string`?c.itemId.trim():void 0,d=l?void 0:n[o],f=g(c.runId)??d?.runId,p=g(c.afterBoundaryRunId)??s,m=g(c.boundaryRunId);!l&&c.boundaryMarker!==!0&&c.persisted!==!0&&(o+=1);let h=L(c),_=os(h?bt(c.text,i):c.text,t.isHiddenStreamText);_&&c.persisted!==!0&&r.push({text:_,replacementText:c.text,source:`segment`,segmentIndex:e,timestamp:typeof c.ts==`number`&&Number.isFinite(c.ts)?c.ts:Date.now(),...u?{itemId:u}:{},...f?{runId:f}:{},...p?{afterBoundaryRunId:p}:{},...m?{boundaryRunId:m}:{},toolCallId:a??d?.id}),h&&(i=Tt(i,c.text)),m&&(s=m)}if(t.includeCurrent!==!1&&typeof e.chatStream==`string`){let n=os(bt(e.chatStream,i),t.isHiddenStreamText);n&&r.push({text:n,replacementText:e.chatStream,source:`current`,timestamp:e.chatStreamStartedAt??Date.now(),...e.chatRunId?{runId:e.chatRunId}:{},...s?{afterBoundaryRunId:s}:{}})}return r}function ss(e,t){if(typeof e.chatStream!=`string`)return null;let n=Array.isArray(e.chatStreamSegments)?e.chatStreamSegments:[],r=F(n);return os(bt(e.chatStream,r),t)}function cs(e,t,n,r,i=e.length){if(t.itemId)return e.slice(r,i).some(e=>{let n=M(e);return n!==void 0&&n.itemId===t.itemId&&(!n.runId||!t.runId||n.runId===t.runId)});let a=e.slice(r,i).map(e=>{let r=N(e);return r?.role&&r.role!==`assistant`||r?.runId&&t.runId&&r.runId!==t.runId||n(e)||Tn(e)?null:I(e)?.trim()??null});return[t.replacementText,t.text].some(e=>!!e.trim()&&!ji(a,e.trim()))}function ls(e,t){let n=$o(e)+1;return e.slice(n).some(e=>!e||typeof e!=`object`||d(e.role)!==`assistant`||t(e)?!1:!!I(e)?.trim())}function us(e,t,n){let r=G(t,n),i=n.persistCommentary===!0?r:r.filter(e=>!e.itemId);return r.length>0&&(i.length>0||ls(e,n.isHiddenAssistantMessage))&&i.every(t=>{let r=H(e,t);return cs(e,t,n.isHiddenAssistantMessage,r.start,r.end)})}function ds(e,t){return G(e,t).length>0}function fs(e,t,n){let r=I(it(e))?.trim();if(!r)return!1;let i=G(t,{includeCurrent:!0,isHiddenStreamText:n.isHiddenStreamText}).filter(e=>n.persistCommentary===!0||!e.itemId);if(i.length===0)return!1;let a=0;for(let[e,t]of i.entries()){let n=t.text.trim(),i=r.indexOf(n,a);if(i<0||e===0&&i!==0)return!1;a=i+n.length}return!0}function ps(e,t,n,r,i,a){let o=Or(t),s=i?kr({id:i,...a?{runId:a}:{}},o):void 0,c=s?new Set([s]):i?new Set:new Set(o.map(e=>e.identity));if(c.size===0)return-1;for(let t=n;t<r;t++)if(Dr(e[t]).some(e=>{let t=kr(e,o);return t!==void 0&&c.has(t)}))return t;return-1}function ms(e){if(!e||typeof e!=`object`)return null;let t=e;return h(t.timestamp)??h(t.ts)??null}function hs(e,t,n){let r=e,i=n.persistCommentary===!0,a=n.replacementMessages;for(let e of G(t,n)){if(!i&&e.itemId)continue;let o=a?.length?[...r,...a]:r,s=H(o,e);if(cs(o,e,n.isHiddenAssistantMessage,s.start,s.end))continue;let c=o===r?s:H(r,e),l=e.source===`segment`&&e.toolCallId?ps(r,t,c.start,c.end,e.toolCallId,e.runId):-1;if(n.requirePersistedTool&&l<0)continue;let u=l>=0?l:e.source===`segment`?Oi(r,e.timestamp,c.start,c.end,ms):c.end,d=r.slice(0,u).map(e=>N(e)?.sequence).findLast(e=>typeof e==`number`),f={role:`assistant`,content:[{type:`text`,text:e.text}],timestamp:ki(r,u,e.timestamp,ms),openclawStreamFallback:{replacementText:e.replacementText,source:e.source,...e.itemId?{itemId:e.itemId}:{},...e.runId?{runId:e.runId}:{},...e.afterBoundaryRunId?{afterBoundaryRunId:e.afterBoundaryRunId}:{},...d===void 0?{}:{afterSequence:d}}};r=[...r.slice(0,u),f,...r.slice(u)]}return r}function gs(){return(gs=e((()=>{ct(),P(),p(),Jt(),An(),Bi(),Cr(),Mr()})))()}function _s(e,t,n,r){return e.flatMap((e,i)=>n(e,i)?!(e.runId&&t&&e.runId!==t)&&L(e)?[{...e,persisted:!0,...r?{retiredItemId:r}:{}}]:[]:[e])}function vs(e,t){if(!e.chatStreamSegments||t.length===0)return;let n=new Set(t);e.chatStreamSegments=_s(e.chatStreamSegments,e.chatRunId,(e,t)=>n.has(t))}function ys(e){let t=e.chatRunId;if(!t)return;for(let n of e.chatStreamSegments??[]){if(n.runId!==t||!n.retiredItemId||!n.pendingCommentary)continue;let r=Ss(e,{runId:t,itemId:n.retiredItemId,text:n.pendingCommentary.text,timestamp:n.ts});r&&(e.chatStreamSegments=e.chatStreamSegments?.map(e=>e.runId===t&&e.itemId===n.retiredItemId?{...e,text:r.text}:e))}let n=e.chatStream??F(e.chatStreamSegments??[]);if(!n)return;let r=Ai((e.chatMessages??[]).filter(e=>{let n=N(e);return n?.role===`assistant`&&n.id&&!n.isImported&&n.runId===t&&!M(e)}),n,t),i=n.slice(0,n.length-(r?.length??0));i&&bs(e,t,i,Date.now())}function bs(e,t,n,r,i){let a=e.chatStream??F(e.chatStreamSegments??[]),o=e.chatStreamSegments??[],s=e.chatStream===null?a:F(o),c=(e,r)=>(!i||r===i.segmentIndex)&&e.persisted!==!0&&e.runId===t&&L(e)&&n.startsWith(e.text);if(o.some(c)&&(o=_s(o,t,c,i?.itemId),e.chatStreamSegments=o),Tt(s,n)===s)return;let l=o.at(-1),u=l?.persisted&&l.runId===t&&!l.boundaryRunId&&!l.toolCallId&&!l.retiredItemId&&!i;e.chatStreamSegments=[...u?o.slice(0,-1):o,{...u?l:{},text:n,ts:e.chatStreamStartedAt??r,runId:t,persisted:!0,...i?{retiredItemId:i.itemId}:{}}]}function xs(e,t){let n=t.pendingCommentary,r=e.chatStream??F(e.chatStreamSegments??[]);if(!n||!r?.startsWith(t.text))return null;let i=n.text,a=r.slice(n.prefixLength),o=Wn(a).text,s=o.replace(/\s+/gu,` `).trim(),c=r,l=i,u;if(i.startsWith(s)&&s!==i)u={...n,text:i};else{let e=i.split(/\s+/u).map(zn).join(`\\s+`),s=RegExp(`^\\s*${e}`,`u`).exec(o);if(!s)return null;let u=o.slice(s[0].length).trimEnd(),d=a.trimEnd();if(u&&!d.endsWith(u))return null;c=r.slice(0,Math.max(t.text.length,n.prefixLength+d.length-u.length)),l=s[0].replace(/^(?:[ \t]*\r?\n)+/u,``).trimEnd()}return e.chatStreamSegments=e.chatStreamSegments?.map(e=>e===t?{...e,text:c,pendingCommentary:u}:e.runId===t.runId&&L(e)&&e.text.startsWith(t.text)&&c.startsWith(e.text)?{...e,persisted:!0}:e),{text:l}}function Ss(e,t){if(e.chatRunId!==t.runId)return null;let n=e.chatStreamSegments?.find(e=>e.runId===t.runId&&e.retiredItemId===t.itemId);if(n){let r=n.pendingCommentary&&n.pendingCommentary.text!==t.text?{...n,pendingCommentary:{...n.pendingCommentary,text:t.text}}:n;return r!==n&&(e.chatStreamSegments=e.chatStreamSegments?.map(e=>e===n?r:e)),xs(e,r)}if(e.chatStreamSegments?.some(e=>e.runId===t.runId&&e.itemId===t.itemId))return null;let r=G(e,{includeCurrent:!0,isHiddenStreamText:()=>!1}).at(-1);if(!r||r.itemId||r.runId!==t.runId||r.boundaryRunId)return null;let i=(e.chatStreamSegments??[]).slice(0,r.segmentIndex),a=F(i),o=a&&r.replacementText.startsWith(a)?r.replacementText.slice(a.length):r.replacementText,s=Wn(o).text.replace(/^(?:[ \t]*\r?\n)+/u,``).trimEnd(),c=s.replace(/\s+/gu,` `).trim();return!s||s!==t.text&&c!==t.text?!c||!t.text.startsWith(c)?null:(bs(e,t.runId,r.replacementText,t.timestamp,{itemId:t.itemId,segmentIndex:r.segmentIndex}),e.chatStreamSegments=e.chatStreamSegments?.map(e=>e.runId===t.runId&&e.retiredItemId===t.itemId?{...e,pendingCommentary:{text:t.text,prefixLength:a?.length??0}}:e),{text:t.text}):(bs(e,t.runId,r.replacementText,t.timestamp,{itemId:t.itemId,segmentIndex:r.segmentIndex}),{text:s})}function Cs(e,t){let n=M(t);n&&e.chatStreamSegments&&vs(e,e.chatStreamSegments.flatMap((e,t)=>{let r=g(e.runId),i=!n.runId||!r||n.runId===r;return g(e.itemId)===n.itemId&&i?[t]:[]}))}function ws(e,t,n){if(!Array.isArray(t.chatStreamSegments))return!1;let r=new Set;for(let i of G(t,{includeCurrent:!1,isHiddenStreamText:n.isHiddenStreamText})){if(i.segmentIndex===void 0||i.itemId&&n.persistCommentary!==!0)continue;let t=H(e,i);cs(e,i,n.isHiddenAssistantMessage,t.start,t.end)&&r.add(i.segmentIndex)}return r.size!==0&&(t.chatStreamSegments=_s(t.chatStreamSegments,t.chatRunId,(e,t)=>r.has(t)),!0)}function Ts(e,t){if(t.size===0)return;let n=Or(e);if(e.toolStreamById instanceof Map)for(let n of t)e.toolStreamById.delete(n);if(Array.isArray(e.toolStreamOrder)&&(e.toolStreamOrder=e.toolStreamOrder.filter(e=>typeof e==`string`&&!t.has(e))),Array.isArray(e.chatToolMessages)&&(e.chatToolMessages=e.chatToolMessages.filter(e=>Dr(e).every(e=>{let r=kr(e,n);return r===void 0||!t.has(r)}))),!Array.isArray(e.chatStreamSegments))return;let r=0;e.chatStreamSegments=_s(e.chatStreamSegments,e.chatRunId,e=>{if(e.boundaryMarker===!0||e.persisted===!0)return!1;let i=g(e.toolCallId),a=At(e),o=a?void 0:n[r];a||(r+=1);let s=g(e.runId),c=i?kr({id:i,...s?{runId:s}:{}},n):o?.identity;return!!(c&&t.has(c))})}function Es(){return(Es=e((()=>{P(),Un(),Bi(),gs(),Mr()})))()}function K(e,t){let n=_(t);if(!n)return null;let r=_(e);if(r){let e=`${r}/`;return`${r}/${(d(n).startsWith(d(e))?n.slice(e.length).trim():n)||n}`}let i=n.indexOf(`/`);if(i>0){let e=n.slice(0,i).trim(),t=n.slice(i+1).trim();if(e&&t)return`${e}/${t}`}return n}function Ds(e,t){if(Array.isArray(e)){let t=e.map(e=>_(e)).filter(e=>!!e).map(e=>C(e));if(t.length>0)return t}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=r(e),i=_(t?.provider),a=_(t?.model);if(!i||!a)continue;let o=C(_(t?.reason)?.replace(/_/g,` `)??_(t?.code)??(typeof t?.status==`number`?`HTTP ${t.status}`:null)??_(t?.error)??`error`),s=K(i,a)??`${i}/${a}`;n.push(`${s}: ${le(o)}`)}return n}function Os(e){if(e.localRunId)return e.localRunId;let t=new Set(e.activeRunIds??[]);return e.queue?.find(e=>e.sendState===`waiting-reconnect`&&typeof e.sendRunId==`string`&&t.has(e.sendRunId))?.sendRunId??null}function ks(e,t){let n=e.waitingApprovalStatuses??=new Map,r=e.waitingApprovalResolvedIds??=new Set,i=new Set(t.map(e=>e.id));for(let e of r)i.has(e)||r.delete(e);let a=t.filter(t=>t.kind===`exec`&&t.request.sessionKey&&S(e,t.request.sessionKey,t.request.agentId)),o=new Set(a.map(e=>e.id)),s=!1;for(let e of n.keys())o.has(e)||(n.delete(e),s=!0);if(n.size>0)return s;for(let t of a){let i=_(t.request.runId);i&&e.knownAgentRunIds?.has(i)&&!r.has(t.id)&&(n.set(t.id,{approvalId:t.id,toolCallId:null,runId:i}),s=!0)}return s}function As(e){e.compactionClearTimer!=null&&(window.clearTimeout(e.compactionClearTimer),e.compactionClearTimer=null)}function q(e,t,n,r){let i=n===`complete`,a=e.compactionStatus,o=a?.runId===t&&(!r||!a.itemId||a.itemId===r),s=r??(o?a?.itemId:void 0);As(e),e.compactionStatus={phase:n,runId:t,...s?{itemId:s}:{},startedAt:o?a.startedAt:Date.now(),completedAt:i?Date.now():null},i||(e.compactionClearTimer=window.setTimeout(()=>{let r=e.compactionStatus;r?.phase!==n||t&&r?.runId!==t||(e.compactionStatus=null,e.compactionClearTimer=null,e.requestUpdate?.())},Rs))}function js(e,t){if(!t||t.operation!==`compact`)return;let n=_(t.sessionKey),r=_(t.agentId)??void 0;if(!n||!S(e,n,r))return;let i=_(t.operationId)??`session-compact:${n}`;if(t.phase===`start`){q(e,i,`active`);return}if(t.phase===`end`&&!(e.compactionStatus?.runId&&e.compactionStatus.runId!==i)){if(t.completed===!0){q(e,i,`complete`);return}As(e),e.compactionStatus=null}}function Ms(e,t){let n=t.data??{},r=typeof n.phase==`string`?n.phase:``,i=n.completed===!0,a=_(n.itemId)??void 0;if(As(e),r===`start`){q(e,t.runId,`active`,a);return}if(r===`end`){if(n.willRetry===!0&&i){q(e,t.runId,`retrying`,a);return}if(i){q(e,t.runId,`complete`,a);return}e.compactionStatus=null}}function Ns(e,t){let n=t.data??{},r=_(n.phase);(r===`end`||r===`error`)&&Ps(e,t)&&e.compactionStatus?.phase===`retrying`&&(e.compactionStatus.runId&&e.compactionStatus.runId!==t.runId||q(e,t.runId,`complete`))}function Ps(e,t){let n=typeof t.sessionKey==`string`?t.sessionKey:void 0;return n&&!S(e,n,_(t.agentId))?!1:e.chatRunId?t.runId===e.chatRunId:!!n}function Fs(e,t){let n=t.data??{},r=t.stream===`fallback`?`fallback`:_(n.phase);if(t.stream===`lifecycle`&&r!==`fallback`&&r!==`fallback_cleared`||!Ps(e,t))return;let i=K(n.selectedProvider,n.selectedModel)??K(n.fromProvider,n.fromModel),a=K(n.activeProvider,n.activeModel)??K(n.toProvider,n.toModel),o=K(n.previousActiveProvider,n.previousActiveModel)??_(n.previousActiveModel);if(!i||!a||r===`fallback`&&i===a)return;let s=_(n.reasonSummary)??_(n.reason),c=s?C(s):null,l=Ds(n.attemptSummaries,n.attempts);e.fallbackClearTimer!=null&&(window.clearTimeout(e.fallbackClearTimer),e.fallbackClearTimer=null),e.fallbackStatus={phase:r===`fallback_cleared`?`cleared`:`active`,selected:i,active:r===`fallback_cleared`?i:a,previous:r===`fallback_cleared`?o??(a===i?void 0:a):void 0,reason:c??void 0,attempts:l,occurredAt:Date.now()},e.fallbackClearTimer=window.setTimeout(()=>{e.fallbackStatus=null,e.fallbackClearTimer=null,e.requestUpdate?.()},zs)}function Is(e,t){let n=_(t.data?.phase);if(n!==`waiting-approval`&&n!==`approval-resolved`)return!1;let r=_(t.data?.approvalId),i=_(t.sessionKey);if(!r||!i)return!0;if(n===`waiting-approval`){let n=e.waitingApprovalStatuses??=new Map;return e.waitingApprovalResolvedIds?.delete(r),n.set(r,{approvalId:r,toolCallId:_(t.data?.toolCallId),runId:t.runId}),!0}return(e.waitingApprovalResolvedIds??=new Set).add(r),e.waitingApprovalStatuses?.delete(r),!0}function Ls(e,t){if(t.stream===`run_status`&&t.data.phase===`retrying`){let n=_(t.data.message);return n&&mn(e,{state:`status`,runId:t.runId,phase:`retrying`,message:le(n.slice(0,256)),seq:t.seq}),!0}return t.stream===`assistant`?(mn(e,{state:`activity`,runId:t.runId,seq:t.seq}),!0):t.stream===`compaction`?(Ms(e,t),!0):t.stream===`lifecycle`?Is(e,t)?!0:(Ns(e,t),Fs(e,t),!0):t.stream===`fallback`&&(Fs(e,t),!0)}var Rs,zs;function Bs(){return(Bs=e((()=>{Oe(),D(),In(),Rs=3e5,zs=8e3})))()}function Vs(e){if(e.stream!==`item`)return null;let t=e.data??{};if(t.kind!==`preamble`)return null;let n=g(t.itemId)??g(t.id),r=Hs(t.progressText);return!r&&!n?null:{text:r,...n?{itemId:n}:{}}}function Hs(e){if(typeof e!=`string`)return``;let t=Wn(e).text.trim(),n=t.replace(/^[\s*_`~]+|[\s*_`~]+$/gu,``).trim();return/^NO_REPLY$/iu.test(n)?``:t}function Us(e,t){let n=Vs(t);if(!n)return!1;if(!et({phase:typeof t.data.phase==`string`?t.data.phase:void 0,progressText:n.text})||!Ps(e,t))return!0;n.text&&mn(e,{state:`activity`,runId:t.runId,seq:t.seq});let r=n.itemId?e.chatStreamSegments.findIndex(e=>e.itemId===n.itemId&&e.runId===t.runId):-1,i=e.chatStreamSegments[r];if(n.text=(n.itemId&&n.text?Ss(e,{runId:t.runId,itemId:n.itemId,text:n.text,timestamp:t.ts}):null)?.text??n.text,n.itemId&&e.chatMessages?.some(e=>{let r=M(e);return r?.itemId===n.itemId&&r?.runId===t.runId})||n.itemId&&!n.text.trim())return e.chatStreamSegments=e.chatStreamSegments.filter(e=>e.itemId!==n.itemId||e.runId!==t.runId),!0;if(i)return e.chatStreamSegments=e.chatStreamSegments.map(e=>e===i?{...e,text:e.text.replace(/\s+/gu,` `).trim()===n.text?e.text:n.text}:e),!0;let a=e.chatStreamSegments[e.chatStreamSegments.length-1];return!n.itemId&&a&&!a.toolCallId&&a.text===n.text||(e.chatStreamSegments=[...e.chatStreamSegments,{text:n.text,ts:t.ts,runId:t.runId,...n.itemId?{itemId:n.itemId}:{}}]),!0}function Ws(){return(Ws=e((()=>{P(),Qe(),Un(),In(),Es(),Bs()})))()}function Gs(e){let t=r(e);if(!t)return null;if(typeof t.text==`string`)return t.text;if(!Array.isArray(t.content))return null;let n=[];for(let e of t.content){let t=r(e);t?.type===`text`&&typeof t.text==`string`&&t.text&&n.push(t.text)}return n.length>0?n.join(`
`):null}function Ks(e){if(e==null)return null;if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=Gs(e),n;if(typeof e==`string`)n=e;else if(t)n=t;else try{n=JSON.stringify(e,null,2)}catch{n=ue(e)}let r=te(n,lc);return r.truncated?`${r.text}\n\n… truncated (${r.total} chars, showing first ${r.text.length}).`:r.text}function qs(e){let t=r(e),n=t?.added,i=t?.removed;return typeof n==`number`&&Number.isInteger(n)&&n>=0&&typeof i==`number`&&Number.isInteger(i)&&i>=0?{added:n,removed:i}:void 0}function Js(e,t){let n=r(r(t.result)?.details);if(n?.changedModel!==!0)return;let i=_(n.sessionKey)??e.sessionKey,a=_(n.agentId);a&&S(e,i,a)&&e.sessions.reconcileMutation(a)}function Ys(e){let t=[];return t.push({type:`toolcall`,name:e.name,arguments:e.args??{},...e.parentToolCallId?{parentToolCallId:e.parentToolCallId}:{},...e.details===void 0?{}:{details:e.details}}),(e.output||e.resultReceived)&&t.push({type:`toolresult`,name:e.name,text:e.output??``,...e.parentToolCallId?{parentToolCallId:e.parentToolCallId}:{},...e.details===void 0?{}:{details:e.details},...e.isError===void 0?{}:{isError:e.isError},...e.exitCode===void 0?{}:{exitCode:e.exitCode}}),{role:`assistant`,toolCallId:e.toolCallId,runId:e.runId,...e.activity?{activity:e.activity}:{},content:t,timestamp:e.startedAt,__openclawToolStreamLive:!0,__openclawToolStreamResultReceived:e.resultReceived===!0,...e.resultReceived!==!0&&e.liveDiffStat?{__openclawToolStreamDiffStat:e.liveDiffStat}:{},__openclawToolStreamReceivedAt:e.receivedAt}}function Xs(e){if(e.toolStreamOrder.length<=sc)return;let t=e.toolStreamOrder.length-sc,n=e.toolStreamOrder.splice(0,t);for(let t of n)e.toolStreamById.delete(t)}function Zs(e){Ja(e),qa(e)}function Qs(e,t=!1){if(t){Zs(e);return}e.toolStreamSyncTimer??=window.setTimeout(()=>{Zs(e),e.requestUpdate?.()},cc)}function $s(e,t){return`tool:${wr(e,t)}`}function ec(e,t){return`${e}:review:${JSON.stringify(t)}`}function tc(e,t){let n=Number.isSafeInteger(t.seq)?t.seq:0;if(t.stream===`tool`){let i=_(t.data?.toolCallId);if(!i)return!0;let a=$s(t.runId,i),o=`${a}:result`,s=e.activityEventSeqById?.get(o),c=_(t.data?.phase);if(c!==`result`&&s!==void 0&&n<=s)return!1;let l=c===`review`?_(r(t.data.review)?.id):void 0,u=e.activityEventSeqById?.get(`${a}:review-floor`);if(l&&u!==void 0&&n<=u)return!1;let d=l?ec(a,l):a,f=e.activityEventSeqById?.get(d);if(f!==void 0&&n<=f)return!1;let p=e.activityEventSeqById??=new Map;if(p.set(d,n),c===`result`){p.set(o,n);for(let e of p.keys())e.startsWith(`${a}:review:`)&&p.delete(e)}return!0}let i,a=t.stream===`lifecycle`&&(t.data?.phase===`end`||t.data?.phase===`error`);if(t.stream===`compaction`||a)i=`compaction:${t.runId}`;else if(t.stream===`item`){let e=_(t.data.itemId)??_(t.data.id)??`latest`;i=`item:${t.runId}:${e}`}else return!0;let o=e.activityEventSeqById?.get(i);return o!==void 0&&n<=o?!1:((e.activityEventSeqById??=new Map).set(i,n),!0)}function nc(e,t){if(t.stream!==`usage`)return!1;let n=_(t.sessionKey);if(n){if(!S(e,n,_(t.agentId)))return!0}else if(!e.chatRunId||t.runId!==e.chatRunId)return!0;let r=t.data?.outputTokens;if(typeof r!=`number`||!Number.isFinite(r))return!0;let i=Math.floor(r);if(i<0)return!0;let a=e.chatRunUsageById?.get(t.runId);if(a&&t.seq<=a.seq)return!0;let o=new Map(e.chatRunUsageById);o.delete(t.runId),o.set(t.runId,{outputTokens:i,seq:t.seq});for(let e of[...o.keys()].slice(0,-50))o.delete(e);return e.chatRunUsageById=o,!0}function rc(e,t){let n=t.stream===`notice`;if(!n&&t.stream!==`codex_app_server.guardian`)return!1;if(!Ps(e,t))return!0;let r=t.data??{},i=_(r.phase);if(n&&i===`provider_policy`){if(r.category!==`cyber`||r.provider!==`openai`)return!0;let n=r.state;if(n!==`buffering`&&n!==`blocked`&&n!==`fallback`&&n!==`escalated`&&n!==`unavailable`&&n!==`cleared`)return!0;let i=e.chatRunId??rr(e)??e.providerPolicyNotice?.runId,a=e.chatQueue?.some(n=>n.sendState===`sending`&&n.sendRunId===t.runId&&n.sessionKey&&S(e,n.sessionKey,n.agentId));if(i!==t.runId&&!a)return!0;let o=`provider-policy:${t.runId}`,s=Math.max(e.activityEventSeqById?.get(o)??-1,e.providerPolicyNotice?.runId===t.runId?e.providerPolicyNotice.seq:-1);if(!Number.isSafeInteger(t.seq)||t.seq<=s)return!0;if((e.activityEventSeqById??=new Map).set(o,t.seq),n===`cleared`)return e.providerPolicyNotice?.runId===t.runId&&e.providerPolicyNotice.state===`buffering`&&(e.providerPolicyNotice=null),!0;let c=e.providerPolicyNotice;if(c?.runId===t.runId&&oc[n]<oc[c.state])return!0;let l=_(r.model),u=_(r.fallbackModel);return e.providerPolicyNotice={runId:t.runId,seq:t.seq,state:n,...l?{model:le(l.slice(0,256))}:{},...u?{fallbackModel:le(u.slice(0,256))}:{}},!0}let a=_(r.status),o=_(r.reviewId),s=_(r.threadId),c=_(r.turnId),l=o??(s&&c&&typeof r.startedAtMs==`number`&&Number.isFinite(r.startedAtMs)?r.startedAtMs:t.seq),u=`${n?`system`:`guardian`}:${t.runId}:`+(i===`warning`?`warning:${t.seq}`:`${s??`thread`}:${c??`turn`}:${l}`),d=e.guardianNotices??[],f=i===`strict_review_required`?`strict-review-required`:i===`warning`?`warning`:i===`started`&&a===`inProgress`?`reviewing`:i===`completed`&&a===`approved`?`approved`:i===`completed`&&[`denied`,`timedOut`,`aborted`].includes(a??``)?`denied`:null;if(!f)return!0;let p=_(r.targetItemId);if((i===`started`||i===`completed`)&&p)return i===`completed`&&(e.guardianNotices=d.filter(e=>e.key!==u)),!0;let m={key:u,runId:t.runId,timestamp:t.ts,kind:f};n&&(m.source=`system`);for(let e of[`command`,`riskLevel`,`rationale`,`message`]){let t=_(r[e]);t&&(m[e]=t)}let h=d.findIndex(e=>e.key===m.key);return e.guardianNotices=h===-1?[...d.slice(-49),m]:d.map((e,t)=>t===h?m:e),!0}function ic(e,t,n,r){let i=n.toolCallId,a=$s(t.runId,i),o=e.activityEventSeqById??=new Map,s=e=>o.get(ec(a,e.id))??0,c=`${a}:review-floor`,l=Mt(n.details),u=Math.max(o.get(c)??0,...l.map(s)),d=[...l.filter(e=>e.id!==r.id),r].toSorted((e,t)=>s(e)-s(t)),f=d.slice(0,-16),p=d.slice(-16);if(f.length>0){o.set(c,Math.max(o.get(c)??0,...f.map(s)));for(let e of f)o.delete(ec(a,e.id))}let m=wt(t.data),h=Ft(p),g=wt(n.details),_=g===`denied`?`denied`:m??h??void 0;n.details=Ct(n.details,p,_&&t.seq>=u?_:g),n.message=Ys(n),Qs(e,!0)}function ac(e,t){if(!t)return!1;let n=typeof t.sessionKey==`string`?t.sessionKey:void 0;if(n&&!S(e,n,_(t.agentId))||!tc(e,t))return!1;if(t.stream===`lifecycle`||t.stream===`tool`){let n=_(t.runId);n&&(e.knownAgentRunIds??=new Set).add(n)}if(nc(e,t)||rc(e,t)||Ls(e,t)||Us(e,t))return!0;let i=t.stream===`item`?tn(st,{...t.data}):void 0;if($t(st,i)){if(!Ps(e,t))return!0;let r=i,a=r.toolCallId??r.itemId,o=wr(t.runId,a),s=e.toolStreamById.get(o);return s||(s={toolCallId:a,runId:t.runId,sessionKey:n,name:r.name??r.title,startedAt:r.startedAt??t.ts,receivedAt:Date.now(),message:{}},e.toolStreamById.set(o,s),e.toolStreamOrder.push(o)),s.activity=[...(s.activity??[]).filter(e=>e.itemId!==r.itemId),r],s.message=Ys(s),Xs(e),Qs(e,r.phase===`end`),!0}if(t.stream!==`tool`)return!1;let a=t.data??{},o=typeof a.toolCallId==`string`?a.toolCallId:``;if(!o)return!1;let s=wr(t.runId,o),c=e.toolStreamById.get(s),l=typeof a.phase==`string`?a.phase:``,u=l===`review`?Ln(a.review):null;if(l===`review`&&!u)return!0;let d=l!==`start`&&c?.name&&c.name!==`tool`?c.name:_(a.name)??c?.name??`tool`;t.runId===e.chatRunId&&mn(e,{state:`activity`,runId:t.runId,seq:t.seq});let f=l===`start`?a.args:void 0,p=_(a.parentToolCallId)??void 0,m=l===`update`?Ks(a.partialResult):l===`result`?Ks(a.result):void 0,h=l===`result`?r(a.result):void 0,g=h?.details,v=wt(a)??wt(g),y=v?Ct(g,[],v):g,b=l===`result`&&typeof a.isError==`boolean`?a.isError:void 0,ee=h?.exitCode,te=typeof ee==`number`&&Number.isInteger(ee)?ee:void 0,ne=l===`input_delta`?qs(a.diff):void 0;d===`session_status`&&l===`result`&&Js(e,a);let x=Date.now();if(!c)c={toolCallId:o,runId:t.runId,...p?{parentToolCallId:p}:{},sessionKey:n,name:d,args:f,output:m||void 0,...y===void 0?{}:{details:y},...b===void 0?{}:{isError:b},...te===void 0?{}:{exitCode:te},...ne?{liveDiffStat:ne}:{},...l===`result`?{resultReceived:!0}:{},startedAt:typeof t.ts==`number`?t.ts:x,receivedAt:x,message:{}},e.toolStreamById.set(s,c),e.toolStreamOrder.push(s);else{if(c.name=d,c.parentToolCallId??=p,f!==void 0&&(c.args=f),m!==void 0&&(c.output=m||void 0),g!==void 0||v){let e=wt(c.details),t=e===`denied`?`denied`:v??e,n=Mt(c.details);c.details=n.length?Ct(g,n,t):y}b!==void 0&&(c.isError=b),te!==void 0&&(c.exitCode=te),ne&&(c.liveDiffStat=ne),l===`result`&&(c.liveDiffStat=void 0,c.resultReceived=!0)}return u?(Xs(e),ic(e,t,c,u),!0):(c.message=Ys(c),Xs(e),Qs(e,l===`result`),!0)}var oc,sc,cc,lc;function uc(){return(uc=e((()=>{en(),ht(),Bn(),Nt(),Oe(),pe(),D(),In(),er(),Mr(),Ws(),Bs(),oc={buffering:0,fallback:1,blocked:2,escalated:3,unavailable:3},sc=50,cc=80,lc=12e4})))()}function dc(e,t,n,r,i){if(t.kind!==`live`)return null;if(t.activeRunId)return i&&i!==t.activeRunId?null:t.activeRunId;let a=e.lastLocalTerminalReconcile,o=a?.sessionKey===e.sessionKey?a.runId:null;if(!o)return null;if(i)return i===o?o:null;let s=Zn(e,r).runs[o]?.message,c=I(s)?.trim();return c&&c===I(n)?.trim()?o:null}function fc(e,t,n,r){let i=c(t),a=i.message,o=c(a),s=N(a,i);if(!s)return;let l=$n(e,{agentId:bn(e)}),u=!!(s.role===`assistant`&&s.sequence!==null&&s.runId&&r.kind===`live`&&r.activeRunId&&s.runId!==r.activeRunId),d=s.runId===i.runId?s.runId:null,f=s.role===`assistant`&&s.id&&!s.isImported&&(d||!s.runId&&n!==!0)?dc(e,r,a,l,d):null,p=jt(s.role)===`tool`&&s.id&&s.sequence!==null&&!s.isImported&&d&&Array.isArray(o.content)&&o.content.some(e=>{let t=c(e);return t.type===`image`&&typeof t.artifactId==`string`&&t.artifactId.trim()})?dc(e,r,a,l,d):null;if(r.kind===`live`&&s.role!==`user`&&!u&&!f&&!p||s.isImported&&!s.externalSource&&ut(a)===null||!s.id&&!s.idempotencyKey&&s.sequence===null)return;let m=c(o.__openclaw),h={...o,__openclaw:{...m,...s.id?{id:s.id}:{},...s.idempotencyKey?{idempotencyKey:s.idempotencyKey}:{},...s.sequence===null?{}:{seq:s.sequence},...d?{runId:d}:{}}},g=tr(e,{type:`messagePersisted`,message:h,envelope:f?{...i,runId:f}:i},{scope:l,runActive:n});s.role===`assistant`&&g.messages.includes(h)&&(Cs(e,h),f&&n===!1&&(e.chatStream=null,e.chatStreamStartedAt=null,ts(e,f)),ys(e));let _=wi(h),v=e.chatRunId,y=_?Ei(g.messages,_):null;s.role===`user`&&(n===!0||n===void 0&&v===_)&&s.runId&&_&&(!v||v===_||v===s.runId)&&y?.runId===s.runId&&Di(e)!==s.runId&&(e.chatRunId=_,zi(e,{runId:_,boundaryRunId:s.runId}))}function pc(){return(pc=e((()=>{P(),Jt(),St(),_n(),er(),Bi(),gs(),Es()})))()}function mc(e,t,n){return{columns:[{id:e,panes:[{id:t,sessionKey:n}],paneWeights:[1]}],columnWeights:[1],activePaneId:t}}function hc(e,t,n){let r=a(e[t],`${n} before divider`);return r/(r+a(e[t+1],`${n} after divider`))}function J(e){return{columns:e.columns.map(e=>({...e,panes:e.panes.map(e=>({...e})),paneWeights:[...e.paneWeights]})),columnWeights:[...e.columnWeights],activePaneId:e.activePaneId}}function gc(e){return`c${e.columns.reduce((e,t)=>Math.max(e,je(t.id,`c`)),0)+1}`}function _c(e){return`p${X(e).reduce((e,t)=>Math.max(e,je(t.id,`p`)),0)+1}`}function Y(e,t){for(let[n,r]of e.columns.entries()){let e=r.panes.findIndex(e=>e.id===t),i=r.panes[e];if(i)return{column:r,columnIndex:n,pane:i,paneIndex:e}}return null}function X(e){return e.columns.flatMap(e=>e.panes)}function vc(e,t){if(!t)return X(e);let n=Y(e,e.activePaneId)?.pane;return n?[n]:[]}function yc(e,t,n,r){let i=Y(e,t),o=J(e);if(!i)return o;let s=_c(e);if(r===`left`||r===`right`){let t=a(o.columnWeights[i.columnIndex],`split column weight for located pane`),c=i.columnIndex+ +(r===`right`);o.columns.splice(c,0,{id:gc(e),panes:[{id:s,sessionKey:n}],paneWeights:[1]}),o.columnWeights.splice(i.columnIndex,1,t/2,t/2)}else{let e=o.columns[i.columnIndex];if(!e)return o;let t=a(e.paneWeights[i.paneIndex],`split pane weight for located pane`),c=i.paneIndex+ +(r===`down`);e.panes.splice(c,0,{id:s,sessionKey:n}),e.paneWeights.splice(i.paneIndex,1,t/2,t/2)}return o.activePaneId=s,o}function bc(e,t,n){let r=Y(e,t);if(!r)return J(e);let i=J(e),a=i.columns[r.columnIndex];if(!a)return i;let o=i.activePaneId===t,s=i.activePaneId;o&&(s=a.panes[r.paneIndex-1]?.id??i.columns[r.columnIndex-1]?.panes.at(-1)?.id??i.columns.flatMap(e=>e.panes).find(e=>e.id!==t)?.id??``),a.panes.splice(r.paneIndex,1),a.paneWeights.splice(r.paneIndex,1),a.panes.length===0?(i.columns.splice(r.columnIndex,1),i.columnWeights.splice(r.columnIndex,1)):a.paneWeights=re(a.paneWeights);let c=X(i);if(!(c.length<=1&&!n?.has(c[0]?.id??``)))return i.columnWeights=re(i.columnWeights),i.activePaneId=s,i}function xc(e,t,n){let r=J(e),i=Y(r,t)?.pane;return i&&(i.sessionKey=n),r}function Sc(e,t){let n=J(e);return Y(e,t)&&(n.activePaneId=t),n}function Cc(e,t,n){if(t.kind===`split`){let r=n?X(e).find(e=>e.sessionKey===n):void 0;return n&&!r?e:yc(e,r?.id??e.activePaneId,t.sessionKey,t.direction)}let r=X(e).find(e=>e.sessionKey===t.sessionKey);return r?t.kind===`close-pane`?bc(e,r.id):Sc(e,r.id):e}function wc(e,t,n){let r=[...e];if(t<0||t+1>=e.length)return r;let i=e[t],a=e[t+1];if(i===void 0||a===void 0)return r;let o=i+a,s=Math.max(Dc,Math.min(.85,n));return r[t]=o*s,r[t+1]=o*(1-s),r}function Tc(e,t,n){let r=J(e);return r.columnWeights=wc(r.columnWeights,t,n),r}function Ec(e,t,n,r){let i=J(e),a=i.columns.find(e=>e.id===t);return a&&(a.paneWeights=wc(a.paneWeights,n,r)),i}var Dc;function Oc(){return(Oc=e((()=>{m(),Ne(),Dc=.15})))()}function kc(e,t){if(!(e.currentTarget instanceof t))throw TypeError(`Skill library listener requires ${t.name}.`);return e.currentTarget}function Ac(){return(Ac=e((()=>{})))()}function jc(e){if(e.encoding!==`base64`)return e.content;try{let t=Uint8Array.from(atob(e.content),e=>e.charCodeAt(0)),n=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(t);return n.includes(`\0`)?null:n}catch{return null}}async function Mc(e,t){if(O(t),e.length>256||e.some(e=>e.size>1048576)||e.reduce((e,t)=>e+t.size,0)>8388608)throw Error(E(`skillLibrary.bundleLimit`));let n,r=[];for(let i of e){O(t);let e=i.webkitRelativePath?i.webkitRelativePath.split(`/`).slice(1).join(`/`):i.name,a=new Uint8Array(await i.arrayBuffer());O(t),e===`SKILL.md`?n=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(a):r.push({path:e,content:De(a),encoding:`base64`})}if(n===void 0)throw Error(E(`skillLibrary.missingSkill`));return{content:n,files:r}}async function Nc(e,t,n,r,i){if(O(i),t.size<1||t.size>8388608)throw Error(E(`skillLibrary.bundleLimit`));let a=new Uint8Array(await t.arrayBuffer());O(i);let o=Array.from(new Uint8Array(await crypto.subtle.digest(`SHA-256`,a)),e=>e.toString(16).padStart(2,`0`)).join(``),s=t=>{if(O(i),!r())throw Error(E(`skillLibrary.connectionChanged`));return e.request(`skills.library.upload`,t)},c=await s({action:`begin`,slug:n,sizeBytes:a.length,sha256:o});if(!(`uploadId`in c))throw Error(E(`skillLibrary.uploadFailed`));let l=c.offset;for(;l<a.length;){let e=Math.min(l+c.maxChunkBytes,a.length),t=await s({action:`chunk`,uploadId:c.uploadId,offset:l,data:De(a.subarray(l,e))});if(!(`offset`in t)||t.offset!==e)throw Error(E(`skillLibrary.uploadFailed`));l=t.offset}let u=await s({action:`commit`,uploadId:c.uploadId});if(!(`state`in u))throw Error(E(`skillLibrary.uploadFailed`));return u}function Pc(){return(Pc=e((()=>{lt(),k(),Ut(),xe(),Ht()})))()}function Fc(e){return A`<details class="muted" style="overflow-wrap: anywhere; min-width: 0;">
<summary>${E(`skillLibrary.technicalDetails`)}</summary>
<dl>
<dt>${E(`skillLibrary.skillId`)}</dt>
<dd>${e.skillId}</dd>
<dt>${E(`skillLibrary.revision`)}</dt>
<dd>${e.revision}</dd>
<dt>${E(`skillLibrary.command`)}</dt>
<dd>${e.name}</dd>
</dl>
</details>`}function Ic(e,t,n=!1){return A`<div class="exec-approval-header">
<strong class="exec-approval-title">${e}</strong
><button
type="button"
class="btn btn--icon btn--ghost"
aria-label=${E(`common.close`)}
?disabled=${n}
@click=${t}
>
${Ke.x}
</button>
</div>`}function Lc(e){let{read:t}=e,n=t.files.find(t=>t.path===e.file),r=e.file===`SKILL.md`?t.content:n?jc(n):null;return A`<openclaw-modal-dialog
label=${t.entry.slug}
style="--openclaw-modal-width: 960px;"
@modal-cancel=${e.onClose}
>
<div class="exec-approval-card skill-reader-dialog">
${Ic(t.entry.slug,e.onClose)}
<div
class="skill-reader-dialog__body"
style="display: grid; gap: var(--space-4); min-width: 0;"
>
<p>
${E(`skillLibrary.ownerRevision`,{owner:t.entry.ownerLabel,revision:t.entry.revision.slice(0,8)})}
</p>
<p class="muted">${E(`skillLibrary.session.readOnly`)}</p>
<label class="field"
><span>${E(`skillLibrary.file`)}</span
><select
class="settings-select"
.value=${e.file}
@change=${t=>e.onFile(kc(t,HTMLSelectElement).value)}
>
<option value="SKILL.md" ?selected=${e.file===`SKILL.md`}>SKILL.md</option>
${t.files.map(t=>A`<option value=${t.path} ?selected=${e.file===t.path}>
${t.path}
</option>`)}
</select></label
>
${r===null?A`<p class="muted">${E(`skillLibrary.binaryRead`)}</p>`:A`<label class="field"
><span>${e.file}</span
><textarea
class="settings-input"
readonly
spellcheck="false"
rows="16"
style="font-family: var(--mono); min-width: 0; max-width: 100%; box-sizing: border-box; resize: vertical;"
.value=${r}
></textarea>
</label>`}
${Fc(t.entry)}
</div>
</div>
</openclaw-modal-dialog>`}function Rc(){return(Rc=e((()=>{Ze(),Je(),k(),Pc(),He()})))()}function zc(){return{entries:[],nextEntryId:1,userEntryId:null,userEntryAwaitingFinal:!1,userEntryAwaitingFinalStartedAtMs:null,assistantEntryId:null}}function Bc(e){return{...zc(),nextEntryId:e.nextEntryId,entries:e.entries.map((e,t)=>({...e,order:t,isStreaming:!1}))}}function Vc(e,t){let n=Hc(e,t);if(!t.transcriptId||n===e)return n;let r=t.itemId===void 0?n.entries.findLastIndex(e=>e.role===t.role):n.entries.findIndex(e=>e.id===`item-${t.itemId}`);if(r<0)return n;let i=n.entries.slice();return i[r]={...i[r],transcriptId:t.transcriptId},{...n,entries:i}}function Hc(e,t){let n=t.text;if(t.final?n.trim()===``:n===``)return e;if(t.itemId!==void 0){let r=`item-${t.itemId}`,i=e.entries.find(e=>e.id===r),a={id:r,role:t.role,order:t.order,text:Xc(t.final?n:(i?.text??``)+n),isStreaming:!t.final};return Uc({...e,entries:[...e.entries.filter(e=>e.id!==r),a]})}let r=t.nowMs??Date.now();if(t.textMode===`verbatim`||t.textMode===`snapshot`)return Wc(e,t.role,t.role===`user`?e.userEntryId:e.assistantEntryId,n,t.final,t.textMode);if(t.role===`assistant`){let i=Kc(e,`user`,r);return Wc(i,t.role,i.assistantEntryId,n,t.final)}let i=e.userEntryId,a=i!==null&&qc(e,i,n,t.final,r),o=i===null||a?Kc(e,`assistant`,r):e;return Wc(a&&i!==null?{...Kc(o,`user`,r),userEntryId:null,userEntryAwaitingFinal:!1,userEntryAwaitingFinalStartedAtMs:null}:o,t.role,a?null:i,n,t.final)}function Uc(e,t=[]){let n=new Map(t.map(({itemId:e,order:t})=>[`item-${e}`,t]));return{...e,entries:e.entries.map(e=>n.has(e.id)?{...e,order:n.get(e.id)}:e).toSorted((e,t)=>(e.order??1/0)-(t.order??1/0)).slice(-60)}}function Wc(e,t,n,r,i,a){if(n===null){let n=`rt-${e.nextEntryId}`,o=[...e.entries,{id:n,role:t,text:Xc(a?r:r.trimStart()),isStreaming:!i}].slice(-60);return Gc({...e,entries:o,nextEntryId:e.nextEntryId+1},t,n,i)}let o=e.entries.findIndex(e=>e.id===n),s=e.entries[o];if(!s)return Wc(e,t,null,r,i,a);let c=Xc(a===`snapshot`?r:a===`verbatim`?s.text+r:t===`assistant`?Jc(s.text,r,i):Yc(s.text,r,i)),l=s.text===c&&s.isStreaming===!i?e.entries:e.entries.map((e,t)=>t===o?{...e,text:c,isStreaming:!i}:e);return Gc({...e,entries:l},t,n,i)}function Gc(e,t,n,r){return t===`user`?{...e,userEntryId:r?null:n,userEntryAwaitingFinal:!1,userEntryAwaitingFinalStartedAtMs:null}:{...e,assistantEntryId:r?null:n}}function Kc(e,t,n=Date.now()){let r=t===`user`?e.userEntryId:e.assistantEntryId;if(r===null)return e;let i=e.entries.map(e=>e.id===r&&e.isStreaming?{...e,isStreaming:!1}:e);return t===`user`?{...e,entries:i,userEntryAwaitingFinal:!0,userEntryAwaitingFinalStartedAtMs:n}:{...e,entries:i,assistantEntryId:null}}function qc(e,t,n,r,i){let a=e.entries.find(e=>e.id===t);if(!a||a.isStreaming)return!1;let o=a.text;return!(o.trim()===``||n.trim()===``||n[0]&&/\s/.test(n[0])||n===o||n.startsWith(o)||o.endsWith(n)||r&&e.userEntryAwaitingFinal&&(e.userEntryAwaitingFinalStartedAtMs===null?1/0:i-e.userEntryAwaitingFinalStartedAtMs)<=ol&&Zc(o,n))}function Jc(e,t,n){return e.trim()===``?t.trimStart():n&&(t===e||t.startsWith(e)||Zc(e,t))?t:`${e}${t}`}function Yc(e,t,n){if(e.trim()===``)return t.trimStart();if(t===``||t===e||e.endsWith(t))return e;if(t.startsWith(e))return t;if(t[0]&&/\s/.test(t[0]))return`${e}${t}`;if(n&&Zc(e,t))return t;let r=tl(e,t),i=r>0?t.slice(r):t;return i===``?e:`${e}${r>0||!nl(e,i)?``:` `}${i}`}function Xc(e){if(e.length<=rl)return e;let t=e.indexOf(al),r=n(e,0,t>=255&&t<=il?t:il).replace(/[\uD800-\uDBFF]$/,``),i=rl-r.length-3,a=n(e,-i);return`${r}${al}${a}`}function Zc(e,t){let n=Qc(e),r=Qc(t);if(n.length===0||r.length===0||n[0]!==r[0])return!1;if(n.length>1&&r.length>1&&n[1]===r[1])return!0;let i=$c(e),a=$c(t),o=el(i,a),s=Math.min(i.length,a.length);return o>=6&&o/Math.max(1,s)>=.45}function Qc(e){return[...e.toLowerCase().matchAll(/[\p{L}\p{N}]+/gu)].map(e=>e[0])}function $c(e){return e.toLowerCase().replace(/\s+/g,` `).trim()}function el(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e[r]===t[r];)r+=1;return r}function tl(e,t){let n=e.toLowerCase(),r=t.toLowerCase(),i=Math.min(n.length,r.length);for(let e=i;e>=3;--e)if(n.endsWith(r.slice(0,e)))return e;return 0}function nl(e,t){let n=e.at(-1),r=t[0];return!n||!r||/\s/.test(n)||/\s/.test(r)?!1:/[\p{L}\p{N}.!?,:;)\]}"'’”]/u.test(n)&&/[\p{L}\p{N}]/u.test(r)}var rl,il,al,ol;function sl(){return(sl=e((()=>{rl=8e3,il=256,al=`
…
`,ol=1500})))()}function cl(e,t){let n=[],r=new Set;for(let i of e){let e=i.deviceId.trim();i.kind===t&&e&&e!=="default"&&!r.has(e)&&(r.add(e),n.push({deviceId:e,label:i.label.trim()||E(t===`audioinput`?`chat.composer.microphoneFallback`:`chat.composer.cameraFallback`,{number:String(n.length+1)})}))}return n}function ll(e,t){let n=e.filter(e=>e.kind===t);return n.length===0||n.some(e=>!e.deviceId||!e.label)}function ul(e){return e instanceof DOMException||e instanceof Error&&e.name===`OverconstrainedError`?e.name:void 0}function dl(e){return Cl[ul(e)??``]??`failed`}function fl(e,t){let[n,r]=Sl[e];return E(t===`audioinput`?n:r)}function pl(e){let t=globalThis.navigator?.mediaDevices;return t?.addEventListener?(t.addEventListener(`devicechange`,e),()=>t.removeEventListener(`devicechange`,e)):()=>void 0}function ml(e){return fl(dl(e),`audioinput`)}async function hl(e,t){let n=globalThis.navigator?.mediaDevices;if(!n?.enumerateDevices)return{devices:[],permissionRequired:!1,issue:`list-unsupported`};let r=e(),i;try{i=await n.enumerateDevices()}catch(n){return!r&&e()?hl(e,t):{devices:[],permissionRequired:!1,issue:dl(n)}}let a=ll(i,t);if(!a||!n.getUserMedia||!e())return{devices:cl(i,t),permissionRequired:a,issue:null};try{return(await n.getUserMedia(t===`audioinput`?{audio:!0}:{video:!0})).getTracks().forEach(e=>e.stop()),i=await n.enumerateDevices(),{devices:cl(i,t),permissionRequired:ll(i,t),issue:null}}catch(e){return{devices:cl(i,t),permissionRequired:a,issue:dl(e)}}}async function gl(e){return hl(e,`audioinput`)}async function _l(e){return hl(e,`videoinput`)}function vl(e){let t=e?.trim();return{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0,...t?{deviceId:{exact:t}}:{}}}function Z(e){return e.reason instanceof Error?e.reason:new DOMException(`Realtime Talk input cancelled`,`AbortError`)}async function yl(e,t){if(t?.aborted)throw Z(t);let n=e();if(!t)return await n;let r=()=>void 0,i=new Promise((e,n)=>{let i=()=>n(Z(t));t.addEventListener(`abort`,i,{once:!0}),r=()=>t.removeEventListener(`abort`,i)});try{return await Promise.race([n,i])}catch(e){throw t.aborted?(n.then(e=>e.getTracks().forEach(e=>e.stop()),()=>void 0),Z(t)):e}finally{r()}}async function bl(e,t={}){let n=globalThis.navigator?.mediaDevices;if(!n?.getUserMedia)throw Error(E(`chat.composer.realtimeTalkRequiresMicrophone`));let r;try{r={stream:await yl(()=>n.getUserMedia({audio:vl(e)}),t.signal)}}catch(t){let n=ul(t);if(!n||n===`AbortError`)throw t;if(e?.trim()&&n===`OverconstrainedError`)throw new wl;r={failure:ml(t)}}if(`failure`in r)throw Error(r.failure);let{stream:i}=r;if(t.signal?.aborted)throw i.getTracks().forEach(e=>e.stop()),Z(t.signal);return i}async function xl(e,t={}){let n=globalThis.navigator?.mediaDevices;if(!n?.getUserMedia)throw Error(E(`chat.composer.cameraAccessFailed`));let r=e?.trim(),i;try{let e=await yl(()=>n.getUserMedia({video:!r||{deviceId:{exact:r}}}),t.signal);if(t.signal?.aborted)throw e.getTracks().forEach(e=>e.stop()),Z(t.signal);i={stream:e}}catch(e){if(t.signal?.aborted)throw Z(t.signal);let n=ul(e);i={failure:r&&n===`OverconstrainedError`?E(`chat.composer.selectedCameraUnavailable`):fl(dl(e),`videoinput`)}}if(`failure`in i)throw Error(i.failure);return i.stream}var Sl,Cl,wl,Tl;function El(){return(El=e((()=>{k(),Sl={"list-unsupported":[`chat.composer.microphoneListUnsupported`,`chat.composer.cameraListUnsupported`],"none-found":[`chat.composer.microphoneNoneFound`,`chat.composer.cameraNoneFound`],"permission-blocked":[`chat.composer.microphonePermissionBlocked`,`chat.composer.cameraPermissionBlocked`],busy:[`chat.composer.microphoneBusy`,`chat.composer.cameraBusy`],"page-inactive":[`chat.composer.microphonePageInactive`,`chat.composer.cameraPageInactive`],failed:[`chat.composer.microphoneAccessFailed`,`chat.composer.cameraAccessFailed`]},Cl={NotAllowedError:`permission-blocked`,NotFoundError:`none-found`,NotReadableError:`busy`,InvalidStateError:`page-inactive`},wl=class extends Error{constructor(){super(E(`chat.composer.selectedMicrophoneUnavailable`)),this.name=`RealtimeTalkSelectedMicrophoneError`}},Tl=class{constructor(e,t){this.onEnded=e,this.onConnecting=t,this.controller=null,this.media=null}get stream(){return this.media}requireStream(){let e=this.media;if(!e)throw Error(E(`chat.composer.microphoneStopped`));return e}adopt(e){let t=this.requireStream();return this.onEnded=e,t}async open(e){this.stop();let t=new AbortController;this.controller=t;try{this.onConnecting?.(E(`chat.composer.microphoneAccessPending`));let n=await bl(e,{signal:t.signal});if(t.signal.aborted)throw n.getTracks().forEach(e=>e.stop()),Z(t.signal);this.media=n;let r=()=>{this.controller===t&&(this.stop(),this.onEnded(E(`chat.composer.microphoneStopped`)))};for(let e of n.getTracks())e.addEventListener(`ended`,r,{signal:t.signal});return this.onConnecting?.(),n}catch(e){throw this.controller===t&&this.stop(),e}}stop(){let e=this.controller,t=this.media;this.controller=null,this.media=null,e?.abort(),t?.getTracks().forEach(e=>e.stop())}}})))()}var Dl;function Ol(){return(Ol=e((()=>{Dl=class{constructor(){this.listeners=new Set,this.currentLevel=0}get value(){return this.currentLevel}set(e){let t=Math.round((Number.isFinite(e)?Math.min(1,Math.max(0,e)):0)*100)/100;if(t!==this.currentLevel){this.currentLevel=t;for(let e of this.listeners)e(t)}}subscribe(e){return this.listeners.add(e),e(this.currentLevel),()=>this.listeners.delete(e)}}})))()}function kl(e,t){let n=Vl.get(e);n||(n=new Map,Vl.set(e,n));let r=n.get(t)??0,i=[...n.values()].reduce((e,t)=>e+t,0);if(r>=Ll||i>=Rl)throw Error(`Too many active or closing realtime Talk voice sessions`);n.set(t,r+1);let a=n,o=new AbortController,s=new AbortController,c=!1,l,u,d=()=>{if(c)return;c=!0,l!==void 0&&(clearTimeout(l),l=void 0),u!==void 0&&(clearTimeout(u),u=void 0);let e=(a.get(t)??1)-1;e>0?a.set(t,e):a.delete(t)};return{signal:o.signal,closeSignal:s.signal,beginDrain:()=>{c||l!==void 0||u!==void 0||(l=setTimeout(()=>{o.abort()},zl),u=setTimeout(()=>{o.abort(),s.abort(),d()},Bl))},release:d}}function Al(e){if(e.nextTransport?.stop({emitClosed:!1}),e.transport===`gateway-relay`&&e.nextTransport){e.owner.release();return}e.closeVoiceSession()}function jl(){let e=Error(`voice transcript persistence aborted`);return e.name=`AbortError`,e}async function Ml(e,t){if(t.aborted)throw jl();e<=0||await new Promise((n,r)=>{let i=setTimeout(()=>{t.removeEventListener(`abort`,a),n()},e),a=()=>{clearTimeout(i),r(jl())};t.addEventListener(`abort`,a,{once:!0})})}async function Nl(e,t,n){let r;for(let n of[0,500,2e3]){if(n>0)await Ml(n,e);else if(e.aborted)throw jl();try{await t();return}catch(t){if(e.aborted)throw jl();r=t}}throw r instanceof Error?r:Error(n,{cause:r})}var Pl,Fl,Il,Ll,Rl,zl,Bl,Vl;function Hl(){return(Hl=e((()=>{l(),u(),Kn(),Pl=1024,Fl=1024,Il=class{constructor(e,t,n){this.queue=e,this.write=t,this.onFailure=n,this.sequence=0,this.nextWriteOrder=1,this.items=new Map,this.changed=v()}observe(e){if(e.type===`settled`)return this.settle(this.requireItem(e.itemId)),[];if(this.items.has(e.itemId))return[];if(this.items.size>=Pl||e.itemId.length>Fl||(e.previousItemId?.length??0)>Fl)throw Error(`Realtime transcript item identity limit exceeded`);let t={previousItemId:e.previousItemId===void 0?this.lastItemId:e.previousItemId,role:e.role,settled:e.role===null};return e.role!==null&&this.enqueue(()=>this.writeThrough(t),z.maxEntryChars,()=>void 0),this.items.set(e.itemId,t),this.assignOrders()}publish(e){if(e.itemId!==void 0){let t=this.requireItem(e.itemId);if(t.role!==e.role)throw Error(`Realtime transcript item changed roles`);return t.settled?void 0:(e.final&&this.settle(t,Rn(e.text)||void 0),{...e,order:t.order})}if(e.final){let t=Rn(e.text);if(t){let n=String(++this.sequence);this.enqueue(()=>this.write(n,e.role,t),t.length)}}return e}close(){let e=new Set;for(let[t,n]of this.items)n.order===void 0&&e.add(t),n.settled||(e.add(t),this.settle(n)),n.previousItemId&&!this.items.has(n.previousItemId)&&e.add(n.previousItemId);return this.assignOrders(!0),[...e]}assignOrders(e=!1){let t=[];for(;;){let n=[...this.items].filter(([,e])=>e.order===void 0),r=n.find(([,e])=>e.previousItemId==null?this.lastItemId===void 0:e.previousItemId===this.lastItemId)??(e?n.find(([,e])=>e.previousItemId==null||!this.items.has(e.previousItemId)||this.items.get(e.previousItemId)?.order!==void 0)??n[0]:void 0);if(!r)break;let[i,a]=r;a.order=a.role===null?this.sequence:++this.sequence,this.lastItemId=i,a.role!==null&&t.push({itemId:i,order:a.order})}return this.notify(),t}async writeThrough(e){let t;for(;!e.written;){let e=[...this.items.values()].find(e=>e.role!==null&&e.order===this.nextWriteOrder);if(!e?.settled){await this.changed.promise;continue}e.written=!0,this.nextWriteOrder+=1;let n=e.text;if(e.text=void 0,n&&e.role!==null)try{await this.write(String(e.order),e.role,n)}catch(e){t??={error:e},this.onFailure(e)}}if(t)throw t.error}settle(e,t){e.settled||(e.settled=!0,e.text=t,this.notify())}notify(){this.changed.resolve(),this.changed=v()}requireItem(e){let t=this.items.get(e);if(!t||t.role===null)throw Error(`Realtime transcript refers to an unknown speech item`);return t}enqueue(e,t,n=this.onFailure){let r=this.queue.enqueue(e,{weight:t});if(!r.accepted)throw Error(z.overflowMessage);r.completion.catch(n)}},Ll=2,Rl=16,zl=b,Bl=zl+b,Vl=new WeakMap})))()}function Ul(e){if(typeof e!=`string`)return;let t=qn(e);if(t===`webrtc`||t===`provider-websocket`||t===`gateway-relay`||t===`managed-room`)return t}function Wl(e){return qn(e.transport)??`webrtc`}function Gl(){return(Gl=e((()=>{Gn()})))()}async function Kl(e){let t=!1,n;if(await Promise.all([...Q].map(async r=>{try{await r.switchCameraIfEnabled(e)}catch(e){t=!0,n??=e}})),t)throw n}function ql(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}var Q,Jl;function Yl(){return(Yl=e((()=>{l(),Kn(),k(),Oe(),El(),Hl(),Gl(),t(),Q=new Set,Jl=class{constructor(e,t,n={},r={},i={}){this.client=e,this.sessionKey=t,this.callbacks=n,this.options=r,this.localOptions=i,this.transport=null,this.pendingStartup=null,this.closed=!1,this.closeCompletion=Promise.resolve(),this.lifecycleGeneration=0,this.videoEnabled=!1,this.videoOperation=0,this.transportGeneration=0,this.acceptingTranscripts=!1,this.transcriptQueue=z.createQueue()}async start(){let e=kl(this.client,this.sessionKey),t=!1,n;try{this.retireTransport();let r=this.lifecycleGeneration;this.closed=!1,this.callbacks.onStatus?.(`connecting`,E(`chat.voice.preparing`));let[{createRealtimeTalkTransport:i},a]=await Promise.all([y(()=>import(`./transport.runtime-DEnmKmQK.js`),__vite__mapDeps([8,2,3,6,4,5,9,7]),import.meta.url),this.resolveVideoCapability()]);if(this.closed||r!==this.lifecycleGeneration)return;n=new Tl(()=>void 0,e=>this.callbacks.onStatus?.(`connecting`,e)),this.pendingStartup=n;try{await n.open(this.localOptions.inputDeviceId)}catch(e){if(this.closed||r!==this.lifecycleGeneration)return;throw e}if(this.closed||r!==this.lifecycleGeneration)return;n.requireStream();let o=[`voice-transcript`,`voice-selection`];a&&o.push(`camera-frame`);let s=await this.createSession({...this.options,capabilities:o},r),c=Wl(s);if(c===`managed-room`)throw Error(`Managed-room realtime Talk sessions are not available in this UI yet`);let l=s.voiceSessionId??(c===`gateway-relay`?s.relaySessionId:void 0);if(!l)throw Error(`Realtime Talk session did not return a voice session id`);if(this.closed||r!==this.lifecycleGeneration){this.closeUnadoptedVoiceSession(l,c,e),t=!0;return}let u=r;c!==`gateway-relay`&&(this.voiceSessionId=l,this.transportGeneration=u,this.acceptingTranscripts=!0,this.clientVoiceSessionOwner=e,t=!0);let d=()=>{if(c===`gateway-relay`)this.closeUnadoptedVoiceSession(l,c,e);else if(this.clientVoiceSessionOwner===e){let e=this.detachVoiceSession();e&&this.closeLogicalVoiceSession(e)}},f=c===`gateway-relay`?this.callbacks:this.clientOwnedTranscriptCallbacks(l,u,e.signal),p=this.transcriptQueue,m=null,h;try{n.requireStream(),m=i(s,{client:this.client,sessionKey:this.sessionKey,voiceSessionId:l,flushTranscriptWrites:async()=>await p.flush(),callbacks:f,input:n,videoDeviceId:this.localOptions.videoDeviceId,consultThinkingLevel:s.consultThinkingLevel,consultFastMode:s.consultFastMode}),this.pendingStartup=m,this.callbacks.onVideoCapability?.(a&&typeof m.setVideoEnabled==`function`),h=this.pendingStartup===m?await m.start():`cancelled`}catch(n){throw this.pendingStartup===m&&(this.pendingStartup=null),Al({nextTransport:m,transport:c,owner:e,closeVoiceSession:d}),t=!0,n}if(this.pendingStartup===m&&(this.pendingStartup=null),h===`cancelled`||this.closed||r!==this.lifecycleGeneration){Al({nextTransport:m,transport:c,owner:e,closeVoiceSession:d}),t=!0;return}this.transport=m,this.selectedTransport=Ul(c),c===`gateway-relay`&&(this.voiceSessionId=l,this.transportGeneration=u,this.acceptingTranscripts=!0,e.release()),t=!0;try{m.activate?.()}catch(e){throw this.transport===m&&this.retireTransport(),e}}finally{n&&this.pendingStartup===n&&(this.pendingStartup=null,n.stop()),t||e.release()}}async resolveVideoCapability(){if(!this.callbacks.onVideoCapability)return!1;try{let e=this.options.provider?.trim(),t=this.options.model?.trim(),n=await this.client.request(`talk.catalog`,{...e?{provider:e}:{},...t?{model:t}:{}},{timeoutMs:b}),r=n.realtime.activeProvider;return r?n.realtime.providers.find(e=>e.id===r||e.aliases?.includes(r))?.supportsVideoFrames===!0:!1}catch{return!1}}async createSession(e,t){let n={...e};if(n.voiceChangeId&&n.transport===`gateway-relay`)return this.createRelaySession(n);try{return await this.client.request(`talk.client.create`,ql({sessionKey:this.sessionKey,...n}),{timeoutMs:b})}catch(e){if(n.voiceChangeId||this.closed||this.lifecycleGeneration!==t)throw e;let r=n.transport;if(!r){let t;try{t=await this.client.request(`talk.config`,{},{timeoutMs:b})}catch{throw e}if(!t.config||typeof t.config!=`object`)throw e;let n=t.config?.talk?.realtime?.transport;if(n!==void 0&&(r=Ul(n),!r))throw e}if(this.closed||this.lifecycleGeneration!==t||r&&r!==`gateway-relay`)throw e;try{return await this.createRelaySession(n)}catch{throw e}}}createRelaySession(e){return this.client.request(`talk.session.create`,ql({sessionKey:this.sessionKey,...e,mode:`realtime`,transport:`gateway-relay`,brain:`agent-consult`,capabilities:[`voice-selection`]}),{timeoutMs:b})}stop(){try{return this.retireTransport()}finally{this.callbacks.onStatus?.(`idle`)}}getVoiceSessionId(){return this.closed?void 0:this.voiceSessionId}getTransport(){return this.closed?void 0:this.selectedTransport}retireTransport(){this.lifecycleGeneration+=1,this.closed=!0,this.videoOperation+=1,this.videoEnabled=!1,Q.delete(this);let e=this.detachVoiceSession(),t=this.transport,n=this.pendingStartup!==null,r=[];this.transport=null,this.selectedTransport=void 0;try{r.push(Promise.resolve(this.stopPendingStartup()))}finally{try{r.push(Promise.resolve(t?.stop()))}finally{e&&r.push(this.closeLogicalVoiceSession(e))}}return(e||t||n)&&(this.closeCompletion=Promise.all(r).then(()=>void 0),this.closeCompletion.catch(()=>void 0)),this.closeCompletion}stopPendingStartup(){let e=this.pendingStartup;return this.pendingStartup=null,e?.stop({emitClosed:!1})}closeUnadoptedVoiceSession(e,t,n){if(t===`gateway-relay`){this.client.request(`talk.session.close`,{sessionId:e},{timeoutMs:b}).catch(()=>void 0).finally(n.release);return}let r=z.createQueue();r.seal(),this.closeLogicalVoiceSession({voiceSessionId:e,transcriptQueue:r,owner:n})}clientOwnedTranscriptCallbacks(e,t,n){let r=new Il(this.transcriptQueue,(t,r,i)=>this.writeTranscriptWithRetry({voiceSessionId:e,entryId:t,role:r,text:i,signal:n}),e=>{if(n.aborted)return;let r=`Voice transcript could not be saved: ${C(e)}`;console.warn(r,e),this.transportGeneration===t&&this.callbacks.onStatus?.(`error`,r)});this.transcriptItems=r;let i=()=>this.transportGeneration===t&&this.voiceSessionId===e&&this.acceptingTranscripts;return{...this.callbacks,onTalkEvent:e=>{if(i())try{e.type===`session.closed`&&this.retireTransport()}finally{this.callbacks.onTalkEvent?.(e)}},onTranscriptItem:e=>{if(!i())return;let n;try{n=r.observe(e)}catch(e){this.failTranscriptPersistence(t,C(e));return}n.length>0&&this.callbacks.onTranscriptOrder?.(n)},onTranscript:e=>{if(!i())return;let n;try{n=r.publish(e)}catch(e){this.failTranscriptPersistence(t,C(e));return}n&&this.callbacks.onTranscript?.(n)}}}failTranscriptPersistence(e,t=z.overflowMessage){this.transportGeneration===e&&this.acceptingTranscripts&&this.voiceSessionId&&(this.retireTransport(),this.transportGeneration+=1,console.warn(t),this.callbacks.onStatus?.(`error`,t))}async writeTranscriptWithRetry(e){await Nl(e.signal,()=>this.client.request(`talk.client.transcript`,{sessionKey:this.sessionKey,voiceSessionId:e.voiceSessionId,entryId:e.entryId,role:e.role,text:e.text,timestamp:Date.now()},{signal:e.signal,timeoutMs:b}),`voice transcript save failed`)}detachVoiceSession(){let e=this.voiceSessionId;if(!e)return;let t=this.clientVoiceSessionOwner?{voiceSessionId:e,generation:this.transportGeneration,transcriptQueue:this.transcriptQueue,owner:this.clientVoiceSessionOwner}:void 0,n=this.transcriptItems?.close()??[];if(this.transcriptItems=void 0,this.transcriptQueue.seal(),this.voiceSessionId=void 0,this.acceptingTranscripts=!1,this.transcriptQueue=z.createQueue(),this.clientVoiceSessionOwner=void 0,n.length>0){let e=`Voice call closed with ${n.length} unfinished transcript item(s); finalized speech was preserved.`;console.warn(e)}return t}closeLogicalVoiceSession(e){let t=e.owner;t.beginDrain();let n=e.transcriptQueue.flush().then(()=>Nl(t.closeSignal,()=>this.client.request(`talk.client.close`,{sessionKey:this.sessionKey,voiceSessionId:e.voiceSessionId},{signal:t.closeSignal,timeoutMs:b}),`Realtime Talk voice session close failed`)).finally(t.release);n.catch(n=>{t.closeSignal.aborted||(console.warn(`Realtime Talk voice session close failed`,n),this.transportGeneration===e.generation&&this.callbacks.onStatus?.(`error`,`Realtime Talk voice session close failed`))});let r=n.then(()=>e.transcriptQueue.flush({requireSuccess:!0}));return r.catch(()=>void 0),r}async setVideoEnabled(e){let t=this.transport;if(this.closed||!t?.setVideoEnabled)throw Error(`Camera is unavailable for this realtime session`);let n=++this.videoOperation,r=this.videoEnabled;this.videoEnabled=e,e?Q.add(this):Q.delete(this);try{await t.setVideoEnabled(e)}catch(e){throw n===this.videoOperation&&!this.closed&&this.transport===t&&(this.videoEnabled=r,r?Q.add(this):Q.delete(this)),e}n===this.videoOperation&&(this.closed||this.transport!==t)&&(this.videoEnabled=!1,Q.delete(this))}async switchCamera(e){let t=e?.trim()||void 0;if(this.localOptions.videoDeviceId=t,this.closed||!this.transport?.switchCamera)throw Error(`Camera switching is unavailable for this realtime session`);await this.transport.switchCamera(t)}async switchCameraIfEnabled(e){if(this.videoEnabled)try{await this.switchCamera(e)}catch(e){throw this.callbacks.onVideoError?.(e),e}}}})))()}var Xl,Zl;function Ql(){return(Ql=e((()=>{rt(),_t(),k(),Xl=yt+1e4,Zl=class{constructor(e){this.owner=e,this.active=!0,this.unsubscribe=e.client.addEventListener(e=>{e.event===`talk.voice.change`&&pt(e.payload)&&this.receive(e.payload)})}current(e=this.owner.currentCall()){return this.active&&this.owner.isCurrent()&&e!==null&&this.owner.currentCall()===e}ready(e){if(!this.current(e))return;let t=this.change;t&&e.getVoiceSessionId()!==t.request.voiceSessionId&&(t.ready=e,this.completeReady(t))}failed(e){this.current(e)&&this.change&&this.fail(this.change,E(`chat.voice.selectionFailed`))}receive(e){if(!this.active||!this.owner.isCurrent()||e.sessionKey!==this.owner.sessionKey)return;if(e.phase===`cancelled`){let t=this.change;t?.request.changeId===e.changeId&&t.request.voiceSessionId===e.voiceSessionId&&(this.clearChange(t),this.owner.cancel(E(`chat.voice.selectionFailed`)));return}let t=this.owner.currentCall();if(!this.current(t)||t.getVoiceSessionId()!==e.voiceSessionId||this.change)return;let n={request:e,completing:!1,timer:setTimeout(()=>this.fail(n,E(`chat.voice.selectionTimedOut`)),Xl)};this.change=n,this.owner.restart(e).then(e=>{if(this.change===n&&this.active&&this.owner.isCurrent()){if(!e||!this.current(e)){this.fail(n,E(`chat.voice.selectionFailed`));return}n.started=e,this.completeReady(n)}}).catch(()=>this.fail(n,E(`chat.voice.selectionFailed`)))}clearChange(e){clearTimeout(e.timer),this.change===e&&(this.change=void 0)}completeReady(e){let t=e.started,n=t?.getVoiceSessionId();this.change===e&&t&&e.ready===t&&this.current(t)&&n&&n!==e.request.voiceSessionId&&!e.completing&&(e.completing=!0,this.owner.client.request(`talk.voice.complete`,{changeId:e.request.changeId,voiceSessionId:n,outcome:`ready`},{timeoutMs:Xl}).then(()=>{this.change===e&&this.current(t)&&this.clearChange(e)}).catch(()=>this.fail(e,E(`chat.voice.selectionConfirmationFailed`))))}fail(e,t){this.change===e&&(this.clearChange(e),this.reportFailure(e,t),this.active&&this.owner.isCurrent()&&this.owner.cancel(t))}reportFailure(e,t){let n=this.owner.currentCall()?.getVoiceSessionId();this.owner.client.request(`talk.voice.complete`,{changeId:e.request.changeId,...n&&n!==e.request.voiceSessionId?{voiceSessionId:n}:{},outcome:`failed`,error:t},{timeoutMs:Xl}).catch(()=>void 0)}dispose(){this.active=!1,this.unsubscribe();let e=this.change;e&&(this.clearChange(e),this.reportFailure(e,E(`common.cancelled`)))}}})))()}function $l(e){return e.connected&&e.client&&!e.client.recoveryScopeReady?null:{...Te(e,e.sessionKey),gatewayOwner:Vt(e.settings?.gatewayUrl).gatewayOwner,recoveryScope:e.client?.recoveryScope?.trim()||void 0}}function eu(e){let t=e.chatQueuedEdit,n=$l(e);return!t||!n||t.gatewayOwner!==n.gatewayOwner||t.recoveryScope!==n.recoveryScope||x(t)!==x(n)?null:t}function tu(e,t){let n=Vt(e.settings?.gatewayUrl).gatewayOwner;return Mn(e,e=>e.chatQueuedEdit?.id===t&&e.chatQueuedEdit.gatewayOwner===n&&x(e.chatQueuedEdit)===x(Te(e,e.sessionKey)))}function nu(e,t){let n=$l(e),r=hn(e,t);return!n||!r||!Ot(r)||r.attachmentStorageError||r.attachments?.some(e=>!xn(e))||r.localCommandName||eu(e)||tu(e,t)?`unavailable`:(e.chatQueuedEdit={...n,attachments:r.attachments??[],draftText:r.text,mentions:r.mentions,id:t,orderKey:Gt(r),revision:0,...r.replyToId?{replyToId:r.replyToId}:{},source:{...r},sourceWasDurable:gn(e).durable(e,t)!==void 0},`started`)}function ru(e,t,n){let r=eu(e);return r?(r.mentions=n??Wt(r.draftText,t,r.mentions),r.draftText=t,r.revision+=1,!0):!1}function iu(e){return eu(e)?(e.chatQueuedEdit=null,!0):!1}function au(e,t,n=[],r){let i=r??eu(e);if(!(r&&e.chatQueuedEdit!==i)&&i){if(!t){let t=hn(e,i.id);if(i.sourceWasDurable||gn(e).durable(e,i.id)!==void 0||!t||!Qt(t,i.source))return}e.chatQueuedEdit=null,gn(e).remove(e,i.id),En(i.attachments,[n])}}var ou,su,cu,lu,uu;function du(){return(du=e((()=>{xt(),Dt(),Lt(),D(),vn(),Sn(),Fn(),Yn(),ou=`A queued message is being edited in another pane. Finish or cancel that edit before editing it here.`,su=`A queued message is being edited in another pane. Finish or cancel that edit before removing it.`,cu=`A queued message is being edited in another pane. Finish or cancel that edit before reordering it.`,lu=`A queued message is being edited in another pane. Finish or cancel that edit before retrying it.`,uu=`A queued message is being edited in another pane. Finish or cancel that edit before steering it.`})))()}function fu(e){if(Xt(e))return null;let t=s(e),n=Vn(e),r=typeof t?.stopReason==`string`?t.stopReason.trim().toLowerCase():``,i=s(t?.__openclaw);if(n===`commentary`||(!r||r===`tooluse`)&&i?.runTerminal!==!0)return null;let a=I(e);if(typeof a==`string`&&Yt(a))return null;let o=(jn(e)?.content??[]).filter(e=>e.type===`text`?typeof e.text==`string`&&e.text.trim().length>0:!Le(e.type)&&!Fe(e.type));if(o.length===0)return null;try{return JSON.stringify(o)??null}catch{return null}}function pu(e,t){let n=$n(e),r=Zn(e,n),i=r.runs[t],a=i?.message===void 0?[]:[i.message];for(let e of r.messages)N(e)?.role===`assistant`&&pn(e)===t&&a.push(e);let o=new Set;for(let e of a){let t=fu(e);t&&o.add(t)}return{acceptedFinal:(i?.acceptedFinalMessageIdentities?.length??0)>0,terminalReplySignatures:o}}function mu(){return(mu=e((()=>{P(),Ie(),Hn(),Jt(),Kt(),An(),Pn(),er()})))()}function hu(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n}function gu(e){let t=new Uint8Array(e.length*2),n=new DataView(t.buffer);for(let t=0;t<e.length;t+=1){let r=Math.max(-1,Math.min(1,e[t]??0));n.setInt16(t*2,r<0?r*32768:r*32767,!0)}return t}function _u(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=1){let r=Math.max(-1,Math.min(1,e[n]??0)),i=Math.round(r<0?r*32768:r*32767),a=0,o=i;o<0&&(a=128,o=-o),o=Math.min(o,32635)+132;let s=7,c=16384;for(;(o&c)===0&&s>0;)--s,c>>=1;let l=o>>s+3&15;t[n]=~(a|s<<4|l)&255}return t}function vu(e){let t=0,n=0;for(let r of e){let e=Number.isFinite(r)?r:0;t=Math.max(t,Math.abs(e)),n+=e*e}return{peak:t,rms:e.length>0?Math.sqrt(n/e.length):0}}function yu(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=new Float32Array(Math.floor(e.byteLength/2));for(let e=0;e<n.length;e+=1)n[e]=t.getInt16(e*2,!0)/32768;return n}function bu(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`);return Math.max(0,Math.floor(e.length*3/4)-t)}var xu,Su,Cu,wu,Tu,Eu;function Du(){return(Du=e((()=>{xu=class{constructor(){this.source=null,this.processor=null,this.sink=null}start(e,t,n){this.stop(),this.source=t.createMediaStreamSource(e),this.processor=t.createScriptProcessor(4096,1,1),this.sink=t.createGain(),this.sink.gain.value=0,this.processor.onaudioprocess=e=>n(e.inputBuffer.getChannelData(0)),this.source.connect(this.processor),this.processor.connect(this.sink),this.sink.connect(t.destination)}stop(){this.processor&&=(this.processor.onaudioprocess=null,this.processor.disconnect(),null),this.sink?.disconnect(),this.sink=null,this.source?.disconnect(),this.source=null}},Su=class{constructor(){this.level=0,this.noiseFloor=.01}sample(e){let t=vu(e),n=.65*t.rms+.35*t.peak;n<=Math.max(.02,this.noiseFloor*2)&&(this.noiseFloor=.95*this.noiseFloor+.05*n);let r=Math.max(0,n-this.noiseFloor*1.5),i=Math.min(1,Math.sqrt(r/.18)),a=i>this.level?.65:.18;return this.level=a*i+(1-a)*this.level,this.level<.01&&(this.level=0),this.level}reset(){this.level=0,this.noiseFloor=.01}},Cu=class{constructor(e){this.onLevel=e,this.context=null,this.source=null,this.analyser=null,this.timer=null,this.ownsContext=!1,this.levelMeter=new Su,this.samples=new Float32Array(512),this.lastLevel=-1}start(e,t){this.stop(!1);try{let n=t??new AudioContext;this.context=n,this.ownsContext=!t;let r=n.createMediaStreamSource(e);this.source=r;let i=n.createAnalyser();this.analyser=i,i.fftSize=this.samples.length,i.smoothingTimeConstant=0,r.connect(i),this.timer=globalThis.setInterval(()=>this.publishCurrentLevel(),100),this.publishCurrentLevel()}catch{this.stop()}}stop(e=!0){this.timer!==null&&(globalThis.clearInterval(this.timer),this.timer=null),this.source?.disconnect(),this.source=null,this.analyser?.disconnect(),this.analyser=null,this.ownsContext&&this.context?.close(),this.context=null,this.ownsContext=!1,this.levelMeter.reset(),this.lastLevel=-1,e&&this.onLevel(0)}publishCurrentLevel(){if(!this.analyser)return;this.samples.fill(0),this.analyser.getFloatTimeDomainData(this.samples);let e=Math.round(this.levelMeter.sample(this.samples)*100)/100;e!==this.lastLevel&&(this.lastLevel=e,this.onLevel(e))}},wu=60,Tu=4096,Eu=class{constructor(){this.playhead=0,this.sources=new Set}get queuedUntil(){return this.playhead}get isPlaying(){return this.sources.size>0}play(e,t,n){if(!t)return`ignored`;let r=Math.max(t.currentTime,this.playhead),i=Math.max(0,r-t.currentTime),a=wu-i,o=bu(e),s=Math.floor(o/2);if(this.sources.size>=Tu||a<=0||s/n>a)return`overflow`;let c;try{c=yu(hu(e))}catch{return`ignored`}if(c.length===0)return`ignored`;let l=r+c.length/n;if(l-t.currentTime>wu)return`overflow`;let u=t.createBuffer(1,c.length,n);u.getChannelData(0).set(c);let d=t.createBufferSource();return this.sources.add(d),d.addEventListener(`ended`,()=>this.sources.delete(d)),d.buffer=u,d.connect(t.destination),d.start(r),this.playhead=l,`queued`}stop(e){let t=[...this.sources];this.sources.clear(),this.playhead=e?.currentTime??0;for(let e of t)try{e.stop()}catch{}}}})))()}function Ou(e,t){try{let n=e.getItem(t);if(!n)return!1;let r=JSON.parse(n);return i(r)&&r.open===!0}catch{return!1}}function ku(e){try{e.setItem(Nu,`1`)}catch{}}function Au(e){try{return e.getItem(Nu)===`1`}catch{return!1}}function ju(){try{return globalThis.localStorage??null}catch{return null}}function Mu(e){let t=e.sessionKey.trim(),n=e.storage===void 0?ju():e.storage;if(!t||!n||Au(n))return e.settings;if(e.settings.sidebarSessionLayouts?.[t]!==void 0)return ku(n),e.settings;let r=new Set([...e.browserAvailable?[`browser`]:[],...e.desktopAvailable?[`desktop`]:[]]),i={columns:[]};for(let e of Pu)r.has(e.slot)&&Ou(n,e.storageKey)&&(i=No(i,e.slot));let a=i.columns.length>0?We({sidebarSessionLayouts:Ee(e.settings.sidebarSessionLayouts,t,i)}):e.settings;return ku(n),a}var Nu,Pu;function Fu(){return(Fu=e((()=>{m(),Xe(),he(),Go(),Nu=`openclaw.chat.sidePanel.legacyDockVisibility.v1`,Pu=[{storageKey:`openclaw.browser.panel.v1`,slot:`browser`},{storageKey:`openclaw.desktopPanel`,slot:`desktop`}]})))()}function Iu(e){return e.split(/[\\/]/).findLast(e=>e.length>0)??e}function Lu(e){let t=e.replace(/[\\/]+$/u,``),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));if(!(n<0))return Iu(n===0?t.slice(0,1):t.slice(0,n))||void 0}function Ru(e){return e.startsWith(`/`)||e.startsWith(`\\`)||/^[A-Za-z]:[\\/]/.test(e)}function zu(e){if(!Ru(e))return null;let t=e.trim().replaceAll(`\\`,`/`),n=/^[A-Za-z]:\//u.test(t)||t.startsWith(`//`),r=[],i=/^[A-Za-z]:\//u.test(t)?1:t.startsWith(`//`)?2:0;for(let e of t.split(`/`))if(e&&e!==`.`){if(e===`..`){r.length>i&&r.pop();continue}r.push(e)}let a=`${t.startsWith(`//`)?`//`:t.startsWith(`/`)?`/`:``}${r.join(`/`)}`.replace(/\/+$/u,``)||`/`;return n?a.toLowerCase():a}function Bu(e,t){let n=zu(e);return n!==null&&n===zu(t)}function Vu(e,t){let n=zu(e),r=zu(t);return!n||!r?!1:r===n||r.startsWith(n===`/`?n:`${n}/`)}function Hu(e,t){return e.some(e=>Vu(e,t))}function Uu(){return(Uu=e((()=>{})))()}function Wu(){return(Wu=e((()=>{})))()}function Gu(e,t,n={}){let{iconUrl:r,onIconError:i,authorIconUrl:a,loading:o=!1,className:s=`plugins-tile`,whiteBackground:c=!1}=n,l=(n,r,a)=>{let l=n?a.loading:o;if(n||l)return A`<span
class=${`${s}${c?` plugins-tile--white`:``}${l?` skeleton`:``}`}
data-plugin-icon-id=${e}
aria-hidden="true"
>
${n?A`<img
class="plugins-icon"
src=${n}
alt=""
loading="eager"
decoding="async"
?hidden=${l}
@load=${a.onLoad}
@error=${()=>{r(),i?.()}}
/>`:j}
</span>`;let[u,d]=vi(e),f=yi(t);return A`<span
class=${`${s} ${s}--fallback`}
data-plugin-icon-id=${e}
style=${`--plugins-art-a:${u};--plugins-art-b:${d}`}
aria-hidden="true"
>
${f?A`<span>${f}</span>`:Ke.plug}
</span>`};return A`${un(r,(e,t,n)=>e?l(e,t,n):A`${un(a,l)}`)}`}function $(e,t,n=!1){return on({title:e,control:A`<span class=${n?`plugins-consent__row--warning`:``}>${t}</span>`,stackedOnNarrow:!0,carapace:!0})}function Ku(e){return A`<span class="plugins-consent__items">${e.join(`, `)}</span>`}function qu(e,t=!1){return gt.flatMap(n=>{let r=e[n];return r?.length&&(t||n!==`dangerousConfigFlags`)?[$(E(id[n]),Ku(r),t)]:[]})}function Ju(e){let t=qu(e);return rn({title:E(`pluginConsent.declaredTitle`),description:E(`pluginConsent.declaredDescription`),carapace:!0},A`${t.length?t:on({title:E(`pluginConsent.declaredEmpty`),carapace:!0})}
${e.hooks.length===0?$(E(`pluginConsent.hooks`),E(`pluginConsent.runtimeHooks`)):j}
${e.dangerousConfigFlags.length>0?$(E(`pluginConsent.dangerousFlags`),Ku(e.dangerousConfigFlags),!0):j}`)}function Yu(e){if(!e.widened)return j;let t=qu(e.widened,!0);return t.length===0?j:A`
<section class="plugins-consent__section oc-section">
<h3>${E(`pluginConsent.widenedTitle`)}</h3>
<p class="plugins-consent__description">
${E(`pluginConsent.widenedDescription`)}
${e.acceptedAt?E(`pluginConsent.previouslyAccepted`,{date:e.acceptedAt}):j}
</p>
<div class="plugins-consent__rows">${t}</div>
</section>
`}function Xu(e,t,n){return`${E(e.effective?t:n)} ${E(e.configured===void 0?`pluginConsent.grantDefault`:`pluginConsent.grantConfigured`)}`}function Zu(e,t){return t===void 0?void 0:E(e,{value:E(t?`pluginConsent.allowed`:`pluginConsent.blocked`)})}function Qu(e){return[Zu(`pluginConsent.modelOverride`,e.allowModelOverride),e.allowedModels?.length?E(`pluginConsent.allowedModels`,{models:e.allowedModels.join(`, `)}):void 0,`allowedCompletionModels`in e&&e.allowedCompletionModels?.length?E(`pluginConsent.allowedCompletionModels`,{models:e.allowedCompletionModels.join(`, `)}):void 0,`allowAuthProfileOverride`in e?Zu(`pluginConsent.authProfileOverride`,e.allowAuthProfileOverride):void 0,`allowAgentIdOverride`in e?Zu(`pluginConsent.agentIdOverride`,e.allowAgentIdOverride):void 0].filter(Boolean).join(` · `)||E(`pluginConsent.noOverrides`)}function $u(e,t){let n=e.hooks.allowConversationAccess;return rn({title:E(`pluginConsent.grantsTitle`),description:E(`pluginConsent.grantsDescription`),carapace:!0},A`
${$(E(`pluginConsent.promptInjection`),Xu(e.hooks.allowPromptInjection,`pluginConsent.allowed`,`pluginConsent.blocked`))}
${$(E(`pluginConsent.conversationAccess`),A`
${Xu(n,`pluginConsent.on`,`pluginConsent.off`)}
${!n.effective&&n.configured===void 0&&t!==`bundled`?A`<span class="plugins-consent__hint">
${E(`pluginConsent.externalAccessHint`)}
</span>`:j}
`)}
${e.llm?$(E(`pluginConsent.modelOverrides`),Qu(e.llm)):j}
${e.subagent?$(E(`pluginConsent.subagentModelOverrides`),Qu(e.subagent)):j}
`)}function ed(e,t){if(t)return E(`pluginsPage.official`);let n=e&&Object.hasOwn(od,e)?od[e]:void 0;return n?E(n):e??(t===!1?E(`pluginConsent.community`):null)}function td(e){if(!e)return j;let t=e.integrityKind===`sha256`?E(`pluginConsent.sha256`):e.integrityKind===`git-commit`?E(`pluginConsent.commit`):E(`pluginConsent.integrity`);return A`
<div class="plugins-consent__provenance">
<span
>${[E(ad[e.kind]),e.spec??e.packageName].filter(Boolean).join(` · `)}</span
>
${e.integrity?A`<span title=${e.integrity}>
${t}: <code>${e.integrity.slice(0,20)}…</code>
</span>`:j}
</div>
${e.integrity?A`<p class="plugins-consent__hint">${E(`pluginConsent.pinnedArtifact`)}</p>`:j}
`}function nd(e){if(!e)return j;let t=E(e.disposition===`clean`?`pluginConsent.verifiedClean`:e.disposition===`review-recommended`?`pluginConsent.reviewRecommended`:e.disposition===`review-required`?`pluginConsent.reviewRequired`:`pluginConsent.trustBlocked`),n=e.disposition===`clean`?`ok`:e.disposition===`blocked`?`danger`:`warn`;return A`
<section class="plugins-consent__trust">
${an({kind:n,label:t,carapace:!0})}
${e.reasons?.length?A`<ul>
${e.reasons.map(e=>A`<li>${e}</li>`)}
</ul>`:j}
${e.checkedAt?A`<p class="plugins-consent__hint">
${E(`pluginConsent.scanDate`,{date:e.checkedAt})}
</p>`:j}
</section>
`}function rd(e){let{consent:t,inspection:n}=e,r=t.details,i=n?.plugin,a=t.fallback,o=n?.source?.packageName,s=t.pluginId??o??a?.name??`plugin`,c=i?.name??a?.name??s,l=i?.version??a?.version,u=[ed(i?.origin,a?.official),o].filter(Boolean).join(` · `),d=e.busy?E(`pluginsPage.working`):E(`pluginConsent.enableNamed`,{name:c}),f=!e.canMutate||e.busy||e.loading||!!e.error||!n,p=A`
<button
type="button"
class="btn primary oc-action oc-action-primary"
?disabled=${f&&!e.mutationBlockedReason}
aria-disabled=${e.canMutate?j:`true`}
@click=${()=>{f||e.onConfirm()}}
>
${d}
</button>
`;return A`
<openclaw-modal-dialog
label=${c}
style="--openclaw-modal-width: min(560px, calc(100vw - 32px));"
@modal-cancel=${e.onCancel}
>
<section class="plugins-consent oc-card" data-plugin-consent=${t.intent.kind}>
<header class="plugins-consent__header">
${Gu(s,c,{iconUrl:e.iconUrl,loading:e.iconLoading})}
<div>
<div class="plugins-detail__title">
<h2>${c}</h2>
${l?A`<span class="plugins-version">${`v${l}`}</span>`:j}
</div>
${u?A`<p class="plugins-consent__description">${u}</p>`:j}
</div>
</header>
${e.loading?A`<p class="plugins-consent__hint" role="status">${E(`pluginConsent.loading`)}</p>`:e.error?A`<div class="plugins-consent__error" role="alert">
<span>${e.error}</span>
<button
type="button"
class="btn btn--sm oc-action oc-action-secondary"
@click=${e.onRetry}
>
${E(`pluginsPage.tryAgain`)}
</button>
</div>`:n?A`
${td(n.source)} ${nd(n.trust)}
${r?Yu(r):j}
${Ju(n.declared)}
${$u(n.grants,i?.origin)}
`:A`<p class="plugins-consent__description">${E(`pluginConsent.fallback`)}</p>`}
<footer class="plugins-consent__actions">
<button type="button" class="btn oc-action oc-action-secondary" @click=${e.onCancel}>
${E(`pluginsPage.cancel`)}
</button>
${dn(e.mutationBlockedReason,p)}
</footer>
</section>
</openclaw-modal-dialog>
`}var id,ad,od;function sd(){return(sd=e((()=>{Ze(),vt(),Je(),ln(),He(),cn(),sn(),k(),It(),Rt(),xi(),Bt(),zt(),id={channels:`pluginsPage.categoryChannels`,providers:`pluginsPage.categoryProviders`,tools:`pluginsPage.categoryTools`,contracts:`pluginConsent.contracts`,hooks:`pluginConsent.hooks`,mcpServers:`pluginConsent.mcpServers`,cliCommands:`pluginConsent.cliCommands`,cliBackends:`pluginConsent.cliBackends`,skills:`pluginConsent.skills`,dangerousConfigFlags:`pluginConsent.dangerousFlags`},ad={bundled:`pluginsPage.included`,"official-catalog":`pluginsPage.official`,clawhub:`pluginConsent.sourceClawHub`,npm:`pluginConsent.sourceNpm`,git:`pluginConsent.sourceGit`,path:`pluginConsent.sourcePath`,archive:`pluginConsent.sourceArchive`,marketplace:`pluginConsent.sourceMarketplace`},od={bundled:`pluginsPage.included`,global:`pluginsPage.global`,workspace:`pluginsPage.workspace`,config:`pluginsPage.config`,official:`pluginsPage.official`}})))()}function cd(){return(cd=e((()=>{})))()}function ld(){return(ld=e((()=>{})))()}function ud(){return(ud=e((()=>{})))()}function dd(e,t){let n=()=>{if(t.aborted||e.signal.aborted)throw Error(`This plugin UI view has ended.`)},r=n=>(...r)=>{!t.aborted&&!e.signal.aborted&&n(...r)},i=new Set,a=r=>{(t.aborted||e.signal.aborted)&&(r(),n());let a=()=>{i.delete(a)&&r()};return i.add(a),a},o=e=>e instanceof Promise?e.then(e=>(n(),e)):e;t.addEventListener(`abort`,()=>{for(let e of i)try{e()}catch(e){console.error(`[openclaw] plugin UI cleanup failed`,e)}i.clear()},{once:!0});let s=(e,t={},i)=>new Proxy(e,{get(e,c,l){if(c===`dispose`&&i)return i;n();let u=Reflect.get(e,c,l);return typeof u==`function`?(...i)=>{n();let l=t[c];if(l!==void 0){let e=i[l];typeof e==`function`&&(i[l]=r((...t)=>Reflect.apply(e,void 0,t)))}let d=Reflect.apply(u,e,i);if(typeof d==`function`)return a(()=>d());if(d&&typeof d==`object`&&`dispose`in d&&typeof d.dispose==`function`){let e=d.dispose,t=a(()=>e.call(d));return s(d,{},t)}return o(d)}:u}});return{...e,signal:t,get connection(){return n(),e.connection},get locale(){return n(),e.locale},request:async(t,r)=>{n();let i=await e.request(t,r);return n(),i},onEvent:(t,i)=>(n(),a(e.onEvent(t,r(i)))),subscribe:t=>(n(),a(e.subscribe(r(t)))),sessions:s(e.sessions,{observe:1}),agents:s(e.agents),navigation:s(e.navigation),ui:s(e.ui),components:s(e.components)}}function fd(){return(fd=e((()=>{})))()}function pd(e,t){return e.registrations(`actions`).filter(e=>e.value.placement===`session`).flatMap(n=>{try{let e=n.value.resolve?.({sessionKey:t.key,agentId:t.agentId,session:structuredClone(t)});return e?.hidden?[]:[{id:n.key,label:e?.label??n.value.label,disabled:e?.disabled}]}catch(t){return e.reportError(n.pluginId,t),[]}})}async function md(e){let t=e.placement===`session`?`Reopen the session menu.`:`Try again from the current view.`;if(e.placement===`session`&&!e.session)throw Error(`This session is no longer available. ${t}`);let n=e.runtime.registrations(`actions`).find(t=>t.key===e.id&&t.value.placement===e.placement);if(!n)throw Error(`This plugin action is no longer active. ${t}`);let r=AbortSignal.any([e.signal,n.signal]);r.throwIfAborted();let i={sessionKey:e.sessionKey,agentId:e.agentId??e.session?.agentId,session:e.session?structuredClone(e.session):void 0},a=n.value.resolve?.(i);if(r.throwIfAborted(),a?.hidden||a?.disabled)throw Error(`This plugin action is currently unavailable. ${t}`);await n.value.run({...i,host:dd(n.host,r),signal:r}),r.throwIfAborted()}function hd(){return(hd=e((()=>{})))()}function gd(){window.dispatchEvent(new CustomEvent(Ue))}function _d(){return(_d=e((()=>{Ve()})))()}export{Ol as $,Fa as $n,Hr as $r,ds as $t,vu as A,cr as Ai,To as An,Ti as Ar,Tc as At,iu as B,Ya as Bn,vi as Br,uc as Bt,Cu as C,hr as Ci,Do as Cn,Qi as Cr,kc as Ct,_u as D,gr as Di,lo as Dn,Hi as Dr,Oc as Dt,bu as E,_r as Ei,eo as En,Yi as Er,Y as Et,cu as F,So as Fn,Li as Fr,hc as Ft,Zl as G,Oa as Gn,mi as Gr,vs as Gt,tu as H,Wa as Hn,_i as Hr,Bs as Ht,lu as I,_o as In,Ai as Ir,vc as It,Yl as J,La as Jn,di as Jr,Ts as Jt,Ql as K,Ea as Kn,pi as Kr,Es as Kt,uu as L,co as Ln,zi as Lr,fc as Lt,pu as M,io as Mn,Ei as Mr,Sc as Mt,ou as N,xo as Nn,Di as Nr,xc as Nt,gu as O,ur as Oi,ro as On,Wi as Or,yc as Ot,su as P,bo as Pn,wi as Pr,mc as Pt,Dl as Q,Da as Qn,Ur as Qr,Qo as Qt,eu as R,to as Rn,Si as Rr,pc as Rt,Mu as S,yr as Si,Lo as Sn,$i as Sr,Ac as St,Eu as T,pr as Ti,Co as Tn,Ki as Tr,bc as Tt,au as U,ka as Un,gi as Ur,ks as Ut,du as V,Ga as Vn,yi as Vr,js as Vt,ru as W,Aa as Wn,hi as Wr,Os as Wt,Gl as X,Ra as Xn,li as Xr,as as Xt,Kl as Y,Ua as Yn,ui as Yr,ys as Yt,Wl as Z,Ba as Zn,ii as Zr,ns as Zt,Ru as _,Mr as _i,Mo as _n,na as _r,Lc as _t,md as a,Rr as ai,ss as an,ba as ar,El as at,Bu as b,Cr as bi,Bo as bn,ta as br,Mc as bt,ud as c,zr as ci,Xo as cn,_a as cr,fl as ct,sd as d,Lr as di,Fo as dn,da as dr,sl as dt,Kr as ei,us as en,Pa as er,Tl as et,Gu as f,V as fi,Po as fn,ua as fr,Uc as ft,Uu as g,Dr as gi,No as gn,oa as gr,Fc as gt,Iu as h,wr as hi,Oo as hn,ga as hr,Ic as ht,pd as i,Br as ii,fs as in,xa as ir,gl as it,mu as j,lr as ji,$a as jn,Bi as jr,Ec as jt,Du as k,sr as ki,no as kn,Gi as kr,X as kt,ld as l,Ir as li,Ko as ln,fa as lr,Bc as lt,Wu as m,Nr as mi,Go as mn,la as mr,Rc as mt,gd as n,ci as ni,hs as nn,Ca as nr,ml as nt,fd as o,Wr as oi,Zo as on,va as or,pl as ot,rd as p,Fr as pi,jo as pn,ma as pr,Vc as pt,Jl as q,Ia as qn,fi as qr,ws as qt,hd as r,Jr as ri,es as rn,Sa as rr,_l as rt,dd as s,qr as si,Yo as sn,ya as sr,xl as st,_d as t,Gr as ti,gs as tn,wa as tr,wl as tt,cd as u,B as ui,Wo as un,pa as ur,zc as ut,Hu as v,Ar as vi,Io as vn,ra as vr,Pc as vt,xu as w,dr as wi,zo as wn,qi as wr,Cc as wt,Fu as x,fr as xi,Ro as xn,ea as xr,Nc as xt,Lu as y,vr as yi,Vo as yn,ia as yr,jc as yt,nu as z,Za as zn,xi as zr,ac as zt};