cc-viewer 1.6.28 → 1.6.29
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.
|
@@ -727,6 +727,6 @@ https://github.com/highlightjs/highlight.js/issues/2277`),En=Pe,Jt=Fe),mt===void
|
|
|
727
727
|
---
|
|
728
728
|
`).filter(g=>g.trim()).map(g=>{try{return JSON.parse(g)}catch{return null}}).filter(Boolean);a.push(...p),l.push(c.name)}catch{}o++,o===r.length&&this._finishLocalLoad(a,l)},u.readAsText(c)})},n.click()});tt(this,"_processJsonlFiles",n=>{if(!n||n.length===0)return;if(n.reduce((a,l)=>a+l.size,0)>500*1024*1024){Tn.error(J("ui.fileTooLarge"));return}this.setState({fileLoading:!0,fileLoadingCount:0});let r=0;const s=[],o=[];n.forEach(a=>{const l=new FileReader;l.onload=c=>{try{const d=c.target.result.split(`
|
|
729
729
|
---
|
|
730
|
-
`).filter(h=>h.trim()).map(h=>{try{return JSON.parse(h)}catch{return null}}).filter(Boolean);s.push(...d),o.push(a.name)}catch{}r++,r===n.length&&this._finishLocalLoad(s,o)},l.readAsText(a)})});tt(this,"_onDragOver",n=>{n.preventDefault(),this.state.isDragging||this.setState({isDragging:!0})});tt(this,"_onDragLeave",n=>{const i=this._layoutRef.current;i&&!i.contains(n.relatedTarget)&&this.setState({isDragging:!1})});tt(this,"_onDrop",n=>{n.preventDefault(),this.setState({isDragging:!1});const i=Array.from(n.dataTransfer.files);i.length&&Promise.all(i.map(r=>$1(r).then(s=>({name:r.name,path:s})).catch(s=>(Tn.error(`${r.name}: ${s.message}`),null)))).then(r=>{const s=r.filter(Boolean).map(o=>`"${o.path}"`);s.length>0&&this.setState(o=>({pendingUploadPaths:[...o.pendingUploadPaths||[],...s]}))})});tt(this,"handleUploadPathsConsumed",()=>{this.setState({pendingUploadPaths:[]})});tt(this,"_finishLocalLoad",(n,i)=>{if(n.length===0){Tn.error(J("ui.noLogs")),this.setState({fileLoading:!1,fileLoadingCount:0});return}this.animateLoadingCount(n.length,()=>{let r=[];for(const o of n)Cr(o)&&o.body&&Array.isArray(o.body.messages)&&(r=this.mergeMainAgentSessions(r,o));const s=aa(n);this._isLocalLog=!0,this._localLogFile=i.length===1?i[0]:`${i.length} files`,this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._rebuildRequestIndex(n),this.setState({requests:n,selectedIndex:s.length>0?s.length-1:null,mainAgentSessions:r,importModalVisible:!1,fileLoading:!1,fileLoadingCount:0})})});const i=parseInt(localStorage.getItem("ccv_cacheExpireAt"),10)||null,r=localStorage.getItem("ccv_cacheType")||null,s=Date.now(),o=i&&i>s?i:null,a=o?r:null;this.state={requests:[],selectedIndex:null,viewMode:"raw",currentTab:"request",pendingCacheHighlight:null,cacheExpireAt:o,cacheType:a,leftPanelWidth:380,mainAgentSessions:[],importModalVisible:!1,localLogs:{},localLogsLoading:!1,refreshingStats:!1,showAll:!1,lang:Em(),userProfile:null,projectName:"",resumeModalVisible:!1,resumeFileName:"",resumeRememberChoice:!1,resumeAutoChoice:null,collapseToolResults:!0,expandThinking:!0,expandDiff:!1,fileLoading:!1,fileLoadingCount:0,isDragging:!1,selectedLogs:new Set,githubStars:null,cliMode:!1,terminalVisible:!0,workspaceMode:!1,mobileMenuVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1,mobilePromptVisible:!1,serverCachedContent:null},this.eventSource=null,this._autoSelectTimer=null,this._chunkedEntries=[],this._chunkedTotal=0,this.mainContainerRef=ie.createRef(),this._layoutRef=ie.createRef(),this._requestIndexMap=new Map,this._pendingEntries=[],this._flushRafId=null,this._cacheLossMap=new Map,this._cacheLossProcessedCount=0,this._cacheLossLastMainAgent=null,this._cacheLossShowAll=void 0}_rebuildRequestIndex(n){this._requestIndexMap.clear();for(let i=0;i<n.length;i++){const r=n[i];this._requestIndexMap.set(`${r.timestamp}|${r.url}`,i)}this._cacheLossProcessedCount=0,this._cacheLossLastMainAgent=null,this._cacheLossMap=new Map}componentDidMount(){yP&&window.visualViewport&&(this._onVisualViewportChange=()=>{const r=this._layoutRef.current;if(!r)return;const s=window.visualViewport;r.style.position="fixed",r.style.top=`${s.offsetTop}px`,r.style.height=`${s.height}px`,r.style.width="100%",r.style.left="0"},window.visualViewport.addEventListener("resize",this._onVisualViewportChange),window.visualViewport.addEventListener("scroll",this._onVisualViewportChange),this._onVisualViewportChange()),this._prefsReady=fetch(mn("/api/preferences")).then(r=>r.json()).then(r=>{r.lang&&(Qk(r.lang),this.setState({lang:r.lang})),r.collapseToolResults!==void 0&&this.setState({collapseToolResults:!!r.collapseToolResults}),r.expandThinking!==void 0&&this.setState({expandThinking:!!r.expandThinking}),r.expandDiff!==void 0&&this.setState({expandDiff:!!r.expandDiff}),r.resumeAutoChoice&&this.setState({resumeAutoChoice:r.resumeAutoChoice});const s=r.filterIrrelevant!==void 0?!!r.filterIrrelevant:!0;return this.setState({showAll:!s}),r}).catch(()=>({})),fetch(mn("/api/user-profile")).then(r=>r.json()).then(r=>this.setState({userProfile:r})).catch(()=>{});const i=new URLSearchParams(window.location.search).get("logfile");fetch(mn("/api/project-name")).then(r=>r.json()).then(r=>{const s=r.projectName||"";this.setState({projectName:s}),_i&&s&&!i&&this.state.requests.length===0&&HDe(s).then(o=>{if(o&&this.state.requests.length===0){this.assignMessageTimestamps(o);const a=this.buildSessionsFromEntries(o),l=aa(o);this._rebuildRequestIndex(o),this.setState({requests:o,selectedIndex:l.length>0?l.length-1:null,mainAgentSessions:a,fileLoading:!1})}})}).catch(()=>{}),fetch("https://api.github.com/repos/weiesky/cc-viewer").then(r=>r.json()).then(r=>{r.stargazers_count!=null&&this.setState({githubStars:r.stargazers_count})}).catch(()=>{}),fetch(mn("/api/cli-mode")).then(r=>r.json()).then(r=>{r.workspaceMode?this.setState({cliMode:!0,workspaceMode:!0,isWorkspaceServer:!0}):r.cliMode&&this.setState({cliMode:!0,viewMode:"chat"})}).catch(()=>{}),i?this.loadLocalLogFile(i):this.initSSE()}componentWillUnmount(){this._onVisualViewportChange&&window.visualViewport&&(window.visualViewport.removeEventListener("resize",this._onVisualViewportChange),window.visualViewport.removeEventListener("scroll",this._onVisualViewportChange)),this.eventSource&&this.eventSource.close(),this._autoSelectTimer&&clearTimeout(this._autoSelectTimer),this._loadingCountTimer&&cancelAnimationFrame(this._loadingCountTimer),this._cacheSaveTimer&&clearTimeout(this._cacheSaveTimer),this._sseTimeoutTimer&&clearTimeout(this._sseTimeoutTimer),this._sseReconnectTimer&&clearTimeout(this._sseReconnectTimer)}_reconnectSSE(){if(this._sseReconnectCount>=10){console.error("SSE reconnect limit reached");return}this._sseReconnectCount=(this._sseReconnectCount||0)+1,this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._flushRafId&&(cancelAnimationFrame(this._flushRafId),this._flushRafId=null),this._pendingEntries=[],this._sseReconnectTimer&&clearTimeout(this._sseReconnectTimer),this._sseReconnectTimer=setTimeout(()=>{this.initSSE()},2e3)}animateLoadingCount(n,i){this._loadingCountTimer&&(cancelAnimationFrame(this._loadingCountTimer),this._loadingCountTimer=null);const r=Math.min(800,Math.max(300,n*.5)),s=performance.now(),o=a=>{const l=Math.min((a-s)/r,1),c=Math.round(l*n);this.setState({fileLoadingCount:c}),l<1?this._loadingCountTimer=requestAnimationFrame(o):(this._loadingCountTimer=null,i())};this._loadingCountTimer=requestAnimationFrame(o)}initSSE(){try{let n="/events",i=!1;if(_i){const r=GDe();r&&r.lastTs&&r.count>0&&(n=`/events?since=${encodeURIComponent(r.lastTs)}&cc=${r.count}`,i=!0)}i||this.setState({fileLoading:!0,fileLoadingCount:0}),this.eventSource=new EventSource(mn(n)),this.eventSource.onmessage=r=>{this._resetSSETimeout(),this.handleEventMessage(r)},this.eventSource.onopen=()=>{this._resetSSETimeout()},this.eventSource.addEventListener("resume_prompt",r=>{try{const s=JSON.parse(r.data);(this._prefsReady||Promise.resolve({})).then(o=>{o!=null&&o.resumeAutoChoice?fetch(mn("/api/resume-choice"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({choice:o.resumeAutoChoice})}).catch(a=>console.error("resume-choice failed:",a)):this.setState({resumeModalVisible:!0,resumeFileName:s.recentFileName||""})})}catch{}}),this.eventSource.addEventListener("resume_resolved",()=>{this.setState({resumeModalVisible:!1,resumeFileName:"",resumeRememberChoice:!1})}),this.eventSource.addEventListener("update_completed",r=>{try{const s=JSON.parse(r.data);this.setState({updateInfo:{type:"completed",version:s.version}})}catch{}}),this.eventSource.addEventListener("update_major_available",r=>{try{const s=JSON.parse(r.data);this.setState({updateInfo:{type:"major",version:s.version}})}catch{}}),this.eventSource.addEventListener("load_start",r=>{try{const s=JSON.parse(r.data);this._chunkedEntries=[],this._chunkedTotal=s.total||0,this._isIncremental=!!s.incremental,this._isIncremental||this.setState({fileLoading:!0,fileLoadingCount:0})}catch{}}),this.eventSource.addEventListener("load_chunk",r=>{try{const s=JSON.parse(r.data);Array.isArray(s)&&(this._chunkedEntries.push(...s),this._isIncremental||this.setState({fileLoadingCount:this._chunkedEntries.length}))}catch{}}),this.eventSource.addEventListener("load_end",()=>{const r=this._chunkedEntries;this._chunkedEntries=[],this._chunkedTotal=0;const s=this._isIncremental;this._isIncremental=!1;const o=s&&_i&&this.state.requests.length>0?[...this.state.requests,...r]:r;if(Array.isArray(o)&&o.length>0){this.assignMessageTimestamps(o);const a=this.buildSessionsFromEntries(o),l=aa(o);this._rebuildRequestIndex(o),this.setState({requests:o,selectedIndex:l.length>0?l.length-1:null,mainAgentSessions:a,fileLoading:!1,fileLoadingCount:0}),_i&&this.state.projectName&&iw(this.state.projectName,o)}else this.setState({fileLoading:!1,fileLoadingCount:0})}),this.eventSource.addEventListener("full_reload",r=>{try{const s=JSON.parse(r.data);if(Array.isArray(s)){this.assignMessageTimestamps(s);const o=this.buildSessionsFromEntries(s),a=aa(s);this._rebuildRequestIndex(s),s.length>0?this.animateLoadingCount(s.length,()=>{this.setState({requests:s,selectedIndex:a.length>0?a.length-1:null,mainAgentSessions:o,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null}),_i&&this.state.projectName&&iw(this.state.projectName,s)}):(this.setState({requests:s,selectedIndex:null,mainAgentSessions:o,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null}),_i&&D2())}else this.setState({fileLoading:!1,fileLoadingCount:0})}catch{this.setState({fileLoading:!1,fileLoadingCount:0})}}),this.eventSource.addEventListener("workspace_started",r=>{try{const s=JSON.parse(r.data);this._loadingCountTimer&&(cancelAnimationFrame(this._loadingCountTimer),this._loadingCountTimer=null),this._rebuildRequestIndex([]),this.setState({workspaceMode:!1,projectName:s.projectName||"",viewMode:"chat",cliMode:!0,requests:[],mainAgentSessions:[],selectedIndex:null}),_i&&D2()}catch{}}),this.eventSource.addEventListener("workspace_stopped",()=>{this._rebuildRequestIndex([]),this.setState({workspaceMode:!0,requests:[],mainAgentSessions:[],projectName:"",selectedIndex:null})}),this.eventSource.addEventListener("context_window",r=>{try{const s=JSON.parse(r.data);this.setState({contextWindow:s})}catch{}}),this.eventSource.addEventListener("kv_cache_content",r=>{try{const s=JSON.parse(r.data);this.setState({serverCachedContent:s})}catch(s){console.error("Failed to parse kv_cache_content:",s)}}),this.eventSource.addEventListener("ping",()=>{this._resetSSETimeout()}),this.eventSource.onerror=()=>console.error("SSE连接错误")}catch(n){console.error("EventSource初始化失败:",n),this.setState({fileLoading:!1,fileLoadingCount:0})}}loadLocalLogFile(n){this._isLocalLog=!0,this._localLogFile=n,this.setState({fileLoading:!0,fileLoadingCount:0}),fetch(`/api/local-log?file=${encodeURIComponent(n)}`).then(i=>{if(!i.ok)return i.text().then(s=>{throw new Error(`HTTP ${i.status}: ${s}`)});const r=i.headers.get("content-type");return!r||!r.includes("application/json")?i.text().then(s=>{throw new Error(`Invalid content type: ${r}. Response: ${s.substring(0,100)}`)}):i.json()}).then(i=>{Array.isArray(i)?this.animateLoadingCount(i.length,()=>{this.assignMessageTimestamps(i);const r=this.buildSessionsFromEntries(i),s=aa(i);this._rebuildRequestIndex(i),this.setState({requests:i,selectedIndex:s.length>0?s.length-1:null,mainAgentSessions:r,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null})}):this.setState({fileLoading:!1,fileLoadingCount:0,serverCachedContent:null})}).catch(i=>{console.error("加载日志文件失败:",i),this.setState({fileLoading:!1,fileLoadingCount:0})})}handleEventMessage(n){try{const i=JSON.parse(n.data);this._pendingEntries.push(i),this._flushRafId||(this._flushRafId=requestAnimationFrame(this._flushPendingEntries))}catch(i){console.error("处理事件消息失败:",i)}}assignMessageTimestamps(n){var s;let i=[],r=null;for(const o of n){if(!Cr(o)||!o.body||!Array.isArray(o.body.messages))continue;const a=o.body.messages,l=a.length,c=((s=o.body.metadata)==null?void 0:s.user_id)||null,u=o.timestamp||new Date().toISOString(),d=i.length;d>0&&(l<d*.5&&d-l>4||r&&c&&c!==r)&&(i=[]);for(let p=i.length;p<l;p++)i.push(u);for(let p=0;p<l;p++)a[p]._timestamp=i[p];r=c}}buildSessionsFromEntries(n){let i=[];for(const r of n)Cr(r)&&r.body&&Array.isArray(r.body.messages)&&(i=this.mergeMainAgentSessions(i,r));return i}mergeMainAgentSessions(n,i){var d;const r=i.body.messages,s=i.response,o=((d=i.body.metadata)==null?void 0:d.user_id)||null,a=i.timestamp||null;if(n.length===0)return[{userId:o,messages:r,response:s,entryTimestamp:a}];const l=n[n.length-1],c=l.messages?l.messages.length:0,u=c>0&&r.length<c*.5&&c-r.length>4;if(o&&o===l.userId&&!u){const h=[...n];return h[h.length-1]={userId:o,messages:r,response:s,entryTimestamp:a},h}else return[...n,{userId:o,messages:r,response:s,entryTimestamp:a}]}static parseSegments(n){const i=[],r=/<([a-zA-Z_][\w-]*)(?:\s[^>]*)?>[\s\S]*?<\/\1>/g;let s=0,o;for(;(o=r.exec(n))!==null;){const l=n.slice(s,o.index).trim();l&&i.push({type:"text",content:l});const c=o[1];if(s=o.index+o[0].length,gO.COMMAND_TAGS.has(c))continue;const u=new RegExp(`^<${c}(?:\\s[^>]*)?>([\\s\\S]*)<\\/${c}>$`),d=o[0].match(u),h=d?d[1].trim():o[0].trim();i.push({type:"system",content:h,label:c})}const a=n.slice(s).trim();return a&&i.push({type:"text",content:a}),i}static extractUserTexts(n){const i=[],r=[];let s=null;for(const o of n)if(o.role==="user"){if(typeof o.content=="string"){const a=o.content.trim();if(!a)continue;if(!Cu(a)){if(/Implement the following plan:/i.test(a))continue;i.push(a),r.push(a)}}else if(Array.isArray(o.content)){const{commands:a,textBlocks:l}=wk(o.content);a.length>0&&(s=a[a.length-1]);const c=[];for(const d of l)/Implement the following plan:/i.test((d.text||"").trim())||c.push(d.text.trim());const u=o.content.filter(d=>{var h;return d.type==="text"&&((h=d.text)==null?void 0:h.trim())}).map(d=>d.text.trim());c.length>0&&(i.push(c.join(`
|
|
730
|
+
`).filter(h=>h.trim()).map(h=>{try{return JSON.parse(h)}catch{return null}}).filter(Boolean);s.push(...d),o.push(a.name)}catch{}r++,r===n.length&&this._finishLocalLoad(s,o)},l.readAsText(a)})});tt(this,"_onDragOver",n=>{n.preventDefault(),this.state.isDragging||this.setState({isDragging:!0})});tt(this,"_onDragLeave",n=>{const i=this._layoutRef.current;i&&!i.contains(n.relatedTarget)&&this.setState({isDragging:!1})});tt(this,"_onDrop",n=>{n.preventDefault(),this.setState({isDragging:!1});const i=Array.from(n.dataTransfer.files);i.length&&Promise.all(i.map(r=>$1(r).then(s=>({name:r.name,path:s})).catch(s=>(Tn.error(`${r.name}: ${s.message}`),null)))).then(r=>{const s=r.filter(Boolean).map(o=>`"${o.path}"`);s.length>0&&this.setState(o=>({pendingUploadPaths:[...o.pendingUploadPaths||[],...s]}))})});tt(this,"handleUploadPathsConsumed",()=>{this.setState({pendingUploadPaths:[]})});tt(this,"_finishLocalLoad",(n,i)=>{if(n.length===0){Tn.error(J("ui.noLogs")),this.setState({fileLoading:!1,fileLoadingCount:0});return}this.animateLoadingCount(n.length,()=>{let r=[];for(const o of n)Cr(o)&&o.body&&Array.isArray(o.body.messages)&&(r=this.mergeMainAgentSessions(r,o));const s=aa(n);this._isLocalLog=!0,this._localLogFile=i.length===1?i[0]:`${i.length} files`,this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._rebuildRequestIndex(n),this.setState({requests:n,selectedIndex:s.length>0?s.length-1:null,mainAgentSessions:r,importModalVisible:!1,fileLoading:!1,fileLoadingCount:0})})});const i=parseInt(localStorage.getItem("ccv_cacheExpireAt"),10)||null,r=localStorage.getItem("ccv_cacheType")||null,s=Date.now(),o=i&&i>s?i:null,a=o?r:null;this.state={requests:[],selectedIndex:null,viewMode:"raw",currentTab:"request",pendingCacheHighlight:null,cacheExpireAt:o,cacheType:a,leftPanelWidth:380,mainAgentSessions:[],importModalVisible:!1,localLogs:{},localLogsLoading:!1,refreshingStats:!1,showAll:!1,lang:Em(),userProfile:null,projectName:"",resumeModalVisible:!1,resumeFileName:"",resumeRememberChoice:!1,resumeAutoChoice:null,collapseToolResults:!0,expandThinking:!0,expandDiff:!1,fileLoading:!1,fileLoadingCount:0,isDragging:!1,selectedLogs:new Set,githubStars:null,cliMode:!1,terminalVisible:!0,workspaceMode:!1,mobileMenuVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1,mobilePromptVisible:!1,serverCachedContent:null},this.eventSource=null,this._autoSelectTimer=null,this._chunkedEntries=[],this._chunkedTotal=0,this.mainContainerRef=ie.createRef(),this._layoutRef=ie.createRef(),this._requestIndexMap=new Map,this._pendingEntries=[],this._flushRafId=null,this._cacheLossMap=new Map,this._cacheLossProcessedCount=0,this._cacheLossLastMainAgent=null,this._cacheLossShowAll=void 0}_rebuildRequestIndex(n){this._requestIndexMap.clear();for(let i=0;i<n.length;i++){const r=n[i];this._requestIndexMap.set(`${r.timestamp}|${r.url}`,i)}this._cacheLossProcessedCount=0,this._cacheLossLastMainAgent=null,this._cacheLossMap=new Map}componentDidMount(){yP&&window.visualViewport&&(this._onVisualViewportChange=()=>{const r=this._layoutRef.current;if(!r)return;const s=window.visualViewport;r.style.position="fixed",r.style.top=`${s.offsetTop}px`,r.style.height=`${s.height}px`,r.style.width="100%",r.style.left="0"},window.visualViewport.addEventListener("resize",this._onVisualViewportChange),window.visualViewport.addEventListener("scroll",this._onVisualViewportChange),this._onVisualViewportChange()),this._prefsReady=fetch(mn("/api/preferences")).then(r=>r.json()).then(r=>{r.lang&&(Qk(r.lang),this.setState({lang:r.lang})),r.collapseToolResults!==void 0&&this.setState({collapseToolResults:!!r.collapseToolResults}),r.expandThinking!==void 0&&this.setState({expandThinking:!!r.expandThinking}),r.expandDiff!==void 0&&this.setState({expandDiff:!!r.expandDiff}),r.resumeAutoChoice&&this.setState({resumeAutoChoice:r.resumeAutoChoice});const s=r.filterIrrelevant!==void 0?!!r.filterIrrelevant:!0;return this.setState({showAll:!s}),r}).catch(()=>({})),fetch(mn("/api/user-profile")).then(r=>r.json()).then(r=>this.setState({userProfile:r})).catch(()=>{});const i=new URLSearchParams(window.location.search).get("logfile");fetch(mn("/api/project-name")).then(r=>r.json()).then(r=>{const s=r.projectName||"";this.setState({projectName:s}),_i&&s&&!i&&this.state.requests.length===0&&HDe(s).then(o=>{if(o&&this.state.requests.length===0){this.assignMessageTimestamps(o);const a=this.buildSessionsFromEntries(o),l=aa(o);this._rebuildRequestIndex(o),this.setState({requests:o,selectedIndex:l.length>0?l.length-1:null,mainAgentSessions:a,fileLoading:!1})}})}).catch(()=>{}),fetch("https://api.github.com/repos/weiesky/cc-viewer").then(r=>r.json()).then(r=>{r.stargazers_count!=null&&this.setState({githubStars:r.stargazers_count})}).catch(()=>{}),fetch(mn("/api/cli-mode")).then(r=>r.json()).then(r=>{r.workspaceMode?this.setState({cliMode:!0,workspaceMode:!0,isWorkspaceServer:!0}):r.cliMode&&this.setState({cliMode:!0,viewMode:"chat"})}).catch(()=>{}),i?this.loadLocalLogFile(i):this.initSSE()}componentWillUnmount(){this._onVisualViewportChange&&window.visualViewport&&(window.visualViewport.removeEventListener("resize",this._onVisualViewportChange),window.visualViewport.removeEventListener("scroll",this._onVisualViewportChange)),this.eventSource&&this.eventSource.close(),this._autoSelectTimer&&clearTimeout(this._autoSelectTimer),this._loadingCountTimer&&cancelAnimationFrame(this._loadingCountTimer),this._cacheSaveTimer&&clearTimeout(this._cacheSaveTimer),this._sseTimeoutTimer&&clearTimeout(this._sseTimeoutTimer),this._sseReconnectTimer&&clearTimeout(this._sseReconnectTimer)}_reconnectSSE(){if(this._sseReconnectCount>=10){console.error("SSE reconnect limit reached");return}this._sseReconnectCount=(this._sseReconnectCount||0)+1,this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._flushRafId&&(cancelAnimationFrame(this._flushRafId),this._flushRafId=null),this._pendingEntries=[],this._sseReconnectTimer&&clearTimeout(this._sseReconnectTimer),this._sseReconnectTimer=setTimeout(()=>{this.initSSE()},2e3)}animateLoadingCount(n,i){this._loadingCountTimer&&(cancelAnimationFrame(this._loadingCountTimer),this._loadingCountTimer=null);const r=Math.min(800,Math.max(300,n*.5)),s=performance.now(),o=a=>{const l=Math.min((a-s)/r,1),c=Math.round(l*n);this.setState({fileLoadingCount:c}),l<1?this._loadingCountTimer=requestAnimationFrame(o):(this._loadingCountTimer=null,i())};this._loadingCountTimer=requestAnimationFrame(o)}initSSE(){try{let n="/events",i=!1;if(_i){const r=GDe();r&&r.lastTs&&r.count>0&&(n=`/events?since=${encodeURIComponent(r.lastTs)}&cc=${r.count}`,i=!0)}i||this.setState({fileLoading:!0,fileLoadingCount:0}),this.eventSource=new EventSource(mn(n)),this.eventSource.onmessage=r=>{this._resetSSETimeout(),this.handleEventMessage(r)},this.eventSource.onopen=()=>{this._resetSSETimeout()},this.eventSource.addEventListener("resume_prompt",r=>{try{const s=JSON.parse(r.data);(this._prefsReady||Promise.resolve({})).then(o=>{o!=null&&o.resumeAutoChoice?fetch(mn("/api/resume-choice"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({choice:o.resumeAutoChoice})}).catch(a=>console.error("resume-choice failed:",a)):this.setState({resumeModalVisible:!0,resumeFileName:s.recentFileName||""})})}catch{}}),this.eventSource.addEventListener("resume_resolved",()=>{this.setState({resumeModalVisible:!1,resumeFileName:"",resumeRememberChoice:!1})}),this.eventSource.addEventListener("update_completed",r=>{try{const s=JSON.parse(r.data);this.setState({updateInfo:{type:"completed",version:s.version}})}catch{}}),this.eventSource.addEventListener("update_major_available",r=>{try{const s=JSON.parse(r.data);this.setState({updateInfo:{type:"major",version:s.version}})}catch{}}),this.eventSource.addEventListener("load_start",r=>{try{const s=JSON.parse(r.data);this._chunkedEntries=[],this._chunkedTotal=s.total||0,this._isIncremental=!!s.incremental,this._isIncremental||this.setState({fileLoading:!0,fileLoadingCount:0})}catch{}}),this.eventSource.addEventListener("load_chunk",r=>{try{const s=JSON.parse(r.data);Array.isArray(s)&&(this._chunkedEntries.push(...s),this._isIncremental||this.setState({fileLoadingCount:this._chunkedEntries.length}))}catch{}}),this.eventSource.addEventListener("load_end",()=>{const r=this._chunkedEntries;this._chunkedEntries=[],this._chunkedTotal=0;const s=this._isIncremental;this._isIncremental=!1;const o=s&&_i&&this.state.requests.length>0?[...this.state.requests,...r]:r;if(Array.isArray(o)&&o.length>0){this.assignMessageTimestamps(o);const a=this.buildSessionsFromEntries(o),l=aa(o);this._rebuildRequestIndex(o),this.setState({requests:o,selectedIndex:l.length>0?l.length-1:null,mainAgentSessions:a,fileLoading:!1,fileLoadingCount:0}),_i&&this.state.projectName&&iw(this.state.projectName,o)}else this.setState({fileLoading:!1,fileLoadingCount:0})}),this.eventSource.addEventListener("full_reload",r=>{try{const s=JSON.parse(r.data);if(Array.isArray(s)){this.assignMessageTimestamps(s);const o=this.buildSessionsFromEntries(s),a=aa(s);this._rebuildRequestIndex(s),s.length>0?this.animateLoadingCount(s.length,()=>{this.setState({requests:s,selectedIndex:a.length>0?a.length-1:null,mainAgentSessions:o,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null}),_i&&this.state.projectName&&iw(this.state.projectName,s)}):(this.setState({requests:s,selectedIndex:null,mainAgentSessions:o,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null}),_i&&D2())}else this.setState({fileLoading:!1,fileLoadingCount:0})}catch{this.setState({fileLoading:!1,fileLoadingCount:0})}}),this.eventSource.addEventListener("workspace_started",r=>{try{const s=JSON.parse(r.data);this._loadingCountTimer&&(cancelAnimationFrame(this._loadingCountTimer),this._loadingCountTimer=null),this._rebuildRequestIndex([]),this.setState({workspaceMode:!1,projectName:s.projectName||"",viewMode:"chat",cliMode:!0,requests:[],mainAgentSessions:[],selectedIndex:null}),_i&&D2()}catch{}}),this.eventSource.addEventListener("workspace_stopped",()=>{this._rebuildRequestIndex([]),this.setState({workspaceMode:!0,requests:[],mainAgentSessions:[],projectName:"",selectedIndex:null})}),this.eventSource.addEventListener("context_window",r=>{try{const s=JSON.parse(r.data);this.setState({contextWindow:s})}catch{}}),this.eventSource.addEventListener("kv_cache_content",r=>{try{const s=JSON.parse(r.data);this.setState({serverCachedContent:s})}catch(s){console.error("Failed to parse kv_cache_content:",s)}}),this.eventSource.addEventListener("ping",()=>{this._resetSSETimeout()}),this.eventSource.onerror=()=>console.error("SSE连接错误")}catch(n){console.error("EventSource初始化失败:",n),this.setState({fileLoading:!1,fileLoadingCount:0})}}loadLocalLogFile(n){this._isLocalLog=!0,this._localLogFile=n,this.setState({fileLoading:!0,fileLoadingCount:0}),fetch(`/api/local-log?file=${encodeURIComponent(n)}`).then(i=>{if(!i.ok)return i.text().then(s=>{throw new Error(`HTTP ${i.status}: ${s}`)});const r=i.headers.get("content-type");return!r||!r.includes("application/json")?i.text().then(s=>{throw new Error(`Invalid content type: ${r}. Response: ${s.substring(0,100)}`)}):i.json()}).then(i=>{Array.isArray(i)?this.animateLoadingCount(i.length,()=>{this.assignMessageTimestamps(i);const r=this.buildSessionsFromEntries(i),s=aa(i);this._rebuildRequestIndex(i),this.setState({requests:i,selectedIndex:s.length>0?s.length-1:null,mainAgentSessions:r,fileLoading:!1,fileLoadingCount:0,serverCachedContent:null})}):this.setState({fileLoading:!1,fileLoadingCount:0,serverCachedContent:null})}).catch(i=>{console.error("加载日志文件失败:",i),this.setState({fileLoading:!1,fileLoadingCount:0})})}handleEventMessage(n){try{const i=JSON.parse(n.data);this._pendingEntries.push(i),this._flushRafId||(this._flushRafId=requestAnimationFrame(this._flushPendingEntries))}catch(i){console.error("处理事件消息失败:",i)}}assignMessageTimestamps(n){var s;let i=[],r=null;for(const o of n){if(!Cr(o)||!o.body||!Array.isArray(o.body.messages))continue;const a=o.body.messages,l=a.length,c=((s=o.body.metadata)==null?void 0:s.user_id)||null,u=o.timestamp||new Date().toISOString(),d=i.length;d>0&&(l<d*.5&&d-l>4||r&&c&&c!==r)&&(i=[]);for(let p=i.length;p<l;p++)i.push(u);for(let p=0;p<l;p++)a[p]._timestamp=i[p];r=c}}buildSessionsFromEntries(n){let i=[];for(const r of n)Cr(r)&&r.body&&Array.isArray(r.body.messages)&&(i=this.mergeMainAgentSessions(i,r));return i}mergeMainAgentSessions(n,i){var d;const r=i.body.messages,s=i.response,o=((d=i.body.metadata)==null?void 0:d.user_id)||null,a=i.timestamp||null;if(n.length===0)return[{userId:o,messages:r,response:s,entryTimestamp:a}];const l=n[n.length-1],c=l.messages?l.messages.length:0,u=c>0&&r.length<c*.5&&c-r.length>4;if(o===l.userId&&!u){const h=[...n];return h[h.length-1]={userId:o,messages:r,response:s,entryTimestamp:a},h}else return[...n,{userId:o,messages:r,response:s,entryTimestamp:a}]}static parseSegments(n){const i=[],r=/<([a-zA-Z_][\w-]*)(?:\s[^>]*)?>[\s\S]*?<\/\1>/g;let s=0,o;for(;(o=r.exec(n))!==null;){const l=n.slice(s,o.index).trim();l&&i.push({type:"text",content:l});const c=o[1];if(s=o.index+o[0].length,gO.COMMAND_TAGS.has(c))continue;const u=new RegExp(`^<${c}(?:\\s[^>]*)?>([\\s\\S]*)<\\/${c}>$`),d=o[0].match(u),h=d?d[1].trim():o[0].trim();i.push({type:"system",content:h,label:c})}const a=n.slice(s).trim();return a&&i.push({type:"text",content:a}),i}static extractUserTexts(n){const i=[],r=[];let s=null;for(const o of n)if(o.role==="user"){if(typeof o.content=="string"){const a=o.content.trim();if(!a)continue;if(!Cu(a)){if(/Implement the following plan:/i.test(a))continue;i.push(a),r.push(a)}}else if(Array.isArray(o.content)){const{commands:a,textBlocks:l}=wk(o.content);a.length>0&&(s=a[a.length-1]);const c=[];for(const d of l)/Implement the following plan:/i.test((d.text||"").trim())||c.push(d.text.trim());const u=o.content.filter(d=>{var h;return d.type==="text"&&((h=d.text)==null?void 0:h.trim())}).map(d=>d.text.trim());c.length>0&&(i.push(c.join(`
|
|
731
731
|
`)),r.push(u.join(`
|
|
732
732
|
`)))}}return{userMsgs:i,fullTexts:r,slashCmd:s}}extractUserPrompts(n){var a;const i=[],r=new Set;let s=null;const o=n.filter(l=>Cr(l));for(let l=0;l<o.length;l++){const c=o[l],u=((a=c.body)==null?void 0:a.messages)||[],d=c.timestamp||"",{userMsgs:h,fullTexts:p,slashCmd:g}=gO.extractUserTexts(u);g&&g!=="/compact"&&g!==s&&i.push({type:"prompt",segments:[{type:"text",content:g}],timestamp:d}),s=g;for(let v=0;v<h.length;v++){const $=h[v];if(r.has($))continue;r.add($);const b=p[v]||$;i.push({type:"prompt",segments:gO.parseSegments(b),timestamp:d})}}return i}renderOriginalPrompt(n){const i=n.segments.filter(r=>r.type==="text");return i.length===0?null:S.jsx("div",{className:vt.mobilePromptCard,children:i.map((r,s)=>S.jsx("pre",{className:vt.mobilePromptPreText,children:r.content},s))})}renderLogTable(n,i){const r=[{title:"",dataIndex:"file",key:"check",width:40,fixed:i?"left":!1,render:s=>S.jsx(ju,{checked:this.state.selectedLogs.has(s)||!1,onClick:o=>o.stopPropagation(),onChange:o=>{o.stopPropagation(),this.handleToggleLogSelect(s,o.target.checked)}})},{title:J("ui.logTime"),dataIndex:"timestamp",key:"time",width:i?150:180,render:s=>S.jsx("span",{style:{whiteSpace:"nowrap"},children:this.formatTimestamp(s,i)})},{title:J("ui.logPreview"),dataIndex:"preview",key:"preview",width:i?150:void 0,ellipsis:!0,render:s=>{if(!Array.isArray(s)||s.length===0)return"—";const o=s[0],a=o.length<=30&&s.length>1?`${o} | ${s[1]}`:o;return s.length<=1?S.jsx("span",{style:{maxWidth:600,display:"inline-block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",verticalAlign:"bottom"},children:a}):S.jsx(Sl,{trigger:i?"click":"hover",placement:i?"bottomLeft":"leftTop",autoAdjustOverflow:{adjustX:!1,adjustY:!0},overlayInnerStyle:{background:"#1e1e1e",border:"1px solid #3a3a3a",borderRadius:8,padding:0,maxHeight:400,overflowY:"auto"},content:S.jsx("div",{className:vt.previewPopover,children:s.map((l,c)=>S.jsx("div",{className:vt.previewItem,children:S.jsx("pre",{className:vt.previewText,children:l})},c))}),children:S.jsx("span",{style:{cursor:"pointer",textDecoration:i?"underline dotted #666":"none",maxWidth:600,display:"inline-block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",verticalAlign:"bottom"},children:a})})}},...i?[]:[{title:J("ui.logTurns"),dataIndex:"turns",key:"turns",width:80,render:s=>S.jsx(to,{style:{background:"#0a0a0a",border:"1px solid #444",color:"#999"},children:s||0})}],{title:J("ui.logSize"),dataIndex:"size",key:"size",width:90,render:s=>S.jsx(to,{style:{background:"#0a0a0a",border:"1px solid #444",color:"#999"},children:this.formatSize(s)})},{title:J("ui.logActions"),key:"actions",width:i?160:180,render:(s,o)=>S.jsxs("span",{style:{display:"flex",gap:4},children:[S.jsx(gn,{size:"small",type:"primary",onClick:a=>{a.stopPropagation(),this.handleOpenLogFile(o.file)},children:J("ui.openLog")}),S.jsx(gn,{size:"small",icon:S.jsx(bP,{}),onClick:a=>{a.stopPropagation(),this.handleDownloadLogFile(o.file)},children:J("ui.downloadLog")})]})}];return S.jsx(ql,{size:"small",dataSource:n,columns:r,rowKey:"file",pagination:!1,scroll:i?{x:"max-content",y:"calc(100vh - 160px)"}:{y:400},onRow:s=>({onClick:()=>{const o=!this.state.selectedLogs.has(s.file);this.handleToggleLogSelect(s.file,o)},style:{cursor:"pointer"}})})}formatTimestamp(n,i){return!n||n.length<15?n:i?`${n.slice(4,6)}-${n.slice(6,8)} ${n.slice(9,11)}:${n.slice(11,13)}:${n.slice(13,15)}`:`${n.slice(0,4)}-${n.slice(4,6)}-${n.slice(6,8)} ${n.slice(9,11)}:${n.slice(11,13)}:${n.slice(13,15)}`}formatSize(n){return n<1024?n+" B":n<1024*1024?(n/1024).toFixed(1)+" KB":(n/(1024*1024)).toFixed(1)+" MB"}render(){const{requests:n,selectedIndex:i,viewMode:r,currentTab:s,cacheExpireAt:o,cacheType:a,leftPanelWidth:l,mainAgentSessions:c,showAll:u,fileLoading:d,fileLoadingCount:h}=this.state;(this._filteredSource!==n||this._filteredShowAll!==u)&&(this._filteredSource=n,this._filteredShowAll=u,this._filteredRequests=u?n:aa(n));const p=this._filteredRequests;this._cacheLossShowAll!==u&&(this._cacheLossShowAll=u,this._cacheLossMap=new Map,this._cacheLossLastMainAgent=null,this._cacheLossProcessedCount=0),p.length<this._cacheLossProcessedCount&&(this._cacheLossMap=new Map,this._cacheLossLastMainAgent=null,this._cacheLossProcessedCount=0),p.length>this._cacheLossProcessedCount&&(this._cacheLossLastMainAgent=QB(this._cacheLossMap,p,this._cacheLossProcessedCount,this._cacheLossLastMainAgent),this._cacheLossProcessedCount=p.length);const g=i!==null?p[i]:null;if(this.state.workspaceMode)return S.jsx(no,{theme:{algorithm:Ep.darkAlgorithm,token:{colorBgContainer:"#111",colorBgLayout:"#0a0a0a",colorBgElevated:"#1a1a1a",colorBorder:"#2a2a2a"}},children:S.jsx(RUe,{onLaunch:this.handleWorkspaceLaunch})});if(this.state.cliMode&&_i){const v=!!this._isLocalLog,$=v||this.state.mobileChatVisible;return S.jsxs("div",{style:{width:"100vw",height:"100vh",display:"flex",flexDirection:"column",background:"#000"},children:[S.jsxs("div",{style:{padding:"10px 12px",background:"#111",borderBottom:"1px solid #222",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0,position:"relative"},children:[S.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[S.jsx("button",{className:vt.mobileMenuBtn,onClick:()=>this.setState(b=>({mobileMenuVisible:!b.mobileMenuVisible})),"aria-label":J("ui.mobileMenu"),children:S.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[S.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),S.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),S.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),S.jsx(WA,{status:"processing",color:"green"}),S.jsx("span",{style:{fontSize:12,color:"#aaa"},children:v?J("ui.historyLog",{file:this._localLogFile}):J("ui.liveMonitoring")+(this.state.projectName?`: ${this.state.projectName}`:"")})]}),S.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[v?S.jsx(gn,{type:"text",size:"small",icon:S.jsx(p0e,{}),onClick:()=>history.back(),style:{color:"#888",fontSize:12},children:J("ui.mobileGoBack")}):S.jsx(gn,{type:"text",size:"small",icon:S.jsx(IW,{}),onClick:()=>this.setState(b=>({mobileGitDiffVisible:!b.mobileGitDiffVisible,mobileChatVisible:!1,mobileStatsVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1})),style:{color:this.state.mobileGitDiffVisible?"#fff":"#888",fontSize:12},children:this.state.mobileGitDiffVisible?J("ui.mobileGitDiffExit"):J("ui.mobileGitDiffBrowse")}),!v&&S.jsx(gn,{type:"text",size:"small",icon:S.jsx(AW,{}),onClick:()=>this.setState(b=>({mobileChatVisible:!b.mobileChatVisible,mobileGitDiffVisible:!1,mobileStatsVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1})),style:{color:this.state.mobileChatVisible?"#fff":"#888",fontSize:12},children:this.state.mobileChatVisible?J("ui.mobileChatExit"):J("ui.mobileChatBrowse")})]}),this.state.mobileMenuVisible&&S.jsxs(S.Fragment,{children:[S.jsx("div",{className:vt.mobileMenuOverlay,onClick:()=>this.setState({mobileMenuVisible:!1})}),S.jsxs("div",{className:vt.mobileMenuDropdown,children:[S.jsxs("button",{className:vt.mobileMenuItem,onClick:()=>{this.setState({mobileMenuVisible:!1,mobileLogMgmtVisible:!0,mobileStatsVisible:!1,mobileGitDiffVisible:!1,mobileChatVisible:!1,mobileSettingsVisible:!1,mobilePromptVisible:!1}),this.handleImportLocalLogs()},children:[S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),S.jsx("polyline",{points:"14 2 14 8 20 8"}),S.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),S.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]}),J("ui.logManagement")]}),S.jsxs("button",{className:vt.mobileMenuItem,onClick:()=>{this.setState({mobileMenuVisible:!1,mobileStatsVisible:!0,mobileGitDiffVisible:!1,mobileChatVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1,mobilePromptVisible:!1})},children:[S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),S.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),S.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),S.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]}),J("ui.tokenStats")]}),S.jsxs("button",{className:vt.mobileMenuItem,onClick:()=>{this.setState({mobileMenuVisible:!1,mobileSettingsVisible:!0,mobileStatsVisible:!1,mobileGitDiffVisible:!1,mobileChatVisible:!1,mobileLogMgmtVisible:!1,mobilePromptVisible:!1})},children:[S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("circle",{cx:"12",cy:"12",r:"3"}),S.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]}),J("ui.settings")]}),S.jsxs("button",{className:vt.mobileMenuItem,onClick:()=>{this.setState({mobileMenuVisible:!1,mobilePromptVisible:!0,mobileStatsVisible:!1,mobileGitDiffVisible:!1,mobileChatVisible:!1,mobileLogMgmtVisible:!1,mobileSettingsVisible:!1})},children:[S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),S.jsx("polyline",{points:"14 2 14 8 20 8"}),S.jsx("line",{x1:"12",y1:"18",x2:"12",y2:"12"}),S.jsx("line",{x1:"12",y1:"12",x2:"9",y2:"15"}),S.jsx("line",{x1:"12",y1:"12",x2:"15",y2:"15"})]}),J("ui.userPrompt")]})]})]})]}),S.jsxs("div",{style:{flex:1,position:"relative",overflow:"hidden"},children:[!v&&S.jsx(dB,{}),S.jsx("div",{className:`${vt.mobileGitDiffOverlay} ${this.state.mobileGitDiffVisible?vt.mobileGitDiffOverlayVisible:""}`,children:S.jsx("div",{className:vt.mobileGitDiffInner,children:S.jsx(mUe,{visible:this.state.mobileGitDiffVisible})})}),S.jsxs("div",{className:`${vt.mobileChatOverlay} ${$?vt.mobileChatOverlayVisible:""}`,children:[d&&S.jsxs("div",{className:vt.mobileLoadingOverlay,children:[S.jsx("div",{className:vt.mobileLoadingSpinner}),S.jsxs("div",{className:vt.mobileLoadingLabel,children:[J("ui.loadingChat"),h>0?` (${h})`:""]})]}),S.jsx(no,{theme:{algorithm:Ep.darkAlgorithm,token:{colorBgContainer:"#111",colorBgLayout:"#0a0a0a",colorBgElevated:"#1a1a1a",colorBorder:"#2a2a2a"}},children:S.jsx("div",{className:vt.mobileChatInner,children:S.jsx(jM,{requests:p,mainAgentSessions:c,userProfile:this.state.userProfile,collapseToolResults:this.state.collapseToolResults,expandThinking:this.state.expandThinking,onViewRequest:null,scrollToTimestamp:null,onScrollTsDone:()=>{},cliMode:!1,terminalVisible:!1,mobileChatVisible:this.state.mobileChatVisible})})})]}),S.jsx("div",{className:`${vt.mobileStatsOverlay} ${this.state.mobileStatsVisible?vt.mobileStatsOverlayVisible:""}`,children:S.jsx("div",{className:vt.mobileStatsInner,children:S.jsx(wUe,{requests:p,visible:this.state.mobileStatsVisible,onClose:()=>this.setState({mobileStatsVisible:!1})})})}),S.jsxs("div",{className:`${vt.mobileLogMgmtOverlay} ${this.state.mobileLogMgmtVisible?vt.mobileLogMgmtOverlayVisible:""}`,children:[S.jsxs("div",{className:vt.mobileLogMgmtHeader,children:[S.jsxs("span",{className:vt.mobileLogMgmtTitle,children:[S.jsx("svg",{onClick:()=>fetch("/api/open-log-dir",{method:"POST"}),title:J("ui.openLogDir"),width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer",opacity:.7,marginRight:6,verticalAlign:"middle"},children:S.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),J("ui.importLocalLogs")]}),S.jsx("button",{className:vt.mobileLogMgmtClose,onClick:()=>this.setState({mobileLogMgmtVisible:!1,selectedLogs:new Set}),children:S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[S.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),S.jsxs("div",{className:vt.mobileLogMgmtActions,children:[S.jsx(gn,{size:"small",type:this.state.selectedLogs.size>=2?"primary":"default",disabled:this.state.selectedLogs.size<2,onClick:this.handleMergeLogs,style:this.state.selectedLogs.size<2?{color:"#666",borderColor:"#333"}:void 0,children:J("ui.mergeLogs")}),S.jsx(gn,{size:"small",icon:S.jsx(c1,{}),disabled:this.state.selectedLogs.size===0,onClick:this.handleDeleteLogs,style:this.state.selectedLogs.size===0?{color:"#666",borderColor:"#333"}:{color:"#ff4d4f",borderColor:"#ff4d4f"},children:J("ui.deleteLogs")}),S.jsx(gn,{size:"small",icon:S.jsx(o1,{spin:this.state.refreshingStats}),loading:this.state.refreshingStats,onClick:this.handleRefreshStats,children:J("ui.refreshStats")})]}),S.jsx("div",{className:vt.mobileLogMgmtBody,children:this.state.localLogsLoading?S.jsx("div",{className:vt.spinCenter,children:S.jsx(qa,{})}):(()=>{const b=this.state.localLogs[this.state.currentProject];return!b||b.length===0?S.jsx("div",{className:vt.emptyCenter,children:J("ui.noLogs")}):S.jsx(no,{theme:{algorithm:Ep.darkAlgorithm,token:{colorBgContainer:"#111",colorBgLayout:"#0a0a0a",colorBgElevated:"#1a1a1a",colorBorder:"#2a2a2a"}},children:S.jsx("div",{className:vt.logListContainer,children:this.renderLogTable(b,!0)})})})()})]}),S.jsxs("div",{className:`${vt.mobileSettingsOverlay} ${this.state.mobileSettingsVisible?vt.mobileSettingsOverlayVisible:""}`,children:[S.jsxs("div",{className:vt.mobileLogMgmtHeader,children:[S.jsx("span",{className:vt.mobileLogMgmtTitle,children:J("ui.settings")}),S.jsx("button",{className:vt.mobileLogMgmtClose,onClick:()=>this.setState({mobileSettingsVisible:!1}),children:S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[S.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),S.jsxs("div",{style:{padding:"12px 16px"},children:[S.jsx("div",{style:{fontSize:13,color:"#888",fontWeight:500,marginBottom:12},children:J("ui.chatDisplaySwitches")}),S.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 0",borderBottom:"1px solid #222"},children:[S.jsx("span",{style:{color:"#ccc",fontSize:14},children:J("ui.collapseToolResults")}),S.jsx(vc,{checked:!!this.state.collapseToolResults,onChange:this.handleCollapseToolResultsChange})]}),S.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 0",borderBottom:"1px solid #222"},children:[S.jsx("span",{style:{color:"#ccc",fontSize:14},children:J("ui.expandThinking")}),S.jsx(vc,{checked:!!this.state.expandThinking,onChange:this.handleExpandThinkingChange})]})]})]}),S.jsxs("div",{className:`${vt.mobilePromptOverlay} ${this.state.mobilePromptVisible?vt.mobilePromptOverlayVisible:""}`,children:[S.jsxs("div",{className:vt.mobileLogMgmtHeader,children:[S.jsx("span",{className:vt.mobileLogMgmtTitle,children:J("ui.userPrompt")}),S.jsx("button",{className:vt.mobileLogMgmtClose,onClick:()=>this.setState({mobilePromptVisible:!1}),children:S.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[S.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),S.jsx("div",{className:vt.mobilePromptBody,children:(()=>{const b=this.extractUserPrompts(p);return b.length===0?S.jsx("div",{style:{textAlign:"center",color:"#666",padding:"40px 20px",fontSize:14},children:J("ui.noPrompt")}):S.jsxs(S.Fragment,{children:[S.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid #222",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[S.jsxs("span",{style:{fontSize:13,color:"#888"},children:[b.length," ",J("ui.promptCountUnit")]}),S.jsx(gn,{size:"small",icon:S.jsx(bP,{}),onClick:()=>this.handleExportPromptsTxt(b),children:J("ui.exportPromptsTxt")})]}),S.jsx("div",{className:vt.mobilePromptList,children:b.map((_,x)=>S.jsxs("div",{className:vt.mobilePromptItem,children:[_.timestamp&&S.jsx("div",{className:vt.mobilePromptTimestamp,children:new Date(_.timestamp).toLocaleString()}),this.renderOriginalPrompt(_)]},x))})]})})()})]})]})]})}return S.jsxs(no,{theme:{algorithm:Ep.darkAlgorithm,token:{colorBgContainer:"#111",colorBgLayout:"#0a0a0a",colorBgElevated:"#1a1a1a",colorBorder:"#2a2a2a"}},children:[d&&S.jsx("div",{className:vt.loadingOverlay,children:S.jsxs("div",{className:vt.loadingText,children:["Loading...(",h,")"]})}),this.state.isDragging&&S.jsx("div",{className:vt.dragOverlay,children:S.jsxs("div",{className:vt.dragOverlayContent,children:[S.jsx(r6,{style:{fontSize:48}}),S.jsx("p",{children:J("ui.dragDropHint")})]})}),S.jsxs(wu,{className:vt.layout,ref:this._layoutRef,onDragOver:this._onDragOver,onDragLeave:this._onDragLeave,onDrop:this._onDrop,children:[S.jsx(wu.Header,{className:vt.header,children:S.jsx(P1,{requestCount:p.length,requests:p,viewMode:r,cacheExpireAt:o,cacheType:a,onToggleViewMode:this.handleToggleViewMode,onLangChange:this.handleLangChange,onImportLocalLogs:this.handleImportLocalLogs,isLocalLog:!!this._isLocalLog,localLogFile:this._localLogFile,projectName:this.state.projectName,collapseToolResults:this.state.collapseToolResults,onCollapseToolResultsChange:this.handleCollapseToolResultsChange,expandThinking:this.state.expandThinking,onExpandThinkingChange:this.handleExpandThinkingChange,expandDiff:this.state.expandDiff,onExpandDiffChange:this.handleExpandDiffChange,filterIrrelevant:!this.state.showAll,onFilterIrrelevantChange:this.handleFilterIrrelevantChange,updateInfo:this.state.updateInfo,onDismissUpdate:()=>this.setState({updateInfo:null}),cliMode:this.state.cliMode,terminalVisible:this.state.terminalVisible,onToggleTerminal:()=>this.setState(v=>({terminalVisible:!v.terminalVisible})),onReturnToWorkspaces:this.state.cliMode?this.handleReturnToWorkspaces:null,contextWindow:this.state.contextWindow,onNavigateCacheMsg:this.handleNavigateCacheMsg,serverCachedContent:this.state.serverCachedContent,resumeAutoChoice:this.state.resumeAutoChoice,onResumeAutoChoiceToggle:this.handleResumeAutoChoiceToggle,onResumeAutoChoiceChange:this.handleResumeAutoChoiceChange})}),S.jsxs(wu.Content,{className:vt.content,children:[r==="raw"&&(p.length===0?S.jsx("div",{className:vt.guideContainer,children:S.jsxs("div",{className:vt.guideContent,children:[S.jsx("h2",{className:vt.guideTitle,children:J("ui.guide.title")}),S.jsxs("div",{className:vt.guideStep,children:[S.jsx("div",{className:vt.guideStepNum,children:"1"}),S.jsxs("div",{className:vt.guideStepBody,children:[S.jsx("p",{className:vt.guideText,children:J("ui.guide.step1")}),S.jsx("code",{className:vt.guideCode,children:J("ui.guide.exampleQuestion")})]})]}),S.jsxs("div",{className:vt.guideStep,children:[S.jsx("div",{className:vt.guideStepNum,children:"2"}),S.jsxs("div",{className:vt.guideStepBody,children:[S.jsx("p",{className:vt.guideText,children:J("ui.guide.step2")}),S.jsx("code",{className:vt.guideCode,children:J("ui.guide.troubleshootCmd")})]})]}),S.jsxs("div",{className:vt.guideStep,children:[S.jsx("div",{className:vt.guideStepNum,children:"3"}),S.jsxs("div",{className:vt.guideStepBody,children:[S.jsx("p",{className:vt.guideText,children:J("ui.guide.step3")}),S.jsx("code",{className:vt.guideCode,children:"npm install -g @anthropic-ai/claude-code"})]})]})]})}):S.jsxs("div",{ref:this.mainContainerRef,className:vt.mainContainer,children:[S.jsxs("div",{className:vt.leftPanel,style:{width:l},children:[S.jsxs("div",{className:vt.leftPanelHeader,children:[S.jsx("span",{children:J("ui.requestList")}),S.jsx("span",{className:vt.leftPanelCount,children:J("ui.totalRequests",{count:p.length})})]}),S.jsx("div",{className:vt.leftPanelBody,children:S.jsx(Ewe,{requests:p,selectedIndex:i,scrollCenter:this.state.scrollCenter,onSelect:this.handleSelectRequest,onScrollDone:this.handleScrollDone,cacheLossMap:this._cacheLossMap})})]}),S.jsx(AYe,{onResize:this.handleResize}),S.jsx("div",{className:vt.rightPanel,children:S.jsx(LCe,{request:g,requests:p,selectedIndex:i,currentTab:s,onTabChange:this.handleTabChange,onViewInChat:this.handleViewInChat,expandDiff:this.state.expandDiff,pendingCacheHighlight:this.state.pendingCacheHighlight,onCacheHighlightDone:this.handleCacheHighlightDone})})]})),S.jsx("div",{style:{display:r==="chat"?"flex":"none",height:"100%",flexDirection:"column"},children:S.jsx(jM,{requests:p,mainAgentSessions:c,userProfile:this.state.userProfile,collapseToolResults:this.state.collapseToolResults,expandThinking:this.state.expandThinking,onViewRequest:this.handleViewRequest,scrollToTimestamp:this.state.chatScrollToTs,onScrollTsDone:this.handleScrollTsDone,cliMode:this._isLocalLog?!1:this.state.cliMode,terminalVisible:this._isLocalLog?!1:this.state.terminalVisible,pendingUploadPaths:this.state.pendingUploadPaths,onUploadPathsConsumed:this.handleUploadPathsConsumed})})]}),S.jsx("div",{className:vt.footer,children:S.jsxs("div",{className:vt.footerRight,children:[S.jsx("span",{className:vt.footerText,children:J("ui.footer.starRequest")}),S.jsxs("a",{href:"https://github.com/weiesky/cc-viewer",target:"_blank",rel:"noopener noreferrer",className:vt.footerLink,children:[S.jsx("svg",{className:vt.footerIcon,viewBox:"0 0 16 16",fill:"currentColor",children:S.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"})}),"GitHub",this.state.githubStars!=null?` ★ ${this.state.githubStars}`:""]}),S.jsx("span",{className:vt.footerDivider,children:"|"}),S.jsx("a",{href:"dingtalk://dingtalkclient/action/sendmsg?dingtalk_id=sthk5es",className:vt.footerLink,children:J("ui.footer.contact")})]})})]}),S.jsx(Sr,{title:J("ui.resume.title"),open:this.state.resumeModalVisible,closable:!1,maskClosable:!1,keyboard:!1,footer:S.jsxs("div",{children:[S.jsxs("div",{style:{textAlign:"right",marginBottom:8},children:[S.jsx(gn,{type:"primary",onClick:()=>this.handleResumeChoice("continue"),style:{marginRight:8},children:J("ui.resume.continue")},"continue"),S.jsx(gn,{onClick:()=>this.handleResumeChoice("new"),children:J("ui.resume.new")},"new")]}),S.jsx("div",{style:{textAlign:"left"},children:S.jsx(ju,{checked:this.state.resumeRememberChoice,onChange:v=>this.setState({resumeRememberChoice:v.target.checked}),style:{opacity:.6},children:S.jsx("span",{style:{opacity:.6},children:J("ui.resume.remember")})})})]}),children:S.jsx("p",{children:J("ui.resume.message",{file:this.state.resumeFileName})})}),S.jsxs(Sr,{title:S.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[S.jsx("svg",{onClick:()=>fetch("/api/open-log-dir",{method:"POST"}),title:J("ui.openLogDir"),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer",opacity:.7,flexShrink:0},onMouseEnter:v=>v.currentTarget.style.opacity="1",onMouseLeave:v=>v.currentTarget.style.opacity="0.7",children:S.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),J("ui.importLocalLogs")]}),open:this.state.importModalVisible,onCancel:this.handleCloseImportModal,footer:null,width:1e3,styles:{body:{overflow:"hidden"}},children:[S.jsxs("div",{className:vt.modalActions,children:[S.jsx(gn,{icon:S.jsx(r6,{}),onClick:this.handleLoadLocalJsonlFile,children:J("ui.loadLocalJsonl")}),S.jsx(gn,{size:"small",type:this.state.selectedLogs.size>1?"primary":"default",disabled:this.state.selectedLogs.size<2,onClick:this.handleMergeLogs,style:{marginLeft:8},children:J("ui.mergeLogs")}),S.jsx(gn,{size:"small",danger:!0,icon:S.jsx(c1,{}),disabled:this.state.selectedLogs.size===0,onClick:this.handleDeleteLogs,style:{marginLeft:8},children:J("ui.deleteLogs")}),S.jsx(gn,{size:"small",icon:S.jsx(o1,{spin:this.state.refreshingStats}),loading:this.state.refreshingStats,onClick:this.handleRefreshStats,style:{marginLeft:8},children:J("ui.refreshStats")})]}),this.state.localLogsLoading?S.jsx("div",{className:vt.spinCenter,children:S.jsx(qa,{})}):(()=>{const v=this.state.localLogs[this.state.currentProject];return!v||v.length===0?S.jsx("div",{className:vt.emptyCenter,children:J("ui.noLogs")}):S.jsx("div",{className:vt.logListContainer,children:this.renderLogTable(v,!1)})})()]})]})}};tt(gO,"COMMAND_TAGS",new Set(["command-name","command-message","command-args","local-command-caveat","local-command-stdout"]));let q2=gO;const KDe=XG.createRoot(document.getElementById("root"));KDe.render(S.jsx(q2,{}));
|
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-DlUAHyh3.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-DbVOM09a.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|