cc-viewer 1.5.34 → 1.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -706,7 +706,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),kn=Pe,Jt=Ze),pt===void
|
|
|
706
706
|
`),lineNums:v})}}}else if(c.role==="assistant"&&Array.isArray(c.content)){for(const u of c.content)if(u.type==="tool_use"&&u.name==="Edit"&&u.input){const d=u.input.file_path,h=u.input.old_string,p=u.input.new_string;if(d&&h!=null&&p!=null&&s[d]){const g=s[d];i[u.id]={plainText:g.plainText,lineNums:g.lineNums.slice()};const v=g.plainText.indexOf(h);if(v>=0){const S=g.plainText.substring(0,v).split(`
|
|
707
707
|
`).length-1,_=h.split(`
|
|
708
708
|
`).length,Q=p.split(`
|
|
709
|
-
`).length,x=Q-_;if(g.plainText=g.plainText.substring(0,v)+p+g.plainText.substring(v+h.length),x!==0){const w=g.lineNums[S]||S+1,C=[];for(let T=0;T<Q;T++)C.push(w+T);g.lineNums=[...g.lineNums.slice(0,S),...C,...g.lineNums.slice(S+_).map(T=>T+x)]}}}}}const o={};for(const c of t)if(c.role==="user"&&Array.isArray(c.content)){for(const u of c.content)if(u.type==="tool_result"){const d=e[u.tool_use_id];if(d&&d.name==="AskUserQuestion"){const h=oQ(u);o[u.tool_use_id]=VVe(h)}}}return{toolUseMap:e,toolResultMap:n,readContentMap:r,editSnapshotMap:i,askAnswerMap:o}}function VVe(t){const e={},n=/"([^"]+)"="([^"]*)"/g;let r;for(;(r=n.exec(t))!==null;)e[r[1]]=r[2];return e}class mj extends ne.Component{constructor(n){super(n);Rt(this,"handleStickToBottom",()=>{this.setState({stickyBottom:!0},()=>{const n=this.containerRef.current;n&&(n.scrollTop=n.scrollHeight)})});Rt(this,"handleLoadMore",()=>{this._mobileExtraItems+=AVe;const n=this.containerRef.current,r=n?n.scrollHeight:0,i=n?n.scrollTop:0,s=this.buildAllItems(),o=this._applyMobileSlice(s);this.setState({allItems:o,visibleCount:o.length},()=>{if(n){const a=n.scrollHeight;n.scrollTop=i+(a-r)}})});Rt(this,"handlePromptOptionClick",n=>{const r=this._inputWs;if(!r||r.readyState!==WebSocket.OPEN)return;const i=this.state.ptyPrompt;if(!i)return;const s=i.options,o=s.findIndex(h=>h.number===n);let a=s.findIndex(h=>h.selected);a<0&&(a=0);const l=o-a,c=l>0?"\x1B[B":"\x1B[A",u=Math.abs(l),d=h=>{h<u?(r.send(JSON.stringify({type:"input",data:c})),setTimeout(()=>d(h+1),30)):setTimeout(()=>{r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({type:"input",data:"\r"}))},50)};d(0),this.setState(h=>{const p=h.ptyPromptHistory.slice(),g=p[p.length-1];return g&&g.status==="active"&&(p[p.length-1]={...g,status:"answered",selectedNumber:n}),{ptyPrompt:null,ptyPromptHistory:p}}),this._ptyBuffer="",this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer)});Rt(this,"handleInputSend",()=>{const n=this._inputRef.current;if(!n)return;const r=n.value.trim();r&&this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&(this._inputWs.send(JSON.stringify({type:"input",data:r})),setTimeout(()=>{this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:"\r"}))},50),n.value="",n.style.height="auto",this.setState({inputEmpty:!0,pendingInput:r,inputSuggestion:null},()=>this.scrollToBottom()))});Rt(this,"handleInputKeyDown",n=>{if(n.key==="Tab"&&this.state.inputSuggestion){n.preventDefault();const r=this._inputRef.current;r&&(r.value=this.state.inputSuggestion,r.style.height="auto",r.style.height=Math.min(r.scrollHeight,120)+"px"),this.setState({inputSuggestion:null,inputEmpty:!1});return}n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),this.handleInputSend())});Rt(this,"handleInputChange",n=>{const r=n.target;r.style.height="auto",r.style.height=Math.min(r.scrollHeight,120)+"px";const i=!r.value.trim();this.setState({inputEmpty:i}),this.state.inputSuggestion&&!i&&this.setState({inputSuggestion:null})});Rt(this,"handleSuggestionToTerminal",()=>{const n=this.state.inputSuggestion;!n||!this._inputWs||this._inputWs.readyState!==WebSocket.OPEN||(this._inputWs.send(JSON.stringify({type:"input",data:n})),setTimeout(()=>{this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:"\r"}))},50),this.setState({inputSuggestion:null,pendingInput:n},()=>this.scrollToBottom()))});Rt(this,"handleSplitMouseDown",n=>{n.preventDefault(),this._resizing=!0;const i=!window.location.search.includes("token=");let s=[];if(i){const l=this.innerSplitRef.current;if(l){const u=l.getBoundingClientRect().width,d=7.8,h=[60,80,100,120],p=5;s=h.map(g=>{const v=g*d,$=v+p;if($>u*.75||$<u*.15)return null;const S=u-v-p;return{cols:g,terminalPx:v,linePosition:S}}).filter(g=>g!==null)}}this.setState({isDragging:!0,snapLines:s});const o=l=>{if(!this._resizing)return;const c=this.innerSplitRef.current;if(!c)return;const u=c.getBoundingClientRect(),d=u.width;let h=u.right-l.clientX;h=Math.max(200,Math.min(d*.75,h));let p=null;if(i&&s.length>0){let v=1/0,$=null;for(const S of s){const _=Math.abs(l.clientX-u.left-S.linePosition);_<v&&(v=_,$=S)}$&&v<60&&(p=$)}this.setState({terminalWidth:h,activeSnapLine:p})},a=()=>{if(this._resizing=!1,i&&this.state.activeSnapLine){const l=this.state.activeSnapLine.terminalPx;localStorage.setItem("cc-viewer-terminal-width",l.toString()),this.setState({terminalWidth:l,isDragging:!1,activeSnapLine:null,snapLines:[],needsInitialSnap:!1})}else localStorage.setItem("cc-viewer-terminal-width",this.state.terminalWidth.toString()),this.setState({isDragging:!1,activeSnapLine:null,snapLines:[],needsInitialSnap:!1});document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",a),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",o),document.addEventListener("mouseup",a),document.body.style.cursor="col-resize",document.body.style.userSelect="none"});Rt(this,"handleToggleExpandPath",n=>{this.setState(r=>{const i=new Set(r.fileExplorerExpandedPaths);return i.has(n)?i.delete(n):i.add(n),{fileExplorerExpandedPaths:i}})});this.containerRef=ne.createRef(),this.splitContainerRef=ne.createRef(),this.innerSplitRef=ne.createRef();const r=localStorage.getItem("cc-viewer-terminal-width"),i=r?parseFloat(r):null;this.state={visibleCount:0,loading:!1,allItems:[],highlightTs:null,highlightFading:!1,terminalWidth:i||468,needsInitialSnap:i===null,inputEmpty:!0,pendingInput:null,stickyBottom:!0,ptyPrompt:null,ptyPromptHistory:[],inputSuggestion:null,fileExplorerOpen:!0,currentFile:null,currentGitDiff:null,scrollToLine:null,fileExplorerExpandedPaths:new Set,gitChangesOpen:!1,snapLines:[],activeSnapLine:null,isDragging:!1,fileVersion:0,editorSessionId:null,editorFilePath:null,fileExplorerRefresh:0,gitChangesRefresh:0},this._processedToolIds=new Set,this._fileRefreshTimer=null,this._gitRefreshTimer=null,this._queueTimer=null,this._prevItemsLen=0,this._scrollTargetIdx=null,this._scrollTargetRef=ne.createRef(),this._scrollFadeTimer=null,this._resizing=!1,this._inputWs=null,this._inputRef=ne.createRef(),this._ptyBuffer="",this._ptyDebounceTimer=null,this._mobileExtraItems=0,this._mobileSliceOffset=0,this._totalItemCount=0}_checkToolFileChanges(){var s,o;const n=this.props.mainAgentSessions;if(!n||n.length===0)return;let r=!1,i=!1;for(const a of n){const l=[];if((o=(s=a.response)==null?void 0:s.body)!=null&&o.content&&l.push(a.response.body.content),Array.isArray(a.messages))for(const c of a.messages)c.role==="assistant"&&Array.isArray(c.content)&&l.push(c.content);for(const c of l)for(const u of c){if(u.type!=="tool_use"||!u.id||this._processedToolIds.has(u.id))continue;this._processedToolIds.add(u.id);const d=u.name;let h=u.input;if(typeof h=="string")try{h=JSON.parse(h.replace(/^\[object Object\]/,""))}catch{h={}}d==="Write"?(r=!0,i=!0):d==="Edit"||d==="NotebookEdit"?i=!0:d==="Bash"&&h&&h.command&&LVe(h.command)&&(r=!0,i=!0)}}r&&this.state.fileExplorerOpen&&(clearTimeout(this._fileRefreshTimer),this._fileRefreshTimer=setTimeout(()=>{this.setState(a=>({fileExplorerRefresh:a.fileExplorerRefresh+1}))},500)),i&&this.state.gitChangesOpen&&(clearTimeout(this._gitRefreshTimer),this._gitRefreshTimer=setTimeout(()=>{this.setState(a=>({gitChangesRefresh:a.gitChangesRefresh+1}))},500))}componentDidMount(){this.startRender(),this.props.cliMode&&this.connectInputWs(),this._bindStickyScroll(),this.state.needsInitialSnap&&this.props.cliMode&&this.props.terminalVisible&&this._snapToInitialPosition()}componentDidUpdate(n){if(n.mainAgentSessions!==this.props.mainAgentSessions)Cr&&(this._mobileExtraItems=0),this.startRender(),this.state.pendingInput&&this.setState({pendingInput:null}),this._updateSuggestion(),this._checkToolFileChanges();else if(n.collapseToolResults!==this.props.collapseToolResults||n.expandThinking!==this.props.expandThinking){const r=this.buildAllItems(),i=this._applyMobileSlice(r);this.setState({allItems:i,visibleCount:i.length})}if(!n.scrollToTimestamp&&this.props.scrollToTimestamp)if(Cr&&this.props.scrollToTimestamp){const r=this.buildAllItems(),i=this._scrollTargetIdx;if(i!=null){const o=Dx+this._mobileExtraItems,a=r.length>o?r.length-o:0;i<a&&(this._mobileExtraItems=r.length-i-Dx,this._mobileExtraItems<0&&(this._mobileExtraItems=0))}const s=this._applyMobileSlice(r);this.setState({allItems:s,visibleCount:s.length},()=>this.scrollToBottom())}else{const r=this.buildAllItems(),i=this._applyMobileSlice(r);this.setState({allItems:i,visibleCount:i.length},()=>this.scrollToBottom())}Cr&&this.props.mobileChatVisible&&!n.mobileChatVisible&&requestAnimationFrame(()=>{const r=this.containerRef.current;r&&(r.scrollTop=r.scrollHeight)}),!n.cliMode&&this.props.cliMode&&this.connectInputWs(),this._rebindStickyEl()}componentWillUnmount(){this._queueTimer&&clearTimeout(this._queueTimer),this._fadeClearTimer&&clearTimeout(this._fadeClearTimer),this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this._fileRefreshTimer&&clearTimeout(this._fileRefreshTimer),this._gitRefreshTimer&&clearTimeout(this._gitRefreshTimer),this._unbindScrollFade(),this._unbindStickyScroll(),this._inputWs&&(this._inputWs.close(),this._inputWs=null)}startRender(){this._queueTimer&&clearTimeout(this._queueTimer);const n=this.buildAllItems(),r=this._applyMobileSlice(n),i=this._prevItemsLen;this._prevItemsLen=r.length;const s=r.length-i;if(s<=0||i>0&&s<=3){this.setState({allItems:r,visibleCount:r.length,loading:!1},()=>this.scrollToBottom());return}if(r.length>MVe)this.setState({allItems:r,visibleCount:0,loading:!0}),this._queueTimer=setTimeout(()=>{this.setState({visibleCount:r.length,loading:!1},()=>this.scrollToBottom())},300);else{const o=Math.max(0,i);this.setState({allItems:r,visibleCount:o,loading:!1}),this.queueNext(o,r.length)}}queueNext(n,r){n>=r||(this._queueTimer=setTimeout(()=>{this.setState({visibleCount:n+1},()=>{this.scrollToBottom(),this.queueNext(n+1,r)})},WVe()))}_isNearBottom(){const n=this.containerRef.current;return n?n.scrollHeight-n.scrollTop-n.clientHeight<=30:!0}scrollToBottom(){if(this._scrollTargetRef.current){const n=this._scrollTargetRef.current,r=this.containerRef.current;r&&n.offsetHeight>r.clientHeight?n.scrollIntoView({block:"start",behavior:"instant"}):n.scrollIntoView({block:"center",behavior:"instant"});const i=this.props.scrollToTimestamp;this._scrollTargetRef=ne.createRef(),i&&(this.setState({highlightTs:i,highlightFading:!1}),this._bindScrollFade()),this.props.onScrollTsDone&&this.props.onScrollTsDone();return}if(this.state.stickyBottom){const n=this.containerRef.current;n&&(n.scrollTop=n.scrollHeight)}}_bindStickyScroll(){this._stickyScrollRafId=null,this._onStickyScroll=()=>{this._stickyScrollLock||this._stickyScrollRafId||(this._stickyScrollRafId=requestAnimationFrame(()=>{this._stickyScrollRafId=null;const n=this.containerRef.current;if(!n)return;const r=n.scrollHeight-n.scrollTop-n.clientHeight;this.state.stickyBottom&&r>30?this.setState({stickyBottom:!1}):!this.state.stickyBottom&&r<=5&&this.setState({stickyBottom:!0})}))},this._rebindStickyEl()}_rebindStickyEl(){const n=this.containerRef.current;n!==this._stickyBoundEl&&(this._stickyBoundEl&&this._stickyBoundEl.removeEventListener("scroll",this._onStickyScroll),this._stickyBoundEl=n,n&&n.addEventListener("scroll",this._onStickyScroll,{passive:!0}))}_unbindStickyScroll(){this._stickyBoundEl&&this._onStickyScroll&&(this._stickyBoundEl.removeEventListener("scroll",this._onStickyScroll),this._stickyBoundEl=null),this._stickyScrollRafId&&(cancelAnimationFrame(this._stickyScrollRafId),this._stickyScrollRafId=null)}_bindScrollFade(){this._unbindScrollFade();const n=this.containerRef.current;n&&(this._scrollFadeIgnoreFirst=!0,this._onScrollFade=()=>{if(this._scrollFadeIgnoreFirst){this._scrollFadeIgnoreFirst=!1;return}this.setState({highlightFading:!0}),this._fadeClearTimer=setTimeout(()=>{this.setState({highlightTs:null,highlightFading:!1})},2e3),this._unbindScrollFade()},n.addEventListener("scroll",this._onScrollFade,{passive:!0}))}_unbindScrollFade(){this._onScrollFade&&this.containerRef.current&&(this.containerRef.current.removeEventListener("scroll",this._onScrollFade),this._onScrollFade=null)}renderSessionMessages(n,r,i,s){const{userProfile:o,collapseToolResults:a,expandThinking:l,onViewRequest:c}=this.props,{toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p}=pj(n),g=[];for(let v=0;v<n.length;v++){const $=n[v],S=$.content,_=$._timestamp||null,Q=_?s[_]:void 0,x=Q!=null&&c?{requestIndex:Q,onViewRequest:c}:{};if($.role==="user"){if(Array.isArray(S)){const w=S.find(T=>T.type==="text"&&/^\[SUGGESTION MODE:/i.test((T.text||"").trim())),C=S.filter(T=>T.type==="tool_result");if(!(w&&C.length>0)){const{commands:T,textBlocks:z,skillBlocks:X}=JT(S);for(let A=0;A<T.length;A++)g.push(y.jsx(il,{role:"user",text:T[A],timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-cmd-${v}-${A}`));for(const A of X){const I=A.text.match(/^#\s+(.+)$/m),E=I?I[1]:"Skill";g.push(y.jsx(il,{role:"skill-loaded",text:A.text,skillName:E,timestamp:_,...x},`${r}-skill-${v}`))}for(let A=0;A<z.length;A++){const I=/^Implement the following plan:/i.test((z[A].text||"").trim());g.push(y.jsx(il,{role:I?"plan-prompt":"user",text:z[A].text,timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-user-${v}-${A}`))}}}else if(typeof S=="string"&&!eb(S)){const w=/^Implement the following plan:/i.test(S.trim());g.push(y.jsx(il,{role:w?"plan-prompt":"user",text:S,timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-user-${v}`))}}else $.role==="assistant"&&(Array.isArray(S)?g.push(y.jsx(il,{role:"assistant",content:S,toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p,timestamp:_,modelInfo:i,collapseToolResults:a,expandThinking:l,...x},`${r}-asst-${v}`)):typeof S=="string"&&g.push(y.jsx(il,{role:"assistant",content:[{type:"text",text:S}],toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p,timestamp:_,modelInfo:i,collapseToolResults:a,expandThinking:l,...x},`${r}-asst-${v}`)))}return g}buildAllItems(){var v,$,S,_;const{mainAgentSessions:n,requests:r,collapseToolResults:i,expandThinking:s,onViewRequest:o}=this.props;if(!n||n.length===0)return[];const a={};if(r)for(let Q=0;Q<r.length;Q++)Ii(r[Q])&&r[Q].timestamp&&(a[r[Q].timestamp]=Q);let l=null;if(r){for(let Q=r.length-1;Q>=0;Q--)if(Ii(r[Q])&&((v=r[Q].body)!=null&&v.model)){l=r[Q].body.model;break}}const c=a0e(l),u=[],d={},h=[];if(r)for(let Q=0;Q<r.length;Q++){const x=r[Q];if(!x.timestamp)continue;const w=Id(x,r[Q+1]);if(w.type==="SubAgent"){const C=(S=($=x.response)==null?void 0:$.body)==null?void 0:S.content;if(Array.isArray(C)&&C.length>0){const T=pj(((_=x.body)==null?void 0:_.messages)||[]).toolResultMap;h.push({timestamp:x.timestamp,content:C,toolResultMap:T,label:gP(w.type,w.subType),requestIndex:Q})}}}let p=0;n.forEach((Q,x)=>{var C,T,z,X;x>0&&u.push(y.jsx(YX,{style:{borderColor:"#333",margin:"16px 0"},children:y.jsx(fj,{className:jn.sessionDividerText,children:"Session"})},`session-div-${x}`));const w=this.renderSessionMessages(Q.messages,`s${x}`,c,a);for(const A of w){const I=A.props.timestamp;for(;p<h.length&&I&&h[p].timestamp<=I;){const E=h[p];E.timestamp&&(d[E.timestamp]=u.length),u.push(y.jsx(il,{role:"sub-agent-chat",content:E.content,toolResultMap:E.toolResultMap,label:E.label,timestamp:E.timestamp,collapseToolResults:i,expandThinking:s,requestIndex:E.requestIndex,onViewRequest:o},`sub-chat-${p}`)),p++}I&&(d[I]=u.length),u.push(A)}for(;p<h.length;){const A=h[p],I=x<n.length-1&&((T=(C=n[x+1].messages)==null?void 0:C[0])==null?void 0:T._timestamp);if(I&&A.timestamp>I)break;A.timestamp&&(d[A.timestamp]=u.length),u.push(y.jsx(il,{role:"sub-agent-chat",content:A.content,toolResultMap:A.toolResultMap,label:A.label,timestamp:A.timestamp,collapseToolResults:i,expandThinking:s,requestIndex:A.requestIndex,onViewRequest:o},`sub-chat-${p}`)),p++}if(x===n.length-1&&((X=(z=Q.response)==null?void 0:z.body)!=null&&X.content)){const A=Q.response.body.content;Array.isArray(A)&&(u.push(y.jsx(ne.Fragment,{children:y.jsx(YX,{style:{borderColor:"#2a2a2a",margin:"8px 0"},children:y.jsx(fj,{type:"secondary",className:jn.lastResponseLabel,children:ae("ui.lastResponse")})})},"resp-divider")),Q.entryTimestamp&&(d[Q.entryTimestamp]=u.length),u.push(y.jsx(il,{role:"assistant",content:A,timestamp:Q.entryTimestamp,modelInfo:c,collapseToolResults:i,expandThinking:s,toolResultMap:{}},"resp-asst")))}});const{scrollToTimestamp:g}=this.props;return this._scrollTargetIdx=g&&d[g]!=null?d[g]:null,this._tsItemMap=d,u}_applyMobileSlice(n){if(!Cr)return this._mobileSliceOffset=0,this._totalItemCount=n.length,n;this._totalItemCount=n.length;const r=Dx+this._mobileExtraItems;if(n.length<=r)return this._mobileSliceOffset=0,n;const i=n.length-r;if(this._mobileSliceOffset=i,this._scrollTargetIdx!=null&&(this._scrollTargetIdx-=i,this._scrollTargetIdx<0&&(this._scrollTargetIdx=null)),this._tsItemMap){const s={};for(const[o,a]of Object.entries(this._tsItemMap)){const l=a-i;l>=0&&(s[o]=l)}this._tsItemMap=s}return n.slice(i)}_extractSuggestion(){var l;const{mainAgentSessions:n}=this.props;if(!(n!=null&&n.length))return null;const r=n[n.length-1],i=r==null?void 0:r.response;if(!i)return null;const s=i.body;if(!s)return null;const o=s.stop_reason;if(o!=="end_turn"&&o!=="max_tokens")return null;const a=s.content;if(!Array.isArray(a))return null;for(let c=a.length-1;c>=0;c--)if(a[c].type==="text"&&((l=a[c].text)!=null&&l.trim()))return a[c].text.trim();return null}_updateSuggestion(){const n=this._extractSuggestion();this.setState({inputSuggestion:n||null})}connectInputWs(){const r=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal`;this._inputWs=new WebSocket(r),this._inputWs.onmessage=i=>{try{const s=JSON.parse(i.data);s.type==="data"?this._appendPtyData(s.data):s.type==="exit"&&this._clearPtyPrompt()}catch{}},this._inputWs.onclose=()=>{setTimeout(()=>{this.splitContainerRef.current&&this.props.cliMode&&this.connectInputWs()},2e3)}}_stripAnsi(n){return n.replace(/\x1b\[[0-9;]*[A-Za-z]/g,"").replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"").replace(/\x1b[^[\]](.|$)/g,"").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g,"")}_appendPtyData(n){const r=this._stripAnsi(n);this._ptyBuffer+=r,this._ptyBuffer.length>4096&&(this._ptyBuffer=this._ptyBuffer.slice(-4096)),this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this._ptyDebounceTimer=setTimeout(()=>this._detectPrompt(),200)}_detectPrompt(){const r=this._ptyBuffer.match(/([^\n]*\?)\s*\n((?:\s*[❯>]?\s*\d+\.\s+[^\n]+\n?){2,})$/);if(r){const i=r[1].trim(),o=r[2].match(/\s*([❯>])?\s*(\d+)\.\s+([^\n]+)/g);if(o){const a=o.map(u=>{const d=u.match(/\s*([❯>])?\s*(\d+)\.\s+(.+)/);return{number:parseInt(d[2],10),text:d[3].trim(),selected:!!d[1]}}),l=this.state.ptyPrompt,c={question:i,options:a};l&&l.question===i?this.setState({ptyPrompt:c}):(this.setState(u=>{const d=u.ptyPromptHistory.slice();if(u.ptyPrompt){const h=d[d.length-1];h&&h.status==="active"&&(d[d.length-1]={...h,status:"dismissed"})}return d.push({...c,status:"active",selectedNumber:null,timestamp:new Date().toISOString()}),{ptyPrompt:c,ptyPromptHistory:d}}),this.scrollToBottom());return}}this.state.ptyPrompt&&this.setState(i=>{const s=i.ptyPromptHistory.slice(),o=s[s.length-1];return o&&o.status==="active"&&(s[s.length-1]={...o,status:"dismissed"}),{ptyPrompt:null,ptyPromptHistory:s}})}_clearPtyPrompt(){this._ptyBuffer="",this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this.state.ptyPrompt&&this.setState({ptyPrompt:null})}_snapToInitialPosition(){this.setState({terminalWidth:468,needsInitialSnap:!1}),localStorage.setItem("cc-viewer-terminal-width","468")}render(){const{mainAgentSessions:n,cliMode:r,terminalVisible:i}=this.props,{allItems:s,visibleCount:o,loading:a,terminalWidth:l}=this.state,c=!n||n.length===0;if(c&&!r)return y.jsx("div",{className:jn.centerEmpty,children:y.jsx(vs,{description:ae("ui.noChat")})});if(a&&!r)return y.jsx("div",{className:jn.centerEmpty,children:y.jsx(qa,{size:"large"})});const u=this._scrollTargetIdx,{highlightTs:d,highlightFading:h}=this.state,p=d&&this._tsItemMap&&this._tsItemMap[d]!=null?this._tsItemMap[d]:null,g=s.slice(0,o),{pendingInput:v,stickyBottom:$,ptyPromptHistory:S}=this.state,_=r&&v?y.jsx(il,{role:"user",text:v,timestamp:new Date().toISOString(),userProfile:this.props.userProfile},"pending-input"):null,Q=$?null:y.jsxs("button",{className:jn.stickyBottomBtn,onClick:this.handleStickToBottom,children:[y.jsx("span",{children:ae("ui.stickyBottom")}),y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:y.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),x=r&&S.length>0?S.map((T,z)=>{const X=T.status==="active",A=T.status==="answered";return y.jsxs("div",{className:`${jn.ptyPromptBubble}${X?"":" "+jn.ptyPromptResolved}`,children:[y.jsx("div",{className:jn.ptyPromptQuestion,children:T.question}),y.jsx("div",{className:jn.ptyPromptOptions,children:T.options.map(I=>{const E=A&&T.selectedNumber===I.number;let k=jn.ptyPromptOption;return X&&I.selected&&(k=jn.ptyPromptOptionPrimary),E&&(k=jn.ptyPromptOptionChosen),!X&&!E&&(k=jn.ptyPromptOptionDimmed),y.jsxs("button",{className:k,disabled:!X,onClick:X?()=>this.handlePromptOptionClick(I.number):void 0,children:[I.number,". ",I.text]},I.number)})})]},`pty-prompt-${z}`)}):null,w=Cr&&this._mobileSliceOffset>0?y.jsx("div",{className:jn.loadMoreWrap,children:y.jsx("button",{className:jn.loadMoreBtn,onClick:this.handleLoadMore,children:ae("ui.loadMoreHistory",{count:this._mobileSliceOffset})})}):null,C=c||a?y.jsxs("div",{className:jn.messageListWrap,children:[y.jsxs("div",{ref:this.containerRef,className:jn.container,children:[!r||a?y.jsx("div",{className:jn.centerEmpty,children:a?y.jsx(qa,{size:"large"}):y.jsx(vs,{description:ae("ui.noChat")})}):null,_,x]}),Q]}):y.jsxs("div",{className:jn.messageListWrap,children:[y.jsxs("div",{ref:this.containerRef,className:jn.container,children:[w,g.map((T,z)=>{const X=z===u,A=z===p;let I=T;return A&&(I=ne.cloneElement(I,{highlight:h?"fading":"active"})),X?y.jsx("div",{ref:this._scrollTargetRef,children:I},T.key+"-anchor"):I}),_,x]}),Q]});return r?y.jsxs("div",{ref:this.splitContainerRef,className:jn.splitContainer,children:[y.jsxs("div",{className:jn.navSidebar,children:[y.jsx("button",{className:this.state.fileExplorerOpen?jn.navBtnActive:jn.navBtn,onClick:()=>this.setState(T=>({fileExplorerOpen:!T.fileExplorerOpen,gitChangesOpen:!1})),title:ae("ui.fileExplorer"),children:y.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:y.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 2h9a2 2 0 0 1 2 2z"})})}),y.jsx("button",{className:this.state.gitChangesOpen?jn.navBtnActive:jn.navBtn,onClick:()=>this.setState(T=>({gitChangesOpen:!T.gitChangesOpen,fileExplorerOpen:!1})),title:ae("ui.gitChanges"),children:y.jsx("svg",{width:"24",height:"24",viewBox:"0 0 1024 1024",fill:"currentColor",children:y.jsx("path",{d:"M759.53332137 326.35000897c0-48.26899766-39.4506231-87.33284994-87.87432908-86.6366625-46.95397689 0.69618746-85.08957923 39.14120645-85.39899588 86.09518335-0.23206249 40.68828971 27.53808201 74.87882971 65.13220519 84.47074592 10.82958281 2.78474987 18.41029078 12.37666607 18.64235327 23.51566553 0.38677082 21.11768647-3.40358317 44.40128953-17.24997834 63.81718442-22.20064476 31.17372767-62.42480948 42.46743545-97.93037026 52.44612248-22.43270724 6.26568719-38.75443563 7.89012462-53.14230994 9.28249954-20.42149901 2.01120825-39.76003975 3.94506233-63.89453858 17.79145747-5.10537475 2.93945818-10.13339535 6.18833303-14.85199928 9.74662453-4.09977063 3.09416652-9.90133285 0.15470833-9.90133286-4.95066641V302.60228095c0-9.43720788 5.26008307-18.17822829 13.69168683-22.3553531 28.69839444-14.23316598 48.42370599-43.93716454 48.19164353-78.20505872-0.38677082-48.57841433-41.15241468-87.71962076-89.730829-86.01782918C338.80402918 117.57112321 301.59667683 155.70672553 301.59667683 202.58334827c0 34.03583169 19.64795738 63.50776777 48.1916435 77.66357958 8.43160375 4.17712479 13.69168685 12.76343689 13.69168684 22.12329062v419.02750058c0 9.43720788-5.26008307 18.17822829-13.69168684 22.3553531-28.69839444 14.23316598-48.42370599 43.93716454-48.1916435 78.20505872 0.30941665 48.57841433 41.07506052 87.6422666 89.65347484 86.01782918C437.74000359 906.42887679 474.87000179 868.2159203 474.87000179 821.41665173c0-34.03583169-19.64795738-63.50776777-48.1916435-77.66357958-8.43160375-4.17712479-13.69168685-12.76343689-13.69168684-22.12329062v-14.85199926c0-32.48874844 15.39347842-63.27570528 42.00331048-81.91805854 2.39797906-1.70179159 4.95066642-3.32622901 7.50335379-4.79595812 14.92935344-8.58631209 25.91364457-9.66927037 44.09187287-11.4484161 15.62554091-1.54708326 35.04143581-3.48093734 61.65126786-10.90693699 39.06385228-10.98429114 92.51557887-25.91364457 124.84961898-71.39789238 18.56499911-26.06835292 27.38337367-58.01562219 26.37776956-95.14562041-0.15470833-5.33743724-0.54147915-10.67487447-1.08295828-16.16702004-0.85089578-8.27689543 2.70739569-16.24437421 9.12779121-21.50445729 19.57060322-15.78024923 32.02462345-39.99210223 32.02462345-67.14341343zM351.1033411 202.58334827c0-20.49885317 16.63114503-37.12999821 37.1299982-37.1299982s37.12999821 16.63114503 37.12999821 37.1299982-16.63114503 37.12999821-37.12999821 37.1299982-37.12999821-16.63114503-37.1299982-37.1299982z m74.25999641 618.83330346c0 20.49885317-16.63114503 37.12999821-37.12999821 37.1299982s-37.12999821-16.63114503-37.1299982-37.1299982 16.63114503-37.12999821 37.1299982-37.1299982 37.12999821 16.63114503 37.12999821 37.1299982z m247.53332139-457.93664456c-20.49885317 0-37.12999821-16.63114503-37.1299982-37.1299982s16.63114503-37.12999821 37.1299982-37.12999821 37.12999821 16.63114503 37.1299982 37.12999821-16.63114503 37.12999821-37.1299982 37.1299982z"})})})]}),y.jsxs("div",{style:{flex:1,display:"flex",minWidth:0,position:"relative"},ref:this.innerSplitRef,children:[this.state.isDragging&&this.state.activeSnapLine&&(()=>{const T=this.innerSplitRef.current;if(!T)return null;const A=T.getBoundingClientRect().width-this.state.terminalWidth-5,I=this.state.activeSnapLine.linePosition,E=Math.min(A,I),k=Math.abs(I-A);return y.jsx("div",{className:jn.snapPreview,style:{left:`${E}px`,width:`${k}px`}})})(),this.state.isDragging&&(()=>{const T=this.innerSplitRef.current;if(!T)return null;const A=T.getBoundingClientRect().width-this.state.terminalWidth-5,I=[...this.state.snapLines].map(R=>({...R,dist:Math.abs(R.linePosition-A)})).sort((R,M)=>R.dist-M.dist);if(I.length===0)return null;const E=I[0],k=this.state.activeSnapLine&&this.state.activeSnapLine.cols===E.cols;return y.jsx("div",{className:k?jn.snapLineActive:jn.snapLine,style:{left:`${E.linePosition}px`}},E.cols)})(),this.state.fileExplorerOpen&&y.jsx(G2e,{refreshTrigger:this.state.fileExplorerRefresh,onClose:()=>this.setState({fileExplorerOpen:!1}),onFileClick:T=>this.setState({currentFile:T,currentGitDiff:null,scrollToLine:null}),expandedPaths:this.state.fileExplorerExpandedPaths,onToggleExpand:this.handleToggleExpandPath,currentFile:this.state.currentFile}),this.state.gitChangesOpen&&y.jsx(mAe,{refreshTrigger:this.state.gitChangesRefresh,onClose:()=>this.setState({gitChangesOpen:!1}),onFileClick:T=>this.setState({currentGitDiff:T,currentFile:null})}),y.jsx("div",{className:jn.chatSection,style:{flex:1,minWidth:0,display:"flex"},children:y.jsxs("div",{style:{flex:1,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden",position:"relative"},children:[this.state.currentGitDiff&&y.jsx("div",{style:{position:"absolute",inset:0,zIndex:1,display:"flex",flexDirection:"column"},children:y.jsx(JWe,{filePath:this.state.currentGitDiff,onClose:()=>this.setState({currentGitDiff:null}),onOpenFile:(T,z)=>this.setState({currentGitDiff:null,currentFile:T,scrollToLine:z||1,fileExplorerOpen:!0,gitChangesOpen:!1})})}),this.state.currentFile&&y.jsx("div",{style:{position:"absolute",inset:0,zIndex:1,display:"flex",flexDirection:"column"},children:NVe(this.state.currentFile)?y.jsx(DLe,{filePath:this.state.currentFile,editorSession:!!this.state.editorSessionId,onClose:()=>{this.state.editorSessionId&&fetch("/api/editor-done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:this.state.editorSessionId})}).catch(()=>{}),this.setState({currentFile:null,fileVersion:0,editorSessionId:null,editorFilePath:null})}},this.state.fileVersion):y.jsx(PLe,{filePath:this.state.currentFile,scrollToLine:this.state.scrollToLine,editorSession:!!this.state.editorSessionId,onClose:()=>{this.state.editorSessionId&&fetch("/api/editor-done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:this.state.editorSessionId})}).catch(()=>{}),this.setState({currentFile:null,fileVersion:0,editorSessionId:null,editorFilePath:null})}},this.state.fileVersion)}),C,!i&&y.jsxs("div",{className:jn.chatInputBar,children:[y.jsxs("div",{className:jn.chatInputWrapper,children:[y.jsxs("div",{className:jn.chatTextareaWrap,children:[y.jsx("textarea",{ref:this._inputRef,className:jn.chatTextarea,placeholder:this.state.inputSuggestion?"":ae("ui.chatInput.placeholder"),rows:1,onKeyDown:this.handleInputKeyDown,onInput:this.handleInputChange}),this.state.inputSuggestion&&this.state.inputEmpty&&y.jsx("div",{className:jn.ghostText,children:this.state.inputSuggestion})]}),y.jsx("div",{className:jn.chatInputHint,children:this.state.inputSuggestion&&this.state.inputEmpty?ae("ui.chatInput.hintTab"):ae("ui.chatInput.hintEnter")})]}),!Cr&&y.jsx("button",{className:jn.chatSendBtn,onClick:()=>{const T=document.createElement("input");T.type="file",T.onchange=async z=>{var A;const X=(A=z.target.files)==null?void 0:A[0];if(X)try{const E=`"${await wY(X)}"`,k=this._inputRef.current;k&&(k.value=(k.value?k.value+" ":"")+E,k.dispatchEvent(new Event("input",{bubbles:!0})),this.setState({inputEmpty:!1}))}catch(I){console.error("[CC Viewer] Upload failed:",I)}},T.click()},title:ae("ui.terminal.upload"),children:y.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),y.jsx("polyline",{points:"17 8 12 3 7 8"}),y.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),y.jsx("button",{className:jn.chatSendBtn,onClick:this.handleInputSend,disabled:this.state.inputEmpty,title:ae("ui.chatInput.send"),children:y.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),y.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),i&&this.state.inputSuggestion&&y.jsxs("div",{className:jn.suggestionChip,onClick:this.handleSuggestionToTerminal,children:[y.jsx("span",{className:jn.suggestionChipText,children:this.state.inputSuggestion}),y.jsx("span",{className:jn.suggestionChipAction,children:"↵"})]})]})}),i&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:jn.vResizer,onMouseDown:this.handleSplitMouseDown}),y.jsx("div",{style:{width:l,flexShrink:0,minWidth:200,display:"flex",flexDirection:"column"},children:y.jsx(PY,{onEditorOpen:(T,z)=>{this.setState({editorSessionId:T,editorFilePath:z,currentFile:z,currentGitDiff:null,scrollToLine:null,fileVersion:(this.state.fileVersion||0)+1})},onFilePath:T=>{const z=`"${T}"`;this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:z}))}})})]})]})]}):C}}const YVe="_resizer_yamj2_1",BVe={resizer:YVe};class qVe extends ne.Component{constructor(e){super(e),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this)}handleMouseDown(e){e.preventDefault(),document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(e){this.props.onResize&&this.props.onResize(e.clientX)}handleMouseUp(){document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}componentWillUnmount(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}render(){return y.jsx("div",{onMouseDown:this.handleMouseDown,className:BVe.resizer})}}const UVe="_container_1um1r_1",DVe="_fileListSection_1um1r_10",ZVe="_header_1um1r_19",GVe="_headerTitle_1um1r_28",FVe="_fileCount_1um1r_36",HVe="_changesContainer_1um1r_44",KVe="_changeItem_1um1r_51",JVe="_changeItemActive_1um1r_68",eYe="_dirItem_1um1r_77",tYe="_dirArrow_1um1r_88",nYe="_dirName_1um1r_97",rYe="_status_1um1r_102",iYe="_icon_1um1r_111",sYe="_fileName_1um1r_120",oYe="_diffSection_1um1r_127",aYe="_diffHeader_1um1r_135",lYe="_diffFilePath_1um1r_145",cYe="_diffBadge_1um1r_155",uYe="_diffContent_1um1r_167",dYe="_diffPlaceholder_1um1r_173",OYe="_statusText_1um1r_184",hYe="_errorText_1um1r_191",fYe="_emptyText_1um1r_198",pYe="_warningText_1um1r_205",Pr={container:UVe,fileListSection:DVe,header:ZVe,headerTitle:GVe,fileCount:FVe,changesContainer:HVe,changeItem:KVe,changeItemActive:JVe,dirItem:eYe,dirArrow:tYe,dirName:nYe,status:rYe,icon:iYe,fileName:sYe,diffSection:oYe,diffHeader:aYe,diffFilePath:lYe,diffBadge:cYe,diffContent:uYe,diffPlaceholder:dYe,statusText:OYe,errorText:hYe,emptyText:fYe,warningText:pYe},mYe={M:"#e2c08d",A:"#73c991",D:"#f14c4c",R:"#73c991",C:"#73c991",U:"#e2c08d","?":"#73c991","??":"#73c991"},gYe={"??":"U"},vYe={js:"#e8d44d",jsx:"#61dafb",ts:"#3178c6",tsx:"#3178c6",json:"#999",md:"#519aba",css:"#a86fd9",scss:"#cd6799",html:"#e34c26",py:"#3572a5",go:"#00add8",rs:"#dea584"};function $Ye(t){const e=t.includes(".")?t.split(".").pop().toLowerCase():"",n=vYe[e]||"#888";return y.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"1.5",children:[y.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),y.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function SYe(){return y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"#c09553",stroke:"none",children:y.jsx("path",{d:"M2 6c0-1.1.9-2 2-2h5l2 2h9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6z"})})}function bYe(t){const e={dirs:{},files:[]};for(const n of t){const r=n.file.split("/");let i=e;for(let s=0;s<r.length-1;s++)i.dirs[r[s]]||(i.dirs[r[s]]={dirs:{},files:[]}),i=i.dirs[r[s]];i.files.push({name:r[r.length-1],status:n.status,fullPath:n.file})}return e}function _Z({name:t,node:e,depth:n,selectedFile:r,onFileClick:i}){const s=Object.keys(e.dirs).sort(),o=[...e.files].sort((a,l)=>a.name.localeCompare(l.name));return y.jsxs(y.Fragment,{children:[t&&y.jsxs("div",{className:Pr.dirItem,style:{paddingLeft:8+n*16},children:[y.jsx("span",{className:Pr.dirArrow,children:y.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:"rotate(90deg)"},children:y.jsx("polyline",{points:"9 6 15 12 9 18"})})}),y.jsx("span",{className:Pr.icon,children:SYe()}),y.jsx("span",{className:Pr.dirName,children:t})]}),s.map(a=>y.jsx(_Z,{name:a,node:e.dirs[a],depth:t?n+1:n,selectedFile:r,onFileClick:i},a)),o.map(a=>y.jsxs("div",{className:`${Pr.changeItem} ${r===a.fullPath?Pr.changeItemActive:""}`,style:{paddingLeft:8+(t?n+1:n)*16},onClick:()=>i&&i(a.fullPath),children:[y.jsx("span",{className:Pr.icon,children:$Ye(a.name)}),y.jsx("span",{className:Pr.fileName,children:a.name}),y.jsx("span",{className:Pr.status,style:{color:mYe[a.status]||"#888"},children:gYe[a.status]||a.status})]},a.fullPath))]})}function yYe({visible:t}){const[e,n]=f.useState(null),[r,i]=f.useState(null),[s,o]=f.useState(!0),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(null),[p,g]=f.useState(!1),v=f.useRef(!0);return f.useEffect(()=>{if(v.current=!0,!!t)return o(!0),i(null),fetch(Ln("/api/git-status")).then($=>$.ok?$.json():Promise.reject()).then($=>{v.current&&(n($.changes||[]),o(!1))}).catch(()=>{v.current&&(i("Failed to load git status"),o(!1))}),()=>{v.current=!1}},[t]),f.useEffect(()=>{if(!a){u(null),h(null);return}g(!0),u(null),h(null),fetch(Ln(`/api/git-diff?files=${encodeURIComponent(a)}`)).then($=>{if(!$.ok)throw new Error(`HTTP ${$.status}`);return $.json()}).then($=>{v.current&&($.diffs&&$.diffs[0]?u($.diffs[0]):h("No diff data available"),g(!1))}).catch($=>{v.current&&(h(`${ae("ui.fileLoadError")}: ${$.message}`),g(!1))})},[a]),y.jsxs("div",{className:Pr.container,children:[y.jsxs("div",{className:Pr.fileListSection,children:[y.jsxs("div",{className:Pr.header,children:[y.jsx("span",{className:Pr.headerTitle,children:ae("ui.gitChanges")}),y.jsx("span",{className:Pr.fileCount,children:e?e.length:0})]}),y.jsxs("div",{className:Pr.changesContainer,children:[s&&y.jsx("div",{className:Pr.statusText,children:"Loading..."}),r&&y.jsx("div",{className:Pr.errorText,children:r}),!s&&!r&&e&&e.length===0&&y.jsx("div",{className:Pr.emptyText,children:"No changes"}),!s&&!r&&e&&e.length>0&&y.jsx(_Z,{name:"",node:bYe(e),depth:0,selectedFile:a,onFileClick:l})]})]}),y.jsx("div",{className:Pr.diffSection,children:a?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:Pr.diffHeader,children:[y.jsx("span",{className:Pr.diffFilePath,children:a}),y.jsx("span",{className:Pr.diffBadge,children:"DIFF"})]}),y.jsxs("div",{className:Pr.diffContent,children:[p&&y.jsx("div",{className:Pr.statusText,children:ae("ui.loading")}),d&&y.jsx("div",{className:Pr.errorText,children:d}),!p&&!d&&c&&y.jsx(y.Fragment,{children:c.is_large?y.jsxs("div",{className:Pr.warningText,children:[y.jsx("p",{children:ae("ui.largeFileWarning")}),y.jsxs("p",{style:{color:"#888",fontSize:12},children:[ae("ui.fileSize"),": ",(c.size/(1024*1024)).toFixed(2)," MB"]})]}):c.is_binary?y.jsx("div",{className:Pr.statusText,style:{fontStyle:"italic"},children:ae("ui.binaryFileNotice")}):y.jsx(yZ,{file_path:a,old_string:c.old_content,new_string:c.new_content})})]})]}):y.jsxs("div",{className:Pr.diffPlaceholder,children:[y.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"#333",strokeWidth:"1.5",children:[y.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),y.jsx("circle",{cx:"18",cy:"6",r:"3"}),y.jsx("circle",{cx:"6",cy:"18",r:"3"}),y.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),y.jsx("span",{children:ae("ui.mobileGitDiffHint")})]})})]})}const _Ye="_container_rkahp_1",QYe="_header_rkahp_9",xYe="_headerTitle_rkahp_18",wYe="_closeBtn_rkahp_24",PYe="_content_rkahp_38",CYe="_empty_rkahp_47",TYe="_fixedTable_rkahp_54",kYe="_ellipsisCell_rkahp_58",su={container:_Ye,header:QYe,headerTitle:xYe,closeBtn:wYe,content:PYe,empty:CYe,fixedTable:TYe,ellipsisCell:kYe},RYe=["ttl","system_change","tools_change","model_change","msg_truncated","msg_modified","key_change"],gj={ttl:"cacheLoss.ttl",system_change:"cacheLoss.systemChange",tools_change:"cacheLoss.toolsChange",model_change:"cacheLoss.modelChange",msg_truncated:"cacheLoss.msgTruncated",msg_modified:"cacheLoss.msgModified",key_change:"cacheLoss.keyChange"};function EYe({requests:t=[],visible:e,onClose:n}){if(!e)return null;const{byModel:r,models:i,toolStats:s,skillStats:o,cacheStats:a,activeReasons:l,totalCount:c,totalCache:u,hasCacheStats:d,subAgentEntries:h,hasSubAgentStats:p,isEmpty:g}=f.useMemo(()=>{const v=XW(t),$=Object.keys(v),S=MW(t),_=jW(t),Q=zW(t),x=RYe.filter(E=>Q[E].count>0),w=x.reduce((E,k)=>E+Q[k].count,0),C=x.reduce((E,k)=>E+Q[k].cacheCreate,0),T=x.length>0,z={};for(let E=0;E<t.length;E++){const k=Id(t[E],t[E+1]);if(k.type==="SubAgent"){const R=k.subType||"Other";z[R]=(z[R]||0)+1}}const X=Object.entries(z).sort((E,k)=>k[1]-E[1]),A=X.length>0,I=$.length===0&&S.length===0&&!T&&!A&&_.length===0;return{byModel:v,models:$,toolStats:S,skillStats:_,cacheStats:Q,activeReasons:x,totalCount:w,totalCache:C,hasCacheStats:T,subAgentEntries:X,hasSubAgentStats:A,isEmpty:I}},[t]);return y.jsxs("div",{className:su.container,children:[y.jsxs("div",{className:su.header,children:[y.jsx("span",{className:su.headerTitle,children:ae("ui.tokenStats")}),y.jsx("button",{className:su.closeBtn,onClick:n,children:y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[y.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),y.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),y.jsx("div",{className:su.content,children:g?y.jsx("div",{className:su.empty,children:"—"}):y.jsxs(y.Fragment,{children:[o.length>0&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.skillUsageStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"Skill"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[o.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label,children:v}),y.jsx("td",{className:pe.td,children:$})]},v)),o.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:o.reduce((v,$)=>v+$[1],0)})]})]})]})]}),p&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.subAgentStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"SubAgent"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[h.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label,children:v}),y.jsx("td",{className:pe.td,children:$})]},v)),h.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:h.reduce((v,$)=>v+$[1],0)})]})]})]})]}),s.length>0&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.toolUsageStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"Tool"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[s.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsxs("td",{className:pe.label,children:[v," ",y.jsx(bc,{doc:`Tool-${v}`})]}),y.jsx("td",{className:pe.td,children:$})]},v)),s.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:s.reduce((v,$)=>v+$[1],0)})]})]})]})]}),d&&y.jsxs("div",{className:pe.modelCard,children:[y.jsxs("div",{className:pe.modelName,children:["MainAgent",y.jsx(bc,{doc:"MainAgent"})," ",ae("ui.cacheRebuildStats"),y.jsx(bc,{doc:"CacheRebuild"})]}),y.jsxs("table",{className:`${pe.statsTable} ${su.fixedTable}`,children:[y.jsxs("colgroup",{children:[y.jsx("col",{style:{width:"50%"}}),y.jsx("col",{style:{width:"25%"}}),y.jsx("col",{style:{width:"25%"}})]}),y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:ae("ui.cacheRebuild.reason")}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.cacheCreate")})]})}),y.jsxs("tbody",{children:[l.map(v=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:`${pe.label} ${su.ellipsisCell}`,title:ae(`ui.${gj[v]}`),children:ae(`ui.${gj[v]}`)}),y.jsx("td",{className:pe.td,children:a[v].count}),y.jsx("td",{className:pe.td,children:Er(a[v].cacheCreate)})]},v)),l.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:c}),y.jsx("td",{className:pe.td,children:Er(u)})]})]})]})]}),i.map(v=>{const $=r[v],S=$.input+$.cacheCreation+$.cacheRead,_=S>0?($.cacheRead/S*100).toFixed(1):"0.0";return y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:v}),y.jsx("table",{className:pe.statsTable,children:y.jsxs("tbody",{children:[y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:"Token"}),y.jsx("td",{className:pe.th,children:"input"}),y.jsx("td",{className:pe.th,children:"output"})]}),y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label}),y.jsx("td",{className:pe.td,children:Er(S)}),y.jsx("td",{className:pe.td,children:Er($.output)})]}),y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:"Cache"}),y.jsx("td",{className:pe.th,children:"create"}),y.jsx("td",{className:pe.th,children:"read"})]}),y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label}),y.jsx("td",{className:pe.td,children:Er($.cacheCreation)}),y.jsx("td",{className:pe.td,children:Er($.cacheRead)})]}),y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:ae("ui.hitRate")}),y.jsxs("td",{colSpan:2,className:pe.td,children:[_,"%"]})]})]})})]},v)})]})})]})}const{Text:xd,Title:XYe}=Ga;function zYe(t){if(!t)return"0 B";const e=["B","KB","MB","GB"];let n=0,r=t;for(;r>=1024&&n<e.length-1;)r/=1024,n++;return`${r.toFixed(n>0?1:0)} ${e[n]}`}function MYe(t){if(!t)return"";const e=Date.now()-new Date(t).getTime(),n=Math.floor(e/6e4);if(n<1)return ae("ui.workspaces.justNow");if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function jYe({open:t,onClose:e,onSelect:n}){const[r,i]=f.useState(""),[s,o]=f.useState(null),[a,l]=f.useState([]),[c,u]=f.useState(!1),[d,h]=f.useState(""),p=f.useCallback(v=>{u(!0);const $=v?`/api/browse-dir?path=${encodeURIComponent(v)}`:"/api/browse-dir";fetch(Ln($)).then(S=>S.json()).then(S=>{S.error?vr.error(S.error):(i(S.current),o(S.parent),l(S.dirs||[]),h(S.current)),u(!1)}).catch(()=>{vr.error("Failed to browse directory"),u(!1)})},[]);f.useEffect(()=>{t&&p("")},[t,p]);const g=()=>{const v=d.trim();v&&p(v)};return y.jsxs(Ti,{title:ae("ui.workspaces.selectDir"),open:t,onCancel:e,footer:null,width:600,styles:{body:{padding:"12px 0"}},children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"0 16px 10px",borderBottom:"1px solid #2a2a2a"},children:[y.jsx(yn,{type:"text",icon:y.jsx(mve,{}),disabled:!s,onClick:()=>s&&p(s),size:"small"}),y.jsxs(xd,{style:{color:"#e0e0e0",fontSize:13,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[y.jsx(t1,{style:{marginRight:6,color:"#1668dc"}}),r]})]}),y.jsx("div",{style:{maxHeight:400,overflowY:"auto",padding:"4px 0"},children:c?y.jsx("div",{style:{textAlign:"center",padding:40},children:y.jsx(qa,{})}):a.length===0?y.jsx("div",{style:{textAlign:"center",padding:40},children:y.jsx(xd,{type:"secondary",children:ae("ui.workspaces.emptyDir")})}):a.map(v=>y.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",cursor:"pointer",transition:"background 0.15s"},onMouseEnter:$=>$.currentTarget.style.background="#1a1a1a",onMouseLeave:$=>$.currentTarget.style.background="transparent",children:[y.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0},onClick:()=>p(v.path),children:[y.jsx(oW,{style:{color:v.hasGit?"#1668dc":"#666",fontSize:16,flexShrink:0}}),y.jsx(xd,{style:{color:"#d0d0d0",fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),v.hasGit&&y.jsxs(eo,{color:"blue",style:{fontSize:11,lineHeight:"18px",padding:"0 4px",margin:0,flexShrink:0},children:[y.jsx(vW,{style:{marginRight:2}}),"git"]})]}),y.jsx(yn,{type:"primary",size:"small",onClick:$=>{$.stopPropagation(),n(v.path)},children:ae("ui.workspaces.select")})]},v.path))}),y.jsxs("div",{style:{borderTop:"1px solid #2a2a2a",padding:"10px 16px 4px",display:"flex",flexDirection:"column",gap:8},children:[y.jsxs(yn,{type:"primary",ghost:!0,block:!0,icon:y.jsx(t1,{}),onClick:()=>n(r),children:[ae("ui.workspaces.selectCurrent")," — ",r.split("/").pop()||r]}),y.jsxs("div",{style:{display:"flex",gap:8},children:[y.jsx(Kd,{size:"small",value:d,onChange:v=>h(v.target.value),onPressEnter:g,placeholder:ae("ui.workspaces.pathPlaceholder"),style:{flex:1}}),y.jsx(yn,{size:"small",onClick:g,children:ae("ui.workspaces.goTo")})]})]})]})}function NYe({onLaunch:t}){const[e,n]=f.useState([]),[r,i]=f.useState(!0),[s,o]=f.useState(null),[a,l]=f.useState(!1),c=()=>{fetch(Ln("/api/workspaces")).then(p=>p.json()).then(p=>{n(p.workspaces||[]),i(!1)}).catch(()=>i(!1))};f.useEffect(()=>{c()},[]);const u=p=>{l(!1),fetch(Ln("/api/workspaces/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p})}).then(g=>g.json()).then(g=>{g.error?vr.error(g.error):c()}).catch(()=>vr.error("Failed to add workspace"))},d=p=>{fetch(Ln(`/api/workspaces/${p}`),{method:"DELETE"}).then(g=>g.json()).then(()=>c()).catch(()=>{})},h=p=>{o(p.id),fetch(Ln("/api/workspaces/launch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p.path})}).then(g=>g.json()).then(g=>{g.error?(vr.error(g.error),o(null)):t({projectName:g.projectName,path:p.path})}).catch(()=>{vr.error("Launch failed"),o(null)})};return y.jsxs("div",{style:{minHeight:"100vh",background:"#0a0a0a",display:"flex",justifyContent:"center",paddingTop:60},children:[y.jsxs("div",{style:{width:"100%",maxWidth:720,padding:"0 24px"},children:[y.jsxs("div",{style:{marginBottom:32,textAlign:"center"},children:[y.jsxs(XYe,{level:3,style:{color:"#e0e0e0",margin:0},children:[y.jsx(t1,{style:{marginRight:8,color:"#1668dc"}}),ae("ui.workspaces.title")]}),y.jsx(xd,{type:"secondary",style:{fontSize:13},children:ae("ui.workspaces.subtitle")})]}),y.jsx("div",{style:{marginBottom:20,textAlign:"center"},children:y.jsx(yn,{type:"primary",icon:y.jsx(H$,{}),onClick:()=>l(!0),size:"large",children:ae("ui.workspaces.browse")})}),r?y.jsx("div",{style:{textAlign:"center",padding:60},children:y.jsx(qa,{})}):e.length===0?y.jsx(vs,{description:y.jsx(xd,{type:"secondary",children:ae("ui.workspaces.empty")}),style:{marginTop:60}}):y.jsx(e1,{dataSource:e,renderItem:p=>y.jsx(jT,{size:"small",style:{marginBottom:10,background:"#141414",borderColor:"#2a2a2a",cursor:"pointer"},hoverable:!0,onClick:()=>h(p),children:y.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[y.jsxs("div",{style:{flex:1,minWidth:0},children:[y.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:y.jsx(xd,{strong:!0,style:{color:"#e0e0e0",fontSize:15},children:p.projectName})}),y.jsx(xd,{type:"secondary",style:{fontSize:12,wordBreak:"break-all"},children:p.path}),y.jsxs("div",{style:{display:"flex",gap:16,marginTop:6,fontSize:12,color:"#666"},children:[y.jsxs("span",{children:[y.jsx(Rde,{style:{marginRight:4}}),MYe(p.lastUsed)]}),p.logCount>0&&y.jsxs("span",{children:[y.jsx(Pve,{style:{marginRight:4}}),p.logCount," logs (",zYe(p.totalSize),")"]})]})]}),y.jsxs(bl,{children:[y.jsx(yn,{type:"primary",icon:y.jsx(Ave,{}),loading:s===p.id,onClick:g=>{g.stopPropagation(),h(p)},children:ae("ui.workspaces.open")}),y.jsx(IA,{title:ae("ui.workspaces.confirmRemove"),onConfirm:g=>{g==null||g.stopPropagation(),d(p.id)},onCancel:g=>g==null?void 0:g.stopPropagation(),okText:"Yes",cancelText:"No",children:y.jsx(yn,{type:"text",danger:!0,icon:y.jsx(r1,{}),onClick:g=>g.stopPropagation()})})]})]})},p.id)})]}),y.jsx(jYe,{open:a,onClose:()=>l(!1),onSelect:u})]})}const IYe="_layout_1ir1q_1",LYe="_header_1ir1q_6",AYe="_content_1ir1q_14",WYe="_mainContainer_1ir1q_19",VYe="_leftPanel_1ir1q_24",YYe="_leftPanelHeader_1ir1q_32",BYe="_leftPanelCount_1ir1q_43",qYe="_leftPanelBody_1ir1q_49",UYe="_rightPanel_1ir1q_54",DYe="_modalActions_1ir1q_60",ZYe="_spinCenter_1ir1q_64",GYe="_emptyCenter_1ir1q_69",FYe="_logListContainer_1ir1q_79",HYe="_loadingOverlay_1ir1q_127",KYe="_loadingText_1ir1q_140",JYe="_mobileLoadingOverlay_1ir1q_146",eBe="_mobileLoadingSpinner_1ir1q_158",tBe="_mobileLoadingLabel_1ir1q_171",nBe="_footer_1ir1q_177",rBe="_footerRight_1ir1q_188",iBe="_footerText_1ir1q_196",sBe="_footerLink_1ir1q_201",oBe="_footerIcon_1ir1q_213",aBe="_footerDivider_1ir1q_218",lBe="_guideContainer_1ir1q_226",cBe="_guideContent_1ir1q_234",uBe="_guideTitle_1ir1q_239",dBe="_guideStep_1ir1q_246",OBe="_guideStepNum_1ir1q_252",hBe="_guideStepBody_1ir1q_267",fBe="_guideText_1ir1q_272",pBe="_guideCode_1ir1q_279",mBe="_mobileChatOverlay_1ir1q_292",gBe="_mobileChatOverlayVisible_1ir1q_304",vBe="_mobileChatInner_1ir1q_308",$Be="_mobileGitDiffOverlay_1ir1q_316",SBe="_mobileGitDiffOverlayVisible_1ir1q_328",bBe="_mobileGitDiffInner_1ir1q_332",yBe="_mobileMenuBtn_1ir1q_340",_Be="_mobileMenuOverlay_1ir1q_357",QBe="_mobileMenuDropdown_1ir1q_363",xBe="_mobileMenuItem_1ir1q_377",wBe="_mobileStatsOverlay_1ir1q_395",PBe="_mobileStatsOverlayVisible_1ir1q_407",CBe="_mobileStatsInner_1ir1q_411",TBe="_mobileLogMgmtOverlay_1ir1q_418",kBe="_mobileLogMgmtOverlayVisible_1ir1q_430",RBe="_mobileLogMgmtHeader_1ir1q_434",EBe="_mobileLogMgmtTitle_1ir1q_443",XBe="_mobileLogMgmtClose_1ir1q_449",zBe="_mobileLogMgmtActions_1ir1q_464",MBe="_mobileLogMgmtBody_1ir1q_472",jBe="_mobileSettingsOverlay_1ir1q_479",NBe="_mobileSettingsOverlayVisible_1ir1q_491",IBe="_mobilePromptOverlay_1ir1q_495",LBe="_mobilePromptOverlayVisible_1ir1q_507",ABe="_mobilePromptBody_1ir1q_511",WBe="_mobilePromptList_1ir1q_519",VBe="_mobilePromptItem_1ir1q_525",YBe="_mobilePromptTimestamp_1ir1q_530",BBe="_mobilePromptCard_1ir1q_537",qBe="_mobilePromptPreText_1ir1q_545",Qt={layout:IYe,header:LYe,content:AYe,mainContainer:WYe,leftPanel:VYe,leftPanelHeader:YYe,leftPanelCount:BYe,leftPanelBody:qYe,rightPanel:UYe,modalActions:DYe,spinCenter:ZYe,emptyCenter:GYe,logListContainer:FYe,loadingOverlay:HYe,loadingText:KYe,mobileLoadingOverlay:JYe,mobileLoadingSpinner:eBe,mobileLoadingLabel:tBe,footer:nBe,footerRight:rBe,footerText:iBe,footerLink:sBe,footerIcon:oBe,footerDivider:aBe,guideContainer:lBe,guideContent:cBe,guideTitle:uBe,guideStep:dBe,guideStepNum:OBe,guideStepBody:hBe,guideText:fBe,guideCode:pBe,mobileChatOverlay:mBe,mobileChatOverlayVisible:gBe,mobileChatInner:vBe,mobileGitDiffOverlay:$Be,mobileGitDiffOverlayVisible:SBe,mobileGitDiffInner:bBe,mobileMenuBtn:yBe,mobileMenuOverlay:_Be,mobileMenuDropdown:QBe,mobileMenuItem:xBe,mobileStatsOverlay:wBe,mobileStatsOverlayVisible:PBe,mobileStatsInner:CBe,mobileLogMgmtOverlay:TBe,mobileLogMgmtOverlayVisible:kBe,mobileLogMgmtHeader:RBe,mobileLogMgmtTitle:EBe,mobileLogMgmtClose:XBe,mobileLogMgmtActions:zBe,mobileLogMgmtBody:MBe,mobileSettingsOverlay:jBe,mobileSettingsOverlayVisible:NBe,mobilePromptOverlay:IBe,mobilePromptOverlayVisible:LBe,mobilePromptBody:ABe,mobilePromptList:WBe,mobilePromptItem:VBe,mobilePromptTimestamp:YBe,mobilePromptCard:BBe,mobilePromptPreText:qBe},UBe="ccv_entryCache",Iu="entries",W5="cache",V5="ccv_cacheMeta",DBe=1,ZBe=10080*60*1e3;let qO=null,UO=null;function Y5(){return qO?Promise.resolve(qO):UO||(UO=new Promise((t,e)=>{const n=indexedDB.open(UBe,DBe);n.onupgradeneeded=()=>{const r=n.result;r.objectStoreNames.contains(Iu)||r.createObjectStore(Iu)},n.onsuccess=()=>{qO=n.result,qO.onclose=()=>{qO=null},UO=null,t(qO)},n.onerror=()=>{UO=null,e(n.error)}}),UO)}let vj=0;function GBe(t,e){try{const n=e[e.length-1],r=(n==null?void 0:n.timestamp)||null;r&&localStorage.setItem(V5,JSON.stringify({projectName:t,lastTs:r,count:e.length}))}catch{}}function FBe(){try{localStorage.removeItem(V5)}catch{}}function HBe(){try{const t=localStorage.getItem(V5);if(!t)return null;const e=JSON.parse(t);return e!=null&&e.lastTs&&(e==null?void 0:e.count)>0&&(e!=null&&e.projectName)?e:null}catch{return null}}async function Zx(t,e){if(!t||!Array.isArray(e)||e.length===0)return;const n=++vj;try{const r=await Y5();return n!==vj?void 0:(GBe(t,e),new Promise(i=>{const s=r.transaction(Iu,"readwrite");s.objectStore(Iu).put({projectName:t,entries:e,ts:Date.now()},W5),s.oncomplete=()=>i(),s.onerror=()=>i()}))}catch{}}async function KBe(t){try{const e=await Y5();return new Promise(n=>{const i=e.transaction(Iu,"readonly").objectStore(Iu).get(W5);i.onsuccess=()=>{const s=i.result;!s||s.projectName!==t||!Array.isArray(s.entries)||s.entries.length===0?n(null):s.ts&&Date.now()-s.ts>ZBe?(j2(),n(null)):n(s.entries)},i.onerror=()=>n(null)})}catch{return null}}async function j2(){FBe();try{const t=await Y5();return new Promise(e=>{const n=t.transaction(Iu,"readwrite");n.objectStore(Iu).delete(W5),n.oncomplete=()=>e(),n.onerror=()=>e()})}catch{}}const hh=class hh extends ne.Component{constructor(n){super(n);Rt(this,"handleSelectRequest",n=>{this.setState({selectedIndex:n,scrollCenter:!1})});Rt(this,"handleViewRequest",n=>{this.setState({viewMode:"raw",selectedIndex:n,scrollCenter:!0})});Rt(this,"handleViewInChat",()=>{this.setState(n=>{const i=(n.showAll?n.requests:Ra(n.requests))[n.selectedIndex];if(!i)return null;let s=null;if(Ii(i)&&i.timestamp)s=i.timestamp;else{if(Id(i).type==="SubAgent"&&i.timestamp)s=i.timestamp;else{const a=n.requests.indexOf(i);a>=0&&(s=F6(n.requests,a))}s||vr.info(ae("ui.cannotMap"))}return{viewMode:"chat",chatScrollToTs:s}})});Rt(this,"handleWorkspaceLaunch",({projectName:n})=>{this._isLocalLog=!1,this._localLogFile=null,this.setState({workspaceMode:!1,projectName:n,viewMode:"chat",cliMode:!0})});Rt(this,"handleReturnToWorkspaces",()=>{fetch(Ln("/api/workspaces/stop"),{method:"POST"}).then(()=>{this.setState({workspaceMode:!0,requests:[],mainAgentSessions:[],projectName:"",selectedIndex:null})}).catch(()=>{})});Rt(this,"handleToggleViewMode",()=>{this.setState(n=>{const r=n.viewMode==="raw"?"chat":"raw";if(r==="raw"){if(n.selectedIndex===null){const o=n.showAll?n.requests:Ra(n.requests);return{viewMode:r,selectedIndex:o.length>0?o.length-1:null,scrollCenter:!0}}return{viewMode:r,scrollCenter:!0}}const i=n.showAll?n.requests:Ra(n.requests),s=n.selectedIndex!=null?i[n.selectedIndex]:null;if(s){let o=null;if(Ii(s)&&s.timestamp)o=s.timestamp;else if(Id(s).type==="SubAgent"&&s.timestamp)o=s.timestamp;else{const l=n.requests.indexOf(s);l>=0&&(o=F6(n.requests,l)),o||vr.info(ae("ui.cannotMap"))}return{viewMode:r,chatScrollToTs:o}}return{viewMode:r,chatScrollToTs:null}})});Rt(this,"handleLangChange",()=>{const n=Qm();this.setState({lang:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lang:n})}).catch(()=>{})});Rt(this,"handleCollapseToolResultsChange",n=>{this.setState({collapseToolResults:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collapseToolResults:n})}).catch(()=>{})});Rt(this,"handleExpandThinkingChange",n=>{this.setState({expandThinking:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expandThinking:n})}).catch(()=>{})});Rt(this,"handleExpandDiffChange",n=>{this.setState({expandDiff:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expandDiff:n})}).catch(()=>{})});Rt(this,"handleFilterIrrelevantChange",n=>{this.setState(r=>{const i=!n,s=i?r.requests:Ra(r.requests);return{showAll:i,selectedIndex:s.length>0?s.length-1:null}}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filterIrrelevant:n})}).catch(()=>{})});Rt(this,"handleExportPromptsTxt",n=>{if(!n||n.length===0)return;const r=[];for(const a of n){const l=[],c=a.timestamp?new Date(a.timestamp).toLocaleString():"";c&&l.push(`${c}:
|
|
709
|
+
`).length,x=Q-_;if(g.plainText=g.plainText.substring(0,v)+p+g.plainText.substring(v+h.length),x!==0){const w=g.lineNums[S]||S+1,C=[];for(let T=0;T<Q;T++)C.push(w+T);g.lineNums=[...g.lineNums.slice(0,S),...C,...g.lineNums.slice(S+_).map(T=>T+x)]}}}}}const o={};for(const c of t)if(c.role==="user"&&Array.isArray(c.content)){for(const u of c.content)if(u.type==="tool_result"){const d=e[u.tool_use_id];if(d&&d.name==="AskUserQuestion"){const h=oQ(u);o[u.tool_use_id]=VVe(h)}}}return{toolUseMap:e,toolResultMap:n,readContentMap:r,editSnapshotMap:i,askAnswerMap:o}}function VVe(t){const e={},n=/"([^"]+)"="([^"]*)"/g;let r;for(;(r=n.exec(t))!==null;)e[r[1]]=r[2];return e}class mj extends ne.Component{constructor(n){super(n);Rt(this,"handleStickToBottom",()=>{this.setState({stickyBottom:!0},()=>{const n=this.containerRef.current;n&&(n.scrollTop=n.scrollHeight)})});Rt(this,"handleLoadMore",()=>{this._mobileExtraItems+=AVe;const n=this.containerRef.current,r=n?n.scrollHeight:0,i=n?n.scrollTop:0,s=this.buildAllItems(),o=this._applyMobileSlice(s);this.setState({allItems:o,visibleCount:o.length},()=>{if(n){const a=n.scrollHeight;n.scrollTop=i+(a-r)}})});Rt(this,"handlePromptOptionClick",n=>{const r=this._inputWs;if(!r||r.readyState!==WebSocket.OPEN)return;const i=this.state.ptyPrompt;if(!i)return;const s=i.options,o=s.findIndex(h=>h.number===n);let a=s.findIndex(h=>h.selected);a<0&&(a=0);const l=o-a,c=l>0?"\x1B[B":"\x1B[A",u=Math.abs(l),d=h=>{h<u?(r.send(JSON.stringify({type:"input",data:c})),setTimeout(()=>d(h+1),30)):setTimeout(()=>{r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({type:"input",data:"\r"}))},50)};d(0),this.setState(h=>{const p=h.ptyPromptHistory.slice(),g=p[p.length-1];return g&&g.status==="active"&&(p[p.length-1]={...g,status:"answered",selectedNumber:n}),{ptyPrompt:null,ptyPromptHistory:p}}),this._ptyBuffer="",this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer)});Rt(this,"handleInputSend",()=>{const n=this._inputRef.current;if(!n)return;const r=n.value.trim();r&&this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&(this._inputWs.send(JSON.stringify({type:"input",data:r})),setTimeout(()=>{this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:"\r"}))},50),n.value="",n.style.height="auto",this.setState({inputEmpty:!0,pendingInput:r,inputSuggestion:null},()=>this.scrollToBottom()))});Rt(this,"handleInputKeyDown",n=>{if(n.key==="Tab"&&this.state.inputSuggestion){n.preventDefault();const r=this._inputRef.current;r&&(r.value=this.state.inputSuggestion,r.style.height="auto",r.style.height=Math.min(r.scrollHeight,120)+"px"),this.setState({inputSuggestion:null,inputEmpty:!1});return}n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),this.handleInputSend())});Rt(this,"handleInputChange",n=>{const r=n.target;r.style.height="auto",r.style.height=Math.min(r.scrollHeight,120)+"px";const i=!r.value.trim();this.setState({inputEmpty:i}),this.state.inputSuggestion&&!i&&this.setState({inputSuggestion:null})});Rt(this,"handleSuggestionToTerminal",()=>{const n=this.state.inputSuggestion;!n||!this._inputWs||this._inputWs.readyState!==WebSocket.OPEN||(this._inputWs.send(JSON.stringify({type:"input",data:n})),setTimeout(()=>{this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:"\r"}))},50),this.setState({inputSuggestion:null,pendingInput:n},()=>this.scrollToBottom()))});Rt(this,"handleSplitMouseDown",n=>{n.preventDefault(),this._resizing=!0;const i=!window.location.search.includes("token=");let s=[];if(i){const l=this.innerSplitRef.current;if(l){const u=l.getBoundingClientRect().width,d=7.8,h=[60,80,100,120],p=5;s=h.map(g=>{const v=g*d,$=v+p;if($>u*.75||$<u*.15)return null;const S=u-v-p;return{cols:g,terminalPx:v,linePosition:S}}).filter(g=>g!==null)}}this.setState({isDragging:!0,snapLines:s});const o=l=>{if(!this._resizing)return;const c=this.innerSplitRef.current;if(!c)return;const u=c.getBoundingClientRect(),d=u.width;let h=u.right-l.clientX;h=Math.max(200,Math.min(d*.75,h));let p=null;if(i&&s.length>0){let v=1/0,$=null;for(const S of s){const _=Math.abs(l.clientX-u.left-S.linePosition);_<v&&(v=_,$=S)}$&&v<60&&(p=$)}this.setState({terminalWidth:h,activeSnapLine:p})},a=()=>{if(this._resizing=!1,i&&this.state.activeSnapLine){const l=this.state.activeSnapLine.terminalPx;localStorage.setItem("cc-viewer-terminal-width",l.toString()),this.setState({terminalWidth:l,isDragging:!1,activeSnapLine:null,snapLines:[],needsInitialSnap:!1})}else localStorage.setItem("cc-viewer-terminal-width",this.state.terminalWidth.toString()),this.setState({isDragging:!1,activeSnapLine:null,snapLines:[],needsInitialSnap:!1});document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",a),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",o),document.addEventListener("mouseup",a),document.body.style.cursor="col-resize",document.body.style.userSelect="none"});Rt(this,"handleToggleExpandPath",n=>{this.setState(r=>{const i=new Set(r.fileExplorerExpandedPaths);return i.has(n)?i.delete(n):i.add(n),{fileExplorerExpandedPaths:i}})});this.containerRef=ne.createRef(),this.splitContainerRef=ne.createRef(),this.innerSplitRef=ne.createRef();const r=localStorage.getItem("cc-viewer-terminal-width"),i=r?parseFloat(r):null;this.state={visibleCount:0,loading:!1,allItems:[],highlightTs:null,highlightFading:!1,terminalWidth:i||468,needsInitialSnap:i===null,inputEmpty:!0,pendingInput:null,stickyBottom:!0,ptyPrompt:null,ptyPromptHistory:[],inputSuggestion:null,fileExplorerOpen:localStorage.getItem("ccv_fileExplorerOpen")!=="false",currentFile:null,currentGitDiff:null,scrollToLine:null,fileExplorerExpandedPaths:new Set,gitChangesOpen:!1,snapLines:[],activeSnapLine:null,isDragging:!1,fileVersion:0,editorSessionId:null,editorFilePath:null,fileExplorerRefresh:0,gitChangesRefresh:0},this._processedToolIds=new Set,this._fileRefreshTimer=null,this._gitRefreshTimer=null,this._queueTimer=null,this._prevItemsLen=0,this._scrollTargetIdx=null,this._scrollTargetRef=ne.createRef(),this._scrollFadeTimer=null,this._resizing=!1,this._inputWs=null,this._inputRef=ne.createRef(),this._ptyBuffer="",this._ptyDebounceTimer=null,this._mobileExtraItems=0,this._mobileSliceOffset=0,this._totalItemCount=0}_setFileExplorerOpen(n){localStorage.setItem("ccv_fileExplorerOpen",String(n)),this.setState({fileExplorerOpen:n})}_checkToolFileChanges(){var s,o;const n=this.props.mainAgentSessions;if(!n||n.length===0)return;let r=!1,i=!1;for(const a of n){const l=[];if((o=(s=a.response)==null?void 0:s.body)!=null&&o.content&&l.push(a.response.body.content),Array.isArray(a.messages))for(const c of a.messages)c.role==="assistant"&&Array.isArray(c.content)&&l.push(c.content);for(const c of l)for(const u of c){if(u.type!=="tool_use"||!u.id||this._processedToolIds.has(u.id))continue;this._processedToolIds.add(u.id);const d=u.name;let h=u.input;if(typeof h=="string")try{h=JSON.parse(h.replace(/^\[object Object\]/,""))}catch{h={}}d==="Write"?(r=!0,i=!0):d==="Edit"||d==="NotebookEdit"?i=!0:d==="Bash"&&h&&h.command&&LVe(h.command)&&(r=!0,i=!0)}}r&&this.state.fileExplorerOpen&&(clearTimeout(this._fileRefreshTimer),this._fileRefreshTimer=setTimeout(()=>{this.setState(a=>({fileExplorerRefresh:a.fileExplorerRefresh+1}))},500)),i&&this.state.gitChangesOpen&&(clearTimeout(this._gitRefreshTimer),this._gitRefreshTimer=setTimeout(()=>{this.setState(a=>({gitChangesRefresh:a.gitChangesRefresh+1}))},500))}componentDidMount(){this.startRender(),this.props.cliMode&&this.connectInputWs(),this._bindStickyScroll(),this.state.needsInitialSnap&&this.props.cliMode&&this.props.terminalVisible&&this._snapToInitialPosition()}componentDidUpdate(n){if(n.mainAgentSessions!==this.props.mainAgentSessions)Cr&&(this._mobileExtraItems=0),this.startRender(),this.state.pendingInput&&this.setState({pendingInput:null}),this._updateSuggestion(),this._checkToolFileChanges();else if(n.collapseToolResults!==this.props.collapseToolResults||n.expandThinking!==this.props.expandThinking){const r=this.buildAllItems(),i=this._applyMobileSlice(r);this.setState({allItems:i,visibleCount:i.length})}if(!n.scrollToTimestamp&&this.props.scrollToTimestamp)if(Cr&&this.props.scrollToTimestamp){const r=this.buildAllItems(),i=this._scrollTargetIdx;if(i!=null){const o=Dx+this._mobileExtraItems,a=r.length>o?r.length-o:0;i<a&&(this._mobileExtraItems=r.length-i-Dx,this._mobileExtraItems<0&&(this._mobileExtraItems=0))}const s=this._applyMobileSlice(r);this.setState({allItems:s,visibleCount:s.length},()=>this.scrollToBottom())}else{const r=this.buildAllItems(),i=this._applyMobileSlice(r);this.setState({allItems:i,visibleCount:i.length},()=>this.scrollToBottom())}Cr&&this.props.mobileChatVisible&&!n.mobileChatVisible&&requestAnimationFrame(()=>{const r=this.containerRef.current;r&&(r.scrollTop=r.scrollHeight)}),!n.cliMode&&this.props.cliMode&&this.connectInputWs(),this._rebindStickyEl()}componentWillUnmount(){this._queueTimer&&clearTimeout(this._queueTimer),this._fadeClearTimer&&clearTimeout(this._fadeClearTimer),this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this._fileRefreshTimer&&clearTimeout(this._fileRefreshTimer),this._gitRefreshTimer&&clearTimeout(this._gitRefreshTimer),this._unbindScrollFade(),this._unbindStickyScroll(),this._inputWs&&(this._inputWs.close(),this._inputWs=null)}startRender(){this._queueTimer&&clearTimeout(this._queueTimer);const n=this.buildAllItems(),r=this._applyMobileSlice(n),i=this._prevItemsLen;this._prevItemsLen=r.length;const s=r.length-i;if(s<=0||i>0&&s<=3){this.setState({allItems:r,visibleCount:r.length,loading:!1},()=>this.scrollToBottom());return}if(r.length>MVe)this.setState({allItems:r,visibleCount:0,loading:!0}),this._queueTimer=setTimeout(()=>{this.setState({visibleCount:r.length,loading:!1},()=>this.scrollToBottom())},300);else{const o=Math.max(0,i);this.setState({allItems:r,visibleCount:o,loading:!1}),this.queueNext(o,r.length)}}queueNext(n,r){n>=r||(this._queueTimer=setTimeout(()=>{this.setState({visibleCount:n+1},()=>{this.scrollToBottom(),this.queueNext(n+1,r)})},WVe()))}_isNearBottom(){const n=this.containerRef.current;return n?n.scrollHeight-n.scrollTop-n.clientHeight<=30:!0}scrollToBottom(){if(this._scrollTargetRef.current){const n=this._scrollTargetRef.current,r=this.containerRef.current;r&&n.offsetHeight>r.clientHeight?n.scrollIntoView({block:"start",behavior:"instant"}):n.scrollIntoView({block:"center",behavior:"instant"});const i=this.props.scrollToTimestamp;this._scrollTargetRef=ne.createRef(),i&&(this.setState({highlightTs:i,highlightFading:!1}),this._bindScrollFade()),this.props.onScrollTsDone&&this.props.onScrollTsDone();return}if(this.state.stickyBottom){const n=this.containerRef.current;n&&(n.scrollTop=n.scrollHeight)}}_bindStickyScroll(){this._stickyScrollRafId=null,this._onStickyScroll=()=>{this._stickyScrollLock||this._stickyScrollRafId||(this._stickyScrollRafId=requestAnimationFrame(()=>{this._stickyScrollRafId=null;const n=this.containerRef.current;if(!n)return;const r=n.scrollHeight-n.scrollTop-n.clientHeight;this.state.stickyBottom&&r>30?this.setState({stickyBottom:!1}):!this.state.stickyBottom&&r<=5&&this.setState({stickyBottom:!0})}))},this._rebindStickyEl()}_rebindStickyEl(){const n=this.containerRef.current;n!==this._stickyBoundEl&&(this._stickyBoundEl&&this._stickyBoundEl.removeEventListener("scroll",this._onStickyScroll),this._stickyBoundEl=n,n&&n.addEventListener("scroll",this._onStickyScroll,{passive:!0}))}_unbindStickyScroll(){this._stickyBoundEl&&this._onStickyScroll&&(this._stickyBoundEl.removeEventListener("scroll",this._onStickyScroll),this._stickyBoundEl=null),this._stickyScrollRafId&&(cancelAnimationFrame(this._stickyScrollRafId),this._stickyScrollRafId=null)}_bindScrollFade(){this._unbindScrollFade();const n=this.containerRef.current;n&&(this._scrollFadeIgnoreFirst=!0,this._onScrollFade=()=>{if(this._scrollFadeIgnoreFirst){this._scrollFadeIgnoreFirst=!1;return}this.setState({highlightFading:!0}),this._fadeClearTimer=setTimeout(()=>{this.setState({highlightTs:null,highlightFading:!1})},2e3),this._unbindScrollFade()},n.addEventListener("scroll",this._onScrollFade,{passive:!0}))}_unbindScrollFade(){this._onScrollFade&&this.containerRef.current&&(this.containerRef.current.removeEventListener("scroll",this._onScrollFade),this._onScrollFade=null)}renderSessionMessages(n,r,i,s){const{userProfile:o,collapseToolResults:a,expandThinking:l,onViewRequest:c}=this.props,{toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p}=pj(n),g=[];for(let v=0;v<n.length;v++){const $=n[v],S=$.content,_=$._timestamp||null,Q=_?s[_]:void 0,x=Q!=null&&c?{requestIndex:Q,onViewRequest:c}:{};if($.role==="user"){if(Array.isArray(S)){const w=S.find(T=>T.type==="text"&&/^\[SUGGESTION MODE:/i.test((T.text||"").trim())),C=S.filter(T=>T.type==="tool_result");if(!(w&&C.length>0)){const{commands:T,textBlocks:z,skillBlocks:X}=JT(S);for(let A=0;A<T.length;A++)g.push(y.jsx(il,{role:"user",text:T[A],timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-cmd-${v}-${A}`));for(const A of X){const I=A.text.match(/^#\s+(.+)$/m),E=I?I[1]:"Skill";g.push(y.jsx(il,{role:"skill-loaded",text:A.text,skillName:E,timestamp:_,...x},`${r}-skill-${v}`))}for(let A=0;A<z.length;A++){const I=/^Implement the following plan:/i.test((z[A].text||"").trim());g.push(y.jsx(il,{role:I?"plan-prompt":"user",text:z[A].text,timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-user-${v}-${A}`))}}}else if(typeof S=="string"&&!eb(S)){const w=/^Implement the following plan:/i.test(S.trim());g.push(y.jsx(il,{role:w?"plan-prompt":"user",text:S,timestamp:_,userProfile:o,modelInfo:i,...x},`${r}-user-${v}`))}}else $.role==="assistant"&&(Array.isArray(S)?g.push(y.jsx(il,{role:"assistant",content:S,toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p,timestamp:_,modelInfo:i,collapseToolResults:a,expandThinking:l,...x},`${r}-asst-${v}`)):typeof S=="string"&&g.push(y.jsx(il,{role:"assistant",content:[{type:"text",text:S}],toolResultMap:u,readContentMap:d,editSnapshotMap:h,askAnswerMap:p,timestamp:_,modelInfo:i,collapseToolResults:a,expandThinking:l,...x},`${r}-asst-${v}`)))}return g}buildAllItems(){var v,$,S,_;const{mainAgentSessions:n,requests:r,collapseToolResults:i,expandThinking:s,onViewRequest:o}=this.props;if(!n||n.length===0)return[];const a={};if(r)for(let Q=0;Q<r.length;Q++)Ii(r[Q])&&r[Q].timestamp&&(a[r[Q].timestamp]=Q);let l=null;if(r){for(let Q=r.length-1;Q>=0;Q--)if(Ii(r[Q])&&((v=r[Q].body)!=null&&v.model)){l=r[Q].body.model;break}}const c=a0e(l),u=[],d={},h=[];if(r)for(let Q=0;Q<r.length;Q++){const x=r[Q];if(!x.timestamp)continue;const w=Id(x,r[Q+1]);if(w.type==="SubAgent"){const C=(S=($=x.response)==null?void 0:$.body)==null?void 0:S.content;if(Array.isArray(C)&&C.length>0){const T=pj(((_=x.body)==null?void 0:_.messages)||[]).toolResultMap;h.push({timestamp:x.timestamp,content:C,toolResultMap:T,label:gP(w.type,w.subType),requestIndex:Q})}}}let p=0;n.forEach((Q,x)=>{var C,T,z,X;x>0&&u.push(y.jsx(YX,{style:{borderColor:"#333",margin:"16px 0"},children:y.jsx(fj,{className:jn.sessionDividerText,children:"Session"})},`session-div-${x}`));const w=this.renderSessionMessages(Q.messages,`s${x}`,c,a);for(const A of w){const I=A.props.timestamp;for(;p<h.length&&I&&h[p].timestamp<=I;){const E=h[p];E.timestamp&&(d[E.timestamp]=u.length),u.push(y.jsx(il,{role:"sub-agent-chat",content:E.content,toolResultMap:E.toolResultMap,label:E.label,timestamp:E.timestamp,collapseToolResults:i,expandThinking:s,requestIndex:E.requestIndex,onViewRequest:o},`sub-chat-${p}`)),p++}I&&(d[I]=u.length),u.push(A)}for(;p<h.length;){const A=h[p],I=x<n.length-1&&((T=(C=n[x+1].messages)==null?void 0:C[0])==null?void 0:T._timestamp);if(I&&A.timestamp>I)break;A.timestamp&&(d[A.timestamp]=u.length),u.push(y.jsx(il,{role:"sub-agent-chat",content:A.content,toolResultMap:A.toolResultMap,label:A.label,timestamp:A.timestamp,collapseToolResults:i,expandThinking:s,requestIndex:A.requestIndex,onViewRequest:o},`sub-chat-${p}`)),p++}if(x===n.length-1&&((X=(z=Q.response)==null?void 0:z.body)!=null&&X.content)){const A=Q.response.body.content;Array.isArray(A)&&(u.push(y.jsx(ne.Fragment,{children:y.jsx(YX,{style:{borderColor:"#2a2a2a",margin:"8px 0"},children:y.jsx(fj,{type:"secondary",className:jn.lastResponseLabel,children:ae("ui.lastResponse")})})},"resp-divider")),Q.entryTimestamp&&(d[Q.entryTimestamp]=u.length),u.push(y.jsx(il,{role:"assistant",content:A,timestamp:Q.entryTimestamp,modelInfo:c,collapseToolResults:i,expandThinking:s,toolResultMap:{}},"resp-asst")))}});const{scrollToTimestamp:g}=this.props;return this._scrollTargetIdx=g&&d[g]!=null?d[g]:null,this._tsItemMap=d,u}_applyMobileSlice(n){if(!Cr)return this._mobileSliceOffset=0,this._totalItemCount=n.length,n;this._totalItemCount=n.length;const r=Dx+this._mobileExtraItems;if(n.length<=r)return this._mobileSliceOffset=0,n;const i=n.length-r;if(this._mobileSliceOffset=i,this._scrollTargetIdx!=null&&(this._scrollTargetIdx-=i,this._scrollTargetIdx<0&&(this._scrollTargetIdx=null)),this._tsItemMap){const s={};for(const[o,a]of Object.entries(this._tsItemMap)){const l=a-i;l>=0&&(s[o]=l)}this._tsItemMap=s}return n.slice(i)}_extractSuggestion(){var h;const{mainAgentSessions:n}=this.props;if(!(n!=null&&n.length))return null;const r=n[n.length-1],i=r==null?void 0:r.messages;if(!Array.isArray(i)||i.length===0)return null;const s=i[i.length-1];if((s==null?void 0:s.role)!=="user")return null;const o=s.content;if(!(Array.isArray(o)?o.some(p=>p.type==="text"&&/^\[SUGGESTION MODE:/i.test((p.text||"").trim())):typeof o=="string"&&/^\[SUGGESTION MODE:/im.test(o.trim())))return null;const l=r==null?void 0:r.response;if(!l)return null;const c=l.body;if(!c)return null;const u=c.stop_reason;if(u!=="end_turn"&&u!=="max_tokens")return null;const d=c.content;if(!Array.isArray(d))return null;for(let p=d.length-1;p>=0;p--)if(d[p].type==="text"&&((h=d[p].text)!=null&&h.trim()))return d[p].text.trim();return null}_updateSuggestion(){const n=this._extractSuggestion();this.setState({inputSuggestion:n||null})}connectInputWs(){const r=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal`;this._inputWs=new WebSocket(r),this._inputWs.onmessage=i=>{try{const s=JSON.parse(i.data);s.type==="data"?this._appendPtyData(s.data):s.type==="exit"&&this._clearPtyPrompt()}catch{}},this._inputWs.onclose=()=>{setTimeout(()=>{this.splitContainerRef.current&&this.props.cliMode&&this.connectInputWs()},2e3)}}_stripAnsi(n){return n.replace(/\x1b\[[0-9;]*[A-Za-z]/g,"").replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"").replace(/\x1b[^[\]](.|$)/g,"").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g,"")}_appendPtyData(n){const r=this._stripAnsi(n);this._ptyBuffer+=r,this._ptyBuffer.length>4096&&(this._ptyBuffer=this._ptyBuffer.slice(-4096)),this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this._ptyDebounceTimer=setTimeout(()=>this._detectPrompt(),200)}_detectPrompt(){const r=this._ptyBuffer.match(/([^\n]*\?)\s*\n((?:\s*[❯>]?\s*\d+\.\s+[^\n]+\n?){2,})$/);if(r){const i=r[1].trim(),o=r[2].match(/\s*([❯>])?\s*(\d+)\.\s+([^\n]+)/g);if(o){const a=o.map(u=>{const d=u.match(/\s*([❯>])?\s*(\d+)\.\s+(.+)/);return{number:parseInt(d[2],10),text:d[3].trim(),selected:!!d[1]}}),l=this.state.ptyPrompt,c={question:i,options:a};l&&l.question===i?this.setState({ptyPrompt:c}):(this.setState(u=>{const d=u.ptyPromptHistory.slice();if(u.ptyPrompt){const h=d[d.length-1];h&&h.status==="active"&&(d[d.length-1]={...h,status:"dismissed"})}return d.push({...c,status:"active",selectedNumber:null,timestamp:new Date().toISOString()}),{ptyPrompt:c,ptyPromptHistory:d}}),this.scrollToBottom());return}}this.state.ptyPrompt&&this.setState(i=>{const s=i.ptyPromptHistory.slice(),o=s[s.length-1];return o&&o.status==="active"&&(s[s.length-1]={...o,status:"dismissed"}),{ptyPrompt:null,ptyPromptHistory:s}})}_clearPtyPrompt(){this._ptyBuffer="",this._ptyDebounceTimer&&clearTimeout(this._ptyDebounceTimer),this.state.ptyPrompt&&this.setState({ptyPrompt:null})}_snapToInitialPosition(){this.setState({terminalWidth:468,needsInitialSnap:!1}),localStorage.setItem("cc-viewer-terminal-width","468")}render(){const{mainAgentSessions:n,cliMode:r,terminalVisible:i}=this.props,{allItems:s,visibleCount:o,loading:a,terminalWidth:l}=this.state,c=!n||n.length===0;if(c&&!r)return y.jsx("div",{className:jn.centerEmpty,children:y.jsx(vs,{description:ae("ui.noChat")})});if(a&&!r)return y.jsx("div",{className:jn.centerEmpty,children:y.jsx(qa,{size:"large"})});const u=this._scrollTargetIdx,{highlightTs:d,highlightFading:h}=this.state,p=d&&this._tsItemMap&&this._tsItemMap[d]!=null?this._tsItemMap[d]:null,g=s.slice(0,o),{pendingInput:v,stickyBottom:$,ptyPromptHistory:S}=this.state,_=r&&v?y.jsx(il,{role:"user",text:v,timestamp:new Date().toISOString(),userProfile:this.props.userProfile},"pending-input"):null,Q=$?null:y.jsxs("button",{className:jn.stickyBottomBtn,onClick:this.handleStickToBottom,children:[y.jsx("span",{children:ae("ui.stickyBottom")}),y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:y.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),x=r&&S.length>0?S.map((T,z)=>{const X=T.status==="active",A=T.status==="answered";return y.jsxs("div",{className:`${jn.ptyPromptBubble}${X?"":" "+jn.ptyPromptResolved}`,children:[y.jsx("div",{className:jn.ptyPromptQuestion,children:T.question}),y.jsx("div",{className:jn.ptyPromptOptions,children:T.options.map(I=>{const E=A&&T.selectedNumber===I.number;let k=jn.ptyPromptOption;return X&&I.selected&&(k=jn.ptyPromptOptionPrimary),E&&(k=jn.ptyPromptOptionChosen),!X&&!E&&(k=jn.ptyPromptOptionDimmed),y.jsxs("button",{className:k,disabled:!X,onClick:X?()=>this.handlePromptOptionClick(I.number):void 0,children:[I.number,". ",I.text]},I.number)})})]},`pty-prompt-${z}`)}):null,w=Cr&&this._mobileSliceOffset>0?y.jsx("div",{className:jn.loadMoreWrap,children:y.jsx("button",{className:jn.loadMoreBtn,onClick:this.handleLoadMore,children:ae("ui.loadMoreHistory",{count:this._mobileSliceOffset})})}):null,C=c||a?y.jsxs("div",{className:jn.messageListWrap,children:[y.jsxs("div",{ref:this.containerRef,className:jn.container,children:[!r||a?y.jsx("div",{className:jn.centerEmpty,children:a?y.jsx(qa,{size:"large"}):y.jsx(vs,{description:ae("ui.noChat")})}):null,_,x]}),Q]}):y.jsxs("div",{className:jn.messageListWrap,children:[y.jsxs("div",{ref:this.containerRef,className:jn.container,children:[w,g.map((T,z)=>{const X=z===u,A=z===p;let I=T;return A&&(I=ne.cloneElement(I,{highlight:h?"fading":"active"})),X?y.jsx("div",{ref:this._scrollTargetRef,children:I},T.key+"-anchor"):I}),_,x]}),Q]});return r?y.jsxs("div",{ref:this.splitContainerRef,className:jn.splitContainer,children:[y.jsxs("div",{className:jn.navSidebar,children:[y.jsx("button",{className:this.state.fileExplorerOpen?jn.navBtnActive:jn.navBtn,onClick:()=>{this._setFileExplorerOpen(!this.state.fileExplorerOpen),this.setState({gitChangesOpen:!1})},title:ae("ui.fileExplorer"),children:y.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:y.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 2h9a2 2 0 0 1 2 2z"})})}),y.jsx("button",{className:this.state.gitChangesOpen?jn.navBtnActive:jn.navBtn,onClick:()=>this.setState(T=>(this._setFileExplorerOpen(!1),{gitChangesOpen:!T.gitChangesOpen})),title:ae("ui.gitChanges"),children:y.jsx("svg",{width:"24",height:"24",viewBox:"0 0 1024 1024",fill:"currentColor",children:y.jsx("path",{d:"M759.53332137 326.35000897c0-48.26899766-39.4506231-87.33284994-87.87432908-86.6366625-46.95397689 0.69618746-85.08957923 39.14120645-85.39899588 86.09518335-0.23206249 40.68828971 27.53808201 74.87882971 65.13220519 84.47074592 10.82958281 2.78474987 18.41029078 12.37666607 18.64235327 23.51566553 0.38677082 21.11768647-3.40358317 44.40128953-17.24997834 63.81718442-22.20064476 31.17372767-62.42480948 42.46743545-97.93037026 52.44612248-22.43270724 6.26568719-38.75443563 7.89012462-53.14230994 9.28249954-20.42149901 2.01120825-39.76003975 3.94506233-63.89453858 17.79145747-5.10537475 2.93945818-10.13339535 6.18833303-14.85199928 9.74662453-4.09977063 3.09416652-9.90133285 0.15470833-9.90133286-4.95066641V302.60228095c0-9.43720788 5.26008307-18.17822829 13.69168683-22.3553531 28.69839444-14.23316598 48.42370599-43.93716454 48.19164353-78.20505872-0.38677082-48.57841433-41.15241468-87.71962076-89.730829-86.01782918C338.80402918 117.57112321 301.59667683 155.70672553 301.59667683 202.58334827c0 34.03583169 19.64795738 63.50776777 48.1916435 77.66357958 8.43160375 4.17712479 13.69168685 12.76343689 13.69168684 22.12329062v419.02750058c0 9.43720788-5.26008307 18.17822829-13.69168684 22.3553531-28.69839444 14.23316598-48.42370599 43.93716454-48.1916435 78.20505872 0.30941665 48.57841433 41.07506052 87.6422666 89.65347484 86.01782918C437.74000359 906.42887679 474.87000179 868.2159203 474.87000179 821.41665173c0-34.03583169-19.64795738-63.50776777-48.1916435-77.66357958-8.43160375-4.17712479-13.69168685-12.76343689-13.69168684-22.12329062v-14.85199926c0-32.48874844 15.39347842-63.27570528 42.00331048-81.91805854 2.39797906-1.70179159 4.95066642-3.32622901 7.50335379-4.79595812 14.92935344-8.58631209 25.91364457-9.66927037 44.09187287-11.4484161 15.62554091-1.54708326 35.04143581-3.48093734 61.65126786-10.90693699 39.06385228-10.98429114 92.51557887-25.91364457 124.84961898-71.39789238 18.56499911-26.06835292 27.38337367-58.01562219 26.37776956-95.14562041-0.15470833-5.33743724-0.54147915-10.67487447-1.08295828-16.16702004-0.85089578-8.27689543 2.70739569-16.24437421 9.12779121-21.50445729 19.57060322-15.78024923 32.02462345-39.99210223 32.02462345-67.14341343zM351.1033411 202.58334827c0-20.49885317 16.63114503-37.12999821 37.1299982-37.1299982s37.12999821 16.63114503 37.12999821 37.1299982-16.63114503 37.12999821-37.12999821 37.1299982-37.12999821-16.63114503-37.1299982-37.1299982z m74.25999641 618.83330346c0 20.49885317-16.63114503 37.12999821-37.12999821 37.1299982s-37.12999821-16.63114503-37.1299982-37.1299982 16.63114503-37.12999821 37.1299982-37.1299982 37.12999821 16.63114503 37.12999821 37.1299982z m247.53332139-457.93664456c-20.49885317 0-37.12999821-16.63114503-37.1299982-37.1299982s16.63114503-37.12999821 37.1299982-37.12999821 37.12999821 16.63114503 37.1299982 37.12999821-16.63114503 37.12999821-37.1299982 37.1299982z"})})})]}),y.jsxs("div",{style:{flex:1,display:"flex",minWidth:0,position:"relative"},ref:this.innerSplitRef,children:[this.state.isDragging&&this.state.activeSnapLine&&(()=>{const T=this.innerSplitRef.current;if(!T)return null;const A=T.getBoundingClientRect().width-this.state.terminalWidth-5,I=this.state.activeSnapLine.linePosition,E=Math.min(A,I),k=Math.abs(I-A);return y.jsx("div",{className:jn.snapPreview,style:{left:`${E}px`,width:`${k}px`}})})(),this.state.isDragging&&(()=>{const T=this.innerSplitRef.current;if(!T)return null;const A=T.getBoundingClientRect().width-this.state.terminalWidth-5,I=[...this.state.snapLines].map(R=>({...R,dist:Math.abs(R.linePosition-A)})).sort((R,M)=>R.dist-M.dist);if(I.length===0)return null;const E=I[0],k=this.state.activeSnapLine&&this.state.activeSnapLine.cols===E.cols;return y.jsx("div",{className:k?jn.snapLineActive:jn.snapLine,style:{left:`${E.linePosition}px`}},E.cols)})(),this.state.fileExplorerOpen&&y.jsx(G2e,{refreshTrigger:this.state.fileExplorerRefresh,onClose:()=>this._setFileExplorerOpen(!1),onFileClick:T=>this.setState({currentFile:T,currentGitDiff:null,scrollToLine:null}),expandedPaths:this.state.fileExplorerExpandedPaths,onToggleExpand:this.handleToggleExpandPath,currentFile:this.state.currentFile}),this.state.gitChangesOpen&&y.jsx(mAe,{refreshTrigger:this.state.gitChangesRefresh,onClose:()=>this.setState({gitChangesOpen:!1}),onFileClick:T=>this.setState({currentGitDiff:T,currentFile:null})}),y.jsx("div",{className:jn.chatSection,style:{flex:1,minWidth:0,display:"flex"},children:y.jsxs("div",{style:{flex:1,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden",position:"relative"},children:[this.state.currentGitDiff&&y.jsx("div",{style:{position:"absolute",inset:0,zIndex:1,display:"flex",flexDirection:"column"},children:y.jsx(JWe,{filePath:this.state.currentGitDiff,onClose:()=>this.setState({currentGitDiff:null}),onOpenFile:(T,z)=>{this._setFileExplorerOpen(!0),this.setState({currentGitDiff:null,currentFile:T,scrollToLine:z||1,gitChangesOpen:!1})}})}),this.state.currentFile&&y.jsx("div",{style:{position:"absolute",inset:0,zIndex:1,display:"flex",flexDirection:"column"},children:NVe(this.state.currentFile)?y.jsx(DLe,{filePath:this.state.currentFile,editorSession:!!this.state.editorSessionId,onClose:()=>{this.state.editorSessionId&&fetch("/api/editor-done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:this.state.editorSessionId})}).catch(()=>{}),this.setState({currentFile:null,fileVersion:0,editorSessionId:null,editorFilePath:null})}},this.state.fileVersion):y.jsx(PLe,{filePath:this.state.currentFile,scrollToLine:this.state.scrollToLine,editorSession:!!this.state.editorSessionId,onClose:()=>{this.state.editorSessionId&&fetch("/api/editor-done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:this.state.editorSessionId})}).catch(()=>{}),this.setState({currentFile:null,fileVersion:0,editorSessionId:null,editorFilePath:null})}},this.state.fileVersion)}),C,!i&&y.jsxs("div",{className:jn.chatInputBar,children:[y.jsxs("div",{className:jn.chatInputWrapper,children:[y.jsxs("div",{className:jn.chatTextareaWrap,children:[y.jsx("textarea",{ref:this._inputRef,className:jn.chatTextarea,placeholder:this.state.inputSuggestion?"":ae("ui.chatInput.placeholder"),rows:1,onKeyDown:this.handleInputKeyDown,onInput:this.handleInputChange}),this.state.inputSuggestion&&this.state.inputEmpty&&y.jsx("div",{className:jn.ghostText,children:this.state.inputSuggestion})]}),y.jsx("div",{className:jn.chatInputHint,children:this.state.inputSuggestion&&this.state.inputEmpty?ae("ui.chatInput.hintTab"):ae("ui.chatInput.hintEnter")})]}),!Cr&&y.jsx("button",{className:jn.chatSendBtn,onClick:()=>{const T=document.createElement("input");T.type="file",T.onchange=async z=>{var A;const X=(A=z.target.files)==null?void 0:A[0];if(X)try{const E=`"${await wY(X)}"`,k=this._inputRef.current;k&&(k.value=(k.value?k.value+" ":"")+E,k.dispatchEvent(new Event("input",{bubbles:!0})),this.setState({inputEmpty:!1}))}catch(I){console.error("[CC Viewer] Upload failed:",I)}},T.click()},title:ae("ui.terminal.upload"),children:y.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),y.jsx("polyline",{points:"17 8 12 3 7 8"}),y.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),y.jsx("button",{className:jn.chatSendBtn,onClick:this.handleInputSend,disabled:this.state.inputEmpty,title:ae("ui.chatInput.send"),children:y.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),y.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),i&&this.state.inputSuggestion&&y.jsxs("div",{className:jn.suggestionChip,onClick:this.handleSuggestionToTerminal,children:[y.jsx("span",{className:jn.suggestionChipText,children:this.state.inputSuggestion}),y.jsx("span",{className:jn.suggestionChipAction,children:"↵"})]})]})}),i&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:jn.vResizer,onMouseDown:this.handleSplitMouseDown}),y.jsx("div",{style:{width:l,flexShrink:0,minWidth:200,display:"flex",flexDirection:"column"},children:y.jsx(PY,{onEditorOpen:(T,z)=>{this.setState({editorSessionId:T,editorFilePath:z,currentFile:z,currentGitDiff:null,scrollToLine:null,fileVersion:(this.state.fileVersion||0)+1})},onFilePath:T=>{const z=`"${T}"`;this._inputWs&&this._inputWs.readyState===WebSocket.OPEN&&this._inputWs.send(JSON.stringify({type:"input",data:z}))}})})]})]})]}):C}}const YVe="_resizer_yamj2_1",BVe={resizer:YVe};class qVe extends ne.Component{constructor(e){super(e),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this)}handleMouseDown(e){e.preventDefault(),document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(e){this.props.onResize&&this.props.onResize(e.clientX)}handleMouseUp(){document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}componentWillUnmount(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}render(){return y.jsx("div",{onMouseDown:this.handleMouseDown,className:BVe.resizer})}}const UVe="_container_1um1r_1",DVe="_fileListSection_1um1r_10",ZVe="_header_1um1r_19",GVe="_headerTitle_1um1r_28",FVe="_fileCount_1um1r_36",HVe="_changesContainer_1um1r_44",KVe="_changeItem_1um1r_51",JVe="_changeItemActive_1um1r_68",eYe="_dirItem_1um1r_77",tYe="_dirArrow_1um1r_88",nYe="_dirName_1um1r_97",rYe="_status_1um1r_102",iYe="_icon_1um1r_111",sYe="_fileName_1um1r_120",oYe="_diffSection_1um1r_127",aYe="_diffHeader_1um1r_135",lYe="_diffFilePath_1um1r_145",cYe="_diffBadge_1um1r_155",uYe="_diffContent_1um1r_167",dYe="_diffPlaceholder_1um1r_173",OYe="_statusText_1um1r_184",hYe="_errorText_1um1r_191",fYe="_emptyText_1um1r_198",pYe="_warningText_1um1r_205",Pr={container:UVe,fileListSection:DVe,header:ZVe,headerTitle:GVe,fileCount:FVe,changesContainer:HVe,changeItem:KVe,changeItemActive:JVe,dirItem:eYe,dirArrow:tYe,dirName:nYe,status:rYe,icon:iYe,fileName:sYe,diffSection:oYe,diffHeader:aYe,diffFilePath:lYe,diffBadge:cYe,diffContent:uYe,diffPlaceholder:dYe,statusText:OYe,errorText:hYe,emptyText:fYe,warningText:pYe},mYe={M:"#e2c08d",A:"#73c991",D:"#f14c4c",R:"#73c991",C:"#73c991",U:"#e2c08d","?":"#73c991","??":"#73c991"},gYe={"??":"U"},vYe={js:"#e8d44d",jsx:"#61dafb",ts:"#3178c6",tsx:"#3178c6",json:"#999",md:"#519aba",css:"#a86fd9",scss:"#cd6799",html:"#e34c26",py:"#3572a5",go:"#00add8",rs:"#dea584"};function $Ye(t){const e=t.includes(".")?t.split(".").pop().toLowerCase():"",n=vYe[e]||"#888";return y.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"1.5",children:[y.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),y.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function SYe(){return y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"#c09553",stroke:"none",children:y.jsx("path",{d:"M2 6c0-1.1.9-2 2-2h5l2 2h9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6z"})})}function bYe(t){const e={dirs:{},files:[]};for(const n of t){const r=n.file.split("/");let i=e;for(let s=0;s<r.length-1;s++)i.dirs[r[s]]||(i.dirs[r[s]]={dirs:{},files:[]}),i=i.dirs[r[s]];i.files.push({name:r[r.length-1],status:n.status,fullPath:n.file})}return e}function _Z({name:t,node:e,depth:n,selectedFile:r,onFileClick:i}){const s=Object.keys(e.dirs).sort(),o=[...e.files].sort((a,l)=>a.name.localeCompare(l.name));return y.jsxs(y.Fragment,{children:[t&&y.jsxs("div",{className:Pr.dirItem,style:{paddingLeft:8+n*16},children:[y.jsx("span",{className:Pr.dirArrow,children:y.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:"rotate(90deg)"},children:y.jsx("polyline",{points:"9 6 15 12 9 18"})})}),y.jsx("span",{className:Pr.icon,children:SYe()}),y.jsx("span",{className:Pr.dirName,children:t})]}),s.map(a=>y.jsx(_Z,{name:a,node:e.dirs[a],depth:t?n+1:n,selectedFile:r,onFileClick:i},a)),o.map(a=>y.jsxs("div",{className:`${Pr.changeItem} ${r===a.fullPath?Pr.changeItemActive:""}`,style:{paddingLeft:8+(t?n+1:n)*16},onClick:()=>i&&i(a.fullPath),children:[y.jsx("span",{className:Pr.icon,children:$Ye(a.name)}),y.jsx("span",{className:Pr.fileName,children:a.name}),y.jsx("span",{className:Pr.status,style:{color:mYe[a.status]||"#888"},children:gYe[a.status]||a.status})]},a.fullPath))]})}function yYe({visible:t}){const[e,n]=f.useState(null),[r,i]=f.useState(null),[s,o]=f.useState(!0),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(null),[p,g]=f.useState(!1),v=f.useRef(!0);return f.useEffect(()=>{if(v.current=!0,!!t)return o(!0),i(null),fetch(Ln("/api/git-status")).then($=>$.ok?$.json():Promise.reject()).then($=>{v.current&&(n($.changes||[]),o(!1))}).catch(()=>{v.current&&(i("Failed to load git status"),o(!1))}),()=>{v.current=!1}},[t]),f.useEffect(()=>{if(!a){u(null),h(null);return}g(!0),u(null),h(null),fetch(Ln(`/api/git-diff?files=${encodeURIComponent(a)}`)).then($=>{if(!$.ok)throw new Error(`HTTP ${$.status}`);return $.json()}).then($=>{v.current&&($.diffs&&$.diffs[0]?u($.diffs[0]):h("No diff data available"),g(!1))}).catch($=>{v.current&&(h(`${ae("ui.fileLoadError")}: ${$.message}`),g(!1))})},[a]),y.jsxs("div",{className:Pr.container,children:[y.jsxs("div",{className:Pr.fileListSection,children:[y.jsxs("div",{className:Pr.header,children:[y.jsx("span",{className:Pr.headerTitle,children:ae("ui.gitChanges")}),y.jsx("span",{className:Pr.fileCount,children:e?e.length:0})]}),y.jsxs("div",{className:Pr.changesContainer,children:[s&&y.jsx("div",{className:Pr.statusText,children:"Loading..."}),r&&y.jsx("div",{className:Pr.errorText,children:r}),!s&&!r&&e&&e.length===0&&y.jsx("div",{className:Pr.emptyText,children:"No changes"}),!s&&!r&&e&&e.length>0&&y.jsx(_Z,{name:"",node:bYe(e),depth:0,selectedFile:a,onFileClick:l})]})]}),y.jsx("div",{className:Pr.diffSection,children:a?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:Pr.diffHeader,children:[y.jsx("span",{className:Pr.diffFilePath,children:a}),y.jsx("span",{className:Pr.diffBadge,children:"DIFF"})]}),y.jsxs("div",{className:Pr.diffContent,children:[p&&y.jsx("div",{className:Pr.statusText,children:ae("ui.loading")}),d&&y.jsx("div",{className:Pr.errorText,children:d}),!p&&!d&&c&&y.jsx(y.Fragment,{children:c.is_large?y.jsxs("div",{className:Pr.warningText,children:[y.jsx("p",{children:ae("ui.largeFileWarning")}),y.jsxs("p",{style:{color:"#888",fontSize:12},children:[ae("ui.fileSize"),": ",(c.size/(1024*1024)).toFixed(2)," MB"]})]}):c.is_binary?y.jsx("div",{className:Pr.statusText,style:{fontStyle:"italic"},children:ae("ui.binaryFileNotice")}):y.jsx(yZ,{file_path:a,old_string:c.old_content,new_string:c.new_content})})]})]}):y.jsxs("div",{className:Pr.diffPlaceholder,children:[y.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"#333",strokeWidth:"1.5",children:[y.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),y.jsx("circle",{cx:"18",cy:"6",r:"3"}),y.jsx("circle",{cx:"6",cy:"18",r:"3"}),y.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),y.jsx("span",{children:ae("ui.mobileGitDiffHint")})]})})]})}const _Ye="_container_rkahp_1",QYe="_header_rkahp_9",xYe="_headerTitle_rkahp_18",wYe="_closeBtn_rkahp_24",PYe="_content_rkahp_38",CYe="_empty_rkahp_47",TYe="_fixedTable_rkahp_54",kYe="_ellipsisCell_rkahp_58",su={container:_Ye,header:QYe,headerTitle:xYe,closeBtn:wYe,content:PYe,empty:CYe,fixedTable:TYe,ellipsisCell:kYe},RYe=["ttl","system_change","tools_change","model_change","msg_truncated","msg_modified","key_change"],gj={ttl:"cacheLoss.ttl",system_change:"cacheLoss.systemChange",tools_change:"cacheLoss.toolsChange",model_change:"cacheLoss.modelChange",msg_truncated:"cacheLoss.msgTruncated",msg_modified:"cacheLoss.msgModified",key_change:"cacheLoss.keyChange"};function EYe({requests:t=[],visible:e,onClose:n}){if(!e)return null;const{byModel:r,models:i,toolStats:s,skillStats:o,cacheStats:a,activeReasons:l,totalCount:c,totalCache:u,hasCacheStats:d,subAgentEntries:h,hasSubAgentStats:p,isEmpty:g}=f.useMemo(()=>{const v=XW(t),$=Object.keys(v),S=MW(t),_=jW(t),Q=zW(t),x=RYe.filter(E=>Q[E].count>0),w=x.reduce((E,k)=>E+Q[k].count,0),C=x.reduce((E,k)=>E+Q[k].cacheCreate,0),T=x.length>0,z={};for(let E=0;E<t.length;E++){const k=Id(t[E],t[E+1]);if(k.type==="SubAgent"){const R=k.subType||"Other";z[R]=(z[R]||0)+1}}const X=Object.entries(z).sort((E,k)=>k[1]-E[1]),A=X.length>0,I=$.length===0&&S.length===0&&!T&&!A&&_.length===0;return{byModel:v,models:$,toolStats:S,skillStats:_,cacheStats:Q,activeReasons:x,totalCount:w,totalCache:C,hasCacheStats:T,subAgentEntries:X,hasSubAgentStats:A,isEmpty:I}},[t]);return y.jsxs("div",{className:su.container,children:[y.jsxs("div",{className:su.header,children:[y.jsx("span",{className:su.headerTitle,children:ae("ui.tokenStats")}),y.jsx("button",{className:su.closeBtn,onClick:n,children:y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[y.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),y.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),y.jsx("div",{className:su.content,children:g?y.jsx("div",{className:su.empty,children:"—"}):y.jsxs(y.Fragment,{children:[o.length>0&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.skillUsageStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"Skill"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[o.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label,children:v}),y.jsx("td",{className:pe.td,children:$})]},v)),o.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:o.reduce((v,$)=>v+$[1],0)})]})]})]})]}),p&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.subAgentStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"SubAgent"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[h.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label,children:v}),y.jsx("td",{className:pe.td,children:$})]},v)),h.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:h.reduce((v,$)=>v+$[1],0)})]})]})]})]}),s.length>0&&y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:ae("ui.toolUsageStats")}),y.jsxs("table",{className:pe.statsTable,children:[y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:"Tool"}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")})]})}),y.jsxs("tbody",{children:[s.map(([v,$])=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsxs("td",{className:pe.label,children:[v," ",y.jsx(bc,{doc:`Tool-${v}`})]}),y.jsx("td",{className:pe.td,children:$})]},v)),s.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:s.reduce((v,$)=>v+$[1],0)})]})]})]})]}),d&&y.jsxs("div",{className:pe.modelCard,children:[y.jsxs("div",{className:pe.modelName,children:["MainAgent",y.jsx(bc,{doc:"MainAgent"})," ",ae("ui.cacheRebuildStats"),y.jsx(bc,{doc:"CacheRebuild"})]}),y.jsxs("table",{className:`${pe.statsTable} ${su.fixedTable}`,children:[y.jsxs("colgroup",{children:[y.jsx("col",{style:{width:"50%"}}),y.jsx("col",{style:{width:"25%"}}),y.jsx("col",{style:{width:"25%"}})]}),y.jsx("thead",{children:y.jsxs("tr",{children:[y.jsx("td",{className:pe.th,style:{textAlign:"left"},children:ae("ui.cacheRebuild.reason")}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.count")}),y.jsx("td",{className:pe.th,children:ae("ui.cacheRebuild.cacheCreate")})]})}),y.jsxs("tbody",{children:[l.map(v=>y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:`${pe.label} ${su.ellipsisCell}`,title:ae(`ui.${gj[v]}`),children:ae(`ui.${gj[v]}`)}),y.jsx("td",{className:pe.td,children:a[v].count}),y.jsx("td",{className:pe.td,children:Er(a[v].cacheCreate)})]},v)),l.length>1&&y.jsxs("tr",{className:pe.rebuildTotalRow,children:[y.jsx("td",{className:pe.label,children:"Total"}),y.jsx("td",{className:pe.td,children:c}),y.jsx("td",{className:pe.td,children:Er(u)})]})]})]})]}),i.map(v=>{const $=r[v],S=$.input+$.cacheCreation+$.cacheRead,_=S>0?($.cacheRead/S*100).toFixed(1):"0.0";return y.jsxs("div",{className:pe.modelCard,children:[y.jsx("div",{className:pe.modelName,children:v}),y.jsx("table",{className:pe.statsTable,children:y.jsxs("tbody",{children:[y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:"Token"}),y.jsx("td",{className:pe.th,children:"input"}),y.jsx("td",{className:pe.th,children:"output"})]}),y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label}),y.jsx("td",{className:pe.td,children:Er(S)}),y.jsx("td",{className:pe.td,children:Er($.output)})]}),y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:"Cache"}),y.jsx("td",{className:pe.th,children:"create"}),y.jsx("td",{className:pe.th,children:"read"})]}),y.jsxs("tr",{className:pe.rowBorder,children:[y.jsx("td",{className:pe.label}),y.jsx("td",{className:pe.td,children:Er($.cacheCreation)}),y.jsx("td",{className:pe.td,children:Er($.cacheRead)})]}),y.jsxs("tr",{children:[y.jsx("td",{className:pe.label,children:ae("ui.hitRate")}),y.jsxs("td",{colSpan:2,className:pe.td,children:[_,"%"]})]})]})})]},v)})]})})]})}const{Text:xd,Title:XYe}=Ga;function zYe(t){if(!t)return"0 B";const e=["B","KB","MB","GB"];let n=0,r=t;for(;r>=1024&&n<e.length-1;)r/=1024,n++;return`${r.toFixed(n>0?1:0)} ${e[n]}`}function MYe(t){if(!t)return"";const e=Date.now()-new Date(t).getTime(),n=Math.floor(e/6e4);if(n<1)return ae("ui.workspaces.justNow");if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function jYe({open:t,onClose:e,onSelect:n}){const[r,i]=f.useState(""),[s,o]=f.useState(null),[a,l]=f.useState([]),[c,u]=f.useState(!1),[d,h]=f.useState(""),p=f.useCallback(v=>{u(!0);const $=v?`/api/browse-dir?path=${encodeURIComponent(v)}`:"/api/browse-dir";fetch(Ln($)).then(S=>S.json()).then(S=>{S.error?vr.error(S.error):(i(S.current),o(S.parent),l(S.dirs||[]),h(S.current)),u(!1)}).catch(()=>{vr.error("Failed to browse directory"),u(!1)})},[]);f.useEffect(()=>{t&&p("")},[t,p]);const g=()=>{const v=d.trim();v&&p(v)};return y.jsxs(Ti,{title:ae("ui.workspaces.selectDir"),open:t,onCancel:e,footer:null,width:600,styles:{body:{padding:"12px 0"}},children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"0 16px 10px",borderBottom:"1px solid #2a2a2a"},children:[y.jsx(yn,{type:"text",icon:y.jsx(mve,{}),disabled:!s,onClick:()=>s&&p(s),size:"small"}),y.jsxs(xd,{style:{color:"#e0e0e0",fontSize:13,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[y.jsx(t1,{style:{marginRight:6,color:"#1668dc"}}),r]})]}),y.jsx("div",{style:{maxHeight:400,overflowY:"auto",padding:"4px 0"},children:c?y.jsx("div",{style:{textAlign:"center",padding:40},children:y.jsx(qa,{})}):a.length===0?y.jsx("div",{style:{textAlign:"center",padding:40},children:y.jsx(xd,{type:"secondary",children:ae("ui.workspaces.emptyDir")})}):a.map(v=>y.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",cursor:"pointer",transition:"background 0.15s"},onMouseEnter:$=>$.currentTarget.style.background="#1a1a1a",onMouseLeave:$=>$.currentTarget.style.background="transparent",children:[y.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0},onClick:()=>p(v.path),children:[y.jsx(oW,{style:{color:v.hasGit?"#1668dc":"#666",fontSize:16,flexShrink:0}}),y.jsx(xd,{style:{color:"#d0d0d0",fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),v.hasGit&&y.jsxs(eo,{color:"blue",style:{fontSize:11,lineHeight:"18px",padding:"0 4px",margin:0,flexShrink:0},children:[y.jsx(vW,{style:{marginRight:2}}),"git"]})]}),y.jsx(yn,{type:"primary",size:"small",onClick:$=>{$.stopPropagation(),n(v.path)},children:ae("ui.workspaces.select")})]},v.path))}),y.jsxs("div",{style:{borderTop:"1px solid #2a2a2a",padding:"10px 16px 4px",display:"flex",flexDirection:"column",gap:8},children:[y.jsxs(yn,{type:"primary",ghost:!0,block:!0,icon:y.jsx(t1,{}),onClick:()=>n(r),children:[ae("ui.workspaces.selectCurrent")," — ",r.split("/").pop()||r]}),y.jsxs("div",{style:{display:"flex",gap:8},children:[y.jsx(Kd,{size:"small",value:d,onChange:v=>h(v.target.value),onPressEnter:g,placeholder:ae("ui.workspaces.pathPlaceholder"),style:{flex:1}}),y.jsx(yn,{size:"small",onClick:g,children:ae("ui.workspaces.goTo")})]})]})]})}function NYe({onLaunch:t}){const[e,n]=f.useState([]),[r,i]=f.useState(!0),[s,o]=f.useState(null),[a,l]=f.useState(!1),c=()=>{fetch(Ln("/api/workspaces")).then(p=>p.json()).then(p=>{n(p.workspaces||[]),i(!1)}).catch(()=>i(!1))};f.useEffect(()=>{c()},[]);const u=p=>{l(!1),fetch(Ln("/api/workspaces/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p})}).then(g=>g.json()).then(g=>{g.error?vr.error(g.error):c()}).catch(()=>vr.error("Failed to add workspace"))},d=p=>{fetch(Ln(`/api/workspaces/${p}`),{method:"DELETE"}).then(g=>g.json()).then(()=>c()).catch(()=>{})},h=p=>{o(p.id),fetch(Ln("/api/workspaces/launch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p.path})}).then(g=>g.json()).then(g=>{g.error?(vr.error(g.error),o(null)):t({projectName:g.projectName,path:p.path})}).catch(()=>{vr.error("Launch failed"),o(null)})};return y.jsxs("div",{style:{minHeight:"100vh",background:"#0a0a0a",display:"flex",justifyContent:"center",paddingTop:60},children:[y.jsxs("div",{style:{width:"100%",maxWidth:720,padding:"0 24px"},children:[y.jsxs("div",{style:{marginBottom:32,textAlign:"center"},children:[y.jsxs(XYe,{level:3,style:{color:"#e0e0e0",margin:0},children:[y.jsx(t1,{style:{marginRight:8,color:"#1668dc"}}),ae("ui.workspaces.title")]}),y.jsx(xd,{type:"secondary",style:{fontSize:13},children:ae("ui.workspaces.subtitle")})]}),y.jsx("div",{style:{marginBottom:20,textAlign:"center"},children:y.jsx(yn,{type:"primary",icon:y.jsx(H$,{}),onClick:()=>l(!0),size:"large",children:ae("ui.workspaces.browse")})}),r?y.jsx("div",{style:{textAlign:"center",padding:60},children:y.jsx(qa,{})}):e.length===0?y.jsx(vs,{description:y.jsx(xd,{type:"secondary",children:ae("ui.workspaces.empty")}),style:{marginTop:60}}):y.jsx(e1,{dataSource:e,renderItem:p=>y.jsx(jT,{size:"small",style:{marginBottom:10,background:"#141414",borderColor:"#2a2a2a",cursor:"pointer"},hoverable:!0,onClick:()=>h(p),children:y.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[y.jsxs("div",{style:{flex:1,minWidth:0},children:[y.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:y.jsx(xd,{strong:!0,style:{color:"#e0e0e0",fontSize:15},children:p.projectName})}),y.jsx(xd,{type:"secondary",style:{fontSize:12,wordBreak:"break-all"},children:p.path}),y.jsxs("div",{style:{display:"flex",gap:16,marginTop:6,fontSize:12,color:"#666"},children:[y.jsxs("span",{children:[y.jsx(Rde,{style:{marginRight:4}}),MYe(p.lastUsed)]}),p.logCount>0&&y.jsxs("span",{children:[y.jsx(Pve,{style:{marginRight:4}}),p.logCount," logs (",zYe(p.totalSize),")"]})]})]}),y.jsxs(bl,{children:[y.jsx(yn,{type:"primary",icon:y.jsx(Ave,{}),loading:s===p.id,onClick:g=>{g.stopPropagation(),h(p)},children:ae("ui.workspaces.open")}),y.jsx(IA,{title:ae("ui.workspaces.confirmRemove"),onConfirm:g=>{g==null||g.stopPropagation(),d(p.id)},onCancel:g=>g==null?void 0:g.stopPropagation(),okText:"Yes",cancelText:"No",children:y.jsx(yn,{type:"text",danger:!0,icon:y.jsx(r1,{}),onClick:g=>g.stopPropagation()})})]})]})},p.id)})]}),y.jsx(jYe,{open:a,onClose:()=>l(!1),onSelect:u})]})}const IYe="_layout_1ir1q_1",LYe="_header_1ir1q_6",AYe="_content_1ir1q_14",WYe="_mainContainer_1ir1q_19",VYe="_leftPanel_1ir1q_24",YYe="_leftPanelHeader_1ir1q_32",BYe="_leftPanelCount_1ir1q_43",qYe="_leftPanelBody_1ir1q_49",UYe="_rightPanel_1ir1q_54",DYe="_modalActions_1ir1q_60",ZYe="_spinCenter_1ir1q_64",GYe="_emptyCenter_1ir1q_69",FYe="_logListContainer_1ir1q_79",HYe="_loadingOverlay_1ir1q_127",KYe="_loadingText_1ir1q_140",JYe="_mobileLoadingOverlay_1ir1q_146",eBe="_mobileLoadingSpinner_1ir1q_158",tBe="_mobileLoadingLabel_1ir1q_171",nBe="_footer_1ir1q_177",rBe="_footerRight_1ir1q_188",iBe="_footerText_1ir1q_196",sBe="_footerLink_1ir1q_201",oBe="_footerIcon_1ir1q_213",aBe="_footerDivider_1ir1q_218",lBe="_guideContainer_1ir1q_226",cBe="_guideContent_1ir1q_234",uBe="_guideTitle_1ir1q_239",dBe="_guideStep_1ir1q_246",OBe="_guideStepNum_1ir1q_252",hBe="_guideStepBody_1ir1q_267",fBe="_guideText_1ir1q_272",pBe="_guideCode_1ir1q_279",mBe="_mobileChatOverlay_1ir1q_292",gBe="_mobileChatOverlayVisible_1ir1q_304",vBe="_mobileChatInner_1ir1q_308",$Be="_mobileGitDiffOverlay_1ir1q_316",SBe="_mobileGitDiffOverlayVisible_1ir1q_328",bBe="_mobileGitDiffInner_1ir1q_332",yBe="_mobileMenuBtn_1ir1q_340",_Be="_mobileMenuOverlay_1ir1q_357",QBe="_mobileMenuDropdown_1ir1q_363",xBe="_mobileMenuItem_1ir1q_377",wBe="_mobileStatsOverlay_1ir1q_395",PBe="_mobileStatsOverlayVisible_1ir1q_407",CBe="_mobileStatsInner_1ir1q_411",TBe="_mobileLogMgmtOverlay_1ir1q_418",kBe="_mobileLogMgmtOverlayVisible_1ir1q_430",RBe="_mobileLogMgmtHeader_1ir1q_434",EBe="_mobileLogMgmtTitle_1ir1q_443",XBe="_mobileLogMgmtClose_1ir1q_449",zBe="_mobileLogMgmtActions_1ir1q_464",MBe="_mobileLogMgmtBody_1ir1q_472",jBe="_mobileSettingsOverlay_1ir1q_479",NBe="_mobileSettingsOverlayVisible_1ir1q_491",IBe="_mobilePromptOverlay_1ir1q_495",LBe="_mobilePromptOverlayVisible_1ir1q_507",ABe="_mobilePromptBody_1ir1q_511",WBe="_mobilePromptList_1ir1q_519",VBe="_mobilePromptItem_1ir1q_525",YBe="_mobilePromptTimestamp_1ir1q_530",BBe="_mobilePromptCard_1ir1q_537",qBe="_mobilePromptPreText_1ir1q_545",Qt={layout:IYe,header:LYe,content:AYe,mainContainer:WYe,leftPanel:VYe,leftPanelHeader:YYe,leftPanelCount:BYe,leftPanelBody:qYe,rightPanel:UYe,modalActions:DYe,spinCenter:ZYe,emptyCenter:GYe,logListContainer:FYe,loadingOverlay:HYe,loadingText:KYe,mobileLoadingOverlay:JYe,mobileLoadingSpinner:eBe,mobileLoadingLabel:tBe,footer:nBe,footerRight:rBe,footerText:iBe,footerLink:sBe,footerIcon:oBe,footerDivider:aBe,guideContainer:lBe,guideContent:cBe,guideTitle:uBe,guideStep:dBe,guideStepNum:OBe,guideStepBody:hBe,guideText:fBe,guideCode:pBe,mobileChatOverlay:mBe,mobileChatOverlayVisible:gBe,mobileChatInner:vBe,mobileGitDiffOverlay:$Be,mobileGitDiffOverlayVisible:SBe,mobileGitDiffInner:bBe,mobileMenuBtn:yBe,mobileMenuOverlay:_Be,mobileMenuDropdown:QBe,mobileMenuItem:xBe,mobileStatsOverlay:wBe,mobileStatsOverlayVisible:PBe,mobileStatsInner:CBe,mobileLogMgmtOverlay:TBe,mobileLogMgmtOverlayVisible:kBe,mobileLogMgmtHeader:RBe,mobileLogMgmtTitle:EBe,mobileLogMgmtClose:XBe,mobileLogMgmtActions:zBe,mobileLogMgmtBody:MBe,mobileSettingsOverlay:jBe,mobileSettingsOverlayVisible:NBe,mobilePromptOverlay:IBe,mobilePromptOverlayVisible:LBe,mobilePromptBody:ABe,mobilePromptList:WBe,mobilePromptItem:VBe,mobilePromptTimestamp:YBe,mobilePromptCard:BBe,mobilePromptPreText:qBe},UBe="ccv_entryCache",Iu="entries",W5="cache",V5="ccv_cacheMeta",DBe=1,ZBe=10080*60*1e3;let qO=null,UO=null;function Y5(){return qO?Promise.resolve(qO):UO||(UO=new Promise((t,e)=>{const n=indexedDB.open(UBe,DBe);n.onupgradeneeded=()=>{const r=n.result;r.objectStoreNames.contains(Iu)||r.createObjectStore(Iu)},n.onsuccess=()=>{qO=n.result,qO.onclose=()=>{qO=null},UO=null,t(qO)},n.onerror=()=>{UO=null,e(n.error)}}),UO)}let vj=0;function GBe(t,e){try{const n=e[e.length-1],r=(n==null?void 0:n.timestamp)||null;r&&localStorage.setItem(V5,JSON.stringify({projectName:t,lastTs:r,count:e.length}))}catch{}}function FBe(){try{localStorage.removeItem(V5)}catch{}}function HBe(){try{const t=localStorage.getItem(V5);if(!t)return null;const e=JSON.parse(t);return e!=null&&e.lastTs&&(e==null?void 0:e.count)>0&&(e!=null&&e.projectName)?e:null}catch{return null}}async function Zx(t,e){if(!t||!Array.isArray(e)||e.length===0)return;const n=++vj;try{const r=await Y5();return n!==vj?void 0:(GBe(t,e),new Promise(i=>{const s=r.transaction(Iu,"readwrite");s.objectStore(Iu).put({projectName:t,entries:e,ts:Date.now()},W5),s.oncomplete=()=>i(),s.onerror=()=>i()}))}catch{}}async function KBe(t){try{const e=await Y5();return new Promise(n=>{const i=e.transaction(Iu,"readonly").objectStore(Iu).get(W5);i.onsuccess=()=>{const s=i.result;!s||s.projectName!==t||!Array.isArray(s.entries)||s.entries.length===0?n(null):s.ts&&Date.now()-s.ts>ZBe?(j2(),n(null)):n(s.entries)},i.onerror=()=>n(null)})}catch{return null}}async function j2(){FBe();try{const t=await Y5();return new Promise(e=>{const n=t.transaction(Iu,"readwrite");n.objectStore(Iu).delete(W5),n.oncomplete=()=>e(),n.onerror=()=>e()})}catch{}}const hh=class hh extends ne.Component{constructor(n){super(n);Rt(this,"handleSelectRequest",n=>{this.setState({selectedIndex:n,scrollCenter:!1})});Rt(this,"handleViewRequest",n=>{this.setState({viewMode:"raw",selectedIndex:n,scrollCenter:!0})});Rt(this,"handleViewInChat",()=>{this.setState(n=>{const i=(n.showAll?n.requests:Ra(n.requests))[n.selectedIndex];if(!i)return null;let s=null;if(Ii(i)&&i.timestamp)s=i.timestamp;else{if(Id(i).type==="SubAgent"&&i.timestamp)s=i.timestamp;else{const a=n.requests.indexOf(i);a>=0&&(s=F6(n.requests,a))}s||vr.info(ae("ui.cannotMap"))}return{viewMode:"chat",chatScrollToTs:s}})});Rt(this,"handleWorkspaceLaunch",({projectName:n})=>{this._isLocalLog=!1,this._localLogFile=null,this.setState({workspaceMode:!1,projectName:n,viewMode:"chat",cliMode:!0})});Rt(this,"handleReturnToWorkspaces",()=>{fetch(Ln("/api/workspaces/stop"),{method:"POST"}).then(()=>{this.setState({workspaceMode:!0,requests:[],mainAgentSessions:[],projectName:"",selectedIndex:null})}).catch(()=>{})});Rt(this,"handleToggleViewMode",()=>{this.setState(n=>{const r=n.viewMode==="raw"?"chat":"raw";if(r==="raw"){if(n.selectedIndex===null){const o=n.showAll?n.requests:Ra(n.requests);return{viewMode:r,selectedIndex:o.length>0?o.length-1:null,scrollCenter:!0}}return{viewMode:r,scrollCenter:!0}}const i=n.showAll?n.requests:Ra(n.requests),s=n.selectedIndex!=null?i[n.selectedIndex]:null;if(s){let o=null;if(Ii(s)&&s.timestamp)o=s.timestamp;else if(Id(s).type==="SubAgent"&&s.timestamp)o=s.timestamp;else{const l=n.requests.indexOf(s);l>=0&&(o=F6(n.requests,l)),o||vr.info(ae("ui.cannotMap"))}return{viewMode:r,chatScrollToTs:o}}return{viewMode:r,chatScrollToTs:null}})});Rt(this,"handleLangChange",()=>{const n=Qm();this.setState({lang:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lang:n})}).catch(()=>{})});Rt(this,"handleCollapseToolResultsChange",n=>{this.setState({collapseToolResults:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collapseToolResults:n})}).catch(()=>{})});Rt(this,"handleExpandThinkingChange",n=>{this.setState({expandThinking:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expandThinking:n})}).catch(()=>{})});Rt(this,"handleExpandDiffChange",n=>{this.setState({expandDiff:n}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expandDiff:n})}).catch(()=>{})});Rt(this,"handleFilterIrrelevantChange",n=>{this.setState(r=>{const i=!n,s=i?r.requests:Ra(r.requests);return{showAll:i,selectedIndex:s.length>0?s.length-1:null}}),fetch(Ln("/api/preferences"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filterIrrelevant:n})}).catch(()=>{})});Rt(this,"handleExportPromptsTxt",n=>{if(!n||n.length===0)return;const r=[];for(const a of n){const l=[],c=a.timestamp?new Date(a.timestamp).toLocaleString():"";c&&l.push(`${c}:
|
|
710
710
|
`);const u=(a.segments||[]).filter(d=>d.type==="text").map(d=>d.content);u.length>0&&l.push(u.join(`
|
|
711
711
|
`)),r.push(l.join(`
|
|
712
712
|
`))}if(r.length===0)return;const i=new Blob([r.join(`
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<title>Claude Code Viewer</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico?v=1">
|
|
8
8
|
<link rel="shortcut icon" href="/favicon.ico?v=1">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-9J7-ZYIy.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-BXsgYNDX.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|