Files
openclaw-config/cache/control-ui-assets/d08fd045b9cb86d13f0b4aa403c8a06ddcd32e533058ae463245169e5cff5e85/assets/new-session-page-entry-BxT3_ZKs.js
T

551 lines
149 KiB
JavaScript

const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./composer-draft-store.runtime-ChgPeVSK.js","./control-ui-boot-Cdpgu1Gm.js","./rolldown-runtime-DkW27tQK.js","./control-ui-foundation-CeFMP1Ly.js","./control-ui-core-pH6nakZ-.js","./lit-runtime-BEtFSUCp.js","./control-ui-core-DGVkFhVB.js","./control-ui-core-Br5DB0Zj.js","./gateway-runtime-DUNO4Mi1.js","./control-ui-core-C8H8-RSs.css","./control-ui-boot-wpHCbPL9.js","./control-ui-boot-gfE6fZcA.js","./config-runtime-C4gfjhZc.js","./control-ui-boot-CKTkvwFZ.js","./control-ui-boot-BPFwXC8p.js","./control-ui-boot-DdPrPuw0.js","./control-ui-boot-9_2QGLIL.js","./control-ui-boot-J-x6DHHT.js","./control-ui-boot-B1lcIXow.js","./control-ui-boot-Clhp68JE.js","./control-ui-boot-D1DWJlBr.js","./control-ui-boot-CQvujP8f.js","./control-ui-boot-BW_XZcbY.js","./control-ui-boot-__AsqpzJ.css","./markdown-runtime-BcrsAQtF.js"])))=>i.map(i=>d[i]);
import{n as e,r as t}from"./rolldown-runtime-DkW27tQK.js";import{Ci as n,Nr as r,Pr as i,Y as a,Z as o,er as s,ki as c,wn as l,xt as u}from"./control-ui-foundation-CeFMP1Ly.js";import{A as d,Ao as f,Ba as p,Da as m,Dr as h,Fr as g,Ir as _,It as v,Jc as y,Js as b,Kc as ee,L as te,Lt as x,Nt as S,Pr as C,S as ne,Tr as re,Va as w,Wc as ie,Xs as ae,Yc as oe,bc as T,br as se,fl as ce,fs as E,hc as le,hl as D,i as ue,ja as de,jo as fe,jr as pe,ml as me,ms as he,qs as ge,vr as _e,w as ve,xr as ye,yr as be}from"./control-ui-core-pH6nakZ-.js";import{G as O,I as xe,J as k,R as Se,W as A,X as Ce,Z as we,_ as Te,at as Ee,b as De,rt as Oe}from"./lit-runtime-BEtFSUCp.js";import{$t as ke,B as Ae,F as je,Jt as Me,Ot as Ne,U as Pe,Ut as Fe,Yt as Ie,Z as Le,en as Re,er as ze,kt as Be,m as Ve,p as He,qt as Ue,tr as We}from"./control-ui-core-DGVkFhVB.js";import{Bt as Ge,Ft as Ke,Ht as j,J as qe,Lt as M,Nt as Je,Rt as N,Y as Ye,qt as P,zt as Xe}from"./control-ui-core-Br5DB0Zj.js";import{F as Ze,I as Qe,In as $e,L as et,Ln as tt,ct as nt,ut as rt,z as F}from"./control-ui-boot-wpHCbPL9.js";import{a as I,n as L,r as R}from"./gateway-runtime-DUNO4Mi1.js";import{Au as it,Bu as at,Cd as ot,Dd as st,Ed as ct,Gt as lt,Ht as ut,Kt as dt,Ku as ft,Ls as pt,Od as mt,Ou as ht,Qt as gt,Rs as _t,Sd as vt,Tt as yt,Ut as bt,Wt as xt,X as St,Xu as Ct,Zu as z,ku as wt,qt as Tt,st as Et,ut as Dt,wd as Ot,wt as kt,x as At,y as jt}from"./control-ui-boot-Cdpgu1Gm.js";import{$t as Mt,A as Nt,Bn as Pt,C as Ft,Ct as It,D as Lt,Dt as Rt,E as zt,Et as Bt,F as Vt,Ft as Ht,I as Ut,Jn as Wt,L as Gt,Ln as Kt,M as qt,N as Jt,O as Yt,P as Xt,Pt as Zt,Qn as Qt,Qt as $t,R as en,S as tn,St as nn,Tt as rn,Xn as B,Yn as an,Yt as on,Zn as sn,Zt as cn,_t as ln,at as un,bt as dn,ct as fn,dn as pn,dt as mn,en as hn,er as V,ft as gn,gt as _n,ht as vn,it as yn,j as bn,k as xn,lt as Sn,mn as Cn,mt as wn,n as Tn,nt as En,ot as Dn,pt as On,qn as kn,rt as An,st as jn,t as Mn,tn as Nn,tr as Pn,tt as Fn,ut as In,vt as Ln,wt as Rn,xt as zn,yt as Bn,z as Vn,zn as Hn}from"./control-ui-boot-B1lcIXow.js";import{i as Un,n as Wn,r as Gn}from"./control-ui-boot-Clhp68JE.js";import{a as Kn,c as qn,i as Jn,l as Yn}from"./control-ui-boot-J-x6DHHT.js";import{B as Xn,Gn as H,H as Zn,Hn as Qn,Jn as $n,Un as er,V as tr,Vn as nr,Wn as rr,qn as ir,z as ar}from"./control-ui-boot-D1DWJlBr.js";import{g as or,h as sr,m as cr}from"./control-ui-boot-CQvujP8f.js";import"./control-ui-boot-BW_XZcbY.js";import{a as lr,n as ur,o as dr,r as U,s as fr,t as pr}from"./place-browser-DiRCxEEz.js";import"./new-session-Df5ycn44.js";import{t as mr}from"./web-awesome-popover-DTDr8XNA.js";import{n as hr,t as gr}from"./draft-cloud-machine-state-B3618rsh.js";import{t as _r}from"./agent-select-registration-Bgp9CYzQ.js";import{i as vr,n as yr,r as br,t as xr}from"./device-placement-CSrN9cIf.js";import{n as Sr,t as Cr}from"./worker-capacity-AlsLTAW4.js";import{a as wr,c as Tr,d as Er,f as W,i as G,l as Dr,n as Or,o as K,p as kr,r as Ar,s as q,t as jr}from"./catalog-target-DMha_lm_.js";import{t as Mr}from"./create-worktree-YmYUx5eq.js";var Nr;function Pr(){return(Pr=e((()=>{A(),Ae(),j(),Nt(),en(),Ut(),Nr=class{constructor(e){this.options=e,this.dictation=null,this.owner=null,this.devicePicker=new Vt(e.requestUpdate)}dispose(){this.owner=null,this.dictation?.dispose(),this.dictation=null,this.devicePicker.dispose()}get active(){return this.dictation?.active===!0}previewDraft(){let e=this.dictation;return e?.active?this.options.textarea.previewTranscript(e.transcript):void 0}renderStatus(){return qt(this.dictation??void 0)}render(e){this.owner?.key!==e&&(this.owner={key:e},this.dictation?.dispose(),this.dictation=null);let t=this.owner,n=()=>this.owner===t,r=this.options.getClient(),i=this.options.isConnected()&&r!==null;this.devicePicker.syncCatalog(r,i);let a=this.options.canCommit(),o={client:r,connected:i,enabled:a,dictationAvailable:this.devicePicker.dictationStatus===`ready`,realtimeTalkActive:!1,onCommit:e=>{if(!n()||!this.options.canCommit())return;let t=this.options.textarea.insertTranscript(e);t!==null&&this.options.onMessage(t),this.options.requestUpdate()},onError:e=>{n()&&this.options.onError(e)},onStateChange:()=>{n()&&this.options.requestUpdate()},onDictationUnavailable:this.devicePicker.handleOpen};this.dictation??=new Gt(o),this.dictation.update(o);let s=this.dictation;return k`
${Jt({connected:i,sending:!1,isBusy:!a,dictation:s,idleLabel:P(`newSession.dictate`),microphonePicker:Xt({devices:this.devicePicker.devices,loading:this.devicePicker.loading,open:this.devicePicker.open,selectedDeviceId:Pe().realtimeTalkInputDeviceId?.trim()??``,voiceActive:!1,issue:this.devicePicker.issue,showRealtimeCapability:!1,realtimeStatus:this.devicePicker.realtimeStatus,dictationStatus:this.devicePicker.dictationStatus,onOpen:this.devicePicker.handleOpen,onClose:this.devicePicker.handleClose,onSelect:e=>{Le({realtimeTalkInputDeviceId:e.trim()||void 0}),this.devicePicker.handleClose()}}),onDirectDictationStart:()=>this.options.textarea.captureSelection()})}
${bn(s,()=>{n()&&this.options.canCommit()&&this.options.onSubmit()})}
`}}})))()}function Fr(e){let t=e.visibility===`draft`,n=e.submitting||e.messageLocked,r=P(`newSession.draft`);return k`
<button
type="button"
class="new-session-page__visibility new-session-page__visibility--draft ${t?`new-session-page__visibility--active`:``}"
role="switch"
aria-label=${r}
aria-checked=${String(t)}
?disabled=${n}
title=${P(`newSession.draftDescription`)}
@click=${()=>e.onVisibilityChange?.(t?`normal`:`draft`)}
>
<span class="new-session-page__visibility-icon" aria-hidden="true">${M.pencil}</span>
<span class="new-session-page__visibility-label">${r}</span>
</button>
`}function Ir(e,t){let n=e.visibility===`draft`,r=e.submitting||e.messageLocked===!0,i=e.textareaController;return xn({attachments:t,capabilityMenu:e.capabilityMenu,disabled:r,open:i.capabilityMenuOpen,view:i.capabilityMenuView,toolOverrides:e.toolOverrides,rootToggles:e.draftAvailable?[{value:`new-session-draft`,label:P(`newSession.draft`),icon:M.pencil,checked:n,disabled:r,title:P(`newSession.draftDescription`),onChange:t=>e.onVisibilityChange?.(t?`draft`:`normal`)}]:void 0,onOpenChange:t=>{i.capabilityMenuOpen=t,t||(i.capabilityMenuView=`root`),e.requestUpdate()},onViewChange:t=>{i.capabilityMenuView=t,e.requestUpdate()}})}function Lr(e){let t=St(e.toolOverrides);if(t===0)return O;let n=e.submitting||e.messageLocked===!0;return k`
<button
type="button"
class="new-session-page__selection-status"
?disabled=${n}
@click=${()=>{e.textareaController.capabilityMenuView=`root`,e.textareaController.capabilityMenuOpen=!0,e.requestUpdate()}}
>
${P(t===1?`chat.composer.overrides.countOne`:`chat.composer.overrides.count`,{count:String(t)})}
</button>
`}function Rr(){return(Rr=e((()=>{A(),N(),j(),Yt()})))()}function J(e){ln(e.textareaController.skillMenuState),fn(e.textareaController.slashMenuState),e.onSubmit()}function zr(e){let t=e.submitting?P(`newSession.starting`):P(`newSession.start`),n=!e.canSubmit&&e.submitDisabledReason!==void 0;if(!e.terminalAction)return k`
<openclaw-tooltip content=${e.submitDisabledReason??P(`newSession.start`)}>
<button
type="button"
class="chat-send-btn new-session-page__start-submit ${n?`new-session-page__start-submit--blocked`:``}"
?disabled=${!e.canSubmit&&!n}
aria-disabled=${String(!e.canSubmit)}
aria-busy=${String(e.submitting)}
aria-label=${t}
@click=${()=>J(e)}
>
${e.submitting?M.loader:M.arrowUp}
</button>
</openclaw-tooltip>
`;let r=P(`newSession.startInTerminal`);return k`
<div class="new-session-page__start-split">
<openclaw-tooltip content=${e.submitDisabledReason??P(`newSession.start`)}>
<button
type="button"
class="chat-send-btn new-session-page__start-submit new-session-page__start-primary ${n?`new-session-page__start-submit--blocked`:``}"
?disabled=${!e.canSubmit&&!n}
aria-disabled=${String(!e.canSubmit)}
aria-busy=${String(e.submitting)}
aria-label=${t}
@click=${()=>J(e)}
>
${e.submitting?M.loader:M.arrowUp}
</button>
</openclaw-tooltip>
<openclaw-tooltip content=${e.terminalAction.disabledReason??r}>
<button
type="button"
class="chat-send-btn new-session-page__start-menu-trigger"
?disabled=${!e.terminalAction.canStart}
aria-label=${r}
@click=${()=>e.terminalAction?.onStart()}
>
${M.squareTerminal}
</button>
</openclaw-tooltip>
</div>
`}function Br(e,t){return k`
<div class="callout danger new-session-page__error new-session-page__alert" role="alert">
<span class="new-session-page__alert-icon" aria-hidden="true">${M.alertTriangle}</span>
<span class="callout__content new-session-page__alert-message"
>${E(e)}</span
>
${t?k`<button class="btn btn--sm" type="button" @click=${t.onClick}>
${t.label}
</button>`:O}
</div>
`}function Vr(e,t,n,r){t.dictationActive||e.isComposing||e.keyCode===229||On(e,t.textareaController.skillMenuState,n,t.requestUpdate)||yn(e,t.textareaController.slashMenuState,r,t.requestUpdate)||e.key!==`Enter`||e.shiftKey||t.requiresModifier&&!e.metaKey&&!e.ctrlKey||(t.canSubmit||t.submitDisabledReason!==void 0)&&(e.preventDefault(),J(t))}function Hr(e){let t=e.textareaController.skillMenuState,n=e.textareaController.slashMenuState,r={paneId:`new-session`,getDraft:()=>e.textareaController.getTextarea()?.value??e.message,commitDraft:e.onInput,getTextarea:e.textareaController.getTextarea,refreshCommands:e.refreshCommands},i={paneId:r.paneId,getDraft:r.getDraft,commitDraft:r.commitDraft,getTextarea:r.getTextarea,resolveArgOptions:e=>e.argOptions??[],runCommand:()=>J(e),canRunInlineCommand:()=>!1,refreshCommands:e.refreshCommands,commandFilter:e=>e.executeLocal!==!0},a=a=>{Sn(a.value,n,i,e.requestUpdate),Ln(a.value,a.selectionStart,t,r,e.requestUpdate)},o=a=>{let o=a.currentTarget;o instanceof HTMLTextAreaElement&&(Sn(o.value,n,i,e.requestUpdate),Ln(o.value,o.selectionStart,t,r,e.requestUpdate))},s=e.submitting||e.messageLocked===!0||e.dictationActive===!0,c={attachmentLimits:e.attachmentLimits,attachments:e.attachments,disabled:s,getAttachments:e.getAttachments,draft:e.message,getDraft:()=>e.message,onAttachmentsChange:e.onAttachmentsChange,onDraftChange:e.onInput,onPendingReadsChange:e.onPendingReadsChange,onOpenImage:e.onOpenImage,readSignal:e.readSignal},l=cn({...c,canCompose:!s}),u=e.dictationPreview??e.message;e.textareaController.syncDraft(u);let d=P(`newSession.messagePlaceholder`),f=e.dictationActive?``:e.textareaController.getPlaceholder(d,e.message,e.requestUpdate),p=!s&&vn(t),m=!s&&Dn(n),h=p||m,g=It(r.paneId,p?`skill-menu-listbox`:`slash-menu-listbox`),_=p?mn(t,r.paneId):En(n,i.paneId),v=p?gn(t):An(n),y=It(r.paneId,`active-menu-announcement`);return k`
<div
class="agent-chat__composer-shell new-session-page__composer"
@drop=${l.onDrop}
@dragenter=${l.onDragenter}
@dragleave=${l.onDragleave}
@dragover=${l.onDragover}
>
<div
class="agent-chat__input agent-chat__input--mobile-toolbar${e.dictationActive?` agent-chat__input--dictating`:``}"
>
${Nn(c)} ${hn(c)}
<div class="agent-chat__composer-lede">${e.dictationStatus??O}</div>
<div class="agent-chat__composer-input-row">
<div class="agent-chat__composer-combobox">
${m?jn(n,i,e.message,e.requestUpdate):O}
${p?_n(t,r,e.requestUpdate):O}
<textarea
${De(e.textareaController.ref)}
class="new-session-page__message"
rows="1"
?autofocus=${globalThis.matchMedia?.(`(max-width: 560px)`)?.matches??!1}
?disabled=${e.submitting||e.messageLocked}
?readonly=${e.dictationActive}
placeholder=${f}
aria-label=${d}
.value=${u}
aria-autocomplete="list"
aria-controls=${Se(h?g:void 0)}
aria-expanded=${Se(h?`true`:void 0)}
aria-activedescendant=${Se(_??void 0)}
aria-describedby=${y}
@input=${t=>{if(e.dictationActive)return;let n=t.target;Bn(n),a(n),e.onInput(n.value)}}
@select=${o}
@keydown=${t=>Vr(t,e,r,i)}
@paste=${e=>{s||$t(e,c)}}
></textarea>
<span
id=${y}
class="sr-only"
role="status"
aria-live="polite"
aria-atomic="true"
>${v}</span
>
</div>
</div>
<div class="agent-chat__composer-footer">
<div class="agent-chat__composer-lead">
${Ir(e,c)}
${e.permissionControl??O}
${e.draftAvailable?Fr(e):O}
${Lr(e)}
</div>
<div class="agent-chat__composer-trail">
<div class="agent-chat__composer-controls">
${e.modelControl&&e.modelControl!==O?k`<div class="chat-composer-model-control">${e.modelControl}</div>`:O}
</div>
<div class="agent-chat__composer-actions">
${e.voiceControl??O}${e.dictationActive?O:zr(e)}
</div>
</div>
</div>
${e.pendingAttachmentReads>0?k`<span class="sr-only" role="status">${P(`newSession.readingAttachment`)}</span>`:O}
</div>
${e.blockedSubmitNotice?k`<div
class="new-session-page__blocked-submit agent-chat__composer-underlaps"
data-tone="info"
role="status"
>
<div class="agent-chat__composer-status-band">
<span class="agent-chat__composer-status-icon" aria-hidden="true">${M.info}</span>
<span class="agent-chat__composer-status-text">${e.blockedSubmitNotice}</span>
</div>
</div>`:O}
</div>
`}var Ur;function Y(){return(Y=e((()=>{A(),xe(),Te(),N(),j(),Ke(),he(),Mt(),zn(),wn(),un(),en(),Rr(),Ur=class{constructor(){this.textarea=null,this.placeholderFrame=null,this.placeholderStartedAt=null,this.placeholderText=``,this.placeholderTarget=``,this.placeholderEntered=!1,this.capturedSelection=null,this.skillCommandClient=null,this.skillCommandAgentId=``,this.skillCommandDraftOwnerKey=``,this.skillMenuState=In(),this.slashMenuState=Fn(),this.capabilityMenuOpen=!1,this.capabilityMenuView=`root`,this.ref=e=>{let t=e instanceof HTMLTextAreaElement?e:null;this.textarea&&this.textarea!==t&&dn(this.textarea),this.textarea&&!t&&this.resetPlaceholder(),this.textarea=t,t&&(nn(t),Rn(t))},this.getTextarea=()=>this.textarea}syncDraft(e){this.textarea?.isConnected&&this.textarea.value!==e&&Rn(this.textarea)}getPlaceholder(e,t,n){if(t.length>0||this.placeholderEntered)return this.placeholderEntered=!0,this.placeholderFrame!==null&&(globalThis.cancelAnimationFrame?.(this.placeholderFrame),this.placeholderFrame=null),e;this.placeholderTarget!==e&&(this.resetPlaceholder(),this.placeholderTarget=e);let r=globalThis.requestAnimationFrame?.bind(globalThis);if(!r||(globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1))return this.placeholderText=e,this.placeholderEntered=!0,e;if(this.placeholderFrame===null){let t=i=>{this.placeholderStartedAt??=i;let a=Math.max(0,i-this.placeholderStartedAt-180),o=Math.min(e.length,Math.floor(a/26));if(o!==this.placeholderText.length&&(this.placeholderText=e.slice(0,o),n()),o<e.length){this.placeholderFrame=r(t);return}this.placeholderFrame=null,this.placeholderEntered=!0};this.placeholderFrame=r(t)}return this.placeholderText}resetPlaceholder(){this.placeholderFrame!==null&&(globalThis.cancelAnimationFrame?.(this.placeholderFrame),this.placeholderFrame=null),this.placeholderStartedAt=null,this.placeholderText=``,this.placeholderTarget=``,this.placeholderEntered=!1}captureSelection(){let e=this.textarea;this.capturedSelection=e?{start:e.selectionStart,end:e.selectionEnd,value:e.value}:null}previewTranscript(e){let t=this.textarea;if(!t)return;let n=this.capturedSelection??{start:t.selectionStart,end:t.selectionEnd,value:t.value};return Vn(n.value,e,n.start,n.end).value}insertTranscript(e){let t=this.textarea;if(!t)return null;let n=this.capturedSelection??{start:t.value.length,end:t.value.length,value:t.value};this.capturedSelection=null;let r=Vn(n.value,e,n.start,n.end);return r.value===n.value?null:(t.value=r.value,Bn(t),queueMicrotask(()=>{t.isConnected&&(t.focus({preventScroll:!0}),t.selectionStart=r.caret,t.selectionEnd=r.caret)}),r.value)}syncSkillCommandOwner(e,t,n){let r=t.trim();(this.skillCommandClient!==e||this.skillCommandAgentId!==r||this.skillCommandDraftOwnerKey!==n)&&(this.skillCommandClient=e,this.skillCommandAgentId=r,this.skillCommandDraftOwnerKey=n,ln(this.skillMenuState))}ownsSkillCommands(e,t,n){return this.skillCommandClient===e&&this.skillCommandAgentId===t.trim()&&this.skillCommandDraftOwnerKey===n}disconnect(){this.resetPlaceholder(),this.skillCommandClient=null,this.skillCommandAgentId=``,this.skillCommandDraftOwnerKey=``,ln(this.skillMenuState),fn(this.slashMenuState),this.capabilityMenuOpen=!1,this.capabilityMenuView=`root`,this.textarea&&=(dn(this.textarea),null)}}})))()}function Wr(e){return/^[A-Za-z0-9_/:=.,@%+-]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`}function Gr(e){if(!e.open)return O;let t=P(`newSession.connectMachineTitle`),n=e.setup?.joinUrl?.trim(),r=n?`npx openclaw connect ${Wr(n)}`:null,i=e.setup?.expiresAtMs?ne(e.setup.expiresAtMs,{hour:`numeric`,minute:`2-digit`},``):``;return k`
<openclaw-modal-dialog
class="connect-machine-dialog"
label=${t}
description=${P(`newSession.connectMachineDescription`)}
@modal-cancel=${e.onClose}
>
<section class="exec-approval-card connect-machine-dialog__card">
<header class="exec-approval-header">
<div>
<h2 class="exec-approval-title">${t}</h2>
<p class="exec-approval-sub">${P(`newSession.connectMachineDescription`)}</p>
</div>
<button
class="btn btn--icon btn--ghost"
type="button"
aria-label=${P(`common.dismiss`)}
@click=${e.onClose}
>
${M.x}
</button>
</header>
<div class="connect-machine-dialog__body">
${e.loading&&!r?k`<p class="connect-machine-dialog__status" role="status">
${P(`newSession.connectMachineGenerating`)}
</p>`:O}
${e.error?k`<p class="exec-approval-error" role="alert">
${P(`newSession.connectMachineFailed`)} ${e.error}
</p>`:O}
${r?k`
${Ye(r)}
<p class="connect-machine-dialog__hint">
${P(`newSession.connectMachineTeamHint`)}
</p>
<p class="connect-machine-dialog__hint">
${i?P(`newSession.connectMachineSingleUseExpires`,{time:i}):P(`newSession.connectMachineSingleUse`)}
</p>
`:O}
</div>
<footer class="exec-approval-actions connect-machine-dialog__actions">
${r||e.error?k`<button
class="btn"
type="button"
?disabled=${e.loading}
@click=${e.onRefresh}
>
${M.refresh}
${e.loading?P(`newSession.connectMachineRefreshing`):P(`newSession.connectMachineFreshCode`)}
</button>`:O}
<button class="btn btn--ghost" type="button" @click=${e.onManageDevices}>
${P(`newSession.connectMachineManageDevices`)}
</button>
</footer>
</section>
</openclaw-modal-dialog>
`}var Kr;function qr(){return(qr=e((()=>{A(),qe(),N(),Je(),j(),d(),he(),ve(),Kr=class{constructor(e,t){this.gateway=e,this.requestUpdate=t,this.openValue=!1,this.loadingValue=!1,this.errorValue=null,this.setupValue=null,this.requestId=0}get open(){return this.openValue}get loading(){return this.loadingValue}get error(){return this.errorValue}get setup(){return this.setupValue}start(){this.openValue=!0,this.errorValue=null,this.setupValue=null,this.requestUpdate(),this.refresh()}close(){this.requestId+=1,this.openValue=!1,this.loadingValue=!1,this.errorValue=null,this.setupValue=null}async refresh(){if(!this.openValue||this.loadingValue)return;let{client:e,connected:t}=this.gateway();if(!t||!e){this.errorValue=P(`newSession.connectMachineUnavailable`),this.requestUpdate();return}let n=++this.requestId;this.loadingValue=!0,this.errorValue=null,this.requestUpdate();try{let t=await te(e);if(!this.stillCurrent(n,e))return;if(!t.joinUrl?.trim()){this.setupValue=null,this.errorValue=P(`newSession.connectMachineMissingUrl`);return}this.setupValue=t}catch(t){this.stillCurrent(n,e)&&(this.errorValue=E(t))}finally{n===this.requestId&&(this.loadingValue=!1,this.requestUpdate())}}stillCurrent(e,t){let n=this.gateway();return e===this.requestId&&t===n.client&&n.connected&&this.openValue}}})))()}function Jr(e){return e.allowedVisibilities?.includes(`draft`)===!0&&e.hasMultipleIdentities===!0}function Yr(e){let t=e.trim();return!t||Zr.test(t)}function Xr(e){let t=c(e.cwd),r=c(e.workspace),i=c(e.catalogId),a=c(e.category),o=c(e.model),s=c(e.contextWindow),l=c(e.thinkingLevel),u=c(e.projectId),d=!u&&(e.message.trim()||e.attachments?.length)?c(e.projectGitUrl):void 0,f=!u&&!d&&t&&t!==r?t:void 0;return{...c(e.key)?{key:c(e.key)}:{},agentId:n(e.agentId),message:e.message,...e.visibility===`incognito`?{incognito:!0}:{},...e.visibility===`draft`?{visibility:`draft`}:{},...e.attachments?.length?{attachments:e.attachments}:{},...i?{catalogId:i}:{},...a?{category:a}:{},...!i&&o?{model:o}:{},...!i&&s?{contextWindow:s}:{},...!i&&l?{thinkingLevel:l}:{},...!i&&e.fastMode!==void 0?{fastMode:e.fastMode}:{},...e.toolOverrides?{toolOverrides:e.toolOverrides}:{},...e.permissionMode?{permissionMode:e.permissionMode}:{},...u?{projectId:u}:{},...d?{projectGitUrl:d}:{},...f?{cwd:f}:{},...e.worktree?{worktree:!0,...c(e.baseRef)?{worktreeBaseRef:c(e.baseRef)}:{},...c(e.worktreeName)?{worktreeName:c(e.worktreeName)}:{}}:{}}}var Zr;function X(){return(X=e((()=>{T(),Zr=/^[a-z0-9][a-z0-9-]{0,63}$/})))()}function Qr(e){return e.destination===`remote`||!e.worktreeAvailable&&!e.worktree?null:{label:e.worktree?P(`newSession.worktree`):P(`newSession.runsDirectly`)}}function $r(e){return k`
<label class="new-session-page__menu-field">
<span>${P(`newSession.baseBranch`)}</span>
<input
type="text"
list="new-session-branches"
?disabled=${e.submitting||e.pendingPlacement}
placeholder=${e.branchesLoading?P(`common.loading`):e.branches?.defaultBranch??P(`newSession.baseBranch`)}
.value=${e.baseRef}
@input=${t=>e.onBaseRefInput(t.target.value.trim())}
/>
<datalist id="new-session-branches">
${(e.branches?.branches??[]).map(e=>k`<option value=${e.name}></option>`)}
</datalist>
</label>
<label class="new-session-page__menu-field">
<span>${e.worktreeNameLabel??P(`newSession.worktreeName`)}</span>
<input
type="text"
?disabled=${e.submitting||e.pendingPlacement}
placeholder=${P(`newSession.worktreeNamePlaceholder`)}
.value=${e.worktreeName}
@input=${t=>e.onWorktreeNameInput(t.target.value.trim())}
/>
</label>
`}function ei(e){let t=e.worktreeAvailable||e.worktree;return k`
<span class="new-session-page__select">
<button
id="new-session-detail-trigger"
type="button"
class="new-session-page__trigger ${e.popoverHiding?`new-session-page__trigger--hiding`:``}"
title=${P(`newSession.detail`)}
aria-label="${P(`newSession.detail`)}: ${e.state.label}"
data-worktree=${String(e.worktree)}
aria-haspopup="dialog"
aria-expanded=${String(e.popoverOpen)}
?disabled=${e.submitting||e.pendingPlacement}
@click=${e.onGuardTransition}
>
<span class="new-session-page__target-icon" aria-hidden="true">${M.gitBranch}</span>
<span class="new-session-page__trigger-label">${e.state.label}</span>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--desktop"
aria-hidden="true"
>${M.chevronDown}</span
>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--mobile"
aria-hidden="true"
>${M.chevronsUpDown}</span
>
</button>
</span>
<wa-popover
class="new-session-page__select new-session-page__detail-popover new-session-page__picker-popover"
for="new-session-detail-trigger"
placement="bottom-start"
without-arrow
@wa-show=${e.onPopoverShow}
@wa-hide=${e.onPopoverHide}
@wa-after-hide=${e.onPopoverAfterHide}
>
<div class="new-session-page__picker-root">
<div class="new-session-page__menu-title">${P(`newSession.branches`)}</div>
${H({value:`worktree`,label:P(`newSession.worktree`),checked:e.worktree,disabled:!t,title:e.worktreeAvailable?P(`chat.runControls.newSessionWorktree`):e.repositoryUnavailable?P(`newSession.gitCheckUnavailable`):P(`newSession.worktreeUnavailable`),onSelect:e.onToggleWorktree,keepOpen:!0},e.submitting)}
${e.worktree?$r(e):k`<div class="new-session-page__menu-note">
${P(`newSession.runsDirectlyNote`)}
</div>`}
</div>
</wa-popover>
`}function ti(){return(ti=e((()=>{A(),N(),j(),nr()})))()}function ni(e){let t=e.attachmentDraft.readSignal,n=e.context?.gateway.snapshot.client??null;return e.textareaController.syncSkillCommandOwner(n,e.agentId,e.draftOwnerKey),Hr({attachmentLimits:e.context?.gateway.snapshot.hello?.policy?.attachments,attachments:e.attachmentDraft.attachments,canSubmit:e.canSubmit,getAttachments:()=>e.attachmentDraft.attachments,message:e.message,visibility:e.visibility,draftAvailable:e.draftAvailable,capabilityMenu:e.capabilityMenu,toolOverrides:e.toolOverrides,modelControl:e.isCatalogTarget?O:e.modelControl.render({agent:e.agent,agentId:e.agentId,context:e.context,sending:e.submitting}),permissionControl:e.permissionControl,pendingAttachmentReads:e.attachmentDraft.pendingReads,readSignal:t,requiresModifier:e.requiresModifier,requestUpdate:e.requestUpdate,refreshCommands:n?()=>Kn({client:n,agentId:e.agentId,shouldApply:()=>e.textareaController.ownsSkillCommands(n,e.agentId,e.draftOwnerKey)}):void 0,submitDisabledReason:e.submitDisabledReason,blockedSubmitNotice:e.blockedSubmitNotice,dictationActive:e.dictationActive,dictationPreview:e.dictationPreview,dictationStatus:e.dictationStatus,terminalAction:e.terminalAction,submitting:e.submitting,textareaController:e.textareaController,voiceControl:e.voiceControl,messageLocked:e.messageLocked,onAttachmentsChange:t=>{!e.submitting&&!e.messageLocked&&e.attachmentDraft.replace(t)},onPendingReadsChange:n=>e.attachmentDraft.updatePending(t,n),onInput:e.onInput,onOpenImage:e.onOpenImage,onVisibilityChange:e.onVisibilityChange,onSubmit:e.onSubmit})}function ri(){return(ri=e((()=>{A(),Jn(),Y()})))()}async function ii(e,t,n){if(!e||!t)return``;try{let t=await e.request(`system.info`,{},{signal:n});return c(t.machineName)??c(t.hostname)?.split(`.`,1)[0]??``}catch{return``}}function ai(){return(ai=e((()=>{})))()}function oi(e){return e.cloudProfileId?{kind:`cloud`,id:e.cloudProfileId}:e.deviceId?{kind:`device`,id:e.deviceId}:e.autoDevice?{kind:`auto-device`}:{kind:`local`}}function si(e){return`${gi}${u(e)}`}function Z(e){if(!l(e))return null;let t=e,n=c(t.workspace),r=c(t.folder),i=c(t.projectId),a=c(t.baseRef),o=c(t.worktreeName),s=c(t.model),u=c(t.thinkingLevel),d=typeof t.worktree==`boolean`?t.worktree:void 0,f=ci(t.where);return!n&&!r&&!f&&!i&&d===void 0&&!a&&!o&&!s&&!u?null:{...n?{workspace:n}:{},...r?{folder:r}:{},...f?{where:f}:{},...i?{projectId:i}:{},...d===void 0?{}:{worktree:d},...a?{baseRef:a}:{},...o?{worktreeName:o}:{},...s?{model:s}:{},...u?{thinkingLevel:u}:{}}}function ci(e){if(!l(e)||typeof e.kind!=`string`)return;if(e.kind===`local`||e.kind===`auto-device`)return{kind:e.kind};let t=c(e.id);return t&&(e.kind===`device`||e.kind===`cloud`)?{kind:e.kind,id:t}:void 0}function li(e,t){try{let n=JSON.parse(e.getItem(si(t))??`null`);return l(n)?n:{}}catch{return{}}}function ui(e,t){let r=D(),i=n(t);return!r||!e||!i?null:Z(li(r,e).agents?.[i])}function di(e){let t=D();if(!t||!e)return{};let r=Object.entries(li(t,e).agents??{}).flatMap(([e,t])=>{let r=n(e),i=Z(t);return r&&i?[[r,i]]:[]});return Object.fromEntries(r)}function fi(e){return Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[`${_i}${e}`,t]))}function pi(e){return Object.fromEntries(Object.entries(e).flatMap(([e,t])=>{if(!e.startsWith(_i))return[];let r=n(e.slice(15)),i=Z(t);return r&&i?[[r,i]]:[]}))}function mi(e,t,r){let i=D(),a=n(t),o=Z(r);if(!i||!e||!a||!o)return;let s=li(i,e);try{i.setItem(si(e),JSON.stringify({...s,agents:{...s.agents,[a]:o}}))}catch{}}function hi(e,t,r){let i=D(),a=n(t);if(!i||!e||!a)return;let o=li(i,e),s=Z({...Z(o.agents?.[a])??{},...r});if(s)try{i.setItem(si(e),JSON.stringify({...o,agents:{...o.agents,[a]:s}}))}catch{}}var gi,_i,vi;function yi(){return(yi=e((()=>{T(),gi=`openclaw.new-session.preferences.v1:`,_i=`new-session.v1:`,vi=`new-session.migration.v1`})))()}function bi(e){return e.gatewayIdentityChanged||!e.placementDraftOwned?`gateway-changed`:`placement-interrupted`}function xi(e,t,n){let r=e.connected&&e.client?.recoveryScopeReady?e.client.recoveryScope??``:t;return{next:r,changed:!n&&e.connected&&t!==r}}var Si;function Ci(){return(Ci=e((()=>{ot(),fe(),Si=class{constructor(){this.sessionKey=``,this.messageId=``,this.message=``,this.target=null,this.agentId=``,this.gatewayUrl=``,this.recoveryScope=``,this.phase=`dispatching`,this.retryAllowed=!1,this.restored=!1,this.persistent=!0}clear(){this.persistent&&vt(this.gatewayUrl,this.recoveryScope,this.sessionKey,this.messageId),this.reset()}owns(e,t,n){return this.gatewayUrl===e&&this.recoveryScope===t&&this.sessionKey===n}reset(){this.sessionKey=``,this.messageId=``,this.message=``,this.attachments=void 0,this.target=null,this.agentId=``,this.gatewayUrl=``,this.recoveryScope=``,this.phase=`dispatching`,this.createParams=void 0,this.retryAllowed=!1,this.restored=!1,this.persistent=!0}restore(e,t){let n=Ot(e,t).find(e=>e.phase===`creating`);return!n||n.phase!==`creating`?null:(this.apply(n,!0,!0),n)}capture(){return this.snapshot(this.sessionKey,this.phase)}stageCreate(e){let t=`agent:${e.agentId}:dashboard:${f()}`,n=ct({...e.createParams,key:t},t,e.agentId);if(!n)return null;let r=e.persistent!==!1;r||delete n.key;let i={sessionKey:t,messageId:f(),message:e.message,attachments:e.attachments,target:e.target,agentId:e.agentId,gatewayUrl:e.gatewayUrl,recoveryScope:e.recoveryScope,phase:`creating`,createParams:n};return r&&!mt(i)?null:(this.apply(i,!1,r),n)}promoteToDispatching(e){let t=this.sessionKey,n=this.snapshot(e,`dispatching`);return!n||this.persistent&&!st(t,n)?!1:(this.sessionKey=e,this.phase=`dispatching`,this.createParams=void 0,!0)}snapshot(e,t){return!this.sessionKey||!this.messageId||!this.target||!this.agentId||t===`creating`&&!this.createParams?null:{sessionKey:e,messageId:this.messageId,message:this.message,attachments:this.attachments?[...this.attachments]:void 0,target:{...this.target},agentId:this.agentId,gatewayUrl:this.gatewayUrl,recoveryScope:this.recoveryScope,phase:t,...t===`creating`&&this.createParams?{createParams:{...this.createParams}}:{}}}apply(e,t,n){this.sessionKey=e.sessionKey,this.messageId=e.messageId,this.message=e.message,this.attachments=e.attachments,this.target={...e.target},this.agentId=e.agentId,this.gatewayUrl=e.gatewayUrl,this.recoveryScope=e.recoveryScope,this.phase=e.phase,this.createParams=e.createParams,this.retryAllowed=!0,this.restored=t,this.persistent=n}}})))()}var wi,Ti;function Ei(){return(Ei=e((()=>{Ze(),Me(),j(),R(),T(),G(),tr(),ai(),yi(),Ci(),wi=[0,1e3,3e3],Ti=class{constructor(e,t,n){this.read=t,this.callbacks=n,this.cloudProfilesValue=[],this.environmentsValue=null,this.cloudProfilesReadyValue=!1,this.catalogRetryingValue=!1,this.gatewaySource=null,this.gatewayClientValue=null,this.gatewayUrlValue=``,this.gatewayBootIdValue=``,this.gatewayRecoveryScopeValue=``,this.gatewayRecoveryScopeReady=!1,this.gatewayConnectedValue=!1,this.gatewayConnectionEpochValue=0,this.catalogRetryScope=``,this.catalogRetryAttempt=0,this.cloudProfileRetryAttempt=0,this.preferenceScope=``,this.preferenceModeValue=`local`,this.identityPreferences={},this.preferenceLoad=Promise.resolve(),this.preferenceWrite=Promise.resolve(),this.handleCatalogRetry=()=>{let{context:e,data:t}=this.read();if(this.catalogRetryingValue||!this.gatewayConnectedValue||t?.group&&e?.sessions.groupsStatus()===`loading`||!K(t,e?.sessions))return;t?.group&&e?.sessions.groupsInvalidate();let n=e?.revalidate(`new-session`);n&&(globalThis.clearTimeout(this.catalogRetryTimer),this.catalogRetryTimer=void 0,this.catalogRetryingValue=!0,this.callbacks.requestUpdate(),n.catch(()=>void 0).then(()=>this.callbacks.updateComplete()).finally(()=>{this.catalogRetryingValue=!1,this.retryPendingCatalogTarget(),this.callbacks.requestUpdate()}))},this.gatewayNameTask=new Qe(e,{args:()=>[this.read().isConnected&&this.gatewayConnectedValue?this.gatewayClientValue:null,I(this.read().context?.gateway.snapshot??{},`system.info`)===!0,this.gatewayConnectionEpochValue],task:([e,t,n],{signal:r})=>ii(e,t,r)}),this.cloudProfileTask=new Qe(e,{args:()=>[this.read().isConnected&&this.gatewayConnectedValue?this.gatewayClientValue:null,this.gatewayConnectionEpochValue,Ue(this.read().context?.gateway.snapshot.hello?.auth??null),this.read().isAdmin,this.gatewayRecoveryScopeValue],task:([e,t,n,r])=>e?Xn(e,n,r):et,onComplete:e=>{this.resetCloudProfileRetry(),this.environmentsValue=e.environments,this.applyCloudProfiles(e.profiles),this.cloudProfilesReadyValue=!0,this.callbacks.requestUpdate()},onError:()=>{this.scheduleCloudProfileRetry(),this.callbacks.requestUpdate()}})}get gatewayName(){return this.gatewayNameTask.status===F.COMPLETE?this.gatewayNameTask.value??``:``}get cloudProfiles(){return this.cloudProfilesValue}get environments(){return this.environmentsValue}get cloudProfilesReady(){return this.cloudProfilesReadyValue}get cloudProfilesPending(){return this.cloudProfileTask.status===F.PENDING}get deviceCatalogDisabledReason(){return this.cloudProfilesReadyValue&&this.cloudProfileTask.status===F.COMPLETE?void 0:P(`newSession.placementNotReady`)}get catalogRetrying(){return this.catalogRetryingValue}get client(){return this.gatewayClientValue}get gatewayUrl(){return this.gatewayUrlValue}get recoveryScope(){return this.gatewayRecoveryScopeValue}get sessionCreateScope(){let e=[this.gatewayUrlValue,this.gatewayRecoveryScopeValue,this.gatewayBootIdValue];return e.every(Boolean)?JSON.stringify(e):``}get connected(){return this.gatewayConnectedValue}get connectionEpoch(){return this.gatewayConnectionEpochValue}get preferenceLoading(){return this.preferenceModeValue===`loading`}resolvedGroupCategory(){let e=this.read();return I(e.context?.gateway.snapshot??{},`sessions.groups.defaults`)===!0?Er(e.data,e.context?.sessions):void 0}refreshCloudProfiles(){return this.cloudProfileTask.run()}synchronize(e){let t=e.snapshot,n=t.phase===`connected`,r=this.gatewaySource===null,i=n?t.hello?.server?.bootId?.trim()??``:this.gatewayBootIdValue,a=!r&&n&&!!this.gatewayBootIdValue&&i!==this.gatewayBootIdValue,o=!r&&this.gatewayUrlValue!==e.connection.gatewayUrl,s=!r&&this.gatewaySource!==e,c=!r&&(s||this.gatewayClientValue!==t.client),l=!r&&this.gatewayConnectedValue!==n,u=n&&(c||!this.gatewayConnectedValue),d=n&&t.client?.recoveryScopeReady===!0&&!this.gatewayRecoveryScopeReady,f=xi({client:t.client,connected:n},this.gatewayRecoveryScopeValue,r);if(this.gatewaySource=e,this.gatewayClientValue=t.client,this.gatewayUrlValue=e.connection.gatewayUrl,this.gatewayBootIdValue=i,this.gatewayRecoveryScopeValue=f.next,this.gatewayRecoveryScopeReady=t.client?.recoveryScopeReady===!0,this.gatewayConnectedValue=n,this.read().visibility===`draft`&&!this.read().canStartAsDraft&&this.callbacks.onVisibilityRetired(),o||a||c||l||f.changed){let e=s||o||f.changed,t=o||f.changed;this.invalidateDiscovery(e,bi({gatewayIdentityChanged:t,placementDraftOwned:!!this.read().pendingPlacement.sessionKey}))}if(r||o||f.changed||d||u){let e=this.read().pendingPlacement;e.gatewayUrl&&(e.gatewayUrl!==this.gatewayUrlValue||e.recoveryScope!==this.gatewayRecoveryScopeValue)&&this.callbacks.onPendingPlacementReset(),n&&t.client?.recoveryScopeReady&&this.callbacks.onRecoveryReady(this.gatewayUrlValue,this.gatewayRecoveryScopeValue)}u&&(this.gatewayConnectionEpochValue+=1,this.retryPendingCatalogTarget()),this.synchronizeIdentityPreferences(t.selfUser?.id),this.callbacks.requestUpdate()}invalidateDiscovery(e,t){this.cloudProfilesValue=[],this.cloudProfilesReadyValue=!1,e&&(this.environmentsValue=null),this.resetCloudProfileRetry(),this.callbacks.onInvalidate(e,t),this.callbacks.requestUpdate()}retryPendingCatalogTarget(){let{context:e,data:t}=this.read();if(this.catalogRetryingValue)return;if(t?.group&&e?.sessions.groupsStatus()===`loading`){globalThis.clearTimeout(this.catalogRetryTimer),this.catalogRetryTimer=void 0;return}if(!this.gatewayConnectedValue||!K(t,e?.sessions)){globalThis.clearTimeout(this.catalogRetryTimer),this.catalogRetryTimer=void 0,this.catalogRetryScope=``,this.catalogRetryAttempt=0;return}let n=`${this.gatewayConnectionEpochValue}:${W(t)}`;if(this.catalogRetryScope!==n&&(globalThis.clearTimeout(this.catalogRetryTimer),this.catalogRetryTimer=void 0,this.catalogRetryScope=n,this.catalogRetryAttempt=0),this.catalogRetryTimer||this.catalogRetryAttempt>=wi.length)return;let r=wi[this.catalogRetryAttempt];this.catalogRetryAttempt+=1,this.catalogRetryTimer=globalThis.setTimeout(()=>{this.catalogRetryTimer=void 0;let e=this.read();if(this.catalogRetryScope!==n||!this.gatewayConnectedValue||e.data?.group&&e.context?.sessions.groupsStatus()===`loading`||!K(e.data,e.context?.sessions))return;e.data?.group&&e.context?.sessions.groupsInvalidate();let t=e.context?.revalidate(`new-session`);t&&t.catch(()=>void 0).then(()=>this.callbacks.updateComplete()).then(()=>this.retryPendingCatalogTarget())},r)}readPreference(e){let t=this.read();return q(t.data)||t.data?.group||t.pendingPlacement.sessionKey?null:this.preferenceModeValue===`remote`?this.identityPreferences[n(e)]??null:ui(this.gatewayUrlValue,e)}persistPreference(e,t,r){let i=this.read();if(q(i.data)||i.data?.group||i.pendingPlacement.sessionKey)return;let a=n(e),o={workspace:t,...r};if(this.preferenceModeValue===`local`){hi(this.gatewayUrlValue,a,o);return}let s=this.preferenceScope,c=this.gatewayClientValue,l=this.gatewayUrlValue,u=async()=>{if(await this.preferenceLoad,!c||this.preferenceScope!==s)return;if(this.preferenceModeValue===`local`){hi(l,a,o);return}let e={...this.identityPreferences[a],...o};try{if((await c.request(`users.prefs.set`,{entries:fi({[a]:e})})).status!==`ok`||this.preferenceScope!==s)return;this.identityPreferences={...this.identityPreferences,[a]:e},mi(l,a,e),this.callbacks.requestUpdate()}catch{}};this.preferenceWrite=this.preferenceWrite.then(u,u)}disconnect(){this.gatewaySource=null,this.gatewayClientValue=null,this.gatewayConnectedValue=!1,this.gatewayConnectionEpochValue=0,this.catalogRetryScope=``,this.catalogRetryAttempt=0,globalThis.clearTimeout(this.catalogRetryTimer),this.catalogRetryTimer=void 0,this.gatewayNameTask.run([null,!1,-1]),this.cloudProfileTask.run([null,-1,!1,!1,``]),this.resetCloudProfileRetry()}applyCloudProfiles(e){let t=Zn(e,this.gatewayClientValue,this.gatewayRecoveryScopeValue);this.cloudProfilesValue=t.profiles;let n=this.read(),r=!!n.pendingPlacement.sessionKey,i=Ue(n.context?.gateway.snapshot.hello?.auth??null);(!this.gatewayConnectedValue||!i)&&!r&&this.callbacks.onCloudProfileCleared(),!r&&n.cloudProfileId&&!e.some(e=>e.id===n.cloudProfileId)?this.callbacks.onCloudState(P(`newSession.catalogUnavailable`)):t.unsupported?this.callbacks.onCloudState(P(`newSession.cloudRecoveryUnavailable`)):this.callbacks.onCloudState(null)}resetCloudProfileRetry(){globalThis.clearTimeout(this.cloudProfileRetryTimer),this.cloudProfileRetryTimer=void 0,this.cloudProfileRetryAttempt=0}scheduleCloudProfileRetry(){if(this.cloudProfileRetryTimer||!this.gatewayConnectedValue||!this.gatewayClientValue)return;if(this.cloudProfileRetryAttempt>=ar.length){this.cloudProfilesReadyValue||=(this.applyCloudProfiles([]),!0);return}let e=ar[this.cloudProfileRetryAttempt];this.cloudProfileRetryAttempt+=1,this.cloudProfileRetryTimer=globalThis.setTimeout(()=>{this.cloudProfileRetryTimer=void 0,this.gatewayConnectedValue&&this.cloudProfileTask.run()},e)}synchronizeIdentityPreferences(e){let t=this.gatewayConnectedValue?this.gatewayClientValue:null,n=this.read().context,r=n&&I(n.gateway.snapshot,`users.prefs.get`)===!0&&I(n.gateway.snapshot,`users.prefs.set`)===!0,i=t&&e&&r?`${this.gatewayConnectionEpochValue}\0${e}`:`local`;if(i!==this.preferenceScope){if(this.preferenceScope=i,this.identityPreferences={},!t||!e||!r){this.preferenceModeValue=`local`,this.preferenceLoad=Promise.resolve();return}this.preferenceModeValue=`loading`,this.preferenceLoad=this.loadIdentityPreferences({client:t,gatewayUrl:this.gatewayUrlValue,scope:i})}}async loadIdentityPreferences(e){try{let t=await e.client.request(`users.prefs.get`,{});if(this.preferenceScope!==e.scope)return;if(t.status!==`ok`){this.preferenceModeValue=`local`;return}let n=pi(t.entries),r=di(e.gatewayUrl);if(t.entries[`new-session.migration.v1`]!==!0){let t=Object.fromEntries(Object.entries(r).filter(([e])=>!Object.hasOwn(n,e))),i=[...Object.entries(fi(t)),[vi,!0]],a=!1;for(let t=0;t<i.length;t+=32){let r=Object.fromEntries(i.slice(t,t+32)),o;try{o=await e.client.request(`users.prefs.set`,{entries:r})}catch{a=!0;break}if(this.preferenceScope!==e.scope)return;if(o.status!==`ok`){a=!0;break}Object.assign(n,pi(r))}a&&(n={...r,...n})}this.identityPreferences=n,this.preferenceModeValue=`remote`;for(let[t,r]of Object.entries(n))mi(e.gatewayUrl,t,r);this.read().agentsHydrated&&this.callbacks.onAdoptAgentDefaults(),this.callbacks.requestUpdate()}catch{this.preferenceScope===e.scope&&(this.preferenceModeValue=`local`,this.callbacks.requestUpdate())}}}})))()}var Di=t({activateDraft:()=>Ai,restoreDraft:()=>ki,restoreDraftOwner:()=>ji,retainDraft:()=>Oi});function Oi(e,t,n,r){t.draftPersistence.persistNow();let i=e?.gateway.snapshot.client;if(!e||!i||t.submitting||t.pendingPlacement.sessionKey)return;let a=n??kr(window.location.search);e.chatAttachmentHandoff.prepare({owner:i,paneId:Mi,scopeKey:a,message:r===a?t.message:``,attachments:t.attachmentDraft.take(),fallbacks:{}})}function ki(e,t,n,r){t.draftPersistence.selectRoute(n);let i=e?.gateway.snapshot.client,a=e&&i?e.chatAttachmentHandoff.consume({owner:i,paneId:Mi,scopeKey:n}):null;return a?t.restoreDraftState({message:r||a.message||``,attachments:a.attachments,visibility:t.visibility}):r&&t.restoreMessage(r),Ai(t,n),n}function Ai(e,t){e.pendingPlacement.sessionKey||e.draftPersistence.activateRoute(t)}function ji(e,t,n){e.restorePendingPlacementRecovery(t,n),e.draftPersistence.setOwner(t,n,!!e.pendingPlacement.sessionKey)}var Mi;function Ni(){return(Ni=e((()=>{G(),Mi=`new-session-draft`})))()}function Pi(e){let t=e.trim();return!t||t.startsWith(`-`)||/\s/u.test(t)?null:/^(?:https:\/\/|ssh:\/\/git@|git@[^:]+:)/iu.test(t)?t:null}function Fi(e){return e.target instanceof HTMLInputElement?e.target.value:``}function Ii(e){let t=e.folder.trim(),n=e.projects.find(t=>t.id===e.projectId),r=e.projectQuery.trim().toLowerCase(),i=r?e.projects.filter(e=>[e.displayName,e.originUrl??``,e.repoRoot??``].join(`
`).toLowerCase().includes(r)):e.projects;return{label:n?n.displayName:e.selectedRemoteProject?.identity?e.selectedRemoteProject.identity:t?U(t):U(e.workspace)||P(`newSession.folderPlaceholder`),localProjects:i,recents:r?[]:e.recents.filter(e=>e.kind===`folder`),showWorkspace:!r||[U(e.workspace),e.workspace].join(`
`).toLowerCase().includes(r)}}function Li(e){let t=e.folder.trim(),n=Pi(e.projectQuery),r=e.projectQuery.trim(),i=!e.browseAvailable&&!e.isAdmin,a=e.state.recents,o=vr(a,e=>e.displayName,[e=>e.kind===`folder`?fr(e.folder):void 0,e=>e.kind===`folder`?e.folder:void 0,e=>e.kind===`folder`?e.folder:e.projectId]),s=k`
<button
type="button"
class="session-menu__item"
data-value="browse"
aria-pressed="false"
aria-disabled=${i?`true`:O}
?disabled=${e.submitting||e.pendingPlacement||!e.browseAvailable&&!i}
@click=${()=>{e.browseAvailable&&!e.submitting&&!e.pendingPlacement&&e.onBrowse()}}
>
<span class="session-menu__check" aria-hidden="true"></span>
<span class="session-menu__text">${P(`newSession.browse`)}</span>
<span class="new-session-page__menu-chevron" aria-hidden="true">${M.chevronRight}</span>
</button>
`;return k`
<span class="new-session-page__select">
<button
id="new-session-project-trigger"
type="button"
class="new-session-page__trigger ${e.popoverHiding?`new-session-page__trigger--hiding`:``}"
title=${P(`newSession.what`)}
aria-label="${P(`newSession.what`)}: ${e.state.label}"
data-project-id=${e.projectId||O}
aria-haspopup="dialog"
aria-expanded=${String(e.popoverOpen)}
?disabled=${e.submitting||e.pendingPlacement}
@click=${e.onGuardTransition}
>
<span class="new-session-page__target-icon" aria-hidden="true"
>${e.projectId?M.gitBranch:M.folder}</span
>
<span class="new-session-page__trigger-label">${e.state.label}</span>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--desktop"
aria-hidden="true"
>${M.chevronDown}</span
>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--mobile"
aria-hidden="true"
>${M.chevronsUpDown}</span
>
</button>
</span>
<wa-popover
class="new-session-page__select new-session-page__project-popover new-session-page__picker-popover"
for="new-session-project-trigger"
placement="bottom-start"
without-arrow
@wa-show=${e.onPopoverShow}
@wa-hide=${e.onPopoverHide}
@wa-after-hide=${e.onPopoverAfterHide}
>
${e.browserOpen?ur({listing:e.browserListing,label:e.gatewayLabel,loading:e.browserLoading,error:e.browserError,pathDraft:e.browserPathDraft,usablePath:e.usableBrowserPath,registerProjectPath:e.registerProjectPath,registeringProject:e.registeringProject,onPathDraftChange:e.onBrowserPathDraftChange,onNavigate:e.onBrowserNavigate,onBack:e.onBrowserBack,onRegisterProject:e.onRegisterProject,onClose:e.onClose,onApplyFolder:e.onApplyFolder}):k`
<div class="new-session-page__picker-root">
<div class="new-session-page__menu-title">${P(`newSession.projects`)}</div>
${k`
${e.workspace&&e.state.showWorkspace?H({value:`workspace`,label:U(e.workspace),icon:M.folder,checked:!e.projectId&&t===e.workspace,onSelect:()=>e.onApplyFolder(e.workspace)},e.submitting):O}
<label class="new-session-page__project-search">
<span class="sr-only">${P(`newSession.projectSearchPlaceholder`)}</span>
<input
type="search"
placeholder=${P(`newSession.projectSearchPlaceholder`)}
.value=${e.projectQuery}
?disabled=${e.submitting||e.pendingPlacement}
@input=${t=>e.onProjectQueryInput(Fi(t))}
@keydown=${t=>{t.key===`Enter`&&n&&e.projectAddAvailable&&(t.preventDefault(),e.onSelectRemoteProject({identity:n,cloneUrl:n}))}}
/>
</label>
${e.state.localProjects.map(t=>H({value:`project:${t.id}`,label:t.displayName,icon:M.gitBranch,checked:e.projectId===t.id,title:t.repoRoot,onSelect:()=>e.onSelectProject(t.id)},e.submitting))}
${n&&e.projectAddAvailable?H({value:`project-clone-url`,label:n,icon:M.gitBranch,sub:P(`newSession.cloneProject`),checked:e.selectedRemoteProject?.cloneUrl===n,onSelect:()=>e.onSelectRemoteProject({identity:n,cloneUrl:n})},e.submitting):O}
${!n&&r.length>=2&&e.projectSearchAvailable?k`
<div class="new-session-page__menu-title">
${P(`newSession.githubProjects`)}
</div>
${e.projectSearchCredentialMissing?k`<div class="new-session-page__menu-note">
${P(`newSession.githubTokenHint`)}
</div>`:O}
${e.projectSearchLoading?k`<div class="new-session-page__project-status" role="status">
${P(`common.loading`)}
</div>`:O}
${e.projectSearchError?k`<div class="new-session-page__project-error" role="alert">
${e.projectSearchError}
</div>`:O}
${e.remoteProjects.map(t=>H({value:`remote-project:${t.fullName}`,label:t.fullName,icon:M.gitBranch,sub:t.description??P(`newSession.cloneProject`),checked:e.selectedRemoteProject?.cloneUrl===t.cloneUrl,title:t.webUrl,onSelect:()=>e.onSelectRemoteProject({identity:t.fullName,cloneUrl:t.cloneUrl})},e.submitting||!e.projectAddAvailable))}
`:O}
${e.projects.length===0&&e.canWrite&&!e.isAdmin?k`<div class="new-session-page__menu-note">
${P(`newSession.projectsAdminHint`)}
</div>`:O}
`}
${e.remotePlacement?k`
<details>
<summary class="new-session-page__menu-title">
${P(`configForm.advancedDivider`)}
</summary>
${$r({branches:e.branches,branchesLoading:e.branchesLoading,baseRef:e.baseRef,worktreeName:e.worktreeName,worktreeNameLabel:P(`newSession.checkoutName`),submitting:e.submitting,pendingPlacement:e.pendingPlacement,onBaseRefInput:e.onBaseRefInput,onWorktreeNameInput:e.onWorktreeNameInput})}
<div class="new-session-page__menu-note">
${P(`newSession.placementSyncsFolder`,{folder:e.state.label})}
</div>
</details>
`:O}
${e.state.recents.length>0?k`
<div class="new-session-page__menu-title">${P(`newSession.recentFolders`)}</div>
${a.map((n,r)=>H({value:n.kind===`project`?`recent-project:${n.projectId}`:`recent:${n.folder}`,label:n.displayName,icon:n.kind===`project`?M.gitBranch:M.folder,sub:o[r],checked:n.kind===`project`?e.projectId===n.projectId:!e.projectId&&t===n.folder,title:n.kind===`project`?void 0:n.folder,onSelect:()=>n.kind===`project`?e.onSelectProject(n.projectId):e.onApplyFolder(n.folder)},e.submitting))}
`:O}
${i?k`<openclaw-tooltip .content=${P(`newSession.browseRequiresAdmin`)}>
${s}
</openclaw-tooltip>`:s}
</div>
`}
</wa-popover>
`}function Ri(){return(Ri=e((()=>{A(),N(),j(),nr(),ti(),pr()})))()}function zi(e,t){let n=new Set,r=[];for(let i of e){let e=c(i.execCwd)??c(i.worktree?.repoRoot),a=c(i.execNode);if(!e||a||e===t.workspace||!t.allowGatewayFolder(e))continue;let o=e;if(!n.has(o)&&(n.add(o),r.push({folder:e}),r.length>=4))break}return r}function Bi(){return(Bi=e((()=>{})))()}var Vi,Hi;function Ui(){return(Ui=e((()=>{Ze(),a(),j(),he(),R(),Ri(),Bi(),Vi=300,Hi=class{constructor(e,t,n,r){this.gateway=t,this.read=n,this.callbacks=r,this.projectsValue=[],this.projectSelection=null,this.projectQueryValue=``,this.debouncedProjectQuery=``,this.browserLoadingValue=!1,this.browserErrorValue=null,this.browserListingValue=null,this.browserOpenValue=!1,this.browserProjectPathValue=null,this.browserRegisteringValue=!1,this.openPopoverValue=null,this.hidingPopovers=new Set,this.browserPathDraftValue=``,this.browserRequestToken=0,this.projectsTask=new Qe(e,{args:()=>[this.read().context&&this.gateway.connected?this.gateway.client:null,I(this.read().context?.gateway.snapshot??{},`projects.list`)===!0,this.gateway.connectionEpoch],task:async([e,t])=>!e||!t?{projects:[]}:await e.request(`projects.list`,{}),onComplete:e=>{let t=e.projects??[];this.projectsValue=t,this.projectRecentsValue=e.recents,this.projectId&&!t.some(e=>e.id===this.projectId)&&this.callbacks.onProjectMissing(),this.callbacks.requestUpdate()},onError:()=>{this.projectsValue=[],this.projectRecentsValue=void 0,this.callbacks.onProjectMissing(),this.callbacks.requestUpdate()}}),this.projectSearchTask=new Qe(e,{args:()=>[this.read().context&&this.gateway.connected?this.gateway.client:null,this.read().context?L(this.read().context?.gateway.snapshot,`projects.searchRemote`,`operator.read`):!1,this.debouncedProjectQuery,this.gateway.connectionEpoch],task:([e,t,n],{signal:r})=>!e||!t||n.length<2||Pi(n)?et:e.request(`projects.searchRemote`,{query:n},{signal:r})})}get projects(){return this.projectsValue}get projectsReady(){return this.projectsTask.status===F.COMPLETE||this.projectsTask.status===F.ERROR}get projectRecents(){return this.projectRecentsValue}get projectId(){return this.projectSelection?.kind===`local`?this.projectSelection.id:``}get remoteProject(){return this.projectSelection?.kind===`remote`?this.projectSelection.project:null}get projectQuery(){return this.projectQueryValue}get projectSearchResult(){return this.projectSearchTask.status===F.COMPLETE&&this.debouncedProjectQuery===this.projectQueryValue.trim()?this.projectSearchTask.value??null:null}get projectSearchLoading(){return this.debouncedProjectQuery.length>=2&&this.debouncedProjectQuery===this.projectQueryValue.trim()&&this.projectSearchTask.status===F.PENDING}get projectSearchError(){if(this.projectSearchTask.status!==F.ERROR||this.debouncedProjectQuery!==this.projectQueryValue.trim())return null;let e=this.projectSearchTask.error;return E(e)}get browserLoading(){return this.browserLoadingValue}get browserError(){return this.browserErrorValue}get browserListing(){return this.browserListingValue}get browserOpen(){return this.browserOpenValue}get browserProjectPath(){return this.browserProjectPathValue}get browserRegistering(){return this.browserRegisteringValue}popoverOpen(e){return this.openPopoverValue===e}popoverHiding(e){return this.hidingPopovers.has(e)}popoverCallbacks(e){return{popoverOpen:this.popoverOpen(e),popoverHiding:this.popoverHiding(e),onGuardTransition:t=>this.guardPopoverTransition(t,e),onPopoverShow:()=>this.onPopoverShow(e),onPopoverHide:()=>this.onPopoverHide(e),onPopoverAfterHide:()=>this.onPopoverAfterHide(e)}}get browserPathDraft(){return this.browserPathDraftValue}set browserPathDraft(e){this.browserPathDraftValue=e,this.callbacks.requestUpdate()}async refreshProjects(){let e=this.read().context;return await this.projectsTask.run([this.gateway.connected?this.gateway.client:null,e?I(e.gateway.snapshot,`projects.list`)===!0:!1,this.gateway.connectionEpoch])}selectedProject(){return this.projectsValue.find(e=>e.id===this.projectId)}selectProject(e){this.projectSelection=e}recordRemoteProjectId(e,t){let n=this.remoteProject;n?.cloneUrl===e&&(this.projectSelection={kind:`remote`,project:{...n,projectId:t}})}clearProjectSelection(){this.projectSelection=null}resolveProjectRecents(e){let t=t=>e.isAdmin||dr(e.workspaceRoots,t);return this.projectRecentsValue?.filter(e=>e.kind===`project`?this.projectsValue.some(t=>t.id===e.projectId):!e.execNode&&t(e.folder))??zi(e.sessions,{workspace:e.workspace,allowGatewayFolder:t}).map(e=>({kind:`folder`,folder:e.folder,displayName:U(e.folder)}))}changeProjectQuery(e){this.projectQueryValue=e,this.clearProjectSearchTimer(),this.debouncedProjectQuery=``,this.projectSearchTask.run([null,!1,``,this.gateway.connectionEpoch]);let t=e.trim(),n=this.read().context;if(t.length<2||Pi(t)||!this.gateway.connected||!this.gateway.client||!n||!L(n.gateway.snapshot,`projects.searchRemote`,`operator.read`)){this.callbacks.requestUpdate();return}let r=this.gateway.client,i=this.gateway.connectionEpoch;this.projectSearchTimer=globalThis.setTimeout(()=>{this.projectSearchTimer=void 0,r===this.gateway.client&&i===this.gateway.connectionEpoch&&(this.debouncedProjectQuery=t,this.projectSearchTask.run([r,!0,t,i]),this.callbacks.requestUpdate())},Vi),this.callbacks.requestUpdate()}resetProjectSearch(){this.clearProjectSearchTimer(),this.projectQueryValue=``,this.debouncedProjectQuery=``,this.callbacks.requestUpdate()}resetProjects(){this.projectsValue=[],this.projectRecentsValue=void 0,this.clearProjectSelection(),this.resetProjectSearch()}close(){this.resetBrowser(!0);for(let e of[`where`,`project`,`detail`]){let t=this.callbacks.querySelector(`.new-session-page__${e}-popover`);t&&(t.open=!1)}}showRoot(){this.resetBrowser(!1)}usableBrowserPath(){let e=this.browserPathDraftValue.trim();return e.length===0?``:lr(e)?e:null}selectGatewayBrowser(e){this.browserOpenValue=!0,this.loadBrowser(e&&lr(e)?e:void 0)}loadBrowser(e,t=null){let n=this.read(),r=n.context?.gateway.snapshot,i=r?.client;if(r?.phase!==`connected`||!i||!this.browserOpenValue)return;let a=++this.browserRequestToken;this.browserLoadingValue=!0,this.browserErrorValue=t,this.browserProjectPathValue=null,this.browserListingValue=null,this.browserPathDraftValue=e??``;let s=this.browserPathDraftValue;this.callbacks.requestUpdate(),i.request(`fs.listDir`,e?{path:e}:{}).then(e=>{a===this.browserRequestToken&&(this.browserListingValue=e??null,e&&this.callbacks.onApprovedListing(e),e?.path&&this.browserPathDraftValue===s&&(this.browserPathDraftValue=e.path),e?.path&&n.isAdmin&&i.request(`worktrees.branches`,{repoRoot:e.path,includeRepositoryStatus:!0}).then(t=>{a===this.browserRequestToken&&this.browserListingValue?.path===e.path&&t.repositoryStatus===`git`&&(this.browserProjectPathValue=e.path,this.callbacks.requestUpdate())}).catch(()=>void 0),this.callbacks.requestUpdate())}).catch(t=>{if(a===this.browserRequestToken){if(e){this.loadBrowser(void 0,o(t)?.missingScope===`operator.admin`?P(`newSession.browseRequiresAdmin`):P(`newSession.browserLoadFailed`));return}this.browserErrorValue=P(`newSession.browserLoadFailed`),this.callbacks.requestUpdate()}}).finally(()=>{a===this.browserRequestToken&&(this.browserLoadingValue=!1,this.callbacks.requestUpdate())})}async registerBrowserProject(e){let t=this.read(),n=t.context?.gateway.snapshot,r=n?.client;if(n?.phase!==`connected`||!r||!t.isAdmin||this.browserProjectPathValue!==e||this.browserRegisteringValue)return;let i=this.browserRequestToken,a=this.gateway.connectionEpoch;this.browserRegisteringValue=!0,this.browserErrorValue=null,this.callbacks.requestUpdate();try{let t=await r.request(`projects.register`,{path:e});if(i!==this.browserRequestToken||r!==this.gateway.client||(await this.projectsTask.run([r,!0,a]),i!==this.browserRequestToken||r!==this.gateway.client))return;this.callbacks.onSelectProject(t.id),this.close()}catch(e){i===this.browserRequestToken&&r===this.gateway.client&&(this.browserErrorValue=E(e))}finally{i===this.browserRequestToken&&(this.browserRegisteringValue=!1,this.callbacks.requestUpdate())}}onPopoverShow(e){this.openPopoverValue=e,e===`project`?this.showRoot():this.callbacks.requestUpdate()}onPopoverHide(e){this.openPopoverValue===e&&(this.openPopoverValue=null),this.hidingPopovers.add(e),e===`project`?this.showRoot():this.callbacks.requestUpdate()}onPopoverAfterHide(e){this.hidingPopovers.delete(e),this.restorePopoverTrigger(`new-session-${e}-trigger`,`.new-session-page__${e}-popover`),this.callbacks.requestUpdate()}guardPopoverTransition(e,t){this.hidingPopovers.has(t)&&(e.preventDefault(),e.stopImmediatePropagation())}clearPopoverHiding(){this.hidingPopovers.clear(),this.callbacks.requestUpdate()}disconnect(){this.clearProjectSearchTimer(),this.projectsTask.run([null,!1,-1]),this.projectSearchTask.run([null,!1,``,-1])}resetBrowser(e){this.browserRequestToken+=1,this.browserLoadingValue=!1,this.browserErrorValue=null,this.browserListingValue=null,this.browserOpenValue=!1,this.browserProjectPathValue=null,this.browserRegisteringValue=!1,this.browserPathDraftValue=``,e&&(this.openPopoverValue=null),this.callbacks.requestUpdate()}clearProjectSearchTimer(){globalThis.clearTimeout(this.projectSearchTimer),this.projectSearchTimer=void 0}restorePopoverTrigger(e,t){let n=this.callbacks.activeElement(),r=this.callbacks.querySelector(t),i=this.callbacks.body();n&&n!==i&&!r?.contains(n)||this.callbacks.querySelector(`#${e}`)?.focus()}}})))()}function Wi(e){if(e.remoteProject)return{plan:`resolved`,state:{kind:`pending-clone`,cloneUrl:e.remoteProject.cloneUrl}};let t=e.selectedProject?.repoRoot??(e.folder.trim()||e.workspace);return!t||e.selectedProject&&!e.selectedProject.repoRoot?{plan:`none`}:!e.selectedProject&&t===e.workspace&&!e.workspaceGit?{plan:`resolved`,state:{kind:`direct`,repoRoot:t}}:{plan:`check`,repoRoot:t}}var Gi;function Ki(){return(Ki=e((()=>{Gi=class{constructor(e,t){this.read=e,this.callbacks=t,this.worktreeValue=!1,this.worktreeNameValue=``,this.baseRefValue=``,this.repositoryValue={kind:`idle`},this.requestToken=0,this.baseRefEditGeneration=0,this.preferredWorktreeRestore=!1,this.preferredBaseRefRestore=``,this.worktreeSelectedByUser=!1,this.detailsSelectedByUser=!1}get worktree(){return this.worktreeValue}get worktreeName(){return this.worktreeNameValue}get baseRef(){return this.baseRefValue}get repository(){return this.repositoryValue}get preferenceReady(){return!this.preferredWorktreeRestore}get hasUserSelection(){return this.worktreeSelectedByUser||this.detailsSelectedByUser}adoptPreference(e){this.preferredWorktreeRestore=e?.worktree===!0,this.preferredBaseRefRestore=e?.baseRef??``,this.worktreeNameValue=e?.worktreeName??``,this.worktreeSelectedByUser=!1,this.detailsSelectedByUser=!1}reset(){this.requestToken+=1,this.baseRefEditGeneration+=1,this.worktreeValue=!1,this.worktreeNameValue=``,this.baseRefValue=``,this.repositoryValue={kind:`idle`},this.preferredWorktreeRestore=!1,this.preferredBaseRefRestore=``,this.worktreeSelectedByUser=!1,this.detailsSelectedByUser=!1}invalidate(){this.requestToken+=1,this.repositoryValue={kind:`idle`},this.baseRefValue=``}selectWorktree(e,t=!0){this.preferredWorktreeRestore=!1,this.worktreeSelectedByUser=!0,this.worktreeValue=e,t&&(this.worktreeNameValue=``)}forceWorktree(e){this.worktreeValue=e}rejectPreferredWorktree(){this.preferredWorktreeRestore=!1,this.worktreeValue=!1}toggle(){this.read().remotePlacement||(this.worktreeValue=!this.worktreeValue,this.preferredWorktreeRestore=!1,this.worktreeSelectedByUser=!0,this.callbacks.persistPreference({folder:this.read().folder.trim()||this.read().workspace,worktree:this.worktreeValue}),this.worktreeValue&&this.repositoryValue.kind!==`git`&&this.repositoryValue.kind!==`pending-clone`&&this.load(),this.callbacks.requestUpdate())}setBaseRef(e,t){t||(this.baseRefEditGeneration+=1,this.baseRefValue=e,this.preferredBaseRefRestore=``,this.detailsSelectedByUser=!0,this.callbacks.persistPreference({baseRef:e}),this.callbacks.requestUpdate())}setWorktreeName(e,t){t||(this.worktreeNameValue=e,this.detailsSelectedByUser=!0,this.callbacks.persistPreference({worktreeName:e}),this.callbacks.requestUpdate())}available(){let e=this.read();if(e.selectedProject?.repoRoot)return!0;let t=this.repositoryValue;return t.kind===`git`||t.kind===`pending-clone`||t.kind===`unavailable`&&t.repoRoot===e.workspace&&e.workspaceGit}matchesCurrentRepo(){let e=this.read(),t=this.repositoryValue;if(t.kind===`pending-clone`)return e.remoteProject?.cloneUrl===t.cloneUrl;if(t.kind===`idle`||e.remoteProject)return!1;let n=e.selectedProject?.repoRoot??(e.folder.trim()||e.workspace);return t.repoRoot===n}load(){let e=++this.requestToken,t={worktree:this.preferredWorktreeRestore&&!this.worktreeSelectedByUser,baseRef:this.preferredBaseRefRestore,baseRefEditGeneration:this.baseRefEditGeneration},n=this.read();this.repositoryValue={kind:`idle`},this.baseRefValue=``;let r=Wi(n);if(r.plan===`resolved`)return this.adoptResolvedRepository(r.state,t);let i=n.gateway?.client;if(r.plan===`none`||n.gateway?.phase!==`connected`||!i)return this.adoptResolvedRepository({kind:`idle`},t);let{repoRoot:a}=r;this.repositoryValue={kind:`checking`,repoRoot:a},i.request(`worktrees.branches`,{repoRoot:a,includeRepositoryStatus:!0}).then(n=>{e===this.requestToken&&this.adoptResolvedRepository(n?.repositoryStatus===`git`?{kind:`git`,repoRoot:a,branches:n.branches,...n.defaultBranch?{defaultBranch:n.defaultBranch}:{},...n.headBranch?{headBranch:n.headBranch}:{}}:{kind:n?.repositoryStatus===`not_git`?`direct`:`unavailable`,repoRoot:a},t)}).catch(()=>{e===this.requestToken&&this.adoptResolvedRepository({kind:`unavailable`,repoRoot:a},t)})}adoptResolvedRepository(e,t){if(this.repositoryValue=e,e.kind===`direct`){if(!this.read().remotePlacement){let e=this.worktreeValue||t.worktree;this.worktreeValue=!1,e&&this.callbacks.persistPreference({worktree:!1})}}else e.kind!==`idle`&&t.worktree&&!this.worktreeSelectedByUser&&this.available()&&(this.worktreeValue=!0);this.preferredWorktreeRestore=!1,e.kind===`git`&&t.baseRefEditGeneration===this.baseRefEditGeneration&&(this.baseRefValue=t.baseRef||e.defaultBranch||e.headBranch||``,t.baseRef&&(this.preferredBaseRefRestore=``)),this.callbacks.requestUpdate()}}})))()}function qi(e){return e instanceof ke&&e.gatewayCode===`INVALID_REQUEST`&&/^(?:Error:\s+)?(?:ENOENT|ENOTDIR):/u.test(e.message)}function Ji(){return(Ji=e((()=>{Re()})))()}function Q(e,t,n){let r=oe(e,t,n);if(!r)return null;let i=r.toLowerCase(),a=n.find(e=>ie(e.id,e.provider).toLowerCase()===i);if(a)return{entry:a,model:a.id,provider:y(a.provider)||null};let o=r.indexOf(`/`);return o>0?{model:r.slice(o+1),provider:y(r.slice(0,o))||null}:{model:r,provider:y(t??``)||null}}function Yi(){return(Yi=e((()=>{ee()})))()}var Xi;function Zi(){return(Zi=e((()=>{j(),pe(),ee(),lt(),jt(),R(),re(),T(),Mn(),$n(),Yi(),Xi=class{constructor(e,t=()=>void 0,n=()=>void 0){this.notify=e,this.onSelectionChange=t,this.onCatalogTargetSelect=n,this.selectionGeneration=0,this.agentId=``,this.metadataState={catalog:[],hasSnapshot:!1,status:`idle`},this.metadataLoading=!1,this.restoringPreference=!1,this.pendingSelectionGeneration=0,this.catalogTargetRequestId=0,this.catalogTargetDiscovery={status:`idle`},this.selected=``,this.contextWindow=``,this.thinkingLevel=``}get catalog(){return this.metadataState.catalog}clearMetadataSubscription(){this.metadataUnsubscribe?.(),this.metadataUnsubscribe=void 0}bindMetadataSubscription(e,t){this.metadataClient===e&&this.metadataUnsubscribe||(this.clearMetadataSubscription(),this.metadataClient=e,this.metadataUnsubscribe=_(e,{agentId:t},n=>{if(this.metadataClient!==e||this.agentId!==t)return;let r=this.pendingContext?.gateway.snapshot;if(r?.phase!==`connected`||r.client!==e){this.metadataLoading=!1,this.restoringPreference=!1,this.updateMetadataState({catalog:[],hasSnapshot:!1,status:`offline`});return}if(n.type===`invalidated`){this.startMetadataRequest(e,t);return}if(this.metadataLoading=n.type===`loading`,n.type===`result`)this.publishMetadataCatalog(Array.isArray(n.result.models)?n.result.models:[],`ready`);else if(n.type===`loading`){let e=this.metadataState.hasSnapshot?`ready`:`loading`;this.metadataState.status!==e&&this.updateMetadataState({...this.metadataState,status:e})}else this.pendingSelectionGeneration===this.selectionGeneration&&(this.pendingPreference?.model||this.pendingPreference?.thinkingLevel)&&(this.selected=this.pendingPreference.model??``,this.thinkingLevel=this.pendingPreference.thinkingLevel??``),this.restoringPreference=!1,this.updateMetadataState({...this.metadataState,status:`error`})}))}clearCatalogTargets(){let e=this.catalogTargetDiscovery;this.catalogTargetDiscovery={status:`idle`},this.catalogTargetRequestId+=1,e.status===`loading`&&e.controller.abort(),e.status!==`idle`&&this.notify()}startCatalogTargetRequest(e){let t=new AbortController,n=++this.catalogTargetRequestId;this.catalogTargetDiscovery={status:`loading`,owner:e,controller:t,requestId:n},this.notify(),e.client.request(`sessions.catalog.list`,{agentId:e.agentId,limitPerHost:1},{signal:t.signal}).then(t=>{let r=this.catalogTargetDiscovery;r.status===`loading`&&r.requestId===n&&(this.catalogTargetDiscovery={status:`ready`,owner:e,targets:t.catalogs.filter(e=>e.capabilities.createSession!==void 0).map(({id:e,label:t})=>({id:e,label:t}))},this.notify())},()=>{let t=this.catalogTargetDiscovery;t.status===`loading`&&t.requestId===n&&(this.catalogTargetDiscovery={status:`error`,owner:e},this.notify())})}loadCatalogTargets(e,t,r){let i=e?.gateway.snapshot,a=i?.client,o=t.trim()?n(t):``;if(!r||i?.phase!==`connected`||!a||!o||I(i,`sessions.catalog.list`)!==!0){this.clearCatalogTargets();return}let s={agentId:o,client:a},c=this.catalogTargetDiscovery;(c.status===`idle`||c.owner.client!==s.client||c.owner.agentId!==s.agentId)&&(this.clearCatalogTargets(),this.startCatalogTargetRequest(s))}updateMetadataState(e){this.metadataState=e,this.notify()}publishMetadataCatalog(e,t){this.metadataState={catalog:e,hasSnapshot:!0,status:t},this.pendingSelectionGeneration===this.selectionGeneration&&this.restorePreference(this.pendingPreference,this.pendingAgent,this.pendingContext),this.restoringPreference=!1,this.notify()}startMetadataRequest(e,t){this.metadataLoading=!0;let n=C(e,{agentId:t});Array.isArray(n?.models)?this.publishMetadataCatalog(n.models,`ready`):this.updateMetadataState({...this.metadataState,status:this.metadataState.hasSnapshot?`ready`:`loading`}),g(e,{agentId:t},{startupRetryWindowMs:6e4}).catch(()=>void 0)}retryPickerCatalogs(e=!1){let t=this.metadataClient;if(this.metadataState.status===`error`&&t&&this.agentId)this.startMetadataRequest(t,this.agentId);else if(e&&this.metadataState.status===`ready`&&t&&this.agentId){let e=this.agentId;h(t,{agentId:e,refreshIfDue:!0,rejectOnFailure:!0}).catch(()=>{this.metadataClient===t&&this.agentId===e&&this.updateMetadataState({...this.metadataState,status:`error`})})}let n=this.catalogTargetDiscovery;n.status===`error`&&n.owner.client===t&&n.owner.agentId===this.agentId&&this.startCatalogTargetRequest(n.owner)}catalogTargetGroups(){let e=this.catalogTargetDiscovery;if(!(e.status===`idle`||e.status===`ready`&&!e.targets.length))return[{errorLabel:P(`newSession.cliAgentsUnavailable`),id:`cliAgents`,label:P(`newSession.cliAgentsGroup`),options:e.status===`ready`?e.targets.map(({id:e,label:t})=>({value:e,label:t})):[],status:e.status}]}invalidate(e=!1){if(this.metadataLoading=!1,this.clearCatalogTargets(),this.restoringPreference=!1,e){this.agentId=``,this.metadataClient=void 0,this.clearMetadataSubscription(),this.selected=``,this.contextWindow=``,this.thinkingLevel=``,this.fastMode=void 0,this.updateMetadataState({catalog:[],hasSnapshot:!1,status:`idle`});return}this.updateMetadataState({...this.metadataState,status:this.metadataState.hasSnapshot?`error`:`idle`})}reset(){this.invalidate(!0)}load(e,t,r,i={}){let a=e?.gateway.snapshot,o=a?.client,s=t.trim()?n(t):``;(this.agentId!==s||this.metadataClient&&this.metadataClient!==o)&&(this.metadataLoading=!1,this.clearMetadataSubscription(),this.agentId!==s&&(this.selected=``,this.contextWindow=``,this.thinkingLevel=``,this.fastMode=void 0),this.agentId=s,this.metadataClient=void 0,this.metadataState={catalog:[],hasSnapshot:!1,status:`idle`});let c=this.selectionGeneration;if(!e||a?.phase!==`connected`||!o||!s||!r){this.metadataLoading=!1,this.clearMetadataSubscription(),this.metadataClient=void 0,this.restoringPreference=!1,e&&a?.phase!==`connected`&&(this.metadataState={catalog:[],hasSnapshot:!1,status:`offline`}),this.notify();return}this.bindMetadataSubscription(o,s),this.pendingPreference=i.preference,this.pendingAgent=i.agent,this.pendingContext=e,this.pendingSelectionGeneration=c,this.restoringPreference=!!(i.preference?.model||i.preference?.thinkingLevel);let l=C(o,{agentId:s});if(this.metadataLoading){l?this.publishMetadataCatalog(Array.isArray(l.models)?l.models:[],`ready`):this.notify();return}if(l&&this.metadataState.status!==`error`){this.publishMetadataCatalog(Array.isArray(l.models)?l.models:[],`ready`);return}this.startMetadataRequest(o,s)}isRestoringPreference(){return this.restoringPreference}modelUnavailableReason(e){return this.metadataState.hasSnapshot&&this.metadataState.status!==`offline`?gt(this.selected||e?.model?.primary,void 0,this.catalog):void 0}restorePreference(e,t,n){if(!e)return;let r=this.reconcileSelection(e.model??``,e.thinkingLevel??``,{agent:t,context:n});this.selected=r.model,this.thinkingLevel=r.thinkingLevel,r.repaired&&this.onSelectionChange({model:r.model,thinkingLevel:r.thinkingLevel})}reconcileSelection(e,t,n){let r=e.trim(),i=r?Q(r,void 0,this.catalog):null;if(r&&(!i?.entry||i.entry.available===!1))return{model:``,thinkingLevel:``,repaired:!0};let a=i?.entry?ie(i.entry.id,i.entry.provider):``;if(!t)return{model:a,thinkingLevel:``,repaired:!1};let o=n.context?.sessions.state.result?.defaults,s=n.agent?.model?.primary,c=a?null:Q(s??o?.model,s?void 0:o?.modelProvider,this.catalog),l=i?.entry??c?.entry,u=a?l?.thinkingLevels:n.agent?.thinkingLevels??o?.thinkingLevels??l?.thinkingLevels,d=At(t),f=u?.some(e=>At(e.id)===d);return l?.reasoning===!1||u!==void 0&&!f?{model:a,thinkingLevel:``,repaired:!0}:{model:a,thinkingLevel:t,repaired:!1}}resolveAgentRuntime(e){let t=e.context?.sessions.state.result?.defaults,n=e.agent?.model?.primary,r;r=this.selected?Q(this.selected,void 0,this.catalog)?.entry?.agentRuntime:Q(n??t?.model,n?void 0:t?.modelProvider,this.catalog)?.entry?.agentRuntime??e.agent?.agentRuntime??t?.agentRuntime;let i=r?.id.trim();if(!(!r||!i||i===`auto`||i==="default"))return i===r.id?r:{...r,id:i}}devicePlacementUnsupportedReason(){let e=this.resolveAgentRuntime({agent:this.pendingAgent,context:this.pendingContext});return e&&!e.devicePlacement?P(`newSession.deviceRuntimeUnsupported`):void 0}autoPlacementSelectionMode(){return this.resolveAgentRuntime({agent:this.pendingAgent,context:this.pendingContext})?.cloudPlacementExecutionMode===`remote-exec`?`eligible-order`:`least-busy`}cloudRuntimeUnsupportedReason(e){let t=this.resolveAgentRuntime({agent:this.pendingAgent,context:this.pendingContext});return t?.cloudPlacementSupported===!1?P(`newSession.cloudRuntimeUnsupported`,{runtime:t.id}):t&&e&&t.cloudPlacementExecutionMode&&!ir(e,t.cloudPlacementExecutionMode)?P(`newSession.cloudProfileRuntimeUnsupported`,{runtime:t.id}):void 0}render(e){let t=e.context?.gateway.snapshot,r=`new-session:${n(e.agentId)}`,i=e.context?.sessions.state.result??null,a=e.agent!==void 0,o=e.agent?.model?.primary,s=Q(o??i?.defaults.model,o?void 0:i?.defaults.modelProvider,this.catalog),c=Q(this.selected,void 0,this.catalog),l=c?.entry??s?.entry,u=l?.contextWindowDefault,d=this.contextWindow||u,f={model:c?.model,modelProvider:c?.provider??void 0,thinkingLevel:this.thinkingLevel||void 0},p={...i?.defaults,modelProvider:s?.provider??i?.defaults.modelProvider??null,model:s?.model??i?.defaults.model??null,contextTokens:i?.defaults.contextTokens??null,agentRuntime:e.agent?.agentRuntime??i?.defaults.agentRuntime,thinkingLevels:e.agent?.thinkingLevels??i?.defaults.thinkingLevels,thinkingOptions:e.agent?.thinkingOptions??i?.defaults.thinkingOptions,thinkingDefault:e.agent?.thinkingDefault??i?.defaults.thinkingDefault??`medium`};return Tn({activeRunId:null,agentDefaultModel:o,connected:t?.phase===`connected`,gatewayAvailable:!!t?.client,loading:!1,modelCatalog:this.catalog,modelCatalogState:{hasSnapshot:a&&this.metadataState.hasSnapshot,status:!a&&this.metadataState.status!==`error`?`loading`:this.metadataState.status},contextWindowTarget:l?.contextWindows&&d?{contextWindow:d,contextWindows:l.contextWindows,...u?{contextWindowDefault:u}:{}}:void 0,fastModeTarget:{model:c?.model??s?.model,modelProvider:c?.provider??s?.provider??void 0,fastMode:this.fastMode,effectiveFastMode:this.fastMode??(c?.entry??s?.entry)?.effectiveFastMode},modelOverrides:{[r]:this.selected},modelPickerTargetGroups:this.catalogTargetGroups(),modelSwitching:!1,sending:e.sending,sessionKey:r,selectedSession:void 0,sessionsResult:i,stream:null,thinkingDefaults:p,thinkingSession:f,onModelSelect:t=>{this.selectionGeneration+=1,this.restoringPreference=!1;let n=this.reconcileSelection(t,this.thinkingLevel,e);this.selected=n.model,this.contextWindow=``,this.thinkingLevel=n.thinkingLevel,this.fastMode=dt((Q(n.model,void 0,this.catalog)??s)?.provider)?this.fastMode:void 0,this.onSelectionChange({model:this.selected,thinkingLevel:this.thinkingLevel})},onModelPickerTargetSelect:(e,t)=>{e===`cliAgents`&&this.onCatalogTargetSelect(t)},onModelPickerTargetRetry:e=>{e===`cliAgents`&&this.retryPickerCatalogs()},onThinkingSelect:e=>{this.selectionGeneration+=1,this.restoringPreference=!1,this.thinkingLevel=e,this.onSelectionChange({model:this.selected,thinkingLevel:this.thinkingLevel})},onFastModeSelect:e=>{this.selectionGeneration+=1,this.restoringPreference=!1,this.fastMode=Tt(e),this.notify()},onContextWindowSelect:e=>{this.selectionGeneration+=1,this.restoringPreference=!1,this.contextWindow=e,this.notify()},onModelSetup:()=>e.context?.navigate(`model-setup`),onModelPickerOpen:()=>this.retryPickerCatalogs(!0),onRequestUpdate:this.notify})}}})))()}var Qi;function $i(){return($i=e((()=>{Me(),j(),ge(),T(),G(),xr(),hr(),Ki(),Ji(),Zi(),yi(),Qi=class{constructor(e,t,n,r){this.gateway=e,this.browser=t,this.read=n,this.callbacks=r,this.agentIdValue=``,this.folderValue=``,this.deviceIdValue=``,this.autoDeviceValue=!1,this.cloudProfileIdValue=``,this.cloudMachines=new gr,this.restoredFolderValidation=`none`,this.gatewayApprovedWorkspaceRoots=[],this.agentsHydratedValue=!1,this.agentSelectedByUser=!1,this.folderSelectedByUser=!1,this.folderGatewayApproved=!1,this.preferredWhereRestore=null,this.preferredProjectRestore=``,this.whereSelectedByUser=!1,this.projectSelectedByUser=!1,this.restoredFolderValidationToken=0,this.repositoryState=new Gi(()=>({remotePlacement:this.remotePlacement,selectedProject:this.browser.selectedProject(),remoteProject:this.browser.remoteProject,folder:this.folderValue,workspace:this.workspacePath(),workspaceGit:this.selectedAgent()?.workspaceGit===!0,gateway:this.read().context?.gateway.snapshot}),{requestUpdate:r.requestUpdate,persistPreference:e=>this.persistPreference(e)}),this.modelControl=new Xi(r.requestUpdate,e=>this.persistPreference(e),e=>this.read().context?.navigate(`new-session`,{search:ue(this.agentIdValue,{catalogId:e})}))}get agentId(){return this.agentIdValue}get folder(){return this.folderValue}get worktree(){return this.repositoryState.worktree}get worktreeName(){return this.repositoryState.worktreeName}get baseRef(){return this.repositoryState.baseRef}get repository(){return this.repositoryState.repository}get deviceId(){return this.deviceIdValue}get autoDevice(){return this.autoDeviceValue}get remotePlacement(){return!!(this.deviceIdValue||this.autoDeviceValue||this.cloudProfileIdValue)}get cloudProfileId(){return this.cloudProfileIdValue}get machineClass(){return this.cloudMachines.resolve(this.cloudProfileIdValue)}get agentsHydrated(){return this.agentsHydratedValue}get placementPreferenceReady(){return this.repositoryState.preferenceReady&&this.preferredWhereRestore===null}canAdoptGroupDefaults(){return!this.folderSelectedByUser&&!this.whereSelectedByUser&&!this.projectSelectedByUser&&!this.repositoryState.hasUserSelection}adoptGroupDefaults(){this.read().data?.groupStatus!==`resolved`||!this.canAdoptGroupDefaults()||this.adoptAgentDefaults({preserveSelectedAgent:!0})}setAgentsHydrated(e){this.agentsHydratedValue=e}agents(){return b(this.read().context?.agents.state.agentsList?.agents??[])}selectedAgent(){let e=n(this.agentIdValue);return this.agents().find(t=>n(t.id)===e)}devicePlacementRequirement(){return this.modelControl.resolveAgentRuntime({agent:this.selectedAgent(),context:this.read().context})?.devicePlacement}devices(){return yr(this.gateway.environments,this.devicePlacementRequirement(),this.gateway.deviceCatalogDisabledReason)}findDevice(e){return this.devices().find(t=>t.deviceId===e)}devicePlacementReady(){return this.autoDeviceValue?this.devices().some(e=>e.selectable):!this.deviceIdValue||this.findDevice(this.deviceIdValue)?.selectable===!0}devicePlacementDisabledReason(){if(this.autoDeviceValue)return br(this.gateway.environments,this.devices());if(this.deviceIdValue)return this.findDevice(this.deviceIdValue)?.disabledReason??P(`newSession.nodeUnavailable`)}isAdmin(){return Fe(this.read().context?.gateway.snapshot.hello?.auth??null)}canWrite(){return Ue(this.read().context?.gateway.snapshot.hello?.auth??null)}workspacePath(){return c(this.selectedAgent()?.workspace)??``}knownWorkspaceRoots(){let e=this.workspacePath();return e?[e,...this.gatewayApprovedWorkspaceRoots]:this.gatewayApprovedWorkspaceRoots}recordGatewayApprovedListing(e){if(this.isAdmin())return;let t=new Set(this.gatewayApprovedWorkspaceRoots);t.add(e.path),e.parent&&t.add(e.parent),t.size!==this.gatewayApprovedWorkspaceRoots.length&&(this.gatewayApprovedWorkspaceRoots=[...t],this.callbacks.requestUpdate())}folderSubmissionBlocked(){return this.browser.projectId||this.browser.remoteProject?!this.browser.remoteProject&&!this.browser.selectedProject():this.restoredFolderValidation!==`none`||(!this.usesCustomFolder()||this.isAdmin()||this.folderGatewayApproved||dr(this.knownWorkspaceRoots(),this.folderValue),!1)}adoptAgentDefaults(e={}){let t=this.read(),n=this.agents(),r=t.context?.agents.state.agentsList?.defaultId,i=n.some(e=>e.id===r)?r??``:n[0]?.id??``;e.preserveSelectedAgent&&this.agentSelectedByUser&&this.selectedAgent()||(this.agentIdValue=Dr(t.data,n,i),this.agentSelectedByUser=!1);let a=this.agentIdValue?this.gateway.readPreference(this.agentIdValue):null,o=e.preserveSelectedFolder&&this.folderSelectedByUser;if(!o&&!t.pendingPlacementSessionKey){let e=this.workspacePath(),n=a?.folder??``,r=!!n&&n===a?.workspace&&a.workspace!==e,i=!!n&&!r,o=!!t.data?.group,s=t.data?.groupCwd??``,c=t.data?.groupWorktree===!0;this.folderValue=o?s||e:i?n:e,this.folderGatewayApproved=!1,this.folderSelectedByUser=!1,this.repositoryState.adoptPreference(o?{worktree:c}:a),o&&this.repositoryState.forceWorktree(c);let l=o?{kind:`local`}:a?.where??{kind:`local`};this.whereSelectedByUser||(this.preferredWhereRestore=l.kind===`local`?null:l),this.preferredProjectRestore=o?``:a?.projectId??``,this.projectSelectedByUser=!1,r&&!o&&this.persistPreference({folder:e})}o&&!t.pendingPlacementSessionKey&&this.agentIdValue&&this.persistPreference({folder:this.folderValue,worktree:this.worktree}),this.remotePlacement&&this.repositoryState.forceWorktree(!0),this.modelControl.load(t.context,this.agentIdValue,!q(t.data),{agent:this.selectedAgent(),preference:a}),this.preferredProjectRestore?this.cancelRestoredFolderValidation():!this.folderSelectedByUser&&this.folderValue!==this.workspacePath()&&!t.pendingPlacementSessionKey?this.validateRestoredFolder(this.folderValue):(this.cancelRestoredFolderValidation(),this.repositoryState.matchesCurrentRepo()||this.repositoryState.load()),this.callbacks.requestUpdate()}resetDraft(){this.agentSelectedByUser=!1,this.folderValue=``,this.browser.clearProjectSelection(),this.browser.resetProjectSearch(),this.folderSelectedByUser=!1,this.folderGatewayApproved=!1,this.gatewayApprovedWorkspaceRoots=[],this.cancelRestoredFolderValidation(),this.preferredWhereRestore=null,this.preferredProjectRestore=``,this.whereSelectedByUser=!1,this.projectSelectedByUser=!1,this.repositoryState.reset(),this.deviceIdValue=``,this.autoDeviceValue=!1,this.modelControl.reset(),this.cloudProfileIdValue=``,this.cloudMachines.clear(),this.callbacks.requestUpdate()}invalidateGatewayDiscovery(e){if(this.repositoryState.invalidate(),this.agentsHydratedValue=!1,this.modelControl.invalidate(e),this.browser.close(),this.cancelRestoredFolderValidation(),this.gatewayApprovedWorkspaceRoots=[],this.folderGatewayApproved=!1,this.browser.resetProjectSearch(),!e){this.callbacks.requestUpdate();return}this.agentIdValue=``,this.agentSelectedByUser=!1,this.folderValue=``,this.browser.resetProjects(),this.folderSelectedByUser=!1,this.preferredWhereRestore=null,this.preferredProjectRestore=``,this.whereSelectedByUser=!1,this.projectSelectedByUser=!1,this.repositoryState.reset(),this.deviceIdValue=``,this.autoDeviceValue=!1,this.cloudProfileIdValue=``,this.cloudMachines.clear(),this.callbacks.requestUpdate()}applyPendingPlacement(e){this.agentIdValue=e.agentId,this.deviceIdValue=e.deviceId??``,this.autoDeviceValue=e.autoDevice===!0,this.cloudProfileIdValue=e.profileId,this.cloudMachines.applyPending(e.profileId,e.machineClass),this.repositoryState.forceWorktree(!0),this.folderValue=e.cwd??``,this.folderGatewayApproved=!1,this.callbacks.requestUpdate()}clearCloudProfile(){this.cloudProfileIdValue=``,this.browser.close(),this.callbacks.requestUpdate()}clearProjectSelection(){this.browser.clearProjectSelection(),this.repositoryState.load(),this.callbacks.requestUpdate()}selectAgentId(e){let t=this.read();t.submitting||t.pendingPlacementSessionKey||q(t.data)||n(e)!==n(this.agentIdValue)&&(this.agentIdValue=n(e),this.cancelRestoredFolderValidation(),this.modelControl.reset(),this.callbacks.onError(null),this.agentSelectedByUser=!0,this.folderSelectedByUser=!1,this.folderGatewayApproved=!1,this.gatewayApprovedWorkspaceRoots=[],this.browser.clearProjectSelection(),this.preferredWhereRestore=null,this.preferredProjectRestore=``,this.whereSelectedByUser=!1,this.projectSelectedByUser=!1,this.deviceIdValue=``,this.cloudProfileIdValue=``,this.autoDeviceValue=!1,this.repositoryState.reset(),this.browser.close(),this.adoptAgentDefaults({preserveSelectedAgent:!0}))}applyFolder(e,t=!1){let n=this.read();n.submitting||n.pendingPlacementSessionKey||(this.browser.clearProjectSelection(),this.cancelRestoredFolderValidation(),this.callbacks.onError(null),this.folderValue=e.trim(),this.folderGatewayApproved=t&&!this.isAdmin(),this.folderSelectedByUser=!0,this.projectSelectedByUser=!0,this.preferredProjectRestore=``,this.repositoryState.selectWorktree(this.remotePlacement),this.agentsHydratedValue&&this.persistPreference({folder:this.folderValue,projectId:``,worktree:this.worktree}),this.repositoryState.load())}selectProjectId(e){let t=this.read();if(t.submitting||t.pendingPlacementSessionKey)return;let n=this.browser.projects.find(t=>t.id===e);n&&this.selectProject({kind:`local`,id:n.id})}selectRemoteProject(e){this.selectProject({kind:`remote`,project:e})}selectProject(e){let t=this.read();t.submitting||t.pendingPlacementSessionKey||(this.browser.selectProject(e),this.cancelRestoredFolderValidation(),this.browser.resetProjectSearch(),this.callbacks.onError(null),this.folderSelectedByUser=!1,this.projectSelectedByUser=!0,this.preferredProjectRestore=``,this.repositoryState.selectWorktree(this.remotePlacement),e.kind===`local`&&this.persistPreference({projectId:e.id,where:oi({cloudProfileId:this.cloudProfileIdValue,deviceId:this.deviceIdValue,autoDevice:this.autoDeviceValue}),worktree:this.worktree,worktreeName:``}),this.repositoryState.load(),this.browser.close())}selectDevice(e,t=!1){let n=this.read();n.submitting||n.pendingPlacementSessionKey||e&&this.findDevice(e)?.selectable!==!0||t&&!this.devices().some(e=>e.selectable)||e===this.deviceIdValue&&t===this.autoDeviceValue&&!this.cloudProfileIdValue||(this.cancelRestoredFolderValidation(),this.deviceIdValue=e,this.autoDeviceValue=t,this.cloudProfileIdValue=``,this.whereSelectedByUser=!0,this.preferredWhereRestore=null,(e||t)&&!this.worktreeAvailable()&&(this.folderValue=this.workspacePath(),this.folderSelectedByUser=!1,this.folderGatewayApproved=!1,this.browser.clearProjectSelection(),this.projectSelectedByUser=!0),this.repositoryState.forceWorktree(!!(e||t)),this.persistPreference({where:oi({cloudProfileId:``,deviceId:e,autoDevice:t}),projectId:this.browser.projectId,folder:this.folderValue,worktree:!!(e||t)||this.worktree}),this.browser.close(),this.repositoryState.matchesCurrentRepo()||this.repositoryState.load(),this.callbacks.requestUpdate())}selectCloudProfile(e){let t=this.read(),n=this.gateway.cloudProfiles.find(t=>t.id===e);t.submitting||t.pendingPlacementSessionKey||!this.isAdmin()||!this.worktreeAvailable()||!n||this.modelControl.cloudRuntimeUnsupportedReason(n)||(this.cloudProfileIdValue=e,this.deviceIdValue=``,this.autoDeviceValue=!1,this.whereSelectedByUser=!0,this.preferredWhereRestore=null,this.callbacks.onError(null),this.repositoryState.forceWorktree(!0),this.persistPreference({where:{kind:`cloud`,id:e},projectId:this.browser.projectId,worktree:!0}),this.browser.close(),this.repositoryState.matchesCurrentRepo()||this.repositoryState.load(),this.callbacks.requestUpdate())}toggleWorktree(){this.repositoryState.toggle()}setBaseRef(e){this.repositoryState.setBaseRef(e,this.read().submitting)}setWorktreeName(e){this.repositoryState.setWorktreeName(e,this.read().submitting)}restorePreferenceSelections(){let e=!1,t=this.whereSelectedByUser?null:this.preferredWhereRestore,n=this.projectSelectedByUser?``:this.preferredProjectRestore;if(t?.kind!==`device`&&t?.kind!==`auto-device`&&n){let t=this.browser.projects.find(e=>e.id===n);t?(this.browser.selectProject({kind:`local`,id:t.id}),this.folderSelectedByUser=!1,this.preferredProjectRestore=``,e=!0):this.browser.projectsReady&&(this.preferredProjectRestore=``,n=``,e=!0)}if((t?.kind===`device`||t?.kind===`auto-device`)&&this.gateway.cloudProfilesReady){let n=t.kind===`auto-device`;this.autoDeviceValue=n,this.deviceIdValue=t.kind===`device`?t.id:``,this.cloudProfileIdValue=``,this.repositoryState.forceWorktree(this.remotePlacement),this.preferredWhereRestore=null,e=!0}else if(t?.kind===`cloud`&&this.gateway.cloudProfilesReady){let r=this.gateway.cloudProfiles.find(e=>e.id===t.id),i=!!(r&&!this.modelControl.cloudRuntimeUnsupportedReason(r)),a=!n||this.browser.projectId===n;this.isAdmin()&&i&&a&&this.worktreeAvailable()?(this.deviceIdValue=``,this.autoDeviceValue=!1,this.cloudProfileIdValue=t.id,this.repositoryState.forceWorktree(!0),this.preferredWhereRestore=null,e=!0):i||(this.cloudProfileIdValue!==t.id&&(this.cloudProfileIdValue=``,e=!0),this.preferredWhereRestore=null,this.persistPreference({where:{kind:`local`}}))}e&&(this.repositoryState.load(),this.callbacks.requestUpdate())}browseAvailable(){return this.gateway.connected&&(this.isAdmin()||!!this.workspacePath())}worktreeAvailable(){return this.repositoryState.available()}usesCustomFolder(){if(this.browser.projectId||this.browser.remoteProject)return!1;let e=this.folderValue.trim();return!!e&&e!==this.workspacePath()}persistPreference(e){this.gateway.persistPreference(this.agentIdValue,this.workspacePath(),e)}cancelRestoredFolderValidation(){this.restoredFolderValidationToken+=1,this.restoredFolderValidation=`none`}restoreWorkspaceFolder(){this.restoredFolderValidation=`none`,this.folderGatewayApproved=!1,this.callbacks.onClearError(P(`newSession.browserLoadFailed`)),this.folderValue=this.workspacePath(),this.repositoryState.rejectPreferredWorktree(),this.persistPreference({folder:this.folderValue,worktree:!1}),this.repositoryState.load()}validateRestoredFolder(e){let t=this.read().context?.gateway.snapshot,n=t?.client;if(t?.phase!==`connected`||!n){this.restoreWorkspaceFolder();return}let r=++this.restoredFolderValidationToken;this.restoredFolderValidation=`checking`,n.request(`fs.listDir`,{path:e}).then(t=>{r!==this.restoredFolderValidationToken||this.folderSelectedByUser||this.folderValue!==e||(this.recordGatewayApprovedListing(t),this.folderGatewayApproved=!this.isAdmin(),this.restoredFolderValidation=`none`,this.callbacks.onClearError(P(`newSession.browserLoadFailed`)),this.repositoryState.load())}).catch(t=>{if(!(r!==this.restoredFolderValidationToken||this.folderSelectedByUser||this.folderValue!==e)){if(!this.isAdmin()||qi(t)){this.restoreWorkspaceFolder();return}this.restoredFolderValidation=`failed`,this.callbacks.onError(P(`newSession.browserLoadFailed`))}})}}})))()}var ea;function ta(){return(ta=e((()=>{S(),Mt(),ea=class{constructor(e,t){this.notify=e,this.onUserChange=t,this.attachments=[],this.reads=new on(e)}get pendingReads(){return this.reads.pendingReads}get readSignal(){return this.reads.readSignal}replace(e){this.attachments=e,this.onUserChange(),this.notify()}restore(e){x(this.attachments,[e]),this.attachments=e,this.notify()}updatePending(e,t){this.reads.updatePending(e,t)}abortReads(){this.reads.abortReads()}take(){this.abortReads();let e=this.attachments;return this.attachments=[],this.notify(),e}reset(e){this.abortReads(),e.release&&v(this.attachments),this.attachments=[],this.notify()}clearAfterSubmit(e){e&&v(this.attachments),this.attachments=[],this.notify()}}})))()}var na;function ra(){return(ra=e((()=>{Me(),j(),Et(),Rt(),X(),na=class{constructor(e){this.notify=e,this.toolOverridesValue=null,this.onMutation=()=>{},this.skillCatalog=new rn(e)}setMutationCallback(e){this.onMutation=e}get toolOverrides(){return this.toolOverridesValue}setToolOverrides(e){let t=St(e)>0?e:null;t!==this.toolOverridesValue&&(this.onMutation(),this.toolOverridesValue=t,this.notify())}reset(){this.toolOverridesValue=null}restoreToolOverrides(e){e!==void 0&&this.setToolOverrides(e)}canStartAsDraft(e){return Jr({allowedVisibilities:e?.gateway.snapshot.hello?.policy?.allowedSessionVisibilities,hasMultipleIdentities:e?.gateway.snapshot.hello?.policy?.hasMultipleSessionSharingIdentities})}composerProps(e,t,n){return{toolOverrides:this.toolOverridesValue,capabilityMenu:e?this.props(e,t,n):void 0}}props(e,t,n){this.skillCatalog.synchronize(t.client,t.connectionEpoch);let r=e.runtimeConfig.state;!r.configSnapshot&&!r.configLoading&&e.runtimeConfig.ensureLoaded().finally(this.notify);let i=r.configSnapshot?.runtimeConfig??null,a=t.connected&&!!t.client,o=Ie(e.gateway.snapshot),s=a?i?o.canAdmin?null:P(`chat.composer.menu.adminBlocked`):P(`common.loading`):P(`chat.composer.menu.offlineBlocked`);return{basePath:e.basePath,skills:this.skillCatalog.rows(n,this.toolOverridesValue),skillsLoading:this.skillCatalog.isLoading(n),skillsError:this.skillCatalog.hasError(n),mcpServers:Dt(i)??[],toolsEffectiveResult:null,toolsEffectiveLoading:!1,toolsEffectiveError:!1,toolAccessMutationBlockedReason:s,webSearchBaseEnabled:Bt(i),mutationBlockedReason:s,canAdmin:o.canAdmin&&a,adminBlockedReason:o.canAdmin?a?null:P(`chat.composer.menu.offlineBlocked`):P(`chat.composer.menu.adminBlocked`),onLoadSkills:()=>{let e=t.client,r=t.connectionEpoch;this.skillCatalog.load(e,r,n,()=>t.connected&&t.client===e&&t.connectionEpoch===r)},onPatchToolOverrides:e=>this.setToolOverrides(e),onNavigate:(t,n)=>e.navigate(t,n)}}}})))()}var ia,aa,oa,sa;function ca(){return(ca=e((()=>{Ct(),at(),S(),Qt(),i(),ia=r(()=>import(`./composer-draft-store.runtime-ChgPeVSK.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]),import.meta.url),aa=()=>ia,oa=200,sa=class{constructor(e,t,n){this.read=e,this.apply=t,this.onStorageError=n,this.gatewayOwner=``,this.recoveryScope=``,this.routeKey=``,this.revision=0,this.mutationGeneration=0,this.pristineMutationBaseline=0,this.restoreGeneration=0,this.restoredIdentity=``,this.pending=null,this.timer=null,this.incognitoRetirement=Promise.resolve(),this.committedByScope=new Map,this.committedWriteIdByScope=new Map,this.localWriteIdsByScope=new Map}setOwner(e,t,n=!1){let r=ft(e).gatewayOwner,i=JSON.stringify([r,t]),a=this.gatewayOwner?JSON.stringify([this.gatewayOwner,this.recoveryScope]):``;if(a===i)return;let o=this.routeKey;this.persistNow(),this.restoreGeneration+=1,this.restoredIdentity=``,this.routeKey=``,this.gatewayOwner=r,this.recoveryScope=t,a&&!n&&this.apply(``,[],!0),n||this.activateRoute(o)}setIncognito(e){return e&&(this.incognitoRetirement=this.retireActive()),this.incognitoRetirement}transitionIncognito(e,t,n){let r=this.setIncognito(t);if(e&&!t){r.finally(n);return}n()}selectRoute(e){e&&this.routeKey!==e&&(this.persistNow(),this.routeKey=e,this.revision=0)}activateRoute(e){this.selectRoute(e);let t=this.scope();if(!t)return;let n=B(t);if(n===this.restoredIdentity)return;if(this.restoredIdentity=n,this.read().incognito){this.retireActive();return}let r=++this.restoreGeneration,i=this.mutationGeneration,a=this.read(),o=Wt(a.message,a.attachments);this.restoreScope(t,r,i,o)}noteDraftReplaced(){this.pristineMutationBaseline=this.mutationGeneration}noteUserMutation(){if(this.mutationGeneration+=1,this.revision=z(this.revision),this.read().incognito)return;this.discardPending();let e=this.snapshot();e&&(this.pending=e,this.timer=globalThis.setTimeout(()=>this.persistNow(),oa))}retireActive(){this.mutationGeneration+=1,this.discardPending();let e=z(this.revision);this.revision=e;let t=this.scope();return t?this.enqueueWrite(async()=>{let{retireDurableComposerDraft:n}=await aa(),r=B(t),i=Math.max(e,this.committedByScope.get(r)??0),a=await n(t,i);a.status===`storage-failed`?V(t,this.onStorageError):a.status===`persisted`&&(this.localWriteIdsByScope.delete(r),this.adoptCommittedRevision(t,a.revision??i,a.writeId))}):Promise.resolve()}clearSubmittedDraft(){this.persistNow(),this.mutationGeneration+=1;let e=this.scope();if(!e)return Promise.resolve();let t=this.read(),n=kn(t.attachments);return this.enqueueWrite(async()=>{let{readDurableComposerDraft:r}=await aa(),i=B(e),a=this.committedByScope.get(i)??0,o=this.committedWriteIdByScope.get(i);for(let i=0;i<3;i+=1){let i=await r(e);if(i.status===`storage-failed`){V(e,this.onStorageError);return}let s=(i.status===`found`?i.draft.revision:i.revision)??0,c=i.status===`found`?i.draft.writeId:i.writeId;if(s!==a||c!==o){if(i.status!==`found`||!await an(i.draft,t.message,n))return;a=s,o=c,this.adoptCommittedRevision(e,s,c)}let l=z(Math.max(this.revision,a)),u=`clear:${l}`,{result:d}=await Pn({scope:e,expectedRevision:a,...o?{expectedWriteId:o}:{},revision:l,text:``,storedAttachments:[],writeId:u});if(d.status===`persisted`){this.adoptCommittedRevision(e,d.revision??l,d.writeId??u);return}if(d.status===`storage-failed`){V(e,this.onStorageError);return}}})}persistNow(){this.clearTimer();let e=this.pending;if(e){if(this.read().incognito){this.discardPending();return}this.pending=null,this.enqueueWrite(async()=>{let t=B(e.scope);try{let{result:t,payloadUnavailable:n}=await Pn({scope:e.scope,expectedRevision:e.expectedRevision,...e.expectedWriteId?{expectedWriteId:e.expectedWriteId}:{},expectedWriteIds:e.expectedWriteIds,revision:e.revision,text:e.text,storedAttachments:e.attachments,writeId:e.writeId});if(n&&V(e.scope,this.onStorageError),t.status===`persisted`||t.status===`payload-too-large`){let n=t.revision??e.revision;this.adoptCommittedRevision(e.scope,n,t.writeId??e.writeId),t.status===`payload-too-large`&&V(e.scope,this.onStorageError);return}if(t.status===`storage-failed`){V(e.scope,this.onStorageError);return}if(this.routeKey!==e.scope.scopeKey||this.revision!==e.revision)return;this.restoredIdentity=``,this.activateRoute(this.routeKey)}finally{let n=this.localWriteIdsByScope.get(t);n?.delete(e.writeId),n?.size===0&&this.localWriteIdsByScope.delete(t)}})}}disconnect(){this.persistNow(),this.restoreGeneration+=1}scope(){return!this.gatewayOwner||!this.recoveryScope||!this.routeKey?null:{gatewayOwner:this.gatewayOwner,recoveryScope:this.recoveryScope,scopeKey:this.routeKey}}snapshot(){let e=this.scope();if(!e||this.revision<=0)return null;let t=this.read(),n=B(e),r=[...this.localWriteIdsByScope.get(n)??[]],i=`${this.revision}:${Math.random().toString(36).slice(2)}`;return this.rememberLocalWriteId(n,i),{scope:e,expectedRevision:this.committedByScope.get(n)??0,...this.committedWriteIdByScope.get(n)?{expectedWriteId:this.committedWriteIdByScope.get(n)}:{},expectedWriteIds:r,revision:this.revision,text:t.message,attachments:kn(t.attachments),writeId:i}}async restoreScope(e,t,n,r){let{readDurableComposerDraft:i}=await aa(),a=await i(e);if(a.status===`storage-failed`){V(e,this.onStorageError);return}let o=a.status===`found`?a.draft.revision:a.revision,s=a.status===`found`?a.draft.writeId:a.writeId,c=B(e);o===void 0?(this.committedByScope.delete(c),this.committedWriteIdByScope.delete(c)):(this.committedByScope.set(c,o),s&&this.committedWriteIdByScope.set(c,s));let l=this.read(),u=this.scope();if(t!==this.restoreGeneration||n!==this.mutationGeneration||!u||B(e)!==B(u)||r!==Wt(l.message,l.attachments))return;if(o===void 0||o<this.revision||n>this.pristineMutationBaseline){o!==void 0&&o>=this.revision?this.revision=z(o):this.revision<=0&&n>this.pristineMutationBaseline&&(this.revision=z(0)),this.pending=this.snapshot(),this.persistNow();return}let d=[];if(a.status===`found`)try{d=await sn(a.draft.attachments)}catch{V(e,this.onStorageError);return}let f=this.read(),p=this.scope();if(t!==this.restoreGeneration||n!==this.mutationGeneration||!p||B(e)!==B(p)||r!==Wt(f.message,f.attachments)){v(d);return}this.revision=o,this.apply(a.status===`found`?a.draft.text:``,d)}enqueueWrite(e){return e()}clearTimer(){this.timer!==null&&(globalThis.clearTimeout(this.timer),this.timer=null)}discardPending(){this.clearTimer();let e=this.pending;if(this.pending=null,!e)return;let t=B(e.scope),n=this.localWriteIdsByScope.get(t);n?.delete(e.writeId),n?.size===0&&this.localWriteIdsByScope.delete(t)}rememberLocalWriteId(e,t){let n=this.localWriteIdsByScope.get(e)??new Set;n.add(t),this.localWriteIdsByScope.set(e,n)}adoptCommittedRevision(e,t,n){let r=B(e);this.committedByScope.set(r,t),n&&this.committedWriteIdByScope.set(r,n);let i=this.scope();i&&B(i)===r&&t>this.revision&&(this.revision=t)}}})))()}function la(e,t){return{target:e.sessionKey?e.target:t.cloudProfileId?{kind:`profile`,profileId:t.cloudProfileId,...t.machineClass?{machineClass:t.machineClass}:{}}:t.deviceId?{kind:`device`,deviceId:t.deviceId}:t.autoDevice?{kind:`auto-device`}:null}}function ua(e){let t=e.createParams?.incognito?`incognito`:e.createParams?.visibility===`draft`?`draft`:`normal`;return{placement:{agentId:e.agentId,profileId:e.target.kind===`profile`?e.target.profileId:``,...e.target.kind===`profile`?{machineClass:e.target.machineClass}:e.target.kind===`device`?{deviceId:e.target.deviceId}:{autoDevice:!0},cwd:e.createParams?.cwd},draft:{message:e.message,attachments:or(e.attachments),visibility:t,toolOverrides:e.createParams?.toolOverrides??null,permissionMode:e.createParams?.permissionMode}}}function da(){return(da=e((()=>{sr()})))()}var fa;function pa(){return(pa=e((()=>{rt(),fe(),fa=class{constructor(e){this.gateway=e,this.pending=null}get active(){return this.pending!==null}start(e){let t=this.gateway.sessionCreateScope;if(!t)return e;if(!this.pending){let n=Date.now();this.pending={params:Object.freeze({...e,idempotencyKey:f()}),scope:t,startedAt:n,deadline:n+nt,interrupted:!1}}return this.pending.params}clear(){this.pending=null}interrupt(){return!this.pending||!this.matchesGateway()?(this.clear(),!1):(this.pending.interrupted=!0,!0)}retireChangedOwner(){return!this.pending||this.matchesGateway()?!1:(this.clear(),!0)}resume(){return this.pending?.interrupted?Date.now()>=this.pending.deadline?(this.clear(),{kind:`expired`}):this.matchesGateway()?this.gateway.connected?(this.pending.interrupted=!1,{kind:`resume`,params:this.pending.params,startedAt:this.pending.startedAt}):{kind:`wait`}:(this.clear(),{kind:`owner-changed`}):{kind:`wait`}}matchesGateway(){return this.pending?.scope===this.gateway.sessionCreateScope}}})))()}var ma;function ha(){return(ha=e((()=>{ma=class{constructor(e){this.requestUpdate=e}setMutationCallback(e){this.onMutation=e}set(e){this.value=e,this.onMutation?.(),this.requestUpdate()}restore(e){this.value=e}reset(){this.value=void 0}}})))()}function ga(e){let t=e.context.gateway.snapshot,r={id:f(),text:e.message,attachments:e.attachments,createdAt:Date.now(),kind:`queued`,refreshSessions:!0,sendAttempts:1,sendError:e.error,sendState:`failed`,sessionKey:e.sessionKey,agentId:n(e.agentId)};return!Hn({settings:Pe(),assistantAgentId:t.assistantAgentId,agentsList:e.context.agents.state.agentsList,hello:t.hello},e.sessionKey,r)&&(Gn(e.sessionKey,{...r,sendRunId:f()}),!0)}function _a(){return(_a=e((()=>{Ae(),T(),fe(),Pt(),Wn()})))()}var va;function ya(){return(ya=e((()=>{Ne(),kt(),m(),T(),va=class{constructor(){this.current=null}isCurrent(e,t){let r=this.current,i=e?.gateway.snapshot;return!!(r&&i?.phase===`connected`&&i.client===r.client&&i.sessionKey===r.key&&n(t)===r.agentId)}async navigate(e,t){this.current=t,Be({selection:e.agentSelection,gateway:e.gateway,sessionKey:t.key,agentId:t.agentId});let n=de({context:e,face:`chat`,sessionKey:t.key,agentId:t.agentId,focusComposer:!0}).options;await yt({document,from:`new-session`,to:`chat`,prefersReducedMotion:globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1,prepare:()=>e.preload(`chat`,n),navigate:()=>e.navigateAndWait(`chat`,n)}),this.current===t&&(this.current=null)}}})))()}function ba(e){return e.modelControl.cloudRuntimeUnsupportedReason()||(e.repository.kind===`checking`?P(`newSession.checkingGit`):e.repository.kind===`unavailable`&&!e.worktreeAvailable()?P(`newSession.gitCheckUnavailable`):e.worktreeAvailable()?void 0:P(`newSession.cloudRequiresWorktree`))}function xa(e,t){let n=e.gatewayState,r=e.placeState,i=e.submissionSnapshot(),a=!!e.pendingPlacement.sessionKey;if(e.submitting)return{gate:`submitting`};if(n.preferenceLoading||r.modelControl.isRestoringPreference()||!r.placementPreferenceReady)return{gate:`preference-restore`,reason:P(`newSession.restoringPreferences`)};if(e.requiresModelSetup())return{gate:`model-setup`,reason:P(`modelSetup.required.title`)};if(K(i.data,i.context?.sessions))return{gate:`route-pending`,reason:P(`newSession.catalogUnavailable`)};let o=xt(r.modelControl.modelUnavailableReason(r.selectedAgent()));if(o)return{gate:`model-unavailable`,reason:o};if(e.pendingAttachmentReads>0)return{gate:`attachment-reads`,reason:P(`newSession.readingAttachment`)};if(!a&&e.submissionOutcomeUnknown)return{gate:`outcome-unknown`,reason:P(e.submissionOutcomeUnknown===`gateway-changed`?`newSession.createOutcomeUnknown`:`newSession.placementSetupInterrupted`)};let s=i.context?.gateway,c=s?.snapshot.phase===`connected`?s.snapshot.client??null:null;if(!s||!c)return{gate:`disconnected`,reason:P(`sessionsView.actionRequiresConnection`)};let l=t===`terminal`?e.terminalStartAccess():e.submissionAccess();if(!l.allowed)return{gate:`access`,reason:l.reason};if(t===`terminal`&&e.hasCapabilityOverrides)return{gate:`terminal-capabilities`,reason:P(`newSession.terminalCapabilityOverridesUnsupported`)};if(r.folderSubmissionBlocked())return{gate:`folder`,reason:P(`newSession.checkingPlace`)};if(a)return e.pendingPlacement.retryAllowed&&c.recoveryScopeReady&&e.placementTargetForSubmission()&&e.pendingPlacement.agentId&&e.pendingPlacement.gatewayUrl===s.connection.gatewayUrl&&e.pendingPlacement.recoveryScope===c.recoveryScope?Sa(e,t,a):{gate:`placement-recovery`,reason:P(`newSession.placementNotReady`)};if(r.agents().length===0)return{gate:`agents`,reason:P(`newSession.agentsUnavailable`)};if(!Or(i.data,r.selectedAgent()))return{gate:`agent-not-allowed`,reason:P(`newSession.catalogUnavailable`)};if(!r.devicePlacementReady())return{gate:`device`,reason:r.devicePlacementDisabledReason()??P(`newSession.nodeUnavailable`)};let u=r.modelControl.devicePlacementUnsupportedReason();if((r.deviceId||r.autoDevice)&&u)return{gate:`device-runtime`,reason:u};let d=e.placementTargetForSubmission();if(d&&(!c.recoveryScope||!c.recoveryScopeReady||n.cloudProfilesPending))return{gate:`placement-recovery`,reason:P(`newSession.placementNotReady`)};let f=d?.kind===`profile`?d.profileId:``;return f&&(!n.cloudProfilesReady||!r.worktree||!n.cloudProfiles.some(e=>e.id===f)||e.cloudRuntimeUnsupportedReason())?{gate:`cloud`,reason:e.cloudDisabledReason()??(r.worktree?P(`newSession.placementNotReady`):P(`newSession.cloudRequiresWorktree`))}:r.worktree&&!r.worktreeAvailable()?{gate:`worktree-unavailable`,reason:r.repository.kind===`checking`?P(`newSession.checkingGit`):P(`newSession.worktreeUnavailable`)}:r.worktree&&!Yr(r.worktreeName)?{gate:`worktree-name`,reason:P(`newSession.worktreeNameInvalid`)}:t===`terminal`&&!(r.folder.trim()||r.workspacePath())?{gate:`terminal-folder`,reason:P(`newSession.terminalNeedsFolder`)}:Sa(e,t,a)}function Sa(e,t,n){if(t!==`session`)return;let r=n?e.pendingPlacement.message:e.message.trim(),i=n?!!e.pendingPlacement.attachments?.length:e.hasDraftAttachments;return r||i?void 0:{gate:`empty-draft`}}var Ca;function wa(){return(wa=e((()=>{j(),lt(),G(),X(),Ca=new Set([`outcome-unknown`,`worktree-name`])})))()}function Ta(e,t){let n=w(e,{method:`sessions.catalog.startTerminal`,requiredScope:`operator.admin`});return!n.allowed||!t?n:w(e,{method:`worktrees.create`,requiredScope:`operator.admin`})}async function Ea(e,t,n){let r=t.cwd;if(t.worktree){let i=await Mr(e,{repoRoot:r,name:t.worktreeName,baseRef:t.baseRef});if(!n())return null;r=i.path}return e.request(`sessions.catalog.startTerminal`,{catalogId:t.catalogId,agentId:t.agentId,cwd:r,...t.initialMessage?{initialMessage:t.initialMessage}:{}})}function Da(){return(Da=e((()=>{p()})))()}var Oa;function ka(){return(ka=e((()=>{j(),ut(),p(),pt(),T(),wt(),se(),sr(),qn(),Pt(),Wn(),ta(),ra(),G(),Y(),X(),ca(),da(),pa(),ha(),_a(),Ci(),ya(),wa(),Da(),Oa=class{constructor(e,t,n,r){this.gateway=e,this.place=t,this.read=n,this.callbacks=r,this.visibilityValue=`normal`,this.messageValue=``,this.submittingValue=!1,this.blockedSubmitGate=null,this.submissionOutcomeUnknown=null,this.startedSession=new va,this.error=null,this.submitRequestToken=0,this.pendingPlacement=new Si,this.composerTextarea=new Ur,this.permission=new ma(()=>this.callbacks.requestUpdate()),this.cloudDisabledReason=()=>ba(this.place),this.placement=()=>la(this.pendingPlacement,this.place),this.capabilities=new na(r.requestUpdate),this.capabilities.setMutationCallback(()=>this.startedSession.current=null),this.permission.setMutationCallback(()=>this.startedSession.current=null),this.sessionStartup=new fa(e),this.draftPersistence=new sa(()=>({message:this.messageValue,attachments:this.attachmentDraft.attachments,incognito:this.visibilityValue===`incognito`}),(e,t,n)=>{this.restoreDraftState({message:e,attachments:t,visibility:n?`normal`:this.visibilityValue})},()=>{this.error=Kt,this.callbacks.requestUpdate()}),this.attachmentDraft=new ea(r.requestUpdate,()=>{this.startedSession.current=null,this.draftPersistence.noteUserMutation()})}get visibility(){return this.visibilityValue}get message(){return this.messageValue}get submitting(){return this.submittingValue||this.sessionStartup.active}resumeInterruptedSubmission(){let e=this.sessionStartup.resume();e.kind===`resume`?this.submit(e):e.kind!==`wait`&&(this.submissionOutcomeUnknown=`gateway-changed`,this.callbacks.requestUpdate())}setMessage(e){this.startedSession.current=null,this.messageValue=e,this.draftPersistence.noteUserMutation(),this.callbacks.requestUpdate()}restoreMessage(e){this.draftPersistence.noteDraftReplaced(),this.messageValue=e,this.callbacks.requestUpdate()}restoreDraftState(e){this.draftPersistence.noteDraftReplaced(),this.messageValue=e.message,this.visibilityValue=e.visibility,this.capabilities.restoreToolOverrides(e.toolOverrides),`permissionMode`in e&&this.permission.restore(e.permissionMode),this.attachmentDraft.restore(e.attachments)}setVisibility(e){this.startedSession.current=null;let t=this.visibilityValue===`incognito`,n=this.callbacks.requestUpdate;this.visibilityValue=e,this.draftPersistence.transitionIncognito(t,e===`incognito`,n)}setError(e){(e!==null||this.error===P(`newSession.cloudRecoveryUnavailable`))&&(this.error=e),this.callbacks.requestUpdate()}clearError(){this.error=null,this.callbacks.requestUpdate()}clearErrorIf(e){this.error===e&&this.clearError()}markPendingPlacementUnavailable(e){this.pendingPlacement.retryAllowed=!1,this.submissionOutcomeUnknown=e,this.callbacks.requestUpdate()}noteBlockedSubmitAttempt(e=`session`){this.blockedSubmitGate=this.submitBlock(e)?.gate??null,this.callbacks.requestUpdate()}blockedSubmitNotice(){let e=this.blockedSubmitGate?this.submitBlock():void 0;return e?.gate===this.blockedSubmitGate&&!Ca.has(e.gate)?e.reason:void 0}showStartInTerminal(){let{context:e,data:t}=this.read();return!!(e&&q(t)&&!this.placement().target&&t?.startTerminal&&e.config.current.cliAgentsEnabled===!0&&ye(e.gateway.snapshot,e.config.current.terminalEnabled??!1))}buildDraftSessionCreateParams(e={}){return Xr({agentId:this.place.agentId,message:e.message??``,model:this.place.modelControl.selected,contextWindow:this.place.modelControl.contextWindow,thinkingLevel:this.place.modelControl.thinkingLevel,fastMode:this.place.modelControl.fastMode,toolOverrides:this.capabilities.toolOverrides,permissionMode:this.permission.value,visibility:e.visibility??this.visibilityValue,attachments:e.attachments,projectId:this.place.browser.remoteProject?.projectId??this.place.browser.projectId,projectGitUrl:this.place.browser.remoteProject?.cloneUrl,worktree:this.place.worktree,baseRef:this.place.baseRef,worktreeName:this.place.worktreeName,cwd:this.place.folder,workspace:this.place.workspacePath(),catalogId:this.read().data?.catalogId,category:this.gateway.resolvedGroupCategory()})}submissionAccess(e=this.pendingPlacement.createParams??this.buildDraftSessionCreateParams()){let t=this.read().context?.gateway.snapshot,n=!!this.pendingPlacement.sessionKey,r=this.placement().target,i=this.messageValue.trim()||this.attachmentDraft.attachments.length,a=r||!i?this.place.browser.remoteProject:null;if(!n&&a&&!a.projectId){let e=w(t,{method:`projects.add`,requiredScope:`operator.write`});if(!e.allowed)return e}if(!r||!n||this.pendingPlacement.phase===`creating`){let n=w(t,{method:`sessions.create`,params:e});if(!n.allowed||!r)return n}return w(t,{method:`sessions.dispatch`,requiredScope:r.kind===`profile`?`operator.admin`:`operator.write`,params:it({key:this.pendingPlacement.sessionKey,agentId:this.pendingPlacement.agentId||this.place.agentId,target:r})})}submitDisabledReason(){return this.submitBlock()?.reason}incognitoDisabledReason(){let e=w(this.read().context?.gateway.snapshot,{method:`sessions.create`,params:this.buildDraftSessionCreateParams({visibility:`incognito`})});return e.allowed?void 0:e.reason}canSubmit(e=`session`){return this.submitBlock(e)===void 0}submitBlock(e=`session`){return e===`session`&&this.attachmentDraft.pendingReads===0&&this.startedSession.isCurrent(this.read().context,this.place.agentId)?this.submittingValue?{gate:`submitting`}:void 0:xa({gatewayState:this.gateway,placeState:this.place,pendingPlacement:this.pendingPlacement,submitting:this.submittingValue,message:this.messageValue,submissionOutcomeUnknown:this.submissionOutcomeUnknown,pendingAttachmentReads:this.attachmentDraft.pendingReads,hasDraftAttachments:this.attachmentDraft.attachments.length>0,hasCapabilityOverrides:this.capabilities.toolOverrides!==null,submissionSnapshot:()=>this.read(),requiresModelSetup:()=>this.requiresModelSetup(),submissionAccess:()=>this.submissionAccess(),terminalStartAccess:()=>Ta(this.read().context?.gateway.snapshot,this.place.worktree),placementTargetForSubmission:()=>this.placement().target,cloudDisabledReason:()=>this.cloudDisabledReason(),cloudRuntimeUnsupportedReason:()=>this.place.modelControl.cloudRuntimeUnsupportedReason(this.gateway.cloudProfiles.find(e=>e.id===this.place.cloudProfileId))},e)}requiresModelSetup(){let e=this.place.selectedAgent();return Yn({catalog:q(this.read().data)||this.place.remotePlacement||!!this.pendingPlacement.sessionKey,connected:this.gateway.connected,agentsLoaded:this.read().context?.agents.state.agentsList!==null,selectedAgentFound:e!==void 0,agentModel:e?.model?.primary})}invalidate(e=null){this.submitRequestToken+=1,this.startedSession.current=null,(e&&this.submittingValue&&!this.sessionStartup.interrupt()||this.sessionStartup.retireChangedOwner())&&(this.submissionOutcomeUnknown=e),this.submittingValue=!1,this.callbacks.requestUpdate()}resetDraft(){this.sessionStartup.clear();let e=!!this.pendingPlacement.sessionKey;if(this.blockedSubmitGate=null,this.invalidate(),this.submissionOutcomeUnknown=e?this.submissionOutcomeUnknown??`placement-interrupted`:null,this.visibilityValue=`normal`,this.capabilities.reset(),this.permission.reset(),this.attachmentDraft.reset({release:!0}),e){this.pendingPlacement.restored||(this.pendingPlacement.retryAllowed=!1);let e=this.pendingPlacement.capture();e&&this.applyRecoveryDraft(e),this.pendingPlacement.restored=!1}else this.clearPendingPlacementRecovery(),this.draftPersistence.noteDraftReplaced(),this.messageValue=``;this.error=null,this.callbacks.requestUpdate()}clearPendingPlacementRecovery(){this.pendingPlacement.clear(),this.submissionOutcomeUnknown=null,this.callbacks.requestUpdate()}releasePendingPlacementOwner(){this.pendingPlacement.reset(),this.submissionOutcomeUnknown=null,this.callbacks.requestUpdate()}restorePendingPlacementRecovery(e,t){let n=this.pendingPlacement.restore(e,t);n&&this.applyRecoveryDraft(n)}async submit(e){let t=this.read().context;if(!t||!e&&!this.canSubmit()){this.noteBlockedSubmitAttempt();return}this.blockedSubmitGate=null;let r=!e&&!!this.pendingPlacement.sessionKey,i=e?.params.message??(r?this.pendingPlacement.message:this.messageValue.trim()),a=this.attachmentDraft.attachments,o=e?e.params.attachments:r?void 0:cr(a),s=r?this.pendingPlacement.attachments:o,c=e?.params.agentId??(r?this.pendingPlacement.agentId:n(this.place.agentId)),l=r?this.pendingPlacement.gatewayUrl:t.gateway.connection.gatewayUrl,u=t.gateway.snapshot.client;if(!u||!t.gateway.snapshot.hello)return;let d=r?this.pendingPlacement.recoveryScope:u.recoveryScope,f=++this.submitRequestToken,p=e?.startedAt??Date.now();this.submittingValue=!0,this.error=null,this.place.browser.close(),this.callbacks.closeTransientUi(),this.callbacks.requestUpdate();try{let n=this.startedSession.current;if(n&&this.startedSession.isCurrent(t,this.place.agentId)){await this.startedSession.navigate(t,n);return}this.startedSession.current=null;let m=e?null:this.placement().target,h=i||s?.length,g=!e&&!r&&(m||!h)?this.place.browser.remoteProject:null;if(g&&!g.projectId&&!this.place.browser.projectId){let e=await u.request(`projects.add`,{gitUrl:g.cloneUrl},{timeoutMs:null});if(f!==this.submitRequestToken||this.gateway.client!==u)return;this.place.browser.recordRemoteProjectId(g.cloneUrl,e.id)}let _=e?.params??this.buildDraftSessionCreateParams({message:m?``:i,visibility:this.visibilityValue===`draft`&&!this.capabilities.canStartAsDraft(this.read().context)?`normal`:this.visibilityValue,attachments:m?void 0:o}),v=m?r?this.pendingPlacement.createParams:this.pendingPlacement.stageCreate({agentId:c,target:m,message:i,attachments:s,gatewayUrl:l,recoveryScope:d,createParams:_,persistent:this.visibilityValue!==`incognito`}):void 0,y=e?w(t.gateway.snapshot,{method:`sessions.create`,params:_}):this.submissionAccess(v??_);if(!y.allowed){this.sessionStartup.clear(),this.error=y.reason;return}let b=m?this.pendingPlacement.capture():null;if(m&&!b){this.setPlacementRecoveryUnavailable();return}let ee=b?.sessionKey??``,te=e=>this.pendingPlacement.owns(l,d,e),x=()=>te(ee),S=()=>this.read().isConnected&&u.recoveryScopeReady&&f===this.submitRequestToken&&this.gateway.client===u&&this.gateway.gatewayUrl===l&&this.gateway.recoveryScope===d,C=r&&this.pendingPlacement.phase!==`creating`?{key:this.pendingPlacement.sessionKey,initialRun:{status:`idle`}}:await t.sessions.createResult(v??e?.params??this.sessionStartup.start(_),{reconciliation:`background`});if(f!==this.submitRequestToken&&!m)return;if(!C){if(f!==this.submitRequestToken)return;this.sessionStartup.clear(),this.error=t.sessions.state.error??P(`newSession.createFailed`);return}if(m&&b){if(b.phase===`creating`&&(!S()||!x())){let e=await ht(u,C.key,c);e?(x()&&(this.pendingPlacement.promoteToDispatching(C.key),this.pendingPlacement.retryAllowed=!0),this.error=P(`newSession.placementStartFailed`,{error:e}),this.callbacks.requestUpdate()):x()&&this.clearPendingPlacementRecovery();return}if(b.phase===`creating`&&S()&&x()&&!this.pendingPlacement.promoteToDispatching(C.key)){this.setPlacementRecoveryUnavailable();return}let e=this.pendingPlacement.capture();if(!e||e.phase===`creating`){this.setPlacementRecoveryUnavailable();return}if(f!==this.submitRequestToken)return;t.placementStartup.start({recovery:e,persistRecovery:this.pendingPlacement.persistent,recovering:b.phase!==`creating`,createdAt:p});let n=()=>S()&&te(e.sessionKey);if(!n()||(await this.draftPersistence.clearSubmittedDraft(),!n()))return;this.pendingPlacement.reset(),this.attachmentDraft.clearAfterSubmit(!0),await this.startedSession.navigate(t,{client:u,key:C.key,agentId:c});return}if(f!==this.submitRequestToken)return;let ne=C.initialRun.status===`rejected`&&ga({agentId:this.place.agentId,attachments:a,context:t,error:C.initialRun.error,message:i,sessionKey:C.key});if(C.initialRun.status===`started`){let{hello:e,selfUser:n}=t.gateway.snapshot,r=bt(e,u.instanceId,n);Un(t.initialUserMessage,C.key,{text:i,attachments:a,createdAt:p,...r?{sender:r}:{}},u,{runId:C.initialRun.runId,messageSeq:C.initialRun.messageSeq})}if(await this.draftPersistence.clearSubmittedDraft(),f!==this.submitRequestToken)return;this.attachmentDraft.clearAfterSubmit(!ne),await this.startedSession.navigate(t,{client:u,key:C.key,agentId:c}),this.sessionStartup.clear()}catch(e){f===this.submitRequestToken&&this.gateway.client===u&&(this.sessionStartup.clear(),this.error=e instanceof Error?e.message:String(e))}finally{f===this.submitRequestToken&&(this.submittingValue=!1,this.callbacks.requestUpdate())}}async startInTerminal(){let{context:e,data:t}=this.read(),r=e?.gateway.snapshot.client,i=t?.catalogId.trim()??``,a=n(this.place.agentId);if(!e||!r||!i||!a||!this.canSubmit(`terminal`)){this.noteBlockedSubmitAttempt(`terminal`);return}this.blockedSubmitGate=null;let o=++this.submitRequestToken,s=this.messageValue.trim();this.submittingValue=!0,this.error=null,this.place.browser.close(),this.callbacks.closeTransientUi(),this.callbacks.requestUpdate();try{let e=await Ea(r,{catalogId:i,agentId:a,cwd:this.place.folder.trim()||this.place.workspacePath(),initialMessage:s,worktree:this.place.worktree,worktreeName:this.place.worktreeName,baseRef:this.place.baseRef},()=>o===this.submitRequestToken&&this.gateway.client===r);if(!e||o!==this.submitRequestToken||this.gateway.client!==r||(this.startedSession.current=null,await this.draftPersistence.clearSubmittedDraft(),o!==this.submitRequestToken||this.gateway.client!==r))return;this.messageValue=``,this.attachmentDraft.clearAfterSubmit(!0),_t(e.sessionId)}catch(e){o===this.submitRequestToken&&this.gateway.client===r&&(this.error=e instanceof Error?e.message:String(e))}finally{o===this.submitRequestToken&&(this.submittingValue=!1,this.callbacks.requestUpdate())}}disconnect(){this.startedSession.current=null,this.draftPersistence.disconnect(),this.attachmentDraft.reset({release:!0}),this.composerTextarea.disconnect()}setPlacementRecoveryUnavailable(){this.error=P(`newSession.placementStartFailed`,{error:`placement recovery storage is unavailable`})}applyRecoveryDraft(e){let t=ua(e);this.place.applyPendingPlacement(t.placement),this.restoreDraftState(t.draft)}}})))()}function Aa(e,t){let n=e.visibility===`incognito`,r=e.visibility===`draft`,i=e.incognitoDisabledReason(),a=e.submitting||!!e.pendingPlacement.sessionKey||!!i,o=i??P(`newSession.incognitoDescription`);return k`
<div class="new-session-page__incognito-rail">
${t?k`
<openclaw-tooltip
class="new-session-page__draft-tooltip"
.content=${P(`newSession.draftDescription`)}
>
<button
type="button"
class="shell-chrome-controls__button new-session-page__draft-toggle ${r?`new-session-page__draft-toggle--active`:``}"
role="switch"
aria-label=${`${P(`newSession.draft`)}: ${P(`newSession.draftDescription`)}`}
aria-checked=${String(r)}
?disabled=${e.submitting||!!e.pendingPlacement.sessionKey}
title=${P(`newSession.draftDescription`)}
@click=${()=>e.setVisibility(r?`normal`:`draft`)}
>
${M.pencil}
${r?k`<span class="new-session-page__draft-toggle-label"
>${P(`newSession.draft`)}</span
>`:O}
</button>
</openclaw-tooltip>
`:O}
<openclaw-tooltip .content=${o}>
<button
type="button"
class="shell-chrome-controls__button new-session-page__incognito-toggle ${n?`new-session-page__incognito-toggle--active`:``}"
role="switch"
aria-label=${P(`newSession.incognito`)}
aria-checked=${String(n)}
?disabled=${a}
title=${o}
@click=${()=>{a||e.setVisibility(n?`normal`:`incognito`)}}
>
${Ma}
</button>
</openclaw-tooltip>
</div>
`}function ja(e){let t=P(`newSession.incognitoDescription`);return k`
<div
class="new-session-page__incognito-notice ${e?`new-session-page__incognito-notice--visible`:``}"
role="status"
aria-hidden=${String(!e)}
>
<span class="new-session-page__incognito-notice-icon" aria-hidden="true">
${Ma}
</span>
<span>${t}</span>
</div>
`}var Ma;function Na(){return(Na=e((()=>{A(),Xe(),N(),Ke(),j(),Ma=Ge(Ce` <path
d="M4 13V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5"
/>
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
<path d="M10 22v-5" />
<path d="M14 19v-2" />
<path d="M18 20v-3" />
<path d="M2 13h20" />
<path d="M6 20v-3" />`)})))()}function Pa(e){return Ba.has(e)}function Fa(e){let t=new Map;for(let n of e){let e=(n.deviceId??n.instanceId)?.trim().toLowerCase();!e||n.mode?.trim().toLowerCase()===`gateway`||t.set(e,n.reason?.trim().toLowerCase()===`disconnect`?`offline`:`connected`)}return JSON.stringify([...t].toSorted(([e],[t])=>e.localeCompare(t)))}function Ia(e){return{addController:t=>e.addController(t),removeController:t=>e.removeController(t),requestUpdate:()=>e.requestUpdate(),get updateComplete(){return e.updateComplete}}}function La(e){let t=e.querySelector(`.new-session-page__select--agent wa-dropdown`);t&&(t.open=!1)}function Ra(e){for(let t of[`wa-dropdown[open]`,`wa-popover.new-session-page__picker-popover`])for(let n of e.querySelectorAll(t))n.open=!1}function za(e,t){if(document.querySelector(`.shell-nav[aria-modal='true']`))return;let n=e.querySelectorAll(`.chat-controls__inline-select[open]`);if(n.length!==0){if(t.type===`keydown`){let e=t;if(tn(e),e.defaultPrevented||e.key!==`Escape`)return;let r=[...n].find(e=>t.composedPath().includes(e))??n[0];if(!r)return;let i=t.composedPath().includes(r);e.preventDefault(),r.open=!1,i&&r.querySelector(`summary`)?.focus();return}for(let e of n)t.composedPath().includes(e)||(e.open=!1)}}var Ba;function Va(){return(Va=e((()=>{Ft(),Ba=new Set([`config.changed`,`node.pair.requested`,`node.pair.resolved`,`node.runnerInventory.changed`,`device.pair.requested`,`device.pair.resolved`])})))()}function Ha(e){let t=n(e.agentId);return k`
<span class="new-session-page__select new-session-page__select--agent">
<openclaw-agent-select
class="agent-select--compact"
.options=${e.agents.map(t=>({value:n(t.id),label:ae(t,e.agentIdentity?.get(t.id)),agent:t}))}
.value=${t}
.accessibleLabel=${P(`newSession.agent`)}
.menuLabel=${P(`newSession.agents`)}
.disabled=${e.disabled}
.onSelect=${e.onSelect}
></openclaw-agent-select>
</span>
`}function Ua(){return(Ua=e((()=>{A(),_r(),j(),ge(),T()})))()}function Wa(e){let t=yr(e.environments,e.devicePlacement,e.deviceDisabledReason),n=br(e.environments,t,e.deviceDisabledReason),r=t.find(t=>t.deviceId===e.deviceId),i=e.cloudProfiles.find(t=>t.id===e.cloudProfileId);if(e.cloudProfileId){let r=i?.machines??[],a=r.find(e=>e.default===!0),o=e.machineClass?r.find(t=>t.id===e.machineClass):a;return{kind:`cloud`,label:e.machineClass?P(`newSession.cloudWorkerMachine`,{profile:i?.id??e.cloudProfileId,machine:o?.label??e.machineClass}):i?.id??e.cloudProfileId,cloudMachines:r,selectedMachineId:o?.id??``,devices:t,cloudProfiles:e.cloudProfiles,autoDeviceDisabledReason:n}}return e.deviceId?{kind:`device`,label:r?.label??e.deviceId,cloudMachines:[],selectedMachineId:``,devices:t,cloudProfiles:e.cloudProfiles,autoDeviceDisabledReason:n}:e.autoDevice?{kind:`auto-device`,label:P(`newSession.autoDevice`),cloudMachines:[],selectedMachineId:``,devices:t,cloudProfiles:e.cloudProfiles,autoDeviceDisabledReason:n}:{kind:`local`,label:P(`newSession.local`),cloudMachines:[],selectedMachineId:``,devices:t,cloudProfiles:e.cloudProfiles,autoDeviceDisabledReason:n}}function Ga(e){let t=e.state.kind===`cloud`?M.server:M.monitor,n=e.gatewayName?P(`newSession.gatewayNamed`,{name:e.gatewayName}):P(`newSession.gateway`);return k`
<span class="new-session-page__select">
<button
id="new-session-where-trigger"
type="button"
class="new-session-page__trigger ${e.popoverHiding?`new-session-page__trigger--hiding`:``}"
title=${P(`newSession.where`)}
aria-label="${P(`newSession.where`)}: ${e.state.label}"
data-cloud-profile=${e.cloudProfileId||O}
data-machine-class=${e.machineClass||O}
data-device-id=${e.deviceId||O}
data-auto-device=${e.autoDevice?`true`:O}
aria-haspopup="dialog"
aria-expanded=${String(e.popoverOpen)}
?disabled=${e.submitting||e.pendingPlacement}
@click=${e.onGuardTransition}
>
<span class="new-session-page__target-icon" aria-hidden="true">${t}</span>
<span class="new-session-page__trigger-label">${e.state.label}</span>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--desktop"
aria-hidden="true"
>${M.chevronDown}</span
>
<span
class="new-session-page__trigger-chevron new-session-page__trigger-chevron--mobile"
aria-hidden="true"
>${M.chevronsUpDown}</span
>
</button>
</span>
<wa-popover
class="new-session-page__select new-session-page__where-popover new-session-page__picker-popover"
for="new-session-where-trigger"
placement="bottom-start"
without-arrow
@wa-show=${e.onPopoverShow}
@wa-hide=${e.onPopoverHide}
@wa-after-hide=${e.onPopoverAfterHide}
>
<div class="new-session-page__picker-root">
<div class="new-session-page__menu-title">${P(`newSession.environments`)}</div>
${H({value:`gateway`,label:P(`newSession.local`),icon:M.monitor,sub:e.gatewayName||void 0,checked:!e.deviceId&&!e.autoDevice&&!e.cloudProfileId,title:n,onSelect:()=>e.onSelectDevice(``)},e.submitting)}
${e.state.devices.length>0?k`
<div class="new-session-page__menu-title">${P(`newSession.yourDevices`)}</div>
${H({value:`auto-device`,label:P(`newSession.autoDevice`),sub:P(e.autoPlacementMode===`eligible-order`?`newSession.autoDeviceSubEligible`:`newSession.autoDeviceSub`),icon:M.monitor,checked:e.autoDevice===!0,disabled:!!e.state.autoDeviceDisabledReason,title:e.state.autoDeviceDisabledReason,facts:e.state.autoDeviceDisabledReason?[e.state.autoDeviceDisabledReason]:void 0,onSelect:e.onSelectAutoDevice},e.submitting)}
${e.state.devices.map(t=>{let n=Sr({workerSlots:t.workerSlots,capabilities:t.capabilities,commands:t.invocableCommands,unavailable:!t.selectable});return H({value:`device:${t.deviceId}`,label:t.label,sub:t.subtitle,icon:M.monitor,facts:t.facts,meter:n?.meter,checked:e.deviceId===t.deviceId,disabled:!t.selectable,title:[t.disabledReason,n?.title].filter(Boolean).join(` · `)||void 0,onSelect:()=>e.onSelectDevice(t.deviceId)},e.submitting)})}
`:O}
${e.isAdmin&&(e.state.cloudProfiles.length>0||e.cloudProfileId)?k`
<div class="new-session-page__menu-title">${P(`newSession.cloud`)}</div>
${er({profiles:e.state.cloudProfiles,selectedId:e.cloudProfileId,submitting:e.submitting,icon:M.server,disabled:!e.worktreeAvailable||!!e.cloudDisabledReason,disabledReason:e.cloudDisabledReason,profileDisabledReason:e.cloudProfileDisabledReason,onSelect:e.onSelectCloudProfile})}
${e.cloudProfileId&&!e.state.cloudProfiles.some(t=>t.id===e.cloudProfileId)?H({value:`cloud:${e.cloudProfileId}`,label:P(`newSession.cloudWorker`,{profile:e.cloudProfileId}),icon:M.server,checked:!0,disabled:!0,title:P(`newSession.catalogUnavailable`),onSelect:()=>void 0},e.submitting):O}
`:O}
${e.state.kind===`cloud`&&e.state.cloudMachines.length>0?k`
<div class="new-session-page__menu-title">${P(`newSession.machine`)}</div>
${Qn({machines:e.state.cloudMachines,selectedId:e.state.selectedMachineId,submitting:e.submitting,onSelect:e.onSelectCloudMachine??(()=>void 0)})}
`:O}
${e.isAdmin?rr({disabled:e.submitting||e.pendingPlacement,onSelect:e.onConnectMachine}):O}
</div>
</wa-popover>
`}function Ka(){return(Ka=e((()=>{A(),N(),Cr(),j(),nr(),xr()})))()}var qa,Ja,Ya,Xa,$;function Za(){return(Za=e((()=>{tt(),A(),we(),Ne(),Ve(),We(),Ae(),j(),mr(),ge(),R(),m(),T(),me(),be(),pn(),zt(),Zt(),G(),Pr(),Y(),qr(),X(),ti(),ri(),Ei(),Ni(),Ui(),$i(),ka(),Na(),Va(),Ri(),Ua(),Ka(),{activateDraft:qa,restoreDraft:Ja,restoreDraftOwner:Ya,retainDraft:Xa}=Di,$=class extends ce{constructor(){super(),this.openedFor=null,this.openedGroupDefaults=``,this.openedAgentId=``,this.messageOwnerKey=``,this.presenceSignature=``,this.imageLightbox=null,this.groupRouteRevalidation=new jr(()=>this.data,()=>this.context?.revalidate(`new-session`)),this.flushDraft=()=>this.submission.draftPersistence.persistNow();let e=Ia(this);this.gateway=new Ti(e,()=>({context:this.context,data:this.data,isConnected:this.isConnected,isAdmin:this.place?.isAdmin()??!1,canStartAsDraft:this.submission?.capabilities.canStartAsDraft(this.context)??!1,visibility:this.submission?.visibility??`normal`,cloudProfileId:this.place?.cloudProfileId??``,pendingPlacement:this.submission?.pendingPlacement??{sessionKey:``,gatewayUrl:``,recoveryScope:``},agentsHydrated:this.place?.agentsHydrated??!1}),{requestUpdate:()=>this.requestUpdate(),updateComplete:()=>this.updateComplete,onInvalidate:(e,t)=>this.invalidateGatewayDiscovery(e,t),onVisibilityRetired:()=>this.submission.setVisibility(`normal`),onCloudProfileCleared:()=>this.place.clearCloudProfile(),onCloudState:e=>this.submission.setError(e),onPendingPlacementReset:()=>this.submission.releasePendingPlacementOwner(),onRecoveryReady:(e,t)=>Ya(this.submission,e,t),onAdoptAgentDefaults:()=>this.place.adoptAgentDefaults({preserveSelectedAgent:!0,preserveSelectedFolder:!0})}),this.browser=new Hi(e,this.gateway,()=>({context:this.context,isAdmin:this.place?.isAdmin()??!1}),{requestUpdate:()=>this.requestUpdate(),onProjectMissing:()=>this.place.clearProjectSelection(),onSelectProject:e=>this.place.selectProjectId(e),onApprovedListing:e=>this.place.recordGatewayApprovedListing(e),querySelector:e=>this.querySelector(e),activeElement:()=>this.ownerDocument.activeElement,body:()=>this.ownerDocument.body}),this.place=new Qi(this.gateway,this.browser,()=>({context:this.context,data:this.data,submitting:this.submission?.submitting??!1,pendingPlacementSessionKey:this.submission?.pendingPlacement.sessionKey??``}),{requestUpdate:()=>this.requestUpdate(),onError:e=>e===null?this.submission.clearError():this.submission.setError(e),onClearError:e=>this.submission.clearErrorIf(e)}),this.submission=new Oa(this.gateway,this.place,()=>({context:this.context,data:this.data,isConnected:this.isConnected}),{requestUpdate:()=>this.requestUpdate(),closeTransientUi:()=>Ra(this)}),this.connectMachine=new Kr(()=>({client:this.gateway.client,connected:this.gateway.connected}),()=>this.requestUpdate()),this.dictation=new Nr({textarea:this.submission.composerTextarea,getClient:()=>this.gateway.client,isConnected:()=>this.gateway.connected,canCommit:()=>!this.submission.submitting&&!this.submission.pendingPlacement.sessionKey,onMessage:e=>this.setMessageFromUser(e),onError:e=>this.submission.setError(e),onSubmit:()=>void this.submission.submit(),requestUpdate:()=>this.requestUpdate()}),this.subscriptions=new _e(this).watch(()=>this.context?.gateway,(e,t)=>e.subscribe(t),e=>this.gateway.synchronize(e)).effect(()=>this.context?.gateway,e=>(this.presenceSignature=Fa(je(e.snapshot.hello?.snapshot)??[]),e.subscribeEvents(t=>{if(this.context?.gateway!==e)return;if(Pa(t.event)){this.refreshPlaceTopology();return}let n=t.event===`presence`?je(t.payload):null;if(!n)return;let r=Fa(n);r!==this.presenceSignature&&(this.presenceSignature=r,this.refreshPlaceTopology())}))).watch(()=>this.context?.agents,(e,t)=>e.subscribe(t)).watch(()=>this.context?.agentIdentity,(e,t)=>e.subscribe(t)).watch(()=>this.context?.sessions,(e,t)=>e.subscribe(t),e=>this.groupRouteRevalidation.synchronize(e)).watch(()=>this.context?.config,(e,t)=>e.subscribe(()=>t()))}refreshPlaceTopology(){this.gateway.refreshCloudProfiles()}handleEvent(e){za(this,e)}connectedCallback(){super.connectedCallback(),document.addEventListener(`keydown`,this,!0),document.addEventListener(`pointerdown`,this,!0),window.addEventListener(`beforeunload`,this.flushDraft)}disconnectedCallback(){document.removeEventListener(`keydown`,this,!0),document.removeEventListener(`pointerdown`,this,!0),window.removeEventListener(`beforeunload`,this.flushDraft),Xa(this.context,this.submission,this.openedFor,this.messageOwnerKey),this.subscriptions.clear(),this.gateway.invalidateDiscovery(!0,this.submission.pendingPlacement.sessionKey?`placement-interrupted`:`gateway-changed`),this.gateway.disconnect(),this.browser.disconnect(),this.submission.disconnect(),this.dictation.dispose(),this.connectMachine.close(),super.disconnectedCallback()}updated(){this.connectMachine.open&&!this.place.isAdmin()&&this.connectMachine.close(),this.gateway.retryPendingCatalogTarget(),this.context?.agentIdentity.ensure(this.place.agents().map(e=>e.id));let e=this.context?.agents.state,t=!!(this.gateway.connected&&this.gateway.client&&e?.connected&&e.client===this.gateway.client&&this.place.agents().length>0);this.place.modelControl.loadCatalogTargets(this.context,t&&this.place.agentId?this.place.selectedAgent()?.id??``:``,this.context?.config.current.cliAgentsEnabled===!0&&!q(this.data));let n=this.routeOwnerKey(),r=this.data?.agentId??``,i=Ar(this.data);if(this.openedFor!==n){let e=this.messageOwnerKey===n?this.submission.message:``;this.openedFor=n,this.openedGroupDefaults=i,this.openedAgentId=r,this.place.setAgentsHydrated(t),this.resetDraft(),this.messageOwnerKey=Ja(this.context,this.submission,n,e);return}this.openedGroupDefaults!==i&&(this.openedGroupDefaults=i,this.place.adoptGroupDefaults()),this.openedAgentId!==r&&(this.openedAgentId=r,this.place.setAgentsHydrated(!1)),!this.place.agentsHydrated&&t&&(this.place.setAgentsHydrated(!0),this.place.adoptAgentDefaults({preserveSelectedAgent:!0,preserveSelectedFolder:!0})),this.place.restorePreferenceSelections(),qa(this.submission,n),this.submission.resumeInterruptedSubmission()}invalidateGatewayDiscovery(e,t){this.place.invalidateGatewayDiscovery(e),this.submission.attachmentDraft.abortReads(),this.submission.invalidate(t),e&&this.submission.pendingPlacement.sessionKey&&this.submission.markPendingPlacementUnavailable(t),e&&this.submission.clearError(),this.connectMachine.close()}resetDraft(){this.place.resetDraft(),this.submission.resetDraft(),this.messageOwnerKey=W(this.data),this.browser.clearPopoverHiding(),La(this),this.browser.close(),this.connectMachine.close(),this.place.adoptAgentDefaults()}routeOwnerKey(){return this.data?W(this.data):kr(window.location.search)}setMessage(e,t=W(this.data)){this.submission.setMessage(e),this.messageOwnerKey=t}setMessageFromUser(e){!this.submission.submitting&&!this.submission.pendingPlacement.sessionKey&&this.setMessage(e,kr(window.location.search))}renderAgentSelect(){return Ha({agents:this.place.agents(),agentId:this.place.agentId,agentIdentity:this.context?.agentIdentity,disabled:this.submission.submitting||!!this.submission.pendingPlacement.sessionKey,onSelect:e=>this.place.selectAgentId(e)})}renderTargetBar(){let e=this.place.agents(),t=this.context?.sessions;return Tr({data:this.data,groupPending:wr(this.data,t),agentSelect:e.length>1?this.renderAgentSelect():O,placeSelect:this.renderPlaceChips(),retrying:this.gateway.catalogRetrying||!!(this.data?.group&&t?.groupsStatus()===`loading`),onRetry:this.gateway.handleCatalogRetry})}renderPlaceChips(){let e=q(this.data)||!this.place.isAdmin()?[]:this.gateway.cloudProfiles,t=this.place.repository.kind===`git`?this.place.repository:null,n=q(this.data)?[]:this.browser.projects,r=q(this.data)?[]:this.browser.resolveProjectRecents({sessions:this.context?.sessions.state.result?.sessions??[],workspace:this.place.workspacePath(),workspaceRoots:this.place.knownWorkspaceRoots(),isAdmin:this.place.isAdmin()}),i=Wa({environments:this.place.canWrite()?this.gateway.environments:[],cloudProfiles:e,cloudProfileId:this.place.cloudProfileId,machineClass:this.place.machineClass,deviceId:this.place.deviceId,autoDevice:this.place.autoDevice,devicePlacement:this.place.devicePlacementRequirement(),deviceDisabledReason:this.place.modelControl.devicePlacementUnsupportedReason()??this.gateway.deviceCatalogDisabledReason}),a=Ii({folder:this.place.folder,workspace:this.place.workspacePath(),projectId:this.browser.projectId,selectedRemoteProject:this.browser.remoteProject,projects:n,recents:r,projectQuery:this.browser.projectQuery}),o=Qr({destination:this.place.remotePlacement?`remote`:`local`,worktree:this.place.worktree,worktreeAvailable:this.place.worktreeAvailable()}),s=this.gateway.gatewayName?P(`newSession.gatewayNamed`,{name:this.gateway.gatewayName}):P(`newSession.gateway`),c=this.submission.submitting,l=!!this.submission.pendingPlacement.sessionKey;return k`${Ga({state:i,gatewayName:this.gateway.gatewayName,cloudProfileId:this.place.cloudProfileId,machineClass:this.place.machineClass,deviceId:this.place.deviceId,autoDevice:this.place.autoDevice,autoPlacementMode:this.place.modelControl.autoPlacementSelectionMode(),worktreeAvailable:this.place.worktreeAvailable(),cloudDisabledReason:this.submission.cloudDisabledReason(),cloudProfileDisabledReason:e=>this.place.modelControl.cloudRuntimeUnsupportedReason(e),submitting:c,pendingPlacement:l,isAdmin:this.place.isAdmin(),...this.browser.popoverCallbacks(`where`),onSelectDevice:e=>this.place.selectDevice(e),onSelectAutoDevice:()=>this.place.selectDevice(``,!0),onSelectCloudProfile:e=>this.place.selectCloudProfile(e),onSelectCloudMachine:t=>this.place.cloudMachines.select(this.place.cloudProfileId,t,e,c||l,()=>this.requestUpdate()),onConnectMachine:()=>this.openConnectMachine()})}${Li({state:a,browseAvailable:this.place.browseAvailable(),isAdmin:this.place.isAdmin(),canWrite:this.place.canWrite(),folder:this.place.folder,workspace:this.place.workspacePath(),projects:n,projectQuery:this.browser.projectQuery,projectSearchAvailable:L(this.context?.gateway.snapshot,`projects.searchRemote`,`operator.read`),projectAddAvailable:L(this.context?.gateway.snapshot,`projects.add`,`operator.write`),remoteProjects:this.browser.projectSearchResult?.projects??[],selectedRemoteProject:this.browser.remoteProject,projectSearchCredentialMissing:this.browser.projectSearchResult?.credential===`missing`,projectSearchLoading:this.browser.projectSearchLoading,projectSearchError:this.browser.projectSearchError,projectId:this.browser.projectId,gatewayLabel:s,remotePlacement:this.place.remotePlacement,branches:t,branchesLoading:this.place.repository.kind===`checking`,baseRef:this.place.baseRef,worktreeName:this.place.worktreeName,submitting:c,pendingPlacement:l,...this.browser.popoverCallbacks(`project`),browserOpen:this.browser.browserOpen,browserListing:this.browser.browserListing,browserLoading:this.browser.browserLoading,browserError:this.browser.browserError,browserPathDraft:this.browser.browserPathDraft,usableBrowserPath:this.browser.usableBrowserPath(),registerProjectPath:this.browser.browserProjectPath,registeringProject:this.browser.browserRegistering,onSelectProject:e=>this.place.selectProjectId(e),onProjectQueryInput:e=>this.browser.changeProjectQuery(e),onSelectRemoteProject:e=>this.place.selectRemoteProject(e),onApplyFolder:e=>this.place.applyFolder(e,this.browser.browserListing?.path===e),onBaseRefInput:e=>this.place.setBaseRef(e),onWorktreeNameInput:e=>this.place.setWorktreeName(e),onBrowse:()=>this.browser.selectGatewayBrowser(this.place.folder.trim()||this.place.workspacePath()),onBrowserPathDraftChange:e=>{this.browser.browserPathDraft=e},onBrowserNavigate:e=>this.browser.loadBrowser(e),onBrowserBack:()=>this.browser.showRoot(),onRegisterProject:e=>void this.browser.registerBrowserProject(e),onClose:()=>this.browser.close()})}${o?ei({state:o,worktree:this.place.worktree,worktreeAvailable:this.place.worktreeAvailable(),repositoryUnavailable:this.place.repository.kind===`unavailable`,branches:t,branchesLoading:this.place.repository.kind===`checking`,baseRef:this.place.baseRef,worktreeName:this.place.worktreeName,submitting:c,pendingPlacement:l,...this.browser.popoverCallbacks(`detail`),onToggleWorktree:()=>this.place.toggleWorktree(),onBaseRefInput:e=>this.place.setBaseRef(e),onWorktreeNameInput:e=>this.place.setWorktreeName(e)}):O}`}openConnectMachine(){this.place.isAdmin()&&(this.browser.close(),this.connectMachine.start())}renderDraftBlock(){let e=this.place.worktree&&!Yr(this.place.worktreeName),t=this.submission.capabilities,n=this.dictation.render(this.routeOwnerKey()),r=this.dictation.active;return k`
<div class="new-session-page__draft" aria-busy=${String(this.submission.submitting)}>
${this.renderTargetBar()}
${e?Br(P(`newSession.worktreeNameInvalid`)):O}
${this.submission.error?Br(this.submission.error):O}
${this.submission.submissionOutcomeUnknown?Br(P(this.submission.submissionOutcomeUnknown===`gateway-changed`?`newSession.createOutcomeUnknown`:`newSession.placementSetupInterrupted`),this.submission.pendingPlacement.sessionKey?{label:P(`common.reset`),onClick:()=>this.submission.clearPendingPlacementRecovery()}:void 0):O}
${ni({agent:this.place.selectedAgent(),agentId:this.place.agentId,attachmentDraft:this.submission.attachmentDraft,canSubmit:!this.submission.submitting&&!r&&this.submission.canSubmit(),submitDisabledReason:this.submission.submitDisabledReason(),blockedSubmitNotice:this.submission.blockedSubmitNotice(),dictationActive:this.dictation.active,dictationPreview:this.dictation.previewDraft(),dictationStatus:this.dictation.renderStatus(),context:this.context,isCatalogTarget:q(this.data),draftOwnerKey:this.routeOwnerKey(),message:this.submission.message,visibility:this.submission.visibility,draftAvailable:t.canStartAsDraft(this.context),...t.composerProps(this.context,this.gateway,this.place.agentId),modelControl:this.place.modelControl,permissionControl:q(this.data)?void 0:Lt({canSelectFull:this.place.isAdmin(),defaultMode:this.place.selectedAgent()?.defaultPermissionMode,disabled:this.submission.submitting||!!this.submission.pendingPlacement.sessionKey,disabledReason:this.submission.submitting?P(`newSession.starting`):void 0,mode:this.submission.permission.value,onSelect:e=>this.submission.permission.set(e??void 0)}),requiresModifier:Pe().chatSendShortcut===`modifier-enter`,requestUpdate:()=>this.requestUpdate(),submitting:this.submission.submitting,textareaController:this.submission.composerTextarea,voiceControl:n,messageLocked:!!this.submission.pendingPlacement.sessionKey,terminalAction:this.submission.showStartInTerminal()?{canStart:!this.submission.submitting&&!r&&this.submission.canSubmit(`terminal`),disabledReason:this.submission.submitBlock(`terminal`)?.reason,onStart:()=>void this.submission.startInTerminal()}:void 0,onInput:e=>this.setMessageFromUser(e),onOpenImage:e=>{this.imageLightbox=e},onVisibilityChange:e=>{!this.submission.submitting&&!this.submission.pendingPlacement.sessionKey&&this.submission.setVisibility(e)},onSubmit:()=>void this.submission.submit()})}
${ja(this.submission.visibility===`incognito`)}
</div>
`}renderWelcome(){let e=this.place.selectedAgent(),t=this.context?.agentIdentity.get(this.place.agentId),n=this.context?.gateway.snapshot;return Ht({assistantName:e?ae(e,t):``,assistantAvatar:e?.identity?.avatar??e?.identity?.emoji??null,assistantAvatarUrl:e?.identity?.avatarUrl??null,hint:P(`newSession.hint`),composer:this.renderDraftBlock(),hideSecondaryContent:this.submission.visibility===`incognito`,fadeSecondaryContent:this.submission.message.trim().length>0,modelSetupRequired:this.submission.requiresModelSetup(),onModelSetup:()=>this.context?.navigate(`model-setup`),sessions:this.context?.sessions.state.result,sessionKey:le({agentId:this.place.agentId||`main`,mainKey:this.context?.agents.state.agentsList?.mainKey}),sessionHost:{assistantAgentId:n?.assistantAgentId??null,agentsList:this.context?.agents.state.agentsList??null,hello:n?.hello??null},onDraftChange:e=>this.setMessageFromUser(e),onSend:()=>void this.submission.submit(),onOpenSession:e=>{if(this.submission.submitting||this.submission.pendingPlacement.sessionKey)return;let t=this.context;t&&(Be({selection:t.agentSelection,gateway:t.gateway,sessionKey:e,agentId:this.place.agentId}),t.navigate(`chat`,de({context:t,face:`chat`,sessionKey:e}).options))}})}render(){return k`
<div
class="new-session-page ${this.submission.visibility===`incognito`?`new-session-page--incognito`:``}"
>
${Aa(this.submission,this.submission.capabilities.canStartAsDraft(this.context))}
<div
class="new-session-page__scroll"
?inert=${this.submission.submitting}
aria-busy=${String(this.submission.submitting)}
@mousedown=${ze}
>
${this.renderWelcome()}
</div>
${Gr({open:this.connectMachine.open&&this.place.isAdmin(),loading:this.connectMachine.loading,error:this.connectMachine.error,setup:this.connectMachine.setup,onRefresh:()=>void this.connectMachine.refresh(),onClose:()=>{this.connectMachine.close(),this.requestUpdate()},onManageDevices:()=>{this.connectMachine.close(),this.context?.navigate(`devices`)}})}
${Cn(this.imageLightbox,()=>{this.imageLightbox=null})}
</div>
`}},s([Ee({attribute:!1})],$.prototype,`data`,void 0),s([$e({context:He,subscribe:!0})],$.prototype,`context`,void 0),s([Oe()],$.prototype,`imageLightbox`,void 0)})))()}var Qa;function $a(){return($a=e((()=>{A(),Za(),customElements.get(`openclaw-new-session-page`)||customElements.define(`openclaw-new-session-page`,$),Qa=e=>k`<openclaw-new-session-page .data=${e}></openclaw-new-session-page>`})))()}$a();export{Qa as render};
//# sourceMappingURL=new-session-page-entry-BxT3_ZKs.js.map