openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 17.1 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Hr as t,Pu as n,So as r,Vr as i,Wr as a,Zl as o,_u as s,kl as c,vu as l,wo as u,xu as d,yu as f,zu as p}from"./control-ui-core-CBJ5efDh.js";import{$n as m,_n as h,er as g,hn as _,wn as v}from"./control-ui-core-DtLivg_r.js";import{ga as ee,ha as y}from"./control-ui-boot-shared-UG5ko-VG.js";import{na as b,ta as x}from"./control-ui-boot-shared-XreXSF7h.js";import{a as S,i as C,n as w,o as T,r as E,t as D}from"./session-workspace-recovery.runtime-C0JCx4Ml.js";import{Fl as te,Pl as ne,Qc as re,Zc as ie,_l as ae,vl as O,yl as k}from"./control-ui-boot-shared-dOnP4mAA.js";import{r as A,t as j}from"./input-dialog-CnAqzRxY.js";import{n as M,t as N}from"./cloud-worker-stop.runtime-B791S2pQ.js";function P(e,n,r){let i=t(n.gateway.snapshot,r);return i.allowed?!0:(e.sessionData.publishSessionMutationError(n,i.reason),!1)}async function F(e,t,n){let r=[...new Set(n.map(e=>o(e,t.selectedAgentId)))],i=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;i&&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 I(e,n,r,i,s={}){if(typeof r.archived==`boolean`&&n.some(e=>!e.sessionId?.trim()))return e.sessionData.publishSessionMutationError(i,`Session lifecycle action requires a durable session identity.`),null;let c=[],l=null;for(let u=0;u<n.length;u+=100){if(!e.sessionData.isSessionMutationScopeCurrent(i))return null;let d=n.slice(u,u+100),f={targets:d.map(e=>({key:e.key,agentId:o(e,i.selectedAgentId),...e.sessionId?{expectedSessionId:e.sessionId}:{}})),patch:r},p=t(i.gateway.snapshot,{method:`sessions.patchMany`,params:f,sessionScope:s.sessionScope,session:a(d)});if(!p.allowed){l=p.reason,c.length===0&&e.sessionData.publishSessionMutationError(i,p.reason);break}try{let t=await i.sessions.patchMany(f.targets,f.patch);if(!t||!e.sessionData.isSessionMutationScopeCurrent(i))return null;c.push({rows:d,result:t})}catch(t){l=t,c.length===0&&e.sessionData.publishSessionMutationError(i,t);break}}if(c.length===0||!s.deferListRefresh&&await F(e,i,n)===`stale`||!e.sessionData.isSessionMutationScopeCurrent(i))return null;let u=[],d=c.flatMap(({rows:t,result:n})=>n.outcomes.flatMap((n,i)=>{if(!n.ok)return u.push(`${n.key}: ${D(new g(n.error))}`),[];let a=t[i];return a?.pinned&&r.archived===!0&&e.pruneSidebarSessionEntry(a.key),a?[a]:[]})),p=l===null?``:f(l);return p&&u.push(p),u.length>0&&e.sessionData.publishSessionMutationError(i,u.join(`; `)),d}async function L(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r)||!t.sessionId)return;let i=o(t,r.selectedAgentId);if(P(e,r,{method:`sessions.setInvolvement`,requiredScope:`operator.read`}))try{if(await u(r.client,{key:t.key,agentId:i,expectedSessionId:t.sessionId,hidden:n}),!e.sessionData.isSessionMutationScopeCurrent(r))return;r.sessions.patchRowLocal(t.key,{hiddenFromInvolvingMe:n},{agentId:i,sessionId:t.sessionId}),await e.sessionData.refreshSidebarSessions(i)}catch(t){e.sessionData.isSessionMutationScopeCurrent(r)&&e.sessionData.publishSessionMutationError(r,t)}}function R(){return(R=e((()=>{m(),d(),i(),c(),r(),w()})))()}async function z(e,t,n){let r=e.knownSessionGroups();return r.includes(t)?`completed`:U(e,n,`sessions.groups.put`,()=>n.sessions.groupsPut([...r,t]))}async function B(e,t,n,r){return await U(e,r,`sessions.groups.rename`,()=>r.sessions.groupsRename(t,n))===`completed`}async function V(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n)||!P(e,n,{method:`sessions.groups.delete`,requiredScope:`operator.write`}))return!1;let r=await b({title:p(`sessionsView.deleteGroupTitle`,{group:t}),message:p(`sessionsView.deleteGroupConfirm`),confirmLabel:p(`common.delete`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))return l({message:p(`sessionsView.deleteGroupStale`,{group:t})}),!1;if(!r)return!1;try{return await n.sessions.groupsDelete(t)===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)}catch(t){return e.sessionData.publishSessionMutationError(n,t),!1}}function H(e,t,n,r){return U(e,r,`sessions.groups.update`,()=>r.sessions.groupsUpdate(t,n))}async function U(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;if(!P(e,t,{method:n,requiredScope:`operator.write`}))return`failed`;try{return await r()===`completed`&&e.sessionData.isSessionMutationScopeCurrent(t)?`completed`:`stale`}catch(n){return e.sessionData.isSessionMutationScopeCurrent(t)?(e.sessionData.publishSessionMutationError(t,n),`failed`):`stale`}}async function oe(e,t,n,r,i){if(e.sessionData.isSessionMutationScopeCurrent(i)&&P(e,i,{method:`sessions.groups.put`,requiredScope:`operator.write`}))try{let a=e.knownSessionGroups(),o=e.knownSessionCatalogIds(),s=O(k(e.knownSectionOrder(),a,o),t,n,r),c=s.flatMap(e=>e.startsWith(`category:`)?[e.slice(9)]:[]);if(await i.sessions.groupsPut(c,s),!e.sessionData.isSessionMutationScopeCurrent(i))return;e.requestUpdate()}catch(t){e.sessionData.publishSessionMutationError(i,t)}}function W(){return(W=e((()=>{n(),ae(),s(),x(),R()})))()}async function G(e,t,n,r,i={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let a=o(t,r.selectedAgentId),s={key:t.key,...n,agentId:a,...t.sessionId?{expectedSessionId:t.sessionId}:{}};if((typeof n.archived==`boolean`||n.snoozedUntil!==void 0)&&!t.sessionId?.trim())return e.sessionData.publishSessionMutationError(r,`Session lifecycle action requires a durable session identity.`),`failed`;if(!P(e,r,{method:`sessions.patch`,params:s,sessionScope:i.sessionScope,session:t}))return`failed`;try{let o=()=>r.sessions.patch(t.key,n,{agentId:a,...t.sessionId?{expectedSessionId:t.sessionId}:{},...i.deferListRefresh?{deferListRefresh:!0}:{}}),s=n.archived===!0?await E({action:`archive`,session:{...t,agentId:a},scope:r,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(r),request:o}):await o();return e.sessionData.isSessionMutationScopeCurrent(r)?s?((n.pinned===!1||n.archived===!0&&t.pinned)&&e.pruneSidebarSessionEntry(t.key),!i.deferListRefresh&&e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(a),!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)?(i.handleError?.(t)||e.sessionData.publishSessionMutationError(r,t),`failed`):`stale`}}function K(){return(K=e((()=>{c(),R(),w()})))()}async function q(e,t,n,r){if(await G(e,t,{snoozedUntil:n},r,{sessionScope:!0})!==`completed`||!e.sessionData.isSessionMutationScopeCurrent(r))return;let i=Y(e,r);l({message:p(`sessionsView.sessionSnoozed`,{time:ne(n)}),actionLabel:p(`common.undo`),onAction:()=>void G(i,t,{snoozedUntil:null},r,{sessionScope:!0})})}async function se(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=n.sessions.beginArchive(t.key,t.sessionId);if(!r)return;let i;try{i=await G(e,t,{archived:!0},n,{sessionScope:!0})}finally{r()}i===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&l({message:p(`sessionsView.sessionArchived`),actionLabel:p(`common.undo`),onAction:J(e,[{session:t,pinned:t.pinned}],n)})}async function ce(e,t,n){if(t.length===0||!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=t.flatMap(e=>{let t=n.sessions.beginArchive(e.key,e.sessionId);return t?[{row:e,finish:t}]:[]});if(r.length===0)return;let i=r.map(({row:e})=>e),a;try{a=await I(e,i,{archived:!0},n,{sessionScope:!0})}finally{for(let{finish:e}of r)e()}if(!a||a.length===0)return;let o=a.map(e=>({session:e,pinned:e.pinned}));l({message:o.length===1?p(`sessionsView.sessionArchived`):p(`sessionsView.sessionsArchived`,{count:String(o.length)}),actionLabel:p(`common.undo`),onAction:J(e,o,n)})}function J(e,t,n){let r=Y(e,n);return()=>void le(r,t,n)}function Y(e,t){let n=t.sessions.captureConnectionScope();return{pruneSidebarSessionEntry:t=>e.pruneSidebarSessionEntry(t),selectSession:t=>e.selectSession(t),sidebarSessionStatusFilter:()=>e.sidebarSessionStatusFilter(),sessionData:{refreshSidebarSessions:t=>e.sessionData.refreshSidebarSessions(t),isSessionMutationScopeCurrent:()=>n!==null&&t.sessions.isConnectionScopeCurrent(n),publishSessionMutationError:(r,i)=>{e.sessionData.isSessionMutationScopeCurrent(r)?e.sessionData.publishSessionMutationError(r,i):n&&t.sessions.isConnectionScopeCurrent(n)&&l({message:f(i)})}}}}async function le(e,t,n){let r=t.map(e=>e.session);if(t.length===1){let{session:r,pinned:i}=t[0];if(await G(e,r,{archived:!1,...i?{pinned:!0}:{}},n,{deferListRefresh:!0,sessionScope:!0})===`stale`)return}else{let i=await I(e,r,{archived:!1},n,{deferListRefresh:!0,sessionScope:!0});if(!i)return;let a=t.flatMap(({session:e,pinned:t})=>t&&i.includes(e)?[e]:[]);if(a.length>0&&!await I(e,a,{pinned:!0},n,{deferListRefresh:!0,sessionScope:!0})&&!e.sessionData.isSessionMutationScopeCurrent(n))return}if(e.sessionData.isSessionMutationScopeCurrent(n)){n.sessions.invalidate();try{let t=await n.sessions.refreshReplacement();if(!e.sessionData.isSessionMutationScopeCurrent(n))return;!t&&n.sessions.state.error&&e.sessionData.publishSessionMutationError(n,n.sessions.state.error)}catch(t){e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,t)}}}function X(e){return{skipped:h().sessionDeleteConfirm===!1,remember:()=>{v({sessionDeleteConfirm:!1}),e.context.theme.refresh()}}}async function Z(e,t,n){if(t.length===0)return;let r=await b({message:p(`sessionsView.deleteSessionsConfirm`,{count:String(t.length)}),confirmLabel:p(`common.delete`),danger:!0,skipPreference:X(n),signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){l({message:p(`sessionsView.deleteSessionsStale`,{count:String(t.length)})});return}if(!r)return;let i=t.map(e=>({key:e.key,agentId:o(e,n.selectedAgentId),deleteTranscript:!0,...e.sessionId?{expectedSessionId:e.sessionId}:{},...e.archived===!0?{archivedOnly:!0}:{}}));for(let t of i)if(!P(e,n,{method:`sessions.delete`,params:t}))return;try{let t=await n.sessions.deleteMany(i);if(!e.sessionData.isSessionMutationScopeCurrent(n)){t.preservedWorktrees.length>0&&l({message:S(t.preservedWorktrees)});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(n.selectedAgentId),!e.sessionData.isSessionMutationScopeCurrent(n))||t.preservedWorktrees.length>0&&(window.alert(S(t.preservedWorktrees)),!e.sessionData.isSessionMutationScopeCurrent(n)))return;t.errors.length>0&&e.sessionData.publishSessionMutationError(n,t.errors.map(({error:e})=>D(e)).join(`; `))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function ue(e,n,r){let i=new Set(n.map(e=>e.key)),a=new Map;for(let e of n.flatMap(e=>e.subagentSummary?.unreadHiddenRuns??[]))i.has(e.key)||a.set(e.key,e);await Promise.all([...a.values()].map(async n=>{if(!e.sessionData.isSessionMutationScopeCurrent(r))return;let i=o(n,r.selectedAgentId),a=n.sessionId?{expectedSessionId:n.sessionId}:{};t(r.gateway.snapshot,{method:`sessions.patch`,params:{key:n.key,unread:!1,agentId:i,...a},session:n}).allowed&&await r.sessions.patch(n.key,{unread:!1},{agentId:i,expectedMarkedUnreadAt:null,...a}).catch(()=>void 0)}))}async function de(e,t,n,r,i){switch(t.kind){case`toggle-unread`:await I(e,n,{unread:!r},i),r&&await ue(e,n,i);break;case`move-to-group`:await I(e,n.filter(e=>(e.category??null)!==t.category),{category:t.category},i);break;case`toggle-archived`:n.every(e=>e.archived===!0)?await I(e,n,{archived:!1},i,{sessionScope:!0}):await ce(e,n.filter(e=>e.archived!==!0),i);break;case`delete`:await Z(e,n,i)}}async function fe(e,t,n){await A({signal:n.signal,title:p(`sessionsView.renameSessionPrompt`),defaultValue:t.renameValue,submit:async r=>{let i=re(r,t.renameValue,t.userLabel);if(!i)return null;let a=null;return await G(e,t,i,n,{sessionScope:!0,handleError:e=>/^label already in use:/iu.test(f(e))?(a=p(`sessionsView.sessionNameInUse`),!0):!1}),a}})}async function pe(e,t,n,r){if(!P(e,r,{method:`sessions.assignOwner`,params:{key:t.key,owner:n},requiredScope:`operator.write`}))return;let i=await r.sessions.assignOwner(t.key,n,{agentId:o(t,r.selectedAgentId)});e.sessionData.isSessionMutationScopeCurrent(r)&&!i&&r.sessions.state.error&&e.sessionData.publishSessionMutationError(r,r.sessions.state.error)}async function me(e,t,n,r){if(n.some(e=>!e.sessionId))return e.sessionData.publishSessionMutationError(r,p(`common.refresh`)),`failed`;let i=await z(e,t,r);if(i!==`completed`)return i;if(n.length>0){if(n.length===1)return G(e,n[0],{category:t},r);let i=await I(e,n,{category:t},r);return i?i.length===n.length?`completed`:`failed`:e.sessionData.isSessionMutationScopeCurrent(r)?`failed`:`stale`}return e.sessionData.isSessionMutationScopeCurrent(r)?(e.requestUpdate(),`completed`):`stale`}async function Q(e,t,n,r,i={},a={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return;let o=!(!n||e.knownSessionGroups().includes(n));if(n&&await z(e,n,r)!==`completed`)return;let s=a.resolveSession?a.resolveSession():t;if(!s){l({message:p(o?`sessionsView.newGroupMoveSkipped`:`common.refresh`)});return}((s.category??null)!==n||i.pinned!==void 0)&&await G(e,s,{category:n,...i},r)}async function he(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=o(t,n.selectedAgentId),i={parentSessionKey:t.key,fork:!0,...t.gatewayHasActiveRun??t.hasActiveRun?{forkFrom:`last-completed`}:{},agentId:r};if(P(e,n,{method:`sessions.create`,params:i}))try{let t=await n.sessions.create(i);if(!e.sessionData.isSessionMutationScopeCurrent(n))return;t?e.selectSession(t):e.sessionData.publishSessionMutationError(n,n.sessions.state.error??p(`newSession.createFailed`))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function ge(e,t,n){let r=t.cloudWorkerStopAction;if(!r||r.blocksActiveRun&&t.hasActiveRun)return;let i=await b({message:p(`sessionsView.stopCloudWorkerConfirm`,{session:t.label}),confirmLabel:p(`sessionsView.stopCloudWorkerConfirmAction`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){l({message:p(`sessionsView.stopCloudWorkerStale`,{session:t.label})});return}if(i&&P(e,n,r))try{let r=o(t,n.selectedAgentId);if(await M(n.client,{key:t.key,agentId:r},n.context.placementStartup),!e.sessionData.isSessionMutationScopeCurrent(n))return;let i=await n.sessions.reconcileMutation(r);i.status===`failed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,i.error)}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function _e(e,n,r,i={}){let a=await b({message:p(`sessionsView.deleteSessionConfirm`,{session:n.label}),confirmLabel:p(`common.delete`),danger:!0,...i.offerSkip?{skipPreference:X(r)}:{},signal:r.signal});if(!e.sessionData.isSessionMutationScopeCurrent(r)){l({message:p(`sessionsView.deleteSessionStale`,{session:n.label})});return}if(!a)return;let s=o(n,r.selectedAgentId),c={agentId:s,deleteTranscript:!0,...n.sessionId?{expectedSessionId:n.sessionId}:{},...n.archived===!0?{archivedOnly:!0}:{}};if(P(e,r,{method:`sessions.delete`,params:{key:n.key,...c}}))try{let i=await E({action:`delete`,session:{...n,agentId:s},scope:r,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(r),request:()=>r.sessions.delete(n.key,c)});if(!i)return;if(!e.sessionData.isSessionMutationScopeCurrent(r)){i.worktreePreserved&&l({message:S([i.worktreePreserved])});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(s),!e.sessionData.isSessionMutationScopeCurrent(r)))return;if(i.worktreePreserved){let n=i.worktreePreserved;if(!t(r.gateway.snapshot,{method:`worktrees.remove`,requiredScope:`operator.admin`}).allowed)window.alert(S([n]));else{let t=await b({message:C(n),confirmLabel:p(`common.remove`),danger:!0,signal:r.signal});if(!e.sessionData.isSessionMutationScopeCurrent(r)){l({message:S([n])});return}if(t)try{let t=await r.client.request(`worktrees.remove`,{id:n.id,force:!0});t.snapshotError&&e.sessionData.publishSessionMutationError(r,t.snapshotError)}catch(t){e.sessionData.publishSessionMutationError(r,t)}}}}catch(t){e.sessionData.publishSessionMutationError(r,t)}}function $(){return($=e((()=>{_(),n(),y(),d(),i(),ie(),c(),te(),T(),s(),N(),x(),j(),R(),W(),K(),w(),ee()})))()}$();export{se as archiveSessionWithUndo,Q as assignSessionCategory,pe as assignSessionOwner,me as createSessionGroup,_e as deleteSession,V as deleteSessionGroup,Z as deleteSessionsBatch,he as forkSession,G as patchSession,fe as renameSession,B as renameSessionGroup,oe as reorderSidebarSection,de as runBatchSessionAction,L as setSessionInvolvement,q as snoozeSessionWithUndo,ge as stopCloudWorker,H as updateSessionGroupDefaults};