@kimicode/cli 1.0.39 → 1.0.40
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.
- package/LICENSE.md +12 -0
- package/README.md +427 -31
- package/bin/stt/requirements.txt +32 -0
- package/bin/stt/stt_server.py +619 -0
- package/bin/tts/requirements.txt +21 -0
- package/bin/tts/tts_server.py +404 -0
- package/cli-wrapper.cjs +4 -0
- package/llms.txt +88 -0
- package/package.json +30 -11
- package/web/dist/assets/AssistantsView-BiUiWjhF.js +1 -0
- package/web/dist/assets/AutomationView-Dcf_yNaI.js +1 -0
- package/web/dist/assets/ChannelConfigView-BLnxsMGm.js +8 -0
- package/web/dist/assets/ConnectorsView-CX3E6X6c.js +1 -0
- package/web/dist/assets/DesignSystemView--x-P-lpD.js +1 -0
- package/web/dist/assets/Drawer-CjAgqH3B.js +1 -0
- package/web/dist/assets/{FileTreeView-hBtHBbAV.js → FileTreeView-Chb_fzTK.js} +3 -3
- package/web/dist/assets/HookConfigView-EafYlWdN.js +1 -0
- package/web/dist/assets/InputArea-BbHslX7b.js +50 -0
- package/web/dist/assets/ModelsView-CGN5Nljr.js +1 -0
- package/web/dist/assets/PluginsView-CDiJgvI8.js +2 -0
- package/web/dist/assets/ProjectsView-C5Usmwqy.js +1 -0
- package/web/dist/assets/SessionGrid-Drxg0r_u.js +4 -0
- package/web/dist/assets/SettingsModal-Cmts6aBG.js +10 -0
- package/web/dist/assets/Skeleton-Dsk6B0U3.js +1 -0
- package/web/dist/assets/SkillsView-TEDR_3XX.js +1 -0
- package/web/dist/assets/TemplatesTab-DtN5Kdgh.js +1 -0
- package/web/dist/assets/ToolsView-VukZnIt1.js +1 -0
- package/web/dist/assets/VizCardsSkeleton-C_GaEfXd.js +1 -0
- package/web/dist/assets/abnfDiagram-YUKMZFIV-BIFw6B_N.js +1 -0
- package/web/dist/assets/arc-BZQ951h9.js +1 -0
- package/web/dist/assets/architectureDiagram-47P4ROYG-BP5qiXzf.js +36 -0
- package/web/dist/assets/blockDiagram-E7TT5TSB-DtRpcE7F.js +140 -0
- package/web/dist/assets/c4Diagram-CRA5TL53-Gdzn8UBh.js +38 -0
- package/web/dist/assets/channel-BND6_KSH.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-3U6HMlsm.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-CYl9mwa-.js +15 -0
- package/web/dist/assets/chunk-7TKQ45FW-Dn6ktcY5.js +1 -0
- package/web/dist/assets/chunk-AW2ZBBNX-De0QX6p1.js +88 -0
- package/web/dist/assets/chunk-FVRAUYC3-CpXDfvz4.js +2 -0
- package/web/dist/assets/chunk-HTAEGDNF-D1KDvcDd.js +1 -0
- package/web/dist/assets/chunk-JWPE2WC7-umm4A-fq.js +1 -0
- package/web/dist/assets/chunk-KQW6MTUR-JYH94hpE.js +1 -0
- package/web/dist/assets/chunk-XXDRQBXY-CSlCFByc.js +1 -0
- package/web/dist/assets/classDiagram-v2-K4WV4PDN-DnFwS0qN.js +217 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-BxUTUyep.js +1 -0
- package/web/dist/assets/cynefin-EF2NZ3EQ-CiMvulJr.js +141 -0
- package/web/dist/assets/cynefinDiagram-3GCD6N5R-DuXFORdW.js +62 -0
- package/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
- package/web/dist/assets/dagre-W4DXFKR2-DzMZHXci.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-2UJZ2QOL-B6tO5G1v.js +200 -0
- package/web/dist/assets/diagram-OVF4WLC6-DRZt8tGc.js +24 -0
- package/web/dist/assets/diagram-PFPMY2P6-DGh6IecR.js +30 -0
- package/web/dist/assets/diagram-UMYRVEAY-BLbnt0yT.js +24 -0
- package/web/dist/assets/diagram-YEKJPTXX-C-S5DVhj.js +41 -0
- package/web/dist/assets/diagram-ZIFT7M5P-JrGHTWbo.js +3 -0
- package/web/dist/assets/ebnfDiagram-VR2GEFS7-DPXA-YOi.js +1 -0
- package/web/dist/assets/elk-IJKZMXRS-CINeWt2W.js +27 -0
- package/web/dist/assets/erDiagram-O2IAPWRE-PPaHmqA1.js +99 -0
- package/web/dist/assets/flowDiagram-OXPTDLAJ-t-u0QXEA.js +213 -0
- package/web/dist/assets/ganttDiagram-R7TSEDQI-Bw49ZD_b.js +292 -0
- package/web/dist/assets/gitGraphDiagram-XJZIOB7I-BAfOqeeg.js +106 -0
- package/web/dist/assets/graph-Bn3Yngep.js +1 -0
- package/web/dist/assets/{icons-BxNxyk-c.js → icons-Bm_ZzSAy.js} +320 -160
- package/web/dist/assets/index-CeeLdENM.js +677 -0
- package/web/dist/assets/index-Ceez9lYk.css +1 -0
- package/web/dist/assets/infoDiagram-5W2HQ5XZ-Bv4RBxYW.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/ishikawaDiagram-K3B6WC7H-DEpj0bRp.js +70 -0
- package/web/dist/assets/journeyDiagram-COXZFDF6-MJu84Iiz.js +139 -0
- package/web/dist/assets/kanban-definition-P3RFRI5V-mlYSRALK.js +89 -0
- package/web/dist/assets/linear-5j9gt8MV.js +1 -0
- package/web/dist/assets/{markdown-B2L4Mq-x.js → markdown-BWXjRrSw.js} +8 -8
- package/web/dist/assets/mermaid.core-DLb6eAON.js +314 -0
- package/web/dist/assets/mindmap-definition-LZFPQGKD-C9v_57Ex.js +96 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/{panels-P_I7Q72_.js → panels-BQOvnbWH.js} +1 -1
- package/web/dist/assets/pegDiagram-BGZESJAR-KQP26s3-.js +1 -0
- package/web/dist/assets/pieDiagram-CAPJLFHJ-DN3RQ_ih.js +39 -0
- package/web/dist/assets/profileChange-B7TaQ18u.js +1 -0
- package/web/dist/assets/quadrantDiagram-GDMTTRAM-BpL_ZL76.js +7 -0
- package/web/dist/assets/railroadDiagram-SM67HX2B-DZ-fPU85.js +1 -0
- package/web/dist/assets/{react-vendor-B2V_5iSS.js → react-vendor-C0HIWSpf.js} +1 -1
- package/web/dist/assets/requirementDiagram-X7JNWC4A-mKPGj64L.js +84 -0
- package/web/dist/assets/sankeyDiagram-UM26HJRW-Bs4xfjQP.js +40 -0
- package/web/dist/assets/sequenceDiagram-ZO4K6R2Y-BjUmzZaO.js +169 -0
- package/web/dist/assets/sizeCapture-INFHLROL-BXBM3j_Q.js +1 -0
- package/web/dist/assets/{state-0T92JV0u.js → state-Kfon1nTr.js} +1 -1
- package/web/dist/assets/stateDiagram-v2-TBUQTH76-FGgFDGUU.js +291 -0
- package/web/dist/assets/sttLanguages-C7kVulzY.js +1 -0
- package/web/dist/assets/swimlanes-N4OXWK64-wkd_n4HU.js +1 -0
- package/web/dist/assets/swimlanesDiagram-K3J5GTZL-CKnwEuq_.js +8 -0
- package/web/dist/assets/timeline-definition-YOQAKGHF-DyBln1jw.js +120 -0
- package/web/dist/assets/usecaseDiagram-VIAY4XPW-Cqis3XHX.js +370 -0
- package/web/dist/assets/vennDiagram-BLWOH2XV-BaiFLOVS.js +34 -0
- package/web/dist/assets/wardleyDiagram-YMQ3BMBF-C4CzpJto.js +78 -0
- package/web/dist/assets/xychartDiagram-TAQBALBS-Dp1hfe3-.js +7 -0
- package/web/dist/figma-demo/product-1.jpg +0 -0
- package/web/dist/figma-demo/product-2.jpg +0 -0
- package/web/dist/figma-demo/trail-1.jpg +0 -0
- package/web/dist/figma-demo/trail-2.jpg +0 -0
- package/web/dist/figma-demo/trail-3.jpg +0 -0
- package/web/dist/index.html +8 -8
- package/web/dist/assets/AssistantsView-0aLB_cG6.js +0 -1
- package/web/dist/assets/AutomationView-CAMjPhJ2.js +0 -1
- package/web/dist/assets/ChannelConfigView-FcioeeYb.js +0 -8
- package/web/dist/assets/ConnectorsView-DERP7zAW.js +0 -1
- package/web/dist/assets/HookConfigView-NModtSB8.js +0 -1
- package/web/dist/assets/ModelsView-BPpO50C_.js +0 -1
- package/web/dist/assets/PluginsView-D0NE7zrt.js +0 -1
- package/web/dist/assets/ProjectsView-PIv7Gx4q.js +0 -1
- package/web/dist/assets/SessionGrid-BsDL3lov.js +0 -47
- package/web/dist/assets/SettingsModal-DdebvEmv.js +0 -10
- package/web/dist/assets/SkillsView-BNoigImJ.js +0 -1
- package/web/dist/assets/TemplatesTab-D8Pa68fj.js +0 -1
- package/web/dist/assets/ToolsView-NY-yk5YX.js +0 -1
- package/web/dist/assets/WorkspaceDirPicker-C5knnArH.js +0 -6
- package/web/dist/assets/index-DaiVo1RY.css +0 -1
- package/web/dist/assets/index-RB5ffy32.js +0 -620
- package/web/dist/assets/profileChange-C7Jg9C61.js +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var ut=Object.defineProperty;var ht=(t,r,e)=>r in t?ut(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var ye=(t,r,e)=>ht(t,typeof r!="symbol"?r+"":r,e);import{j as n}from"./markdown-BWXjRrSw.js";import{a as d,aN as mt,aO as ft,aP as pt,aQ as xt,S as gt,X as le,A as pe,a0 as bt,f as vt,aR as kt,m as yt,u as jt,aA as St,x as wt,aS as ie,ab as Nt,C as Ie,k as Ct,y as Tt,o as De,E as It,h as Mt,s as Et,ak as At,a4 as Rt,e as Ot,aT as _t,aU as zt,M as Dt,aV as Ft}from"./icons-Bm_ZzSAy.js";import{b as Pt,t as $t,v as Lt,s as Ht,T as qt,P as Fe,a as Bt,c as Kt,C as Vt,I as Wt}from"./InputArea-BbHslX7b.js";import{a2 as Ee,a3 as Ut,a4 as Gt,u as Z,r as Xt,a5 as Pe,a6 as Jt,A as ae,w as ne,a7 as st,a8 as nt,a9 as Ae,aa as Qt,ab as Yt,ac as Zt,ad as es,ae as ts,af as $e,B as ss,ag as fe,ah as Le,ai as ns,a as xe,l as rs,Y as as}from"./index-CeeLdENM.js";import{c as is}from"./state-Kfon1nTr.js";import{P as He}from"./profileChange-B7TaQ18u.js";import{a as os,i as ls}from"./sttLanguages-C7kVulzY.js";import"./Skeleton-Dsk6B0U3.js";import"./VizCardsSkeleton-C_GaEfXd.js";import"./react-vendor-C0HIWSpf.js";import"./panels-BQOvnbWH.js";function ce(t){return t.recordId!==void 0?t.recordId:t.callId!==void 0?`${t.kind}\0call\0${t.callId}`:t.sourceSeq!==void 0?`${t.kind}\0seq\0${t.sourceSeq}`:`${t.kind}\0index\0${t.index}`}function Re(t){return Ee(t===null?null:t*1e3)}const cs=2048,ds=512;function us(t){return t.replace(/```[^\n]*\n([\s\S]*?)```/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/^#{1,6}\s+/gm,"").replace(/^[ \t]*[-*+]\s+/gm,"").replace(/^[ \t]*>\s?/gm,"").replace(/(\*\*|__)(.*?)\1/g,"$2").replace(/(\*|_)(.*?)\1/g,"$2").replace(/~~(.*?)~~/g,"$1")}function ge(t){const r=t.slice(0,cs),e=us(r).replace(/\s+/g," ").trim(),s=e.slice(0,ds).trimEnd();return r.length<t.length||s.length<e.length?`${s}…`:s}function qe(t){if(Number.isFinite(t))return Re(t)}function ue(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function hs(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return""}}function Me(t){if(typeof t=="string")return t;if(t==null)return"";try{return JSON.stringify(t,null,2)}catch{return String(t)}}function ms(t){if(t.status==="error")return{result:t.result===void 0?"error":Me(t.result)};const r=Me(t.result);return r===""?{result:"No output"}:{result:"",resultPreviewMarkdown:r}}function fs(t,r){var i;const e=(r==null?void 0:r.get(t.id))??null,s=((i=t.summary)==null?void 0:i.durationMs)!==void 0?(e??t.timestamp)+t.summary.durationMs:null,a=e!==null||s!==null;if(a)return{timingRecorded:a,stepStartTime:t.timestamp,firstTokenTime:e,completedTime:s,usageProvided:!1,outputTokens:null}}function ps(t,r,e){var o;const s=t.thinkingBlocks?t.thinkingBlocks.map(l=>l.text).join(`
|
|
2
|
+
`):t.thinking??"",a=fs(t,e),i=(o=t.summary)==null?void 0:o.durationMs;return{index:r,kind:"message",text:"",...t.content===""?{}:{previewMarkdown:t.content},sourceSeq:r,inputDetail:t.content,...s===""?{}:{thinkingDetail:s},...a===void 0?{}:{assistantMetrics:a},timeSeconds:i===void 0?null:i/1e3,startedAt:t.timestamp}}function Be(t,r){const e=hs(t.args),s=Me(t.result),a=ms(t);return{index:r,kind:"tool",text:t.name,...e===""?{}:{previewMarkdown:e},sourceSeq:r,callId:t.id,...e===""?{}:{inputDetail:e},...s===""?{}:{outputDetail:s},...a,isError:t.status==="error",timeSeconds:t.duration===void 0?null:t.duration/1e3,startedAt:t.timestamp}}function Ke(t,r){return{index:r,kind:"user",text:"",...t.content===""?{}:{previewMarkdown:t.content},sourceSeq:r,inputDetail:t.content,opensTurn:!0,timeSeconds:0,startedAt:t.timestamp}}function xs(t,r){const e=[t.originalCount!==void 0?`original ${t.originalCount} msgs`:"",t.compressedCount!==void 0?`compressed ${t.compressedCount} msgs`:"",t.tokensSaved!==void 0?`freed ${t.tokensSaved} tokens`:""].filter(Boolean).join(", ");return{index:r,kind:"compacted",text:"Context compressed",sourceSeq:t.seq,...e===""?{}:{outputDetail:e},timeSeconds:0,startedAt:t.timestamp}}function gs(t){var a;const r=[],e=[];for(const i of t)i.absTime===null||!Number.isFinite(i.absTime)||(e.push(i.absTime),i.cell.kind==="tool"&&i.cell.timeSeconds!==null&&Number.isFinite(i.cell.timeSeconds)&&e.push(i.absTime+i.cell.timeSeconds*1e3));if(e.length>=2){const i=qe((Math.max(...e)-Math.min(...e))/1e3);i!==void 0&&r.push(i)}else if(e.length===1){const i=(a=t.find(l=>l.absTime===e[0]))==null?void 0:a.cell.timeSeconds,o=i!=null?qe(i):void 0;o!==void 0&&r.push(o)}const s=new Map;for(const i of t)i.toolName===void 0||i.cell.kind!=="tool"||s.set(i.toolName,(s.get(i.toolName)??0)+1);for(const[i,o]of s)r.push(o>1?`${i}×${o}`:i);return r.length===0?void 0:r.join(" ")}function Ve(t,r){const e=r.groups.map(({title:s,laid:a})=>{const i=gs(a);return{title:s,...i!==void 0?{description:i}:{},cells:a.map(o=>o.cell)}});return{turn:t,groups:e}}function We(t){return Math.min(...t.groups.flatMap(r=>r.cells.map(e=>e.index)),Number.POSITIVE_INFINITY)}function bs(t){const{messages:r,compacted:e=[],ttft:s}=t,a=new Map,i=[];let o=0,l=0,c=null;const u=x=>{let v=a.get(x);return v===void 0&&(v={groups:[]},a.set(x,v)),v},p=(x,v)=>{const k=u(x).groups,C=k[k.length-1];if((C==null?void 0:C.title)==="Message"){C.laid.push(v);return}k.push({title:"Message",laid:[v]})},f=(x,v,k)=>{if(k.length===0)return;const C=u(x).groups,h=`Step ${v}`,y=C.find(T=>T.title===h);if(y!==void 0){y.laid.push(...k);return}C.push({title:h,laid:[...k]})},g=[...r.map(x=>({kind:"message",message:x})),...e.map(x=>({kind:"compacted",record:x}))].sort((x,v)=>{const k=x.kind==="message"?x.message.timestamp:x.record.timestamp,C=v.kind==="message"?v.message.timestamp:v.record.timestamp;return k-C});for(const x of g){if(x.kind==="compacted"){const h=xs(x.record,++o);i.push({groups:[{title:`Compaction ${x.record.seq}`,laid:[{absTime:ue(x.record.timestamp),cell:h}]}]});continue}const v=x.message;if(Ut(v)){l+=1;const h=Ke(v,++o);p(l,{absTime:ue(v.timestamp),cell:h});continue}const k=l>0?l:c??1,C=Gt(v)?Ke(v,++o):ps(v,++o,s);p(k,{absTime:ue(v.timestamp),cell:C}),c=k;for(const h of v.toolCalls??[]){const y=Be(h,++o);p(k,{absTime:ue(h.timestamp),toolName:h.name,callId:h.id,cell:y})}for(const[h,y]of(v.steps??[]).entries()){const T=(y.toolCalls??[]).map(I=>{const N=Be(I,++o);return{absTime:ue(I.timestamp),toolName:I.name,callId:I.id,cell:N}});f(k,h+1,T)}}return[...[...a.entries()].map(([x,v])=>Ve(x,v)),...i.map(x=>Ve(null,x))].sort((x,v)=>We(x)-We(v))}function ke(t){if(t.text!=="")return t.text;if(t.previewMarkdown!==void 0){const r=ge(t.previewMarkdown);if(r!=="")return r}if(t.result!==void 0&&t.result!=="")return t.result;if(t.resultPreviewMarkdown!==void 0){const r=ge(t.resultPreviewMarkdown);if(r!=="")return r}return t.kind}function je(t){return Ee(t)}function rt(t){return t==="tool"||t==="subtool"?2:t==="message"||t==="compacted"?1:0}function Ue(t){return t!=null&&Number.isFinite(t)}function vs(t){if(!Ue(t.startedAt))return null;const r=Ue(t.timeSeconds)?Math.max(0,t.timeSeconds*1e3):0;return{start:t.startedAt,end:t.startedAt+r}}function at(t,r="sequence"){if(r!=="sequence")return ks(t,r==="duration");const e=[],s=[];for(const a of t){const i=a.groups.flatMap(o=>o.cells.filter(l=>l.requestOnly!==!0));i.length!==0&&(a.turn!==null&&s.push({turn:a.turn,time:e.length}),e.push(...i.map((o,l)=>({start:e.length+l,end:e.length+l+1,index:o.index,isError:o.isError===!0,kind:o.kind,label:o.text,lane:rt(o.kind)}))))}return e.length===0?null:{start:0,end:e.length,spans:e,turnBoundaries:s}}function ks(t,r){const e=t.flatMap(u=>{const p=u.groups.flatMap(f=>f.cells.flatMap(g=>{if(g.requestOnly===!0)return[];const x=vs(g);return x===null?[]:[{...x,index:g.index,isError:g.isError===!0,kind:g.kind,label:g.text,lane:rt(g.kind)}]}));return p.length===0?[]:[{turn:u.turn,rawSpans:p}]}),s=e.flatMap(u=>u.rawSpans);if(s.length===0)return null;const a=new Map;let i=0,o=null;for(const u of[...s].sort((p,f)=>p.start-f.start||p.end-f.end))r&&o!==null&&u.start>o&&(i+=u.start-o),a.set(u,i),o=o===null?u.end:Math.max(o,u.end);const l=[],c=[];for(const u of e){const p=u.rawSpans.map(f=>{const g=a.get(f)??0;return{...f,start:f.start-g,end:f.end-g}});l.push(...p),u.turn!==null&&c.push({turn:u.turn,time:Math.min(...p.map(f=>f.start))})}return{start:Math.min(...l.map(u=>u.start)),end:Math.max(...l.map(u=>u.end)),spans:l,turnBoundaries:c}}function ys(t,r,e="sequence"){const s=at(t,e);return new Set(s==null?void 0:s.spans.filter(a=>a.start<=r.end&&a.end>=r.start).map(a=>a.index))}function js(t,r){return t.length===r.length&&t.every((e,s)=>e===r[s])}function Ss(t){if(t.previewMarkdown===void 0)return"";const r=ge(t.previewMarkdown);return t.text===""?r:r===""?t.text:`${t.text} · ${r}`}function ws(t){return t.resultPreviewMarkdown===void 0?t.result??"":ge(t.resultPreviewMarkdown)}function Ns(t,r,e){const s=[...e.sourceBlocks??[],...e.outputBlocks??[]];return[t===null?"between turns":`turn ${t}`,r,e.kind,e.kind==="message"?"assistant":"",e.text,e.previewMarkdown??"",e.inputDetail??"",e.outputDetail??"",e.thinkingDetail??"",e.schemaDetail??"",e.result??"",e.resultPreviewMarkdown??"",e.callId??"",...s.flatMap(a=>[a.type,a.content,a.callId??"",a.toolName??"",a.imageAlt??""])]}class Cs{constructor(){ye(this,"entries",new Map);ye(this,"layouts")}update(r){if(this.layouts===r)return!1;this.layouts=r;const e=new Set;for(const s of r)for(const a of s)for(const i of a.groups)for(const o of i.cells){if(o.requestOnly===!0)continue;const l=ce(o),c=Ns(a.turn,i.title,o),u=this.entries.get(l),p=u!==void 0&&js(u.sources,c)?u:{sources:c,text:[...c,Ss(o),ws(o)].join(`
|
|
3
|
+
`).toLocaleLowerCase()};this.entries.set(l,p),e.add(l)}for(const s of this.entries.keys())e.has(s)||this.entries.delete(s);return!0}search(r){const e=r.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);if(e.length===0)return null;const s=new Set;for(const[a,i]of this.entries)e.every(o=>i.text.includes(o))&&s.add(a);return s}}const Ts=d.memo(function({actualDuration:r,onActualDurationChange:e,allTurnsCollapsed:s,onToggleAllTurns:a,allAssistantsCollapsed:i,onToggleAllAssistants:o,searchQuery:l,onSearchQueryChange:c}){const{t:u}=Z();return n.jsxs("div",{className:"flex h-9 shrink-0 items-center gap-1 border-b border-dark-border/40 px-2",role:"toolbar",children:[n.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":r,title:u(r?"trajectory.toolbar.equalWidth":"trajectory.toolbar.actualDuration"),onClick:()=>e(!r),children:[n.jsx(mt,{size:13}),u("trajectory.toolbar.duration")]}),n.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":s,title:u(s?"trajectory.toolbar.expandTurns":"trajectory.toolbar.collapseTurns"),onClick:a,children:[s?n.jsx(ft,{size:13}):n.jsx(pt,{size:13}),u("trajectory.toolbar.turns")]}),n.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":i,title:u(i?"trajectory.toolbar.expandCalls":"trajectory.toolbar.collapseCalls"),onClick:o,children:[n.jsx(xt,{size:13}),u("trajectory.toolbar.calls")]}),n.jsx("div",{className:"ml-auto flex min-w-0 flex-1 items-center justify-end",children:n.jsxs("div",{className:"relative flex w-56 items-center",children:[n.jsx(gt,{size:12,className:"pointer-events-none absolute left-2 text-dark-muted/50"}),n.jsx("input",{type:"search",className:"h-7 w-full rounded border border-dark-border/40 bg-dark-surface/60 pl-7 pr-2 text-xs text-dark-text outline-none placeholder:text-dark-muted/40 focus:border-accent-blue/50","aria-label":u("trajectory.toolbar.search"),placeholder:u("trajectory.toolbar.searchPlaceholder"),value:l,onChange:p=>c(p.currentTarget.value)})]})})]})}),Is=3,Ms=500;function Es(t){const r=t==null?void 0:t.stepStartTime,e=t==null?void 0:t.firstTokenTime,s=t==null?void 0:t.completedTime;return(t==null?void 0:t.timingRecorded)!==!0||typeof r!="number"||typeof e!="number"||typeof s!="number"||!Number.isFinite(r)||!Number.isFinite(e)||!Number.isFinite(s)||e<r||s<e?{}:{ttftMs:e-r,decodingMs:s-e}}function As(t){const r=t.timeSeconds===null||!Number.isFinite(t.timeSeconds)?void 0:Math.max(0,t.timeSeconds*1e3),e=t.startedAt===null||!Number.isFinite(t.startedAt)?void 0:t.startedAt;return{...r===void 0?{}:{durationMs:r},...e===void 0?{}:{startedAt:e},...Es(t.assistantMetrics)}}function Rs(t){switch(t){case"system":return"SYSTEM";case"user":return"USER";case"context":return"CONTEXT";case"compacted":return"COMPACTED";case"message":return"ASSISTANT";case"tool":return"TOOL";case"subtool":return"SUBTOOL"}}function Se(t){const r=new Date(t),e=a=>String(a).padStart(2,"0"),s=a=>String(a).padStart(3,"0");return`${e(r.getHours())}:${e(r.getMinutes())}:${e(r.getSeconds())}.${s(r.getMilliseconds())}`}function Os(t,r){const e=Rs(t);if(r===void 0)return e;const s=r.durationMs===void 0?null:`Total ${je(r.durationMs)}`,a=r.startedAt===void 0?null:r.durationMs===void 0?`Started ${Se(r.startedAt)}`:`${Se(r.startedAt)} → ${Se(r.startedAt+r.durationMs)}`,i=r.ttftMs===void 0||r.decodingMs===void 0?null:`TTFT ${je(r.ttftMs)} · Decoding ${je(r.decodingMs)}`,o=[s,i].filter(l=>l!==null).join(" · ");return[e,a,o].filter(l=>l!==null&&l!=="").join(`
|
|
4
|
+
`)}function _s(t,r){return t<=r?{start:t,end:r}:{start:r,end:t}}function zs(t){return Math.min(1,Math.max(0,t))}const Ds=d.memo(function({turns:r,mode:e,range:s,selectedIndex:a=null,searchMatchIndexes:i=null,onRangeChange:o,onRecordSelect:l}){const c=d.useMemo(()=>at(r,e),[e,r]),u=d.useMemo(()=>new Map(r.flatMap(b=>b.groups.flatMap(M=>M.cells.map(_=>[_.index,As(_)])))),[r]),p=d.useMemo(()=>new Map(r.flatMap(b=>b.groups.flatMap(M=>M.cells.map(_=>[_.index,ke(_)])))),[r]),f=d.useRef(null),g=d.useRef(null),[x,v]=d.useState(null),[k,C]=d.useState(null),h=d.useRef(null),[y,T]=d.useState(null);if(d.useEffect(()=>{c!==null&&s!==null&&(s.end<c.start||s.start>c.end)&&o(null)},[c,o,s]),d.useEffect(()=>{c!==null&&T(b=>b!==null&&(b.end<c.start||b.start>c.end)?null:b)},[c]),c===null)return n.jsxs("div",{className:"traj-root","data-empty":"",children:[n.jsxs("div",{className:"traj-labels","aria-hidden":"true",children:[n.jsx("span",{children:"Input"}),n.jsx("span",{children:"Model"}),n.jsx("span",{children:"Tools"})]}),n.jsx("div",{className:"traj-track"})]});const I=Math.max(1,c.end-c.start),N=(y==null?void 0:y.start)??c.start,O=y===null?I:Math.max(1,y.end-y.start),D=b=>{const M=f.current;if(!M)return 0;const _=M.getBoundingClientRect();return zs((b-_.left)/Math.max(1,_.width))},E=b=>N+b*O,K=b=>{if(b.button===2){o(null);return}const _=b.target.closest("[data-timeline-record-index]"),$=_===null?null:Number(_.dataset.timelineRecordIndex);if($!==null&&Number.isFinite($)){l==null||l($);return}g.current={pointerId:b.pointerId,anchorFraction:D(b.clientX),anchorClientX:b.clientX,recordIndex:null},b.currentTarget.setPointerCapture(b.pointerId)},P=b=>{const M=g.current;if(M!==null&&b.pointerId===M.pointerId){const G=D(b.clientX);if(Math.abs(b.clientX-M.anchorClientX)>=Is){const Q=E(M.anchorFraction),Y=E(G);v(_s(Q,Y))}return}const _=D(b.clientX),$=b.target.closest("[data-timeline-record-index]"),V=$===null?null:Number($.dataset.timelineRecordIndex);h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{C({fraction:_,recordIndex:Number.isFinite(V)?V:null})},Ms)},j=b=>{const M=g.current;M===null||b.pointerId!==M.pointerId||(g.current=null,x!==null&&(o(x),v(null)))},R=b=>{var M;((M=g.current)==null?void 0:M.pointerId)===b.pointerId&&(g.current=null,v(null))},L=b=>{if(c===null)return;const M=D(b.clientX),_=E(M),$=b.deltaY<0?.75:1.35,V=Math.min(I,Math.max(1,O*$)),G=Math.min(Math.max(_-V/2,c.start),c.end-V);T({start:G,end:G+V})},H=d.useRef(()=>{});H.current=L,d.useEffect(()=>{const b=f.current;if(!b)return;const M=_=>{_.preventDefault(),H.current(_)};return b.addEventListener("wheel",M,{passive:!1}),()=>b.removeEventListener("wheel",M)},[c]);const z=x??s,J=k==null?void 0:k.recordIndex;return n.jsxs("div",{className:"traj-root",children:[n.jsxs("div",{className:"traj-labels","aria-hidden":"true",children:[n.jsx("span",{children:"Input"}),n.jsx("span",{children:"Model"}),n.jsx("span",{children:"Tools"})]}),n.jsxs("div",{ref:f,className:"traj-track",role:"slider","aria-label":"Trajectory timeline",tabIndex:0,onKeyDown:b=>{b.key==="Escape"&&o(null)},onPointerDown:K,onPointerMove:P,onPointerUp:j,onPointerCancel:R,onPointerLeave:()=>{h.current&&clearTimeout(h.current),h.current=null,g.current===null&&C(null)},onDoubleClick:b=>{b.preventDefault(),o(null)},onContextMenu:b=>{b.preventDefault(),o(null)},children:[k!==null&&k.recordIndex===null&&x===null&&n.jsx("div",{className:"traj-hoverLine","aria-hidden":"true",style:{"--trajectory-hover-left":`${k.fraction*100}%`}}),z!==null&&n.jsx("div",{className:"traj-selection","data-dragging":x===null?void 0:"true","aria-hidden":"true",style:{"--trajectory-selection-left":`${(z.start-N)/O*100}%`,"--trajectory-selection-width":`${(z.end-z.start)/O*100}%`}}),n.jsx("div",{className:"traj-turnBoundaries","aria-hidden":"true",children:c.turnBoundaries.filter(b=>b.time>c.start&&b.time>=N&&b.time<=N+O).map(b=>n.jsx("span",{className:"traj-turnBoundary","data-turn":b.turn,style:{"--trajectory-turn-left":`${(b.time-c.start)/I*100}%`}},b.turn))}),n.jsx("div",{className:"traj-lanes","data-timeline-domain":"",children:c.spans.filter(b=>b.index===a||b.end>=N&&b.start<=N+O).map(b=>{const M=(b.start-c.start)/I,$=(b.end-b.start)/I*100,V=u.get(b.index),G=V==null?void 0:V.ttftMs,Q=V==null?void 0:V.decodingMs,Y=G===void 0||Q===void 0||G+Q<=0?null:G/(G+Q),m=p.get(b.index)??b.label;return n.jsx("span",{"aria-hidden":"true",className:"traj-span","data-timeline-span":b.kind,"data-timeline-record-index":b.index,"data-assistant-timing":Y===null?void 0:"true","data-error":b.isError||void 0,"data-current":b.index===a||void 0,"data-hovered":J===b.index||void 0,"data-search-match":i===null?void 0:i.has(b.index)?"true":"false","data-selected":z===null?void 0:b.start<=z.end&&b.end>=z.start?"true":"false",title:Os(b.kind,V),style:{"--trajectory-span-left":`${M*100}%`,"--trajectory-span-width":`${$}%`,"--trajectory-span-lane":b.lane,...Y===null?{}:{"--trajectory-assistant-ttft":`${Y*100}%`}},children:m},b.index)})})]})]})});function Fs(t,r,e){const s=new Array(t);return new Proxy(s,{get(a,i,o){if(typeof i=="string"){const l=i.charCodeAt(0);if(l>=48&&l<=57){const c=+i;if(Number.isInteger(c)&&c>=0&&c<t){let u=a[c];if(!u){const p=r[c*2];u=a[c]={index:c,key:e(c),start:p,size:r[c*2+1],end:p+r[c*2+1],lane:0}}return u}}if(i==="length")return t}return Reflect.get(a,i,o)}})}function oe(t,r,e){let s=e.initialDeps??[],a,i=!0;function o(){const l=t();return(l.length!==s.length||l.some((u,p)=>s[p]!==u))&&(s=l,a=r(...l),e!=null&&e.onChange&&!(i&&e.skipInitialOnChange)&&e.onChange(a),i=!1),a}return o.updateDeps=l=>{s=l},o}function Ge(t,r){if(t===void 0)throw new Error("Unexpected undefined");return t}const Ps=(t,r)=>Math.abs(t-r)<1.01,$s=(t,r,e)=>{let s;return Object.assign(function(...a){t.clearTimeout(s),s=t.setTimeout(()=>r.apply(this,a),e)},{cancel:()=>{t.clearTimeout(s)}})};let he;const we=()=>{if(he!==void 0)return he;if(typeof navigator>"u")return he=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return he=!0;const t=navigator.maxTouchPoints;return he=navigator.platform==="MacIntel"&&t!==void 0&&t>0},Xe=t=>{const{offsetWidth:r,offsetHeight:e}=t;return{width:r,height:e}},Ls=t=>t,Hs=t=>{const r=Math.max(t.startIndex-t.overscan,0),s=Math.min(t.endIndex+t.overscan,t.count-1)-r+1,a=new Array(s);for(let i=0;i<s;i++)a[i]=r+i;return a},qs=(t,r)=>{const e=t.scrollElement;if(!e)return;const s=t.targetWindow;if(!s)return;const a=o=>{const{width:l,height:c}=o;r({width:Math.round(l),height:Math.round(c)})};if(a(Xe(e)),!s.ResizeObserver)return()=>{};const i=new s.ResizeObserver(o=>{const l=()=>{const c=o[0];if(c!=null&&c.borderBoxSize){const u=c.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(Xe(e))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return i.observe(e,{box:"border-box"}),()=>{i.unobserve(e)}},be={passive:!0},Bs=typeof window>"u"?!0:"onscrollend"in window,Ks=(t,r,e)=>{const s=t.scrollElement;if(!s)return;const a=t.targetWindow;if(!a)return;const i=t.options.useScrollendEvent&&Bs;let o=0;const l=i?null:$s(a,()=>r(o,!1),t.options.isScrollingResetDelay),c=f=>()=>{o=e(s),l==null||l(),r(o,f)},u=c(!0),p=c(!1);return s.addEventListener("scroll",u,be),i&&s.addEventListener("scrollend",p,be),()=>{s.removeEventListener("scroll",u),i&&s.removeEventListener("scrollend",p),l==null||l.cancel()}},Vs=(t,r)=>Ks(t,r,e=>{const{horizontal:s,isRtl:a}=t.options;return s?e.scrollLeft*(a&&-1||1):e.scrollTop}),Ws=(t,r,e)=>{if(e.options.useCachedMeasurements){const s=e.indexFromElement(t),a=e.options.getItemKey(s);return e.itemSizeCache.get(a)??e.options.estimateSize(s)}if(r!=null&&r.borderBoxSize){const s=r.borderBoxSize[0];if(s)return Math.round(s[e.options.horizontal?"inlineSize":"blockSize"])}if(!r){const s=e.indexFromElement(t),a=e.options.getItemKey(s),i=e.itemSizeCache.get(a);if(i!==void 0)return i}return t[e.options.horizontal?"offsetWidth":"offsetHeight"]},Us=(t,{adjustments:r=0,behavior:e},s)=>{var a,i;(i=(a=s.scrollElement)==null?void 0:a.scrollTo)==null||i.call(a,{[s.options.horizontal?"left":"top"]:t+r,behavior:e})},Gs=Us;class Xs{constructor(r){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e,s,a;return((a=(s=(e=this.targetWindow)==null?void 0:e.performance)==null?void 0:s.now)==null?void 0:a.call(s))??Date.now()},this.observer=(()=>{let e=null;const s=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(a=>{a.forEach(i=>{const o=()=>{const l=i.target,c=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[u,p]of this.elementsCache)if(p===l){this.elementsCache.delete(u);break}return}this.isIndexInRange(c)&&this.shouldMeasureDuringScroll(c)&&this.resizeItem(c,this.options.measureElement(l,i,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var a;(a=s())==null||a.disconnect(),e=null},observe:a=>{var i;return(i=s())==null?void 0:i.observe(a,{box:"border-box"})},unobserve:a=>{var i;return(i=s())==null?void 0:i.unobserve(a)}}})(),this.range=null,this.setOptions=e=>{var s,a;const i={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Ls,rangeExtractor:Hs,onChange:()=>{},measureElement:Ws,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const g in e){const x=e[g];x!==void 0&&(i[g]=x)}const o=this.options;let l=null,c=null,u=!1;if(o!==void 0&&o.enabled&&i.enabled&&i.anchorTo==="end"&&this.scrollElement!==null){const g=o.count,x=i.count,v=this.getMeasurements(),k=g>0?((s=v[0])==null?void 0:s.key)??o.getItemKey(0):null,C=g>0?((a=v[g-1])==null?void 0:a.key)??o.getItemKey(g-1):null;if(x!==g||g>0&&x>0&&(i.getItemKey(0)!==k||i.getItemKey(x-1)!==C)){u=!0;const T=g>0?this.getVirtualItemForOffset(this.getScrollOffset())??v[0]:null;T&&(l=[T.key,this.getScrollOffset()-T.start]);const I=i.followOnAppend===!0?"auto":i.followOnAppend||null;I&&x>g&&this.isAtEnd(o.scrollEndThreshold)&&(g===0||i.getItemKey(x-1)!==C)&&(c=I)}}this.options=i,u&&(this.pendingMin=0,this.itemSizeCacheVersion++);let p=!1,f=0;if(l&&this.scrollOffset!==null){const[g,x]=l,v=this.getMeasurements(),{count:k,getItemKey:C}=this.options;let h=0;for(;h<k&&C(h)!==g;)h++;if(h<k){const y=v[h];if(y){const T=Math.max(0,y.start+x);T!==this.scrollOffset&&(f=T-this.scrollOffset,this.scrollOffset=T,p=!0)}}}(p||c)&&(this.pendingScrollAnchor=[p?l[0]:null,p?l[1]:0,c,f])},this.notify=e=>{var s,a;(a=(s=this.options).onChange)==null||a.call(s,this,e)},this.maybeNotify=oe(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}if(this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((e=this.scrollElement)==null?void 0:e.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{if(o&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=o?l===i?this.scrollDirection:l<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const i=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!we()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",o,be),i.addEventListener("touchend",l,be),this.unsubs.push(()=>{i.removeEventListener("touchstart",o),i.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[i,o,l,c]=a;i!==null&&!l&&(we()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?c!==0&&(this._iosDeferredAdjustment+=c):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const e=this.getScrollOffset(),s=this.getMaxScrollOffset();if(e<0||e>s)return;if(this._iosDeferredAdjustment<0&&e>=s-1){this._iosDeferredAdjustment=0;return}const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=oe(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,s,a,i,o,l,c,u)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:e,paddingStart:s,scrollMargin:a,getItemKey:i,enabled:o,lanes:l,laneAssignmentMode:c,gap:u}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=oe(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:s,scrollMargin:a,getItemKey:i,enabled:o,lanes:l,laneAssignmentMode:c,gap:u},p)=>{const f=this.itemSizeCache;if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(const h of this.laneAssignments.keys())h>=e&&this.laneAssignments.delete(h);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(h=>{this.itemSizeCache.set(h.key,h.size)}));const g=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),l===1){const h=e*2;let y=this._flatMeasurements;if(!y||y.length<h){const N=new Float64Array(h);y&&g>0&&N.set(y.subarray(0,g*2)),y=N,this._flatMeasurements=y}let T;if(g===0)T=s+a;else{const N=g-1;T=y[N*2]+y[N*2+1]+u}for(let N=g;N<e;N++){const O=i(N),D=f.get(O),E=typeof D=="number"?D:this.options.estimateSize(N);y[N*2]=T,y[N*2+1]=E,T+=E+u}const I=Fs(e,y,i);return this.measurementsCache=I,I}const x=this.measurementsCache.slice(0,g),v=new Array(l).fill(void 0),k=new Float64Array(l);let C=0;for(let h=0;h<g;h++){const y=x[h];y&&(v[y.lane]===void 0&&C++,v[y.lane]=h,k[y.lane]=y.end)}for(let h=g;h<e;h++){const y=i(h),T=this.laneAssignments.get(h);let I,N;const O=c==="estimate"||f.has(y);if(T!==void 0&&this.options.lanes>1){I=T;const P=v[I],j=P!==void 0?x[P]:void 0;N=j?j.end+u:s+a}else if(C===l){let P=0,j=k[0],R=v[0];for(let L=1;L<l;L++){const H=k[L];(H<j||H===j&&v[L]<R)&&(P=L,j=H,R=v[L])}I=P,N=j+u,O&&this.laneAssignments.set(h,I)}else I=h%this.options.lanes,N=s+a,O&&this.laneAssignments.set(h,I);const D=f.get(y),E=typeof D=="number"?D:this.options.estimateSize(h),K=N+E;x[h]={index:h,start:N,size:E,end:K,key:y,lane:I},v[I]===void 0&&C++,v[I]=h,k[I]=K}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=oe(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,s,a,i)=>e.length===0||s===0?(this.range=null,null):(this.range=Qs(e,s,a,i,i===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=oe(()=>{let e=null,s=null;const a=this.calculateRange();return a&&(e=a.startIndex,s=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,s]},(e,s,a,i,o)=>i===null||o===null?[]:e({startIndex:i,endIndex:o,overscan:s,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{const s=this.options.indexAttribute,a=e.getAttribute(s);return a?parseInt(a,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(a!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,a-i),l=Math.min(this.options.count-1,a+i);return e>=o&&e<=l}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((o,l)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(l))});return}const s=this.indexFromElement(e);if(!this.isIndexInRange(s))return;const a=this.options.getItemKey(s),i=this.elementsCache.get(a);i!==e&&(i&&this.observer.unobserve(i),this.observer.observe(e),this.elementsCache.set(a,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,s)=>{var a,i;if(!this.isIndexInRange(e))return;let o,l,c;const u=this._flatMeasurements;if(this.options.lanes===1&&u!==null)c=this.options.getItemKey(e),l=u[e*2],o=u[e*2+1];else{const g=this.measurementsCache[e];if(!g)return;c=g.key,l=g.start,o=g.size}const p=this.itemSizeCache.get(c)??o,f=s-p;if(f!==0){const g=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=g?this.getTotalSize():0,v=this.getScrollOffset()+this.scrollAdjustments,C=!this.itemSizeCache.has(c)?l<v:l+p<=v&&this.scrollDirection!=="backward",h=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:c,start:l,size:o,end:l+o,lane:0},f,this):C);(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(c,s),this.itemSizeCacheVersion++;let y=!1;g?y=this.applyScrollAdjustment(this.getTotalSize()-x):h&&(y=this.applyScrollAdjustment(f)),this.notify(y)}},this.getVirtualItems=oe(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,s)=>{const a=[];for(let i=0,o=e.length;i<o;i++){const l=e[i],c=s[l];a.push(c)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{const s=this.getMeasurements();if(s.length===0)return;const a=this._flatMeasurements,i=this.options.lanes===1&&a!=null,o=it(0,s.length-1,i?l=>a[l*2]:l=>Ge(s[l]).start,e);return Ge(s[o])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,s,a=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),o=this.getScrollOffset();s==="auto"&&(s=e>=o+i?"end":"start"),s==="center"?e+=(a-i)/2:s==="end"&&(e-=i);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,e),0)},this.getOffsetForIndex=(e,s="auto")=>{e=Math.max(0,Math.min(e,this.options.count-1));const a=this.getSize(),i=this.getScrollOffset(),o=this.measurementsCache[e];if(!o)return;if(s==="auto")if(o.end>=i+a-this.options.scrollPaddingEnd)s="end";else if(o.start<=i+this.options.scrollPaddingStart)s="start";else return[i,s];if(s==="end"&&e===this.options.count-1)return[this.getMaxScrollOffset(),s];const l=s==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,s,o.size),s]},this.scrollToOffset=(e,{align:s="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;const i=this.getOffsetForAlignment(e,s),o=this.now();this.scrollState={index:null,align:s,behavior:a,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:s="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));const i=this.getOffsetForIndex(e,s);if(!i)return;const[o,l]=i,c=this.now();this.scrollState={index:e,align:l,behavior:a,startedAt:c,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:s="auto"}={})=>{const a=this.getScrollOffset()+e,i=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:i,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{var e;const s=this.getMeasurements();let a;if(s.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const i=s.length-1,o=this._flatMeasurements;o!=null?a=o[i*2]+o[i*2+1]:a=((e=s[i])==null?void 0:e.end)??0}else{const i=Array(this.options.lanes).fill(null);let o=s.length-1;for(;o>=0&&i.some(l=>l===null);){const l=s[o];i[l.lane]===null&&(i[l.lane]=l.end),o--}a=Math.max(...i.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const e=[];if(this.itemSizeCache.size===0)return e;const s=this.getMeasurements();for(const a of s)a&&this.itemSizeCache.has(a.key)&&e.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return e},this._scrollToOffset=(e,{adjustments:s,behavior:a})=>{this._intendedScrollOffset=e+(s??0),this.options.scrollToFn(e,{behavior:a,adjustments:s},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(r)}applyScrollAdjustment(r,e){return r===0?!1:we()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?(this._iosDeferredAdjustment+=r,!1):(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=r,behavior:e}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=s?s[0]:this.scrollState.lastTargetOffset,i=1,o=a!==this.scrollState.lastTargetOffset;if(!o&&Ps(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){const l=this.getSize()||600,c=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&c>l;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}}const it=(t,r,e,s)=>{for(;t<=r;){const a=(t+r)/2|0,i=e(a);if(i<s)t=a+1;else if(i>s)r=a-1;else return a}return t>0?t-1:0};function Js(t,r,e){let s=0;for(;s<=r;){const a=(s+r)/2|0,i=t[a*2];if(i<e)s=a+1;else if(i>e)r=a-1;else return a}return s>0?s-1:0}function Qs(t,r,e,s,a){const i=t.length-1;if(t.length<=s)return{startIndex:0,endIndex:i};if(s===1&&a!==null){const u=Js(a,i,e);let p=u;const f=e+r;for(;p<i&&a[p*2]+a[p*2+1]<f;)p++;return{startIndex:u,endIndex:p}}let l=it(0,i,u=>t[u].start,e),c=l;if(s===1)for(;c<i&&t[c].end<e+r;)c++;else if(s>1){const u=Array(s).fill(0);for(;c<i&&u.some(f=>f<e+r);){const f=t[c];u[f.lane]=f.end,c++}const p=Array(s).fill(e+r);for(;l>=0&&p.some(f=>f>=e);){const f=t[l];p[f.lane]=f.start,l--}l=Math.max(0,l-l%s),c=Math.min(i,c+(s-1-c%s))}return{startIndex:l,endIndex:c}}const Ne=typeof document<"u"?d.useLayoutEffect:d.useEffect;function Ys({useFlushSync:t=!0,directDomUpdates:r=!1,directDomUpdatesMode:e="transform",...s}){const a=d.useReducer(p=>p+1,0)[1],i=d.useRef({enabled:r,mode:e,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});i.current.enabled=r,i.current.mode=e;const o=p=>{const f=i.current;if(!f.enabled||!f.container)return;const g=p.getTotalSize();if(g!==f.lastSize){f.lastSize=g;const x=p.options.horizontal?"width":"height";f.container.style[x]=`${g}px`}},l=p=>{const f=i.current;if(!f.enabled||!f.container)return;o(p);const g=!!p.options.horizontal,x=f.mode==="transform",v=g?"left":"top",k=p.options.scrollMargin,C=p.getVirtualItems();for(const h of C){const y=h.start-k,T=p.elementsCache.get(h.key);T&&f.lastPositions.get(T)!==y&&(f.lastPositions.set(T,y),x?T.style.transform=g?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:T.style[v]=`${y}px`)}},c={...s,onChange:(p,f)=>{var g;const x=i.current;let v=!0;if(x.enabled){l(p);const k=p.range,C=x.prevRange;v=!C||C.isScrolling!==p.isScrolling||C.startIndex!==(k==null?void 0:k.startIndex)||C.endIndex!==(k==null?void 0:k.endIndex),v&&(x.prevRange=k?{startIndex:k.startIndex,endIndex:k.endIndex,isScrolling:p.isScrolling}:null)}v&&(t&&f?Xt.flushSync(a):a()),(g=s.onChange)==null||g.call(s,p,f)}},[u]=d.useState(()=>{const p=new Xs(c);return Object.assign(p,{containerRef:f=>{const g=i.current;if(g.container=f,g.lastSize=null,f&&g.enabled){const x=p.getTotalSize();g.lastSize=x;const v=p.options.horizontal?"width":"height";f.style[v]=`${x}px`}}})});return u.setOptions(c),Ne(()=>u._didMount(),[]),Ne(()=>(o(u),u._willUpdate())),Ne(()=>{l(u)}),u}function Zs(t){return Ys({observeElementRect:qs,observeElementOffset:Vs,scrollToFn:Gs,...t})}const en=30,tn=20,sn=9;function ve(t){const r=encodeURIComponent(ce(t.cell));return t.collapsedSummaryKind===void 0?r:`${r}\0summary\0${t.collapsedSummaryKind}`}function nn(t){const r=[];let e=[];for(const[s,a]of t.entries()){const i={logicalIndex:s,record:a};if(a.cell.requestOnly===!0){e.push(i);continue}const o=[...e,i];e=[],r.push({entries:o,height:a.collapsedSummaryKind===void 0?en:tn,key:ve(a)})}return e.length>0&&r.push({entries:e,height:sn,key:e.map(s=>ve(s.record)).join("|")}),r}const rn=["Input","Output","Think","Time"],an=d.memo(function({turn:r}){return n.jsxs("div",{className:"sticky top-0 z-10 flex h-[26px] items-center border-b border-dark-border/40 bg-dark-surface/95 px-2 backdrop-blur",children:[n.jsxs("span",{className:"text-meta font-semibold text-dark-text",children:["Turn ",r]}),n.jsx("div",{className:"ml-auto flex items-center gap-3 pr-1 text-badge text-dark-muted/50","aria-hidden":"true",children:rn.map(e=>n.jsx("span",{className:"w-12 text-right",children:e},e))})]})}),on=d.memo(function({title:r,description:e}){return n.jsxs("div",{className:"flex h-[22px] items-center gap-2 px-2 text-meta",children:[n.jsx("span",{className:"font-medium text-dark-muted",children:r}),e!==void 0&&e!==""&&n.jsx("span",{className:"truncate text-dark-muted/50",children:e})]})}),ln={system:"System",user:"User",context:"Context",compacted:"Compacted",message:"Message",tool:"Tool",subtool:"Sub"},cn={system:"bg-dark-surface text-dark-muted border-dark-border/40",user:"bg-accent-blue/10 text-accent-blue border-accent-blue/30",context:"bg-dark-surface text-dark-muted border-dark-border/40",compacted:"bg-accent-yellow/15 text-accent-yellow border-accent-yellow",message:"bg-accent-green/10 text-accent-green border-accent-green/30",tool:"bg-accent-purple/10 text-accent-purple border-accent-purple/30",subtool:"bg-dark-surface text-dark-muted border-dark-border/40"},dn=d.memo(function({cell:r,selected:e=!1,onClick:s}){const{index:a,kind:i,timeSeconds:o,input:l,output:c,think:u}=r,p=ke(r),f=i==="message";return n.jsxs("div",{className:["flex h-[30px] items-center gap-2 border-b border-dark-border/20 px-2 text-xs cursor-pointer select-none",e?"bg-accent-blue/10":"hover:bg-dark-surface/40"].join(" "),"data-kind":i,"data-selected":e||void 0,onClick:()=>s==null?void 0:s(a),children:[n.jsxs("span",{className:"w-10 shrink-0 text-right tabular-nums text-dark-muted/50",children:["#",a]}),n.jsx("span",{className:"w-[74px] shrink-0",children:n.jsx("span",{className:["inline-block rounded border px-1 py-px text-badge leading-none",cn[i]].join(" "),children:ln[i]})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-text",title:p,children:p}),n.jsxs("span",{className:"flex shrink-0 items-center gap-2 tabular-nums text-dark-muted/60",children:[f&&n.jsxs(n.Fragment,{children:[l!==void 0&&n.jsx("span",{title:"Input tokens",children:l}),c!==void 0&&n.jsx("span",{title:"Output tokens",children:c}),u!==void 0&&n.jsx("span",{title:"Reasoning tokens",children:u})]}),n.jsx("span",{className:"w-16 text-right",children:Re(o)})]})]})}),un=100,hn=12,mn=600,fn=2;function pn(t){const r=d.useRef({rows:[],structure:[]});if(r.current.rows===t)return r.current.structure;const e=r.current.structure.length===t.length&&t.every((s,a)=>{const i=r.current.structure[a];return(i==null?void 0:i.key)===s.key&&i.height===s.height})?r.current.structure:t.map(s=>({key:s.key,height:s.height}));return r.current={rows:t,structure:e},e}function xn(t){const r=[];for(const e of t){const s=[];for(const a of e.groups)a.cells.forEach((i,o)=>{s.push({turn:e.turn,group:a.title,groupDescription:a.description,groupStart:o===0,turnStart:s.length===0,cell:i,turnEnd:!1})});if(s.length>0){const a=s[s.length-1];a&&(a.turnEnd=!0)}r.push(...s)}return r}function gn(t,r){const e=[];let s=[],a=null;const i=()=>{if(s.length!==0){if(a!==null&&r.has(a)){const o=s.filter(c=>c.cell.requestOnly!==!0&&c.cell.kind!=="system"),l=s[0];e.push({...l,groupStart:!0,turnStart:!0,turnEnd:!0,collapsedSummary:`Turn ${a} · ${o.length} records`,collapsedSummaryKind:"turn",cell:{...l.cell,index:l.cell.index}})}else e.push(...s);s=[],a=null}};for(const o of t)o.turnStart&&i(),a=o.turn,s.push(o);return i(),e}function bn(t,r){var a;const e=[];let s=0;for(;s<t.length;){const i=t[s],o=t[s+1];if(i.cell.kind==="message"&&o!==void 0&&(o.cell.kind==="tool"||o.cell.kind==="subtool")&&r.has(ce(i.cell))){let l=s+1;for(;l<t.length&&(t[l].cell.kind==="tool"||t[l].cell.kind==="subtool");)l+=1;const c=l-s-1;e.push({...i,groupStart:!0,turnEnd:((a=t[l-1])==null?void 0:a.turnEnd)??i.turnEnd,collapsedSummary:`${ke(i.cell)||"Message"} · ${c} tool call${c>1?"s":""}`,collapsedSummaryKind:"assistant"}),s=l;continue}e.push(i),s+=1}return e}function vn(t,r){const e=[];let s=null,a=null;for(const i of t)i.turnStart&&(s=i),i.groupStart&&(a=i),r.has(i.cell.index)&&(s!==null&&e.length===0&&(e.push({...s,groupStart:!0,turnStart:!0}),s=null),a!==null&&e.length>0&&e[e.length-1].group!==i.group&&(e.push({...a,groupStart:!0,turnStart:!1}),a=null),e.push(i));return e}function Ce(t){if(t===null||!Number.isFinite(t))return"Not available";const r=new Date(t),e=o=>String(o).padStart(2,"0"),s=o=>String(o).padStart(3,"0"),a=`${e(r.getHours())}:${e(r.getMinutes())}:${e(r.getSeconds())}.${s(r.getMilliseconds())}`;return`${`${r.getFullYear()}-${e(r.getMonth()+1)}-${e(r.getDate())}`} ${a}`}function kn(t){const r=[{id:"overview",label:"Summary"}];return t.inputDetail!==void 0&&t.inputDetail!==""&&r.push({id:"input",label:"Input"}),t.outputDetail!==void 0&&t.outputDetail!==""&&r.push({id:"output",label:"Output"}),t.thinkingDetail!==void 0&&t.thinkingDetail!==""&&r.push({id:"thinking",label:"Thinking"}),t.assistantMetrics!==void 0&&r.push({id:"timing",label:"Timing"}),(t.input!==void 0||t.output!==void 0||t.think!==void 0)&&r.push({id:"usage",label:"Usage"}),r}function yn({cell:t,onClose:r}){var l;const e=kn(t),[s,a]=d.useState(((l=e[0])==null?void 0:l.id)??"overview"),i=ke(t),o=()=>{switch(s){case"overview":return n.jsxs("dl",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Kind"}),n.jsx("dd",{className:"traj-detailValue",children:t.kind})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Index"}),n.jsxs("dd",{className:"traj-detailValue",children:["#",t.index]})]}),t.callId!==void 0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Call ID"}),n.jsx("dd",{className:"traj-detailValue break-all",children:t.callId})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Duration"}),n.jsx("dd",{className:"traj-detailValue",children:Re(t.timeSeconds)})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Started"}),n.jsx("dd",{className:"traj-detailValue",children:Ce(t.startedAt??null)})]}),t.isError===!0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Status"}),n.jsx("dd",{className:"traj-detailValue text-accent-red",children:"error"})]}),i!==""&&n.jsxs("div",{className:"pt-1",children:[n.jsx("dt",{className:"traj-detailKey mb-1",children:"Summary"}),n.jsx("dd",{className:"traj-detailBody",children:i})]})]});case"input":return n.jsx("div",{className:"traj-detailBody",children:t.inputDetail});case"output":return n.jsx("div",{className:"traj-detailBody",children:t.outputDetail});case"thinking":return n.jsx("div",{className:"traj-detailBody",children:t.thinkingDetail});case"timing":{const c=t.assistantMetrics;if(!c)return null;const u=c.firstTokenTime!==null&&c.stepStartTime!==null?c.firstTokenTime-c.stepStartTime:null,p=c.completedTime!==null&&c.firstTokenTime!==null?c.completedTime-c.firstTokenTime:null;return n.jsxs("dl",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Step start"}),n.jsx("dd",{className:"traj-detailValue",children:Ce(c.stepStartTime)})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"First token"}),n.jsx("dd",{className:"traj-detailValue",children:Ce(c.firstTokenTime)})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"TTFT"}),n.jsx("dd",{className:"traj-detailValue",children:u===null?"—":`${u} ms`})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Decoding"}),n.jsx("dd",{className:"traj-detailValue",children:p===null?"—":`${p} ms`})]})]})}case"usage":return n.jsxs("dl",{className:"space-y-1.5",children:[t.input!==void 0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Input"}),n.jsx("dd",{className:"traj-detailValue",children:t.input})]}),t.output!==void 0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Output"}),n.jsx("dd",{className:"traj-detailValue",children:t.output})]}),t.think!==void 0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Reasoning"}),n.jsx("dd",{className:"traj-detailValue",children:t.think})]}),t.input===void 0&&t.output===void 0&&t.think===void 0&&n.jsx("div",{className:"traj-detailValue",children:"Token usage not reported by provider yet."})]});default:return null}};return n.jsxs("div",{className:"flex h-full w-[360px] shrink-0 flex-col border-l border-dark-border/40 bg-dark-surface/40",children:[n.jsxs("div",{className:"flex h-9 shrink-0 items-center justify-between border-b border-dark-border/40 px-3",children:[n.jsxs("span",{className:"text-xs font-medium text-dark-text",children:["Record #",t.index]}),n.jsx("button",{type:"button",className:"rounded p-1 text-dark-muted hover:bg-dark-surface/60",onClick:r,"aria-label":"Close details",children:n.jsx(le,{size:14})})]}),n.jsx("div",{className:"flex shrink-0 flex-wrap gap-1 border-b border-dark-border/40 px-2 py-1.5",children:e.map(c=>n.jsx("button",{type:"button",className:"traj-detailTab","data-active":s===c.id||void 0,onClick:()=>a(c.id),children:c.label},c.id))}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-3",children:o()})]})}function jn({turns:t,searchMatchIndexes:r=null,selectedIndex:e,onSelectIndex:s,onDeselect:a,onClearSelection:i,collapsedTurns:o,onToggleTurn:l,collapsedAssistants:c,onToggleAssistant:u}){var P;const p=d.useRef(null),f=d.useMemo(()=>xn(t),[t]),g=d.useMemo(()=>e===null?void 0:f.find(j=>j.cell.index===e),[f,e]),x=d.useMemo(()=>{if(r!==null)return vn(f,r);const j=o.size===0?f:gn(f,o);return c.size===0?j:bn(j,c)},[f,c,o,r]),v=d.useMemo(()=>nn(x),[x]),k=pn(v),C=x.length>un,h=d.useCallback(j=>{var R;return((R=k[j])==null?void 0:R.height)??30},[k]),y=d.useCallback(j=>{var R;return((R=k[j])==null?void 0:R.key)??j},[k]),T=d.useCallback(()=>p.current,[]),I=Zs({count:C?k.length:0,enabled:C,estimateSize:h,getItemKey:y,getScrollElement:T,initialRect:{width:0,height:mn},anchorTo:"end",overscan:hn,scrollEndThreshold:fn}),N=C?I.getVirtualItems():[],O=((P=N[0])==null?void 0:P.start)??0,D=C?I.getTotalSize():0,E=j=>{s(j)},K=j=>j.collapsedSummary!==void 0?n.jsxs("div",{className:"flex h-[20px] cursor-pointer items-center gap-2 px-2 text-xs text-dark-muted hover:bg-dark-surface/40",onClick:()=>{j.collapsedSummaryKind==="turn"&&j.turn!==null?l(j.turn):j.collapsedSummaryKind==="assistant"&&u(ce(j.cell))},children:[n.jsx("span",{className:"text-dark-muted/50",children:"▸"}),n.jsx("span",{className:"truncate",children:j.collapsedSummary})]}):n.jsxs(n.Fragment,{children:[j.turnStart&&j.turn!==null&&n.jsx(an,{turn:j.turn}),j.groupStart&&n.jsx(on,{title:j.group,description:j.groupDescription}),n.jsx(dn,{cell:j.cell,selected:e===j.cell.index,onClick:E})]});return n.jsxs("div",{className:"flex min-h-0 flex-1",children:[n.jsx("div",{ref:p,className:"min-w-0 flex-1 overflow-auto",onClick:j=>{j.target===j.currentTarget&&(i==null||i())},children:C?n.jsx("div",{style:{height:D,position:"relative"},children:N.map(j=>{const R=v[j.index];return R?n.jsx("div",{"data-virtual-row-key":R.key,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${j.start-O}px)`,height:R.height},children:R.entries.map(L=>n.jsx("div",{children:K(L.record)},ve(L.record)))},R.key):null})}):x.map(j=>n.jsx("div",{children:K(j)},ve(j)))}),g!==void 0&&n.jsx(yn,{cell:g.cell,onClose:a},g.cell.index)]})}function Je(t){const r=new Date(t),e=s=>String(s).padStart(2,"0");return`${e(r.getHours())}:${e(r.getMinutes())}:${e(r.getSeconds())}`}const Sn=d.memo(function({errors:r,onOpenLogs:e}){const{t:s}=Z(),[a,i]=d.useState(!1),[o,l]=d.useState(null),c=d.useMemo(()=>r.filter(f=>f.level==="error"),[r]);if(d.useEffect(()=>{l(f=>f!==null&&c.length>f?null:f)},[c.length]),c.length===0||o!==null)return null;const u=c[c.length-1];if(u===void 0)return null;const p=c.slice(-20).reverse();return n.jsxs("div",{"data-trajectory-error-banner":"",className:"mx-2 mt-1 shrink-0 rounded-md border border-accent-red/50 bg-accent-red/10 text-xs",role:"alert",children:[n.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-accent-red",children:[n.jsx(pe,{size:14,className:"shrink-0","aria-hidden":"true"}),n.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>i(f=>!f),title:s(a?"trajectory.errorBanner.collapse":"trajectory.errorBanner.expand"),children:[n.jsxs("span",{className:"shrink-0 font-semibold",children:[s("trajectory.errorBanner.title"),c.length>1&&n.jsxs("span",{className:"ml-1.5 rounded bg-accent-red px-1.5 py-0.5 text-badge font-semibold text-accent-fg",children:["×",c.length]})]}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-dark-text",children:[Je(u.timestamp)," · ",u.message]}),a?n.jsx(bt,{size:14,className:"shrink-0","aria-hidden":"true"}):n.jsx(vt,{size:14,className:"shrink-0","aria-hidden":"true"})]}),e&&n.jsxs("button",{type:"button",className:"flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-accent-red hover:bg-accent-red/15",onClick:e,title:s("trajectory.errorBanner.viewLogs"),children:[n.jsx(kt,{size:12,"aria-hidden":"true"}),s("trajectory.errorBanner.viewLogs")]}),n.jsx("button",{type:"button",className:"shrink-0 rounded p-0.5 text-dark-muted hover:bg-accent-red/15 hover:text-accent-red",onClick:()=>{l(c.length),i(!1)},title:s("trajectory.errorBanner.dismiss"),children:n.jsx(le,{size:14,"aria-hidden":"true"})})]}),a&&n.jsx("div",{className:"max-h-40 overflow-y-auto border-t border-accent-red/30 px-2 py-1.5 font-mono text-meta custom-scrollbar",children:p.map(f=>n.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[n.jsx("span",{className:"shrink-0 text-dark-muted",children:Je(f.timestamp)}),n.jsx("span",{className:"shrink-0 rounded bg-accent-red px-1 py-0.5 text-avatar font-semibold uppercase leading-none text-accent-fg",children:f.source}),n.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-all text-dark-text",children:f.message})]},f.id))})]})}),wn=new Set,Nn=new Set,Cn=[],Tn=3e3;function In({sessionId:t,messages:r,errorLogs:e,onOpenLogs:s}){const[a,i]=d.useState(wn),[o,l]=d.useState(Nn),[c,u]=d.useState(null),[p,f]=d.useState(!1),[g,x]=d.useState(""),[v]=d.useState(()=>new Cs),[k,C]=d.useState(0),h=d.useRef(null),y=d.useRef(!1),[T,I]=d.useState(null),N=Pe(m=>m.compactedBySession[t]??Mn),O=Pe(m=>m.ttftBySession[t]),D=d.useMemo(()=>{if(O!==void 0)return new Map(Object.entries(O))},[O]),E=d.useMemo(()=>bs({messages:r,compacted:N,ttft:D}),[r,N,D]),K=p?"duration":"sequence";d.useEffect(()=>(h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{v.update([E]),C(m=>m+1),y.current=!0},y.current?Tn:0),()=>{h.current&&clearTimeout(h.current)}),[E,v]);const P=d.useMemo(()=>g.trim()===""?null:v.search(g),[g,k]),j=d.useMemo(()=>{if(P===null)return null;const m=new Set;for(const S of E)for(const A of S.groups)for(const q of A.cells)P.has(ce(q))&&m.add(q.index);return m},[E,P]),R=d.useMemo(()=>c===null?null:ys(E,c,K),[E,K,c]),L=d.useMemo(()=>E.filter(m=>m.turn!==null&&m.groups.reduce((S,A)=>S+A.cells.filter(q=>q.requestOnly!==!0&&q.kind!=="system").length,0)>1).flatMap(m=>m.turn===null?[]:[m.turn]),[E]),H=L.length>0&&L.every(m=>a.has(m)),z=d.useMemo(()=>{const m=[];for(const S of E){const A=S.groups.flatMap(q=>q.cells);for(let q=0;q<A.length;q++){const X=A[q];if((X==null?void 0:X.kind)!=="message")continue;const B=A[q+1];((B==null?void 0:B.kind)==="tool"||(B==null?void 0:B.kind)==="subtool")&&m.push(ce(X))}}return m},[E]),J=z.length>0&&z.every(m=>o.has(m)),b=d.useCallback(m=>{i(S=>{const A=new Set(S);return A.has(m)?A.delete(m):A.add(m),A})},[]),M=d.useCallback(()=>{i(m=>{const S=new Set(m);if(H)for(const A of L)S.delete(A);else for(const A of L)S.add(A);return S})},[H,L]),_=d.useCallback(m=>{l(S=>{const A=new Set(S);return A.has(m)?A.delete(m):A.add(m),A})},[]),$=d.useCallback(()=>{l(m=>{const S=new Set(m);if(J)for(const A of z)S.delete(A);else for(const A of z)S.add(A);return S})},[J,z]),V=d.useCallback(m=>{u(m)},[]),G=d.useCallback(m=>{R!==null&&!R.has(m)&&u(null),I(S=>S===m?null:m)},[R]),Q=d.useCallback(()=>{I(null)},[]),Y=d.useCallback(()=>{u(null),I(null)},[]);return n.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-conversation-composer-overlay":"",children:[n.jsx(Ts,{actualDuration:p,onActualDurationChange:m=>{f(m),u(null)},allTurnsCollapsed:H,onToggleAllTurns:M,allAssistantsCollapsed:J,onToggleAllAssistants:$,searchQuery:g,onSearchQueryChange:x}),n.jsx(Sn,{errors:e??Cn,onOpenLogs:s}),n.jsx(Ds,{turns:E,mode:K,range:c,selectedIndex:T,searchMatchIndexes:j,onRangeChange:V,onRecordSelect:G}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:n.jsx(jn,{turns:E,searchMatchIndexes:j,selectedIndex:T,onSelectIndex:G,onDeselect:Q,onClearSelection:Y,collapsedTurns:a,onToggleTurn:b,collapsedAssistants:o,onToggleAssistant:_})})]})}const Mn=[],En=d.memo(function({activeSessionId:r}){const{t:e}=Z(),a=Jt(i=>i.observed).filter(i=>i.id!==r);return a.length===0?null:n.jsxs("div",{className:"mb-2 flex flex-col gap-1.5",children:[a.map(i=>n.jsx(An,{id:i.id,title:i.title},i.id)),n.jsx("span",{className:"sr-only",children:e("chat.observedTitle")})]})});function An({id:t,title:r}){const{t:e}=Z(),s=ae(l=>{var c;return((c=l.generatingSessions)==null?void 0:c.includes(t))??!1}),a=ae(l=>{const c=l.messagesBySession[t],u=c&&c.length>0?c[c.length-1]:void 0;return!!(u!=null&&u.errorCard)}),i=ae(l=>{const c=l.messagesBySession[t];if(!c||c.length===0)return"";for(let u=c.length-1;u>=0;u--){const p=c[u];if(p.type==="user")continue;const f=p.content||"";if(f.trim())return f.trim().slice(-160)}return""}),o=e(s?"chat.observedRunning":a?"chat.observedFailed":"chat.observedDone");return n.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs",children:[n.jsx(yt,{size:13,className:"shrink-0 text-accent-blue","aria-hidden":"true"}),n.jsx("span",{className:"max-w-[180px] truncate font-medium text-dark-text",title:r,children:r}),n.jsx("span",{className:"shrink-0 text-badge text-dark-muted",children:t.slice(0,8)}),s?n.jsx(jt,{size:12,className:"shrink-0 animate-spin text-accent-yellow","aria-hidden":"true"}):a?n.jsx(St,{size:12,className:"shrink-0 text-accent-red","aria-hidden":"true"}):n.jsx(wt,{size:12,className:"shrink-0 text-accent-green","aria-hidden":"true"}),n.jsx("span",{className:`shrink-0 text-badge ${a?"text-accent-red":s?"text-accent-yellow":"text-accent-green"}`,children:o}),i&&n.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:i,children:i})]})}function Qe(t,r){if(!t||!r||r.length===0)return;const e=t.find(s=>s.switchMode&&r.includes(s.label));e!=null&&e.switchMode&&Ae.getState().setBaseMode(e.switchMode)}const Rn=15e3,On=300;function ot(t){const{t:r}=Z();return d.useMemo(()=>{if(t.secret)return{allItems:[],otherIdx:-1,proceedIdx:-1,displayItems:[]};const e=r("chat.askOtherLabel"),s=r("chat.askProceedLabel"),a=t.options||[],i=a.some(p=>p.label===e),o=a.some(p=>p.label===s),l=[...a];o||l.push({label:s,description:r("chat.askProceedDesc")}),i||l.push({label:e,description:r("chat.askCustomDesc")});const c=i?l.findIndex(p=>p.label===e):l.length-1,u=o?l.findIndex(p=>p.label===s):l.length-(i?1:2);return{allItems:l,otherIdx:c,proceedIdx:u,displayItems:l}},[t,r])}function Ye({item:t,answered:r,selectedIdx:e,multiSelected:s,customInput:a,showCustomInput:i,onSelect:o,onToggleMulti:l,onProceed:c,onEnterCustom:u,onCancelCustom:p,onSubmitCustom:f,onCustomChange:g,inputRef:x}){const{t:v}=Z(),{otherIdx:k,proceedIdx:C,displayItems:h}=ot(t),y=!!t.multiSelect,T=d.useRef(null);if(t.secret)return n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("input",{ref:T,type:"password",autoComplete:"off",autoCorrect:"off",spellCheck:!1,className:"w-full px-3 py-2 text-sm border border-dark-border rounded-md bg-dark-bg text-dark-text focus:outline-none focus:ring-2 focus:ring-accent-blue/50",value:a,onChange:N=>g(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),f())},placeholder:v("chat.askSecretPlaceholder"),autoFocus:!0}),n.jsx("div",{className:"flex gap-2",children:n.jsxs("button",{type:"button",className:"btn btn-accent px-3 py-1 text-xs disabled:cursor-not-allowed",onClick:f,disabled:!a,children:[n.jsx(ie,{size:12}),v("chat.askSubmit")]})}),n.jsx("div",{className:"text-xs text-dark-muted",children:v("chat.askSecretHint")})]});const I=N=>{if(N===C){c();return}if(N===k){u();return}if(y){l(N);return}o(N)};return n.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[h.map((N,O)=>{const D=e===O,E=s.has(O),K=O===k;return n.jsxs("div",{children:[n.jsxs("button",{type:"button",className:`w-full text-left px-3 py-2 rounded-md text-sm transition-colors ${D?"bg-accent-blue/10 border border-accent-blue/40":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,onClick:()=>I(O),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[y&&n.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-badge ${E?"bg-accent-blue border-accent-blue text-accent-fg":"border-dark-border"}`,children:E&&n.jsx(Ct,{size:10})}),n.jsxs("span",{className:`font-medium ${D?"text-accent-blue":"text-dark-text"}`,children:[y?"":`${O+1}. `,N.label]}),O===C&&n.jsx("span",{className:"text-xs text-accent-green",children:v("chat.askDirectTag")}),K&&n.jsx("span",{className:"text-xs text-dark-muted",children:v("chat.askCustomTag")})]}),N.description&&n.jsx("div",{className:"text-xs text-dark-muted mt-0.5 ml-6",children:N.description})]}),K&&D&&i&&n.jsxs("div",{className:"mt-2 ml-4",children:[n.jsx("textarea",{ref:x,className:"w-full px-3 py-2 text-sm border border-dark-border rounded-md bg-dark-bg text-dark-text focus:outline-none focus:ring-2 focus:ring-accent-blue/50 resize-none",rows:3,value:a,onChange:P=>g(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),f()),P.key==="Escape"&&p()},placeholder:v("chat.askAnswerPlaceholder"),autoFocus:!0}),n.jsxs("div",{className:"flex gap-2 mt-1",children:[n.jsxs("button",{type:"button",className:"btn btn-accent px-3 py-1 text-xs",onClick:f,children:[n.jsx(ie,{size:12}),v("chat.askSubmit")]}),n.jsxs("button",{type:"button",className:"btn btn-ghost px-3 py-1 text-xs",onClick:p,children:[n.jsx(le,{size:12}),v("common.cancel")]})]})]})]},`opt-${O}`)}),r&&n.jsx("div",{className:"text-xs text-accent-green font-medium",children:v("chat.askAnswered")})]})}function _n({isOpen:t,onClose:r}){const{t:e}=Z(),[s,a]=d.useState(null),[i,o]=d.useState(-1),[l,c]=d.useState(new Set),[u,p]=d.useState(""),[f,g]=d.useState(!1),[x,v]=d.useState(!1),[k,C]=d.useState(!1),[h,y]=d.useState(!1),[T,I]=d.useState(0),[N,O]=d.useState([]),[D,E]=d.useState(!1),K=d.useRef(null),P=d.useRef(null),j=d.useMemo(()=>s?s.questions&&s.questions.length>0?s.questions:[{question:s.question,header:s.header,options:s.options,multiSelect:s.multiSelect,secret:s.secret}]:[],[s]),R=j.length>1,L=d.useCallback(w=>{a(w),o(w.multiSelect?-1:0),c(new Set),p(""),g(w.secret===!0),v(!1),C(!1),y(!1),I(0),E(!1);const F=w.questions&&w.questions.length>0?w.questions:[w];O(F.map(()=>null))},[]);d.useEffect(()=>{P.current=s}),d.useEffect(()=>{if(t){const w=window.__pendingQuestion;w&&L(w)}},[t,L]),d.useEffect(()=>{const w=F=>{var de;const W=F.detail,ee=((de=P.current)==null?void 0:de.questionId)??null;if(W&&ee&&W!==ee)return;const re=ee;v(!0),setTimeout(()=>{var ze;const _e=((ze=P.current)==null?void 0:ze.questionId)??null;re&&_e&&_e!==re||(r(),a(null),v(!1))},On)};return window.addEventListener("ask-question-dismiss",w),()=>window.removeEventListener("ask-question-dismiss",w)},[r]),d.useEffect(()=>{if(!x)return;const w=setTimeout(()=>{v(!1),C(!0)},Rn);return()=>clearTimeout(w)},[x]),d.useEffect(()=>{const w=()=>{C(!1),y(!1)};return window.addEventListener("ask-question-dismiss",w),()=>window.removeEventListener("ask-question-dismiss",w)},[]),d.useEffect(()=>{const w=F=>{var re;const W=F.detail,ee=((re=P.current)==null?void 0:re.questionId)??null;W&&ee&&W!==ee||(v(!1),C(!0),y(!0))};return window.addEventListener("ask-question-ack-failed",w),()=>window.removeEventListener("ask-question-ack-failed",w)},[]),d.useEffect(()=>{const w=F=>{const W=F.detail,ee=nt.getState().activeSessionId;if(W&&ee&&W!==ee)return;const re=window.__pendingQuestion;re&&L(re)};return window.addEventListener("ask-question-required",w),()=>window.removeEventListener("ask-question-required",w)},[L]),d.useEffect(()=>{o(0),c(new Set),p(""),g((s==null?void 0:s.secret)===!0)},[T,D,s]);const H=j[T]||null,{allItems:z,otherIdx:J}=ot(H||{question:""}),b=(H==null?void 0:H.secret)===!0||(s==null?void 0:s.secret)===!0,M=d.useCallback((w,F)=>{x||!s||(C(!1),v(!0),Qe(s.options,F),ne.send({type:"question_answer",sessionId:s.sessionId||ne.getSessionId()||void 0,data:JSON.stringify({questionId:s.questionId,answer:w,selectedOptions:F})}))},[x,s]),_=d.useCallback(()=>{x||!s||(C(!1),v(!0),ne.send({type:"question_answer",sessionId:s.sessionId||ne.getSessionId()||void 0,data:JSON.stringify({questionId:s.questionId,answers:j.map((w,F)=>N[F]||{answer:e("chat.askUnansweredValue")})})}))},[x,s,j,N,e]),$=d.useCallback((w,F,W)=>{var ee;Qe((ee=j[w])==null?void 0:ee.options,W),O(re=>{const de=re.slice();return de[w]={answer:F,selectedOptions:W},de}),w<j.length-1?I(w+1):E(!0)},[j]),V=d.useCallback(w=>{if(x||!s)return;const F=z[w];F&&(o(w),M(F.label,[F.label]))},[x,s,z,M]),G=d.useCallback(()=>{if(x||!s||i<0)return;const w=z[i];w&&M(w.label,[w.label])},[x,s,i,z,M]),Q=d.useCallback(()=>{if(x||i<0)return;const w=z[i];w&&$(T,w.label,[w.label])},[x,i,z,$,T]),Y=d.useCallback(w=>{if(x)return;const F=z[w];F&&$(T,F.label,[F.label])},[x,z,$,T]),m=d.useCallback(w=>{x||c(F=>{const W=new Set(F);return W.has(w)?W.delete(w):W.add(w),W})},[x]),S=d.useCallback(()=>{if(x)return;const w=[...l].map(F=>{var W;return((W=z[F])==null?void 0:W.label)||""});R?$(T,w.join(", "),w):M(w.join(", "),w)},[x,l,z,R,$,T,M]),A=d.useCallback(()=>{if(x)return;const w=e("chat.askProceedLabel");R?$(T,w,[w]):M(w,[w])},[x,R,$,T,M,e]),q=d.useCallback(()=>{x||(o(J),g(!0),setTimeout(()=>{var w;return(w=K.current)==null?void 0:w.focus()},100))},[x,J]),X=d.useCallback(()=>{g(!1),p("")},[]),B=d.useCallback(()=>{if(x)return;const w=u||e("chat.askEmptyInputValue");R?$(T,w):M(w)},[x,u,R,$,T,M,e]),U=d.useCallback(()=>{x||!s||(C(!1),v(!0),ne.send({type:"question_answer",sessionId:s.sessionId||ne.getSessionId()||void 0,data:JSON.stringify({questionId:s.questionId,answers:j.map(()=>({answer:"(cancelled)"}))})}))},[x,s,j]),te=d.useCallback(()=>{if(!x){if(h){r();return}if(R){if(f&&!b){g(!1),p("");return}if(D){E(!1),I(j.length-1);return}U();return}if(f&&!b){g(!1),p("");return}M("(cancelled)")}},[x,R,f,D,j.length,U,M,h,r,b]);if(!t||!s)return null;const Oe=N.filter(w=>!w).length;return n.jsx(st,{isOpen:t,onClose:te,title:s.header||e(R?"chat.askBatchTitle":"chat.askSingleTitle"),badge:n.jsxs("span",{className:"flex items-center gap-1 text-meta text-accent-blue shrink-0",children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-pulse"}),e("chat.askPendingBadge"),R?` · ${N.filter(Boolean).length}/${j.length}`:""]}),collapsedSummary:n.jsx("span",{className:"truncate",children:(H==null?void 0:H.question)||s.question}),maxHeight:"50vh",children:R?n.jsxs("div",{className:"flex flex-col gap-4",children:[s.autoResolutionMs&&s.autoResolutionMs>0&&n.jsx("div",{className:"inline-flex items-center gap-2 rounded-md border border-accent-yellow/30 bg-accent-yellow/10 px-3 py-1.5 text-xs text-accent-yellow",children:e("chat.askAutoContinue",{seconds:Math.max(1,Math.round(s.autoResolutionMs/1e3))})}),n.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[j.map((w,F)=>{const W=!!N[F],ee=!D&&T===F;return n.jsxs("button",{type:"button",onClick:()=>{I(F),E(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${ee?"bg-accent-blue text-accent-fg":W?"bg-accent-green/10 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:["Q",F+1," ",W?"✓":""]},`nav-${F}`)}),n.jsx("button",{type:"button",onClick:()=>E(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${D?"bg-accent-blue text-accent-fg":"bg-dark-hover text-dark-muted"}`,children:e("chat.askSubmit")})]}),D?n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"text-sm font-medium text-dark-text",children:e("chat.askReviewTitle")}),j.map((w,F)=>{const W=N[F];return n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs("div",{className:"text-sm text-dark-muted leading-relaxed min-w-0",children:[n.jsxs("span",{className:"font-medium",children:[F+1,". "]}),w.question]}),n.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${W?"text-accent-green":"text-accent-yellow"}`,children:W?W.answer:e("chat.askNotAnswered")})]},`rev-${F}`)}),Oe>0&&n.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md border border-accent-yellow/30 bg-accent-yellow/10 px-3 py-2 text-xs text-accent-yellow",children:[n.jsx(pe,{size:14}),e("chat.askUnansweredWarning",{count:Oe})]}),n.jsxs("div",{className:"flex gap-2 mt-1",children:[n.jsxs("button",{type:"button",className:"btn btn-accent px-4 py-2 text-sm",onClick:_,disabled:x,children:[n.jsx(ie,{size:14}),e("chat.askSubmitAll")]}),n.jsx("button",{type:"button",className:"btn btn-secondary px-4 py-2 text-sm",onClick:()=>{E(!1),I(j.length-1)},disabled:x,children:e("chat.askBackToEdit")})]})]}):H?n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("div",{className:"text-sm text-dark-muted leading-relaxed min-w-0",children:H.question}),n.jsxs("div",{className:"flex gap-1 shrink-0",children:[n.jsxs("button",{type:"button",className:"btn btn-secondary px-2 py-1 text-xs",onClick:()=>{I(w=>Math.max(0,w-1)),E(!1)},disabled:T===0,children:[n.jsx(Nt,{size:12}),e("chat.askPrevQuestion")]}),T<j.length-1?n.jsxs("button",{type:"button",className:"btn btn-secondary px-2 py-1 text-xs",onClick:()=>{I(w=>Math.min(j.length-1,w+1)),E(!1)},children:[e("chat.askNextQuestion"),n.jsx(Ie,{size:12})]}):n.jsxs("button",{type:"button",className:"btn btn-accent px-2 py-1 text-xs",onClick:()=>E(!0),children:[e("chat.askViewSubmit"),n.jsx(Ie,{size:12})]})]})]}),n.jsx(Ye,{item:H,answered:!!N[T],selectedIdx:i,multiSelected:l,customInput:u,showCustomInput:f,onSelect:Y,onToggleMulti:m,onProceed:A,onEnterCustom:q,onCancelCustom:X,onSubmitCustom:B,onCustomChange:p,inputRef:K}),!f&&n.jsx("div",{className:"flex items-center gap-2",children:H.multiSelect?n.jsxs("button",{type:"button",className:"btn btn-accent px-4 py-2 text-sm disabled:cursor-not-allowed",onClick:S,disabled:x||l.size===0,children:[n.jsx(ie,{size:14}),e("chat.askFinishQuestion",{count:l.size})]}):n.jsxs("button",{type:"button",className:"btn btn-accent px-4 py-2 text-sm disabled:cursor-not-allowed",onClick:Q,disabled:x||i<0,children:[n.jsx(ie,{size:14}),e("chat.askConfirmQuestion")]})}),n.jsx("div",{className:"text-xs text-dark-muted",children:f?n.jsx("span",{children:e("chat.askEnterHint")}):H.multiSelect?n.jsx("span",{children:e("chat.askMultiHintBatch")}):n.jsx("span",{children:e("chat.askSingleHintBatch")})})]}):null]}):n.jsxs("div",{className:"flex flex-col gap-4",children:[s.autoResolutionMs&&s.autoResolutionMs>0&&n.jsx("div",{className:"inline-flex items-center gap-2 rounded-md border border-accent-yellow/30 bg-accent-yellow/10 px-3 py-1.5 text-xs text-accent-yellow",children:e("chat.askAutoContinue",{seconds:Math.max(1,Math.round(s.autoResolutionMs/1e3))})}),n.jsx("div",{className:"text-sm text-dark-muted leading-relaxed",children:s.question}),n.jsx(Ye,{item:j[0],answered:!1,selectedIdx:i,multiSelected:l,customInput:u,showCustomInput:f,onSelect:V,onToggleMulti:m,onProceed:A,onEnterCustom:q,onCancelCustom:X,onSubmitCustom:B,onCustomChange:p,inputRef:K}),!f&&n.jsx("div",{className:"flex items-center gap-2",children:s.multiSelect?n.jsxs("button",{type:"button",className:"btn btn-accent px-4 py-2 text-sm disabled:cursor-not-allowed",onClick:S,disabled:x||l.size===0,children:[n.jsx(ie,{size:14}),e("chat.askSubmitSelected",{count:l.size})]}):n.jsxs("button",{type:"button",className:"btn btn-accent px-4 py-2 text-sm disabled:cursor-not-allowed",onClick:G,disabled:x||i<0,children:[n.jsx(ie,{size:14}),e("chat.askSubmit")]})}),n.jsx("div",{className:"text-xs text-dark-muted",children:x?n.jsx("span",{children:e("chat.askSubmitting")}):k?n.jsxs("span",{className:"flex items-center gap-1.5 text-accent-yellow",children:[n.jsx(pe,{size:12}),e("chat.askSubmitRetry")]}):f?n.jsx("span",{children:e(b?"chat.askSecretHint":"chat.askEnterHint")}):s.multiSelect?n.jsx("span",{children:e("chat.askMultiHintSingle")}):n.jsx("span",{children:e("chat.askSingleHintSingle")})})]})})}const me=15;function zn({isOpen:t,onCloseModal:r}){const{t:e}=Z("hook"),s=Qt(),a=s.pendingApprovals,i=s.autoMode,o=s.setAutoMode,[l,c]=d.useState(0),[u,p]=d.useState(!1),[f,g]=d.useState(me),[x,v]=d.useState(!0),k=d.useRef(null),C=d.useRef(!1);d.useEffect(()=>{if(a.length!==0){if(i){a.forEach(B=>{ne.send({type:"hook_allow",data:JSON.stringify({approvalId:B.approvalId})})}),s.clearApprovals();return}c(B=>Math.min(B,a.length-1))}},[a.length,i]);const h=a[l]??null,y=a.length>0&&h!==null,T=a.length,I=y?T-l-1:0;d.useEffect(()=>{if(!(!y||u||!t||!h))return g(me),k.current=setInterval(()=>{g(B=>B<=1?(k.current&&clearInterval(k.current),0):B-1)},1e3),()=>{k.current&&clearInterval(k.current)}},[y,u,t,h==null?void 0:h.approvalId]);const N=h?Yt(h.toolName,h.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},O=Zt[N.level],D=es[N.level==="CRITICAL"?"critical":N.level==="HIGH"?"high":N.level==="LOW"?"low":"medium"],E=h?Pt(h.toolName,h.askPayload):null,K=h?ts(h.toolName,h.askPayload):null,P=h?{verb:Lt(h.toolName),target:$t(h.toolName,h.askPayload)}:null,j=h?$e(h.askPayload)!==null:!1,R=h?Ht(h.toolName,h.askPayload):null,L=f/me*100,H=f<=5,z=Ee((me-f)*1e3),J=d.useCallback((B,U)=>{const te=nt.getState().activeSessionId;te&&ae.getState().updateHookApprovalStatus(te,B,U)},[]),b=d.useCallback(B=>{h&&(B&&J(h.approvalId,B),p(!0),setTimeout(()=>{s.removeApproval(h.approvalId),c(0),p(!1),C.current=!1,g(me)},200))},[h==null?void 0:h.approvalId,s,J]),M=d.useCallback(()=>{!h||u||C.current||(C.current=!0,k.current&&clearInterval(k.current),ne.send({type:"hook_allow",data:JSON.stringify({approvalId:h.approvalId})}),b("approved"))},[h,b,u]),_=d.useCallback(()=>{!h||u||C.current||(C.current=!0,k.current&&clearInterval(k.current),ne.send({type:"hook_deny",data:JSON.stringify({approvalId:h.approvalId})}),b("denied"))},[h,b,u]),$=d.useCallback(()=>{if(!h||u||C.current)return;C.current=!0,k.current&&clearInterval(k.current);const B=$e(h.askPayload);B?(s.addToSessionAllowList(h.toolName,B),ne.send({type:"hook_allow",data:JSON.stringify({approvalId:h.approvalId,sessionAllow:!0})})):(s.addToSessionAllowList(h.toolName),ne.send({type:"hook_allow",data:JSON.stringify({approvalId:h.approvalId})})),b("approved")},[h,b,s,u]),V=d.useCallback(()=>{!h||u||C.current||(C.current=!0,k.current&&clearInterval(k.current),o(!0),Ae.getState().setAuto(!0),ne.send({type:"hook_allow",data:JSON.stringify({approvalId:h.approvalId})}),b("approved"))},[h,b,u,o]),G=((h==null?void 0:h.timeoutMs)??15e3)>0,Q=(h==null?void 0:h.timeoutAction)==="deny"?_:M;if(d.useEffect(()=>{f===0&&t&&!u&&h&&G&&Q()},[f,t,u,h,Q,G]),d.useEffect(()=>{if(!t||!x)return;const B=U=>{const te=U.target;te&&typeof te.closest=="function"&&te.closest('input, textarea, select, [contenteditable="true"]')||(U.key==="Escape"?(U.preventDefault(),U.stopPropagation(),_()):U.key==="Enter"?(U.preventDefault(),M()):U.key==="1"?M():U.key==="2"?_():U.key==="3"?$():U.key==="4"&&V())};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[t,x,M,_,$,V]),!y||!h)return null;const Y=e("optionAllowHint"),m=e("optionDenyHint"),S=j?e("optionAllowPathHint"):e("optionAllowAlwaysHint",{tool:h.toolName}),A=e("optionAutoModeHint"),q=(E==null?void 0:E.text)??K??null,X=q?n.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx("code",{className:"font-mono text-meta bg-dark-surface text-accent-blue px-1 py-0.5 rounded shrink-0",children:h.toolName}),n.jsx("span",{className:"truncate",children:q})]}):null;return n.jsx(st,{isOpen:t,onClose:()=>r==null?void 0:r(),title:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(De,{className:"w-4 h-4 text-accent-yellow"}),n.jsx("span",{children:e("hookApproval")}),n.jsxs("span",{className:"text-xs text-dark-muted",children:["(",l+1,"/",T,")"]})]}),badge:n.jsxs("span",{className:`px-1.5 py-0.5 rounded text-badge font-bold border shrink-0 ${O.badge}`,children:[O.icon," ",N.level]}),collapsedSummary:X,onExpandedChange:v,maxHeight:"50vh",children:n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${O.bg} border ${O.border}`,children:[n.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${O.badge}`,children:[O.icon," ",N.level]}),n.jsx("span",{className:"text-xs text-dark-muted truncate",children:e(N.reasonKey)}),n.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[n.jsx(Tt,{size:12,className:H?"text-accent-red":"text-dark-muted"}),n.jsx("span",{className:`text-xs font-mono ${H?"text-accent-red animate-pulse":"text-dark-muted"}`,children:G?`${f}s`:"∞"}),n.jsx("div",{className:"w-12 h-1.5 bg-dark-border rounded-full overflow-hidden",children:n.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${H?"bg-accent-red":f<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${L}%`}})})]})]}),n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx("span",{className:"flex-none w-7 h-7 rounded-lg bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center",children:n.jsx(De,{size:15})}),P&&n.jsx(qt,{pre:e(P.verb),obj:P.target})]}),R&&(R.external&&R.path?n.jsxs("span",{className:"flex items-center gap-1 text-meta px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow border border-accent-yellow shrink-0",title:R.path,children:[n.jsx(It,{size:10}),e("scopeExternal"),": ",R.path.length>48?`${R.path.slice(0,47)}…`:R.path]}):n.jsx("span",{className:"text-meta text-dark-muted/60 shrink-0",children:e("scopeLocal")}))]}),n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"text-dark-muted shrink-0",children:e("tool")}),n.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate",children:h.toolName}),n.jsx("span",{className:"text-dark-muted/50",children:z}),n.jsx("span",{className:"text-dark-muted/50",children:D.label}),h.timeoutAction&&n.jsxs("span",{className:`text-xs ${h.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",G?`${h.timeoutAction==="allow"?"auto-allow":"auto-deny"}${h.timeoutMs?` (${(h.timeoutMs/1e3).toFixed(0)}s)`:""}`:e("timeoutWaitUser")]})]}),E?n.jsx(Fe,{text:E.text,mono:E.mono}):K?n.jsx(Fe,{text:K}):null,(N.level==="CRITICAL"||N.level==="HIGH")&&n.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${O.bg} ${O.text}`,children:[n.jsx(pe,{size:13}),n.jsx("span",{children:N.level==="CRITICAL"?e("highRiskWarning"):e("mediumRiskConfirm")})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsxs(ss,{variant:"accent",onClick:M,disabled:u,children:[n.jsx("span",{className:"text-badge font-mono bg-accent-fg/20 rounded px-1",children:"1"}),n.jsx("span",{children:fe.allow.label}),n.jsx("span",{className:"text-meta text-accent-fg/70 hidden sm:inline",children:Y})]}),n.jsxs("button",{onClick:$,disabled:u,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[n.jsx("span",{className:"text-badge font-mono text-dark-muted bg-dark-surface rounded px-1",children:"3"}),n.jsx("span",{children:fe.allow_session.label}),n.jsx("span",{className:"text-meta text-dark-muted/60 hidden sm:inline",children:S})]}),n.jsxs("button",{onClick:V,disabled:u,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[n.jsx("span",{className:"text-badge font-mono text-dark-muted bg-dark-surface rounded px-1",children:"4"}),n.jsx("span",{children:fe.auto.label}),n.jsx("span",{className:"text-meta text-dark-muted/60 hidden sm:inline",children:A})]}),n.jsx("span",{className:"flex-1"}),n.jsxs("button",{onClick:_,disabled:u,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-accent-red/15 hover:text-accent-red text-sm transition-colors disabled:opacity-50",children:[n.jsx("span",{className:"text-badge font-mono text-dark-muted/60 rounded px-1",children:"2"}),n.jsx("span",{children:fe.deny.label}),n.jsx("span",{className:"text-meta text-dark-muted/60 hidden sm:inline",children:m})]})]}),n.jsxs("div",{className:"flex items-center justify-between text-xs text-dark-muted/60",children:[n.jsx("span",{children:e("shortcutHint")}),n.jsx("span",{children:I>0?e("morePending",{n:I}):e("lastItem")})]})]})})}const Te="dsc-auto-access-banner-dismissed",Dn=d.memo(function(){const{t:r}=Z(),e=Ae(l=>l.mode),[s,a]=d.useState(()=>localStorage.getItem(Te)==="1");d.useEffect(()=>{Le(e==="normal"?"act":e)||localStorage.getItem(Te)==="1"&&a(!1)},[e]);const i=d.useCallback(l=>{l&&localStorage.setItem(Te,"1"),a(!0)},[]);return!(e!=="normal"&&Le(e))||s?null:n.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-1 text-meta leading-snug text-accent-yellow/75 bg-accent-yellow/[0.05] border-b border-accent-yellow/10 select-none",role:"note",title:r("autoAccess.desc"),children:[n.jsx(Mt,{size:11,className:"shrink-0 text-accent-yellow/70"}),n.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[n.jsx("span",{className:"font-medium",children:r("autoAccess.title")}),n.jsxs("span",{className:"text-accent-yellow/60",children:[" · ",r("autoAccess.desc")]})]}),n.jsx("button",{onClick:()=>i(!1),className:"shrink-0 rounded p-0.5 text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors",title:r("autoAccess.dismiss"),"aria-label":r("autoAccess.dismiss"),children:n.jsx(le,{size:11})}),n.jsx("button",{onClick:()=>i(!0),className:"shrink-0 rounded px-1 py-px text-badge text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors whitespace-nowrap",children:r("autoAccess.neverShow")})]})}),Fn=12,Pn=56;function lt(t,r){const e=t.replace(/\s+/g," ").trim();return e.length>r?`${e.slice(0,r)}…`:e}function $n(t){return lt(t,Fn)}function Ze(){return`custom-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Ln(t,r){return t.some(e=>e.kind==="scenario"&&e.id===r)}function Hn(t){if(!t||typeof t!="object")return!1;const r=t;return typeof r.id!="string"||r.id===""||typeof r.label!="string"||r.label===""||typeof r.hint!="string"?!1:r.kind==="template"?typeof r.templateId=="string"&&r.templateId!=="":r.kind!==void 0&&r.kind!=="prompt"?!1:typeof r.prompt=="string"&&r.prompt!==""}function qn(t){if(!t||typeof t!="object")return!1;const r=t;return typeof r.id=="string"&&r.id!==""&&typeof r.label=="string"&&r.label!==""&&Array.isArray(r.scenarios)&&r.scenarios.length>0&&r.scenarios.every(Hn)}function Bn(t){const r=t("chat.start.categories",{returnObjects:!0,defaultValue:[]});return Array.isArray(r)?r.filter(qn):[]}const Kn="tpl:",Vn="tpl-";function et(t){return t.trim().toLowerCase()}function Wn(t){const r=new Map;for(const e of t){const s=(e.category??"").trim();if(!s)continue;const a=(e.name??"").trim();if(!a)continue;const i={id:`${Vn}${e.id}`,label:a,hint:e.description??"",prompt:"",kind:"template",templateId:e.id},o=r.get(s);o?o.push(i):r.set(s,[i])}return[...r].map(([e,s])=>({id:`${Kn}${e}`,label:e,scenarios:s}))}function Un(t,r){if(r.length===0)return t;const e=t.map(i=>({...i})),s=new Set(e.map(i=>i.id)),a=new Map(e.map((i,o)=>[et(i.label),o]));for(const i of r){const o=et(i.label),l=a.get(o);if(l!==void 0){const c=e[l];e[l]={...c,scenarios:[...c.scenarios,...i.scenarios]};continue}s.has(i.id)||(s.add(i.id),a.set(o,e.length),e.push(i))}return e}const ct=6;function Gn(t,r,e){const s=new Map;for(const o of t)for(const l of o.scenarios)s.set(l.id,l);const a=new Set,i=[];for(const o of r){if(a.has(o.id))continue;if(a.add(o.id),o.kind==="custom"){i.push({id:o.id,label:o.label,hint:lt(o.prompt,Pn),prompt:o.prompt});continue}const l=s.get(o.id);l&&i.push(l)}return dt(i,e).slice(0,ct)}function Xn(t){return t<5?"chat.start.greetingDawn":t<11?"chat.start.greetingMorning":t<13?"chat.start.greetingNoon":t<18?"chat.start.greetingAfternoon":"chat.start.greetingEvening"}function Jn(t,r,e){const s=t(Xn(r)),a=(e??"").trim();return a?t("chat.start.withName",{greeting:s,name:a}):s}function dt(t,r){return t.map((e,s)=>({scenario:e,index:s,count:r[e.id]??0})).sort((e,s)=>s.count-e.count||e.index-s.index).map(e=>e.scenario)}function Qn(t,r){return t.length===0||!r?null:t.find(e=>e.id===r)??null}const se=is()(ns((t,r)=>({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0,setCategoryId:e=>t({categoryId:e,suggestionsHidden:!1}),recordUse:e=>t(s=>({clickCounts:{...s.clickCounts,[e]:(s.clickCounts[e]??0)+1},favorites:s.favorites.some(a=>a.id===e)?s.favorites:[{kind:"scenario",id:e},...s.favorites]})),toggleFavorite:e=>t(s=>({favorites:s.favorites.some(a=>a.kind==="scenario"&&a.id===e)?s.favorites.filter(a=>!(a.kind==="scenario"&&a.id===e)):[{kind:"scenario",id:e},...s.favorites]})),removeFavorite:e=>t(s=>({favorites:s.favorites.filter(a=>a.id!==e)})),addCustomFavorite:(e,s)=>{const a=s.trim();if(!a)return null;let i=Ze();const o=new Set(r().favorites.map(c=>c.id));for(;o.has(i);)i=Ze();const l={kind:"custom",id:i,label:e.trim()||$n(a),prompt:a};return t(c=>({favorites:[l,...c.favorites]})),l},toggleSuggestions:()=>t(e=>({suggestionsHidden:!e.suggestionsHidden})),requestFocus:()=>t(e=>({prefillNonce:e.prefillNonce+1})),reset:()=>t({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0})}),{name:"deepseekcode-start-page-storage",partialize:t=>({categoryId:t.categoryId,clickCounts:t.clickCounts,favorites:t.favorites,suggestionsHidden:t.suggestionsHidden}),version:2,migrate:(t,r)=>{const e=r??0;if(e>=2||!t||typeof t!="object")return t;const s=t,a=e<1?!0:s.suggestionsHidden,i=e<1?Object.entries(s.clickCounts??{}).sort((o,l)=>l[1]-o[1]).slice(0,ct).map(([o])=>o):s.favoriteIds??[];return{categoryId:s.categoryId??null,clickCounts:s.clickCounts??{},suggestionsHidden:a,favorites:i.map(o=>({kind:"scenario",id:o}))}}}));function Yn(t){return typeof t!="string"||!t?null:t.split(/[\\/]+/).pop()||null}const Zn={enabled:!0,exists:!1,name:null,file:null};function er(){const[t,r]=d.useState(Zn);return d.useEffect(()=>{let e=!1;const s=()=>{xe.profile.get().then(a=>{if(e||!a.success||!a.data)return;const i=a.data,o=i.enabled!==!1,l=i.exists===!0,c={enabled:o,exists:l,name:o&&i.name?i.name:null,file:o&&l?Yn(i.path):null};r(u=>u.enabled===c.enabled&&u.exists===c.exists&&u.name===c.name&&u.file===c.file?u:c)}).catch(()=>{})};return s(),window.addEventListener(He,s),()=>{e=!0,window.removeEventListener(He,s)}},[]),t}const tr=d.memo(function(){return n.jsxs("div",{className:"relative isolate flex min-h-[8.5rem] w-full flex-col justify-end pb-1",children:[n.jsx(sr,{}),n.jsx(ar,{})]})}),sr=d.memo(function(){const{t:r}=Z(),{enabled:e,exists:s,name:a,file:i}=er(),o=d.useMemo(()=>Jn(r,new Date().getHours(),a),[r,a]);return n.jsxs("div",{className:"chat-col px-4 pt-2 sm:px-6",children:[n.jsxs("h1",{className:"text-2xl font-semibold leading-snug tracking-tight text-dark-text",children:[n.jsx("span",{className:"block",children:o}),n.jsx("span",{className:"block",children:r("chat.start.question")})]}),n.jsx(nr,{enabled:e,exists:s,name:a,file:i})]})});function nr({enabled:t,exists:r,name:e,file:s}){const{t:a}=Z(),i=t?e?a("chat.start.profileOn",{name:e}):r?s?a("chat.start.profileFile",{file:s}):a("chat.start.profileSet"):a("chat.start.profileAnonymous"):a("chat.start.profileDisabled"),o=d.useCallback(()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"profile"}}))},[]);return n.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:n.jsxs("button",{type:"button",onClick:o,title:a("chat.start.profileHint"),className:"inline-flex min-w-0 items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-meta text-dark-muted transition-colors hover:border-accent-blue/40 hover:text-dark-text",children:[n.jsx(zt,{size:11,"aria-hidden":"true",className:"shrink-0"}),n.jsx("span",{className:"truncate",children:i}),n.jsxs("span",{className:"shrink-0 text-dark-muted/70",children:["· ",a("chat.start.profileEdit")]})]})})}const rr=[{glyph:"/",labelKey:"shortcuts.slashCommand"},{glyph:"@",labelKey:"shortcuts.fileRef"},{glyph:"!",labelKey:"shortcuts.shellCommand"},{glyph:"$",labelKey:"shortcuts.skillRef"}],ar=d.memo(function(){const{t:r}=Z();return n.jsx("ul",{"data-testid":"start-tips","aria-label":r("shortcuts.title"),className:"chat-col mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 px-4 sm:px-6",children:rr.map(e=>n.jsxs("li",{className:"inline-flex items-center gap-1.5 text-badge text-dark-muted/60",children:[n.jsx("kbd",{className:"rounded border border-dark-border bg-dark-bg px-1.5 py-0.5 font-mono text-badge leading-none text-dark-muted",children:e.glyph}),n.jsx("span",{children:r(e.labelKey)})]},e.glyph))})}),ir=d.memo(function({sessionId:r,onStartTemplate:e}){const{t:s}=Z(),[a,i]=d.useState([]);d.useEffect(()=>{if(!e)return;let m=!1;return xe.templates.list().then(S=>{!m&&S.success&&S.data&&i(S.data)}).catch(()=>{}),()=>{m=!0}},[e]);const o=d.useMemo(()=>Un(Bn(s),Wn(a)),[s,a]),l=se(m=>m.categoryId),c=se(m=>m.setCategoryId),u=se(m=>m.clickCounts),p=se(m=>m.favorites),f=se(m=>m.recordUse),g=se(m=>m.toggleFavorite),x=se(m=>m.removeFavorite),v=se(m=>m.addCustomFavorite),k=se(m=>m.suggestionsHidden),C=se(m=>m.toggleSuggestions),h=se(m=>m.requestFocus),y=d.useMemo(()=>Qn(o,l),[o,l]),T=d.useCallback(()=>c(null),[c]),I=d.useMemo(()=>y?dt(y.scenarios,u):Gn(o,p,u),[y,o,p,u]),[N,O]=d.useState(!1),[D,E]=d.useState(""),[K,P]=d.useState(""),j=d.useCallback(()=>{O(!1),E(""),P("")},[]),R=d.useCallback(()=>{O(!0),k&&C()},[k,C]),L=d.useCallback(m=>{m.preventDefault(),v(D,K)&&j()},[v,j,D,K]),H=d.useCallback(m=>{r&&(ae.getState().setSessionInput(r,m.prompt),f(m.id),h())},[r,f,h]),[z,J]=d.useState(null),[b,M]=d.useState(""),_=d.useCallback(async m=>{M("");const S=await xe.templates.get(m);if(!S.success||!S.data){M(s("templates.loadFailed"));return}J(S.data),k&&C()},[s,k,C]),$=d.useCallback(m=>{if(m.kind==="template"&&m.templateId){e&&_(m.templateId);return}H(m)},[e,_,H]),V=d.useRef([]),[G,Q]=d.useState(0),Y=d.useCallback((m,S,A)=>{var q;if(m.key==="ArrowDown"||m.key==="ArrowUp"){m.preventDefault();const X=m.key==="ArrowDown"?Math.min(S+1,I.length-1):Math.max(S-1,0);Q(X),(q=V.current[X])==null||q.focus();return}if(m.key==="Tab"){m.preventDefault(),$(A);return}},[$,I.length]);return o.length===0?null:n.jsxs("div",{className:"start-col max-md:order-3 px-4 pb-4 sm:px-6",children:[n.jsxs("div",{role:"tablist","aria-label":s("chat.start.categoriesLabel"),onKeyDown:m=>{m.key==="Escape"&&l&&(m.preventDefault(),T())},className:"snap-row mt-5 flex items-center gap-2 overflow-x-auto pb-1",children:[o.map(m=>{const S=m.id===l;return n.jsxs("span",{"data-testid":"start-chip","data-category-id":m.id,"data-selected":S?"true":void 0,className:`inline-flex shrink-0 items-center overflow-hidden rounded-full border transition-colors focus-within:ring-1 focus-within:ring-accent-blue/60 ${S?"border-transparent bg-gradient-to-r from-accent-blue to-accent-purple text-accent-fg shadow-sm":"border-dark-border/70 text-dark-muted hover:border-accent-blue/40 hover:text-dark-text"}`,children:[n.jsx("button",{type:"button",role:"tab","aria-selected":S,"data-testid":"start-chip-label",onClick:()=>c(S?null:m.id),className:`py-1 text-meta transition-colors focus-visible:outline-none ${S?"pl-3 pr-1.5":"px-3"}`,children:m.label}),S&&n.jsx("button",{type:"button","data-testid":"start-chip-clear","aria-label":s("chat.start.clearCategory",{label:m.label}),title:s("chat.start.clearCategory",{label:m.label}),onClick:T,className:"py-1 pl-0 pr-2 text-accent-fg/75 transition-colors hover:text-accent-fg focus-visible:outline-none",children:n.jsx(le,{size:12,"aria-hidden":"true"})})]},m.id)}),n.jsx(Ie,{size:13,"aria-hidden":"true",className:"shrink-0 text-dark-muted/50"})]}),n.jsxs("div",{className:"mt-2.5",children:[n.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[n.jsxs("span",{className:"min-w-0 truncate text-meta text-dark-muted/60",children:[y?s("chat.start.categoryTitle",{label:y.label}):s("chat.start.frequentTitle"),n.jsx("span",{className:"ml-2 text-dark-muted/40",children:s(y?"chat.start.selectedHint":"chat.start.frequentHint")})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[!y&&!N&&n.jsxs("button",{type:"button","data-testid":"start-custom-add",onClick:R,className:"inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text",children:[n.jsx(Et,{size:11,"aria-hidden":"true"}),s("chat.start.customAdd")]}),n.jsx("button",{type:"button",onClick:C,className:"inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text",children:k?n.jsxs(n.Fragment,{children:[n.jsx(At,{size:11,"aria-hidden":"true"}),s("chat.start.show")]}):n.jsxs(n.Fragment,{children:[n.jsx(Rt,{size:11,"aria-hidden":"true"}),s("chat.start.hide")]})})]})]}),b&&n.jsx("div",{"data-testid":"start-template-error",className:"mb-2 text-meta text-accent-red",children:b}),z&&n.jsxs("div",{"data-testid":"start-template-form",className:"mb-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3",children:[n.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:z.name}),n.jsx(rs,{template:z,onCancel:()=>J(null),onSubmit:m=>{const S=z;J(null),e==null||e(S,m)},submitLabel:s("templates.launch")})]}),N&&!y&&n.jsxs("form",{"data-testid":"start-custom-form",onSubmit:L,className:"mb-2 flex flex-col gap-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3",children:[n.jsx("input",{"data-testid":"start-custom-label",value:D,onChange:m=>E(m.target.value),placeholder:s("chat.start.customLabelPlaceholder"),maxLength:40,className:"w-full rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none"}),n.jsx("textarea",{"data-testid":"start-custom-prompt",value:K,onChange:m=>P(m.target.value),placeholder:s("chat.start.customPromptPlaceholder"),rows:2,autoFocus:!0,className:"w-full resize-none rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs leading-snug text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none"}),n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("button",{type:"button","data-testid":"start-custom-cancel",onClick:j,className:"rounded-md px-2.5 py-1 text-meta text-dark-muted transition-colors hover:text-dark-text",children:s("chat.start.customCancel")}),n.jsx("button",{type:"submit","data-testid":"start-custom-save",disabled:!K.trim(),className:"rounded-md border border-accent-blue/40 bg-accent-blue/10 px-2.5 py-1 text-meta font-medium text-accent-blue transition-colors hover:bg-accent-blue/20 disabled:cursor-not-allowed disabled:border-dark-border/60 disabled:bg-transparent disabled:text-dark-muted/40",children:s("chat.start.customSave")})]})]}),!k&&!z&&(I.length===0?N?null:n.jsx("p",{"data-testid":"start-frequent-empty",className:"rounded-xl border border-dashed border-dark-border/60 px-4 py-3 text-xs leading-relaxed text-dark-muted/70",children:s("chat.start.frequentEmpty")}):n.jsx("div",{className:"overflow-hidden rounded-xl border border-dark-border/60 bg-dark-surface/40",children:I.map((m,S)=>{const A=Ln(p,m.id);return n.jsxs("div",{"data-testid":"start-row-shell",className:`group flex items-center transition-colors hover:bg-dark-hover/40 focus-within:bg-dark-hover/40 ${S>0?"border-t border-dark-border/40":""}`,children:[n.jsxs("button",{ref:q=>{V.current[S]=q},type:"button","data-testid":"start-row","data-scenario-id":m.id,tabIndex:S===G?0:-1,onClick:()=>$(m),onKeyDown:q=>Y(q,S,m),className:"flex min-w-0 flex-1 items-baseline gap-3 py-2.5 pl-4 pr-2 text-left transition-colors focus-visible:outline-none",children:[n.jsx("span",{className:"w-[84px] shrink-0 text-compact font-medium leading-snug text-dark-text",children:m.label}),n.jsx("span",{className:"min-w-0 flex-1 border-l border-dark-border/50 pl-3 text-compact leading-snug text-dark-muted",children:m.hint}),n.jsx(Ot,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-dark-muted/40"})]}),y?n.jsx("button",{type:"button","data-testid":"start-row-favorite","aria-pressed":A,"aria-label":s(A?"chat.start.removeFavorite":"chat.start.addFavorite",{label:m.label}),title:s(A?"chat.start.removeFavorite":"chat.start.addFavorite",{label:m.label}),onClick:()=>g(m.id),className:`mr-2 shrink-0 rounded-md p-1.5 transition-colors focus-visible:outline-none ${A?"text-accent-yellow":"text-dark-muted/40 hover:text-dark-text"}`,children:n.jsx(_t,{size:13,"aria-hidden":"true",className:A?"fill-current":""})}):n.jsx("button",{type:"button","data-testid":"start-row-remove","aria-label":s("chat.start.removeFavorite",{label:m.label}),title:s("chat.start.removeFavorite",{label:m.label}),onClick:()=>x(m.id),className:"mr-2 shrink-0 rounded-md p-1.5 text-dark-muted/40 transition-colors hover:text-dark-text focus-visible:outline-none",children:n.jsx(le,{size:13,"aria-hidden":"true"})})]},m.id)})}))]})]})});function or(t){const{sessionId:r,isGenerating:e,messages:s}=t,{i18n:a}=Z(),i=d.useRef(e),o=d.useRef(r);d.useEffect(()=>{const l=i.current,c=o.current!==r;if(i.current=e,o.current=r,c||!l||e)return;const u=os();if(!(!u.enabled||!u.autoPlay))for(let p=s.length-1;p>=0;p--){const f=s[p];if(!f||f.type!=="assistant")continue;const g=(f.content||"").trim();if(g){if(!ls(g))return;Bt(g,as(a.language));return}}},[e,r,s,a.language]),d.useEffect(()=>()=>Kt(),[r])}const lr=[{mode:"chat",Icon:Dt,labelKey:"trajectory.viewChat"},{mode:"trajectory",Icon:Ft,labelKey:"trajectory.viewTrajectory"}],tt=[],yr=d.memo(function({tabs:r,activeSessionId:e,onSend:s,onStop:a,onPause:i,onResume:o,activeTab:l,setActiveTab:c,createNewSession:u,clearMessages:p,setTheme:f,setThemePreset:g,setLogs:x,setUnreadLogs:v,onRegenerate:k,onRetryTurn:C,onDeleteMessage:h,onOpenSidebarView:y,hookDrawerOpen:T,onCloseHookDrawer:I,questionDrawerOpen:N,onCloseQuestionDrawer:O,workspaceDir:D,onWorkspaceSelect:E,errorLogs:K,onOpenLogs:P,onStartTemplate:j}){const R=d.useMemo(()=>({setActiveTab:c,createNewSession:u,clearMessages:p,setTheme:f,setThemePreset:g,setLogs:x,setUnreadLogs:v}),[c,u,p,f,g,x,v]),[L,H]=d.useState("chat"),{t:z}=Z(),J=ae(S=>e?S.messagesBySession[e]??tt:tt),b=ae(S=>e?S.generatingSessions.includes(e):!1),M=ae(S=>e?S.pausedSessions.includes(e):!1);or({sessionId:e,isGenerating:b,messages:J});const _=r.find(S=>S.id===e)||null,$=d.useMemo(()=>J.filter(S=>!S.deleted).length===0,[J]),V=se(S=>S.prefillNonce),G=d.useCallback((S,A,q,X,B,U)=>{if(!e)return;const te=X||U?{...X?{mentions:X,mentionDeliveryMode:B}:{},...U?{display:U}:{}}:void 0;s(e,S,A,q,te)},[s,e]),Q=d.useCallback(async S=>{const A=e;if(!A)return;const q=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,X=Date.now();ae.getState().addMessage(A,{id:q,type:"user",content:`!${S}`,timestamp:X,noTruncate:!0,shellRun:{command:S,stdout:"",stderr:"",exitCode:null,durationMs:0,running:!0}});const U=await xe.shell.exec(S,D),te=U.success&&U.data?{...U.data,running:!1}:{command:S,stdout:"",stderr:"",exitCode:null,durationMs:Date.now()-X,running:!1,error:U.error||z("chat.shellRequestFailedGeneric")};ae.getState().updateMessage(A,q,{shellRun:te})},[e,D,z]),Y=d.useCallback(S=>{e&&k&&k(e,S)},[k,e]),m=d.useCallback(S=>{e&&h&&h(e,S)},[h,e]);return n.jsx("div",{className:"flex-1 flex min-h-0",children:n.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[n.jsx(Dn,{}),_&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex h-7 shrink-0 items-center justify-end px-3",children:n.jsxs("div",{role:"radiogroup","aria-label":z("trajectory.viewToggleTitle"),className:"relative inline-grid grid-cols-2 items-center rounded-full border border-dark-border bg-dark-surface/60 p-0.5 text-meta leading-none",children:[n.jsx("span",{"aria-hidden":"true",className:`pointer-events-none absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-full ring-1 transition-transform duration-200 ease-out motion-reduce:transition-none ${L==="trajectory"?"translate-x-full bg-accent-blue/20 ring-accent-blue/40":"translate-x-0 bg-dark-hover ring-dark-border"}`}),lr.map(({mode:S,Icon:A,labelKey:q})=>{const X=L===S;return n.jsxs("button",{type:"button",role:"radio","aria-checked":X,title:z("trajectory.viewToggleTitle"),onClick:()=>H(S),className:`relative z-10 flex items-center justify-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60 ${X?"text-dark-text":"text-dark-muted hover:text-dark-text"}`,children:[n.jsx(A,{size:11}),z(q)]},S)})]})}),n.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col ${$&&L==="chat"?"justify-center overflow-y-auto custom-scrollbar py-2 max-md:justify-start":""}`,children:[L==="chat"?n.jsx(n.Fragment,{children:$?n.jsx(tr,{}):n.jsxs(n.Fragment,{children:[n.jsx(Vt,{messages:J,isGenerating:b,isPaused:M,sessionId:_.id,onRegenerate:k?Y:void 0,onRetryTurn:C,onDeleteMessage:h?m:void 0,onOpenSidebarView:y}),n.jsx(zn,{isOpen:!!T,onCloseModal:I}),n.jsx(_n,{isOpen:!!N,onClose:O??(()=>{})})]})}):n.jsx(In,{sessionId:_.id,messages:J,errorLogs:K,onOpenLogs:P}),n.jsx(n.Fragment,{children:n.jsx(En,{activeSessionId:_.id})}),n.jsx(Wt,{sessionId:_.id,onSend:G,onRunShell:Q,onStop:()=>a(_.id),onPause:()=>i(_.id),onResume:()=>o(_.id),slashOptions:R,workspaceDir:D,onWorkspaceSelect:E,focusRequest:V}),L==="chat"&&$&&n.jsx(ir,{sessionId:_.id,onStartTemplate:j})]})]})]})})});export{yr as SessionGrid};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{j as e}from"./markdown-BWXjRrSw.js";import{a,d as _,ax as je,A as F,p as ve,f as Ae,C as Be,G as ye,u as R,i as Oe,J as Ne,x as W,am as V,ay as de,az as Me,O as ae,D as we,aA as ne,aB as Re,aC as Ge,aD as re,P as He,aE as Ue,k as Ce,aF as le,z as Z,at as We,aG as se,aH as Se,q as _e,aI as Ve,aJ as Ee,o as Te,a7 as ze,v as Q,aK as $e,t as ie,X as qe,S as Ye,ak as Ke,Q as Xe,aL as Je,E as Fe,aM as Qe,H as Ze}from"./icons-Bm_ZzSAy.js";import{a as E,t as j,B as G,u as D,f as H,j as xe,e as et,i as Le,S as tt,W as ue,X as st,Y as at,h as nt,Z as rt,$ as lt,a0 as it,a1 as me}from"./index-CeeLdENM.js";import{r as ct,p as ot,s as dt,D as xt,a as ut,w as mt,T as pt,b as gt}from"./sttLanguages-C7kVulzY.js";import{n as ee}from"./profileChange-B7TaQ18u.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";function bt(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ft(t){return new Date(t).toLocaleString()}function ht(){const[t,s]=a.useState([]),[l,i]=a.useState(null),[m,r]=a.useState(""),[x,d]=a.useState(""),[f,n]=a.useState(!1),[b,p]=a.useState(!1),k=a.useCallback(async()=>{n(!0);try{const g=await E.config.files.list();g.success&&Array.isArray(g.data)&&s(g.data)}catch{j.error("Failed to load config files")}finally{n(!1)}},[]),v=a.useCallback(async g=>{try{const K=await E.config.files.read(g);if(K.success&&K.data){const L=K.data;i(L.name),r(L.content),d(L.content)}}catch{j.error(`Failed to read ${g}`)}},[]);a.useEffect(()=>{k()},[k]);const o=a.useCallback(async()=>{if(l){p(!0);try{const g=await E.config.files.write(l,m);g.success?(d(m),j.success(`${l} saved`),k()):j.error(g.error||"Failed to save")}catch{j.error("Failed to save file")}finally{p(!1)}}},[l,m,k]),y=m!==x,N=(l==null?void 0:l.endsWith(".yaml"))||(l==null?void 0:l.endsWith(".yml")),S=l==null?void 0:l.endsWith(".json"),$=g=>N?g.replace(/(#.*)$/,'<span class="text-dark-muted">$1</span>').replace(/^(\s*)([\w-]+)(:)/,'$1<span class="text-accent-blue">$2</span>$3').replace(/:\s+(true|false|null|~)(\s*)$/,': <span class="text-accent-purple">$1</span>$2').replace(/:\s+(\d+\.?\d*)(\s*)$/,': <span class="text-accent-green">$1</span>$2').replace(/:\s+"([^"]*)"(\s*)$/,': <span class="text-accent-yellow">"$1"</span>$2'):S?g.replace(/(\s*"[^"]*")(\s*:)/g,'<span class="text-accent-blue">$1</span>$2').replace(/:\s+(true|false|null)/g,': <span class="text-accent-purple">$1</span>').replace(/:\s+(\d+\.?\d*)/g,': <span class="text-accent-green">$1</span>').replace(/:\s+"([^"]*)"/g,': <span class="text-accent-yellow">"$1"</span>'):g;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-medium text-dark-text",children:"Config Files"}),e.jsx("button",{onClick:k,disabled:f,className:"p-1.5 rounded hover:bg-dark-hover transition-colors text-dark-muted",title:"Refresh file list",children:e.jsx(_,{size:14,className:f?"animate-spin":""})})]}),t.length===0&&!f&&e.jsx("p",{className:"text-xs text-dark-muted",children:"No config files found in ~/.agent/"}),t.length>0&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-48 shrink-0 space-y-0.5 max-h-[300px] overflow-y-auto custom-scrollbar",children:t.map(g=>e.jsxs("button",{onClick:()=>v(g.name),className:`w-full text-left px-2.5 py-1.5 rounded text-xs flex items-center gap-2 transition-colors ${l===g.name?"bg-accent-blue/10 text-accent-blue":"text-dark-text hover:bg-dark-hover"}`,children:[e.jsx(je,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:g.name}),!g.editable&&e.jsx("span",{className:"text-badge text-dark-muted shrink-0",title:"Read-only",children:"read"})]},g.name))}),l?e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx("span",{className:"text-dark-text font-medium",children:l}),t.find(g=>g.name===l)&&e.jsxs("span",{children:[bt(t.find(g=>g.name===l).size)," · ",ft(t.find(g=>g.name===l).modified)]}),y&&e.jsxs("span",{className:"text-accent-yellow flex items-center gap-1",children:[e.jsx(F,{size:10}),"unsaved changes"]})]}),e.jsx(G,{variant:"accent",size:"sm",leftIcon:e.jsx(ve,{size:12}),loading:b,disabled:!y,onClick:o,children:"Save"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"w-full h-[260px] p-3 rounded-lg bg-dark-bg border border-dark-border font-mono text-xs leading-relaxed overflow-auto custom-scrollbar pointer-events-none",dangerouslySetInnerHTML:{__html:m.split(`
|
|
2
|
+
`).map($).join(`
|
|
3
|
+
`)||" "}}),e.jsx("textarea",{value:m,onChange:g=>r(g.target.value),className:"absolute inset-0 w-full h-full p-3 rounded-lg bg-transparent border border-dark-border font-mono text-xs leading-relaxed resize-none overflow-auto custom-scrollbar text-transparent caret-dark-text focus:outline-none focus:border-accent-blue/50",style:{color:"transparent"},spellCheck:!1})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-dark-muted",children:"Select a file to edit"})]})]})}const pe=[{key:"pipIndexUrl",labelKey:"stt.sources.pipIndexUrl",placeholderKey:"stt.sources.phPipIndex",preset:"pipIndexUrl"},{key:"pipExtraIndexUrl",labelKey:"stt.sources.pipExtraIndexUrl",placeholderKey:"stt.sources.phPipExtra"},{key:"proxy",labelKey:"stt.sources.proxy",placeholderKey:"stt.sources.phProxy"},{key:"hfEndpoint",labelKey:"stt.sources.hfEndpoint",placeholderKey:"stt.sources.phHub",preset:"hfEndpoint"},{key:"modelscopeEndpoint",labelKey:"stt.sources.modelscopeEndpoint",placeholderKey:"stt.sources.phHub",preset:"modelscopeEndpoint"}],kt="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50";function jt(){const{t}=D(),[s,l]=a.useState(!1),[i,m]=a.useState(!1),[r,x]=a.useState(!1),[d,f]=a.useState(!1),[n,b]=a.useState(null),[p,k]=a.useState({pipIndexUrl:"",pipExtraIndexUrl:"",proxy:"",hfEndpoint:"",modelscopeEndpoint:""}),v=a.useCallback(h=>{b(h),k({pipIndexUrl:h.settings.pipIndexUrl??"",pipExtraIndexUrl:h.settings.pipExtraIndexUrl??"",proxy:h.settings.proxy??"",hfEndpoint:h.settings.hfEndpoint??"",modelscopeEndpoint:h.settings.modelscopeEndpoint??""})},[]),o=a.useCallback(async()=>{x(!0);try{const h=await E.stt.getConfig();h.success&&h.data?v(h.data):h.error&&j.error(h.error)}catch{}x(!1),m(!0)},[v]);a.useEffect(()=>{s&&!i&&o()},[s,i,o]);const y=n==null?void 0:n.envKeys,N=(n==null?void 0:n.resolved.fromEnv)??[],S=h=>N.includes(h),$=Object.keys(p).filter(h=>{const P=p[h].trim();return!P||S(h)?!1:h==="pipExtraIndexUrl"||h==="proxy"?!0:P!==(n==null?void 0:n.official[h])}),g=Object.keys(p).some(h=>S(h)?!1:p[h].trim()!==((n==null?void 0:n.settings[h])??"")),K=a.useCallback(async()=>{f(!0);try{const h={};for(const{key:c}of pe){if(S(c))continue;const u=p[c].trim();h[c]=u||null}const P=await E.stt.setConfig(h);P.success&&P.data?(j.success(t("stt.sources.saved")),await o()):j.error(P.error||t("stt.sources.saveFailed"))}catch(h){j.error(h instanceof Error?h.message:String(h))}f(!1)},[p,S,o,t]),L=a.useCallback(async()=>{f(!0);try{const h=await E.stt.setConfig({pipIndexUrl:null,pipExtraIndexUrl:null,proxy:null,hfEndpoint:null,modelscopeEndpoint:null});h.success&&h.data?(j.success(t("stt.sources.resetDone")),await o()):j.error(h.error||t("stt.sources.saveFailed"))}catch(h){j.error(h instanceof Error?h.message:String(h))}f(!1)},[o,t]);return e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface overflow-hidden",children:[e.jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2.5 text-left hover:bg-dark-hover transition-colors",onClick:()=>l(h=>!h),children:[s?e.jsx(Ae,{size:14,className:"text-dark-muted"}):e.jsx(Be,{size:14,className:"text-dark-muted"}),e.jsx(ye,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium text-dark-text flex-1",children:t("stt.sources.title")}),$.length>0&&!s&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-orange/15 text-accent-orange",children:[e.jsx(F,{size:11}),t("stt.sources.badgeCustom",{count:$.length})]})]}),s&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-meta text-dark-muted",children:t("stt.sources.hint")}),r&&!n?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted py-2",children:[e.jsx(R,{size:13,className:"animate-spin"}),t("stt.sources.loading")]}):e.jsxs(e.Fragment,{children:[pe.map(({key:h,labelKey:P,placeholderKey:c,preset:u})=>{var O;const C=S(h),T=((y==null?void 0:y[h])??[]).join(" / ")||"ENV",I=u?((O=n==null?void 0:n.presets)==null?void 0:O[u])??[]:[];return e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-dark-muted mb-1",children:[t(P),C&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-badge text-accent-yellow",title:t("stt.sources.envTitle",{name:T}),children:[e.jsx(F,{size:11}),"env: ",T]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:C?(n==null?void 0:n.resolved[h])??"":p[h],disabled:C,spellCheck:!1,placeholder:t(c),onChange:w=>k(z=>({...z,[h]:w.target.value})),className:kt}),I.length>0&&e.jsxs("select",{value:"",disabled:C,title:t("stt.sources.preset"),onChange:w=>{const z=I.find(M=>M.id===w.target.value);z&&k(M=>({...M,[h]:z.url}))},className:"shrink-0 bg-dark-bg border border-dark-border rounded-lg px-2 py-1.5 text-xs text-dark-text focus:border-accent-blue/60 outline-none transition-all disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("stt.sources.preset")}),I.map(w=>e.jsx("option",{value:w.id,children:w.label},w.id))]})]})]},h)}),$.length>0&&e.jsxs("div",{className:"rounded-md border border-accent-orange/30 bg-accent-orange/5 px-2.5 py-2 text-meta text-accent-orange flex items-start gap-1.5",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("stt.sources.warning")})]}),n&&!n.allowPrivateHosts&&e.jsx("p",{className:"text-badge text-dark-muted",children:t("stt.sources.privateBlocked")}),e.jsxs("div",{className:"flex items-center gap-2 pt-0.5",children:[e.jsx(G,{variant:"accent",size:"sm",leftIcon:e.jsx(ve,{size:13}),loading:d,disabled:!g,onClick:()=>void K(),children:t("stt.sources.save")}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm border border-dark-border text-dark-muted hover:border-dark-hover hover:text-dark-text transition-colors disabled:opacity-50",disabled:d,onClick:()=>void L(),children:[e.jsx(Oe,{size:13}),t("stt.sources.reset")]}),e.jsx("span",{className:"text-badge text-dark-muted",children:t("stt.sources.httpsOnly")})]})]})]})]})}function vt(){var T,I,O;const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState(null),[r,x]=a.useState({running:!1,logs:[]}),[d,f]=a.useState(!1),n=a.useRef(null),b=a.useRef(r),p=a.useRef(null),[k,v]=a.useState(ct),o=a.useCallback(w=>{v(w),ot(w),window.dispatchEvent(new CustomEvent("stt-lang-changed",{detail:{lang:w}}))},[]);a.useEffect(()=>{b.current=r},[r]);const y=a.useCallback(async()=>{f(!0);const w=await E.stt.status();w.success&&w.data?(l(w.data),w.data.env&&m(w.data.env)):w.error&&j.error(w.error),f(!1)},[]);a.useEffect(()=>{y()},[y]);const N=a.useCallback(async()=>{const w=await E.stt.installStatus();if(w.success&&w.data){const z=b.current.running;x(w.data),w.data.running?n.current=window.setTimeout(()=>void N(),1e3):(y(),z&&w.data.status==="done"&&window.dispatchEvent(new CustomEvent("stt-backends-changed")))}},[y]);a.useEffect(()=>()=>{n.current&&window.clearTimeout(n.current)},[]),a.useEffect(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},[r.logs]);const S=a.useCallback(async w=>{var M,B,U,q;const z=await E.stt.install(w);z.success&&((M=z.data)!=null&&M.started)?(x({running:!0,backend:w,logs:[],status:"running"}),N()):(B=z.data)!=null&&B.alreadyRunning?(j.info(t("stt.setup.jobInProgress")),N()):x({running:!1,backend:w,logs:[],status:"error",error:z.error||((U=z.data)==null?void 0:U.error)||"install failed",manualCommand:(q=z.data)==null?void 0:q.manualCommand})},[N,t]),$=a.useCallback(async()=>{await E.stt.cancelInstall(),N()},[N]),g=a.useCallback(w=>{navigator.clipboard.writeText(w).then(()=>j.success(t("stt.setup.copySuccess")),()=>j.error(t("stt.setup.copyFailed")))},[t]),K=r.running?r.backend:void 0,L=r.running,h=!L&&r.status==="done"&&r.backend?(T=s==null?void 0:s.backends)==null?void 0:T[r.backend]:void 0,P=h?!h.installed:!1,c=w=>w?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-green/15 text-accent-green",children:[e.jsx(W,{size:12}),t("stt.setup.installed")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-dark-hover text-dark-muted",children:[e.jsx(ne,{size:12}),t("stt.setup.notInstalled")]}),u=(w,z,M)=>{var oe;const B=((oe=s==null?void 0:s.backends)==null?void 0:oe[w])??{installed:!1},U=K===w,q=L&&!U,Y=w==="zh"?k==="zh":k!=="zh",ce=w==="en"&&k!=="en"&&k!=="zh"?dt(k):null;return e.jsxs("div",{className:H("rounded-lg border p-3 flex items-start justify-between gap-3 transition-colors cursor-pointer",Y?"border-accent-blue/50 bg-accent-blue/5":"border-dark-border bg-dark-bg hover:border-dark-hover"),onClick:()=>o(w),children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:H("w-9 h-9 shrink-0 rounded-lg flex items-center justify-center text-sm font-semibold",Y?"bg-accent-blue/15 text-accent-blue":"bg-accent-blue/10 text-accent-blue"),children:w==="en"?"W":"F"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text",children:z}),c(B.installed),Y&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-blue/15 text-accent-blue",children:[e.jsx(de,{size:12}),t("stt.setup.inUse")]}),ce&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-dark-hover text-dark-muted",children:ce.label})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-meta text-dark-muted",children:[e.jsx("code",{className:"text-badge bg-dark-hover px-1.5 py-0.5 rounded",children:M}),e.jsx("span",{children:t(w==="en"?"stt.setup.whisperDesc":"stt.setup.funasrDesc")})]}),w==="zh"&&e.jsxs("p",{className:"mt-1 text-meta text-dark-muted flex items-center gap-1",children:[e.jsx(ae,{size:11}),t("stt.setup.torchHint")]}),Y&&!B.installed&&e.jsxs("p",{className:"mt-1 text-meta text-accent-orange flex items-center gap-1",children:[e.jsx(F,{size:11}),t("stt.setup.engineNotInstalledHint")]}),!B.installed&&B.error&&e.jsxs("p",{className:"mt-1 text-meta text-accent-orange break-all",title:B.error,children:[e.jsx(F,{size:11}),t("stt.setup.probeError"),B.error]})]})]}),e.jsx("div",{className:"shrink-0",onClick:De=>De.stopPropagation(),children:U?e.jsxs("button",{className:"btn btn-secondary cursor-not-allowed opacity-70",disabled:!0,children:[e.jsx(R,{size:14,className:"animate-spin"}),t("stt.setup.installing")]}):q?e.jsx("button",{className:"btn btn-secondary cursor-not-allowed opacity-50",disabled:!0,children:t("stt.setup.installing")}):B.installed?e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void y(),title:t("stt.setup.recheck"),children:[e.jsx(_,{size:14}),t("stt.setup.recheck")]}):e.jsxs("button",{className:"btn btn-accent",onClick:()=>void S(w),children:[e.jsx(we,{size:14}),t("stt.setup.install")]})})]})},C=(i==null?void 0:i.pythonAvailable)&&(i==null?void 0:i.pipAvailable);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(Ne,{size:14,className:"text-accent-blue"}),t("stt.setup.envCard")]}),e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void y(),disabled:d,children:[e.jsx(_,{size:13,className:d?"animate-spin":""}),t("stt.setup.recheck")]})]}),e.jsxs("div",{className:"mt-2.5 space-y-2",children:[i?i.pythonAvailable?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-text",children:[e.jsx(W,{size:13,className:"text-accent-green"}),t("stt.setup.pythonOk",{version:(i.pythonVersion||"").replace(/^Python\s*/i,"")||i.pythonPath||"Python"}),i.pythonPath?e.jsx("code",{className:"text-badge text-dark-muted",children:i.pythonPath}):null]}):e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:13}),t("stt.setup.pythonMissing")]}),e.jsx("a",{className:"btn btn-secondary !py-1 !px-2 text-xs",href:"https://www.python.org/downloads/",target:"_blank",rel:"noreferrer",children:t("stt.setup.pythonGuide")})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(R,{size:13,className:"animate-spin"}),t("stt.setup.envChecking")]}),i&&!i.pipAvailable&&e.jsxs("div",{className:"rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:13}),t("stt.setup.pipMissing")]}),e.jsxs("div",{className:"mt-1.5",children:[e.jsx("div",{className:"text-badge text-dark-muted mb-1",children:t("stt.setup.pipGuide")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1 font-mono text-badge text-dark-text break-all select-all",children:[i.pythonPath||"python"," -m ensurepip --upgrade"]}),e.jsx("button",{className:"btn btn-ghost !py-1 !px-2 text-xs",onClick:()=>g(`${i.pythonPath||"python"} -m ensurepip --upgrade`),children:e.jsx(V,{size:12})})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(de,{size:14,className:"text-accent-blue"}),t("stt.setup.defaultEngine")]}),e.jsx("p",{className:"mt-1 text-meta text-dark-muted",children:t("stt.setup.defaultEngineHint")})]}),u("en",t("stt.setup.whisperTitle"),"base.en"),u("zh",t("stt.setup.funasrTitle"),"paraformer-zh"),e.jsx(jt,{}),L&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-blue font-medium",children:[e.jsx(R,{size:13,className:"animate-spin"}),t("stt.setup.installing"),e.jsxs("span",{className:"text-dark-muted font-normal",children:["(",K==="en"?"whisper":"funasr",")"]})]}),e.jsx("button",{className:"btn btn-danger !py-1 !px-2 text-xs",onClick:()=>void $(),children:t("stt.setup.cancel")})]}),e.jsx("div",{ref:p,className:"rounded-md border border-dark-border bg-dark-bg p-2.5 font-mono text-meta text-dark-muted overflow-auto max-h-48 whitespace-pre-wrap custom-scrollbar",children:r.logs.length===0?e.jsx("span",{className:"text-dark-muted/70",children:t("stt.setup.logWaiting")}):r.logs.join(`
|
|
4
|
+
`)})]}),!L&&r.status&&r.status!=="done"&&e.jsxs("div",{className:"rounded-lg border border-accent-red/30 bg-accent-red/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red font-medium",children:[e.jsx(F,{size:13}),r.status==="timeout"?t("stt.setup.installTimeout"):r.status==="cancelled"?t("stt.setup.installCancelled"):t("stt.setup.installFailed")]}),r.error?e.jsx("p",{className:"mt-1 text-xs text-accent-red/90 break-all",children:r.error}):null,r.manualCommand&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-badge text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(Me,{size:11}),t("stt.setup.manualCommand")]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1.5 font-mono text-badge text-dark-text break-all whitespace-pre-wrap select-all",children:r.manualCommand}),e.jsxs("button",{className:"btn btn-ghost !py-1 !px-2 text-xs shrink-0",onClick:()=>g(r.manualCommand),children:[e.jsx(V,{size:12}),t("stt.setup.copyCommand")]})]})]})]}),!L&&r.status==="done"&&!P&&e.jsxs("div",{className:"rounded-lg border border-accent-green/30 bg-accent-green/5 px-3 py-2.5 flex items-center gap-2 text-xs text-accent-green",children:[e.jsx(W,{size:14}),t("stt.setup.installDone")]}),!L&&r.status==="done"&&P&&e.jsxs("div",{className:"rounded-lg border border-accent-orange/30 bg-accent-orange/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-orange font-medium",children:[e.jsx(F,{size:13}),t("stt.setup.installDoneButMissing")]}),(h==null?void 0:h.error)&&e.jsx("p",{className:"mt-1 text-xs text-accent-orange/90 break-all",children:h.error}),e.jsx("p",{className:"mt-1 text-meta text-dark-muted",children:t("stt.setup.installDoneButMissingHint")})]}),!L&&C&&s&&!((I=s.backends.en)!=null&&I.installed)&&!((O=s.backends.zh)!=null&&O.installed)&&e.jsx("p",{className:"text-meta text-dark-muted px-1",children:t("stt.setup.chooseHint")})]})}function yt(){const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState({running:!1,logs:[]}),[r,x]=a.useState(!1),[d,f]=a.useState(xt),n=a.useRef(null),b=a.useRef(i),p=a.useRef(null);a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{f(ut())},[]),a.useEffect(()=>()=>{n.current&&window.clearTimeout(n.current)},[]),a.useEffect(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},[i.logs]);const k=a.useCallback(async()=>{x(!0);const u=await E.tts.status();u.success&&u.data?l(u.data):u.error&&j.error(u.error),x(!1)},[]);a.useEffect(()=>{k()},[k]);const v=a.useCallback(async()=>{const u=await E.tts.installStatus();if(!u.success||!u.data)return;const C=b.current.running;m(u.data),u.data.running?n.current=window.setTimeout(()=>void v(),1e3):C&&k()},[k]),o=a.useCallback(async()=>{var C,T,I,O;const u=await E.tts.install();u.success&&((C=u.data)!=null&&C.started)?(m({running:!0,logs:[],status:"running"}),v()):(T=u.data)!=null&&T.alreadyRunning?(j.info(t("tts.setup.jobInProgress")),v()):m({running:!1,logs:[],status:"error",error:u.error||((I=u.data)==null?void 0:I.error)||"install failed",manualCommand:(O=u.data)==null?void 0:O.manualCommand})},[v,t]),y=a.useCallback(async()=>{await E.tts.cancelInstall(),v()},[v]),N=a.useCallback(u=>{navigator.clipboard.writeText(u).then(()=>j.success(t("tts.setup.copySuccess")),()=>j.error(t("tts.setup.copyFailed")))},[t]),S=a.useCallback(u=>{f(mt(u))},[]),$=s==null?void 0:s.engine,g=(s==null?void 0:s.service)==="ok",K=($==null?void 0:$.voiceNames)??[],L=s==null?void 0:s.env,h=L?!L.pythonAvailable:!1,P=(s==null?void 0:s.missingWeights)??($==null?void 0:$.missingWeights)??[],c=(u,C)=>e.jsxs("span",{className:H("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium",u?"bg-accent-green/15 text-accent-green":"bg-dark-hover text-dark-muted"),children:[u?e.jsx(W,{size:12}):e.jsx(ne,{size:12}),C]});return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",children:t("tts.setup.engine")}),c(g,t(g?"tts.setup.ready":"tts.setup.notReady"))]}),e.jsx("button",{type:"button",className:"p-1.5 rounded-md hover:bg-dark-hover text-dark-muted",onClick:()=>void k(),disabled:r,title:t("tts.setup.refresh"),children:e.jsx(_,{size:14,className:H(r&&"animate-spin")})})]}),(s==null?void 0:s.error)&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-all",children:s.error})]}),P.length>0&&e.jsx("div",{className:"text-xs text-dark-muted",children:t("tts.setup.missingWeights",{files:P.join("、")})}),h&&e.jsx("div",{className:"text-xs text-accent-yellow",children:t("tts.setup.envMissing")}),($==null?void 0:$.model)&&e.jsx("div",{className:"text-xs text-dark-muted",children:t("tts.setup.model",{model:$.model})}),i.running?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{size:14,className:"animate-spin text-accent-blue"}),e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("tts.setup.installing"),i.phase?` · ${i.phase}`:""]}),e.jsx("button",{type:"button",className:"ml-auto text-xs text-accent-red hover:underline",onClick:()=>void y(),children:t("tts.setup.cancel")})]}):e.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-md text-xs bg-accent-blue/15 text-accent-blue hover:bg-accent-blue/25 disabled:opacity-50",onClick:()=>void o(),disabled:g,children:[e.jsx(we,{size:14}),t(g?"tts.setup.installed":"tts.setup.install")]}),i.status==="error"&&i.error&&!i.running&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-all",children:i.error})]}),i.manualCommand&&!i.running&&e.jsxs("div",{className:"rounded-md bg-dark-bg border border-dark-border p-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-dark-muted",children:[e.jsx(Ne,{size:12}),t("tts.setup.manualCommand")]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 text-xs text-accent-blue hover:underline",onClick:()=>N(i.manualCommand),children:[e.jsx(V,{size:12}),t("tts.setup.copy")]})]}),e.jsx("code",{className:"block text-xs break-all text-dark-text",children:i.manualCommand})]}),i.logs.length>0&&e.jsx("div",{ref:p,className:"max-h-40 overflow-auto rounded-md bg-dark-bg border border-dark-border p-2",children:i.logs.map((u,C)=>e.jsx("div",{className:"text-xs font-mono text-dark-muted whitespace-pre-wrap break-all",children:u},C))})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border p-3 space-y-3",children:[e.jsxs("label",{className:"flex items-center justify-between gap-3 cursor-pointer",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Re,{size:14,className:"text-accent-blue"}),t("tts.setup.enabled")]}),e.jsx("input",{type:"checkbox",className:"accent-accent-blue",checked:d.enabled,onChange:u=>S({enabled:u.target.checked})})]}),e.jsxs("label",{className:H("flex items-center justify-between gap-3 cursor-pointer",!d.enabled&&"opacity-50"),children:[e.jsxs("span",{className:"text-sm",children:[t("tts.setup.autoPlay"),e.jsx("span",{className:"block text-xs text-dark-muted",children:t("tts.setup.autoPlayHint")})]}),e.jsx("input",{type:"checkbox",className:"accent-accent-blue",checked:d.autoPlay,disabled:!d.enabled,onChange:u=>S({autoPlay:u.target.checked})})]}),e.jsxs("div",{className:H("flex items-center justify-between gap-3",!d.enabled&&"opacity-50"),children:[e.jsx("span",{className:"text-sm",children:t("tts.setup.voice")}),e.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-md px-2 py-1 text-xs max-w-[60%]",value:d.voice??"",disabled:!d.enabled||K.length===0,onChange:u=>S({voice:u.target.value||null}),children:[e.jsx("option",{value:"",children:t("tts.setup.voiceAuto")}),K.map(u=>e.jsx("option",{value:u,children:u},u))]})]}),e.jsxs("label",{className:H("flex items-center justify-between gap-3",!d.enabled&&"opacity-50"),children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Ge,{size:14,className:"text-accent-blue"}),t("tts.setup.speed")]}),e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"range",min:gt,max:pt,step:.1,value:d.speed,disabled:!d.enabled,onChange:u=>S({speed:Number(u.target.value)})}),e.jsx("span",{className:"text-xs text-dark-muted w-8 text-right",children:d.speed.toFixed(1)})]})]})]})]})}function X({label:t,value:s,onChange:l,min:i,max:m,disabled:r,envOverridden:x,hint:d}){return e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t,x&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",title:d,children:[e.jsx(F,{size:12})," env"]})]}),e.jsx("input",{type:"number",value:s,onChange:f=>l(f.target.value),min:i,max:m,disabled:r||x,className:"w-40 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]})}function Nt(){const{t}=D(),[s,l]=a.useState(!0),[i,m]=a.useState(!1),[r,x]=a.useState({}),[d,f]=a.useState(!1),[n,b]=a.useState(""),[p,k]=a.useState(null),[v,o]=a.useState(!1),[y,N]=a.useState(""),[S,$]=a.useState(""),[g,K]=a.useState(""),[L,h]=a.useState(""),[P,c]=a.useState(""),u=a.useCallback(async()=>{l(!0);try{const T=await E.config.context.get();if(T.success&&T.data){const I=T.data.values??{};x(T.data.envOverridden??{}),f(T.data.effective.offload),b(T.data.defaultArtifactRoot??""),k(T.data.stats??null),o(typeof I.artifactOffload=="boolean"?I.artifactOffload:T.data.effective.offload),N(typeof I.artifactDir=="string"?I.artifactDir:""),$(I.artifactMaxTotalMb!=null?String(I.artifactMaxTotalMb):""),K(I.artifactTtlDays!=null?String(I.artifactTtlDays):""),h(I.outboundToolBytes!=null?String(I.outboundToolBytes):""),c(I.turnBudgetTokens!=null?String(I.turnBudgetTokens):"")}}catch{}l(!1)},[]);a.useEffect(()=>{u()},[u]);const C=async()=>{m(!0);try{const T={artifactOffload:v};r.artifactDir||(T.artifactDir=y.trim()||null),!r.artifactMaxTotalMb&&S.trim()&&(T.artifactMaxTotalMb=parseInt(S,10)),!r.artifactTtlDays&&g.trim()&&(T.artifactTtlDays=parseInt(g,10)),!r.outboundToolBytes&&L.trim()&&(T.outboundToolBytes=parseInt(L,10)),!r.turnBudgetTokens&&P.trim()&&(T.turnBudgetTokens=parseInt(P,10));for(const O of["artifactMaxTotalMb","artifactTtlDays","outboundToolBytes","turnBudgetTokens"])if(O in T&&(isNaN(T[O])||T[O]<=0)){j.error(t("settings.contextOffload.invalidNumber")),m(!1);return}const I=await E.config.context.save(T);I.success?(j.success(t("settings.contextOffload.saved")),await u()):j.error(I.error||t("settings.contextOffload.saveFailed"))}catch(T){j.error(T instanceof Error?T.message:String(T))}m(!1)};return s?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-dark-muted py-2",children:[e.jsx(R,{size:14,className:"animate-spin"}),t("common.loading")]}):e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.contextOffload.desc")}),e.jsxs("label",{className:"flex items-center justify-between mb-4 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.contextOffload.enableLabel"),e.jsxs("span",{className:`ml-2 text-xs ${d?"text-accent-green":"text-dark-muted"}`,children:["(",t("settings.contextOffload.currently"),": ",d?"ON":"OFF",")"]})]}),e.jsx("button",{role:"switch","aria-checked":v,onClick:()=>o(!v),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${v?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${v?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6",children:[e.jsx(X,{label:t("settings.contextOffload.maxTotalMb"),value:S,onChange:$,min:1,envOverridden:r.artifactMaxTotalMb}),e.jsx(X,{label:t("settings.contextOffload.ttlDays"),value:g,onChange:K,min:1,max:365,envOverridden:r.artifactTtlDays}),e.jsx(X,{label:`${t("settings.contextOffload.outboundBytes")} (${t("settings.contextOffload.optional")})`,value:L,onChange:h,min:1024,envOverridden:r.outboundToolBytes}),e.jsx(X,{label:t("settings.contextOffload.turnBudget"),value:P,onChange:c,min:1e3,envOverridden:r.turnBudgetTokens})]}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t("settings.contextOffload.dir")," (",t("settings.contextOffload.optional"),")",r.artifactDir&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",children:[e.jsx(F,{size:12})," env"]})]}),e.jsx("input",{type:"text",value:y,onChange:T=>N(T.target.value),disabled:r.artifactDir,placeholder:n,className:"w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{variant:"accent",size:"sm",onClick:C,loading:i,disabled:s,children:t("common.save")}),e.jsx("span",{className:"text-xs text-dark-muted",children:t("settings.contextOffload.envHint")})]}),p&&p.count>0&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:t("settings.contextOffload.stats",{count:p.count,size:(p.totalBytes/1024/1024).toFixed(1)})})]})}const ge="bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50";function J({checked:t,onChange:s,disabled:l}){return e.jsx("button",{role:"switch","aria-checked":t,disabled:l,onClick:()=>s(!t),className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors disabled:opacity-40 ${t?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${t?"translate-x-6":"translate-x-1"}`})})}function wt(){const{t}=D(),[s,l]=a.useState(!0),[i,m]=a.useState(!1),[r,x]=a.useState(null),[d,f]=a.useState("none"),[n,b]=a.useState(""),[p,k]=a.useState(!0),[v,o]=a.useState(!1),[y,N]=a.useState(!1),S=a.useCallback(async()=>{l(!0);try{const z=await E.config.sandbox.get();if(z.success&&z.data){const M=z.data;x(M);const B=M.values??{};f(B.backend??"none"),b(B.policy??""),k(B.networkAccess!==!1),o(B.excludeTmpdirEnvVar===!0),N(B.excludeSlashTmp===!0)}}catch{}l(!1)},[]);a.useEffect(()=>{S()},[S]);const $=n==="danger-full-access",g=d!=="none"&&n!==""&&!$,K=g&&n==="workspace-write",L=z=>{z?(f("auto"),b(n==="read-only"||n==="workspace-write"?n:"workspace-write")):(f("none"),b(""))},h=z=>{b(z),z==="danger-full-access"&&f("none")},P=async()=>{if(d!=="none"&&n===""){j.error(t("settings.sandbox.needPolicy"));return}m(!0);try{const z=await E.config.sandbox.save({backend:d,policy:d==="none"?null:n,networkAccess:p,excludeTmpdirEnvVar:v,excludeSlashTmp:y});z.success?(j.success(t("settings.sandbox.saved")),await S()):j.error(z.error||t("settings.sandbox.saveFailed"))}catch(z){j.error(z instanceof Error?z.message:String(z))}m(!1)};if(s)return e.jsxs("div",{className:"flex items-center gap-2 text-sm text-dark-muted py-2",children:[e.jsx(R,{size:14,className:"animate-spin"}),t("common.loading")]});const c=r==null?void 0:r.status,u=(c==null?void 0:c.backendId)==="docker",C=c!==void 0&&c.status==="enabled"&&c.backendId===null,T=c!==void 0&&c.status==="enabled"&&c.backendId!==null||u,I=T?W:(c==null?void 0:c.status)==="invalid"?ne:F,O=T?"text-accent-green":(c==null?void 0:c.status)==="invalid"?"text-accent-red":C?"text-accent-yellow":"text-dark-muted",w=u?t("settings.sandbox.statusDocker"):C?t("settings.sandbox.statusNoBackend"):(c==null?void 0:c.status)==="enabled"?t("settings.sandbox.statusOn",{backend:c.backendId??"—"}):(c==null?void 0:c.status)==="invalid"?t("settings.sandbox.statusInvalid"):t("settings.sandbox.statusOff");return e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.sandbox.desc")}),e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-bg/40 px-3 py-2.5",children:[e.jsxs("div",{className:`flex items-center gap-2 text-sm ${O}`,children:[e.jsx(I,{size:14}),e.jsx("span",{children:w}),e.jsxs("span",{className:"text-xs text-dark-muted",children:["(",t("settings.sandbox.restartNotice"),")"]})]}),(c==null?void 0:c.policyDescription)&&e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:c.policyDescription}),(c==null?void 0:c.reason)&&e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:c.reason}),(c==null?void 0:c.error)&&e.jsx("p",{className:"mt-1 text-xs text-accent-red whitespace-pre-wrap",children:c.error}),c&&c.capabilityGaps.length>0&&e.jsx("p",{className:"mt-1 text-xs text-accent-yellow",children:t("settings.sandbox.gaps",{fields:c.capabilityGaps.join(", ")})})]}),(r==null?void 0:r.envOverride.active)&&e.jsxs("p",{className:"mb-3 flex items-start gap-1.5 text-xs text-accent-yellow",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),r.envOverride.note||t("settings.sandbox.envOverride",{value:r.envOverride.value})]}),(r==null?void 0:r.status.platform)==="win32"&&e.jsxs("p",{className:"mb-3 flex items-start gap-1.5 text-xs text-accent-yellow",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),t("settings.sandbox.win32Warn")]}),(r==null?void 0:r.status.legacySource)&&e.jsx("p",{className:"mb-3 text-xs text-accent-blue",children:t("settings.sandbox.legacySource")}),(r==null?void 0:r.status.bothPresent)&&e.jsxs("p",{className:"mb-3 flex items-start gap-1.5 text-xs text-accent-yellow",children:[e.jsx(F,{size:12,className:"mt-0.5 shrink-0"}),t("settings.sandbox.bothPresent")]}),e.jsxs("label",{className:"flex items-center justify-between mb-4 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.sandbox.enableLabel"),e.jsxs("span",{className:`ml-2 text-xs ${g?"text-accent-green":"text-dark-muted"}`,children:["(",t("settings.sandbox.currently"),": ",g?"ON":"OFF",")"]})]}),e.jsx(J,{checked:g,onChange:L})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("settings.sandbox.backend")}),e.jsxs("select",{value:d,onChange:z=>f(z.target.value),className:`w-full ${ge}`,children:[e.jsx("option",{value:"auto",children:t("settings.sandbox.backendAuto")}),e.jsx("option",{value:"bubblewrap",children:t("settings.sandbox.backendBubblewrap")}),e.jsx("option",{value:"macos-sandbox",children:t("settings.sandbox.backendMacos")}),e.jsx("option",{value:"windows-mxc",children:t("settings.sandbox.backendWindows")}),e.jsx("option",{value:"none",children:t("settings.sandbox.backendNone")})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("settings.sandbox.policy")}),e.jsxs("select",{value:n,onChange:z=>h(z.target.value),disabled:d==="none",className:`w-full ${ge}`,children:[e.jsx("option",{value:"",children:t("settings.sandbox.policyEmpty")}),e.jsx("option",{value:"read-only",children:t("settings.sandbox.policyReadOnly")}),e.jsx("option",{value:"workspace-write",children:t("settings.sandbox.policyWorkspaceWrite")}),e.jsx("option",{value:"danger-full-access",children:t("settings.sandbox.policyDanger")})]}),$&&e.jsx("p",{className:"mt-1 text-xs text-accent-yellow",children:t("settings.sandbox.policyDangerHint")})]})]}),e.jsxs("label",{className:"flex items-center justify-between mb-4 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.sandbox.networkAccess"),e.jsx("span",{className:"block text-xs text-dark-muted mt-0.5",children:t("settings.sandbox.networkAccessHint")})]}),e.jsx(J,{checked:p,onChange:k,disabled:!g})]}),K&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border px-3 py-2.5",children:[e.jsx("p",{className:"text-xs text-dark-muted mb-2",children:t("settings.sandbox.advancedHint")}),e.jsxs("label",{className:"flex items-center justify-between mb-2 cursor-pointer",children:[e.jsx("span",{className:"text-sm",children:t("settings.sandbox.excludeTmpdir")}),e.jsx(J,{checked:v,onChange:o})]}),e.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[e.jsx("span",{className:"text-sm",children:t("settings.sandbox.excludeSlashTmp")}),e.jsx(J,{checked:y,onChange:N})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{variant:"accent",size:"sm",onClick:P,loading:i,children:t("common.save")}),e.jsx("span",{className:"text-xs text-dark-muted",children:t("settings.sandbox.restartHint")})]})]})}function A({icon:t,iconColor:s,title:l,children:i}){return e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-bg/40 p-4 mb-4",children:[e.jsxs("h3",{className:"font-medium mb-3 flex items-center gap-2",children:[e.jsx(t,{size:16,className:s}),l]}),i]})}const Ct=8e3,St=["assistant","pet","lover"];function Et(){const{t}=D(),[s,l]=a.useState(void 0),[i,m]=a.useState(!0),[r,x]=a.useState(!1),[d,f]=a.useState(!1),[n,b]=a.useState(""),[p,k]=a.useState(""),[v,o]=a.useState(!1),y=a.useCallback(async()=>{m(!0);try{const c=await E.profile.get();c.success&&c.data?l(c.data):j.error(c.error||t("settings.profile.loadFailed"))}catch(c){j.error(`${t("settings.profile.loadFailed")}: ${c instanceof Error?c.message:String(c)}`)}m(!1)},[t]);a.useEffect(()=>{y()},[y]);const N=(s==null?void 0:s.maxBytes)??Ct,S=a.useMemo(()=>{const c=n.trim(),u=p.trim(),C=c?`---
|
|
5
|
+
name: ${c}
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
${u}
|
|
9
|
+
`:u?`${u}
|
|
10
|
+
`:"";return new TextEncoder().encode(C).length},[n,p]),$=async()=>{if(!s||r)return;const c=!s.enabled;x(!0),l({...s,enabled:c});try{const u=await E.config.profile.set({enabled:c});u.success?ee():(l(C=>C&&{...C,enabled:!c}),j.error(u.error||t("settings.profile.saveFailed")))}catch(u){l(C=>C&&{...C,enabled:!c}),j.error(`${t("settings.profile.saveFailed")}: ${u instanceof Error?u.message:String(u)}`)}x(!1)},g=async()=>{if(!v){o(!0);try{const c=await E.profile.raw();c.success&&c.data?(b(c.data.name??""),k(c.data.content),f(!0)):j.error(c.error||t("settings.profile.loadFailed"))}catch(c){j.error(`${t("settings.profile.loadFailed")}: ${c instanceof Error?c.message:String(c)}`)}o(!1)}},K=()=>{f(!1),b(""),k("")},L=c=>{const u=t(`settings.profile.templates.${c}Body`),C=p.trim();C&&C!==u.trim()&&!window.confirm(t("settings.profile.templates.overwriteConfirm"))||k(u)},h=async()=>{if(!r){if(!n.trim()&&!p.trim()){j.error(t("settings.profile.empty"));return}x(!0);try{const c=await E.profile.set({name:n.trim()?n.trim():null,body:p});c.success?(j.success(t("settings.profile.saveOk")),f(!1),b(""),k(""),ee(),await y()):j.error(c.error||t("settings.profile.saveFailed"))}catch(c){j.error(`${t("settings.profile.saveFailed")}: ${c instanceof Error?c.message:String(c)}`)}x(!1)}},P=async()=>{if(!r&&window.confirm(t("settings.profile.clearConfirm"))){x(!0);try{const c=await E.profile.clear();c.success?(j.success(t("settings.profile.clearOk")),K(),ee(),await y()):j.error(c.error||t("settings.profile.clearFailed"))}catch(c){j.error(`${t("settings.profile.clearFailed")}: ${c instanceof Error?c.message:String(c)}`)}x(!1)}};return i?e.jsx("div",{className:"text-sm text-dark-muted",children:t("settings.profile.loading")}):s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 py-1 mb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm text-dark-text font-medium flex items-center gap-2",children:[e.jsx(re,{size:15,className:"text-accent-purple shrink-0"}),t("settings.profile.enabled")]}),e.jsx("div",{className:"text-xs text-dark-muted mt-1",children:t("settings.profile.enabledHint")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s.enabled,"aria-label":t("settings.profile.enabled"),disabled:r,onClick:()=>void $(),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 mt-0.5 ${s.enabled?"bg-accent-blue":"bg-dark-border"} ${r?"opacity-60":""}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${s.enabled?"translate-x-[18px]":"translate-x-0.5"}`})})]}),e.jsx("p",{className:"text-xs text-dark-muted mb-4 leading-relaxed",children:t("settings.profile.hint")}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"text-xs font-medium text-dark-text mb-1.5 flex items-center gap-1.5",children:[e.jsx(je,{size:13,className:"text-dark-muted"}),t("settings.profile.path")]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("code",{className:"flex-1 min-w-0 truncate bg-dark-bg border border-dark-border rounded px-2 py-1 text-meta font-mono text-dark-text",title:s.path,children:s.path}),e.jsx("span",{className:`shrink-0 px-1.5 py-0.5 rounded text-badge border ${s.exists?"bg-accent-green/10 text-accent-green border-accent-green/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:s.exists?t("settings.profile.exists"):t("settings.profile.missing")})]}),e.jsx("div",{className:"mt-1.5 text-meta text-dark-muted font-mono",children:t("settings.profile.size",{used:s.bytes,max:s.maxBytes})}),s.truncated&&e.jsxs("div",{className:"mt-1.5 flex items-start gap-1.5 text-meta text-accent-yellow",children:[e.jsx(F,{size:12,className:"mt-[1px] shrink-0"}),e.jsx("span",{children:t("settings.profile.truncated")})]})]}),d?e.jsxs("div",{className:"border-t border-dark-border pt-3",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"text-xs font-medium text-dark-text mb-1.5",children:t("settings.profile.templates.title")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:St.map(c=>e.jsx("button",{type:"button",onClick:()=>L(c),className:"px-2.5 py-1 rounded-lg text-xs text-dark-muted bg-dark-hover border border-dark-border hover:text-dark-text hover:bg-accent-blue/10 hover:border-accent-blue/40 transition-colors",children:t(`settings.profile.templates.${c}`)},c))}),e.jsx("div",{className:"text-meta text-dark-muted mt-1.5 leading-relaxed",children:t("settings.profile.templates.hint")})]}),e.jsxs("label",{className:"block mb-3",children:[e.jsx("div",{className:"text-xs font-medium text-dark-text mb-1",children:t("settings.profile.name")}),e.jsx("input",{type:"text",value:n,onChange:c=>b(c.target.value),placeholder:t("settings.profile.namePlaceholder"),maxLength:200,className:"w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"})]}),e.jsx("div",{className:"text-xs font-medium text-dark-text mb-1",children:t("settings.profile.body")}),e.jsx("textarea",{value:p,onChange:c=>k(c.target.value),placeholder:t("settings.profile.bodyPlaceholder"),rows:10,className:"w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all resize-y font-mono leading-relaxed"}),e.jsx("div",{className:`mt-1 text-meta font-mono ${S>N?"text-accent-yellow":"text-dark-muted"}`,children:t("settings.profile.size",{used:S,max:N})}),e.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[e.jsx(G,{variant:"accent",size:"sm",onClick:()=>void h(),loading:r,children:t("settings.profile.save")}),e.jsx("button",{onClick:K,disabled:r,className:"px-3 py-1.5 rounded-lg text-sm text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors disabled:opacity-50",children:t("settings.profile.cancel")})]})]}):e.jsxs("div",{className:"border-t border-dark-border pt-3",children:[s.preview?e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap break-words mb-3 leading-relaxed max-h-40 overflow-y-auto custom-scrollbar",children:s.preview}):e.jsx("p",{className:"text-xs text-dark-muted mb-3",children:t("settings.profile.empty")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>void g(),disabled:v||r,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm bg-accent-blue/10 text-accent-blue hover:bg-accent-blue/20 border border-accent-blue/30 transition-colors disabled:opacity-50",children:[e.jsx(He,{size:13}),t("settings.profile.edit")]}),s.exists&&e.jsxs("button",{onClick:()=>void P(),disabled:r,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30 transition-colors disabled:opacity-50",children:[e.jsx(Ue,{size:13}),t("settings.profile.clear")]})]})]})]}):e.jsxs("button",{onClick:()=>void y(),className:"text-sm text-accent-blue hover:underline",children:[t("settings.profile.loadFailed")," — ",t("common.retry")]})}async function Ie(t){var s;try{if((s=navigator.clipboard)!=null&&s.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{const l=document.createElement("textarea");l.value=t,l.setAttribute("readonly",""),l.style.position="fixed",l.style.top="-1000px",l.style.opacity="0",document.body.appendChild(l),l.select();const i=document.execCommand("copy");return document.body.removeChild(l),i}catch{return!1}}const be=t=>new Promise(s=>setTimeout(s,t));function Tt(){const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState(!1),[r,x]=a.useState(null),[d,f]=a.useState(null),n=a.useCallback(async()=>{const o=await E.system.network();return o.success&&o.data?(l(o.data),x(o.data.lastError)):x(o.error||t("settings.network.loadFailed")),o},[t]);a.useEffect(()=>{n()},[n]);const b=s?!s.loopbackOnly:!1,p=a.useCallback(async()=>{if(!s||i)return;const o=!b;if(!window.confirm(t(o?"settings.network.confirmEnable":"settings.network.confirmDisable")))return;m(!0),x(null);const y=await E.system.setNetwork(o);if(!y.success){x(y.error||t("settings.network.applyFailed")),m(!1);return}j.info(t(o?"settings.network.enabledToast":"settings.network.disabledToast")),await be(900);for(let N=0;N<8;N++){const S=await E.system.network();if(S.success&&S.data&&(l(S.data),x(S.data.lastError),S.data.loopbackOnly===!o&&!S.data.lastError)){m(!1);return}await be(600)}x(t("settings.network.applyFailed")),m(!1)},[i,b,s,t]),k=a.useCallback(async o=>{await Ie(o)&&(f(o),setTimeout(()=>f(y=>y===o?null:y),1800))},[]),v=s!=null&&s.lockedByHostOverride?t("settings.network.lockedByHost",{host:s.hostOverride||""}):s!=null&&s.fromEnv?t("settings.network.lockedByEnv",{env:s.envKey}):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.network.description")}),r&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/40 bg-accent-red/10 px-3 py-2 mb-3",children:[e.jsx(F,{size:14,className:"text-accent-red mt-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-accent-red break-all",children:r})]}),e.jsxs("label",{className:`flex items-center justify-between gap-3 py-1 ${v?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.network.toggleLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.network.toggleHint")})]}),e.jsx(Pe,{checked:b,disabled:i||!s||!!v,onToggle:()=>void p(),label:t("settings.network.toggleLabel")})]}),i&&e.jsx("p",{className:"text-xs text-accent-blue mt-2",children:t("settings.network.pendingHint")}),v&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:v}),s&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-dark-muted",children:t(b?"settings.network.stateLan":"settings.network.stateLocal")}),e.jsxs("span",{className:"text-dark-text font-mono",children:[s.bindHost,":",s.httpPort]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-dark-muted mb-1",children:t("settings.network.addresses")}),e.jsx("div",{className:"space-y-1",children:(b?s.lanUrls.length?s.lanUrls:[s.loopbackUrl]:[s.loopbackUrl]).map(o=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 min-w-0 break-all text-xs text-dark-text bg-dark-surface border border-dark-border rounded px-2 py-1 font-mono",children:o}),e.jsxs("button",{type:"button",onClick:()=>void k(o),title:t("settings.network.copy"),className:"shrink-0 flex items-center gap-1 px-2 py-1 rounded text-xs text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[d===o?e.jsx(Ce,{size:13,className:"text-accent-green"}):e.jsx(V,{size:13}),t(d===o?"settings.network.copied":"settings.network.copy")]})]},o))}),b&&s.lanUrls.length===0&&e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:t("settings.network.noLanAddress")})]})]}),b&&e.jsxs("div",{className:"mt-3 rounded-lg border border-accent-yellow/40 bg-accent-yellow/10 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-accent-yellow",children:[e.jsx(F,{size:13}),t("settings.network.warningTitle")]}),e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:t("settings.network.warning")}),e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:s!=null&&s.authTokenRequired?t("settings.network.tokenHint"):t("settings.network.noTokenHint")})]}),e.jsx(zt,{state:s,onState:l})]})}function Pe({checked:t,disabled:s,onToggle:l,label:i}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":i,disabled:s,onClick:l,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:cursor-not-allowed ${t?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-[18px]":"translate-x-0.5"}`})})}function zt({state:t,onState:s}){const{t:l}=D(),[i,m]=a.useState(!1),[r,x]=a.useState(null),[d,f]=a.useState(null),n=t==null?void 0:t.tailscale,b=a.useCallback(async()=>{if(!n||i)return;const y=!n.serving;if(!window.confirm(l(y?"settings.network.tailscale.confirmEnable":"settings.network.tailscale.confirmDisable")))return;m(!0),x(null);const N=await E.system.setTailscale(y);if(m(!1),!N.success||!N.data){x(N.error||l("settings.network.tailscale.applyFailed"));return}s(N.data),j.info(N.data.message)},[i,s,l,n]),p=a.useCallback(async y=>{await Ie(y)&&(f(y),setTimeout(()=>f(N=>N===y?null:N),1800))},[]);if(!n)return null;const k=n.installed&&n.running,v=n.fromEnv?l("settings.network.tailscale.lockedByEnv",{env:n.envKey}):null,o=r||n.lastError||n.probeError;return e.jsxs("div",{className:"mt-4 pt-4 border-t border-dark-border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:l("settings.network.tailscale.title")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:l("settings.network.tailscale.hint")})]}),e.jsx(Pe,{checked:n.serving,disabled:i||!k||!!v,onToggle:()=>void b(),label:l("settings.network.tailscale.title")})]}),!n.installed&&e.jsxs("p",{className:"text-xs text-accent-yellow mt-2",children:[l("settings.network.tailscale.notInstalled")," ",e.jsx("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:"underline hover:text-accent-blue",children:"tailscale.com/download"})]}),n.installed&&!n.running&&e.jsx("p",{className:"text-xs text-accent-yellow mt-2",children:l("settings.network.tailscale.notRunning",{state:n.backendState||"unknown"})}),i&&e.jsx("p",{className:"text-xs text-accent-blue mt-2",children:l("settings.network.tailscale.pendingHint")}),o&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/40 bg-accent-red/10 px-3 py-2 mt-2",children:[e.jsx(F,{size:14,className:"text-accent-red mt-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-accent-red break-all",children:o})]}),v&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:v}),n.serving&&n.url&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-xs text-dark-muted mb-1",children:l("settings.network.tailscale.address")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 min-w-0 break-all text-xs text-dark-text bg-dark-surface border border-dark-border rounded px-2 py-1 font-mono",children:n.url}),e.jsxs("button",{type:"button",onClick:()=>void p(n.url),title:l("settings.network.copy"),className:"shrink-0 flex items-center gap-1 px-2 py-1 rounded text-xs text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[d===n.url?e.jsx(Ce,{size:13,className:"text-accent-green"}):e.jsx(V,{size:13}),d===n.url?l("settings.network.copied"):l("settings.network.copy")]})]}),n.allServeUrls.length>1&&e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:l("settings.network.tailscale.otherEntries",{n:n.allServeUrls.length-1})})]}),n.serving&&e.jsxs("div",{className:"mt-2 rounded-lg border border-accent-yellow/40 bg-accent-yellow/10 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-accent-yellow",children:[e.jsx(F,{size:13}),l("settings.network.tailscale.warningTitle")]}),e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:l("settings.network.tailscale.warning")})]})]})}function $t(){const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState(!1),[r,x]=a.useState(null),d=a.useCallback(async()=>{const p=await E.system.daemon();return p.success&&p.data?l(p.data):x(p.error||t("settings.daemon.loadFailed")),p},[t]);a.useEffect(()=>{d()},[d]);const f=(s==null?void 0:s.daemonEnabled)??!1,n=s!=null&&s.fromEnv?t("settings.daemon.lockedByEnv",{env:s.envKey}):null,b=a.useCallback(async()=>{if(!s||i)return;const p=!f;if(!window.confirm(t(p?"settings.daemon.confirmEnable":"settings.daemon.confirmDisable")))return;m(!0),x(null);const k=await E.system.setDaemon(p);if(m(!1),!k.success){x(k.error||t("settings.daemon.applyFailed"));return}k.data&&l(k.data),j.info(t(p?"settings.daemon.enabledToast":"settings.daemon.disabledToast"))},[i,f,s,t]);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.daemon.description")}),r&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/40 bg-accent-red/10 px-3 py-2 mb-3",children:[e.jsx(F,{size:14,className:"text-accent-red mt-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-accent-red break-all",children:r})]}),e.jsxs("label",{className:`flex items-center justify-between gap-3 py-1 ${n?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.daemon.toggleLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.daemon.toggleHint")})]}),e.jsx(Kt,{checked:f,disabled:i||!s||!!n,onToggle:()=>void b(),label:t("settings.daemon.toggleLabel")})]}),n&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:n})]})}function Kt({checked:t,disabled:s,onToggle:l,label:i}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":i,disabled:s,onClick:l,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:cursor-not-allowed ${t?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-[18px]":"translate-x-0.5"}`})})}function Ft(){const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState(!1),[r,x]=a.useState(null),d=a.useCallback(async()=>{const p=await E.system.browse();return p.success&&p.data?l(p.data):x(p.error||t("settings.browse.loadFailed")),p},[t]);a.useEffect(()=>{d()},[d]);const f=(s==null?void 0:s.allowFullDiskBrowse)??!1,n=(s==null?void 0:s.writable)===!1?t("settings.browse.lockedByEnv",{env:s.envKey}):null,b=a.useCallback(async()=>{if(!s||i)return;const p=!f;if(!window.confirm(t(p?"settings.browse.confirmEnable":"settings.browse.confirmDisable")))return;m(!0),x(null);const k=await E.system.setBrowse(p);if(m(!1),!k.success){x(k.error||t("settings.browse.applyFailed"));return}k.data&&l(k.data),j.info(t(p?"settings.browse.enabledToast":"settings.browse.disabledToast"))},[i,f,s,t]);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.browse.description")}),r&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/40 bg-accent-red/10 px-3 py-2 mb-3",children:[e.jsx(F,{size:14,className:"text-accent-red mt-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-accent-red break-all",children:r})]}),e.jsxs("label",{className:`flex items-center justify-between gap-3 py-1 ${n?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.browse.toggleLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.browse.toggleHint")})]}),e.jsx(Lt,{checked:f,disabled:i||!s||!!n,onToggle:()=>void b(),label:t("settings.browse.toggleLabel")})]}),e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:t(f?"settings.browse.currentFull":"settings.browse.currentRestricted")}),n&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:n})]})}function Lt({checked:t,disabled:s,onToggle:l,label:i}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":i,disabled:s,onClick:l,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:cursor-not-allowed ${t?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-[18px]":"translate-x-0.5"}`})})}function It(){const{t}=D(),[s,l]=a.useState(null),[i,m]=a.useState(!0),[r,x]=a.useState(null),[d,f]=a.useState(!1),[n,b]=a.useState(""),[p,k]=a.useState(!1),v=a.useCallback(async()=>{const u=await E.config.desktop();if(u.success&&u.data){l(u.data),x(null),b(u.data.values.port===null?"":String(u.data.values.port)),k(!1);return}x(u.error||t("settings.desktop.loadFailed"))},[t]);a.useEffect(()=>{(async()=>(await v(),m(!1)))()},[v]);const o=!!(s!=null&&s.envOverridden.autoLaunch),y=!!(s!=null&&s.envOverridden.port),N=a.useCallback(async u=>{if(d)return;f(!0),x(null);const C=await E.config.setDesktop(u);if(f(!1),!C.success){x(C.error||t("settings.desktop.applyFailed"));return}C.data&&(l(C.data),b(C.data.values.port===null?"":String(C.data.values.port)),k(!1)),j.info(t("settings.desktop.savedRestartHint"))},[d,t]),S=a.useCallback(()=>{!s||o||N({autoLaunch:!s.values.autoLaunch})},[o,N,s]),$=a.useCallback(()=>{const u=n.trim();if(!u)return{ok:!0,value:null};if(!/^\d+$/.test(u))return{ok:!1};const C=Number(u);return C<1||C>65534?{ok:!1}:{ok:!0,value:C}},[n]),g=p&&!$().ok,K=(s==null?void 0:s.values.port)??null,L=$(),h=!p||L.ok&&L.value===K,P=a.useCallback(()=>{const u=$();u.ok&&N({port:u.value})},[$,N]),c=a.useCallback(()=>{b(""),k(!1),K!==null&&N({port:null})},[K,N]);return i?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-dark-muted",children:[e.jsx(R,{size:14,className:"animate-spin"}),t("settings.desktop.loading")]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.desktop.description")}),r&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/40 bg-accent-red/10 px-3 py-2 mb-3",children:[e.jsx(F,{size:14,className:"text-accent-red mt-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-accent-red break-all",children:r})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.desktop.autoLaunchLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.desktop.autoLaunchHint")})]}),e.jsx(Pt,{checked:!!(s!=null&&s.values.autoLaunch),disabled:d||o,onToggle:S,label:t("settings.desktop.autoLaunchLabel")})]}),o&&e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:t("settings.desktop.lockedByEnv",{env:(s==null?void 0:s.envKeys.autoLaunch)||""})}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-dark-border",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.desktop.portLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5 mb-2",children:t("settings.desktop.portHint")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:65534,value:n,disabled:d||y,placeholder:t("settings.desktop.portAuto"),onChange:u=>{b(u.target.value),k(!0)},onKeyDown:u=>{u.key==="Enter"&&!g&&!h&&P()},className:`flex-1 min-w-0 rounded-lg bg-dark-surface border px-3 py-2 text-sm text-dark-text font-mono focus:outline-none disabled:opacity-60 ${g?"border-accent-red":"border-dark-border focus:border-accent-blue"}`}),e.jsx("button",{type:"button",onClick:P,disabled:d||y||g||h,className:"shrink-0 px-3 py-2 rounded-lg text-sm bg-accent-blue/10 text-accent-blue hover:bg-accent-blue/20 border border-accent-blue/30 disabled:opacity-40 disabled:cursor-not-allowed",children:t("settings.desktop.save")}),K!==null&&e.jsx("button",{type:"button",onClick:c,disabled:d||y,className:"shrink-0 px-3 py-2 rounded-lg text-sm text-dark-muted hover:text-dark-text hover:bg-dark-hover border border-dark-border disabled:opacity-40",children:t("settings.desktop.portAuto")})]}),g&&e.jsx("p",{className:"text-xs text-accent-red mt-1",children:t("settings.desktop.portInvalid")}),y&&e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:t("settings.desktop.lockedByEnv",{env:(s==null?void 0:s.envKeys.port)||""})}),K!==null&&!g&&e.jsxs("div",{className:"mt-2 rounded-lg border border-accent-yellow/40 bg-accent-yellow/10 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-accent-yellow",children:[e.jsx(F,{size:13}),t("settings.desktop.pinnedWarningTitle")]}),e.jsx("p",{className:"text-xs text-dark-muted mt-1",children:t("settings.desktop.pinnedWarning",{port:K})})]})]}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-dark-border flex items-start gap-2",children:[e.jsx(le,{size:13,className:"text-dark-muted mt-0.5 shrink-0"}),e.jsxs("p",{className:"text-xs text-dark-muted",children:[t("settings.desktop.restartHint"),(s==null?void 0:s.configPath)&&e.jsx("span",{className:"block mt-1 font-mono break-all",children:s.configPath})]})]})]})}function Pt({checked:t,disabled:s,onToggle:l,label:i}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":i,disabled:s,onClick:l,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:cursor-not-allowed ${t?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-[18px]":"translate-x-0.5"}`})})}const fe={get:()=>xe.get("/api/config/attention"),set:t=>xe.post("/api/config/attention",{sound:t})};function Dt(){const{t}=D(),[s,l]=a.useState(!0),[i,m]=a.useState(!1),[r,x]=a.useState(null),d=a.useCallback(async()=>{try{const n=await fe.get();n.success&&n.data?(l(n.data.sound),x(null)):x(n.error||t("settings.notifications.loadFailed"))}catch{x(t("settings.notifications.loadFailed"))}},[t]);a.useEffect(()=>{d()},[d]);const f=a.useCallback(async()=>{if(i)return;const n=!s;m(!0),x(null),l(n);try{const b=await fe.set(n);!b.success||!b.data?(l(!n),x(b.error||t("settings.notifications.saveFailed"))):l(b.data.sound)}catch{l(!n),x(t("settings.notifications.saveFailed"))}finally{m(!1)}},[i,s,t]);return e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center justify-between gap-3 py-1 cursor-pointer",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.notifications.soundLabel")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.notifications.soundHint")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s,disabled:i,onClick:f,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:cursor-not-allowed ${s?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${s?"translate-x-[18px]":"translate-x-0.5"}`})})]}),r&&e.jsxs("div",{className:"mt-2 flex items-start gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-all",children:r})]})]})}const te="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50";function At(){const{t}=D(),[s,l]=a.useState(!0),[i,m]=a.useState(!1),[r,x]=a.useState(null),[d,f]=a.useState(!1),[n,b]=a.useState(""),[p,k]=a.useState(""),[v,o]=a.useState(""),[y,N]=a.useState(!1),S=a.useCallback(async()=>{l(!0);try{const g=await E.config.image.get();if(g.success&&g.data){const K=g.data;x(K),f(K.toolEnabled&&K.supportsImageGeneration!==!1),b(K.imageEndpoint??""),k(K.imageModel??""),o(""),N(!1)}}catch{}l(!1)},[]);a.useEffect(()=>{S()},[S]);const $=async()=>{m(!0);try{const g=await E.config.image.save({supportsImageGeneration:d,toolEnabled:d,imageEndpoint:n.trim(),imageModel:p.trim(),...y?{imageApiKey:null}:v.trim()?{imageApiKey:v.trim()}:{}});g.success?(j.success(t("settings.imageGen.saved")),await S()):j.error(g.error||t("settings.imageGen.saveFailed"))}catch(g){j.error(g instanceof Error?g.message:String(g))}m(!1)};return s?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-dark-muted py-2",children:[e.jsx(R,{size:14,className:"animate-spin"}),t("common.loading")]}):r!=null&&r.hasProviderEntry?e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.imageGen.desc")}),e.jsxs("label",{className:"flex items-center justify-between mb-1 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.imageGen.enableLabel"),e.jsxs("span",{className:`ml-2 text-xs ${d?"text-accent-green":"text-dark-muted"}`,children:["(",t("settings.imageGen.currently"),": ",d?"ON":"OFF",")"]})]}),e.jsx("button",{role:"switch","aria-checked":d,"aria-label":t("settings.imageGen.enableLabel"),onClick:()=>f(!d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${d?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?"translate-x-6":"translate-x-1"}`})})]}),e.jsx("p",{className:"mb-4 text-xs text-dark-muted",children:t("settings.imageGen.toolHint")}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"mb-1 block text-sm text-dark-muted",children:t("settings.imageGen.endpoint")}),e.jsx("input",{type:"text",value:n,onChange:g=>b(g.target.value),placeholder:r.defaultEndpoint?t("settings.imageGen.endpointPlaceholder",{url:r.defaultEndpoint}):t("settings.imageGen.endpointNoProvider"),className:te}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:t("settings.imageGen.endpointHint")})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"mb-1 block text-sm text-dark-muted",children:t("settings.imageGen.model")}),e.jsx("input",{type:"text",value:p,onChange:g=>k(g.target.value),placeholder:t("settings.imageGen.modelPlaceholder"),className:te}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:t("settings.imageGen.modelHint")})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"mb-1 block text-sm text-dark-muted",children:t("settings.imageGen.apiKey")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",value:v,onChange:g=>{o(g.target.value),g.target.value&&N(!1)},disabled:y,placeholder:r.hasImageApiKey?t("settings.imageGen.apiKeyKeep"):t("settings.imageGen.apiKeyInherit"),className:te}),r.hasImageApiKey&&e.jsxs("label",{className:"flex shrink-0 cursor-pointer items-center gap-1.5 text-xs text-dark-muted",children:[e.jsx("input",{type:"checkbox",checked:y,onChange:g=>{N(g.target.checked),g.target.checked&&o("")}}),t("settings.imageGen.clearKey")]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{variant:"accent",size:"sm",onClick:$,loading:i,children:t("common.save")}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-dark-muted",children:[e.jsx(Z,{size:12}),r.providerName??r.provider]})]})]}):e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-yellow/40 bg-accent-yellow/5 p-3 text-sm text-dark-muted",children:[e.jsx(F,{size:14,className:"mt-0.5 shrink-0 text-accent-yellow"}),e.jsx("span",{children:t("settings.imageGen.noProvider")})]})}const Bt=a.memo(function({nameKey:s,descriptionKey:l,colors:i,isSelected:m,onClick:r}){const{t:x}=D(),d=["bg","surface","border","text","muted","accentBlue","accentGreen","accentRed","accentYellow","accentPurple"];return e.jsxs("button",{onClick:r,className:`relative flex flex-col items-center rounded-xl p-2 transition-all focus:outline-none focus:ring-2 focus:ring-accent-blue/50 ${m?"ring-2 ring-accent-blue/60 bg-dark-bg border border-accent-blue/40 shadow-sm":"border border-dark-border hover:border-accent-blue/30 bg-dark-bg hover:shadow-sm"}`,title:x(l),"aria-pressed":m,"aria-label":x(s),children:[e.jsx("div",{className:"flex gap-0.5 rounded-md overflow-hidden w-full h-8 mb-1.5 border border-dark-border/40",children:d.map(f=>e.jsx("div",{className:"flex-1",style:{backgroundColor:i[f]},title:f},f))}),e.jsx("span",{className:`text-meta font-medium truncate w-full text-center ${m?"text-accent-blue":"text-dark-text"}`,children:x(s)}),m&&e.jsx("span",{className:"absolute top-1 right-1 w-4 h-4 bg-accent-blue rounded-full flex items-center justify-center shadow-sm",children:e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",children:e.jsx("path",{d:"M1.5 4L3.5 6L6.5 2",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}),Ot="1.0.0",Mt={version:Ot},he=[{labelKey:"settings.groups.general",items:[{id:"general",icon:We,labelKey:"settings.nav.general",searchKeys:["language","display","developer","general","语言","界面","开发者","通用"]},{id:"appearance",icon:se,labelKey:"settings.nav.appearance",searchKeys:["theme","color","palette","custom","ripple","effect","主题","颜色","波纹","动效","背景"]},{id:"profile",icon:re,labelKey:"settings.nav.profile",searchKeys:["profile","soul","persona","identity","name","画像","个性化","身份","称呼","soul.md"]},{id:"voice",icon:Se,labelKey:"settings.nav.voice",searchKeys:["voice","stt","whisper","funasr","speech","语音","安装"]}]},{labelKey:"settings.groups.features",items:[{id:"models",icon:ae,labelKey:"settings.nav.models",searchKeys:["provider","model","api","key","openai","anthropic","deepseek","模型"]},{id:"connectors",icon:_e,labelKey:"settings.nav.connectors",searchKeys:["connector","capabilities","computer use","gmail","grok","连接器","能力"]},{id:"imageGen",icon:Z,labelKey:"settings.nav.imageGen",searchKeys:["image","imagegen","generate_image","text to image","flux","siliconflow","dall-e","图片","生图","文生图","绘图"]},{id:"context",icon:Ve,labelKey:"settings.nav.context",searchKeys:["context","token","offload","artifact","上下文","外置"]},{id:"configFiles",icon:Ee,labelKey:"settings.nav.configFiles",searchKeys:["config","file","yaml","json","editor","配置文件"]}]},{labelKey:"settings.groups.system",items:[{id:"sandbox",icon:Te,labelKey:"settings.nav.sandbox",searchKeys:["sandbox","sandbox-exec","bwrap","bubblewrap","isolation","seccomp","permission","沙箱","隔离","命令","权限"]},{id:"network",icon:ze,labelKey:"settings.nav.network",searchKeys:["network","lan","wifi","port","share","access","server","bind","网络","局域网","内网","多人","共享","访问","端口"]},{id:"daemon",icon:Q,labelKey:"settings.nav.daemon",searchKeys:["daemon","background","persistent","server","backend","service","常驻","后台","守护","进程","服务"]},{id:"browse",icon:$e,labelKey:"settings.nav.browse",searchKeys:["browse","disk","directory","folder","picker","scope","boundary","home","explorer","浏览","磁盘","目录","文件夹","范围","边界","家目录"]},{id:"desktop",icon:ie,labelKey:"settings.nav.desktop",searchKeys:["desktop","autolaunch","autostart","startup","boot","launch","port","backend","桌面","客户端","开机","自启","启动","端口","后台"]},{id:"system",icon:Q,labelKey:"settings.nav.system",searchKeys:["system","server","uptime","restart","reboot","系统","重启"]},{id:"about",icon:le,labelKey:"settings.nav.about",searchKeys:["about","version","info","关于","版本"]}]}],ke=[{key:"bg",labelKey:"settings.colorBg"},{key:"surface",labelKey:"settings.colorSurface"},{key:"border",labelKey:"settings.colorBorder"},{key:"text",labelKey:"settings.colorText"},{key:"muted",labelKey:"settings.colorMuted"},{key:"accentBlue",labelKey:"settings.colorAccentBlue"},{key:"accentGreen",labelKey:"settings.colorAccentGreen"},{key:"accentRed",labelKey:"settings.colorAccentRed"},{key:"accentYellow",labelKey:"settings.colorAccentYellow"},{key:"accentPurple",labelKey:"settings.colorAccentPurple"}],cs=a.memo(function({isOpen:s,onClose:l,onNavigate:i,focusSection:m}){const{t:r}=D(),[x,d]=a.useState("general"),[f,n]=a.useState("");et({isOpen:s,onClose:l});const b=a.useRef(null);a.useEffect(()=>{!s||(m==null?void 0:m.section)!=="stt"||(d("voice"),requestAnimationFrame(()=>{var v;(v=b.current)==null||v.scrollIntoView({behavior:"smooth",block:"start"})}))},[m==null?void 0:m.nonce,s]);const p=a.useRef(null);a.useEffect(()=>{!s||(m==null?void 0:m.section)!=="profile"||(d("profile"),requestAnimationFrame(()=>{var v;(v=p.current)==null||v.scrollIntoView({behavior:"smooth",block:"start"})}))},[m==null?void 0:m.nonce,s]),a.useEffect(()=>{s&&n("")},[s]);const k=a.useMemo(()=>{if(!f.trim())return he;const v=f.toLowerCase().trim();return he.map(o=>({...o,items:o.items.filter(y=>r(y.labelKey).toLowerCase().includes(v)||y.searchKeys.some(N=>N.toLowerCase().includes(v)))})).filter(o=>o.items.length>0)},[f,r]);return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden p-4",role:"dialog","aria-modal":"true","aria-label":r("settings.title"),children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"relative w-full max-w-4xl h-[80vh] bg-dark-surface border border-dark-border rounded-2xl shadow-2xl flex flex-col overflow-hidden animate-fade-in",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between pl-5 pr-3 py-3 border-b border-dark-border",children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:r("settings.title")}),e.jsx("button",{onClick:l,"aria-label":"Close",className:"p-1.5 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:e.jsx(qe,{size:18,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"flex flex-1 min-h-0",children:[e.jsxs("nav",{className:"w-52 shrink-0 border-r border-dark-border bg-dark-bg/40 flex flex-col min-h-0",children:[e.jsx("div",{className:"p-3 pb-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ye,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),e.jsx("input",{type:"text",value:f,onChange:v=>n(v.target.value),placeholder:r("settings.searchPlaceholder"),className:"w-full bg-dark-surface border border-dark-border rounded-lg pl-8 pr-2 py-1.5 text-xs text-dark-text placeholder-dark-muted focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 pb-3",children:[k.map(v=>e.jsxs("div",{className:"mt-3 first:mt-1",children:[e.jsx("div",{className:"px-2 mb-1 text-badge font-medium uppercase tracking-wide text-dark-muted/80",children:r(v.labelKey)}),e.jsx("div",{className:"space-y-0.5",children:v.items.map(o=>{const y=o.icon,N=x===o.id;return e.jsxs("button",{onClick:()=>d(o.id),"aria-current":N?"page":void 0,className:`w-full flex items-center gap-2.5 px-2.5 py-1.5 rounded-lg text-sm transition-colors ${N?"bg-accent-blue/10 text-accent-blue font-medium":"text-dark-text/90 hover:bg-dark-hover"}`,children:[e.jsx(y,{size:15,className:N?"text-accent-blue":"text-dark-muted"}),e.jsx("span",{className:"truncate",children:r(o.labelKey)})]},o.id)})})]},v.labelKey)),k.length===0&&e.jsx("div",{className:"mt-6 text-center text-xs text-dark-muted",children:r("settings.noResults")})]})]}),e.jsx("div",{className:"flex-1 min-w-0 min-h-0 overflow-y-auto custom-scrollbar",children:e.jsxs("div",{className:"max-w-2xl px-6 py-5",children:[x==="general"&&e.jsx(Rt,{}),x==="appearance"&&e.jsx(Gt,{}),x==="profile"&&e.jsx("div",{ref:p,id:"settings-section-profile",className:"scroll-mt-5",children:e.jsx(Ut,{})}),x==="voice"&&e.jsx("div",{ref:b,id:"settings-section-stt",className:"scroll-mt-5",children:e.jsx(Ht,{})}),x==="models"&&e.jsx(Wt,{onNavigate:i}),x==="connectors"&&e.jsx(_t,{onNavigate:i}),x==="imageGen"&&e.jsx(Vt,{}),x==="context"&&e.jsx(qt,{}),x==="configFiles"&&e.jsx(Yt,{}),x==="sandbox"&&e.jsx(Xt,{}),x==="network"&&e.jsx(A,{icon:ze,iconColor:"text-accent-green",title:r("settings.nav.network"),children:e.jsx(Tt,{})}),x==="daemon"&&e.jsx(A,{icon:Q,iconColor:"text-accent-green",title:r("settings.daemon.title"),children:e.jsx($t,{})}),x==="browse"&&e.jsx(A,{icon:$e,iconColor:"text-accent-green",title:r("settings.browse.title"),children:e.jsx(Ft,{})}),x==="desktop"&&e.jsx(A,{icon:ie,iconColor:"text-accent-blue",title:r("settings.nav.desktop"),children:e.jsx(It,{})}),x==="system"&&e.jsx(Jt,{}),x==="about"&&e.jsx(Qt,{})]})})]})]})]}):null});function Rt(){const{t}=D(),{language:s,setLanguage:l,developerView:i,setDeveloperView:m}=Le(),r=tt(s),x=[{code:ue,label:t("settings.languageAuto")},...st.map(d=>({code:d.code,label:d.label}))];return e.jsxs(e.Fragment,{children:[e.jsxs(A,{icon:ye,iconColor:"text-accent-blue",title:t("settings.language"),children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:x.map(({code:d,label:f})=>e.jsx("button",{lang:d===ue?void 0:d,onClick:()=>{l(d),d!==r&&E.config.language.set(at(nt(d))).catch(()=>{})},className:`px-4 py-2 rounded-lg transition-all ${r===d?"bg-accent-blue text-accent-fg":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:f},d))}),e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:t("settings.languageHint")})]}),e.jsx(A,{icon:Ke,iconColor:"text-accent-blue",title:t("settings.display"),children:e.jsxs("label",{className:"flex items-center justify-between gap-3 py-1 cursor-pointer",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:t("settings.developerView")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t("settings.developerViewHint")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":i,onClick:()=>m(!i),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${i?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${i?"translate-x-[18px]":"translate-x-0.5"}`})})]})}),e.jsx(A,{icon:Xe,iconColor:"text-accent-yellow",title:t("settings.notifications.title"),children:e.jsx(Dt,{})})]})}function Gt(){const{t}=D(),{theme:s,setTheme:l,themePresetId:i,setThemePreset:m,customTheme:r,customThemeEnabled:x,setCustomTheme:d,setCustomThemeEnabled:f,resetCustomTheme:n}=Le(),[b,p]=a.useState(x),k=a.useMemo(()=>s==="dark"?"dark":s==="light"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[s]),v=a.useMemo(()=>Object.values(rt),[]);return e.jsxs(A,{icon:se,iconColor:"text-accent-purple",title:t("settings.theme"),children:[e.jsx("div",{className:"flex gap-2 mb-4",children:["dark","light","auto"].map(o=>e.jsx("button",{onClick:()=>l(o),className:`px-4 py-2 rounded-lg transition-all ${s===o?"bg-accent-blue text-accent-fg":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:t(o==="dark"?"settings.themeDark":o==="light"?"settings.themeLight":"settings.themeAuto")},o))}),e.jsxs("div",{className:"mb-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-text mb-2",children:t("settings.themePresets")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:v.map(o=>{if(!o)return null;const y=(i||lt)===o.id,N=k==="dark"?o.dark:o.light;return e.jsx(Bt,{id:o.id,nameKey:o.nameKey,descriptionKey:o.descriptionKey,colors:N,isSelected:y,onClick:()=>m(o.id)},o.id)})})]}),e.jsxs("div",{className:"pt-4 border-t border-dark-border",children:[e.jsxs("button",{onClick:()=>{const o=!b;p(o),f(o)},className:"flex items-center gap-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(se,{size:14}),e.jsx("span",{children:t("settings.customOverrides")}),e.jsx("span",{className:`w-8 h-4 rounded-full transition-colors ${b?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`block w-3 h-3 rounded-full bg-white transition-transform mt-0.5 ${b?"ml-4":"ml-0.5"}`})})]}),b&&e.jsx("p",{className:"text-badge text-dark-muted mt-1 mb-2",children:t("settings.customOverridesHint")}),b&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex gap-1 mb-3 rounded-lg overflow-hidden h-6",children:ke.map(({key:o})=>e.jsx("div",{className:"flex-1",style:{backgroundColor:r[o]},title:o},o))}),e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:ke.map(({key:o,labelKey:y})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:r[o],onChange:N=>d({[o]:N.target.value}),className:"w-8 h-8 rounded border border-dark-border cursor-pointer bg-transparent p-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-dark-muted flex-1 truncate",children:t(y)}),e.jsx("input",{type:"text",value:r[o],onChange:N=>{const S=N.target.value;/^#[0-9a-fA-F]{0,6}$/.test(S)&&d({[o]:S})},className:"w-16 bg-dark-bg border border-dark-border rounded px-1 py-0.5 text-xs text-dark-text font-mono text-center",maxLength:7})]},o))}),e.jsx("button",{onClick:n,className:"mt-2 text-xs text-dark-muted hover:text-accent-red transition-colors",children:t("settings.resetColors")})]})]})]})}function Ht(){const{t}=D();return e.jsxs(e.Fragment,{children:[e.jsx(A,{icon:Se,iconColor:"text-accent-blue",title:t("stt.setup.title"),children:e.jsx(vt,{})}),e.jsx(A,{icon:Je,iconColor:"text-accent-purple",title:t("tts.setup.title"),children:e.jsx(yt,{})})]})}function Ut(){const{t}=D();return e.jsx(A,{icon:re,iconColor:"text-accent-purple",title:t("settings.profile.title"),children:e.jsx(Et,{})})}function Wt({onNavigate:t}){return e.jsxs(A,{icon:ae,iconColor:"text-accent-yellow",title:"Provider & Models",children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Configure AI providers, API keys, and model settings. Add or remove providers like OpenAI, Anthropic, DeepSeek, and more."}),e.jsx(G,{variant:"accent",leftIcon:e.jsx(Fe,{size:14}),onClick:()=>t==null?void 0:t("models"),className:"w-fit",children:"Manage Providers & Models"})]})}function _t({onNavigate:t}){const{t:s}=D();return e.jsxs(A,{icon:ie,iconColor:"text-accent-green",title:s("settings.capabilities.title"),children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Computer Use、外部服务连接器(X/Twitter、Gmail、Google Workspace、Microsoft 365 等)与 xAI (Grok) 统一在连接器页集中管理。"}),e.jsx(G,{variant:"accent",leftIcon:e.jsx(Fe,{size:14}),onClick:()=>t==null?void 0:t("connectors"),className:"w-fit",children:"Manage Connectors & Capabilities"})]})}function Vt(){const{t}=D();return e.jsx(A,{icon:Z,iconColor:"text-accent-purple",title:t("settings.imageGen.title"),children:e.jsx(At,{})})}function qt(){const{t}=D();return e.jsxs(e.Fragment,{children:[e.jsx(A,{icon:Qe,iconColor:"text-accent-blue",title:"Max Context",children:e.jsx(Zt,{})}),e.jsx(A,{icon:Ke,iconColor:"text-accent-purple",title:t("settings.contextOffload.title"),children:e.jsx(Nt,{})})]})}function Yt(){return e.jsx(A,{icon:Ee,iconColor:"text-accent-green",title:"Config Files (~/.agent/)",children:e.jsx(ht,{})})}function Xt(){const{t}=D();return e.jsx(A,{icon:Te,iconColor:"text-accent-green",title:t("settings.sandbox.title"),children:e.jsx(wt,{})})}function Jt(){const[t,s]=a.useState(0),[l,i]=a.useState(!1),[m,r]=a.useState(!1);a.useEffect(()=>{let n=!0;const b=async()=>{try{const k=await E.system.status();n&&k.success&&k.data&&s(k.data.uptime)}catch{}};b();const p=setInterval(b,l?2e3:1e4);return()=>{n=!1,clearInterval(p)}},[l]);const x=a.useCallback(async()=>{if(window.confirm("Restart the server? All active sessions will be disconnected.")){i(!0);try{const n=await E.system.restart();n.success?j.info("Server restarting..."):(j.error(n.error||"Restart failed"),i(!1))}catch{j.error("Failed to send restart request"),i(!1)}}},[]),d=a.useCallback(async()=>{if(window.confirm("Shut down the server? This will stop the entire backend process.")&&window.confirm("Are you sure? All active sessions and unsaved work will be lost.")){r(!0);try{const n=await E.system.shutdown();n.success?j.info("Server shutting down..."):(j.error(n.error||"Shutdown failed"),r(!1))}catch{j.error("Failed to send shutdown request"),r(!1)}}},[]);a.useEffect(()=>{l&&t<1e4&&(i(!1),j.success("Server restarted"))},[t,l]);const f=n=>{const b=Math.floor(n/1e3),p=Math.floor(b/60),k=Math.floor(p/60);return k>0?`${k}h ${p%60}m`:p>0?`${p}m ${b%60}s`:`${b}s`};return e.jsx(A,{icon:Q,iconColor:"text-dark-muted",title:"System",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-dark-muted",children:"Server Uptime"}),e.jsx("span",{className:"text-dark-text font-mono",children:f(t)})]}),e.jsxs("button",{onClick:x,disabled:l,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${l?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(_,{size:14,className:l?"animate-spin":""}),l?"Restarting...":"Restart Server"]}),e.jsxs("button",{onClick:d,disabled:m,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${m?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(Ze,{size:14,className:m?"animate-pulse":""}),m?"Shutting Down...":"Shutdown Server"]})]})})}function Qt(){const{t}=D();return e.jsx(A,{icon:le,iconColor:"text-accent-blue",title:t("settings.about"),children:e.jsxs("div",{className:"text-sm text-dark-muted space-y-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-dark-text",children:"DeepSeekCode Web"})," v",Mt.version]}),e.jsx("p",{children:t("settings.aboutDesc")}),e.jsx("p",{className:"text-xs",children:"Powered by React + TypeScript + TailwindCSS"}),e.jsx("p",{className:"text-xs",children:"联系:ngwlh2026@gmail.com"}),e.jsxs("button",{onClick:()=>it.getState().openWhatsNew(),className:"mt-2 flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all bg-accent-blue/10 text-accent-blue hover:bg-accent-blue/20 border border-accent-blue/30",children:[e.jsx(Z,{size:14}),t("settings.whatsNew")]})]})})}function Zt(){const t=me(n=>n.maxContextTokens),s=me(n=>n.setMaxContextTokens),[l,i]=a.useState(String(t)),[m,r]=a.useState(!1),x=[32e3,64e3,128e3,256e3,512e3,1e6,2e6],d=async()=>{const n=parseInt(l,10);if(!(isNaN(n)||n<1e3)){r(!0),s(n);try{await E.config.provider.save({contextWindow:n}),j.success("Context window saved")}catch(b){j.error("Failed to save context window: "+(b instanceof Error?b.message:"Unknown error"))}r(!1)}},f=n=>n>=1e6?(n/1e6).toFixed(0)+"M":(n/1e3).toFixed(0)+"K";return e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Set the maximum context window (in tokens) for your AI model. This controls how the progress bar and usage percentage are calculated."}),e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("input",{type:"number",value:l,onChange:n=>i(n.target.value),min:1e3,max:1e7,step:1e3,className:"w-32 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"}),e.jsx("span",{className:"text-sm text-dark-muted",children:"tokens"}),e.jsx(G,{variant:"accent",onClick:d,loading:m,size:"sm",children:"Apply"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:x.map(n=>e.jsx("button",{onClick:async()=>{i(String(n)),s(n);try{await E.config.provider.save({contextWindow:n}),j.success("Context window saved")}catch(b){j.error("Failed to save context window: "+(b instanceof Error?b.message:"Unknown error"))}},className:"px-3 py-1 rounded-lg text-xs transition-all",children:f(n)},n))}),e.jsxs("p",{className:"text-xs text-dark-muted mt-2",children:["Current: ",e.jsx("span",{className:"font-mono text-dark-text",children:parseInt(l,10).toLocaleString()})," tokens"]})]})}export{cs as SettingsModal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./markdown-BWXjRrSw.js";import{f as i}from"./index-CeeLdENM.js";function r({className:t,variant:a="rectangular",width:d,height:s,shimmer:n=!0}){const l={text:"rounded h-4",circular:"rounded-full",rectangular:"rounded-lg"};return e.jsx("div",{"aria-hidden":"true",className:i(n?"skeleton-shimmer":"animate-pulse bg-dark-border/50",l[a],t),style:{width:d,height:s}})}function x({className:t}){return e.jsxs("div",{className:i("bg-dark-surface border border-dark-border rounded-lg p-4 space-y-3",t),children:[e.jsx(r,{variant:"text",width:"60%",height:20}),e.jsx(r,{variant:"text",width:"100%"}),e.jsx(r,{variant:"text",width:"80%"}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(r,{variant:"circular",width:32,height:32}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(r,{variant:"text",width:"40%",height:14}),e.jsx(r,{variant:"text",width:"60%",height:14})]})]})]})}function o({count:t=3,className:a}){return e.jsx("div",{className:i("space-y-2",a),children:Array.from({length:t}).map((d,s)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(r,{variant:"circular",width:40,height:40}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(r,{variant:"text",width:"30%",height:16}),e.jsx(r,{variant:"text",width:"70%",height:14})]})]},`skeleton-${s}`))})}export{o as S,r as a,x as b};
|