openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
6 lines (4 loc) • 4.06 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Qo as t,Uu as n,Y as r,Z as i,_l as a,hs as o,li as s,oi as c,tu as l}from"./_4____________________________.js";import{AN as u,EN as d,JO as f,YO as p,_o as m,mF as h,pF as g,vo as _}from"./_2_____________________________.js";import{Bi as v,Hi as y}from"./deferred-ui-support-DZEPWjAk.js";import{n as b,t as x}from"./session-management-english-BXruTz7H.js";function S(e){return e.some(e=>e.hasAutomation===!0)}function C(e,t,n){return S(e.sessions)?w(e).then(async e=>{D(e,`shown`);let r=await t(e);return D(e,n(r)?`confirmed`:`cancelled`),r}):t(null)}async function w(e){let t=e.sessions.filter(e=>e.hasAutomation===!0),{jobs:n,total:r}=await T(e.gateway.snapshot,t,e),i=e.sessions.length===1?e.sessions[0]:void 0,a=s(e.action===`archive`?i?`sessionsView.automationPauseArchiveOne`:`sessionsView.automationPauseArchiveOther`:i?`sessionsView.automationDeleteWarningOne`:`sessionsView.automationDeleteWarningOther`,{session:i?.label??i?.key??``,count:String(t.length)});if(n.length===0)return{action:e.action,message:a+`
`+s(`sessionsView.automationPauseUnlisted`),automationCount:t.length};let o=n.slice(0,O).map(e=>e.name+` (`+e.id+`)`);return r>o.length&&o.push(s(`sessionsView.automationPauseMore`,{count:String(r-o.length)})),{action:e.action,message:a,details:o.join(`
`),automationCount:r}}async function T(e,t,n){let i=e.client;if(!i||!r(e,`cron.list`,`operator.read`,{requireAdvertisement:!1}))return{jobs:[],total:0};let a=await Promise.all(t.map(async t=>{let r=o(e,t.key,t.agentId??n.selectedAgentId);try{return await i.request(`cron.list`,{sessionKey:r.sessionKey,...r.agentId?{sessionAgentId:r.agentId}:{},enabled:`enabled`,compact:!0,includeDeliveryPreviews:!1,sortBy:`name`,limit:O},{signal:n.signal})}catch{return null}})),s=new Map,c=0;for(let e of a){let t=Array.isArray(e?.jobs)?e.jobs:[];for(let e of t)s.set(e.id,e);c+=Math.max(0,(e?.total??0)-t.length)}return{jobs:[...s.values()],total:s.size+c}}function E(e,t){return{...e,skipPreference:void 0,message:e.message?e.message+`
`+t.message:t.message,...t.details?{details:t.details}:{},confirmLabel:s(t.action===`archive`?`sessionsView.archiveAnyway`:`sessionsView.deleteAnyway`)}}function D(e,t){console.info(`[session-automation-confirm] `+e.action+` `+t,{automations:e.automationCount})}var O;function k(){return(k=e((()=>{c(),x(),i(),t(),b(),O=10})))()}function A(e){let t=n(e),r=n(t?.details),i=n(r?.source);return t?.code!==a.UNAVAILABLE||r?.code!==g.SESSION_WORKSPACE_RECOVERY_REQUIRED||r.cause!==`device_offline`||r.recoveryAction!==`continue_on_gateway`||!l(r.sessionId)||typeof i?.generation!=`number`||!Number.isSafeInteger(i.generation)||i.generation<0||!l(i.environmentId)||typeof i.ownerEpoch!=`number`||!Number.isSafeInteger(i.ownerEpoch)||i.ownerEpoch<1?null:{code:r.code,cause:r.cause,recoveryAction:r.recoveryAction,sessionId:r.sessionId,source:{generation:i.generation,environmentId:i.environmentId,ownerEpoch:i.ownerEpoch}}}function j(){return(j=e((()=>{h()})))()}function M(e){let t=d(e);return A(e)?`${t} ${s(`sessionsView.workspaceRecoveryBatchHint`)}`:t}async function N(e){let t=!1;for(;e.isCurrent();)try{return await e.request()}catch(n){if(!e.isCurrent())return;let r=A(n);if(t||!r||r.sessionId!==e.session.sessionId)throw n;let i={key:e.session.key,...e.session.agentId?{agentId:e.session.agentId}:{},expected:r.source,target:{kind:`gateway`},abandonSource:!0},a=()=>{let t=p(e.scope.gateway.snapshot,{method:`sessions.move`,params:i,requiredScope:`operator.write`});if(!t.allowed)throw Error(t.reason,{cause:n})};a();let o=e.action===`delete`?`Delete`:`Archive`,c=await y({title:s(`sessionsView.discardWorkspaceTitle`),message:s(`sessionsView.discardWorkspace${o}Confirm`,{session:e.session.label}),confirmLabel:s(`sessionsView.discardWorkspace${o}Action`),danger:!0,signal:e.scope.signal});if(!e.isCurrent())return;if(!c)throw n;a(),await e.scope.client.request(`sessions.move`,i),t=!0}}function P(){return(P=e((()=>{j(),c(),m(),u(),f(),v(),_()})))()}export{k as a,C as i,P as n,E as o,N as r,M as t};