UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines (3 loc) • 14.3 kB
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Ko as n,Qo as r,Ss as i,is as a,li as o,oi as s,v as c,xs as l,y as u}from"./_4____________________________.js";import{$O as d,AN as f,EN as p,Hf as m,JE as h,JO as ee,Lf as te,Pk as g,Rf as ne,Uf as re,Xh as ie,YE as ae,YO as _,Yh as oe,ZO as se,ak as v,bl as ce,fk as le,jk as ue,mk as y,ok as de,yl as b}from"./_2_____________________________.js";import{Bi as fe,Hi as x,Vi as pe}from"./deferred-ui-support-DZEPWjAk.js";import{n as S,t as C}from"./_0___________________.js";import{Xt as me,Zt as he}from"./control-ui-boot-chat-CqvkfPXD.js";import{n as ge,t as _e}from"./session-management-english-BXruTz7H.js";import{r as ve,s as ye,t as be}from"./custom-snooze-_bGjRBTT.js";import{a as xe,i as w,n as T,o as E,r as D,t as O}from"./session-workspace-recovery.runtime-CrnLuShq.js";import{r as k}from"./session-mutation-runtime-DOqRCEjO.js";function A(e){let t=e.closest(`.sidebar-session-tree`)??e,n=t.parentElement,r=e.ownerDocument.defaultView;if(!n||!r||typeof t.animate!=`function`||r.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return()=>void 0;let i=t.getBoundingClientRect().height;j(n);let a=!1,o=new MutationObserver(e=>{let r=e.find(e=>[...e.removedNodes].includes(t));r&&(a=!0,o.disconnect(),Se(t,i,n,r.nextSibling))});return o.observe(n,{childList:!0}),()=>r.requestAnimationFrame(()=>{o.disconnect(),a||M(n)})}function j(e){I.set(e,(I.get(e)??0)+1),e.dataset.sidebarArchiveExiting=``}function M(e){let t=(I.get(e)??1)-1;I.set(e,t),t===0&&delete e.dataset.sidebarArchiveExiting}function Se(e,t,n,r){let i=e.cloneNode(!0);for(let e of[i,...i.getElementsByTagName(`*`)])for(let t of F)e.removeAttribute(t);i.dataset.sidebarArchiveExit=``,i.inert=!0,i.setAttribute(`aria-hidden`,`true`),i.style.overflow=`hidden`,n.insertBefore(i,r?.parentNode===n?r:null);let a={opacity:0,translate:`-10px 0`,scale:`0.98`,filter:`blur(1.5px)`},o={opacity:1,translate:`0 0`,scale:`1`,filter:`blur(0)`},s=n.classList.contains(`sidebar-session-window`)?[o,a]:[{...o,height:`${t}px`},{...a,height:`${t}px`,offset:.5},{...a,height:`0px`,marginBottom:`${-Number.parseFloat(getComputedStyle(n).rowGap)||0}px`}],c=()=>{i.remove(),M(n)};i.animate(s,{duration:N,easing:P,fill:`forwards`}).finished.then(c,c)}var N,P,F,I;function L(){return(L=e((()=>{N=240,P=`cubic-bezier(0.2, 0, 0, 1)`,F=[`id`,`data-session-key`,`data-session-tree`,`data-session-window-key`],I=new WeakMap})))()}function R(e,t,n){let r=_(t.gateway.snapshot,n);return r.allowed?!0:(e.sessionData.publishSessionMutationError(t,r.reason),!1)}async function Ce(e,t,n){let r=[...new Set(n.map(e=>i(e,t.selectedAgentId)))],a=e.sidebarSessionStatusFilter()!==`active`;for(let n of r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;try{let r=await t.sessions.reconcileMutation(n);if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;if(r.status!==`refreshed`)return r.status===`failed`&&e.sessionData.publishSessionMutationError(t,r.error),r.status;a&&await e.sessionData.refreshSidebarSessions(n)}catch(n){return e.sessionData.isSessionMutationScopeCurrent(t)?(e.sessionData.publishSessionMutationError(t,n),`failed`):`stale`}}return e.sessionData.isSessionMutationScopeCurrent(t)?`completed`:`stale`}async function z(e,t,n,r,a={}){if(typeof n.archived==`boolean`&&t.some(e=>!e.sessionId?.trim()))return e.sessionData.publishSessionMutationError(r,o(`sessionsView.lifecycleIdentityRequired`)),null;let s=r.gateway.snapshot;if(typeof n.archived==`boolean`&&Object.keys(n).length===1&&!t.some(e=>e.archiveGuard)&&(s.phase!==`connected`||s.deferredIntentCount||s.deferredIntentDraining)){let o=[];for(let s of t){if(!e.sessionData.isSessionMutationScopeCurrent(r))return null;let t={key:s.key,agentId:i(s,r.selectedAgentId),expectedSessionId:s.sessionId,...n};if(!R(e,r,{method:`sessions.patch`,params:t,session:s,sessionScope:a.sessionScope,allowDeferred:!0}))return null;await r.sessions.patch(s.key,n,{agentId:t.agentId,expectedSessionId:s.sessionId,onConfirmed:()=>{n.archived&&e.pruneSidebarSessionEntry(s.key)}})&&o.push(s)}return o}let l=[],u=null;for(let o=0;o<t.length;o+=100){if(!e.sessionData.isSessionMutationScopeCurrent(r))return null;let s=t.slice(o,o+100),c={targets:s.map(e=>({key:e.key,agentId:i(e,r.selectedAgentId),...e.sessionId?{expectedSessionId:e.sessionId}:{},...n.archived===!0?e.archiveGuard:{}})),patch:n},d=_(r.gateway.snapshot,{method:`sessions.patchMany`,params:c,sessionScope:a.sessionScope,session:se(s)});if(!d.allowed){u=d.reason,l.length===0&&e.sessionData.publishSessionMutationError(r,d.reason);break}try{let t=await r.sessions.patchMany(c.targets,c.patch);if(!t||!e.sessionData.isSessionMutationScopeCurrent(r))return null;l.push({rows:s,result:t})}catch(t){u=t,l.length===0&&e.sessionData.publishSessionMutationError(r,t);break}}if(l.length===0||!a.deferListRefresh&&await Ce(e,r,t)===`stale`||!e.sessionData.isSessionMutationScopeCurrent(r))return null;let d=[],f=l.flatMap(({rows:t,result:r})=>r.outcomes.flatMap((r,i)=>{if(!r.ok)return d.push(`${r.key}: ${O(new c(r.error))}`),[];let a=t[i];return a&&n.archived===!0&&e.pruneSidebarSessionEntry(a.key),a?[a]:[]})),m=u===null?``:p(u);return m&&d.push(m),d.length>0&&e.sessionData.publishSessionMutationError(r,d.join(`; `)),f}async function we(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r)||!t.sessionId)return;let a=i(t,r.selectedAgentId);if(R(e,r,{method:`sessions.setInvolvement`,requiredScope:`operator.read`,sessionScope:!0}))try{if(await ae(r.client,{key:t.key,agentId:a,expectedSessionId:t.sessionId,hidden:n}),!e.sessionData.isSessionMutationScopeCurrent(r))return;r.sessions.patchRowLocal(t.key,{hiddenFromInvolvingMe:n},{agentId:a,sessionId:t.sessionId}),await e.sessionData.refreshSidebarSessions(a)}catch(t){e.sessionData.isSessionMutationScopeCurrent(r)&&e.sessionData.publishSessionMutationError(r,t)}}function B(){return(B=e((()=>{u(),s(),C(),f(),ee(),r(),h(),T(),S()})))()}async function V(e,t,n,r,a={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let s=i(t,r.selectedAgentId),c={key:t.key,...n,agentId:s,...t.sessionId?{expectedSessionId:t.sessionId}:{}};if((typeof n.archived==`boolean`||n.snoozedUntil!==void 0)&&!t.sessionId?.trim())return e.sessionData.publishSessionMutationError(r,o(`sessionsView.lifecycleIdentityRequired`)),`failed`;if(!R(e,r,{method:`sessions.patch`,params:c,allowDeferred:d(n),sessionScope:a.sessionScope,session:t}))return`failed`;try{let i=r.gateway.snapshot,o=n.archived===!0&&(i.phase!==`connected`||i.deferredIntentCount||i.deferredIntentDraining),c=()=>r.sessions.patch(t.key,n,{agentId:s,...t.sessionId?{expectedSessionId:t.sessionId}:{},...a.deferListRefresh?{deferListRefresh:!0}:{},...o||a.onConfirmed?{onConfirmed:n=>{o&&e.pruneSidebarSessionEntry(t.key),a.onConfirmed?.(n)}}:{},...a.onDeferredSettled?{onDeferredSettled:a.onDeferredSettled}:{}}),l=n.archived===!0?await D({action:`archive`,session:{...t,agentId:s},scope:r,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(r),request:c}):await c();return e.sessionData.isSessionMutationScopeCurrent(r)?l?`queued`in l?`completed`:((n.pinned===!1||n.archived===!0)&&e.pruneSidebarSessionEntry(t.key),!a.deferListRefresh&&e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(s),!e.sessionData.isSessionMutationScopeCurrent(r))?`stale`:`completed`):(r.sessions.state.error&&e.sessionData.publishSessionMutationError(r,r.sessions.state.error),`failed`):`stale`}catch(t){return e.sessionData.isSessionMutationScopeCurrent(r)?(a.handleError?.(t)||e.sessionData.publishSessionMutationError(r,t),`failed`):`stale`}}function H(){return(H=e((()=>{s(),C(),k(),r(),B(),T(),S()})))()}var Te=t({archiveConfirmedSessionsWithUndo:()=>Z,archiveSessionWithUndo:()=>Y,archiveSessionsWithUndo:()=>X,confirmRunningSessionsArchive:()=>J,confirmSessionArchive:()=>G,promoteSession:()=>W,snoozeSessionWithUndo:()=>U});async function U(e,t,n,r){let{snoozedUntil:i,rememberCustom:a}=n;if(await V(e,t,{snoozedUntil:i},r,{sessionScope:!0})!==`completed`||!e.sessionData.isSessionMutationScopeCurrent(r))return;a&&ye(be(r.client.gatewayUrl,r.client.recoveryScope),i);let s=Q(e,r);y({severity:`success`,message:o(`sessionsView.sessionSnoozed`,{time:oe(i)}),actionLabel:o(`common.undo`),onAction:()=>void V(s,t,{snoozedUntil:null},r,{sessionScope:!0})})}async function W(e,t,n){await V(e,t,{sidebarRoot:!0},n,{sessionScope:!0})===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&y({severity:`success`,message:o(`sessionsView.sessionMovedToTopLevel`)})}async function G(e,t,r){if(!r())return null;if(e.hasArchiveDescendants&&t.gateway.snapshot.phase!==`connected`){let n={title:o(`sessionsView.archiveSessionTitle`),message:o(`sessionsView.archiveSessionNestedOffline`,{session:e.label})+(K(e)?` `+o(`sessionsView.archiveRunningSessions`):``),confirmLabel:o(`sessionsView.archiveThisSession`),signal:t.signal};return await w(q([e],t),e=>x(e?E(n,e):n),Boolean)&&r()?{kind:`single`}:null}if(e.hasArchiveDescendants){let{session:s}=await t.sessions.describe({key:e.key,agentId:i(e,t.selectedAgentId)},{refresh:!0});if(!r())return null;if(!s||!s.sessionId||s.sessionId!==e.sessionId||s.archived)throw Error(o(`sessionsView.archiveTreeChanged`));if(a(s.key))throw Error(o(`sessionsView.archiveTreeRootRequired`));let c=[],u=new Map,d=new Set,f=[{row:s,ancestors:[]}];for(;f.length>0;){let{row:e,ancestors:i}=f.shift();if(d.has(e.key))continue;d.add(e.key);let o=!a(e.key);if(e.archived||o&&e!==s&&(e.sidebarRoot||e.category?.trim())||(o&&(c.push(e),u.set(e.key,i)),!e.childSessions?.length))continue;let p=await m({sessions:t.sessions,parentKey:e.key,isCurrent:r});if(!r()||p===null)return null;let h=o?[e,...i]:i;f.push(...p.filter(t=>n(l(t)??e.key,e.key)).map(e=>({row:e,ancestors:h})))}if(!r())return null;if(c.some(e=>!e.sessionId))throw Error(o(`sessionsView.archiveTreeChanged`));if(c.length>1){let n=c.toReversed().map(n=>({key:n.key,agentId:n.agentId,sessionId:n.sessionId,sharingRole:n.sharingRole,label:g(n.key,n),pinned:n.pinned===!0,archived:n.archived,category:n.category,active:n.key===e.key&&e.active,archiveGuard:{expectedSidebarRoot:n.sidebarRoot===!0,expectedCategory:n.category??null,expectedArchived:!1,expectedSidebarAncestors:(u.get(n.key)??[]).map(e=>{if(!e.sessionId)throw Error(o(`sessionsView.archiveTreeChanged`));return{key:e.key,agentId:i(e,t.selectedAgentId),expectedSessionId:e.sessionId,expectedSidebarRoot:e.sidebarRoot===!0,expectedCategory:e.category??null}})}})),a=c.filter(e=>u.get(e.key)?.length===1).length,s={title:o(`sessionsView.archiveSessionTitle`),message:o(a===1?`sessionsView.archiveSessionNestedOne`:`sessionsView.archiveSessionNestedOther`,{count:String(a),session:e.label})+(c.some(K)?` `+o(`sessionsView.archiveRunningSessions`):``),confirmLabel:o(`sessionsView.archiveAllSessions`,{count:String(c.length)}),alternativeLabel:o(`sessionsView.archiveThisSession`),groupChoicesOnMobile:!0,signal:t.signal},l=c.map(e=>({key:e.key,agentId:i(e,t.selectedAgentId),label:g(e.key,e),hasAutomation:e.hasAutomation})),d=await w(q(l,t),e=>pe(e?{...E(s,e),confirmLabel:s.confirmLabel}:s),e=>e!==null);return!r()||d===null?null:d===`confirm`?{kind:`tree`,rows:n}:{kind:`single`}}}return await J([e],t)&&r()?{kind:`single`}:null}function K(e){return!!((e.gatewayHasActiveRun??e.hasActiveRun)||e.hasActiveSubagentRun)}function q(e,t){return{action:`archive`,sessions:e,gateway:t.gateway,selectedAgentId:t.selectedAgentId,signal:t.signal}}async function J(e,t){let n=e.some(K),r=e.length===1?e[0]:void 0,i={title:r?o(`sessionsView.archiveSessionPrompt`,{session:r.label}):o(`sessionsView.archiveSessionsPrompt`,{count:String(e.length)}),message:n?o(r?`sessionsView.archiveRunningSessionConfirm`:`sessionsView.archiveRunningSessions`):``,confirmLabel:r?o(`sessionsView.archiveSession`):o(`sessionsView.archiveSessionCount`,{count:String(e.length)}),signal:t.signal};return w(q(e,t),e=>e?x(E(i,e)):n?x(i):Promise.resolve(!0),Boolean)}async function Y(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let i;try{i=await G(t,n,()=>e.sessionData.isSessionMutationScopeCurrent(n))}catch(t){e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,t);return}i&&Z(e,i.kind===`tree`?i.rows:[t],n,i.kind===`tree`?void 0:r)}async function X(e,t,n){e.sessionData.isSessionMutationScopeCurrent(n)&&await J(t,n)&&Z(e,t,n)}function Z(e,t,n,r){if(t.length===0||!e.sessionData.isSessionMutationScopeCurrent(n))return;let i=Q(e,n),a=r?A(r):void 0,o=t.flatMap(e=>{let t=n.sessions.beginArchive(e.key,e.sessionId);return t?[{row:e,finish:t}]:[]});if(a?.(),o.length===0)return;let s=o.map(({row:e})=>e),c=s.length===1&&!s[0].archiveGuard?s[0]:void 0;return Ee({keys:s.map(e=>e.key),commit:()=>c?V(i,c,{archived:!0},n,{sessionScope:!0}):z(i,s,{archived:!0},n,{sessionScope:!0}),publishError:e=>i.sessionData.publishSessionMutationError(n,e),release:()=>{for(let{finish:e}of o)e()}}),`completed`}function Ee(e){let t=!1,n=new AbortController,r={keys:e.keys,settle:r=>{t||(t=!0,i(),r?e.commit().catch(e.publishError).finally(e.release):(n.abort(),e.release()))}},i=me(r);y({severity:`success`,message:e.keys.length===1?o(`sessionsView.sessionArchived`):o(`sessionsView.sessionsArchived`,{count:String(e.keys.length)}),actionLabel:o(`common.undo`),signal:n.signal,onAction:()=>r.settle(!1),onDismiss:e=>{e!==`action`&&r.settle(!0)}})}function De(e){let t=e.sessions.captureConnectionScope();if(t)return()=>e.sessions.isConnectionScopeCurrent(t);let n=v(e.gateway).key;return()=>e.allowDeferred===!0&&ne(e.context,e)&&v(e.gateway).key===n}function Q(e,t){let n=De(t);return{pruneSidebarSessionEntry:t=>e.pruneSidebarSessionEntry(t),selectSession:t=>e.selectSession(t),sidebarSessionStatusFilter:()=>e.sidebarSessionStatusFilter(),sessionData:{refreshSidebarSessions:t=>e.sessionData.refreshSidebarSessions(t),isSessionMutationScopeCurrent:n,publishSessionMutationError:(t,r)=>{e.sessionData.isSessionMutationScopeCurrent(t)?e.sessionData.publishSessionMutationError(t,r):n()&&y({severity:`error`,message:p(r)})}}}}function $(){return($=e((()=>{de(),s(),b(),_e(),f(),ue(),re(),ve(),r(),ie(),le(),L(),fe(),he(),xe(),te(),B(),H(),ce(),ge()})))()}export{W as a,H as c,z as d,R as f,$ as i,V as l,X as n,Te as o,we as p,J as r,U as s,Y as t,B as u};