openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines • 10.5 kB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{R as t,wr as n,z as r}from"./control-ui-foundation-Cydpkyqa.js";import{Bi as i,Eo as a,Fa as o,J as s,La as c,Oo as l,Sc as u,Ui as d,Wi as f,bc as p,k as m,w as h}from"./control-ui-core-Rwzhj6nO.js";import{$ as g,K as _,X as v,at as y,q as b}from"./lit-runtime-CV_MH99K.js";import{An as x,_ as S,_n as C,g as w,jn as T,nn as E,rn as D}from"./control-ui-core-YphAl4aM.js";import{Yt as O,en as k}from"./control-ui-core-vvcQQV2m.js";import{B as A,U as j,V as M,z as N}from"./control-ui-boot-shared-BYq7Cchl.js";import{J as P,K as F,L as I,Q as L,V as R,X as z,in as B,rn as V,z as H}from"./control-ui-boot-chat-_QSl8fbH.js";import{Is as U,Ls as W}from"./control-ui-boot-shared-CXVvK2AW.js";import{a as G}from"./control-ui-boot-new-Bj2SAUyl.js";import{n as K,t as q}from"./settings-workspace-Bseic8Tf.js";import{n as J,t as Y}from"./sessions-hub-header-CjvNBRq9.js";var X,Z;function Q(){return(Q=e((()=>{r(),N(),_(),g(),C(),S(),E(),V(),Y(),I(),q(),O(),l(),m(),o(),i(),W(),u(),X=`https://docs.openclaw.ai/concepts/managed-worktrees`,Z=class extends p{constructor(...e){super(...e),this.records=[],this.error=null,this.busyId=null,this.createOpen=!1,this.createRepoRoot=``,this.createName=``,this.createBaseRef=``,this.createBranches=[],this.creating=!1,this.gcLoading=!1,this.listClient=null,this.gateway=new U(this,{getGateway:()=>this.context?.gateway,onIdentityChange:()=>{this.records=[],this.error=null},invalidateRequests:e=>{(e.snapshot.phase!==`connected`||!e.snapshot.client)&&(this.listClient=null,this.listTask.run([null])),this.branchesTask.run([null,``]),this.invalidateOperations()},ensureInitialData:()=>void this.load(),onSnapshot:e=>{D(e.snapshot).canAdmin||(this.createOpen=!1)}}),this.listTask=new A(this,{autoRun:!1,args:()=>[this.gateway.connected?this.gateway.client:null],task:([e],{signal:t})=>e?e.request(`worktrees.list`,{},{signal:t}):M,onComplete:e=>{this.records=e.worktrees.toSorted((e,t)=>t.lastActiveAt-e.lastActiveAt)},onError:e=>{this.error=a(e)}}),this.branchesTask=new A(this,{autoRun:!1,args:()=>[this.gateway.connected?this.gateway.client:null,this.createRepoRoot.trim()],task:([e,t],{signal:n})=>e&&t?e.request(`worktrees.branches`,{repoRoot:t},{signal:n}):M,onComplete:e=>{this.createBranches=e.branches.map(e=>e.name),this.createBaseRef||=e.defaultBranch??e.headBranch??``},onError:()=>{this.createBranches=[]}})}disconnectedCallback(){this.listClient=null,this.listTask.run([null]),this.branchesTask.run([null,``]),super.disconnectedCallback()}invalidateOperations(){this.busyId=null,this.creating=!1,this.gcLoading=!1}get operationPending(){return this.loading||this.busyId!==null||this.creating}get loading(){return this.gcLoading||this.listTask.status===j.PENDING}get canAdmin(){return D(this.context.gateway.snapshot).canAdmin}get canWrite(){return D(this.context.gateway.snapshot).canWrite}async load(e={}){let t=this.gateway.client;!t||!this.gateway.connected||this.busyId!==null||this.creating||this.gcLoading||this.listTask.status===j.PENDING&&this.listClient===t||(this.listClient=t,e.preserveError||(this.error=null),await this.listTask.run([t]))}async removeWorktree(e){let t=this.gateway.capture();if(!(!t||!this.canAdmin||this.operationPending)&&!(!await B({message:k(`worktrees.confirmDelete`,{name:e.name}),confirmLabel:k(`common.delete`),danger:!0})||!this.gateway.isCurrent(t)||!this.canAdmin||this.operationPending)){this.busyId=e.id,this.error=null;try{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 B({message:k(`worktrees.confirmForceDelete`,{error:r}),confirmLabel:k(`common.delete`),danger:!0});if(!this.gateway.isCurrent(t)||!this.canAdmin)return;if(!i){this.error=r||null;return}try{let n=await t.client.request(`worktrees.remove`,{id:e.id,force:!0});this.gateway.isCurrent(t)&&(this.error=n.snapshotError??null)}catch(e){this.gateway.isCurrent(t)&&(this.error=a(e))}}catch(e){this.gateway.isCurrent(t)&&(this.error=a(e))}finally{this.gateway.isCurrent(t)&&(this.busyId=null,await this.load({preserveError:!0}))}}}async restore(e){let t=this.gateway.capture();if(!(!t||!this.canAdmin||this.operationPending)){this.busyId=e.id,this.error=null;try{await t.client.request(`worktrees.restore`,{id:e.id})}catch(e){this.gateway.isCurrent(t)&&(this.error=a(e))}finally{this.gateway.isCurrent(t)&&(this.busyId=null,await this.load({preserveError:!0}))}}}async gc(){let e=this.gateway.capture();if(!(!e||!this.canAdmin||this.operationPending)){this.gcLoading=!0,this.error=null;try{await e.client.request(`worktrees.gc`,{})}catch(t){this.gateway.isCurrent(e)&&(this.error=a(t))}finally{this.gateway.isCurrent(e)&&(this.gcLoading=!1,await this.load({preserveError:!0}))}}}toggleCreate(){if(!(!this.canAdmin||this.creating)&&(this.createOpen=!this.createOpen,this.createOpen&&!this.createRepoRoot)){let e=this.context.agents.state.agentsList,t=e?.agents.find(t=>t.id===e.defaultId);this.createRepoRoot=t?.workspace??``,this.loadCreateBranches()}}loadCreateBranches(){let e=this.gateway.connected?this.gateway.client:null,t=this.createRepoRoot.trim();if(!e||!t||!this.canWrite){this.createBranches=[],this.branchesTask.run([null,``]);return}this.branchesTask.run([e,t])}async createWorktree(){let e=this.gateway.capture(),t=this.createRepoRoot.trim();if(!(!e||!this.canAdmin||!t||this.operationPending)){this.creating=!0,this.error=null;try{await G(e.client,{repoRoot:t,name:this.createName,baseRef:this.createBaseRef}),this.gateway.isCurrent(e)&&(this.createOpen=!1,this.createName=``)}catch(t){this.gateway.isCurrent(e)&&(this.error=a(t))}finally{this.gateway.isCurrent(e)&&(this.creating=!1,await this.load({preserveError:!0}))}}}renderOwner(e){if(e.ownerKind===`session`&&e.ownerId){let t=d(this.context,e.ownerId),n=f({context:this.context,face:t,sessionKey:e.ownerId,preferenceDerivedFace:!0});return v`<a
href=${n.href}
title=${e.ownerId}
@click=${e=>{s(e)&&(e.preventDefault(),this.context.navigate(t,n.options))}}
>${k(`worktrees.ownerSession`)}</a
>`}return e.ownerKind===`workboard`?v`<span title=${e.ownerId??``}>${k(`worktrees.ownerWorkboard`)}</span>`:v`<span>${k(`worktrees.ownerManual`)}</span>`}renderCreateRows(){return this.createOpen?v`
${P({title:k(`worktrees.repo`),control:v`
<input
class="settings-input"
type="text"
aria-label=${k(`worktrees.repo`)}
?disabled=${this.creating}
.value=${this.createRepoRoot}
@change=${e=>{this.createRepoRoot=e.target.value,this.createBaseRef=``,this.loadCreateBranches()}}
/>
`})}
${P({title:k(`worktrees.name`),control:v`
<input
class="settings-input"
type="text"
aria-label=${k(`worktrees.name`)}
?disabled=${this.creating}
placeholder=${k(`worktrees.namePlaceholder`)}
.value=${this.createName}
@input=${e=>{this.createName=e.target.value}}
/>
`})}
${P({title:k(`worktrees.baseBranch`),control:v`
<input
class="settings-input"
type="text"
aria-label=${k(`worktrees.baseBranch`)}
?disabled=${this.creating}
list="worktrees-create-branches"
.value=${this.createBaseRef}
@input=${e=>{this.createBaseRef=e.target.value}}
/>
<datalist id="worktrees-create-branches">
${this.createBranches.map(e=>v`<option value=${e}></option>`)}
</datalist>
`})}
${P({title:k(`worktrees.newWorktree`),control:v`
<button
class="btn btn--sm"
?disabled=${this.operationPending||!this.createRepoRoot.trim()}
@click=${()=>void this.createWorktree()}
>
${this.creating?k(`common.loading`):k(`common.create`)}
</button>
`})}
`:b}renderRecordRow(e){return P({title:e.name,description:v`
<span title=${e.repoRoot}>${c(e.repoRoot)}</span> · ${e.branch} ·
${this.renderOwner(e)} · ${h(e.lastActiveAt)}
`,control:v`
${e.removedAt?L({kind:`muted`,label:k(`worktrees.restorable`)}):L({kind:`ok`,label:k(`common.active`)})}
<button
class=${e.removedAt?`btn btn--sm`:`btn btn--sm danger`}
title=${this.canAdmin?``:k(`worktrees.adminRequired`)}
?disabled=${!this.canAdmin||this.operationPending}
@click=${()=>void(e.removedAt?this.restore(e):this.removeWorktree(e))}
>
${e.removedAt?k(`worktrees.restore`):k(`common.delete`)}
</button>
`})}render(){let e=v`
<button
class="btn"
title=${this.canAdmin?``:k(`worktrees.adminRequired`)}
?disabled=${!this.canAdmin||this.creating}
@click=${()=>this.toggleCreate()}
>
${k(`worktrees.newWorktree`)}
</button>
<button
class="btn"
title=${this.canAdmin?``:k(`worktrees.adminRequired`)}
?disabled=${!this.canAdmin||this.operationPending}
@click=${()=>void this.gc()}
>
${this.loading?k(`common.loading`):k(`worktrees.cleanNow`)}
</button>
`,t=v`
${this.renderCreateRows()}
${this.records.length===0?R(k(`worktrees.empty`)):this.records.map(e=>this.renderRecordRow(e))}
`,n=F(v`
${this.canAdmin?b:v`<div class="callout info" role="note">${k(`worktrees.adminRequired`)}</div>`}
${this.error?v`<div class="callout danger" role="alert">${this.error}</div>`:b}
${z({title:k(`worktrees.title`),description:k(`worktrees.subtitle`),actions:e},t)}
`,{wide:!0});return v`
${J({active:`worktrees`,title:T(`sessions`),subtitle:v`${x(`worktrees`)} ${H(X)}`,onSelect:e=>{e!==`worktrees`&&this.context?.navigate(e)}})}
${K(n,{id:`sessions-hub-panel`})}
`}},n([t({context:w,subscribe:!0})],Z.prototype,`context`,void 0),n([y()],Z.prototype,`records`,void 0),n([y()],Z.prototype,`error`,void 0),n([y()],Z.prototype,`busyId`,void 0),n([y()],Z.prototype,`createOpen`,void 0),n([y()],Z.prototype,`createRepoRoot`,void 0),n([y()],Z.prototype,`createName`,void 0),n([y()],Z.prototype,`createBaseRef`,void 0),n([y()],Z.prototype,`createBranches`,void 0),n([y()],Z.prototype,`creating`,void 0),n([y()],Z.prototype,`gcLoading`,void 0),customElements.get(`openclaw-worktrees-page`)||customElements.define(`openclaw-worktrees-page`,Z)})))()}Q();
//# sourceMappingURL=worktrees-page-vZu6xind.js.map