openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 78.9 kB
JavaScript
import{i as e,n as t,t as n}from"./rolldown-runtime-CNOWq4Kh.js";import{Fu as r,Ju as i,X as a,Y as o,Z as s,b as c,h as l,li as u,oi as d,si as f,ut as p,v as m}from"./_4____________________________.js";import{AN as h,EN as g,FN as _,Ft as v,GN as y,JN as b,Lj as ee,Lt as x,Mm as S,Op as C,PN as w,Qo as T,Zo as te,dT as E,dx as D,fT as O,fk as k,iv as A,ix as j,jj as ne,jm as M,kp as N,mk as re,ov as ie,qN as ae,wl as oe,xl as P}from"./_2_____________________________.js";import{Bi as se,Hi as ce}from"./deferred-ui-support-DZEPWjAk.js";import{B as F,C as I,Ct as le,F as L,I as ue,J as R,O as z,Rt as de,S as fe,St as pe,T as me,U as B,V as he,_ as V,d as H,f as U,g as W,gt as ge,j as G,k as _e,l as K,s as q,u as J,w as ve,x as Y,yt as ye}from"./_6____________________.js";import{n as be,t as xe}from"./en-settings-DEvavpke.js";import{n as Se,t as Ce}from"./gateway-page-runtime-CW2orlv_.js";import{C as we,S as Te,a as Ee,c as De,f as Oe,g as X,m as Z,p as ke,s as Ae,u as je,w as Q,x as Me,y as Ne}from"./settings-controls-runtime-CwXZmgDo.js";import{a as Pe,c as Fe,o as Ie,s as Le}from"./route-chrome-Dr9fhzjf.js";import{n as Re,r as ze}from"./settings-disclosure-C2Lxm_wL.js";import{n as Be,t as Ve}from"./settings-select-row-DhCp1sjn.js";function He(e){let t=i(e.cloudWorkers)?e.cloudWorkers:null;return i(t?.profiles)?t.profiles:{}}function Ue(e){return i(e.settings)?e.settings:{}}function $(e,t){return r(e[t])??``}function We(e){return e?Object.entries(He(e)).flatMap(([e,t])=>{if(!i(t))return[];let n=Ue(t);return[{id:e,providerId:r(t.provider)??``,backend:$(n,`provider`),target:$(n,`target`),machineClass:$(n,`class`),ttl:$(n,`ttl`),idleTimeout:$(n,`idleTimeout`),setup:$(n,`setup`),setupEnv:Array.isArray(n.setupEnv)?n.setupEnv.join(`, `):``,warmImage:n.warmImage===!0?`on`:n.warmImage===!1?`off`:`auto`,readyWorkers:typeof t.readyWorkers==`number`?String(t.readyWorkers):``,suspendAfter:$(t,`suspendAfter`),desktop:n.desktop===!0,binary:$(n,`binary`)}]}).toSorted((e,t)=>e.id.localeCompare(t.id)):[]}function Ge(e){return{id:e?.id??``,backend:e?.backend??``,target:e?.target??``,machineClass:e?.machineClass??``,ttl:e?.ttl||`8h`,idleTimeout:e?.idleTimeout||`45m`,setup:e?.setup??``,setupEnv:e?.setupEnv??``,warmImage:e?.warmImage??`auto`,readyWorkers:e?.readyWorkers??``,suspendAfter:e?.suspendAfter??``,desktop:e?.desktop??!1,binary:e?.binary??``}}function Ke(e){return e.split(/[,\s]+/u).filter(Boolean)}function qe(e,t,n){let r=e.id.trim();if(!Xe.test(r)||r!==e.id)return`profileId`;if(!n&&Object.hasOwn(t,r))return`profileExists`;if(n&&!Object.hasOwn(t,n))return`profileMissing`;if(!e.backend.trim())return`backend`;if(e.target!==e.target.trim()||e.target.length>64)return`target`;if(e.warmImage===`on`&&e.target&&e.target!==`linux`)return`warmImage`;let i=e.machineClass.trim();if(!i||i.length>128)return`machineClass`;if(!Ze.test(e.ttl.trim()))return`ttl`;if(!Ze.test(e.idleTimeout.trim()))return`idleTimeout`;let a=Ke(e.setupEnv);if(a.length>16||new Set(a).size!==a.length||a.some(e=>!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)||e===`CRABBOX_ENV_ALLOW`))return`setupEnv`;if(a.length&&!e.setup.trim())return`setupEnvRequiresSetup`;let o=e.readyWorkers.trim();if(o&&(!/^\d+$/u.test(o)||!Number.isSafeInteger(Number(o))))return`readyWorkers`;let s=e.suspendAfter.trim();if(s)try{if(!/(?:ms|s|m|h|d)$/i.test(s)||T(s)<6e4)return`suspendAfter`}catch{return`suspendAfter`}let c=e.binary.trim();return c&&!c.startsWith(`/`)&&!Qe.test(c)?`binary`:null}function Je(e,t,n){let a=He(e),o=qe(t,a,n);if(o)return{error:o};let s=n??t.id,c=i(a[s])?a[s]:{},l=Ue(c);if(n&&(r(c.provider)!==`crabbox`||!$(l,`class`)))return{error:`profileMissing`};let u=t.setup.trim(),d=Ke(t.setupEnv),f={provider:t.backend.trim(),target:t.target||null,class:t.machineClass.trim(),ttl:t.ttl.trim(),idleTimeout:t.idleTimeout.trim(),setup:u||null,setupEnv:d.length?d:null,warmImage:t.warmImage===`auto`?null:t.warmImage===`on`,desktop:t.desktop?!0:null,binary:t.binary.trim()||null},p={provider:r(c.provider)??`crabbox`,install:c.install===`npm`?`npm`:`bundle`,readyWorkers:t.readyWorkers.trim()?Number(t.readyWorkers):null,suspendAfter:t.suspendAfter.trim()||null,settings:f};return{patch:{cloudWorkers:{profiles:{[s]:p}}},replacePaths:v(l.setupEnv,`cloudWorkers.profiles.${s}.settings.setupEnv`)}}function Ye(e,t){let n=He(e);if(!Object.hasOwn(n,t))return{error:`profileMissing`};let r=i(e.cloudWorkers)?e.cloudWorkers:null,a=i(r?.projectProfiles)?r.projectProfiles:{},o=Object.fromEntries(Object.entries(a).filter(([,e])=>e===t).map(([e])=>[e,null]));return{patch:{cloudWorkers:{profiles:{[t]:null},...Object.keys(o).length>0?{projectProfiles:o}:{}}},replacePaths:v(n[t],`cloudWorkers.profiles.${t}`)}}var Xe,Ze,Qe;function $e(){return($e=t((()=>{te(),x(),Xe=/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/u,Ze=/^(?=.*[1-9])\+?(?:(?:\d+(?:\.\d*)?|\.\d+)(?:ns|us|µs|μs|ms|s|m|h))+$/u,Qe=/^[A-Za-z]:[\\/]/u})))()}function et(){return G(X,{get children(){return G(Te,{get message(){return b(`cloudWorkersPage.environments.adminRequired`)}})}})}function tt(){return(tt=t((()=>{J(),Q(),y()})))()}function nt(e){return e.status===`available`&&e.worker?.state===`ready`&&e.worker.destroyRequestedAtMs===void 0&&e.preparation?.details?.consumedAtMs===null&&e.preparation.details.expiresAtMs>Date.now()&&!e.worker.attachedSessionIds.length}function rt(e){return e.status===`unavailable`||e.status===`error`||!!e.worker?.error||[`failed`,`orphaned`].includes(e.worker?.state??``)||e.preparation?.details?.expiresAtMs!==void 0&&e.preparation.details.expiresAtMs<=Date.now()}function it(e){return!(!e.worker||e.worker.state===`ready`&&!rt(e)&&e.worker.destroyRequestedAtMs===void 0)}function at(e){let t=e.worker;return!!(e.preparation&&t&&t.state!==`destroyed`&&!t.attachedSessionIds.length&&([`requested`,`provisioning`,`bootstrapping`,`ready`,`failed`,`orphaned`].includes(t.state)||t.destroyRequestedAtMs!==void 0||t.error))}function ot(e,t,n){let r=new Map;function i(e){let t=r.get(e);return t||(t={key:e,label:e,images:[],workers:[]},r.set(e,t)),t}for(let e of n)i(e.repository).defaultProfile=e.profileId;for(let t of e)(t.projectKey||t.projectLabel||t.projectRoot)&&i(t.projectLabel??t.projectRoot??t.projectKey??t.profileKey).images.push(t);for(let e of t?.environments??[]){let t=e.preparation?.details?.project?.label;t&&at(e)&&i(t).workers.push(e)}return[...r.values()].toSorted((e,t)=>e.label.localeCompare(t.label))}function st(e){let t=e.images.toSorted((e,t)=>(t.createdAtMs??0)-(e.createdAtMs??0));return t.find(t=>t.profileId===e.defaultProfile)??t[0]}function ct(e){let t=e.images.filter(e=>e.state===`available`).toSorted((e,t)=>(t.createdAtMs??0)-(e.createdAtMs??0))[0]?.createdAtMs,n=e.workers.find(e=>e.worker?.state===`ready`)?.worker;return t??(n?Date.now()-n.ageMs:void 0)}function lt(e,t){return e.images.some(e=>ut(e)===`attention`)||e.workers.some(rt)?`attention`:e.images.some(e=>ut(e)===`building`)||e.workers.some(e=>[`requested`,`provisioning`,`bootstrapping`].includes(e.worker?.state??``))?`building`:e.images.some(e=>e.state===`available`)||e.workers.some(nt)?`ready`:t?`coldOnly`:null}function ut(e){return e.recipePreparation?.failure||e.capture?.phase===`uncertain`||e.retirement&&e.retirement.checkpointId===e.checkpointId?`attention`:e.capture?`building`:e.state===`available`?`ready`:`coldOnly`}var dt=n((e=>{var t=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),n=t(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.tracing=e.metrics=void 0;var t={hasSubscribers:!1};e.metrics=t,e.tracing=t}),r=t(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultPerf=void 0,e.defaultPerf=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date});Object.defineProperty(e,"__esModule",{value:!0}),e.LRUCache=void 0;var i=n(),a=r(),o=()=>i.metrics.hasSubscribers||i.tracing.hasSubscribers,s=new Set,c=typeof process==`object`&&process?process:{},l=(e,t,n,r)=>{typeof c.emitWarning==`function`?c.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)},u=e=>!s.has(e),d=e=>!!e&&e===Math.floor(e)&&e>0&&isFinite(e),f=e=>d(e)?e<=256?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?p:null:null,p=class extends Array{constructor(e){super(e),this.fill(0)}},m=class e{heap;length;static#e=!1;static create(t){let n=f(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};e.LRUCache=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;#E;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,autopurgeTimers:e.#S,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g},free:e.#_,isBackgroundFetch:t=>e.#W(t),backgroundFetch:(t,n,r,i)=>e.#U(t,n,r,i),moveToTail:t=>e.#X(t),indexes:t=>e.#I(t),rindexes:t=>e.#L(t),isStale:t=>e.#j(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:o,updateAgeOnGet:c,updateAgeOnHas:p,allowStale:h,dispose:g,onInsert:_,disposeAfter:v,noDisposeOnSet:y,noUpdateTTL:b,maxSize:ee=0,maxEntrySize:x=0,sizeCalculation:S,fetchMethod:C,memoMethod:w,noDeleteOnFetchRejection:T,noDeleteOnStaleGet:te,allowStaleOnFetchRejection:E,allowStaleOnFetchAbort:D,ignoreFetchAbort:O,backgroundFetchSize:k=1,perf:A}=t;if(this.backgroundFetchSize=k,A!==void 0&&typeof A?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=A??a.defaultPerf,n!==0&&!d(n))throw TypeError(`max option must be a nonnegative integer`);let j=n?f(n):Array;if(!j)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=ee,this.maxEntrySize=x||this.#t,this.sizeCalculation=S,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(w!==void 0&&typeof w!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=w,C!==void 0&&typeof C!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=C,this.#w=!!C,this.#u=new Map,this.#d=Array.from({length:n}).fill(void 0),this.#f=Array.from({length:n}).fill(void 0),this.#p=new j(n),this.#m=new j(n),this.#h=0,this.#g=0,this.#_=m.create(n),this.#c=0,this.#l=0,typeof g==`function`&&(this.#n=g),typeof _==`function`&&(this.#r=_),typeof v==`function`?(this.#i=v,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#C=!!this.#n,this.#E=!!this.#r,this.#T=!!this.#i,this.noDisposeOnSet=!!y,this.noUpdateTTL=!!b,this.noDeleteOnFetchRejection=!!T,this.allowStaleOnFetchRejection=!!E,this.allowStaleOnFetchAbort=!!D,this.ignoreFetchAbort=!!O,this.maxEntrySize!==0){if(this.#t!==0&&!d(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!d(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#M()}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!te,this.updateAgeOnGet=!!c,this.updateAgeOnHas=!!p,this.ttlResolution=d(i)||i===0?i:1,this.ttlAutopurge=!!o,this.ttl=r||0,this.ttl){if(!d(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#D()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;u(t)&&(s.add(t),l(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#D(){let e=new p(this.#e),t=new p(this.#e);this.#x=e,this.#b=t;let n=this.ttlAutopurge?Array.from({length:this.#e}):void 0;this.#S=n,this.#A=(n,i,a=this.#s.now())=>{t[n]=i===0?0:a,e[n]=i,r(n,i)},this.#O=n=>{t[n]=e[n]===0?0:this.#s.now(),r(n,e[n])};let r=this.ttlAutopurge?(e,t)=>{if(n?.[e]&&(clearTimeout(n[e]),n[e]=void 0),t&&t!==0&&n){let i=setTimeout(()=>{this.#j(e)?(this.#Z(this.#d[e],`expire`),n[e]=void 0):r(e,o(e))},t+1);i.unref&&i.unref(),n[e]=i}}:()=>{};this.#k=(n,r)=>{if(e[r]){let o=e[r],s=t[r];if(!o||!s)return;n.ttl=o,n.start=s,n.now=i||a(),n.remainingTTL=o-(n.now-s)}};let i=0,a=()=>{let e=this.#s.now();if(this.ttlResolution>0){i=e;let t=setTimeout(()=>i=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=e=>{let t=this.#u.get(e);return t===void 0?0:o(t)};let o=n=>{let r=e[n],o=t[n];return!r||!o?1/0:r-((i||a())-o)};this.#j=n=>{let r=t[n],o=e[n];return!!o&&!!r&&(i||a())-r>o}}#O=()=>{};#k=()=>{};#A=()=>{};#j=()=>!1;#M(){let e=new p(this.#e);this.#l=0,this.#y=e,this.#N=t=>{this.#l-=e[t],e[t]=0},this.#F=(e,t,n,r)=>{if(!d(n)){if(this.#W(t))return this.backgroundFetchSize;if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!d(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`)}return n},this.#P=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#B(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#N=e=>{};#P=(e,t,n)=>{};#F=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#h);)t=this.#m[t]}*#L({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#g);)t=this.#p[t]}#R(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#L())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#L()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*values(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#L())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.#J(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}rforEach(e,t=this){for(let n of this.#L()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#L({allowStale:!0}))this.#j(t)&&(this.#Z(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#W(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#I({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#W(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.#z(t,n.value,n)}}set(e,t,n={}){let{status:r=i.metrics.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op=`set`,r.key=e,t!==void 0&&(r.value=t),r.cache=this);let a=this.#z(e,t,n);return r&&i.metrics.hasSubscribers&&i.metrics.publish(r),a}#z(e,t,n,r){let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:s=this.sizeCalculation,status:c}=n,l=this.#W(t);if(t===void 0)return c&&(c.set=`deleted`),this.delete(e),this;let{noUpdateTTL:u=this.noUpdateTTL}=n;c&&!l&&(c.value=t);let d=this.#F(e,t,n.size||0,s,c);if(this.maxEntrySize&&d>this.maxEntrySize)return this.#Z(e,`set`),c&&(c.set=`miss`,c.maxEntrySizeExceeded=!0),this;let f=this.#c===0?void 0:this.#u.get(e);if(f===void 0)f=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#B(!1):this.#c:this.#_.pop(),this.#d[f]=e,this.#f[f]=t,this.#u.set(e,f),this.#p[this.#g]=f,this.#m[f]=this.#g,this.#g=f,this.#c++,this.#P(f,d,c),c&&(c.set=`add`),u=!1,this.#E&&!l&&this.#r?.(t,e,`add`);else{this.#X(f);let n=this.#f[f];if(t!==n){if(!o){if(this.#W(n)){n!==r&&n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:i}=n;i!==void 0&&i!==t&&(this.#C&&this.#n?.(i,e,`set`),this.#T&&this.#v?.push([i,e,`set`]))}else this.#C&&this.#n?.(n,e,`set`),this.#T&&this.#v?.push([n,e,`set`])}if(this.#N(f),this.#P(f,d,c),this.#f[f]=t,!l){let r=n&&this.#W(n)?n.__staleWhileFetching:n,i=r===void 0?`add`:t===r?`update`:`replace`;c&&(c.set=i,r!==void 0&&(c.oldValue=r)),this.#E&&this.onInsert?.(t,e,i)}}else l||(c&&(c.set=`update`),this.#E&&this.onInsert?.(t,e,`update`))}if(i!==0&&!this.#x&&this.#D(),this.#x&&(u||this.#A(f,i,a),c&&this.#k(c,f)),!o&&this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#B(!0),this.#W(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}#B(e){let t=this.#h,n=this.#d[t],r=this.#f[t],i=this.#W(r);i&&r.__abortController.abort(Error(`evicted`));let a=i?r.__staleWhileFetching:r;return(this.#C||this.#T)&&a!==void 0&&(this.#C&&this.#n?.(a,n,`evict`),this.#T&&this.#v?.push([a,n,`evict`])),this.#N(t),this.#S?.[t]&&(clearTimeout(this.#S[t]),this.#S[t]=void 0),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{status:n=i.metrics.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`has`,n.key=e,n.cache=this);let r=this.#V(e,t);return i.metrics.hasSubscribers&&i.metrics.publish(n),r}#V(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#W(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#j(i))r&&(r.has=`stale`,this.#k(r,i));else return n&&this.#O(i),r&&(r.has=`hit`,this.#k(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{status:n=o()?{}:void 0}=t;n&&(n.op=`peek`,n.key=e,n.cache=this),t.status=n;let r=this.#H(e,t);return i.metrics.hasSubscribers&&i.metrics.publish(n),r}#H(e,t){let{status:n,allowStale:r=this.allowStale}=t,i=this.#u.get(e);if(i===void 0||!r&&this.#j(i)){n&&(n.peek=i===void 0?`miss`:`stale`);return}let a=this.#f[i],o=this.#W(a)?a.__staleWhileFetching:a;return n&&(o===void 0?n.peek=`miss`:(n.peek=`hit`,n.value=o)),o}#U(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#W(i))return i;let a=new AbortController,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0,l=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&r!==void 0);if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return u(a.signal.reason,l);let d=f,p=this.#f[t];return(p===f||p===void 0&&c&&i)&&(r===void 0?d.__staleWhileFetching===void 0?this.#Z(e,`fetch`):this.#f[t]=d.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.#z(e,r,s.options,d))),r},l=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),u(e,!1)),u=(r,i)=>{let{aborted:o}=a.signal,s=o&&n.allowStaleOnFetchAbort,c=s||n.allowStaleOnFetchRejection,l=c||n.noDeleteOnFetchRejection,u=f;if(this.#f[t]===f&&(!l||!i&&u.__staleWhileFetching===void 0?this.#Z(e,`fetch`):s||(this.#f[t]=u.__staleWhileFetching)),c)return n.status&&u.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),u.__staleWhileFetching;if(u.__returned===u)throw r},d=(t,r)=>{let o=this.#a?.(e,i,s);a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))}),o&&o instanceof Promise?o.then(e=>t(e===void 0?void 0:e),r):o!==void 0&&t(o)};n.status&&(n.status.fetchDispatched=!0);let f=new Promise(d).then(c,l),p=Object.assign(f,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.#z(e,p,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=p,p}#W(e){if(!this.#w)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof AbortController}fetch(e,t={}){let n=i.tracing.hasSubscribers,{status:r=o()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let a=this.#G(e,t);return r&&n&&(r.trace=!0,i.tracing.tracePromise(()=>a,r).catch(()=>{})),a}async#G(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(g&&(g.op=`fetch`,g.key=e,h&&(g.forceRefresh=!0),g.cache=this),!this.#w)return g&&(g.fetch=`get`),this.#J(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#U(e,y,v,m);return t.__returned=t}{let t=this.#f[y];if(this.#W(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#j(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#X(y),r&&this.#O(y),g&&this.#k(g,y),t;let a=this.#U(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}forceFetch(e,t={}){let n=i.tracing.hasSubscribers,{status:r=o()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let a=this.#K(e,t);return r&&n&&(r.trace=!0,i.tracing.tracePromise(()=>a,r).catch(()=>{})),a}async#K(e,t={}){let n=await this.#G(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let{status:n=i.metrics.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`memo`,n.key=e,t.context&&(n.context=t.context),n.cache=this);let r=this.#q(e,t);return n&&(n.value=r),i.metrics.hasSubscribers&&i.metrics.publish(n),r}#q(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,status:i,forceRefresh:a,...o}=t;i&&a&&(i.forceRefresh=!0);let s=this.#J(e,o),c=a||s===void 0;if(i&&(i.memo=c?`miss`:`hit`,c||(i.value=s)),!c)return s;let l=n(e,s,{options:o,context:r});return i&&(i.value=l),this.#z(e,l,o),l}get(e,t={}){let{status:n=i.metrics.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`get`,n.key=e,n.cache=this);let r=this.#J(e,t);return n&&(r!==void 0&&(n.value=r),i.metrics.hasSubscribers&&i.metrics.publish(n)),r}#J(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o===void 0){a&&(a.get=`miss`);return}let s=this.#f[o],c=this.#W(s);return a&&this.#k(a,o),this.#j(o)?c?(a&&(a.get=`stale-fetching`),n&&s.__staleWhileFetching!==void 0?(a&&(a.returnedStale=!0),s.__staleWhileFetching):void 0):(i||this.#Z(e,`expire`),a&&(a.get=`stale`),n?(a&&(a.returnedStale=!0),s):void 0):(a&&(a.get=c?`fetching`:`hit`),this.#X(o),r&&this.#O(o),c?s.__staleWhileFetching:s)}#Y(e,t){this.#m[t]=e,this.#p[e]=t}#X(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#Y(this.#m[e],this.#p[e]),this.#Y(this.#g,e),this.#g=e)}delete(e){return this.#Z(e,`delete`)}#Z(e,t){i.metrics.hasSubscribers&&i.metrics.publish({op:`delete`,delete:t,key:e,cache:this});let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0){if(this.#S?.[r]&&(clearTimeout(this.#S[r]),this.#S[r]=void 0),n=!0,this.#c===1)this.#Q(t);else{this.#N(r);let n=this.#f[r];if(this.#W(n)?n.__abortController.abort(Error(`deleted`)):(this.#C||this.#T)&&(this.#C&&this.#n?.(n,e,t),this.#T&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}}if(this.#T&&this.#v?.length){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return n}clear(){return this.#Q(`delete`)}#Q(e){for(let t of this.#L({allowStale:!0})){let n=this.#f[t];if(this.#W(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#C&&this.#n?.(n,r,e),this.#T&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b){this.#x.fill(0),this.#b.fill(0);for(let e of this.#S??[])e!==void 0&&clearTimeout(e);this.#S?.fill(void 0)}if(this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}})),ft=n(((e,t)=>{var n=(...e)=>e.every(e=>e)?e.join(``):``,r=e=>e?encodeURIComponent(e):``,i=e=>e.toLowerCase().replace(/^\W+/g,``).replace(/(?<!\W)\W+$/,``).replace(/\//g,``).replace(/\W+/g,`-`),a={sshtemplate:({domain:e,user:t,project:r,committish:i})=>`git@${e}:${t}/${r}.git${n(`#`,i)}`,sshurltemplate:({domain:e,user:t,project:r,committish:i})=>`git+ssh://git@${e}/${t}/${r}.git${n(`#`,i)}`,edittemplate:({domain:e,user:t,project:i,committish:a,editpath:o,path:s})=>`https://${e}/${t}/${i}${n(`/`,o,`/`,r(a||`HEAD`),`/`,s)}`,browsetemplate:({domain:e,user:t,project:i,committish:a,treepath:o})=>`https://${e}/${t}/${i}${n(`/`,o,`/`,r(a))}`,browsetreetemplate:({domain:e,user:t,project:i,committish:a,treepath:o,path:s,fragment:c,hashformat:l})=>`https://${e}/${t}/${i}/${o}/${r(a||`HEAD`)}/${s}${n(`#`,l(c||``))}`,browseblobtemplate:({domain:e,user:t,project:i,committish:a,blobpath:o,path:s,fragment:c,hashformat:l})=>`https://${e}/${t}/${i}/${o}/${r(a||`HEAD`)}/${s}${n(`#`,l(c||``))}`,docstemplate:({domain:e,user:t,project:i,treepath:a,committish:o})=>`https://${e}/${t}/${i}${n(`/`,a,`/`,r(o))}#readme`,httpstemplate:({auth:e,domain:t,user:r,project:i,committish:a})=>`git+https://${n(e,`@`)}${t}/${r}/${i}.git${n(`#`,a)}`,filetemplate:({domain:e,user:t,project:n,committish:i,path:a})=>`https://${e}/${t}/${n}/raw/${r(i||`HEAD`)}/${a}`,shortcuttemplate:({type:e,user:t,project:r,committish:i})=>`${e}:${t}/${r}${n(`#`,i)}`,pathtemplate:({user:e,project:t,committish:r})=>`${e}/${t}${n(`#`,r)}`,bugstemplate:({domain:e,user:t,project:n})=>`https://${e}/${t}/${n}/issues`,hashformat:i},o={};o.github={protocols:[`git:`,`http:`,`git+ssh:`,`git+https:`,`ssh:`,`https:`],domain:`github.com`,treepath:`tree`,blobpath:`blob`,editpath:`edit`,filetemplate:({auth:e,user:t,project:i,committish:a,path:o})=>`https://${n(e,`@`)}raw.githubusercontent.com/${t}/${i}/${r(a||`HEAD`)}/${o}`,gittemplate:({auth:e,domain:t,user:r,project:i,committish:a})=>`git://${n(e,`@`)}${t}/${r}/${i}.git${n(`#`,a)}`,tarballtemplate:({domain:e,user:t,project:n,committish:i})=>`https://codeload.${e}/${t}/${n}/tar.gz/${r(i||`HEAD`)}`,extract:e=>{let[,t,n,r,i]=e.pathname.split(`/`,5);if(!(r&&r!==`tree`)&&(r||(i=e.hash.slice(1)),n&&n.endsWith(`.git`)&&(n=n.slice(0,-4)),t&&n))return{user:t,project:n,committish:i}}},o.bitbucket={protocols:[`git+ssh:`,`git+https:`,`ssh:`,`https:`],domain:`bitbucket.org`,treepath:`src`,blobpath:`src`,editpath:`?mode=edit`,edittemplate:({domain:e,user:t,project:i,committish:a,treepath:o,path:s,editpath:c})=>`https://${e}/${t}/${i}${n(`/`,o,`/`,r(a||`HEAD`),`/`,s,c)}`,tarballtemplate:({domain:e,user:t,project:n,committish:i})=>`https://${e}/${t}/${n}/get/${r(i||`HEAD`)}.tar.gz`,extract:e=>{let[,t,n,r]=e.pathname.split(`/`,4);if(![`get`].includes(r)&&(n&&n.endsWith(`.git`)&&(n=n.slice(0,-4)),t&&n))return{user:t,project:n,committish:e.hash.slice(1)}}},o.gitlab={protocols:[`git+ssh:`,`git+https:`,`ssh:`,`https:`],domain:`gitlab.com`,treepath:`tree`,blobpath:`tree`,editpath:`-/edit`,tarballtemplate:({domain:e,user:t,project:n,committish:i})=>`https://${e}/api/v4/projects/${r(t+`/`+n)}/repository/archive.tar.gz?sha=${r(i||`HEAD`)}`,extract:e=>{let t=e.pathname.slice(1);if(t.includes(`/-/`)||t.includes(`/archive.tar.gz`))return;let n=t.split(`/`),r=n.pop();r.endsWith(`.git`)&&(r=r.slice(0,-4));let i=n.join(`/`);if(i&&r)return{user:i,project:r,committish:e.hash.slice(1)}}},o.gist={protocols:[`git:`,`git+ssh:`,`git+https:`,`ssh:`,`https:`],domain:`gist.github.com`,editpath:`edit`,sshtemplate:({domain:e,project:t,committish:r})=>`git@${e}:${t}.git${n(`#`,r)}`,sshurltemplate:({domain:e,project:t,committish:r})=>`git+ssh://git@${e}/${t}.git${n(`#`,r)}`,edittemplate:({domain:e,user:t,project:i,committish:a,editpath:o})=>`https://${e}/${t}/${i}${n(`/`,r(a))}/${o}`,browsetemplate:({domain:e,project:t,committish:i})=>`https://${e}/${t}${n(`/`,r(i))}`,browsetreetemplate:({domain:e,project:t,committish:i,path:a,hashformat:o})=>`https://${e}/${t}${n(`/`,r(i))}${n(`#`,o(a))}`,browseblobtemplate:({domain:e,project:t,committish:i,path:a,hashformat:o})=>`https://${e}/${t}${n(`/`,r(i))}${n(`#`,o(a))}`,docstemplate:({domain:e,project:t,committish:i})=>`https://${e}/${t}${n(`/`,r(i))}`,httpstemplate:({domain:e,project:t,committish:r})=>`git+https://${e}/${t}.git${n(`#`,r)}`,filetemplate:({user:e,project:t,committish:i,path:a})=>`https://gist.githubusercontent.com/${e}/${t}/raw${n(`/`,r(i))}/${a}`,shortcuttemplate:({type:e,project:t,committish:r})=>`${e}:${t}${n(`#`,r)}`,pathtemplate:({project:e,committish:t})=>`${e}${n(`#`,t)}`,bugstemplate:({domain:e,project:t})=>`https://${e}/${t}`,gittemplate:({domain:e,project:t,committish:r})=>`git://${e}/${t}.git${n(`#`,r)}`,tarballtemplate:({project:e,committish:t})=>`https://codeload.github.com/gist/${e}/tar.gz/${r(t||`HEAD`)}`,extract:e=>{let[,t,n,r]=e.pathname.split(`/`,4);if(r!==`raw`){if(!n){if(!t)return;n=t,t=null}return n.endsWith(`.git`)&&(n=n.slice(0,-4)),{user:t,project:n,committish:e.hash.slice(1)}}},hashformat:function(e){return e&&`file-`+i(e)}},o.sourcehut={protocols:[`git+ssh:`,`https:`],domain:`git.sr.ht`,treepath:`tree`,blobpath:`tree`,filetemplate:({domain:e,user:t,project:n,committish:i,path:a})=>`https://${e}/${t}/${n}/blob/${r(i)||`HEAD`}/${a}`,httpstemplate:({domain:e,user:t,project:r,committish:i})=>`https://${e}/${t}/${r}${n(`#`,i)}`,tarballtemplate:({domain:e,user:t,project:n,committish:i})=>`https://${e}/${t}/${n}/archive/${r(i)||`HEAD`}.tar.gz`,bugstemplate:()=>null,extract:e=>{let[,t,n,r]=e.pathname.split(`/`,4);if(![`archive`].includes(r)&&(n&&n.endsWith(`.git`)&&(n=n.slice(0,-4)),t&&n))return{user:t,project:n,committish:e.hash.slice(1)}}};for(let[e,t]of Object.entries(o))o[e]=Object.assign({},a,t);t.exports=o})),pt=n(((e,t)=>{var n=(e,t,n)=>{let r=e.indexOf(n);return e.lastIndexOf(t,r>-1?r:1/0)},r=e=>{try{return new URL(e)}catch{}},i=(e,t)=>{let n=e.indexOf(`:`),r=e.slice(0,n+1);if(Object.prototype.hasOwnProperty.call(t,r)||e.substr(n,3)===`://`)return e;let i=e.indexOf(`@`);return i>-1?i>n?`git+ssh://${e}`:e:`${e.slice(0,n+1)}//${e.slice(n+1)}`},a=e=>{let t=n(e,`@`,`#`),r=n(e,`:`,`#`);return r>t&&(e=e.slice(0,r)+`/`+e.slice(r+1)),n(e,`:`,`#`)===-1&&e.indexOf(`//`)===-1&&(e=`git+ssh://${e}`),e};t.exports=(e,t)=>{let n=t?i(e,t):e;return r(n)||r(a(n))}})),mt=n(((e,t)=>{var n=pt(),r=e=>{let t=e.indexOf(`#`),n=e.indexOf(`/`),r=e.indexOf(`/`,n+1),i=e.indexOf(`:`),a=/\s/.exec(e),o=e.indexOf(`@`),s=!a||t>-1&&a.index>t,c=o===-1||t>-1&&o>t,l=i===-1||t>-1&&i>t,u=r===-1||t>-1&&r>t,d=n>0,f=t>-1?e[t-1]!==`/`:!e.endsWith(`/`),p=!e.startsWith(`.`);return s&&d&&f&&p&&c&&l&&u};t.exports=(e,t,{gitHosts:i,protocols:a})=>{if(!e)return;let o=n(r(e)?`github:${e}`:e,a);if(!o)return;let s=i.byShortcut[o.protocol],c=i.byDomain[o.hostname.startsWith(`www.`)?o.hostname.slice(4):o.hostname],l=s||c;if(!l)return;let u=i[s||c],d=null;a[o.protocol]?.auth&&(o.username||o.password)&&(d=`${o.username}${o.password?`:`+o.password:``}`);let f=null,p=null,m=null,h=null;try{if(s){let e=o.pathname.startsWith(`/`)?o.pathname.slice(1):o.pathname,t=e.indexOf(`@`);t>-1&&(e=e.slice(t+1));let n=e.lastIndexOf(`/`);n>-1?(p=decodeURIComponent(e.slice(0,n)),p||=null,m=decodeURIComponent(e.slice(n+1))):m=decodeURIComponent(e),m.endsWith(`.git`)&&(m=m.slice(0,-4)),o.hash&&(f=decodeURIComponent(o.hash.slice(1))),h=`shortcut`}else{if(!u.protocols.includes(o.protocol))return;let e=u.extract(o);if(!e)return;p=e.user&&decodeURIComponent(e.user),m=decodeURIComponent(e.project),f=decodeURIComponent(e.committish),h=a[o.protocol]?.name||o.protocol.slice(0,-1)}}catch(e){if(e instanceof URIError)return;throw e}return[l,p,d,m,f,h,t]}})),ht=n(((e,t)=>{var{LRUCache:n}=dt(),r=ft(),i=mt(),a=pt(),o=new n({max:1e3});function s(e){try{let{protocol:t,hostname:n,pathname:r}=new URL(e);return n?`${/(?:git\+)http:$/.test(t)?`http:`:`https:`}//${n}${r.replace(/\.git$/,``)}`:null}catch{return null}}var c=class e{constructor(t,n,r,i,a,o,s={}){Object.assign(this,e.#e[t],{type:t,user:n,auth:r,project:i,committish:a,default:o,opts:s})}static#e={byShortcut:{},byDomain:{}};static#t={"git+ssh:":{name:`sshurl`},"ssh:":{name:`sshurl`},"git+https:":{name:`https`,auth:!0},"git:":{auth:!0},"http:":{auth:!0},"https:":{auth:!0},"git+http:":{auth:!0}};static addHost(t,n){e.#e[t]=n,e.#e.byDomain[n.domain]=t,e.#e.byShortcut[`${t}:`]=t,e.#t[`${t}:`]={name:t}}static fromUrl(t,n){if(typeof t!=`string`)return;let r=t+JSON.stringify(n||{});if(!o.has(r)){let a=i(t,n,{gitHosts:e.#e,protocols:e.#t});o.set(r,a?new e(...a):void 0)}return o.get(r)}static fromManifest(t,n={}){if(!t||typeof t!=`object`)return;let r=t.repository,i=r&&(typeof r==`string`?r:typeof r==`object`&&typeof r.url==`string`?r.url:null);if(!i)throw Error(`no repository`);let a=i&&e.fromUrl(i.replace(/^git\+/,``),n)||null;if(a)return a;let o=s(i);return e.fromUrl(o,n)||o}static parseUrl(e){return a(e)}#n(e,t){if(typeof e!=`function`)return null;let n={...this,...this.opts,...t};n.path||=``,n.path.startsWith(`/`)&&(n.path=n.path.slice(1)),n.noCommittish&&(n.committish=null);let r=e(n);return n.noGitPlus&&r.startsWith(`git+`)?r.slice(4):r}hash(){return this.committish?`#${this.committish}`:``}ssh(e){return this.#n(this.sshtemplate,e)}sshurl(e){return this.#n(this.sshurltemplate,e)}browse(e,...t){return typeof e==`string`?typeof t[0]==`string`?this.#n(this.browsetreetemplate,{...t[1],fragment:t[0],path:e}):this.#n(this.browsetreetemplate,{...t[0],path:e}):this.#n(this.browsetemplate,e)}browseFile(e,...t){return typeof t[0]==`string`?this.#n(this.browseblobtemplate,{...t[1],fragment:t[0],path:e}):this.#n(this.browseblobtemplate,{...t[0],path:e})}docs(e){return this.#n(this.docstemplate,e)}bugs(e){return this.#n(this.bugstemplate,e)}https(e){return this.#n(this.httpstemplate,e)}git(e){return this.#n(this.gittemplate,e)}shortcut(e){return this.#n(this.shortcuttemplate,e)}path(e){return this.#n(this.pathtemplate,e)}tarball(e){return this.#n(this.tarballtemplate,{...e,noCommittish:!1})}file(e,t){return this.#n(this.filetemplate,{...t,path:e})}edit(e,t){return this.#n(this.edittemplate,{...t,path:e})}getDefaultRepresentation(){return this.default}toString(e){return this.default&&typeof this[this.default]==`function`?this[this.default](e):this.sshurl(e)}};for(let[e,t]of Object.entries(r))c.addHost(e,t);t.exports=c}));function gt(e){let t=e.indexOf(`://`),n=e.startsWith(`git@`)?e.indexOf(`:`)+1:e.indexOf(`/`,t<0?0:t+3)+1;if(n<=0)return e;let r=e.slice(n).search(/[?#]/),i=r<0?e.length:n+r,a=e.indexOf(`@`,n);return a===n&&(a=e.indexOf(`@`,n+1)),a<=n||a===i-1||a>=i?e:t<0?e.slice(0,a):e.slice(0,a)+e.slice(i)}function _t(e){let t=e.split(/[?#]/,1)[0]??``;return t.includes(`\\`)||/(?:^|\/)(?:\.|%2e){1,2}(?:\/|$)/i.test(t)}function vt(e){let t,n,r=e.match(/^git@([^:]+):(.+)$/);if(r)t=r[1]??``,n=r[2]??``;else if(/^(?:https?|ssh|git):\/\//.test(e)){let r=URL.parse(e);if(!r)return null;t=r.hostname,n=r.pathname.replace(/^\/+/,``)}else{let r=e.indexOf(`/`);if(r<0||(t=e.slice(0,r),n=e.slice(r+1),!t.includes(`.`)&&t!==`localhost`))return null}return yt(t,n)}function yt(e,t){let n=xt(t);return bt(e)&&n?{type:`git`,host:e,path:n}:null}function bt(e){return!!e&&!e.includes(`/`)&&!e.includes(`\\`)&&e!==`.`&&e!==`..`}function xt(e){let t=e.replace(/\.git$/,``).replace(/^\/+/,``).split(`/`);return t.length<2||t.some(e=>!e||e===`.`||e===`..`||e.includes(`\\`))?null:t.join(`/`)}function St(e){let t=[e];!e.includes(`://`)&&!e.startsWith(`git@`)&&t.push(`https://${e}`);for(let e of t){let t=wt.default.fromUrl(e);if(!t)continue;let n=yt(t.domain||``,`${t.user}/${t.project}`);if(n)return n}return null}function Ct(e){let t=e.trim(),n=t.startsWith(`git:`),r=n?t.slice(4).trim():t;if(!n&&!/^(https?|ssh|git):\/\//i.test(r))return null;let i=gt(r);return _t(i)?null:St(i)??vt(i)}var wt;function Tt(){return(Tt=t((()=>{wt=e(ht(),1)})))()}function Et(e){let t=e.trim();if(!t)return;let n=Ct(`git:${t}`);if(!n)return;let r=n.path.split(`/`).filter(Boolean);if(!(!n.host||r.length<2))return`${n.host}/${r.join(`/`)}`.toLowerCase()}function Dt(){return(Dt=t((()=>{Tt()})))()}function Ot(e){return i(e?.cloudWorkers)?e.cloudWorkers:{}}function kt(e){let t=Ot(e??{}),n=i(t.projectProfiles)?t.projectProfiles:{};return Object.entries(n).flatMap(([e,t])=>typeof t==`string`?[{repository:e,profileId:t}]:[]).toSorted((e,t)=>e.repository.localeCompare(t.repository))}function At(e){let t=Ot(e),n=i(t.preparedPool)?t.preparedPool:{};return typeof n.maxTotal==`number`?String(n.maxTotal):``}function jt(e){let t=e.trim();return t&&(!/^\d+$/u.test(t)||!Number.isSafeInteger(Number(t)))?{error:`preparedPool`}:{patch:{cloudWorkers:{preparedPool:{maxTotal:t?Number(t):null}}},replacePaths:[]}}function Mt(e,t,n){let r=Et(t);if(!r||Et(`https://${r}`)!==r)return{error:`repository`};let a=Ot(e).profiles;return!i(a)||!Object.hasOwn(a,n)||!i(a[n])?{error:`repositoryProfile`}:{patch:{cloudWorkers:{projectProfiles:{[r]:n}}},replacePaths:[]}}function Nt(){return(Nt=t((()=>{Dt()})))()}var Pt;function Ft(){return(Ft=t((()=>{d(),h(),Pt=class{constructor(e){this.notify=e,this.state={busy:!1,error:null,notice:null}}update(e){Object.assign(this.state,e),this.notify()}async save(e,t,n){this.update({busy:!0,error:null,notice:null});try{let r=await e.patchFromSnapshot(e=>{let t=n.build(e);return`error`in t?{error:u(`cloudWorkersPage.errors.${t.error}`)}:{options:{raw:t.patch,...t.replacePaths?{replacePaths:t.replacePaths}:{},note:n.note,canDispatch:n.canDispatch}}});return t()?r?(this.update({notice:n.success()}),!0):(this.update({error:e.state.lastError??n.failed()}),!1):!1}catch(e){return t()&&this.update({error:g(e)}),!1}finally{t()&&this.update({busy:!1})}}}})))()}function It(e,t){let n=_(),r=oe(n.runtimeConfig),[i,a]=F(0,{ownedWrite:!0}),s=new Pt(()=>a(e=>e+1)),c=Promise.withResolvers();function l(){c.resolve(),c=Promise.withResolvers()}let u=Se({getGateway:()=>n.gateway,onIdentityChange:()=>{s.update({error:null,notice:null}),e()},onSnapshot:({snapshot:n})=>{n.phase===`connected`&&!o(n,`config.patch`,`operator.admin`)&&(u.invalidate(),l(),s.update({busy:!1,error:null,notice:null}),e()),t?.()},invalidateRequests:()=>{l(),s.update({busy:!1})}}),d=()=>(i(),s.state);ge(()=>{let e=n.router.subscribe(()=>{l(),a(e=>e+1)});return()=>{e(),c.resolve()}});let f=L(()=>(i(),u.snapshot,c)),p=L(()=>{let e=f().promise,[t,n]=ue(!1);return{retired:e,saving:t,setSaving:n}}),m=()=>p().saving()||d().busy,h=ye(function*(e,t){return e.retired===c.promise&&e.setSaving(!0),yield Promise.race([t,e.retired.then(()=>!1)])}),g=()=>o(u.snapshot,`config.patch`,`operator.admin`)&&!!r.read().state.configSnapshot?.hash&&!r.read().state.configSaving&&!m();return{gateway:u,runtime:r,state:d,busy:m,editable:g,loading:()=>r.read().state.configLoading,ensureLoaded:()=>n.runtimeConfig.ensureLoaded(),config:()=>ee(r.read().state.configSnapshot),update:e=>s.update(e),async save(e){let t=u.capture(),r=n.runtimeConfig;if(!t||!g())return!1;let i=()=>u.isCurrent(t)&&n.runtimeConfig===r,a=p(),c=s.save(r,i,{...e,canDispatch:()=>i()&&o(u.snapshot,`config.patch`,`operator.admin`)});return await Promise.resolve(),h(a,c)}}}function Lt(){return(Lt=t((()=>{B(),ne(),s(),w(),P(),Ce(),Ft()})))()}function Rt(e){let[t,n]=F(null,{ownedWrite:!0}),r=It(()=>n(null)),i=()=>e.inventory?.environments.filter(nt).length??0;async function a(){let e=t()??At(r.config());await r.save({build:()=>jt(e),note:`cloud environments: update pool cap`,failed:()=>b(`cloudWorkersPage.errors.saveFailed`),success:()=>(n(null),b(`cloudWorkersPage.settingsSaved`))})}return[G(Z,{get title(){return b(`cloudWorkersPage.environments.pool`,{count:String(i())})},get control(){return[(()=>{var i=zt();return i._$$input=e=>n(e.currentTarget.value),K(()=>({e:b(`cloudWorkersPage.environments.poolCap`),t:b(`cloudWorkersPage.preparedPoolHelp`),a:t()??At(r.config()),o:String(e.inventory?.preparedPool?.maxTotal??4),i:!r.editable()}),({e,t,a:n,o:r,i:a},o)=>{e!==o?.e&&W(i,`aria-label`,e),t!==o?.t&&W(i,`title`,t),i.value=n??``,r!==o?.o&&W(i,`placeholder`,r),a!==o?.i&&W(i,`disabled`,a)}),i})(),(()=>{var e=Bt();return e._$$click=()=>void a(),H(e,()=>b(`cloudWorkersPage.savePool`)),K(()=>!r.editable(),t=>{W(e,`disabled`,t)}),e})()]}}),G(z,{get when(){return r.state().error},get children(){return G(E,{tone:`warning`,role:`alert`,get children(){return r.state().error}})}})]}var zt,Bt;function Vt(){return(Vt=t((()=>{J(),B(),O(),Q(),y(),Nt(),Lt(),zt=Y(`<input class=settings-input type=number min=0 step=1>`),Bt=Y(`<button class="btn btn--sm"type=button>`),q([`input`,`click`])})))()}function Ht(){let[e,t]=he({value:null}),n=()=>{t(e=>{e.value=null})},r=It(n);r.ensureLoaded();let a=r.state,o=L(()=>{let e=r.config();for(let t of[`plugins`,`entries`,`crabbox`,`config`,`warmImages`])e=i(e)?e[t]:void 0;let t=i(e)?e:{};return{refreshAfter:typeof t.refreshAfter==`string`?t.refreshAfter:`24h`,retainUnused:typeof t.retainUnused==`string`?t.retainUnused:`14d`,keepPrevious:t.keepPrevious===1?`1`:`0`}}),s=()=>e.value??o(),c=()=>r.editable()&&!r.loading();function l(e){t(t=>{t.value??={...o()},Object.assign(t.value,e)}),r.update({error:null,notice:null})}async function u(){if(!c())return;let e={...s()};for(let[t,n]of[[`refreshAfter`,36e5],[`retainUnused`,864e5]])if(!/^[1-9][0-9]{0,7}(m|h|d)(?![\s\S])/.test(e[t])||T(e[t])<n){r.update({error:b(`cloudWorkersPage.snapshots.${t}Invalid`)});return}await r.save({build:()=>({patch:{plugins:{entries:{crabbox:{config:{warmImages:{refreshAfter:e.refreshAfter,retainUnused:e.retainUnused,keepPrevious:Number(e.keepPrevious)}}}}}}}),note:`cloud workers: update snapshot retention policy`,failed:()=>b(`cloudWorkersPage.snapshots.policySaveFailed`),success:()=>(n(),b(`cloudWorkersPage.snapshots.policySaved`))})}var d=Ut();return d._$owner=de(),H(d,G(X,{get title(){return b(`cloudWorkersPage.environments.retention`)},get children(){return[G(I,{each:[`refreshAfter`,`retainUnused`],children:e=>G(Z,{get title(){return b(`cloudWorkersPage.snapshots.${e}`)},get control(){var t=Wt();return t._$$input=t=>l({[e]:t.currentTarget.value}),K(()=>({e:b(`cloudWorkersPage.snapshots.${e}Help`),t:b(`cloudWorkersPage.snapshots.${e}`),a:s()[e],o:!c()}),({e,t:n,a:r,o:i},a)=>{e!==a?.e&&W(t,`title`,e),n!==a?.t&&W(t,`aria-label`,n),t.value=r??``,i!==a?.o&&W(t,`disabled`,i)}),t}})}),G(Ve,{get title(){return b(`cloudWorkersPage.snapshots.keepPrevious`)},get value(){return s().keepPrevious},get disabled(){return!c()},onChange:e=>l({keepPrevious:e===`1`?`1`:`0`}),get options(){return[{value:`0`,label:b(`cloudWorkersPage.snapshots.keepNone`)},{value:`1`,label:b(`cloudWorkersPage.snapshots.keepOne`)}]}}),G(Z,{title:``,get control(){var e=Gt();return e._$$click=()=>void u(),H(e,()=>b(`cloudWorkersPage.snapshots.savePolicy`)),K(()=>!c(),t=>{W(e,`disabled`,t)}),e}}),U(()=>U(()=>!!a().error)()?G(E,{tone:`warning`,role:`alert`,get children(){return a().error}}):null),U(()=>U(()=>!!a().notice)()?(()=>{var e=Kt();return H(e,()=>a().notice),e})():null)]}})),d}var Ut,Wt,Gt,Kt;function qt(){return(qt=t((()=>{J(),B(),te(),O(),Q(),xe(),y(),Be(),Lt(),Ut=Y(`<openclaw-cloud-worker-snapshot-policy class=cloud-environments__refresh style=display:contents>`,1),Wt=Y(`<input class=settings-input>`),Gt=Y(`<button class="btn btn--sm"type=button>`),Kt=Y(`<div class=callout role=status>`),ae(be),q([`input`,`click`])})))()}function Jt(e){return G(I,{get each(){return[e.repository]},children:()=>G(Yt,e)})}function Yt(e){let[t,n]=F(!1,{ownedWrite:!0}),r=It(()=>n(!1)),i=L(()=>We(r.config())),a=L(()=>i().find(t=>t.id===e.profileId)),o=()=>e.machineFacts||[a()?.backend,a()?.machineClass,a()?.target].filter(Boolean).join(` · `),s=()=>Et(`https://${e.repository}`)===e.repository?e.repository:null,c=()=>!!(s()&&r.editable());async function l(e){let t=s();t&&await r.save({build:n=>Mt(n,t,e),note:`cloud environments: change machine for ${t}`,failed:()=>b(`cloudWorkersPage.errors.saveFailed`),success:()=>(n(!1),b(`cloudWorkersPage.settingsSaved`))})}return G(X,{get title(){return b(`cloudWorkersPage.environments.machine`)},get children(){return[(()=>{var a=Qt(),u=a.firstChild;return H(u,()=>o()||e.profileId||`—`),H(a,G(z,{get when(){return t()},get fallback(){var e=$t(),t=e.firstChild;return t._$$click=()=>n(!0),H(t,()=>b(`cloudWorkersPage.environments.change`)),K(()=>({e:s()?void 0:b(`cloudWorkersPage.environments.identityUnavailable`),t:!c()}),({e:n,t:r},i)=>{n!==i?.e&&W(e,`title`,n),r!==i?.t&&W(t,`disabled`,r)}),e},get children(){return[(()=>{var t=Xt(),n=t.firstChild;return t.addEventListener(`change`,e=>void l(e.currentTarget.value)),H(n,()=>b(`cloudWorkersPage.selectProfile`)),H(t,G(I,{get each(){return i()},children:t=>(()=>{var n=en();return H(n,()=>t.id),K(()=>({e:t.id,t:e.defaultProfileId===t.id}),({e,t},r)=>{n.value=e,n.selected=t}),n})()}),null),K(()=>({e:b(`cloudWorkersPage.repositoryProfile`),t:e.defaultProfileId??``,a:!c()}),({e,t:n,a:r},i)=>{e!==i?.e&&W(t,`aria-label`,e),V(t,`value`,n),r!==i?.a&&W(t,`disabled`,r)}),t})(),(()=>{var e=Zt();return e._$$click=()=>n(!1),H(e,()=>b(`common.cancel`)),K(()=>r.busy(),t=>{W(e,`disabled`,t)}),e})()]}}),null),K(()=>e.profileId,e=>{W(u,`title`,e)}),a})(),G(z,{get when(){return r.state().error},get children(){return G(E,{tone:`warning`,role:`alert`,get children(){return r.state().error}})}})]}})}var Xt,Zt,Qt,$t,en;function tn(){return(tn=t((()=>{J(),B(),Dt(),O(),Q(),y(),$e(),Nt(),Lt(),Xt=Y(`<select class=settings-select><option value disabled>`),Zt=Y(`<button type=button class="btn btn--sm">`),Qt=Y(`<div class=cloud-environments__machine><span>`),$t=Y(`<span><button type=button class="btn btn--sm">`),en=Y(`<option>`),q([`click`])})))()}function nn(e){let t=()=>{let t=e.image,n=e.busy||!!(t.capture||t.retirement),r=[];return t.checkpointId&&e.canCall(`crabbox.images.pin`)&&r.push({id:`pin`,label:b(`cloudWorkersPage.snapshots.${t.pinned?`unpin`:`pin`}`),disabled:n}),t.previous&&e.canCall(`crabbox.images.pin`)&&r.push({id:`pinPrevious`,label:b(t.previous.pinned?`cloudWorkersPage.environments.unpinPrevious`:`cloudWorkersPage.environments.pinPrevious`),disabled:n}),t.previous&&e.canCall(`crabbox.images.rollback`)&&r.push({id:`rollback`,label:b(`cloudWorkersPage.snapshots.rollback`),disabled:n}),t.checkpointId&&e.canCall(`crabbox.images.delete`)&&r.push({id:`delete`,label:b(`common.delete`),disabled:e.busy||!!e.deleteReason(t),variant:`danger`,attributes:{title:e.deleteReason(t)??void 0}}),r};return G(z,{get when(){return t().length},get children(){return G(A,{get id(){return`cloud-environment-actions-${e.image.profileKey}`},get label(){return b(`cloudWorkersPage.environments.actions`)},trigger:`⋯`,triggerClass:`btn btn--sm`,get items(){return t()},onSelect:t=>{let n=e.image;t.id===`pinPrevious`?e.onMutate(n,`pin`,!0):(t.id===`pin`||t.id===`delete`||t.id===`rollback`)&&e.onMutate(n,t.id,t.id===`rollback`)}})}})}function rn(e){var t=cn(),n=t.firstChild,r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=n.nextSibling,l=c.nextSibling,u=l.nextSibling;return H(r,G(z,{get when(){return e.label},children:e=>(()=>{var t=ln();return H(t,e),t})()}),i),H(i,()=>b(`cloudWorkersPage.environments.${ut(e.image)}`)),H(r,G(z,{get when(){return e.image.baseCommit},children:e=>(()=>{var t=un();return H(t,()=>e().slice(0,8)),t})()}),a),H(r,G(z,{get when(){return e.image.createdAtMs},children:e=>(()=>{var t=dn();return H(t,()=>b(`cloudWorkersPage.environments.built`,{age:j(e())})),t})()}),o),H(r,G(z,{get when(){return e.image.lastDemandAtMs},children:e=>(()=>{var t=dn();return H(t,()=>b(`cloudWorkersPage.snapshots.lastUsed`,{age:j(e())})),t})()}),s),H(n,G(z,{get when(){return e.actions},get children(){return G(nn,e)}}),null),H(t,G(z,{get when(){return e.image.captureUnsupported},children:e=>(()=>{var t=fn();return H(t,()=>e().message),t})()}),c),H(t,G(z,{get when(){return e.image.retirement},children:e=>G(E,{tone:`warning`,role:`status`,get children(){return b(`cloudWorkersPage.snapshots.retirementHint`,{checkpoint:e().checkpointId})}})}),l),H(t,G(z,{get when(){return e.image.capture?.phase===`uncertain`},get children(){var t=sn(),n=t.firstChild,r=n.nextSibling;return H(n,()=>b(`cloudWorkersPage.snapshots.uncertain`)),r._$$click=()=>e.onRecover(e.image),H(r,()=>b(`cloudWorkersPage.snapshots.recover`)),K(()=>e.busy||!e.canCall(`crabbox.images.recover`),e=>{W(r,`disabled`,e)}),t}}),u),K(()=>e.image.profileId??e.image.profileKey,e=>{W(t,`aria-label`,e)}),t}function an(e){let t=()=>e.environment.worker?.state===`failed`,n=()=>e.environment.worker?.state===`orphaned`,r=()=>{let t=e.environment.worker;if(t?.state===`ready`&&rt(e.environment))return b(`cloudWorkersPage.environments.attention`);let n=t?.state===`ready`&&t.destroyRequestedAtMs!==void 0?`destroying`:t?.state;return b(`cloudWorkersPage.snapshots.buildStates.${n}`)};return G(Z,{get title(){return`${e.label?`${e.label} · `:``}${r()}`},get description(){return e.environment.worker?.error},get control(){return G(z,{get when(){return U(()=>!n())()&&e.canCall(`environments.destroy`)},get children(){var n=pn();return n._$$click=()=>e.onDestroy(e.environment,t()),H(n,()=>b(t()?`cloudWorkersPage.snapshots.dismiss`:`common.cancel`)),K(()=>({e:e.destroying,t:`${b(t()?`cloudWorkersPage.snapshots.dismiss`:`common.cancel`)}: ${e.environment.id}`}),({e,t},r)=>{e!==r?.e&&W(n,`disabled`,e),t!==r?.t&&W(n,`aria-label`,t)}),n}})}})}function on(e){let t=L(()=>st(e.environment)),n=()=>e.environment.defaultProfile??t()?.profileId??e.environment.workers[0]?.worker?.profileId,r=L(()=>e.profiles.find(e=>e.id===n())),i=()=>t()?.projectRoot?!e.canCall(`environments.prepare`)||r()?.warmImages!==`on`?b(`cloudWorkersPage.snapshots.invalidProfile`):void 0:b(`cloudWorkersPage.environments.localOnly`),a=L(()=>{let t=e.environment.defaultProfile;return e.environment.images.toSorted((e,n)=>Number(n.profileId===t)-Number(e.profileId===t)||(e.profileId??e.profileKey).localeCompare(n.profileId??n.profileKey)||(n.createdAtMs??0)-(e.createdAtMs??0))}),o=L(()=>e.environment.images.toSorted((e,t)=>(t.recipePreparationAtMs??0)-(e.recipePreparationAtMs??0)).find(e=>e.recipePreparation)?.recipePreparation),s=L(()=>{let e=o()?.phaseDurationsMs;return[`retainedGit`,`retainedManifest`,`inspection`,`seedPreparation`,`seedTransfer`,`seedVerification`,`seedCheckout`,`seedManifest`,`gitUpdate`,`toolchainPreparation`,`onCreate`,`updateContent`,`detectedInstall`,`preparedManifest`].flatMap(t=>e?.[t]===void 0?[]:[{name:t,durationMs:e[t]}])}),c=()=>Math.max(...s().map(e=>e.durationMs));var l=gn(),u=l.firstChild,d=u.firstChild,f=d.nextSibling,p=f.firstChild,m=p.firstChild,h=u.nextSibling,g=h.nextSibling,_=g.nextSibling;return H(d,()=>e.environment.label),m._$$click=()=>{let r=t(),i=n();i&&r?.projectRoot&&e.onRebuild(i,r.projectRoot)},H(m,()=>b(`cloudWorkersPage.snapshots.rebuild`)),H(f,G(z,{get when(){return a().length===1},get children(){return G(I,{get each(){return a()},keyed:e=>e.profileKey,children:t=>G(nn,R(e,{get image(){return t()}}))})}}),null),H(l,G(z,{get when(){return e.snapshotsKnown||e.environment.workers.some(it)},get children(){return G(X,{get title(){return b(`cloudWorkersPage.environments.snapshot`)},get children(){return[G(I,{get each(){return a()},keyed:e=>e.profileKey,get fallback(){return U(()=>!!e.snapshotsKnown)()?(()=>{var e=_n();return H(e,()=>b(`cloudWorkersPage.environments.coldOnly`)),e})():void 0},children:t=>G(rn,R(e,{get image(){return t()},get label(){return U(()=>a().length>1)()?t().profileId??t().profileKey:void 0},get actions(){return a().length>1}}))}),G(I,{get each(){return e.environment.workers.filter(it)},keyed:e=>e.id,children:t=>G(an,{get environment(){return t()},get destroying(){return e.destroying},get canCall(){return e.canCall},get onDestroy(){return e.onDestroy}})})]}})}}),h),H(l,G(X,{get title(){return b(`cloudWorkersPage.environments.setup`)},get children(){return[(()=>{var e=mn();return H(e,(()=>{var e=U(()=>o()?.source===`script`);return()=>e()?vn():U(()=>o()?.source===`devcontainer`)()?b(`cloudWorkersPage.environments.devcontainer`):U(()=>o()?.source===`detected`)()?b(`cloudWorkersPage.environments.detected`):`—`})()),K(()=>[o()?.note,o()?.ignoredPropertiesNote].filter(Boolean).join(`
`)||void 0,t=>{W(e,`title`,t)}),e})(),G(z,{get when(){return s().length},get children(){var e=hn();return H(e,G(I,{get each(){return s()},children:e=>(()=>{var t=yn(),n=t.firstChild,r=n.nextSibling;return H(n,()=>b(`cloudWorkersPage.environments.phases.${e.name}`)),H(r,()=>M(e.durationMs)),K(()=>e.durationMs===c(),e=>{t.classList.toggle(`cloud-environments__step--longest`,e)}),t})()})),e}}),G(I,{get each(){return a()},keyed:e=>e.profileKey,children:e=>G(z,{get when(){return e().recipePreparation?.failure},children:t=>G(E,{tone:`warning`,role:`alert`,get children(){return[G(z,{get when(){return a().length>1},get children(){var t=ln();return H(t,()=>e().profileId??e().profileKey),t}}),(()=>{var e=bn();return H(e,()=>t().reason),e})(),G(z,{get when(){return t().outputTail},children:e=>(()=>{var t=xn();return H(t,e),t})()})]}})})})]}}),g),H(l,G(Jt,{get repository(){return e.environment.label},get profileId(){return n()},get defaultProfileId(){return e.environment.defaultProfile},get machineFacts(){return[`backend`,`machineClass`,`os`].map(e=>t()?.profileId===n()?t()?.[e]??r()?.[e]:r()?.[e]).filter(Boolean).join(` · `)}}),_),K(()=>({e:e.environment.label,t:e.snapshotsKnown?i():void 0,a:e.busy||!!i()}),({e,t,a:n},r)=>{e!==r?.e&&W(l,`aria-label`,e),t!==r?.t&&W(p,`title`,t),n!==r?.a&&W(m,`disabled`,n)}),l}var sn,cn,ln,un,dn,fn,pn,mn,hn,gn,_n,vn,yn,bn,xn;function Sn(){return(Sn=t((()=>{J(),B(),O(),ie(),Q(),S(),D(),y(),tn(),sn=Y(`<div class=cloud-environments__recovery><span></span><button class="btn btn--sm"type=button>`),cn=Y(`<div class=cloud-environments__snapshot role=group><div class=cloud-environments__snapshot-summary><div class=cloud-environments__facts><span></span><!><!><!></div></div><!><!><!>`),ln=Y(`<strong>`),un=Y(`<code>`),dn=Y(`<span>`),fn=Y(`<p class=muted>`),pn=Y(`<button class="btn btn--sm"type=button>`),mn=Y(`<span class=cloud-environments__source>`),hn=Y(`<ol class=cloud-environments__steps>`),gn=Y(`<section class=cloud-environments__sheet><header class=cloud-environments__header><h2></h2><div class=cloud-environments__actions><span><button class="btn btn--sm"type=button></button></span></div></header><!><!><!>`),_n=Y(`<div class=cloud-environments__facts>`),vn=Y(`<code>.openclaw/worktree-setup.sh`),yn=Y(`<li class=cloud-environments__step><span></span><span>`),bn=Y(`<p>`),xn=Y(`<pre class=cloud-environments__output>`),q([`click`])})))()}function Cn(e){let t=_(),n=oe(t.runtimeConfig),[r,i]=F(null,{ownedWrite:!0}),[a,s]=he({result:null,inventory:null,initialInventorySettled:!1}),[l,u]=F(),d=L(()=>l()?.promise.then(()=>!1)??!1,{loadingValue:!0}),h=()=>pe(d)||le(d),[v,y]=F(null),x={},S=Promise.withResolvers(),[w,T]=F(null),te=L(()=>w()?.then(()=>null)??null);function D(e){T(()=>e),e.catch(()=>{})}let O=new Set,k=!1,A,ne=C(()=>void q(),1e4),M,N=null;function ie(){i(null),O.clear(),s(e=>{e.inventory=null,e.result=null})}function ae(){S.resolve(),S=Promise.withResolvers(),k=!1,A=void 0,delete x.preparing,delete x.image,delete x.destroying,T(null),ne.cancel(),u(void 0),y(null),N?.abort()}let P=Se({getGateway:()=>t.gateway,onIdentityChange:ie,onSnapshot:({snapshot:e})=>{e.phase===`connected`&&!o(e,`environments.list`,`operator.admin`)&&(P.invalidate(),ae(),ie()),me()},invalidateRequests:ae,ensureInitialData:()=>queueMicrotask(()=>void q()),onPageActivation:()=>void q()}),se=L(()=>P.epoch),R=L(()=>{let e=se(),[t,n]=ue(!1),[r,i]=ue(!1),[a,o]=ue(!1);return{epoch:e,preparing:{read:t,write:n},image:{read:r,write:i},destroying:{read:a,write:o}}}),de=ye(function*(e,t,n,r){e.epoch===P.readEpoch()&&e[t].write(!0),yield Promise.race([n,r])});function me(){let e=[t.runtimeConfig.state.configSnapshot?.appliedConfigHash,o(t.gateway.snapshot,`crabbox.images.list`,`operator.admin`)],n=M?.some((t,n)=>t!==e[n]);M=e,n&&queueMicrotask(()=>void q())}ge(()=>{let e=n.subscribe(me);return me(),()=>{e(),N?.abort()}});let B=e=>o(P.snapshot,e,`operator.admin`),V=e=>o(t.gateway.snapshot,e,`operator.admin`);async function _e(e){let t=new AbortController;N=t;let n=await ce({...e,signal:t.signal});return N===t&&(N=null),n}function q(){let e=P.capture();if(A){k=!0;return}if(!e||!V(`environments.list`)||document.visibilityState===`hidden`)return;let t={};A=t;let n=(async()=>{try{let t=await e.client.request(`environments.list`,{includePreparedDetails:!0});if(!P.isCurrent(e))return;s(e=>{e.initialInventorySettled=!0,e.inventory={...t,environments:t.environments.filter(e=>!O.has(e.id))}}),t.environments.some(e=>at(e)&&[`failed`,`orphaned`].includes(e.worker?.state??``)&&!O.has(e.id))&&y(null);let n=V(`crabbox.images.list`)?await e.client.request(`crabbox.images.list`,{}):null;P.isCurrent(e)&&(s(e=>{e.result=n}),n?.images.some(e=>e.recipePreparation?.failure)&&y(null))}catch(t){if(P.isCurrent(e))throw s(e=>{e.initialInventorySettled=!0}),t}finally{P.isCurrent(e)&&A===t&&(A=void 0,ne.cancel(),queueMicrotask(()=>{P.isCurrent(e)&&(k?(k=!1,q()):(a.inventory?.environments.some(e=>at(e)&&[`requested`,`provisioning`,`bootstrapping`,`ready`].includes(e.worker?.state??``))||a.result?.images.some(e=>e.capture&&e.capture.phase!==`uncertain`))&&ne.schedule())}))}})(),r=n.catch(()=>{});return u({promise:r}),D(n),r}function J(e,t){let n=P.capture();n&&!x.preparing&&V(`environments.prepare`)&&(!a.result?.profiles.some(t=>t.id===e&&t.warmImages===`on`)||!t?D(Promise.reject(Error(f.t(`cloudWorkersPage.snapshots.selectBuildInputs`)))):(y(null),we(n,`preparing`,async()=>{let r=await n.client.request(`environments.prepare`,{profileId:e,projectPath:t});P.isCurrent(n)&&(y(f.t(`cloudWorkersPage.snapshots.${r.reused?`buildReused`:`buildStarted`}`)),await q())})))}async function Y(e,t){let n=P.capture(),r=e.id;n&&!x.destroying&&!N&&V(`environments.destroy`)&&await _e({title:f.t(`cloudWorkersPage.snapshots.${t?`dismissBuild`:`cancelBuildTitle`}`),message:f.t(`cloudWorkersPage.snapshots.${t?`dismissBuildMessage`:`cancelBuildMessage`}`),details:r,confirmLabel:f.t(`cloudWorkersPage.snapshots.${t?`dismiss`:`cancelBuild`}`),danger:!t})&&P.isCurrent(n)&&V(`environments.destroy`)&&(y(null),await we(n,`destroying`,async()=>{await n.client.request(`environments.destroy`,{environmentId:r}),P.isCurrent(n)&&(t&&(O.add(r),s(e=>{e.inventory&&(e.inventory.environments=e.inventory.environments.filter(e=>e.id!==r))})),y(f.t(`cloudWorkersPage.snapshots.${t?`buildDismissed`:`buildCancelled`}`)),await q())}))}async function be(e){let t=P.capture(),n=e.capture?.selector;t&&n&&e.capture?.phase===`uncertain`&&!x.image&&!N&&V(`crabbox.images.recover`)&&await _e({title:f.t(`cloudWorkersPage.snapshots.recoverTitle`),message:f.t(`cloudWorkersPage.snapshots.recoverMessage`),details:n,confirmLabel:f.t(`cloudWorkersPage.snapshots.recover`),requiredAcknowledgement:f.t(`cloudWorkersPage.snapshots.acknowledgement`)})&&(!P.isCurrent(t)||!V(`crabbox.images.recover`)?D(Promise.reject(Error(f.t(`cloudWorkersPage.snapshots.recoveryChanged`)))):(y(null),await we(t,`recovering`,async()=>{await t.client.request(`crabbox.images.recover`,{selector:n,acknowledgeProviderCleanup:!0}),P.isCurrent(t)&&(y(f.t(`cloudWorkersPage.snapshots.recovered`)),await q())})))}function xe(e){return e.pinned?b(`cloudWorkersPage.snapshots.deletePinned`):e.held?b(`cloudWorkersPage.snapshots.deleteHeld`):e.capture?b(`cloudWorkersPage.snapshots.deleteCapturing`):null}function Ce(e,t,n=!1){let r=P.capture(),i=n?e.previous:e,a=i?.checkpointId,o=`crabbox.images.${t}`;r&&i&&a&&!x.image&&!A&&V(o)&&(t===`delete`&&xe(e)||t!==`delete`&&(e.capture||e.retirement)||we(r,`mutating`,async()=>{if(t!==`pin`&&!await _e({title:f.t(`cloudWorkersPage.snapshots.${t}Title`),message:f.t(`cloudWorkersPage.snapshots.${t}Message`),details:a,confirmLabel:f.t(`cloudWorkersPage.snapshots.${t}`),danger:t===`delete`})||!P.isCurrent(r)||!V(o))return;let e=null;t===`delete`?(await r.client.request(o,{checkpointId:a})).status===`retiring`&&(e=f.t(`cloudWorkersPage.snapshots.deletionRetiring`)):await r.client.request(o,{checkpointId:a,...t===`pin`?{pinned:!i.pinned}:{}}),P.isCurrent(r)&&(y(e),await q())}))}async function we(e,t,n){let r=t===`mutating`||t===`recovering`?`image`:t;if(x[r])return;let i=R(),a=S.promise;x[r]=e;let o=(async()=>{try{await n()}catch(n){if(P.isCurrent(e)){if(t===`mutating`)re({severity:`error`,message:g(n)});else{let e=n instanceof m?c(n):null,r=t===`preparing`&&e?Dn.get(e):void 0;throw new p(r?f.t(`cloudWorkersPage.snapshots.${r}`):g(n),{cause:n})}}}finally{x[r]===e&&delete x[r]}})(),s=o.catch(()=>{});return t!==`mutating`&&D(o),await new Promise(e=>{setTimeout(e,0)}),x[r]===e&&P.isCurrent(e)&&await de(i,r,s,a),s}let Te=()=>a.result!==null||P.connected&&!B(`crabbox.images.list`),ke=L(()=>ot(a.result?.images??[],a.inventory,kt(ee(n.read().state.configSnapshot)))),Ae=L(()=>(a.result?.images??[]).filter(e=>!e.projectKey&&!e.projectLabel&&!e.projectRoot).toSorted((e,t)=>(e.profileId??e.profileKey).localeCompare(t.profileId??t.profileKey))),je=L(()=>(a.inventory?.environments??[]).filter(e=>at(e)&&!e.preparation?.details?.project?.label&&it(e))),Q=L(()=>ke().find(e=>e.key===r())??ke()[0]);return G(z,{get when(){return!B(`environments.list`)||a.initialInventorySettled},get fallback(){return G(Oe,{get children(){return G(De,{get message(){return b(`common.loading`)}})}})},get children(){return[G(Oe,{get children(){return G(z,{get when(){return B(`environments.list`)||a.inventory!==null},get fallback(){return U(()=>!!P.connected)()?G(et,{}):void 0},get children(){return[G(ve,{get on(){return w()},get children(){return G(fe,{fallback:e=>G(E,{tone:`warning`,role:`alert`,get children(){return g(e())}}),get children(){return te()}})}}),G(z,{get when(){return v()},get children(){var e=wn();return H(e,v),e}}),G(z,{get when(){return ke().length},get fallback(){return U(()=>!!a.inventory)()?G(De,{get message(){return[U(()=>b(`cloudWorkersPage.environments.empty`)),` `,G(Ee,{url:`https://docs.openclaw.ai/gateway/cloud-workers`,get children(){return b(`cloudWorkersPage.environments.docs`)}})]}}):a.inventory},get children(){var e=Tn(),t=e.firstChild;return H(t,G(I,{get each(){return ke()},keyed:e=>e.key,children:e=>{let t=()=>lt(e(),Te()),n=()=>ct(e());var r=En(),a=r.firstChild,o=a.nextSibling,s=o.firstChild,c=s.nextSibling;return r._$$click=()=>i(e().key),H(a,()=>e().label),H(o,(()=>{var e=U(()=>!!t());return()=>e()?b(`cloudWorkersPage.environments.${t()}`):null})(),s),H(o,(()=>{var e=U(()=>t()===`ready`&&n()!==void 0);return()=>e()?` · ${j(n())}`:``})(),c),K(()=>({e:Q()?.key===e().key,t:Q()?.key===e().key?`true`:`false`}),({e,t},n)=>{e!==n?.e&&r.classList.toggle(`cloud-environments__row--selected`,e),t!==n?.t&&W(r,`aria-pressed`,t)}),r}})),H(e,G(z,{get when(){return Q()},children:e=>G(on,{get environment(){return e()},get profiles(){return a.result?.profiles??[]},get snapshotsKnown(){return Te()},get busy(){return R().image.read()||R().preparing.read()||h()},canCall:B,deleteReason:xe,onRebuild:J,onMutate:Ce,onRecover:e=>void be(e),onDestroy:(e,t)=>void Y(e,t),get destroying(){return R().destroying.read()}})}),null),K(()=>b(`cloudWorkersPage.environments.repositories`),e=>{W(t,`aria-label`,e)}),e}})]}})}}),G(Oe,{get children(){return G(Re,{sections:!0,get title(){return b(`cloudWorkersPage.environments.advanced`)},get children(){return[U(()=>e.machines()),G(Rt,{get inventory(){return a.inventory}}),G(Ht,{}),G(z,{get when(){return Ae().length||a.result?.legacyLeases.length||je().length},get children(){return G(X,{get title(){return b(`cloudWorkersPage.environments.machineImages`)},get children(){return[G(I,{get each(){return Ae()},keyed:e=>e.profileKey,children:e=>G(rn,{get image(){return e()},get label(){return e().profileId??e().profileKey},actions:!0,get busy(){return R().image.read()||h()},canCall:B,deleteReason:xe,onMutate:Ce,onRecover:e=>void be(e)})}),G(I,{get each(){return je()},keyed:e=>e.id,children:e=>G(an,{get environment(){return e()},get label(){return e().worker?.profileId??e().id},get destroying(){return R().destroying.read()},canCall:B,onDestroy:(e,t)=>void Y(e,t)})}),G(I,{get each(){return a.result?.legacyLeases??[]},keyed:e=>e.leaseId,children:e=>G(Z,{get title(){return e().leaseId},get description(){return e().recoveryHint}})})]}})}})]}})}})]}})}var wn,Tn,En,Dn;function On(){return(On=t((()=>{J(),B(),l(),se(),O(),ze(),Q(),d(),xe(),ne(),h(),D(),s(),w(),P(),Ce(),y(),N(),k(),tt(),Vt(),Nt(),qt(),Sn(),wn=Y(`<div class=callout role=status>`),Tn=Y(`<div class=cloud-environments><div class=cloud-environments__list>`),En=Y(`<button type=button class=cloud-environments__row><span></span><span class=cloud-environments__status><!><!>`),ae(be),Dn=new Map([[`capacity`,`capacity`],[`invalid_project`,`invalidProject`],[`invalid_profile`,`invalidProfile`],[`profile_not_found`,`invalidProfile`]]),q([`click`])})))()}function kn(){let e=_(),[t,n]=he({editor:null,draft:Ge()}),r=It(y,x),{gateway:i,runtime:s,state:c,busy:l}=r,[u,d]=F(),[f,p]=F(null),m=L(()=>f()?.promise.then(()=>null)??null),h,v;function y(){v?.abort(),n(e=>{e.editor=null,e.draft=Ge()}),d(void 0),p(null)}r.ensureLoaded();function ee(){let t=e.gateway.snapshot;return[t.client,t.phase,i.readEpoch(),e.runtimeConfig.state.configSnapshot?.appliedConfigHash]}function x(){let t=ee();if(h?.every((e,n)=>e===t[n]))return;h=t,v?.abort();let n=t[3],r=v=new AbortController;queueMicrotask(()=>{if(r.signal.aborted)return;let t=i.capture();if(!t||!o(i.snapshot,`environments.list`,`operator.admin`)){i.connected&&d(void 0),p(null);return}let a=t.client.request(`environments.list`,{projection:`profiles`},{signal:r.signal}).then(a=>{!r.signal.aborted&&i.isCurrent(t)&&e.runtimeConfig.state.configSnapshot?.appliedConfigHash===n&&d(new Map((a.profiles??[]).map(e=>[e.id,e])))},e=>{if(!r.signal.aborted&&i.isCurrent(t))throw e});p({promise:a}),a.catch(()=>void 0)})}ge(()=>{let e=s.subscribe(x);return x(),()=>{e(),v?.abort()}});let S=r.config,C=L(()=>We(S()));function w(){return o(i.snapshot,`config.patch`,`operator.admin`)}function T(){let e=s.read().state;return!(!w()||!e.configSnapshot?.hash||e.configLoading||e.configSaving||c().busy)}function te(t){T()&&(t&&(t.providerId!==`crabbox`||!t.machineClass)?e.navigate(`advanced`,{search:`?section=cloudWorkers`}):(n(e=>{e.editor=t?{kind:`edit`,profileId:t.id}:{kind:`add`},e.draft=Ge(t)}),r.update({error:null,notice:null})))}function D(){c().busy||(n(e=>{e.editor=null}),r.update({error:null}))}function O(e){n(t=>{Object.assign(t.draft,e)}),r.update({error:null})}async function k(e){let i=t.editor?.kind===`edit`?t.editor.profileId:null,a=S();if(!t.editor||!a||!T())return;let o=qe(e,Object.fromEntries(We(a).map(e=>[e.id,!0])),i);if(o){r.update({error:b(`cloudWorkersPage.errors.${o}`)});return}let s=i??e.id;await r.save({build:t=>Je(t,e,i),note:`cloud workers: ${i?`update`:`add`} ${s}`,failed:()=>b(`cloudWorkersPage.errors.saveFailed`),success:()=>(n(e=>{e.editor=null}),b(`cloudWorkersPage.profileSaved`))})}async function A(a){let o=e.gateway,s=o.snapshot.client,c=o.connection.gatewayUrl,l=e.runtimeConfig;if(!T()||!await ce({title:b(`cloudWorkersPage.deleteTitle`),message:b(`cloudWorkersPage.deleteConfirm`,{profile:a.id}),confirmLabel:b(`common.delete`),danger:!0}))return;let u=i.capture();!u||u.client!==s||e.gateway!==o||o.connection.gatewayUrl!==c||e.runtimeConfig!==l||!T()?r.update({error:b(`cloudWorkersPage.errors.deleteFailed`)}):await r.save({build:e=>Ye(e,a.id),note:`cloud workers: delete ${a.id}`,failed:()=>b(`cloudWorkersPage.errors.deleteFailed`),success:()=>(t.editor?.kind===`edit`&&t.editor.profileId===a.id&&n(e=>{e.editor=null}),b(`cloudWorkersPage.settingsSaved`))})}function j(e){return e.providerId===`crabbox`?[b(`cloudWorkersPage.backendFact`,{backend:e.backend||b(`common.unknown`)}),b(`cloudWorkersPage.classFact`,{value:e.machineClass||b(`common.unknown`)}),...e.target&&e.target!==`linux`?[b(`cloudWorkersPage.operatingSystemFact`,{value:u()?.get(e.id)?.operatingSystems?.find(t=>t.id===e.target)?.label??e.target})]:[],b(`cloudWorkersPage.ttlFact`,{value:e.ttl||b(`common.unknown`)}),b(`cloudWorkersPage.idleFact`,{value:e.idleTimeout||b(`common.unknown`)}),b(`cloudWorkersPage.desktopFact`,{value:e.desktop?b(`common.enabled`):b(`common.disabled`)})].join(` · `):b(`cloudWorkersPage.providerFact`,{provider:e.providerId||b(`common.unknown`)})}function ne(e){let t=()=>G(Ne,{kind:`warn`,get label(){return b(`cloudWorkersPage.unavailable`)}}),n=()=>G(z,{get when(){return u()},get fallback(){return G(z,{get when(){return f()},keyed:!0,get fallback(){return t()},children:e=>G(fe,{get fallback(){return t()},get children(){return G(ve,{on:e,get fallback(){return G(Ne,{kind:`muted`,get label(){return b(`common.loading`)}})},get children(){return[U(()=>m()),U(()=>t())]}})}})})},get children(){return G(z,{get when(){return u()?.has(e.id)},get fallback(){return t()},get children(){return G(Ne,{kind:`ok`,get label(){return b(`cloudWorkersPage.advertised`)}})}})}});return G(Z,{get title(){var t=An();return H(t,()=>e.id),t},get description(){return j(e)},get control(){return[U(n),(()=>{var t=jn();return t._$$click=()=>te(e),H(t,()=>b(`cloudWorkersPage.editAction`)),K(()=>({e:`${b(`cloudWorkersPage.editAction`)}: ${e.id}`,t:l()||!T()}),({e,t:n},r)=>{e!==r?.e&&W(t,`aria-label`,e),n!==r?.t&&W(t,`disabled`,n)}),t})(),(()=>{var t=Mn();return t._$$click=()=>void A(e),H(t,()=>b(`common.delete`)),K(()=>({e:`${b(`common.delete`)}: ${e.id}`,t:l()||!T()}),({e,t:n},r)=>{e!==r?.e&&W(t,`aria-label`,e),n!==r?.t&&W(t,`disabled`,n)}),t})()]}})}function M(e){let n=()=>e.field===`id`?`profileId`:e.field;return G(Z,{get title(){return b(`cloudWorkersPage.fields.${n()}`)},get description(){return e.description??b(`cloudWorkersPage.fields.${n()}Help`)},get control(){var r=Nn();return r._$$input=t=>O({[e.field]:t.currentTarget.value}),K(()=>({e:b(`cloudWorkersPage.fields.${n()}`),t:e.placeholder,a:e.type,o:e.field===`readyWorkers`?`0`:void 0,i:e.field===`readyWorkers`?`1`:void 0,n:t.draft[e.field],s:l()}),({e,t,a:n,o:i,i:a,n:o,s},c)=>{e!==c?.e&&W(r,`aria-label`,e),t!==c?.t&&W(r,`placeholder`,t),n!==c?.a&&W(r,`type`,n),i!==c?.o&&W(r,`min`,i),a!==c?.i&&W(r,`step`,a),V(r,`value`,o),s!==c?.s&&W(r,`disabled`,s)}),r}})}function N(){let e=()=>t.editor?.kind===`edit`,n=()=>e()?u()?.get(t.draft.id)?.operatingSystems??[]:[],r=()=>!(!t.draft.target||n().some(e=>e.id===t.draft.target));return G(X,{get title(){return U(()=>!!e())()?b(`cloudWorkersPage.editProfile`):b(`cloudWorkersPage.addProfile`)},get children(){return[G(z,{get when(){return e()},get fallback(){return G(M,{field:`id`})},get children(){return G(Z,{get title(){return b(`cloudWorkersPage.fields.profileId`)},get description(){return b(`cloudWorkersPage.fields.profileIdHelp`)},get control(){return G(we,{get value(){return t.draft.id},mono:!0})}})}}),G(M,{field:`backend`,get description(){return[U(()=>b(`cloudWorkersPage.fields.backendHelp`)),` `,G(Ee,{url:Vn,get children(){return b(`cloudWorkersPage.providerList`)}})]},get placeholder(){return b(`cloudWorkersPage.fields.backendPlaceholder`)}}),G(z,{get when(){return n().length>=2||r()},get children(){return G(Z,{get title(){return b(`cloudWorkersPage.fields.operatingSystem`)},get description(){return b(`cloudWorkersPage.fields.operatingSystemHelp`)},get control(){return G(Le,{get"aria-label"(){return b(`cloudWorkersPage.fields.operatingSystem`)},get value(){return t.draft.target},get options(){return[{value:``,label:b(`cloudWorkersPage.fields.providerDefault`)},...n().map(e=>({value:e.id,label:`${e.label}${e.disabledReason?` — ${e.disabledReason}`:``}`,disabled:!!e.disabledReason})),...r()?[{value:t.draft.target,label:t.draft.target}]:[]]},get disabled(){return l()},onChange:e=>{let t=e.currentTarget.value;n().find(e=>e.id===t)?.disabledReason||O({target:t})}})}})}}),G(M,{field:`machineClass`}),G(M,{field:`ttl`,get placeholder(){return b(`cloudWorkersPage.fields.ttlPlaceholder`)}}),G(M,{field:`idleTimeout`,get placeholder(){return b(`cloudWorkersPage.fields.idleTimeoutPlaceholder`)}}),G(Z,{get title(){return b(`cloudWorkersPage.fields.setup`)},get description(){return b(`cloudWorkersPage.fields.setupHelp`)},stacked:!0,get control(){var e=Pn();return e._$$input=e=>O({setup:e.currentTarget.value}),K(()=>({e:b(`cloudWorkersPage.fields.setup`),t:b(`cloudWorkersPage.fields.setupPlaceholder`),a:t.draft.setup,o:l()}),({e:t,t:n,a:r,o:i},a)=>{t!==a?.e&&W(e,`aria-label`,t),n!==a?.t&&W(e,`placeholder`,n),e.value=r??``,i!==a?.o&&W(e,`disabled`,i)}),e}}),G(Me,{get title(){return b(`cloudWorkersPage.fields.desktop`)},get description(){return b(`cloudWorkersPage.fields.desktopHelp`)},get checked(){return t.draft.desktop},get disabled(){return l()},onChange:e=>O({desktop:e})}),G(M,{field:`binary`,get placeholder(){return b(`cloudWorkersPage.fields.binaryPlaceholder`)}}),G(X,{get title(){return b(`cloudWorkersPage.advanced`)},get children(){return[G(Ve,{get title(){return b(`cloudWorkersPage.fields.warmImage`)},get description(){return b(`cloudWorkersPage.fields.warmImageHelp`)},get value(){return t.draft.warmImage},get disabled(){return l()},onChange:e=>{(e===`auto`||e===`on`||e===`off`)&&O({warmImage:e})},get options(){return[`auto`,`on`,`off`].map(e=>({value:e,label:b(`cloudWorkersPage.warmImage.${e}`)}))}}),G(I,{each:[`setupEnv`,`readyWorkers`,`suspendAfter`],children:e=>G(M,{field:e,type:e===`readyWorkers`?`number`:`text`})})]}}),G(z,{get when(){return c().error},get children(){return G(Z,{get title(){return b(`cloudWorkersPage.errors.title`)},get description(){var e=Fn();return H(e,()=>c().error),e}})}}),G(Z,{get title(){return b(`cloudWorkersPage.fields.actions`)},get description(){return b(`cloudWorkersPage.fields.actionsHelp`)},get control(){return[(()=>{var e=In();return e._$$click=()=>void k({...t.draft}),H(e,(()=>{var e=U(()=>!!l());return()=>e()?b(`common.saving`):b(`common.save`)})()),K(()=>l()||!T(),t=>{W(e,`disabled`,t)}),e})(),(()=>{var e=Ln();return e._$$click=D,H(e,()=>b(`common.cancel`)),K(()=>l(),t=>{W(e,`disabled`,t)}),e})()]}})]}})}var re=Rn(),ie=re.firstChild,ae=ie.nextSibling;return re._$owner=de(),H(re,G(ke,{get title(){return b(`tabs.cloudWorkers`)}}),ie),H(re,G(Pe,{get children(){return G(Cn,{machines:()=>[G(z,{get when(){return!w()},get children(){return G(E,{tone:`warning`,role:`note`,get children(){return b(i.connected?a(i.snapshot,`config.patch`,`operator.admin`,{requireAdvertisement:!1})?`cloudWorkersPage.unavailableAccess`:`cloudWorkersPage.adminRequired`:`cloudWorkersPage.reconnectRequired`)}})}}),G(fe,{fallback:e=>G(E,{tone:`warning`,role:`status`,get children(){return b(`cloudWorkersPage.catalogFailed`,{error:g(e())})}}),get children(){return G(ve,{get on(){return f()},get children(){return m()}})}}),G(z,{get when(){return U(()=>!!c().error)()?!t.editor:c().error},get children(){return G(E,{tone:`warning`,role:`alert`,get children(){return c().error}})}}),G(z,{get when(){return c().notice},get children(){var e=zn();return H(e,()=>c().notice),e}}),G(X,{get title(){return b(`cloudWorkersPage.environments.machines`)},get count(){return U(()=>!!S())()?C().length:void 0},get actions(){return G(z,{get when(){return U(()=>!l())()&&T()},get children(){var e=Bn();return e._$$click=()=>te(),H(e,()=>b(`cloudWorkersPage.addProfile`)),e}})},get children(){return G(I,{get each(){return C()},get fallback(){return G(_e,{get children(){return[G(me,{get when(){return S()},get children(){return G(De,{get message(){return b(`cloudWorkersPage.empty`)}})}}),G(me,{get when(){return s.read().state.configLoading},get children(){return G(je,{rows:1})}}),G(me,{get when(){return s.read().state.lastError},children:t=>G(E,{tone:`warning`,role:`alert`,get children(){return[U(()=>t()),` `,G(Ae,{get disabled(){return!i.connected},onRetry:()=>void e.runtimeConfig.refresh()})]}})})]}})},children:e=>ne(e)})}}),G(z,{get when(){return t.editor},get children(){return G(N,{})}})]})}}),ae),re}var An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn;function Hn(){return(Hn=t((()=>{J(),B(),se(),O(),Fe(),Q(),Ie(),xe(),h(),s(),w(),y(),Be(),$e(),On(),Lt(),An=Y(`<code>`),jn=Y(`<button class="btn btn--sm"type=button>`),Mn=Y(`<button class="btn btn--sm danger"type=button>`),Nn=Y(`<input class="settings-input mono"autocomplete=off spellcheck=false>`),Pn=Y(`<textarea class="settings-input mono"autocomplete=off spellcheck=false>`),Fn=Y(`<span role=alert>`),In=Y(`<button class="btn primary"type=button>`),Ln=Y(`<button class=btn type=button>`),Rn=Y(`<openclaw-cloud-workers-page><!><!>`,1),zn=Y(`<div class=callout role=status>`),Bn=Y(`<button class="btn btn--sm primary"type=button>`),ae(be),Vn=`https://docs.openclaw.ai/gateway/cloud-workers`,q([`click`,`input`])})))()}Hn();export{kn as CloudWorkersPage};