UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 12.3 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Nt as t,Qt as n,Xt as r,jt as i,wa as a,wc as o,xa as s,xc as c}from"./control-ui-connection-Bfj9beF_.js";import{BD as ee,Cb as te,FA as ne,Nt as l,Pt as u,XO as d,dj as re,ej as ie,kb as f,mj as p,nk as ae,tj as m,tk as oe}from"./control-ui-boot-shared-DFTSUQQ0.js";import{C as h,Ct as g,F as _,I as se,O as v,Rt as y,S as ce,U as le,a as b,d as x,f as S,g as C,j as w,l as T,s as ue,u as de,w as fe,x as E,yt as pe}from"./solid-runtime-C416s-HC.js";import{gr as D,mr as me}from"./deferred-ui-support-D-VedBtc.js";import{d as he,h as O}from"./route-controls-runtime-Bx6nx3QW.js";import{n as k,t as A}from"./en-session-organization-D0fXDuFy.js";import{a as j,d as M,h as N,l as P,p as F,y as I}from"./settings-ui-Ck6BJLhD.js";import"./settings-DAApurug.js";import"./hub-tabs-BnaRSduq.js";import{n as L,t as R}from"./gateway-page-BGbclR08.js";import{a as ge,i as _e,o as ve,r as ye}from"./route-chrome-7YRVJwhf.js";import{n as be,t as xe}from"./session-hub-tabs-BiAZBaJZ.js";var z;function B(){return(B=e((()=>{c(),i(),me(),s(),A(),n(),k(),z=class{constructor(e,t){this.getContext=e,this.publish=t,this.records=[],this.listLoaded=!1,this.listRead={result:Promise.resolve()},this.presentationLifetime=Promise.withResolvers(),this.error=null,this.operation=null,this.createOpen=!1,this.createRepoRoot=``,this.createName=``,this.createBaseRef=``,this.createBranches=[],this.listRequest=O(()=>this.update({}),{task:(e,{signal:t})=>e.client.request(`worktrees.list`,{},{signal:t}),onComplete:e=>{this.records=e.worktrees.toSorted((e,t)=>t.lastActiveAt-e.lastActiveAt),this.listLoaded=!0},onError:e=>{this.error=r(e)}}),this.branchesRequest=O(()=>this.update({}),{task:({scope:e,repoRoot:t},{signal:n})=>e.client.request(`worktrees.branches`,{repoRoot:t},{signal:n}),onComplete:e=>{this.createBranches=e.branches.map(e=>e.name)},onError:()=>{this.createBranches=[]}})}get context(){return this.getContext()}update(e){Object.assign(this,e),this.publish()}invalidateRequests(){this.presentationLifetime.resolve(),this.presentationLifetime=Promise.withResolvers(),this.listRequest.cancel(),this.branchesRequest.cancel(),this.update({operation:null})}get retired(){return this.presentationLifetime.promise}get loading(){return this.operation===`gc`||this.listRequest.pending}get operationPending(){return this.loading||this.operation!==null}get operatorAccess(){return t(this.context.gateway.snapshot)}async load(e={}){let t=this.gateway.capture();if(!t||this.operation!==null||this.listRequest.pending)return;e.preserveError||(this.error=null);let n=this.listRequest.run(t);this.listRead={result:Promise.race([n,this.retired])},this.publish(),await n}async runOperation(e,t){this.update({error:null});try{await t()}catch(t){this.gateway.isCurrent(e)&&this.update({error:r(t)})}finally{this.gateway.isCurrent(e)&&(this.update({operation:null}),await this.load({preserveError:!0}))}}async removeWorktree(e){let t=this.gateway.capture();t&&this.operatorAccess.canAdmin&&!this.operationPending&&await D({message:a(`worktrees.confirmDelete`,{name:e.name}),confirmLabel:a(`common.delete`),danger:!0})&&this.gateway.isCurrent(t)&&this.operatorAccess.canAdmin&&!this.operationPending&&(this.update({operation:`row`}),await this.runOperation(t,async()=>{let n=await t.client.request(`worktrees.remove`,{id:e.id});if(!this.gateway.isCurrent(t)||n.removed)return;let r=n.snapshotError??``,i=await D({message:a(`worktrees.confirmForceDelete`,{error:r}),confirmLabel:a(`common.delete`),danger:!0});if(!this.gateway.isCurrent(t)||!this.operatorAccess.canAdmin)return;if(!i){this.update({error:r||null});return}let o=await t.client.request(`worktrees.remove`,{id:e.id,force:!0});this.gateway.isCurrent(t)&&this.update({error:o.snapshotError??null})}))}async restore(e){let t=this.gateway.capture();t&&this.operatorAccess.canAdmin&&!this.operationPending&&(this.update({operation:`row`}),await this.runOperation(t,()=>t.client.request(`worktrees.restore`,{id:e.id})))}async gc(){let e=this.gateway.capture();e&&this.operatorAccess.canAdmin&&!this.operationPending&&(this.update({operation:`gc`}),await this.runOperation(e,async()=>{if(!this.gateway.isCurrent(e))return;let t=await e.client.request(`worktrees.gc`,{}),n=t.jobId;for(;t.state===`queued`||t.state===`running`;){if(!this.gateway.isCurrent(e))return;if(!n)throw Error(a(`sessionsView.deletePreservedReasons.cleanup-failed`));if(await o(1e3),!this.gateway.isCurrent(e))return;t=await e.client.request(`worktrees.gc`,{jobId:n})}if(this.gateway.isCurrent(e)&&(t.state===`failed`||t.outcome===`partial`))throw Error(t.error||t.issues?.map(e=>e.reason).join(`; `)||a(`sessionsView.deletePreservedReasons.cleanup-failed`))}))}toggleCreate(){if(this.operatorAccess.canAdmin&&this.operation!==`create`&&(this.update({createOpen:!this.createOpen}),this.createOpen&&!this.createRepoRoot)){let e=this.context.agents.state.agentsList,t=e?.agents.find(t=>t.id===e.defaultId);this.update({createRepoRoot:t?.workspace??``}),this.loadCreateBranches()}}async loadCreateBranches(){this.branchesRequest.cancel();let e=this.gateway.capture(),t=this.createRepoRoot.trim();!e||!t||!this.operatorAccess.canWrite?this.update({createBranches:[]}):await this.branchesRequest.run({scope:e,repoRoot:t})}async createWorktree(){let e=this.gateway.capture(),t=this.createRepoRoot.trim();e&&this.operatorAccess.canAdmin&&t&&!this.operationPending&&(this.update({operation:`create`}),await this.runOperation(e,async()=>{await he(e.client,{repoRoot:t,name:this.createName,baseRef:this.createBaseRef}),this.gateway.isCurrent(e)&&this.update({createOpen:!1,createName:``})}))}}})))()}function Se(){let e=m(),{owner:t,view:n}=u(t=>new z(()=>e,t),e=>e);var r=V();return r._$owner=y(),x(r,()=>Ce(t,n.read)),r}function Ce(e,t){e.gateway=L({getGateway:()=>e.context.gateway,onIdentityChange:()=>e.update({records:[],listLoaded:!1,error:null}),invalidateRequests:()=>e.invalidateRequests(),ensureInitialData:()=>void e.load(),onSnapshot:()=>e.update(e.operatorAccess.canAdmin?{}:{createOpen:!1})});let n=_(()=>t().listRead),i=_(()=>n().result.then(()=>{if(!e.listLoaded&&e.error)throw Error(e.error)})),a=_(()=>e.gateway.epoch),o=_(()=>{let e=a(),[t,n]=se(null);return{epoch:e,operation:t,setOperation:n}}),s=pe(function*(t,n,i,a){try{t.epoch===e.gateway.readEpoch()&&t.setOperation(n),yield Promise.race([i,a])}catch(n){t.epoch===e.gateway.readEpoch()&&e.update({error:r(n)})}});async function c(t,n){let r=o(),i=e.retired,a=n();return await Promise.resolve(),s(r,t,a,i)}let l=()=>o().operation()??t().operation,u=()=>l()!==null||t().operationPending,d=t=>{if(t.ownerKind===`session`&&t.ownerId){let i=oe(e.context,t.ownerId),a=ae({context:e.context,face:i,sessionKey:t.ownerId,preferenceDerivedFace:!0});var n=H(),r=y();return n._$$click=t=>ne(t,()=>e.context.navigate(i,a.options)),x(n,()=>p(`worktrees.ownerSession`)),T(()=>({e:a.href,t:t.ownerId}),({e,t},i)=>{e!==i?.e&&C(n,`href`,e),t!==i?.t&&C(n,`title`,t),b(n,r)}),n}return t.ownerKind===`workboard`?(()=>{var e=U();return x(e,()=>p(`worktrees.ownerWorkboard`)),T(()=>t.ownerId??``,t=>{C(e,`title`,t)}),e})():(()=>{var e=U();return x(e,()=>p(`worktrees.ownerManual`)),e})()};return[w(ye,{active:`worktrees`,get tabs(){return be(`worktrees`,t=>e.context.navigate(t))},docsUrl:Q,class:`sessions-hub-header`}),w(ge,{id:`sessions-hub-panel`,get children(){return w(P,{wide:!0,get children(){return[w(v,{get when(){return!t().operatorAccess.canAdmin},get children(){var e=W();return x(e,()=>p(`worktrees.adminRequired`)),e}}),w(v,{get when(){return t().error},get children(){var e=G();return x(e,()=>t().error),e}}),w(F,{get title(){return p(`worktrees.title`)},get description(){return p(`worktrees.subtitle`)},get actions(){return[(()=>{var n=K();return n._$$click=()=>e.toggleCreate(),x(n,()=>p(`worktrees.newWorktree`)),T(()=>({e:t().operatorAccess.canAdmin?``:p(`worktrees.adminRequired`),t:t().createOpen?`true`:`false`,a:!t().operatorAccess.canAdmin||l()===`create`}),({e,t,a:r},i)=>{e!==i?.e&&C(n,`title`,e),t!==i?.t&&C(n,`aria-expanded`,t),r!==i?.a&&C(n,`disabled`,r)}),n})(),(()=>{var n=K();return n._$$click=()=>void c(`gc`,()=>e.gc()),x(n,(()=>{var e=S(()=>!!(l()===`gc`||t().loading));return()=>e()?p(`common.loading`):p(`worktrees.cleanNow`)})()),T(()=>({e:t().operatorAccess.canAdmin?``:p(`worktrees.adminRequired`),t:!e.gateway.connected||!t().operatorAccess.canAdmin||u()}),({e,t},r)=>{e!==r?.e&&C(n,`title`,e),t!==r?.t&&C(n,`disabled`,t)}),n})()]},get children(){return[w(v,{get when(){return t().createOpen},get children(){return[w(M,{get title(){return p(`worktrees.repo`)},get control(){var n=q();return n.addEventListener(`change`,t=>{e.update({createRepoRoot:t.currentTarget.value,createBaseRef:``}),e.loadCreateBranches()}),n._$$input=t=>e.update({createRepoRoot:t.currentTarget.value}),T(()=>({e:p(`worktrees.repo`),t:l()===`create`,a:t().createRepoRoot}),({e,t,a:r},i)=>{e!==i?.e&&C(n,`aria-label`,e),t!==i?.t&&C(n,`disabled`,t),n.value=r??``}),n}}),w(M,{get title(){return p(`worktrees.name`)},get control(){var n=q();return n._$$input=t=>e.update({createName:t.currentTarget.value}),T(()=>({e:p(`worktrees.name`),t:l()===`create`,a:p(`worktrees.namePlaceholder`),o:t().createName}),({e,t,a:r,o:i},a)=>{e!==a?.e&&C(n,`aria-label`,e),t!==a?.t&&C(n,`disabled`,t),r!==a?.a&&C(n,`placeholder`,r),n.value=i??``}),n}}),w(M,{get title(){return p(`worktrees.baseBranch`)},get control(){return[(()=>{var n=J();return n._$$input=t=>e.update({createBaseRef:t.currentTarget.value}),T(()=>({e:p(`worktrees.baseBranch`),t:l()===`create`,a:p(`worktrees.baseBranchPlaceholder`),o:t().createBaseRef}),({e,t,a:r,o:i},a)=>{e!==a?.e&&C(n,`aria-label`,e),t!==a?.t&&C(n,`disabled`,t),r!==a?.a&&C(n,`placeholder`,r),n.value=i??``}),n})(),(()=>{var e=Y();return x(e,w(h,{get each(){return t().createBranches},children:e=>(()=>{var t=X();return t.value=e,t})()})),e})()]}}),w(M,{get title(){return p(`worktrees.newWorktree`)},get control(){var n=Z();return n._$$click=()=>void c(`create`,()=>e.createWorktree()),x(n,(()=>{var e=S(()=>l()===`create`);return()=>e()?p(`common.loading`):p(`common.create`)})()),T(()=>!e.gateway.connected||u()||!t().createRepoRoot.trim(),e=>{C(n,`disabled`,e)}),n}})]}}),w(ce,{fallback:(t,n)=>(()=>{var t=K();return t._$$click=()=>{e.load(),n()},x(t,()=>p(`common.retry`)),t})(),get children(){return w(fe,{get on(){return g(a)},get fallback(){return w(j,{get message(){return p(`common.loading`)}})},get children(){return[S(()=>(g(i),null)),w(v,{get when(){return t().records.length>0},get fallback(){return w(j,{get message(){return p(`worktrees.empty`)}})},get children(){return w(h,{get each(){return t().records},keyed:e=>e.id,children:n=>w(M,{get title(){return n().name},get description(){return[(()=>{var e=U();return x(e,()=>ee(n().repoRoot)),T(()=>n().repoRoot,t=>{C(e,`title`,t)}),e})(),` · `,S(()=>n().branch),` · `,S(()=>d(n())),` · `,S(()=>te(n().lastActiveAt))]},get control(){return[w(N,{get kind(){return n().removedAt?`muted`:`ok`},get label(){return S(()=>!!n().removedAt)()?p(`worktrees.restorable`):p(`common.active`)}}),(()=>{var r=Z();return r._$$click=()=>void c(`row`,()=>n().removedAt?e.restore(n()):e.removeWorktree(n())),x(r,(()=>{var e=S(()=>!!n().removedAt);return()=>e()?p(`worktrees.restore`):p(`common.delete`)})()),T(()=>({e:!n().removedAt,t:t().operatorAccess.canAdmin?``:p(`worktrees.adminRequired`),a:`${n().removedAt?p(`worktrees.restore`):p(`common.delete`)}: ${n().name}`,o:!e.gateway.connected||!t().operatorAccess.canAdmin||u()}),({e,t,a:n,o:i},a)=>{e!==a?.e&&r.classList.toggle(`danger`,e),t!==a?.t&&C(r,`title`,t),n!==a?.a&&C(r,`aria-label`,n),i!==a?.o&&C(r,`disabled`,i)}),r})()]}})})}})]}})}})]}})]}})}})]}var V,H,U,W,G,K,q,J,Y,X,Z,Q;function $(){return($=e((()=>{de(),le(),_e(),I(),ve(),n(),f(),l(),ie(),R(),re(),d(),xe(),B(),V=E(`<openclaw-worktrees-page>`,1),H=E(`<a>`),U=E(`<span>`),W=E(`<div class="callout info"role=note>`),G=E(`<div class="callout danger"role=alert>`),K=E(`<button class=btn>`),q=E(`<input class=settings-input type=text>`),J=E(`<input class=settings-input type=text list=worktrees-create-branches>`),Y=E(`<datalist id=worktrees-create-branches>`),X=E(`<option>`),Z=E(`<button class="btn btn--sm">`),Q=`https://docs.openclaw.ai/concepts/managed-worktrees`,ue([`click`,`input`])})))()}$();export{Se as WorktreesPage};