import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{Gt as n,Kt as r,S as i,Wt as a,fl as o,g as s,ml as c,w as l,x as u}from"./control-ui-core-pH6nakZ-.js";import{G as d,J as f,W as p,Z as m,_ as h,at as g,b as _,i as v,n as y,rt as b}from"./lit-runtime-BEtFSUCp.js";import{Ft as x,Ht as S,Lt as C,N as w,Rt as T,qt as E}from"./control-ui-core-Br5DB0Zj.js";import{$i as D,Da as O,Ea as k,Oa as A,Qi as j,Ta as M,Zi as N,ea as P}from"./control-ui-boot-Cdpgu1Gm.js";function F(e){return e.digest?e.running?e.activeRunId&&e.digest.runId===e.activeRunId?e.digest:null:e.digest:null}function I(e,t){return(e.health===`done`||e.health===`failed`)&&(t??0)0||e.pendingQuestion!==null||e.failedQuestion!==null||e.draft.length>0}function V(e){return W[e]}var H,U,W,G;function K(){return(K=e((()=>{p(),m(),h(),y(),T(),D(),O(),M(),x(),w(),S(),l(),j(),c(),a(),H=class{constructor(e=n()){this.displayPreference=e,this.autoExpandedRunIds=new Set,this.autoExpandedRunId=null,this.transientExpanded=!1,this.manualOpen=!1}resetTransientState(){this.transientExpanded=!1,this.autoExpandedRunId=null,this.manualOpen=!1}tryAutoOpen(){return this.displayPreference!==`off`&&(this.transientExpanded=!0,!0)}mode(e){let t=F(e),n=t!==null&&(e.running||I(t,e.lastReadAt))||e.hasCompanionActivity||this.manualOpen||this.transientExpanded;if(this.displayPreference===`off`||!n)return this.autoExpandedRunId=null,`hidden`;let r=e.activeRunId??t?.runId??null;return(t?.health===`stuck`||t?.health===`waiting-on-user`)&&r&&!this.autoExpandedRunIds.has(r)&&(this.autoExpandedRunIds.add(r),this.autoExpandedRunId=r),this.displayPreference===`card`||this.transientExpanded||r!==null&&this.autoExpandedRunId===r?`expanded`:`pill`}expand(){this.displayPreference=`card`,this.transientExpanded=!1,this.autoExpandedRunId=null,r(`card`)}collapse(){this.displayPreference=`pill`,this.transientExpanded=!1,this.autoExpandedRunId=null,this.manualOpen=!1,r(`pill`)}hide(){this.displayPreference=`off`,this.resetTransientState(),r(`off`)}openExplicitly(){this.displayPreference=`pill`,this.transientExpanded=!0,this.autoExpandedRunId=null,this.manualOpen=!0,r(`pill`)}},U=[`changed`,`stopped`,`remaining`],W={busy:`chat.rail.askBusy`,"history-unavailable":`chat.rail.askHistoryUnavailable`,missing:`chat.rail.askMissing`,"model-unavailable":`chat.rail.askModelUnavailable`,"rate-limited":`chat.rail.askRateLimited`,unavailable:`chat.rail.askUnavailable`},G=class extends o{constructor(...e){super(...e),this.sessionKey=``,this.digest=null,this.running=!1,this.activeRunId=null,this.pullRequests=[],this.companion={exchanges:[],loading:!1,pendingQuestion:null,failedQuestion:null,hint:null,retryable:!1,draft:``},this.connected=!1,this.command=null,this.consumedCommandGeneration=0,this.embedded=!1,this.now=Date.now(),this.railState=new H,this.clock=null,this.renderedMode=`hidden`,this.reportedMode=null,this.terminalAgeReference=Date.now()}disconnectedCallback(){this.stopClock(),super.disconnectedCallback()}willUpdate(e){e.has(`sessionKey`)&&(this.terminalAgeReference=Date.now(),this.railState.resetTransientState()),e.has(`digest`)&&this.digest&&(this.digest.health===`done`||this.digest.health===`failed`)&&(this.terminalAgeReference=Date.now()),e.has(`command`)&&this.applyPaneCommand()}applyPaneCommand(){let e=this.command;if(!(!e||e.generation<=this.consumedCommandGeneration)){if(this.onCommandConsumed?.(e.generation),e.intent===`open`){this.railState.tryAutoOpen()&&this.onVisibilityChange?.(!0);return}if(this.renderedMode===`expanded`){this.railState.collapse();return}this.railState.openExplicitly(),this.onVisibilityChange?.(!0)}}updated(){this.running&&this.startedAt!=null&&F(this.input())?this.scheduleClock():this.stopClock(),this.reportedMode!==this.renderedMode&&(this.reportedMode=this.renderedMode,this.onModeChange?.(this.renderedMode))}input(){return{running:this.running,activeRunId:this.activeRunId,digest:this.digest,lastReadAt:this.lastReadAt,hasCompanionActivity:B(this.companion)}}scheduleClock(){this.clock===null&&(this.clock=globalThis.setTimeout(()=>{this.clock=null,this.now=Date.now()},1e3))}stopClock(){this.clock!==null&&(globalThis.clearTimeout(this.clock),this.clock=null)}collapse(){this.railState.collapse(),this.requestUpdate()}expand(){this.railState.expand(),this.requestUpdate()}hide(){this.railState.hide(),this.onVisibilityChange?.(!1),this.requestUpdate()}submit(){let e=this.companion.draft.trim();!e||!this.connected||this.companion.pendingQuestion||!this.onSubmit||this.onSubmit(e)}renderStatus(e){let t=e.health===`done`||e.health===`failed`,n=e.health===`stuck`||e.health===`waiting-on-user`;return f` ${t?f``:f``} ${L(e.health)} `}renderPullRequests(){let e=this.pullRequests.slice(0,2);return e.length===0?d:f`
${e.map(e=>{let t=z(e);return f` #${e.number} ${R(e.state)} ${t?f`${t}`:d} `})}
`}renderDigestDetails(e){return e?f` ${e.assessment?f`

${e.assessment}

`:d} ${this.renderPullRequests()} `:d}renderExchange(e,t,n){return f`
${e}
${v(P(t))}
`}renderStarters(){let e=!this.connected||this.companion.pendingQuestion!==null;return f`
${U.map(t=>{let n=E(`chat.rail.starters.${t}`);return f` `})}
`}renderThread(){let e=`${this.companion.exchanges.length}:${this.companion.pendingQuestion??``}:${this.companion.failedQuestion??``}`;return f`
{!(t instanceof HTMLElement)||t.dataset.railScrollKey===e||(t.dataset.railScrollKey=e,t.scrollTop=t.scrollHeight)})}> ${this.companion.loading&&this.companion.exchanges.length===0?k(`chat`,E(`chat.thread.loading`)):d} ${!this.companion.loading&&this.companion.exchanges.length===0&&!this.companion.pendingQuestion?A({icon:C.bot,heading:E(`chat.sidePanel.companion`),description:E(`chat.rail.empty`)}):d} ${this.companion.exchanges.map(e=>this.renderExchange(e.question,e.answer,e.ts))} ${this.companion.failedQuestion&&this.companion.hint?f`
${this.companion.failedQuestion}
${E(V(this.companion.hint))}
${this.companion.retryable&&this.connected&&this.onSubmit?f` `:d}
`:d} ${this.companion.pendingQuestion?f`
${this.companion.pendingQuestion}
${E(`chat.rail.askPending`)}
`:d}
`}render(){let e=this.input(),t=this.embedded?`expanded`:this.railState.mode(e);if(this.renderedMode=t,t===`hidden`)return d;let n=F(e);if(t===`pill`)return f`
${n?this.renderStatus(n):d}
`;let r=this.running&&this.startedAt!=null?s(Math.max(0,this.now-this.startedAt)):null,i=n&&(n.health===`done`||n.health===`failed`)?E(`chat.rail.finished`,{time:u(Math.max(0,this.terminalAgeReference-n.updatedAt))}):null;return f`
{!this.embedded&&e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.collapse())}} > ${this.embedded?d:f`
${n?this.renderStatus(n):f`${E(`chat.rail.title`)}`} ${r?f`${r}`:i?f`${i}`:d}
${n?f`${n.headline}`:f`${E(`chat.rail.subtitle`)}`}
`} ${n?f`
${this.renderDigestDetails(n)}
`:d} ${this.renderThread()} ${this.companion.exchanges.length===0&&!this.companion.pendingQuestion?this.renderStarters():d}
{e.preventDefault(),this.submit()}} >
`}},t([g({attribute:!1})],G.prototype,`sessionKey`,void 0),t([g({attribute:!1})],G.prototype,`digest`,void 0),t([g({attribute:!1})],G.prototype,`running`,void 0),t([g({attribute:!1})],G.prototype,`activeRunId`,void 0),t([g({attribute:!1})],G.prototype,`startedAt`,void 0),t([g({attribute:!1})],G.prototype,`lastReadAt`,void 0),t([g({attribute:!1})],G.prototype,`pullRequests`,void 0),t([g({attribute:!1})],G.prototype,`companion`,void 0),t([g({attribute:!1})],G.prototype,`connected`,void 0),t([g({attribute:!1})],G.prototype,`command`,void 0),t([g({attribute:!1})],G.prototype,`consumedCommandGeneration`,void 0),t([g({attribute:!1})],G.prototype,`onCommandConsumed`,void 0),t([g({attribute:!1})],G.prototype,`onSubmit`,void 0),t([g({attribute:!1})],G.prototype,`onDraftChange`,void 0),t([g({attribute:!1})],G.prototype,`onModeChange`,void 0),t([g({attribute:!1})],G.prototype,`onVisibilityChange`,void 0),t([g({type:Boolean})],G.prototype,`embedded`,void 0),t([b()],G.prototype,`now`,void 0),customElements.get(`openclaw-chat-session-rail`)||customElements.define(`openclaw-chat-session-rail`,G)})))()}K();export{G as ChatSessionRailElement,H as ChatSessionRailState}; //# sourceMappingURL=chat-session-rail-3W0BOxYg.js.map