@wudao-org/web 0.4.21 → 0.5.1

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.
@@ -0,0 +1,339 @@
1
+ import{t as fr,a as Mo,W as To,r as i,j as e,i as Ue,b as _e,c as He,I as xr,d as Do,e as Gs,f as Ao,g as et,h as bt,k as vr,l as Oo,R as ce,m as On,p as Io,n as Lo,s as Po,E as _o,o as gr,q as ut,u as Zt,v as Fo,w as es,x as zo,y as Zn,z as Bo,A as Ko,B as Wo,C as Uo,D as jr,P as $t,F as Rt,G as ft,H as vn,J as Ho,K as gn,L as jn,M as qo,N as ts,O as br,Q as Go,S as Vo,T as Mt,U as yr,V as ea,X as Nr,Y as Yo,Z as Xo,_ as Jo,$ as Qo,a0 as Zo,a1 as ec,a2 as tc,a3 as sc,a4 as nc,a5 as ac,a6 as lc,a7 as rc,a8 as ic,a9 as oc,aa as cc,ab as dc,ac as uc,ad as hc,ae as mc,af as ol,ag as pc,ah as kr,ai as fc,aj as xc,ak as vc}from"./tokens-w4ILWEys.js";const bn=1;function gc(t){const s=new WebSocket(t);return{get readyState(){return s.readyState},send:n=>s.send(n),close:(n,a)=>s.close(n,a),addEventListener:(n,a)=>s.addEventListener(n,a)}}function jc(){return`L-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function bc(t,s){if(s==null)return t;let n=t===void 0||Object.keys(t).length!==Object.keys(s).length;const a={};for(const[l,r]of Object.entries(s)){if(r===null||typeof r!="object"){n=!0;continue}const o=r.busy===!0,c=typeof r.sessionId=="string"?r.sessionId:"",d=t?.[l];d===void 0||d.busy!==o||d.sessionId!==c?(a[l]={busy:o,sessionId:c,history:d?.history??[],historyEpoch:d?.historyEpoch??0},n=!0):a[l]=d}return n?a:t}function yc(t,s,n,a){const l=t?.[s];return{...t??{},[s]:{busy:l?.busy??!1,sessionId:l?.sessionId??"",history:a?[...n]:[...l?.history??[],...n],historyEpoch:(l?.historyEpoch??0)+(a?1:0)}}}function Nc(t=window.location){return decodeURIComponent(t.hash.replace(/^#/,""))}function In(t=window.location){return new URLSearchParams(t.search).get("shell")==="desktop"?"desktop":null}function kc(t=window.location){return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}`}function wc(t){return[1e3,2e3,4e3,8e3,16e3,3e4][Math.min(t-1,5)]??3e4}const Ln=8;function Sc(){const t=globalThis.crypto;return typeof t?.randomUUID=="function"?t.randomUUID():`c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Cc(t){switch(t.op){case"submit":case"interrupt":case"setMode":case"answerPermission":case"recallSteer":case"answerAskUser":case"detachToolCall":case"resume":case"rewind":case"edit":case"settingsSaveKey":case"settingsSet":case"settingsSaveProvider":case"switchWorkspace":case"panelRootSet":case"agentRootSwitch":case"attachmentSave":case"fileSave":case"pluginMarketAdd":case"pluginMarketUpdate":case"pluginMarketRemove":case"pluginInstall":case"pluginInstallSpec":case"longtermMemoryForget":case"pluginUninstall":case"pluginEnable":case"pluginDisable":case"personaSave":case"personaDelete":case"petSubmit":case"petInterrupt":case"petAnswerPermission":case"petNewSession":case"petSetModel":case"petSetEffort":case"petSetWorkspace":case"memoryDecide":case"memoryEdit":case"fileRevert":case"schedulesSetEnabled":case"schedulesRunNow":return!0;case"improvementFace":return t.action!=="list";case"switch":return t.n!==void 0;case"recentWorkspaces":return t.add!==void 0;default:return!1}}function Fs(t,s){return s===void 0||s===""||s===t.provider}function wr(t,s){return Fs(t,s)?`/model ${t.model}`:`/provider ${t.provider}`}function cl(t){return t==="reply"?"language.reply":"language.reasoning"}function Pn(t){return t==="workspace"?"accept":t}function Ec(t){return t==="workspace"?"ask":t==="ask"?"auto":t==="auto"?"plan":"workspace"}function Sr(t){if(t<100)return"<0.1s";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s);return n<3600?`${Math.floor(n/60)}m${String(n%60).padStart(2,"0")}s`:`${Math.floor(n/3600)}h${String(Math.floor(n%3600/60)).padStart(2,"0")}m`}function $c(t,s){const n=t.models.map(a=>a.contextLength!=null?{name:a.name,contextLength:a.contextLength}:{name:a.name});return t.custom?{...t.label!==""?{label:t.label}:{},baseUrl:t.baseUrl??"",...t.defaultModel!==""?{defaultModel:t.defaultModel}:{},...t.defaultContextLength!=null?{defaultContextLength:t.defaultContextLength}:{},...t.reasoningFormat!==void 0?{reasoningFormat:t.reasoningFormat}:{},...t.wire!==void 0?{wire:t.wire}:{},...t.persona!==void 0?{persona:t.persona}:{},models:n,effort:s}:{models:n,...t.reasoningFormat!==void 0?{reasoningFormat:t.reasoningFormat}:{},...t.wire!==void 0?{wire:t.wire}:{},...t.persona!==void 0?{persona:t.persona}:{},effort:s}}class Rc{opts;probeListeners=new Set;loopListeners=new Set;ws=null;nextId=1;pendingOps=new Map;replayQueue=[];listeners=new Set;snap;userClosed=!1;reconnectAttempt=0;timer=null;clientId=Sc();queuedSetMode=null;constructor(s){this.opts={...s,wsFactory:s.wsFactory??gc,reconnect:s.reconnect??!0,backoff:s.backoff??wc,maxReconnectAttempts:s.maxReconnectAttempts??Ln,setTimeout:s.setTimeout??((n,a)=>setTimeout(n,a)),clearTimeout:s.clearTimeout??(n=>clearTimeout(n))},this.snap={connection:"connecting",reconnectAttempt:0,lastClose:null,status:null,history:[],historyEpoch:0}}subscribe=s=>(this.listeners.add(s),()=>this.listeners.delete(s));getSnapshot=()=>this.snap;notify(){for(const s of this.listeners)s()}connect(){if(this.userClosed)return;this.opts.clearTimeout(this.timer),this.timer=null;const s=this.opts.wsFactory(this.opts.url);this.ws=s,this.snap.connection!=="reconnecting"&&(this.snap={...this.snap,connection:"connecting"},this.notify());const n=()=>this.ws===s;s.addEventListener("open",()=>{n()&&(s.send(JSON.stringify({t:"auth",token:this.opts.token})),this.snap={...this.snap,connection:"authenticating"},this.notify())}),s.addEventListener("message",a=>{n()&&this.onMessage(a.data)}),s.addEventListener("close",a=>{this.ws!==s&&this.ws!==null||this.onClose(a.code,a.reason??"")}),s.addEventListener("error",()=>{})}close(){this.userClosed=!0,this.opts.clearTimeout(this.timer),this.timer=null,this.failPending(new Error("client closed")),this.replayQueue=[],this.queuedSetMode=null,this.ws?.close(1e3,"client closed"),this.ws=null,this.snap={...this.snap,connection:"closed",reconnectAttempt:0},this.notify()}reconnect(){this.userClosed||(this.opts.clearTimeout(this.timer),this.timer=null,this.reconnectAttempt=0,this.snap={...this.snap,connection:"connecting",reconnectAttempt:0},this.notify(),this.connect())}clearView(){this.snap={...this.snap,history:[],historyEpoch:this.snap.historyEpoch+1},this.notify()}onClose(s,n){const a=new Error(`connection closed (${s})`);if(this.ws=null,this.snap={...this.snap,lastClose:{code:s,reason:n}},this.userClosed||this.opts.reconnect===!1||s===4401){this.failPending(a),this.replayQueue=[],this.snap={...this.snap,connection:s===4401?"auth-failed":"closed",reconnectAttempt:0},this.notify();return}if(this.reconnectAttempt>=this.opts.maxReconnectAttempts){this.failPending(a),this.replayQueue=[],this.snap={...this.snap,connection:"gave-up",reconnectAttempt:this.reconnectAttempt},this.notify();return}this.replayQueue=[];for(const[r,o]of this.pendingOps)o.replay!==void 0?this.replayQueue.push({id:r,op:o.replay}):(this.pendingOps.delete(r),o.reject(a));this.reconnectAttempt+=1,this.snap={...this.snap,connection:"reconnecting",reconnectAttempt:this.reconnectAttempt},this.notify();const l=this.opts.backoff(this.reconnectAttempt);this.timer=this.opts.setTimeout(()=>{this.timer=null,this.connect()},l)}onMessage(s){let n;try{n=JSON.parse(String(s))}catch{return}if(typeof n!="object"||n===null)return;const a=n;if(a.t==="state"){const l=this.snap.connection==="connected";this.snap={...this.snap,connection:"connected",reconnectAttempt:0,status:a.state,pet:a.pet,lanes:bc(this.snap.lanes,a.lanes)},this.reconnectAttempt=0,l||(this.snap={...this.snap,lastClose:null},this.flushReplayOps(),this.flushQueuedSetMode()),this.notify();return}if(a.t==="history"){const l=a;if(typeof l.sid=="string"&&l.sid!==""){this.snap={...this.snap,lanes:yc(this.snap.lanes,l.sid,l.entries,l.reset===!0)},this.notify();return}const r=l.reset===!0?[...l.entries]:[...this.snap.history,...l.entries];this.snap={...this.snap,connection:"connected",history:r,...l.reset===!0?{historyEpoch:this.snap.historyEpoch+1}:{}},this.notify();return}if(a.t==="event"){const l=a;if(l.event!==void 0)for(const r of[...this.loopListeners])r(l.event,typeof l.at=="number"?l.at:Date.now());return}if(a.t==="probe"){const l=a.event;if(l!==void 0)for(const r of[...this.probeListeners])r(l);return}if(a.t==="result"){const l=a,r=this.pendingOps.get(l.id);if(r===void 0)return;this.pendingOps.delete(l.id),typeof l.err=="string"?r.reject(new Error(l.err)):r.resolve(l.ok);return}}failPending(s){for(const[,n]of this.pendingOps)n.reject(s);this.pendingOps.clear()}sendOp(s){return new Promise((n,a)=>{if(this.ws===null||this.ws.readyState!==bn){a(new Error("not connected"));return}const l=this.nextId++;this.pendingOps.set(l,{resolve:n,reject:a,...Cc(s)?{replay:s}:{}}),this.ws.send(JSON.stringify({t:"op",id:l,op:s,cid:this.clientId}))})}flushReplayOps(){for(;this.replayQueue.length>0;){const s=this.replayQueue[0];if(s===void 0||this.ws===null||this.ws.readyState!==bn)return;this.replayQueue.shift(),this.ws.send(JSON.stringify({t:"op",id:s.id,op:s.op,cid:this.clientId}))}}submit(s,n){return this.sendOp({op:"submit",text:s,...n?.plan===!0?{plan:!0}:{},...n?.expand===!1?{expand:!1}:{},...n?.images!==void 0&&n.images.length>0?{images:n.images}:{},...n?.files!==void 0&&n.files.length>0?{files:n.files}:{},...n?.sid!==void 0?{sid:n.sid}:{}})}interrupt(s){return this.sendOp({op:"interrupt",...s!==void 0?{sid:s}:{}})}setMode(s,n){return n===void 0&&(this.ws===null||this.ws.readyState!==bn||this.snap.connection!=="connected")?(this.queuedSetMode=s,Promise.resolve(!0)):this.sendOp({op:"setMode",mode:s,...n!==void 0?{sid:n}:{}})}flushQueuedSetMode(){if(this.queuedSetMode===null)return;const s=this.queuedSetMode;this.queuedSetMode=null,this.sendOp({op:"setMode",mode:s}).catch(()=>{})}answerPermission(s,n,a){return this.sendOp({op:"answerPermission",allow:s,...n!==void 0?{reason:n}:{},...a!==void 0?{scope:a}:{}})}recallSteer(s,n){return this.sendOp({op:"recallSteer",index:s,text:n})}answerAskUser(s){return this.sendOp({op:"answerAskUser",...s!==void 0?{answer:s}:{}})}detachToolCall(s){return this.sendOp({op:"detachToolCall",...s!==void 0?{callId:s}:{}})}petSubmit(s){return this.sendOp({op:"petSubmit",text:s})}petInterrupt(){return this.sendOp({op:"petInterrupt"})}petAnswerPermission(s,n,a){return this.sendOp({op:"petAnswerPermission",allow:s,...n!==void 0?{reason:n}:{},...a!==void 0?{scope:a}:{}})}petHistory(){return this.sendOp({op:"petHistory"})}petNewSession(){return this.sendOp({op:"petNewSession"})}petSetModel(s,n,a){return this.sendOp({op:"petSetModel",provider:s,...n!==void 0?{model:n}:{},...a!==void 0?{effort:a}:{}})}petSetEffort(s){return this.sendOp({op:"petSetEffort",effort:s})}petSetWorkspace(s){return this.sendOp({op:"petSetWorkspace",path:s})}listSlashCommands(){return this.sendOp({op:"listSlashCommands"})}sessions(){return this.sendOp({op:"sessions"})}sessionSearch(s){return this.sendOp({op:"sessionSearch",q:s})}sessionDelete(s){return this.sendOp({op:"sessionDelete",id:s})}sessionTrashList(){return this.sendOp({op:"sessionTrashList"})}sessionRestore(s){return this.sendOp({op:"sessionRestore",id:s})}sessionContinue(s){return this.sendOp({op:"sessionContinue",id:s})}schedulesList(){return this.sendOp({op:"schedulesList"})}schedulesSetEnabled(s,n){return this.sendOp({op:"schedulesSetEnabled",id:s,enabled:n})}schedulesRemove(s){return this.sendOp({op:"schedulesRemove",id:s})}schedulesRunNow(s,n){return this.sendOp({op:"schedulesRunNow",id:s,...n?.resetBreaker===!0?{resetBreaker:!0}:{}})}resume(s,n){return this.sendOp({op:"resume",id:s,...n!==void 0?{sid:n}:{}})}resumeFork(s){return this.sendOp({op:"resume",id:s,fork:!0})}rewind(s){return this.sendOp({op:"rewind",target:s})}edit(s){return this.sendOp({op:"edit",n:s})}tree(){return this.sendOp({op:"tree"})}switchBranch(s){return this.sendOp({op:"switch",...s!==void 0?{n:s}:{}})}disarmEdit(){return this.sendOp({op:"edit",n:0})}branchLeaves(){return this.sendOp({op:"branchLeaves"})}memoryList(){return this.sendOp({op:"memoryList"})}memoryDecide(s,n){return this.sendOp({op:"memoryDecide",id:s,action:n})}memoryEdit(s,n){return this.sendOp({op:"memoryEdit",id:s,content:n})}improvementFace(s,n){return this.sendOp({op:"improvementFace",action:s,...n!==void 0?{id:n}:{}})}settingsStatus(){return this.sendOp({op:"settingsStatus"})}settingsSaveKey(s,n){return this.sendOp({op:"settingsSaveKey",provider:s,key:n})}settingsTestConnection(s,n){return this.sendOp({op:"settingsTestConnection",provider:s,...n?.key!==void 0?{key:n.key}:{},...n?.model!==void 0?{model:n.model}:{}})}settingsSet(s,n){return this.sendOp({op:"settingsSet",key:s,value:n})}settingsSaveProvider(s,n){return this.sendOp({op:"settingsSaveProvider",id:s,config:n})}settingsDeleteProvider(s){return this.sendOp({op:"settingsDeleteProvider",id:s})}settingsListModels(s,n){return this.sendOp({op:"settingsListModels",provider:s,...n?.key!==void 0?{key:n.key}:{}})}recentWorkspaces(s){return this.sendOp({op:"recentWorkspaces",...s!==void 0?{add:s}:{}})}switchWorkspace(s){return this.sendOp({op:"switchWorkspace",path:s})}fileTree(s){return this.sendOp({op:"fileTree",path:s})}fileRead(s){return this.sendOp({op:"fileRead",path:s})}fileWrite(s,n,a){return this.sendOp({op:"fileWrite",path:s,content:n,base:a})}fileRevert(s,n){return this.sendOp({op:"fileRevert",path:s,sha:n})}sideQuestion(s,n){return this.sendOp({op:"sideQuestion",sessionId:s,text:n})}panelRootSet(s){return this.sendOp({op:"panelRootSet",path:s})}agentRootStatus(){return this.sendOp({op:"agentRootStatus"})}probeStream(s){return this.sendOp({op:"probeStream",...s!==void 0?{cat:s}:{}})}probeRecent(s,n){return this.sendOp({op:"probeRecent",...s!==void 0?{cat:s}:{},...n!==void 0?{limit:n}:{}})}probeStats(){return this.sendOp({op:"probeStats"})}probeEnable(s){return this.sendOp({op:"probeEnable",on:s})}onProbe(s){return this.probeListeners.add(s),()=>this.probeListeners.delete(s)}sessionAnatomy(){return this.sendOp({op:"sessionAnatomy"})}onLoopEvent(s){return this.loopListeners.add(s),()=>this.loopListeners.delete(s)}agentRootSwitch(s){return this.sendOp({op:"agentRootSwitch",path:s})}ctxInfo(){return this.sendOp({op:"ctxInfo"})}recap(s,n,a){return this.sendOp({op:"recap",sessionId:s,sinceMark:n,...a!==void 0?{sinceTs:a}:{}})}recoveryStatus(){return this.sendOp({op:"recoveryStatus"})}attachmentSave(s){return this.sendOp({op:"attachmentSave",inputs:s})}attachmentGet(s){return this.sendOp({op:"attachmentGet",ref:s})}fileSave(s){return this.sendOp({op:"fileSave",inputs:s})}pluginList(){return this.sendOp({op:"pluginList"})}mcpList(){return this.sendOp({op:"mcpList"})}pluginMarketList(){return this.sendOp({op:"pluginMarketList"})}pluginMarketAdd(s,n){return this.sendOp({op:"pluginMarketAdd",source:s,...n!==void 0?{name:n}:{}})}pluginMarketUpdate(s){return this.sendOp({op:"pluginMarketUpdate",name:s})}pluginMarketRemove(s){return this.sendOp({op:"pluginMarketRemove",name:s})}pluginInstall(s,n,a){return this.sendOp({op:"pluginInstall",name:s,market:n,scope:a})}longtermMemoryList(){return this.sendOp({op:"longtermMemoryList"})}longtermMemoryForget(s){return this.sendOp({op:"longtermMemoryForget",id:s})}pluginInstallSpec(s,n){return this.sendOp({op:"pluginInstallSpec",spec:s,...n===!0?{preview:!0}:{}})}pluginUninstall(s){return this.sendOp({op:"pluginUninstall",id:s})}pluginEnable(s){return this.sendOp({op:"pluginEnable",id:s})}pluginDisable(s){return this.sendOp({op:"pluginDisable",id:s})}personaList(){return this.sendOp({op:"personaList"})}personaGet(s){return this.sendOp({op:"personaGet",id:s})}personaSave(s){return this.sendOp({op:"personaSave",definition:s})}personaDelete(s){return this.sendOp({op:"personaDelete",id:s.id,...s.unbind===!0?{unbind:!0}:{}})}}function Mc(t,s){return n=>{t.detachToolCall(n).then(a=>{a.kind==="refused"&&s(a.reason==="not_detachable"?`⏳ ${a.toolName??"该工具"} 不可转后台(不可中断族)——等待其结束,或停止整个运行`:"(这条调用刚好已结束——无需转后台)")}).catch(()=>{})}}function zs(){return document.documentElement.dataset.theme==="light"?"light":"dark"}function vt(t){document.documentElement.dataset.theme=t,localStorage.setItem("wudao.ui.theme",t),fr(To,{theme:t}),document.documentElement.classList.contains("glass")&&Mo(t)}function _n(){const t=document.documentElement.dataset.accent;return t==="black"||t==="blue"||t==="green"?t:"green"}function ss(t){document.documentElement.dataset.accent=t,localStorage.setItem("wudao.ui.accent",t)}function Tc(){return localStorage.getItem("wudao.ui.theme")==="light"?"light":"dark"}function Dc(){const t=localStorage.getItem("wudao.ui.accent");return t==="black"||t==="blue"||t==="green"?t:"green"}function Ac(){vt(Tc()),ss(Dc())}const Rs="─",Oc=" │ ",Fn=1;function Cr(t){return(t??[]).some(s=>s.status==="ready")}function Ic(t){return Cr(t.providers)?!1:t.wizardCompletedVersion<(t.copyVersion??Fn)}function Lc(t){return i.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}const dl=16,Er=8,Pc=6,_c=4,$r=8,Fc=3,zc=1,Bc=64,Kc=4,Wc=1e3,Uc=.95,Hc=t=>t===47||t===92||t===45||t===95||t===46||t===32,qc=t=>t>=97&&t<=122,Gc=t=>t>=65&&t<=90;function ul(t,s,n){if(s===0)return n?$r:0;const a=t.charCodeAt(s-1);return Hc(a)?Er:qc(a)&&Gc(t.charCodeAt(s))?Pc:0}function Vc(t,s){const n=t.paths[s].toLowerCase();t.lowerPaths[s]=n;let a=0;for(let l=0;l<n.length;l++){const r=n.charCodeAt(l);r>=97&&r<=122&&(a|=1<<r-97)}t.charBits[s]=a}const Rr=new WeakMap;function Yc(t,s={}){const n=s.chunkMs??Kc,a=s.now??(()=>performance.now()),l=s.schedule??(async()=>{await new Promise(p=>setTimeout(p,0))}),r={paths:[],lowerPaths:[],charBits:new Int32Array(0),ready:0},o={get size(){return r.ready}};Rr.set(o,r);let c=()=>{};const d=new Promise(p=>{c=p}),m=(async()=>{const p=new Set,g=[];let v=a();for(let S=0;S<t.length;S++){const R=t[S];R.length>0&&!p.has(R)&&(p.add(R),g.push(R)),(S&255)===255&&a()-v>n&&(await l(),v=a())}r.paths=g,r.lowerPaths=new Array(g.length),r.charBits=new Int32Array(g.length),v=a();let N=!0;for(let S=0;S<g.length;S++)Vc(r,S),(S&255)===255&&a()-v>n&&(r.ready=S+1,N&&(c(),N=!1),await l(),v=a());r.ready=g.length,c()})();return{index:o,queryable:d,done:m,readyCount:()=>r.ready}}function Xc(t,s,n){if(s.length===0)return[];const a=Rr.get(t),l=a.ready,r=s!==s.toLowerCase(),o=r?s:s.toLowerCase(),c=Math.min(o.length,Bc);let d=0;for(let g=0;g<c;g++){const v=o.charCodeAt(g);v>=97&&v<=122&&(d|=1<<v-97)}const m=[];let p=-1/0;e:for(let g=0;g<l;g++){if((a.charBits[g]&d)!==d)continue;const v=r?a.paths[g]:a.lowerPaths[g];let N=v.indexOf(o.charAt(0));if(N===-1)continue;const S=[N];let R=0,j=0,f=N;for(let D=1;D<c;D++){if(N=v.indexOf(o.charAt(D),f+1),N===-1)continue e;S.push(N);const V=N-f-1;V===0?j+=_c:R+=Fc+V*zc,f=N}const A=c*(dl+Er)+$r+32;if(m.length===n&&A+j-R<=p)continue;const $=a.paths[g];let y=c*dl+j-R;y+=ul($,S[0],!0);for(let D=1;D<c;D++)y+=ul($,S[D],!1);y+=Math.max(0,32-($.length>>2)),S[0]<$.lastIndexOf("/")+1&&(y-=Wc),$.includes("test")&&(y*=Uc),m.length<n?(m.push({path:$,hits:new Set(S),fuzzScore:y}),m.length===n&&(m.sort((D,V)=>V.fuzzScore-D.fuzzScore||(D.path<V.path?-1:1)),p=m[m.length-1].fuzzScore)):y>p&&(m.push({path:$,hits:new Set(S),fuzzScore:y}),m.sort((D,V)=>V.fuzzScore-D.fuzzScore||(D.path<V.path?-1:1)),m.pop(),p=m[m.length-1].fuzzScore)}return m.sort((g,v)=>v.fuzzScore-g.fuzzScore||(g.path<v.path?-1:1)),m.map(({path:g,hits:v,fuzzScore:N})=>({path:g,hits:v,score:N}))}function tt(){i.useEffect(()=>{const t=document.activeElement;return()=>{t?.focus?.()}},[])}const Jc=200,Qc=80;function Zc(){try{return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Mr(t){const[s,n]=i.useState(!1),a=i.useRef(!0),l=i.useCallback(()=>{const o=t.current;if(o===null)return;const c=o.scrollHeight-o.scrollTop-o.clientHeight;a.current=c<Qc,n(c>Jc)},[t]);i.useEffect(()=>{const o=t.current;a.current&&o!==null&&typeof o.scrollTo=="function"&&o.scrollTo({top:o.scrollHeight})});const r=i.useCallback(()=>{const o=t.current;o!==null&&(typeof o.scrollTo=="function"&&o.scrollTo({top:o.scrollHeight,behavior:Zc()?"auto":"smooth"}),n(!1))},[t]);return{onScroll:l,jump:r,show:s}}function Tr({show:t,onJump:s}){return t?e.jsx("button",{type:"button",className:"jump-bottom","aria-label":"回到底部",title:"回到底部",onClick:s,children:"↓"}):null}const hl="(该命令由插件/扩展实现 —— WS 协议 v1 无法在此展开;请使用 TUI 或 /help)",ed="工作区",yn=()=>typeof window<"u"&&window.innerWidth<900,Nn=["描述任务,或 /help 查看命令","@ 可引用文件","拖入图片直接发送","shift+tab 切换权限档"];let ml=0;function pl(t){return t==="ask"?"ask(每个工具执行前都会确认)":t==="workspace"?"accept(默认:工作区内读写与只读命令放行,其余命令/网络/MCP 仍确认)":t==="auto"?"auto(全自动:全部放行,不再询问)":"plan(只读探查:只放行读取与只读命令;完成方案后切回 accept/auto 执行)"}function td(){const t=Nn[ml%Nn.length]??Nn[0];return ml+=1,t}const kn=()=>typeof window<"u"&&window.innerWidth<700,sd=260,As=180,Os=()=>Math.floor(window.innerWidth*.4);function ot(t){return Math.min(Math.max(t,As),Os())}const fl=220,xl=360,nd=320,zn=10;function xt(t){return t.split("/").filter(s=>s!=="").slice(-1)[0]??t}function ad(t){return t.kind==="tool"&&(t.name==="write_file"||t.name==="edit_file")}const ld=50,rd=20;function id(t,s){const n=[];let a=0;for(const l of t)n.push({ch:l,hit:s.has(a)}),a+=l.length;return n}const vl=50,od=/^(.*) ×(\d+)$/;function cd(t,s,n,a){const l=t[t.length-1];if(l!==void 0){const o=od.exec(l.text),c=o!==null?o[1]??"":l.text;if(c===s){const d=o!==null?Number(o[2]??"1")+1:2;return[...t.slice(0,-1),{text:`${c} ×${d}`,after:n,epoch:l.epoch}]}}const r=[...t,{text:s,after:n,epoch:a}];return r.length>vl?r.slice(r.length-vl):r}function dd(t,s){if(s.length===0)return t;const n=[];let a=0;for(let l=0;l<t.length;l++){for(;a<s.length;){const o=s[a];if(o===void 0||o.after>l)break;n.push({kind:"notice",text:o.text}),a+=1}const r=t[l];r!==void 0&&n.push(r)}for(;a<s.length;a++){const l=s[a];l!==void 0&&n.push({kind:"notice",text:l.text})}return n}const Dr="wudao.ui.v1";function ud(){try{const t=window.localStorage.getItem(Dr);if(t===null)return{};const s=JSON.parse(t);return typeof s=="object"&&s!==null?s:{}}catch{return{}}}function gl(t){return Array.isArray(t.tabs)?t.tabs.filter(s=>typeof s=="object"&&s!==null&&typeof s.path=="string"&&s.path!==""&&typeof s.isDir=="boolean").slice(0,zn).map(s=>({path:s.path,name:xt(s.path),isDir:s.isDir})):[]}function hd({getAllKnownPaths:t,onOpenPath:s,onClose:n}){const[a,l]=i.useState(""),[r,o]=i.useState(0),c=i.useRef(null),d=i.useRef({composing:!1,endedAt:0}),[m,p]=i.useState(0),g=i.useRef(null),v=()=>{const j=t(),f=g.current;if(f!==null&&f.source===j)return f.build;const A=Yc(j);return g.current={source:j,build:A},A.readyCount()<j.length&&(A.queryable.then(()=>p($=>$+1)),A.done.then(()=>p($=>$+1))),A},N=i.useId();tt(),i.useEffect(()=>{c.current?.focus()},[]);const S=i.useMemo(()=>{const j=a.trim();return j===""?t().slice(0,ld).map(f=>({path:f,hits:new Set})):Xc(v().index,j,rd)},[a,m]),R=j=>{l(j),o(0)};return e.jsx("div",{className:"search-scrim",onClick:n,children:e.jsxs("div",{className:"search-pop",role:"dialog","aria-label":"文件搜索",onClick:j=>j.stopPropagation(),children:[e.jsx("div",{className:"session-head",children:"文件搜索 — ↑↓ 选择 · Enter 打开 · Esc 关闭"}),e.jsx("input",{ref:c,className:"search-input",type:"text",placeholder:"搜索文件…","aria-label":"搜索文件",value:a,onChange:j=>R(j.target.value),onCompositionStart:()=>{d.current=He(d.current)},onCompositionEnd:()=>{d.current=_e(d.current,Date.now())},onKeyDown:j=>{if(!Ue(j.nativeEvent,d.current,Date.now())){if(j.key==="Escape"){j.preventDefault(),n();return}if(j.key==="ArrowDown"){j.preventDefault(),o(f=>Math.min(f+1,S.length-1));return}if(j.key==="ArrowUp"){j.preventDefault(),o(f=>Math.max(f-1,0));return}if(j.key==="Enter"){j.preventDefault();const f=S[r];f!==void 0&&s(f.path)}}}}),e.jsx("div",{className:"search-results",role:"listbox","aria-activedescendant":S[r]!==void 0?`${N}-opt-${r}`:void 0,children:S.length===0?e.jsx("div",{className:"search-empty",children:"无匹配文件"}):S.map((j,f)=>e.jsx("div",{id:`${N}-opt-${f}`,className:`search-item${f===r?" sel":""}`,role:"option","aria-selected":f===r,"data-path":j.path,onClick:()=>s(j.path),children:id(j.path,j.hits).map(({ch:A,hit:$},y)=>$?e.jsx("span",{className:"hit",children:A},y):e.jsx("span",{children:A},y))},j.path))})]})})}function md(t){const[s,n]=i.useState(null),a=t.lanes,l=s!==null&&a!==void 0?a[s]:void 0,r=l===void 0,o=t.status;return{view:{capable:a!==void 0,viewingMain:r,sid:r?null:s,key:r?o?.sessionId??"":l.sessionId,sessionId:r?o?.sessionId??null:l.sessionId,busy:r?o?.busy??!1:l.busy,history:r?t.history:l.history,historyEpoch:r?t.historyEpoch:l.historyEpoch},viewLane:s,setViewLane:n}}const jl={notes:[],armedEdit:null,forkBadges:new Set,forkEcho:null};function pd(){const[t,s]=i.useState({}),n=i.useCallback((m,p)=>{m!==""&&s(g=>({...g,[m]:p(g[m]??jl)}))},[]),a=i.useCallback(m=>t[m]??jl,[t]),l=i.useCallback((m,p,g,v)=>{n(m,N=>({...N,notes:cd(N.notes,p,g,v)}))},[n]),r=i.useCallback((m,p)=>{n(m,g=>({...g,notes:g.notes.filter(p)}))},[n]),o=i.useCallback((m,p)=>{n(m,g=>({...g,armedEdit:p}))},[n]),c=i.useCallback((m,p)=>{n(m,g=>({...g,forkBadges:p}))},[n]),d=i.useCallback((m,p)=>{n(m,g=>({...g,forkEcho:p}))},[n]);return i.useMemo(()=>({slots:t,slot:a,stampNote:l,filterNotes:r,setArmedEdit:o,setForkBadges:c,setForkEcho:d}),[t,a,l,r,o,c,d])}function fd(t,s){if(s===void 0)return;const n=new Set;t!==null&&t.busy&&t.sessionId!==""&&n.add(t.sessionId);for(const a of Object.values(s))a.busy&&a.sessionId!==""&&n.add(a.sessionId);return n}function xd(t,s,n){if(n===(t?.sessionId??null))return{kind:"view-main"};if(s!==void 0){for(const[a,l]of Object.entries(s))if(l.sessionId===n)return{kind:"view-lane",laneId:a}}return{kind:"open-lane",laneId:jc()}}const vd=`<!-- @license lucide-static v1.48.0 - ISC -->
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ viewBox="0 0 24 24"
5
+ fill="none"
6
+ stroke="currentColor"
7
+ stroke-width="1.5"
8
+ stroke-linecap="round"
9
+ stroke-linejoin="round"
10
+ >
11
+ <path d="M5 22h14" />
12
+ <path d="M5 2h14" />
13
+ <path d="M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22" />
14
+ <path d="M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2" />
15
+ </svg>
16
+ `,gd=`<!-- @license lucide-static v1.48.0 - ISC -->
17
+ <svg
18
+ xmlns="http://www.w3.org/2000/svg"
19
+ viewBox="0 0 24 24"
20
+ fill="none"
21
+ stroke="currentColor"
22
+ stroke-width="1.5"
23
+ stroke-linecap="round"
24
+ stroke-linejoin="round"
25
+ >
26
+ <path d="M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z" />
27
+ </svg>
28
+ `,jd=`<!-- @license lucide-static v1.48.0 - ISC -->
29
+ <svg
30
+ xmlns="http://www.w3.org/2000/svg"
31
+ viewBox="0 0 24 24"
32
+ fill="none"
33
+ stroke="currentColor"
34
+ stroke-width="1.5"
35
+ stroke-linecap="round"
36
+ stroke-linejoin="round"
37
+ >
38
+ <circle cx="12" cy="12" r="10" />
39
+ <path d="M12 6v6l4 2" />
40
+ </svg>
41
+ `,bd=`<!-- @license lucide-static v1.48.0 - ISC -->
42
+ <svg
43
+ xmlns="http://www.w3.org/2000/svg"
44
+ viewBox="0 0 24 24"
45
+ fill="none"
46
+ stroke="currentColor"
47
+ stroke-width="1.5"
48
+ stroke-linecap="round"
49
+ stroke-linejoin="round"
50
+ >
51
+ <rect width="8" height="4" x="8" y="2" rx="1" ry="1" />
52
+ <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />
53
+ <path d="M12 11h4" />
54
+ <path d="M12 16h4" />
55
+ <path d="M8 11h.01" />
56
+ <path d="M8 16h.01" />
57
+ </svg>
58
+ `,yd=`<!-- @license lucide-static v1.48.0 - ISC -->
59
+ <svg
60
+ xmlns="http://www.w3.org/2000/svg"
61
+ viewBox="0 0 24 24"
62
+ fill="none"
63
+ stroke="currentColor"
64
+ stroke-width="1.5"
65
+ stroke-linecap="round"
66
+ stroke-linejoin="round"
67
+ >
68
+ <path d="m2 21 9.6-9.6" />
69
+ <path d="m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19" />
70
+ <circle cx="15.5" cy="7.5" r="5.5" />
71
+ </svg>
72
+ `,Nd=`<!-- @license lucide-static v1.48.0 - ISC -->
73
+ <svg
74
+ xmlns="http://www.w3.org/2000/svg"
75
+ viewBox="0 0 24 24"
76
+ fill="none"
77
+ stroke="currentColor"
78
+ stroke-width="1.5"
79
+ stroke-linecap="round"
80
+ stroke-linejoin="round"
81
+ >
82
+ <path d="M20 4v7a4 4 0 0 1-4 4H4" />
83
+ <path d="m9 10-5 5 5 5" />
84
+ </svg>
85
+ `,kd=`<!-- @license lucide-static v1.48.0 - ISC -->
86
+ <svg
87
+ xmlns="http://www.w3.org/2000/svg"
88
+ viewBox="0 0 24 24"
89
+ fill="none"
90
+ stroke="currentColor"
91
+ stroke-width="1.5"
92
+ stroke-linecap="round"
93
+ stroke-linejoin="round"
94
+ >
95
+ <circle cx="12" cy="12" r="10" />
96
+ <path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" />
97
+ <path d="M12 17h.01" />
98
+ </svg>
99
+ `,wd=`<!-- @license lucide-static v1.48.0 - ISC -->
100
+ <svg
101
+ xmlns="http://www.w3.org/2000/svg"
102
+ viewBox="0 0 24 24"
103
+ fill="none"
104
+ stroke="currentColor"
105
+ stroke-width="1.5"
106
+ stroke-linecap="round"
107
+ stroke-linejoin="round"
108
+ >
109
+ <rect width="18" height="18" x="3" y="3" rx="2" ry="2" />
110
+ <circle cx="9" cy="9" r="2" />
111
+ <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
112
+ </svg>
113
+ `,Sd=`<!-- @license lucide-static v1.48.0 - ISC -->
114
+ <svg
115
+ xmlns="http://www.w3.org/2000/svg"
116
+ viewBox="0 0 24 24"
117
+ fill="none"
118
+ stroke="currentColor"
119
+ stroke-width="1.5"
120
+ stroke-linecap="round"
121
+ stroke-linejoin="round"
122
+ >
123
+ <path d="M12 18V5" />
124
+ <path d="M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4" />
125
+ <path d="M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5" />
126
+ <path d="M17.997 5.125a4 4 0 0 1 2.526 5.77" />
127
+ <path d="M18 18a4 4 0 0 0 2-7.464" />
128
+ <path d="M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517" />
129
+ <path d="M6 18a4 4 0 0 1-2-7.464" />
130
+ <path d="M6.003 5.125a4 4 0 0 0-2.526 5.77" />
131
+ </svg>
132
+ `,Cd=`<!-- @license lucide-static v1.48.0 - ISC -->
133
+ <svg
134
+ xmlns="http://www.w3.org/2000/svg"
135
+ viewBox="0 0 24 24"
136
+ fill="none"
137
+ stroke="currentColor"
138
+ stroke-width="1.5"
139
+ stroke-linecap="round"
140
+ stroke-linejoin="round"
141
+ >
142
+ <path d="M5.8 11.3 2 22l10.7-3.79" />
143
+ <path d="M4 3h.01" />
144
+ <path d="M22 8h.01" />
145
+ <path d="M15 2h.01" />
146
+ <path d="M22 20h.01" />
147
+ <path d="m22 2-2.24.75a2.9 2.9 0 0 0-1.96 3.12c.1.86-.57 1.63-1.45 1.63h-.38c-.86 0-1.6.6-1.76 1.44L14 10" />
148
+ <path d="m22 13-.82-.33c-.86-.34-1.82.2-1.98 1.11c-.11.7-.72 1.22-1.43 1.22H17" />
149
+ <path d="m11 2 .33.82c.34.86-.2 1.82-1.11 1.98C9.52 4.9 9 5.52 9 6.23V7" />
150
+ <path d="M11 13c1.93 1.93 2.83 4.17 2 5-.83.83-3.07-.07-5-2-1.93-1.93-2.83-4.17-2-5 .83-.83 3.07.07 5 2Z" />
151
+ </svg>
152
+ `,Ed=`<!-- @license lucide-static v1.48.0 - ISC -->
153
+ <svg
154
+ xmlns="http://www.w3.org/2000/svg"
155
+ viewBox="0 0 24 24"
156
+ fill="none"
157
+ stroke="currentColor"
158
+ stroke-width="1.5"
159
+ stroke-linecap="round"
160
+ stroke-linejoin="round"
161
+ >
162
+ <path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z" />
163
+ </svg>
164
+ `,$d=`<!-- @license lucide-static v1.48.0 - ISC -->
165
+ <svg
166
+ xmlns="http://www.w3.org/2000/svg"
167
+ viewBox="0 0 24 24"
168
+ fill="none"
169
+ stroke="currentColor"
170
+ stroke-width="1.5"
171
+ stroke-linecap="round"
172
+ stroke-linejoin="round"
173
+ >
174
+ <path d="M3 3v16a2 2 0 0 0 2 2h16" />
175
+ <path d="M18 17V9" />
176
+ <path d="M13 17V5" />
177
+ <path d="M8 17v-3" />
178
+ </svg>
179
+ `,Rd=`<!-- @license lucide-static v1.48.0 - ISC -->
180
+ <svg
181
+ xmlns="http://www.w3.org/2000/svg"
182
+ viewBox="0 0 24 24"
183
+ fill="none"
184
+ stroke="currentColor"
185
+ stroke-width="1.5"
186
+ stroke-linecap="round"
187
+ stroke-linejoin="round"
188
+ >
189
+ <rect width="18" height="18" x="3" y="3" rx="2" />
190
+ <path d="M7 3v18" />
191
+ <path d="M3 7.5h4" />
192
+ <path d="M3 12h18" />
193
+ <path d="M3 16.5h4" />
194
+ <path d="M17 3v18" />
195
+ <path d="M17 7.5h4" />
196
+ <path d="M17 16.5h4" />
197
+ </svg>
198
+ `,Md=`<!-- @license lucide-static v1.48.0 - ISC -->
199
+ <svg
200
+ xmlns="http://www.w3.org/2000/svg"
201
+ viewBox="0 0 24 24"
202
+ fill="none"
203
+ stroke="currentColor"
204
+ stroke-width="1.5"
205
+ stroke-linecap="round"
206
+ stroke-linejoin="round"
207
+ >
208
+ <path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
209
+ <path d="M14 2v5a1 1 0 0 0 1 1h5" />
210
+ <path d="M10 9H8" />
211
+ <path d="M16 13H8" />
212
+ <path d="M16 17H8" />
213
+ </svg>
214
+ `,Td=`<!-- @license lucide-static v1.48.0 - ISC -->
215
+ <svg
216
+ xmlns="http://www.w3.org/2000/svg"
217
+ viewBox="0 0 24 24"
218
+ fill="none"
219
+ stroke="currentColor"
220
+ stroke-width="1.5"
221
+ stroke-linecap="round"
222
+ stroke-linejoin="round"
223
+ >
224
+ <path d="M10 11v6" />
225
+ <path d="M14 11v6" />
226
+ <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
227
+ <path d="M3 6h18" />
228
+ <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
229
+ </svg>
230
+ `,Dd=`<!-- @license lucide-static v1.48.0 - ISC -->
231
+ <svg
232
+ xmlns="http://www.w3.org/2000/svg"
233
+ viewBox="0 0 24 24"
234
+ fill="none"
235
+ stroke="currentColor"
236
+ stroke-width="1.5"
237
+ stroke-linecap="round"
238
+ stroke-linejoin="round"
239
+ >
240
+ <path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" />
241
+ </svg>
242
+ `,Ad=`<!-- @license lucide-static v1.48.0 - ISC -->
243
+ <svg
244
+ xmlns="http://www.w3.org/2000/svg"
245
+ viewBox="0 0 24 24"
246
+ fill="none"
247
+ stroke="currentColor"
248
+ stroke-width="1.5"
249
+ stroke-linecap="round"
250
+ stroke-linejoin="round"
251
+ >
252
+ <path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" />
253
+ <path d="m14.5 9.5-5 5" />
254
+ <path d="m9.5 9.5 5 5" />
255
+ </svg>
256
+ `,Od=`<!-- @license lucide-static v1.48.0 - ISC -->
257
+ <svg
258
+ xmlns="http://www.w3.org/2000/svg"
259
+ viewBox="0 0 24 24"
260
+ fill="none"
261
+ stroke="currentColor"
262
+ stroke-width="1.5"
263
+ stroke-linecap="round"
264
+ stroke-linejoin="round"
265
+ >
266
+ <path d="M13 5h8" />
267
+ <path d="M13 12h8" />
268
+ <path d="M13 19h8" />
269
+ <path d="m3 17 2 2 4-4" />
270
+ <path d="m3 7 2 2 4-4" />
271
+ </svg>
272
+ `,Id=`<!-- @license lucide-static v1.48.0 - ISC -->
273
+ <svg
274
+ xmlns="http://www.w3.org/2000/svg"
275
+ viewBox="0 0 24 24"
276
+ fill="none"
277
+ stroke="currentColor"
278
+ stroke-width="1.5"
279
+ stroke-linecap="round"
280
+ stroke-linejoin="round"
281
+ >
282
+ <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" />
283
+ <path d="M12 9v4" />
284
+ <path d="M12 17h.01" />
285
+ </svg>
286
+ `,bl=.9,yl={hourglass:vd,zap:gd,clock:jd,"clipboard-list":bd,key:yd,"corner-down-left":Nd,"circle-help":kd,image:wd,brain:Sd,"party-popper":Cd,star:Ed,"chart-column":$d,film:Rd,"file-text":Md,"trash-2":Td,shield:Dd,"shield-x":Ad,"list-checks":Od,"triangle-alert":Id};// 留 inner 标记 + viewBox。注意定位必须从 "<svg" 起步——文件头有 @license
287
+ const Ld=t=>{const s=t.indexOf("<svg"),n=t.indexOf(">",s),a=t.lastIndexOf("</svg>"),l=/viewBox="([^"]+)"/.exec(t)?.[1]??"0 0 24 24",r=t.slice(n+1,a).replace(/>\s+</g,"><").trim();return{viewBox:l,inner:r}},Pd=Object.fromEntries(Object.keys(yl).map(t=>[t,Ld(yl[t])]));function ae({name:t,size:s=16,className:n,filled:a=!1}){const{viewBox:l,inner:r}=Pd[t];return e.jsx("svg",{width:(s??16)*bl,height:(s??16)*bl,viewBox:l,fill:a?"currentColor":"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,className:n===void 0?"ic":`ic ${n}`,dangerouslySetInnerHTML:{__html:r}})}const Ar="wudao.archive.v1";function Or(){try{const t=window.localStorage.getItem(Ar);if(t===null)return[];const s=JSON.parse(t);return typeof s!="object"||s===null||!Array.isArray(s.archived)?[]:s.archived.filter(n=>typeof n=="string")}catch{return[]}}function Ir(t){try{window.localStorage.setItem(Ar,JSON.stringify({archived:t}))}catch{}}function Nl(t){const s=Or(),n=s.includes(t)?s.filter(a=>a!==t):[...s,t];return Ir(n),n}const Lr="wudao.unread.v1",Bn=30;function _d(){try{const t=window.localStorage.getItem(Lr);if(t===null)return{};const s=JSON.parse(t);if(typeof s!="object"||s===null||typeof s.marks!="object"||s.marks===null||Array.isArray(s.marks))return{};const n={};for(const[a,l]of Object.entries(s.marks))typeof l=="number"&&Number.isFinite(l)&&l>=0&&(n[a]=l);return n}catch{return{}}}function Fd(t){const s=Object.entries(t),n={};for(const[a,l]of s.length>Bn?s.slice(s.length-Bn):s)n[a]=l;try{window.localStorage.setItem(Lr,JSON.stringify({marks:n}))}catch{}return n}const zd=50,Ms=48,kl=6e4,wl=36e5,gt=864e5;function Sl(t,s=Date.now()){const n=new Date(t).getTime();if(Number.isNaN(n))return"";const a=s-n;return a<kl?"刚刚":a<wl?`${Math.floor(a/kl)}分钟前`:a<gt?`${Math.floor(a/wl)}小时前`:a<2*gt?"昨天":a<7*gt?`${Math.floor(a/gt)}天前`:new Date(n).toISOString().slice(0,10)}function Pr(t){return(t.firstUser.split(`
288
+ `)[0]??"").replace(/\s+/g," ").trim()}function jt(t){if(t.lane==="pet")return"小精灵";const s=(t.name??"").trim();if(s!=="")return s;const n=Pr(t);if(n!==""){const a=Array.from(n);return a.length>16?`${a.slice(0,16).join("")}…`:n}return t.id.slice(0,8)}function Is(t){const s=(t.name??"").trim();if(s!=="")return s;const n=Pr(t);if(n!==""){const a=Array.from(n);return a.length>120?`${a.slice(0,120).join("")}…`:n}return t.id.slice(0,8)}function wn(t,s){const n=s[t.id];if(n===void 0)return 0;const a=t.messages-n;return a>0?a:0}function _r(t,s=Date.now()){const n=new Date(t).getTime(),a=Number.isNaN(n)?1/0:s-n;return a<gt?"今天":a<2*gt?"昨天":a<7*gt?"7 天内":"更早"}function Bd({client:t,activeSessionId:s,onResume:n,onNewChat:a,onOpenSearch:l,onRenameSession:r,sessionsEpoch:o,awaitingIds:c,busySessionIds:d,onFollowUp:m}){const[p,g]=i.useState(null),[v,N]=i.useState(void 0),[S,R]=i.useState(!1),[j,f]=i.useState(0),A=()=>{g(null),R(!1),f(b=>b+1)},[$,y]=i.useState(null),[q,D]=i.useState(""),V=i.useRef({composing:!1,endedAt:0}),[H,X]=i.useState(()=>Or()),[W,z]=i.useState(!1),[F,M]=i.useState(()=>_d()),[P,T]=i.useState(!1),U=i.useRef(null),Q=()=>{T(!0),U.current!==null&&clearTimeout(U.current),U.current=setTimeout(()=>T(!1),2500)};i.useEffect(()=>{if(s===null||s===""||!H.includes(s))return;const b=H.filter(k=>k!==s);Ir(b),X(b)},[s,H]),i.useEffect(()=>{let b=!1;return t.sessions().then(k=>{b||(g(k),R(!1))}).catch(()=>{b||(R(!0),g(k=>k??[]))}),()=>{b=!0}},[t,s,o,j]);const[,se]=i.useState(0);i.useEffect(()=>{const b=setInterval(()=>{se(k=>k+1)},6e4);return()=>clearInterval(b)},[]),i.useEffect(()=>{if(t.schedulesList===void 0)return;let b=!1;return t.schedulesList().then(k=>{b||N(new Set(k.filter(w=>w.sessionId!==void 0&&w.enabled&&!w.paused).map(w=>w.sessionId)))}).catch(()=>{b||N(void 0)}),()=>{b=!0}},[t,s,o,j]),i.useEffect(()=>()=>{U.current!==null&&clearTimeout(U.current)},[]);const de=[...p??[]].sort((b,k)=>b.mtime<k.mtime?1:b.mtime>k.mtime?-1:0),le=new Set(H),K=de.filter(b=>!le.has(b.id)).slice(0,zd),O=de.filter(b=>le.has(b.id));i.useEffect(()=>{const b={...F};let k=!1;const w=s!==null&&s!==""?(p??[]).find(E=>E.id===s):void 0;w!==void 0&&b[w.id]!==w.messages&&(delete b[w.id],b[w.id]=w.messages,k=!0);for(const E of K){if(Object.keys(b).length>=Bn)break;b[E.id]===void 0&&(b[E.id]=E.messages,k=!0)}k&&M(Fd(b))},[p,H,s,F]);const x=[];for(const b of K){const k=_r(b.mtime),w=x[x.length-1];w!==void 0&&w.label===k?w.rows.push(b):x.push({label:k,rows:[b]})}return e.jsxs("div",{className:"sb",children:[e.jsxs("button",{type:"button",className:"sb-new",onClick:a,children:[e.jsx(xr,{size:13}),e.jsx("span",{children:"新对话"})]}),e.jsxs("div",{className:"sb-search",role:"button",tabIndex:0,onClick:l,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),l())},children:[e.jsx(Do,{size:12}),e.jsx("span",{children:"搜索会话…"})]}),e.jsx("div",{className:"sb-list",role:"list",children:p===null?e.jsxs("div",{className:"sb-skels",role:"status",children:[e.jsx("span",{className:"sr-only",children:"正在加载会话列表…"}),e.jsx("div",{className:"sb-skeleton","aria-hidden":!0}),e.jsx("div",{className:"sb-skeleton","aria-hidden":!0}),e.jsx("div",{className:"sb-skeleton","aria-hidden":!0})]}):x.length===0?S?e.jsx("div",{className:"tree-err",role:"button",tabIndex:0,onClick:A,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),A())},children:"加载失败 · 点击重试"}):e.jsx("div",{className:"tree-empty",role:"status",children:"暂无会话"}):x.map(b=>e.jsxs(i.Fragment,{children:[e.jsx("div",{className:"sb-g",role:"presentation",children:b.label}),b.rows.map(k=>{const w=()=>{if(k.lane==="pet"){Q();return}n(k.id)};return $===k.id?e.jsx("div",{role:"listitem",className:`sb-i${k.id===s?" on":""}`,children:e.jsx("input",{className:"sb-rename-in","aria-label":"重命名会话",placeholder:"会话名",autoFocus:!0,value:q,title:Array.from(q).length>Ms?`最多 ${Ms} 字`:void 0,style:Array.from(q).length>Ms?{borderColor:"var(--warn)"}:void 0,onChange:E=>D(E.target.value),onBlur:()=>{y(null)},onCompositionStart:()=>{V.current=He(V.current)},onCompositionEnd:()=>{V.current=_e(V.current,Date.now())},onKeyDown:E=>{if(!Ue(E.nativeEvent,V.current,Date.now()))if(E.key==="Enter"){const G=Array.from(q).length>Ms,ee=q.trim();if(G)return;y(null),ee!==""&&r?.(k.id,ee)}else E.key==="Escape"&&y(null)}})},k.id):e.jsxs("div",{role:"listitem",className:`sb-i${k.id===s?" on":""}`,title:Is(k),onClick:w,children:[e.jsxs("div",{className:"sb-main",role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),w())},children:[e.jsx("span",{className:"sb-t",children:jt(k)}),d!==void 0&&d.has(k.id)&&k.lane!=="pet"?e.jsx("span",{className:"sb-run",title:"任务进行中",role:"img","aria-label":"任务进行中",children:e.jsx(Gs,{size:12,className:"spin"})}):null,v!==void 0&&v.has(k.id)&&k.lane!=="pet"?e.jsx("span",{className:"sb-sched",title:"这个会话有定时任务或提醒",children:e.jsx(ae,{name:"clock",size:11})}):null,e.jsx("span",{className:"sb-when",children:Sl(k.mtime)}),c!==void 0&&c.has(k.id)&&k.lane!=="pet"?e.jsx("span",{className:"sb-await",children:"等你授权"}):null,k.id!==s&&wn(k,F)>0&&!(c!==void 0&&c.has(k.id)&&k.lane!=="pet")?e.jsxs("span",{className:"sb-unread",children:[wn(k,F)>99?"99+":wn(k,F)," 新"]}):null]}),r!==void 0?e.jsx("button",{type:"button",className:"sb-rename",title:"重命名",onClick:E=>{E.stopPropagation(),y(k.id),D((k.name??"").trim())},children:e.jsx(Ao,{size:12})}):null,m!==void 0&&k.lane!=="pet"?e.jsx("button",{type:"button",className:"sb-follow",title:"基于这段对话开一份副本继续问,原对话保持不变",onClick:E=>{E.stopPropagation(),m(k.id)},children:"追问"}):null,k.id===s?null:e.jsx("button",{type:"button",className:"sb-act",title:"归档",onClick:E=>{E.stopPropagation(),X(Nl(k.id))},children:"归档"})]},k.id)})]},b.label))}),P?e.jsx("div",{className:"sb-toast",role:"status",children:"精灵会话在精灵窗口继续"}):null,O.length>0?e.jsxs("div",{className:"sb-arch",children:[e.jsxs("button",{type:"button",className:"sb-arch-h","aria-expanded":W,title:W?"收起已归档":"展开已归档",onClick:()=>z(b=>!b),children:[e.jsx("span",{className:"sb-arch-caret",children:W?e.jsx(et,{size:12}):e.jsx(bt,{size:12})}),e.jsxs("span",{className:"sb-arch-t",children:["已归档 ",O.length]}),e.jsx("span",{className:"sb-arch-hint",children:"可随时恢复"})]}),W?e.jsx("div",{className:"sb-arch-list",role:"list",children:O.map(b=>e.jsxs("button",{type:"button",role:"listitem",className:"sb-arch-i",title:`恢复「${jt(b)}」到会话列表`,onClick:()=>{X(Nl(b.id))},children:[e.jsx("span",{className:"sb-t",children:jt(b)}),e.jsx("span",{className:"sb-when",children:Sl(b.mtime)}),e.jsx("span",{className:"sb-act",children:"恢复"})]},b.id))}):null]}):null]})}const Kd=20,Cl=50;function El(t){const s=t.name!==void 0&&t.name!==""?t.name:t.firstUser!==""?t.firstUser:"(空会话)";return s.length>Cl?`${s.slice(0,Cl)}…`:s}function Sn(t){const s=Date.parse(t);if(Number.isNaN(s))return"";const n=Date.now()-s;return n<6e4?"刚刚":n<60*6e4?`${Math.floor(n/6e4)}分钟前`:n<24*60*6e4?`${Math.floor(n/36e5)}小时前`:n<30*24*60*6e4?`${Math.floor(n/864e5)}天前`:t.slice(0,10)}function Wd({rows:t,onPick:s,onClose:n,onSearch:a,activeId:l=null,onDelete:r,trashRows:o=null,onRestore:c}){const[d,m]=i.useState(0),[p,g]=i.useState(""),[v,N]=i.useState(null),S=i.useRef(0),R=i.useRef(null),j=i.useRef({composing:!1,endedAt:0}),[f,A]=i.useState(null),[$,y]=i.useState(!1),[q,D]=i.useState(0),V=i.useId();tt(),i.useEffect(()=>{R.current?.focus()},[]),i.useEffect(()=>{m(0)},[t]);const H=p.trim()!=="";i.useEffect(()=>{m(0)},[p,v]),i.useEffect(()=>{D(T=>Math.min(T,Math.max(0,(o??[]).length-1)))},[o]);const X=T=>{const U=T.trim(),Q=++S.current;if(m(0),A(null),U===""){N(null);return}N(null),a(U).then(se=>{S.current===Q&&N(se)},()=>{S.current===Q&&N([])})},W=t?.slice().sort((T,U)=>Date.parse(U.mtime)-Date.parse(T.mtime)).slice(0,Kd)??null;let z="";const F=T=>{A(null),r?.(T).then(U=>{U&&X(p)})},M=H?v!==null&&v[d]!==void 0?{key:`${v[d].sessionId}-${d}`,id:v[d].sessionId}:null:W!==null&&W[d]!==void 0?{key:W[d].id,id:W[d].id}:null,P=T=>{if(!Ue(T.nativeEvent,j.current,Date.now())){if($){if(T.key==="Escape"){T.preventDefault(),y(!1);return}const U=o??[];if(U.length>0){if(T.key==="ArrowDown"){T.preventDefault(),D(Q=>Math.min(Q+1,U.length-1));return}if(T.key==="ArrowUp"){T.preventDefault(),D(Q=>Math.max(Q-1,0));return}if(T.key==="Enter"){T.preventDefault();const Q=U[q];Q!==void 0&&c?.(Q.id).then(se=>{se&&y(!1)});return}}return}if(T.key==="Escape"){if(T.preventDefault(),f!==null){A(null);return}n();return}if(T.key==="Delete"&&r!==void 0&&M!==null&&M.id!==l){T.preventDefault(),A(M);return}if(H){if(v===null)return;if(T.key==="ArrowDown"){T.preventDefault(),m(U=>Math.min(U+1,v.length-1));return}if(T.key==="ArrowUp"){T.preventDefault(),m(U=>Math.max(U-1,0));return}if(T.key==="Enter"){if(T.preventDefault(),f!==null&&M!==null&&f.key===M.key){F(f.id);return}const U=v[d];U!==void 0&&s(U.sessionId)}return}if(W!==null){if(T.key==="ArrowDown"){T.preventDefault(),m(U=>Math.min(U+1,W.length-1));return}if(T.key==="ArrowUp"){T.preventDefault(),m(U=>Math.max(U-1,0));return}if(T.key==="Enter"){if(T.preventDefault(),f!==null&&M!==null&&f.key===M.key){F(f.id);return}const U=W[d];U!==void 0&&s(U.id)}}}};return e.jsx("div",{className:"search-scrim",onClick:n,children:e.jsxs("div",{className:"search-pop",role:"dialog","aria-label":"会话列表",tabIndex:-1,onClick:T=>T.stopPropagation(),onCompositionStart:()=>{j.current=He(j.current)},onCompositionEnd:()=>{j.current=_e(j.current,Date.now())},onKeyDown:P,children:[e.jsx("div",{className:"session-head",children:$?"回收站 — ↑↓ 选择 · Enter 恢复 · Esc 返回列表":H?"全文搜索 — ↑↓ 选择 · Enter 恢复 · Esc 关闭":"切换会话 — ↑↓ 选择 · Enter 恢复 · Esc 关闭"}),$?null:e.jsx("input",{ref:R,className:"session-q",type:"text",placeholder:"搜索所有会话内容…","aria-label":"搜索所有会话内容",value:p,onChange:T=>{g(T.target.value),j.current.composing||X(T.target.value)},onCompositionEnd:T=>{j.current=_e(j.current,Date.now()),X(T.target.value)}}),e.jsx("div",{className:"search-results session-results",role:"listbox","aria-label":$?"回收站列表":void 0,"aria-activedescendant":$?(o??[])[q]!==void 0?`${V}-opt-${q}`:void 0:(H?v!==null&&v[d]!==void 0:W!==null&&W[d]!==void 0)?`${V}-opt-${d}`:void 0,children:$?o===null||o.length===0?e.jsx("div",{className:"search-empty",children:"回收站是空的"}):o.map((T,U)=>e.jsxs("div",{id:`${V}-opt-${U}`,className:`search-item session-item${U===q?" sel":""}`,role:"option","aria-selected":U===q,"data-id":T.id,title:Is(T),children:[e.jsxs("div",{className:"session-row1",children:[e.jsx("span",{className:"session-title",children:jt(T)}),e.jsx("span",{className:"session-time",children:Sn(T.mtime)}),e.jsx("button",{className:"session-restore wudao","aria-label":"恢复这个会话",title:"恢复这个会话",onClick:Q=>{Q.stopPropagation(),c?.(T.id).then(se=>{se&&y(!1)})},children:"恢复"})]}),e.jsx("div",{className:"session-preview",children:El(T)})]},T.id)):H?v===null?e.jsx("div",{className:"search-empty",children:"搜索中…"}):v.length===0?e.jsx("div",{className:"search-empty",children:"没有找到相关内容"}):v.map((T,U)=>{const Q=`${T.sessionId}-${U}`;return e.jsx("div",{id:`${V}-opt-${U}`,className:`search-item session-item${U===d?" sel":""}${f?.key===Q?" session-confirm":""}`,role:"option","aria-selected":U===d,"data-id":T.sessionId,title:Is($l(T)),onClick:()=>f?.key===Q?A(null):s(T.sessionId),children:f?.key===Q?e.jsxs("div",{className:"session-row1",children:[e.jsx("span",{className:"session-title",children:"删除这个会话?"}),e.jsx(Ml,{id:T.sessionId,onConfirm:F,onCancel:()=>A(null)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"session-row1",children:[e.jsx("span",{className:"session-title",children:jt($l(T))}),e.jsx("span",{className:`session-kind${T.kind==="assistant"?" ans":""}`,children:T.kind==="user"?"问":"答"}),e.jsx("span",{className:"session-time",children:Sn(T.mtime)}),r!==void 0&&T.sessionId!==l?e.jsx(Rl,{rowKey:Q,id:T.sessionId,onArm:A}):null]}),e.jsx("div",{className:"session-preview",children:Ud(T.snippet,p.trim())})]})},Q)}):W===null?e.jsx("div",{className:"search-empty",children:"加载中…"}):W.length===0?e.jsx("div",{className:"search-empty",children:"暂无会话"}):W.map((T,U)=>{const Q=_r(T.mtime),se=Q!==z?e.jsx("div",{className:"session-pg",role:"presentation",children:Q},`${T.id}-g`):null;return z=Q,e.jsxs(i.Fragment,{children:[se,e.jsx("div",{id:`${V}-opt-${U}`,className:`search-item session-item${U===d?" sel":""}${f?.key===T.id?" session-confirm":""}`,role:"option","aria-selected":U===d,"data-id":T.id,title:Is(T),onClick:()=>f?.key===T.id?A(null):s(T.id),children:f?.key===T.id?e.jsxs("div",{className:"session-row1",children:[e.jsx("span",{className:"session-title",children:"删除这个会话?"}),e.jsx(Ml,{id:T.id,onConfirm:F,onCancel:()=>A(null)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"session-row1",children:[T.unfinished===!0?e.jsx("span",{className:"session-kind",children:"未完成"}):null,e.jsx("span",{className:"session-title",children:jt(T)}),e.jsx("span",{className:"session-time",children:Sn(T.mtime)}),r!==void 0&&T.id!==l?e.jsx(Rl,{rowKey:T.id,id:T.id,onArm:A}):null]}),e.jsx("div",{className:"session-preview",children:El(T)})]})})]},T.id)})}),$?e.jsx("div",{className:"btnrow",children:e.jsx("button",{className:"wudao",onClick:()=>y(!1),children:"← 返回会话列表"})}):!H&&o!==null&&c!==void 0?e.jsx("div",{className:"btnrow",children:e.jsxs("button",{className:"session-trash-link wudao",onClick:()=>{A(null),D(0),y(!0)},children:["回收站 (",o.length,")"]})}):null]})})}function $l(t){return{id:t.sessionId,mtime:t.mtime,messages:0,firstUser:t.firstUser,model:"",...t.name!==""?{name:t.name}:{}}}function Rl({rowKey:t,id:s,onArm:n}){return e.jsx("button",{className:"session-del","aria-label":"删除这个会话",title:"删除这个会话",onClick:a=>{a.stopPropagation(),n({key:t,id:s})},children:e.jsx(Oo,{size:12})})}function Ml({id:t,onConfirm:s,onCancel:n}){return e.jsxs("span",{className:"session-confirm-actions",children:[e.jsx("button",{className:"session-del-ok",onClick:a=>{a.stopPropagation(),s(t)},children:"删除"}),e.jsx("button",{className:"session-del-cancel",onClick:a=>{a.stopPropagation(),n()},children:"取消"})]})}function Ud(t,s){if(s==="")return e.jsx(e.Fragment,{children:t});const n=t.toLowerCase().indexOf(s.toLowerCase());return n<0?e.jsx(e.Fragment,{children:t}):e.jsxs(e.Fragment,{children:[t.slice(0,n),e.jsx("span",{className:"session-hit-mark",children:t.slice(n,n+s.length)}),t.slice(n+s.length)]})}const Fr="✅ 悟道Harness — 任务完成";async function Hd(){return vr(Fr)}function zr(){try{return typeof document.hasFocus=="function"?!document.hasFocus():!1}catch{return!1}}const Tl=(t,s)=>{if(t===null||s===void 0||s==="")return;const n=(t.providers??[]).find(a=>a.provider===s);return n!==void 0?n.label:void 0};function qd({onChoose:t}){const s=i.useRef(!1),n=i.useRef(null);tt(),i.useEffect(()=>{n.current?.focus()},[]);const a=l=>{s.current||(s.current=!0,t(l))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in",role:"dialog","aria-label":"新对话",ref:n,tabIndex:-1,onKeyDown:l=>{(l.key==="Escape"||l.key==="Enter")&&(l.preventDefault(),a(!1))},children:[e.jsx("h3",{children:"清空当前对话?"}),e.jsx("div",{className:"muted",children:"未保存的工作保留在磁盘"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao danger",onClick:()=>a(!0),children:"确认"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>a(!1),children:"取消"})]})]})})}function Gd(t,s){const n=i.useRef(!1),a=i.useRef(null),l=i.useCallback(()=>{const r=document.title;let o=0;a.current=setInterval(()=>{o+=1,document.title=o%2===1?Fr:r,o>=6&&(a.current!==null&&clearInterval(a.current),a.current=null,document.title=r)},300)},[]);i.useEffect(()=>{if(t){n.current=!0;return}if(n.current)return n.current=!1,(document.hidden||document.visibilityState==="visible"&&zr())&&Hd().then(r=>{r||l()}),()=>{a.current!==null&&(clearInterval(a.current),a.current=null,document.title="悟道Harness")}},[t,l,s])}function Vd(t){return t===void 0||t.verifiedDone===void 0||t.remaining===void 0||t.verifiedDone<=0&&t.remaining<=0?null:`已验证完成 ${t.verifiedDone} / 待续 ${t.remaining}`}function Yd(t){return t===void 0?[]:t.filter(s=>s.state==="blocked"&&s.permissionAsk!==void 0).map(s=>s.sessionId)}function Xd(t){const s=t.map(a=>a.title).filter(a=>a!==void 0&&a.trim()!=="");if(t.length<=1)return s.length===1?{title:"⏸ 悟道Harness — 有会话在等你授权",body:s[0]}:{title:"⏸ 悟道Harness — 有会话在等你授权"};const n=s.slice(0,3).join("、");return{title:`⏸ 悟道Harness — 有 ${t.length} 个会话在等你授权`,...n===""?{}:{body:s.length>3?`${n} 等`:n}}}function Jd(t,s,n){const[a,l]=i.useState({line:null,morning:null,awaiting:[]});return i.useEffect(()=>{if(t===null||s===null||s===void 0){l({line:null,morning:null,awaiting:[]});return}let r=!0;const o=()=>{t.recoveryStatus().then(d=>{if(!r)return;const m=(d??[]).find(p=>p.sessionId===s);l({line:Vd(m),morning:Zd(m),awaiting:Yd(d)})}).catch(()=>{r&&l({line:null,morning:null,awaiting:[]})})};o();const c=window.setInterval(o,5e3);return()=>{r=!1,window.clearInterval(c)}},[t,s,n]),a}function Qd({line:t}){return e.jsx("div",{className:"recovery-banner",role:"status",children:e.jsx("div",{className:"recovery-title",children:t})})}function Zd(t){if(t===void 0||t.state!=="blocked")return null;const s=t.permissionAsk;return s===void 0?null:`昨夜停在这里等你授权:${s.question}应答后任务自动继续`}function eu({line:t}){return e.jsx("div",{className:"recovery-banner",role:"status",children:e.jsx("div",{className:"recovery-title",children:t})})}function tu(t,s){const n=s.join(","),[a,l]=i.useState(null),[r,o]=i.useState(null);i.useEffect(()=>{if(n==="")return;let p=!0;return t.sessions().then(g=>{if(!p)return;const v=new Map;for(const N of g??[])v.set(N.id,jt(N));l(v),o(n)}).catch(()=>{p&&o(n)}),()=>{p=!1}},[t,n]);const c=i.useMemo(()=>s.map(p=>({id:p,title:a?.get(p)??p.slice(0,8)})),[s,a]),d=i.useMemo(()=>new Set(s),[n]),m=i.useRef(new Set);return i.useEffect(()=>{const p=m.current;for(const N of[...p])s.includes(N)||p.delete(N);const g=s.filter(N=>!p.has(N));if(g.length===0||r!==n)return;for(const N of g)p.add(N);if(!(document.hidden||document.visibilityState==="visible"&&zr()))return;const v=Xd(g.map(N=>({id:N,title:a?.get(N)})));vr(v.title,v.body)},[s,n,r,a]),{names:c,set:d}}const Br="wudao.recap.v1",su=10*6e4,nu=3,Dl=20;function Kr(){try{const t=window.localStorage.getItem(Br);if(t===null)return{};const s=JSON.parse(t);return typeof s!="object"||s===null||typeof s.sessions!="object"||s.sessions===null?{}:s.sessions}catch{return{}}}function au(t){try{const s=Object.keys(t);if(s.length>Dl){const n=new Set(s.sort((a,l)=>(t[l]?.at??0)-(t[a]?.at??0)).slice(0,Dl));for(const a of s)n.has(a)||delete t[a]}window.localStorage.setItem(Br,JSON.stringify({sessions:t}))}catch{}}function lu(t){const s=Kr()[t];if(!(s===void 0||typeof s!="object")&&!(typeof s.mark!="number"||typeof s.at!="number"))return s}function Ht(t,s){const n=Kr();n[t]=s,au(n)}function ru(t){if(typeof t!="object"||t===null)return!1;const s=t.stats;if(typeof s!="object"||s===null)return!1;const n=s;return typeof n.turns=="number"&&typeof n.toolCalls=="number"&&typeof n.filesTouched=="number"}function iu(t){const{client:s,sessionId:n,history:a,historyEpoch:l}=t,[r,o]=i.useState(null),c=i.useRef(a);c.current=a;const d=i.useRef(n);d.current=n;const m=i.useCallback(()=>{const g=d.current,v=c.current;if(g===null||g===""||v.length===0)return;const N=lu(g);if(N===void 0)return;if(!Number.isInteger(N.mark)||N.mark<0||N.mark>v.length){Ht(g,{mark:v.length,at:Date.now()});return}if(N.servedMark===N.mark)return;const S=v.slice(N.mark).filter(R=>R.kind==="user"||R.kind==="assistant").length;if(Date.now()-N.at<su||S<nu){Ht(g,{mark:v.length,at:Date.now()});return}Ht(g,{...N,servedMark:N.mark}),s.recap(g,N.mark,N.at).then(R=>{ru(R)&&o(R)}).catch(()=>{})},[s]);i.useEffect(()=>{m()},[n,l,m]),i.useEffect(()=>{const g=()=>{const v=d.current;v===null||v===""||(document.hidden?Ht(v,{mark:c.current.length,at:Date.now()}):m())};return document.addEventListener("visibilitychange",g),()=>document.removeEventListener("visibilitychange",g)},[m]);const p=i.useCallback(()=>{o(null);const g=d.current;g!==null&&g!==""&&Ht(g,{mark:c.current.length,at:Date.now()})},[]);return{payload:r,onDismiss:p}}const Al=["完成了:","还在进行:","等你决定:"];function ou(t,s){if(t===null||!Number.isFinite(t)||t>s)return null;const n=Math.floor((s-t)/6e4);if(n<60)return`${Math.max(n,1)} 分钟`;const a=Math.floor(n/60);return a<24?`${a} 小时`:`${Math.floor(a/24)} 天`}function cu(t){const s=t.split(`
289
+ `).map(l=>l.trim()).filter(l=>l!==""),n=[];s.forEach((l,r)=>{Al.some(o=>l.startsWith(o))&&n.push(r)});const a=[];return n.forEach((l,r)=>{const o=r+1<n.length?n[r+1]:s.length,c=s[l]??"",d=Al.find(p=>c.startsWith(p));if(d===void 0)return;const m=s.slice(l,o).map((p,g)=>g===0?p.slice(d.length).trim():p);a.push({label:d,body:m.filter(p=>p!=="").join(" ")})}),a}function du({payload:t,now:s,onClose:n}){const a=ou(t.stats.sinceTs,s),l=t.narrative!==void 0?cu(t.narrative):[];return e.jsxs("div",{className:"recap-banner",role:"status",children:[e.jsx("div",{className:"recap-title",children:a!==null?`你离开了 ${a}——这期间:`:"你离开了这段时间——"}),l.length>0?e.jsx("div",{className:"recap-segments",children:l.map(r=>e.jsxs("div",{className:"recap-segment",children:[e.jsx("span",{className:"recap-label",children:r.label}),r.body]},r.label))}):null,e.jsx("div",{className:"recap-stats",children:`${t.stats.turns} 轮 · ${t.stats.toolCalls} 次工具调用 · ${t.stats.filesTouched} 个文件`}),e.jsx("button",{type:"button",className:"wudao action recap-close",onClick:n,children:"知道了"})]})}const Wr="wudao.recent-models.v1",Kn=5;function uu(){try{const t=window.localStorage.getItem(Wr);if(t===null)return[];const s=JSON.parse(t);if(typeof s!="object"||s===null||!Array.isArray(s.recent))return[];const n=[];for(const a of s.recent){if(typeof a!="object"||a===null)continue;const{provider:l,model:r}=a;typeof l!="string"||l===""||typeof r!="string"||r===""||n.push({provider:l,model:r})}return n}catch{return[]}}function hu(t){const s=t.length>Kn?t.slice(0,Kn):[...t];try{window.localStorage.setItem(Wr,JSON.stringify({recent:s}))}catch{}return s}function mu(t,s,n=Kn){return[s,...t.filter(a=>!(a.provider===s.provider&&a.model===s.model))].slice(0,n)}function pu(t){if(!t.startsWith("/"))return;const s=t.slice(1);return/\s/.test(s)?void 0:s}function fu(t,s){return t.filter(n=>n.name.startsWith(s))}function xu(t,s){return`/${s}`}function vu(t){if(t.args===void 0)return`/${t.name}`;const s=t.name.endsWith(":")?"":" ";return`/${t.name}${s}${t.isSensitive===!0?"<redacted>":t.args}`}const gu=7;function ju(t,s,n=gu){if(t<=0)return{start:0,rows:0};if(t<=n)return{start:0,rows:t};const a=Math.min(Math.max(s,0),t-1);return{start:Math.max(0,Math.min(a-Math.floor(n/2),t-n)),rows:n}}function bu(t,s={}){const n=["命令:"];for(const a of t)n.push(` ${vu(a)}${a.description?` ${a.description}`:""}`);return n.push("键位:"),n.push(" Enter 发送 · Shift+Enter 换行 · ↑↓ 翻历史 · / 命令 · @ 提及文件 · Esc 中断 · shift+tab 切模式 (workspace → ask → auto)"),n.push(" Ctrl+P 文件搜索 · Ctrl+B 左栏 · Ctrl+\\ 中栏 · Cmd/Ctrl+, 设置 · Ctrl+W 关标签页 · Ctrl+Tab 切标签页 · Ctrl+1-9 跳标签页"),s.mode!==void 0&&n.push(`模式:${s.mode}`),n.join(`
290
+ `)}function yu(t){const s=t.trim();return s===""?{kind:"noop"}:s==="/exit"||s==="/quit"?{kind:"exit"}:s==="/clear"?{kind:"clear"}:s==="/help"||s==="/?"?{kind:"help"}:s==="/resume"||s.startsWith("/resume ")?{kind:"resume"}:/^\/edit\s+\d+$/.test(s)?{kind:"edit",n:Number(s.split(/\s+/)[1])}:{kind:"pass",text:t}}const Nu=["const","let","var","function","return","if","else","for","while","do","switch","case","break","continue","new","class","extends","implements","interface","type","enum","import","from","export","default","as","async","await","try","catch","finally","throw","typeof","instanceof","in","of","this","super","static","public","private","protected","readonly","get","set","yield","void","null","undefined","true","false","struct","impl","fn","pub","mut","match","package","defer","go","chan","select","map","nil","string","number","boolean","any","unknown","never"],ku=["if","then","else","elif","fi","for","in","do","done","while","until","case","esac","function","return","export","local","source","alias","echo","cd","ls","cat","grep","sed","awk","mkdir","rm","cp","mv","chmod","sudo","apt","brew","npm","pnpm","yarn","git","curl","wget","set","unset","shift","test","exit"],wu=["def","class","return","if","elif","else","for","while","break","continue","import","from","as","with","try","except","finally","raise","yield","lambda","pass","global","nonlocal","assert","del","in","is","not","and","or","None","True","False","self","async","await","print","len","range","str","int","float","list","dict"],Su={clike:{lineComment:["//"],keywords:Nu},shell:{lineComment:["#"],keywords:ku},python:{lineComment:["#"],keywords:wu}},Cu={ts:"clike",tsx:"clike",typescript:"clike",js:"clike",jsx:"clike",javascript:"clike",mjs:"clike",cjs:"clike",json:void 0,jsonc:"clike",go:"clike",rust:"clike",rs:"clike",java:"clike",c:"clike",h:"clike",cpp:"clike","c++":"clike",cs:"clike",csharp:"clike",kotlin:"clike",swift:"clike",dart:"clike",scala:"clike",sh:"shell",bash:"shell",zsh:"shell",shell:"shell",console:"shell",fish:"shell",dockerfile:"shell",makefile:"shell",make:"shell",py:"python",python:"python",python3:"python",yaml:"shell",yml:"shell",toml:"shell",ini:"shell",conf:"shell",rb:"python",ruby:"python",lua:"python",r:"python",perl:"python",sql:"sql",psql:"sql",mysql:"sql",htm:"html",html:"html",xml:"html",svg:"html",vue:"html",css:"css",scss:"css",less:"css",php:"clike",m:"clike",mm:"clike",hpp:"clike",cc:"clike",hh:"clike"};function Ur(t,s){const n=s!==void 0?Cu[s.toLowerCase()]:void 0;if(n==="html")return Tu(t);if(n==="css")return Du(t);if(n==="sql")return Mu(t);const a=n===void 0?void 0:Su[n];return a===void 0?Ol(t,{lineComment:[],keywords:[]}):Ol(t,a)}function Wn(t){const s=t.split("/").pop()??"",n=s.lastIndexOf(".");if(!(n<=0||n===s.length-1))return s.slice(n+1).toLowerCase()}function Ol(t,s){if(t==="")return[];const n=Eu(t,s.lineComment),a=n===-1?t:t.slice(0,n),l=$u(a,s);return n!==-1&&l.push({text:t.slice(n),cls:"tok-com"}),l}function Eu(t,s){if(s.length===0)return-1;let n=null;for(let a=0;a<t.length;a++){const l=t[a];if(n!==null){l==="\\"?a++:l===n&&(n=null);continue}if(l==='"'||l==="'"||l==="`"){n=l;continue}for(const r of s)if(t.startsWith(r,a))return a}return-1}const Hr=/[A-Za-z_$][A-Za-z0-9_$]*/,ta=/\d[\d._xXa-fA-F]*/,Bs=/([A-Za-z_$][A-Za-z0-9_$]*)\s*(?=\()/;function $u(t,s){const n=[];let a=0,l="";const r=()=>{l!==""&&(n.push({text:l}),l="")};for(;a<t.length;){const o=t[a]??"";if(o==='"'||o==="'"||o==="`"){let c=a+1;for(;c<t.length&&(t[c]??"")!==o;)(t[c]??"")==="\\"&&c++,c++;r(),n.push({text:t.slice(a,Math.min(c+1,t.length)),cls:"tok-str"}),a=c+1;continue}if(/[0-9]/.test(o)){const c=ta.exec(t.slice(a));if(c!==null){r(),n.push({text:c[0],cls:"tok-num"}),a+=c[0].length;continue}}if(/[A-Za-z_$]/.test(o)){const c=t.slice(a),d=Hr.exec(c)?.[0];if(d!==void 0){s.keywords.includes(d)?(r(),n.push({text:d,cls:"tok-key"})):Bs.test(c)&&Bs.exec(c)?.[1]===d?(r(),n.push({text:d,cls:"tok-fn"})):l+=d,a+=d.length;continue}}l+=o,a++}return r(),n}const Ru=["select","from","where","join","left","right","inner","outer","full","cross","on","group","order","by","having","limit","offset","insert","into","values","update","set","delete","create","table","index","view","drop","alter","add","column","primary","foreign","key","references","unique","null","not","default","as","and","or","in","between","like","is","exists","case","when","then","else","end","union","all","distinct","asc","desc","with","returning","conflict","do","nothing"];function Mu(t){if(t==="")return[];const s=[];let n="";const a=()=>{n!==""&&(s.push({text:n}),n="")};let l=0;for(;l<t.length;){const r=t.slice(l);if(r.startsWith("--")){a(),s.push({text:r,cls:"tok-com"});break}if(r.startsWith("/*")){const c=r.indexOf("*/",2),d=c===-1?r.length:c+2;a(),s.push({text:r.slice(0,d),cls:"tok-com"}),l+=d;continue}const o=r[0]??"";if(o==="'"){let c=1;for(;c<r.length;){if(r[c]==="'"){if(r[c+1]==="'"){c+=2;continue}c+=1;break}c+=1}const d=Math.min(c,r.length);a(),s.push({text:r.slice(0,d),cls:"tok-str"}),l+=d;continue}if(/[0-9]/.test(o)){const c=ta.exec(r);if(c!==null){a(),s.push({text:c[0],cls:"tok-num"}),l+=c[0].length;continue}}if(/[A-Za-z_]/.test(o)){const c=Hr.exec(r)?.[0];if(c!==void 0){Ru.includes(c.toLowerCase())?(a(),s.push({text:c,cls:"tok-key"})):Bs.test(r)&&Bs.exec(r)?.[1]===c?(a(),s.push({text:c,cls:"tok-fn"})):n+=c,l+=c.length;continue}}n+=o,l+=1}return a(),s}function Tu(t){if(t==="")return[];const s=[];let n="",a=!1;const l=()=>{n!==""&&(s.push({text:n}),n="")};let r=0;for(;r<t.length;){const o=t.slice(r);if(!a&&o.startsWith("<!--")){const c=o.indexOf("-->",4),d=c===-1?o.length:c+3;l(),s.push({text:o.slice(0,d),cls:"tok-com"}),r+=d;continue}if(!a&&(o[0]??"")==="<"){a=!0;const c=/^<[A-Za-z][\w:.-]*/.exec(o)||/^<\/[A-Za-z][\w:.-]*>/.exec(o);if(c!==null){l(),s.push({text:c[0],cls:"tok-key"}),r+=c[0].length;continue}l(),s.push({text:"<",cls:"tok-key"}),r+=1;continue}if(a){const c=o[0]??"";if(c===">"){a=!1,l(),s.push({text:">",cls:"tok-key"}),r+=1;continue}if(c==='"'||c==="'"){let d=1;for(;d<o.length&&o[d]!==c;)d+=1;const m=Math.min(d+1,o.length);l(),s.push({text:o.slice(0,m),cls:"tok-str"}),r+=m;continue}if(/[A-Za-z_]/.test(c)){const d=/^[A-Za-z_][\w:.-]*/.exec(o)?.[0];if(d!==void 0){l(),s.push({text:d,cls:"tok-fn"}),r+=d.length;continue}}n+=c,r+=1;continue}if((o[0]??"")==="&"){const c=/^&[A-Za-z][A-Za-z\d]{0,10};/.exec(o)??/^&#\d{1,7};/.exec(o);if(c!==null){l(),s.push({text:c[0],cls:"tok-num"}),r+=c[0].length;continue}}n+=o[0]??"",r+=1}return n!==""&&s.push({text:n}),s}function Du(t){if(t==="")return[];const s=[];let n=0;for(;n<t.length;){const a=t.slice(n);if(a.startsWith("/*")){const r=a.indexOf("*/",2),o=r===-1?a.length:r+2;s.push({text:a.slice(0,o),cls:"tok-com"}),n+=o;continue}const l=a.indexOf("{");if(l>-1){let r=a.slice(0,l);if(r!=="")if(r.trim()==="")s.push({text:r});else if(r[0]==="@"){const o=/^(@[\w-]+)(\s*)/.exec(r);if(o!==null){s.push({text:o[1]+(o[2]??""),cls:"tok-key"});const c=r.slice(o[0].length);c!==""&&s.push({text:c})}else s.push({text:r,cls:"tok-key"})}else s.push({text:r,cls:"tok-key"});s.push({text:"{"}),n+=l+1;continue}s.push(...Au(a)),n=t.length}return s}function Au(t){const s=[],n=/^(\s*)([-\w]+)(\s*:)/.exec(t);let a=0;n!==null&&(s.push({text:n[1]??""}),s.push({text:n[2]??"",cls:"tok-fn"}),s.push({text:n[3]??""}),a=n[0]?.length??0);const l=t.slice(a);let r=0,o="";const c=()=>{o!==""&&(s.push({text:o}),o="")};for(;r<l.length;){const d=l.slice(r),m=d[0]??"";if(m==='"'||m==="'"){let p=1;for(;p<d.length&&d[p]!==m;)p+=1;const g=Math.min(p+1,d.length);c(),s.push({text:d.slice(0,g),cls:"tok-str"}),r+=g;continue}if(/[0-9]/.test(m)){const p=ta.exec(d);if(p!==null){c(),s.push({text:p[0],cls:"tok-num"}),r+=p[0].length;continue}}if(m==="#"||m==="$"||m==="@"){const p=/^[$@]?[-\w]+/.exec(d.slice(1));if(p!==null){c(),s.push({text:m+p[0],cls:"tok-num"}),r+=1+p[0].length;continue}}o+=m,r+=1}return c(),s}function Ks(t){try{const s=navigator.clipboard?.writeText(t);s!==void 0&&s.catch(()=>{})}catch{}}function qr({x:t,y:s,items:n,onClose:a}){return tt(),i.useEffect(()=>{const l=r=>{r.key==="Escape"&&a()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[a]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ctx-backdrop",onClick:a}),e.jsx("div",{className:"menu ctx",role:"menu",style:{"--ctx-x":`${t}px`,"--ctx-y":`${s}px`},children:n.map(l=>e.jsxs("button",{type:"button",role:"menuitem",className:"menu-item",onClick:()=>{a(),l.onSelect()},children:[l.label,l.kbd!==void 0?e.jsx("span",{className:"menu-kbd",children:l.kbd}):null]},l.label))})]})}function Ou(t){return t.startsWith("https://")||t.startsWith("http://")}function Iu(t){t.preventDefault();const s=t.currentTarget.href;Lo(s).then(n=>{n||window.open(s,"_blank","noopener")})}function qt({s:t}){return e.jsx(e.Fragment,{children:Io(t).map((s,n)=>s.href!==void 0&&Ou(s.href)?e.jsx("a",{href:s.href,target:"_blank",rel:"noopener noreferrer",onClick:Iu,children:s.text},n):s.code?e.jsx("code",{className:"inline",children:s.text},n):s.bold?e.jsx("span",{className:"bold",children:s.text},n):e.jsx("span",{children:s.text},n))})}function Lu({lang:t,lines:s,meta:n}){const[a,l]=ce.useState(!1),r=ce.useRef(void 0);ce.useEffect(()=>()=>{r.current!==void 0&&window.clearTimeout(r.current)},[]);const o=()=>{Ks(s.join(`
291
+ `)),l(!0),r.current!==void 0&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>l(!1),1200)};return e.jsxs("div",{className:n?.file!==void 0?"pre has-pre-head":"pre",children:[n?.file!==void 0?e.jsxs("div",{className:"pre-head",children:[e.jsx("span",{className:"pre-file",children:n.file}),n.line!==void 0?e.jsx("span",{className:"pre-ln",children:`L${n.line}`}):null]}):null,e.jsx("button",{type:"button",className:a?"pre-copy done":"pre-copy","aria-label":"复制代码",onClick:o,children:a?"已复制 ✓":"复制"}),e.jsx("pre",{children:e.jsx("code",{children:s.map((c,d)=>e.jsxs(ce.Fragment,{children:[d>0?`
292
+ `:null,Ur(c,t).map((m,p)=>m.cls===void 0?m.text:e.jsx("span",{className:m.cls,children:m.text},p))]},d))})})]})}function Gr(t,s){return t.map((n,a)=>n.kind==="code"?e.jsx(Lu,{lang:n.lang,lines:n.lines,meta:s},a):n.kind==="heading"?e.jsx("div",{className:"md-heading","data-level":n.level,children:e.jsx(qt,{s:n.text})},a):n.kind==="table"?e.jsxs("table",{className:"md-table",children:[e.jsx("thead",{children:e.jsx("tr",{children:n.header.map((l,r)=>e.jsx("th",{children:e.jsx(qt,{s:l})},r))})}),e.jsx("tbody",{children:n.rows.map((l,r)=>e.jsx("tr",{children:l.map((o,c)=>e.jsx("td",{children:e.jsx(qt,{s:o})},c))},r))})]},a):n.kind==="list"?e.jsx("div",{className:"md-list",children:n.items.map((l,r)=>e.jsxs("div",{children:["• ",e.jsx(qt,{s:l})]},r))},a):n.kind==="quote"?e.jsx("div",{className:"md-quote",children:n.lines.map((l,r)=>e.jsx("div",{children:`| ${l}`},r))},a):e.jsx("div",{className:"md-para",children:n.lines.map((l,r)=>e.jsx("div",{children:e.jsx(qt,{s:l})},r))},a))}const Vr=ce.memo(function({source:s,meta:n}){return e.jsx("div",{className:"md",children:Gr(On(s),n)})});function Pu({source:t}){const n=ce.useRef({prefix:"",stable:[]}).current;t.startsWith(n.prefix)||(n.prefix="",n.stable=[]);const a=t.slice(n.prefix.length),l=Po(a);l>0&&(n.stable=n.stable.concat(On(a.slice(0,l))),n.prefix=t.slice(0,n.prefix.length+l));const r=t.slice(n.prefix.length),o=r===""?_o:On(r);return e.jsx("div",{className:"md",children:Gr(n.stable.concat(o))})}function Yr({children:t}){return e.jsxs("div",{className:"msg-a",children:[e.jsxs("div",{className:"msg-sig",children:[e.jsx("span",{className:"sig-avatar","aria-hidden":"true"}),e.jsx("span",{className:"sig-name",children:"悟道Harness"})]}),e.jsx("div",{className:"reply-card",children:t})]})}const Jt={done:"☑ ",inProgress:"◐ ",pending:"☐ "};function _u(t){return t.startsWith(Jt.done)?"done":t.startsWith(Jt.inProgress)?"wip":"todo"}function Ae(t){return t>=999950?Math.round(t/1e5)/10+"M":Math.round(t/100)/10+"k"}function Xr(t,s){return t.length>s?`${t.slice(0,s)}…`:t}function Vs(t){const s=t.indexOf(`
293
+ `);return s===-1?t:`${t.slice(0,s)} …`}const Fu=5e3;function Jr(t,s){const n=t.split(`
294
+ `),a=s.split(`
295
+ `),l=Date.now()+Fu;let r=0;for(;r<n.length&&r<a.length&&n[r]===a[r];){if(!(r&4095)&&Date.now()>l)return Il(n,a);r++}let o=n.length-1,c=a.length-1;for(;o>=r&&c>=r&&n[o]===a[c];){if(!(n.length-o&4095)&&Date.now()>l)return Il(n,a);o--,c--}const d=[];for(let m=0;m<r;m++)d.push({kind:"ctx",text:n[m]??""});for(let m=r;m<=o;m++)d.push({kind:"del",text:n[m]??""});for(let m=r;m<=c;m++)d.push({kind:"add",text:a[m]??""});for(let m=o+1;m<n.length;m++)d.push({kind:"ctx",text:n[m]??""});return d}function Il(t,s){return[...t.map(n=>({kind:"del",text:n})),...s.map(n=>({kind:"add",text:n}))]}function Qr(t,s=3){const n=[];let a=[];const l=()=>{a.length<=s*2?n.push(...a):n.push(...a.slice(0,s),{kind:"gap",count:a.length-s*2},...a.slice(a.length-s)),a=[]};for(const r of t)r.kind==="ctx"?a.push(r):(l(),n.push(r));return l(),n}function zu(t,s){const n=(a,l)=>{const r=t.filter(d=>d.kind===a),o=r.slice(0,s),c=r.length-o.length;return c>0?[...o,{kind:"gap",count:c,label:`⋯ 再 ${l}${c} 行 ⋯`}]:o};return[...n("del","-"),...n("add","+")]}function Ll(t){return t.split(/(\s+)/).filter(s=>s!=="")}const De=(t,s)=>t===""?[]:[{text:t,changed:s}];function Bu(t,s){let n=0;for(;n<t.length&&n<s.length&&t[n]===s[n];)n++;let a=0;for(;a<t.length-n&&a<s.length-n&&t[t.length-1-a]===s[s.length-1-a];)a++;const l=t.slice(n,t.length-a),r=s.slice(n,s.length-a);return l===""||r===""?{a:De(t,!0),b:De(s,!0)}:{a:[...De(t.slice(0,n),!1),...De(l,!0),...De(t.slice(t.length-a),!1)],b:[...De(s.slice(0,n),!1),...De(r,!0),...De(s.slice(s.length-a),!1)]}}function Ku(t,s){if(t===s)return{old:De(t,!1),new:De(s,!1)};const n=Ll(t),a=Ll(s);let l=0;for(;l<n.length&&l<a.length&&n[l]===a[l];)l++;let r=0;for(;r<n.length-l&&r<a.length-l&&n[n.length-1-r]===a[a.length-1-r];)r++;const o=n.slice(l,n.length-r),c=a.slice(l,a.length-r),d=o.length===1&&c.length===1?Bu(o[0]??"",c[0]??""):{a:De(o.join(""),!0),b:De(c.join(""),!0)};return{old:[...De(n.slice(0,l).join(""),!1),...d.a,...De(n.slice(n.length-r).join(""),!1)],new:[...De(a.slice(0,l).join(""),!1),...d.b,...De(a.slice(a.length-r).join(""),!1)]}}function ct({text:t,lang:s}){return e.jsx(e.Fragment,{children:Ur(t,s).map((n,a)=>n.cls===void 0?n.text:e.jsx("span",{className:n.cls,children:n.text},a))})}function Wu(t){const s=new Map;let n=0;for(;n<t.length;){const a=t[n];if(a!==void 0&&(a.kind==="del"||a.kind==="add")){let l=n;for(;l<t.length;){const c=t[l];if(c===void 0||c.kind!=="del"&&c.kind!=="add")break;l++}const r=t[n],o=t[n+1];l-n===2&&r?.kind==="del"&&o?.kind==="add"&&s.set(n,Ku(r.text,o.text)),n=l}else n++}return s}function Pl({spans:t,lang:s}){return e.jsx(e.Fragment,{children:t.map((n,a)=>n.changed?e.jsx("span",{className:"wchg",children:e.jsx(ct,{text:n.text,lang:s})},a):e.jsx(ct,{text:n.text,lang:s},a))})}function Uu({path:t,oldString:s,newString:n,rows:a,onOpenFile:l}){const r=a??Qr(Jr(s,n)),o=Wu(r),c=Wn(t);return e.jsxs("div",{className:"diff",children:[e.jsxs("div",{className:"path",children:[e.jsx(gr,{size:13})," ",l!==void 0?e.jsx("button",{type:"button",className:"fv-chip",title:t,onClick:()=>l(t),children:t}):t]}),r.map((d,m)=>d.kind==="gap"?e.jsx("div",{className:"ctx",children:d.label??` ⋯ ${d.count} 行未变 ⋯`},m):d.kind==="del"?e.jsxs("div",{className:"del",children:["- ",o.has(m)?e.jsx(Pl,{spans:o.get(m)?.old??[],lang:c}):e.jsx(ct,{text:d.text,lang:c})]},m):d.kind==="add"?e.jsxs("div",{className:"add",children:["+ ",o.has(m-1)?e.jsx(Pl,{spans:o.get(m-1)?.new??[],lang:c}):e.jsx(ct,{text:d.text,lang:c})]},m):e.jsxs("div",{className:"ctx",children:[" ",e.jsx(ct,{text:d.text,lang:c})]},m))]})}function sa(t){const s=t.toLowerCase();return s==="read_file"?"read":s==="grep"||s==="glob"?"search":s==="web_search"||s==="web_fetch"?"web":"inout"}const Zr={read:"读取",search:"搜索",web:"联网",inout:"执行"},Hu=t=>Zr[sa(t)],We=8,Ws=50;function Us(t,s=We){const n=t.split(`
296
+ `);return{lines:n.slice(0,s),total:n.length}}const ei="132px",ti="960px";function na({total:t,expanded:s,onToggle:n}){return e.jsx("button",{type:"button",className:"activity-toggle","aria-expanded":s,onClick:n,children:s?"收起 ▴":`展开 ▾ (${t} 行)`})}const qu={ok:"完成",run:"进行中",err:"出错"};function Gu(t,s){return s.some(n=>(n.name==="edit"||n.name==="write_file")&&n.summary===t.path)}function si({entry:t,running:s=!1,onOpenFile:n}){const[a,l]=i.useState(!1);return t.kind==="edit"?e.jsx(Qu,{entry:t,open:a,onToggle:()=>l(!a),running:s,onOpenFile:n}):e.jsx(Xu,{entry:t,open:a,onToggle:()=>l(!a)})}function ni({status:t,verb:s,file:n,note:a,open:l,onToggle:r}){return e.jsxs("button",{type:"button",className:"act-row","data-status":t,"aria-expanded":l,onClick:r,children:[e.jsx("span",{className:`act-st st-${t}`,"aria-hidden":!0,children:t==="ok"?e.jsx(ut,{size:13}):t==="run"?e.jsx(Gs,{size:13,className:"spin"}):"✕"}),e.jsx("span",{className:"sr-only",children:qu[t]}),e.jsx("span",{className:"act-verb",children:s}),n!==""?e.jsx("span",{className:"act-file",children:n}):null,e.jsx("span",{className:"act-tail",children:a}),e.jsx(et,{size:12,className:"act-chev"})]})}function Vu(t){const s=t.toLowerCase();return s.endsWith(".xlsx")?"chart-column":s.endsWith(".pptx")?"film":"file-text"}function Yu({file:t}){return e.jsxs("div",{className:"act-file-card",children:[e.jsx("span",{className:"act-file-icon","aria-hidden":!0,children:e.jsx(ae,{name:Vu(t.name),size:13})}),e.jsx("span",{className:"act-file-name",children:t.name}),e.jsx("span",{className:"act-file-size",children:`${(t.bytes/1024).toFixed(1)} KB`}),e.jsx("button",{type:"button",className:"act-file-reveal",onClick:()=>{Zt("open_path",{path:t.path})},children:"打开"}),e.jsx("button",{type:"button",className:"act-file-reveal",onClick:()=>{Zt("reveal_path",{path:t.path})},children:"在访达中显示"})]})}function Xu({entry:t,open:s,onToggle:n}){const a=sa(t.name),l=t.resultPreview??"",r=t.isError?Vs(l):"",o=(t.durationMs??0)/1e3,c=t.durationMs!==void 0&&!t.isError?`· ${o<.1?"<0.1":o.toFixed(1)}s`:"",d=r===""?c:s?r:`${r} · 点击查看`,m=t.isError?"err":"ok";return e.jsxs("div",{className:`act${t.isError?" err":""}`,"data-kind":a,"data-status":m,"data-err":t.isError===!0,"data-open":s,children:[e.jsx(ni,{status:m,verb:Zr[a],file:t.summary,note:d,open:s,onToggle:n}),t.file!==void 0&&!t.isError?e.jsx(Yu,{file:t.file}):null,s?e.jsx(Ju,{entry:t,kind:a}):null]})}function Ju({entry:t,kind:s}){const[n,a]=i.useState(!1),l=t.resultPreview??"";if(l==="")return null;const{lines:r,total:o}=Us(l,n?Ws:We),c=o>We||n?e.jsx(na,{total:o,expanded:n,onToggle:()=>a(m=>!m)}):null,d=n?ti:ei;if(s==="inout"){let m=r,p="";if(t.name==="shell"){const v=[...l.split(`
297
+ `)];v.length>0&&v[0].startsWith("$ ")&&v.shift();const N=v[v.length-1]??"",S=/^\[exit (-?\d+)\]$/.exec(N.trim());v.length>0&&S!==null&&(p=` · exit ${S[1]}`,v.pop()),m=Us(v.join(`
298
+ `),n?Ws:We).lines}return e.jsxs("div",{className:"act-body inout","data-truncated":o>We,style:{maxHeight:d},children:[e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"blocklabel",children:"输入"}),e.jsx("span",{className:"blocktext",children:t.summary===""?"(无参数摘要)":t.summary})]}),e.jsxs("div",{className:`block${t.isError?" err":""}`,children:[e.jsxs("span",{className:"blocklabel",children:[t.isError?"出错":"输出",p]}),e.jsx("span",{className:"blocktext",children:m.join(`
299
+ `)===""&&p!==""?"(无输出)":m.join(`
300
+ `)}),c]})]})}return e.jsxs("div",{className:`act-body ${s}`,"data-truncated":o>We,style:{maxHeight:d},children:[e.jsx("span",{className:"blocktext",children:r.join(`
301
+ `)}),c]})}function Qu({entry:t,open:s,onToggle:n,running:a,onOpenFile:l}){const r=a?"run":"ok";return e.jsxs("div",{className:"act","data-kind":"diff","data-status":r,"data-open":s,children:[e.jsx(ni,{status:r,verb:"修改",file:t.path,note:s?"":a?"正在写入…":"查看改动",open:s,onToggle:n}),s?e.jsx(Zu,{entry:t,onOpenFile:l}):null]})}function Zu({entry:t,onOpenFile:s}){const[n,a]=i.useState(!1),l=Qr(Jr(t.oldString,t.newString)),r=l.length>We,o=!n&&r?zu(l,3):l;return e.jsxs("div",{className:"act-body diffwrap",style:{maxHeight:n?ti:ei},children:[e.jsx(Uu,{path:t.path,oldString:t.oldString,newString:t.newString,rows:o,onOpenFile:s}),r?e.jsx(na,{total:l.length,expanded:n,onToggle:()=>a(c=>!c)}):null,n&&l.length>Ws?e.jsx("div",{className:"activity-foot",children:`⋯ diff 共 ${l.length} 行,卡内滚动查看`}):null]})}function eh(){return e.jsx(Gs,{size:13,className:"spin"})}function aa({text:t,streaming:s=!1,defaultOpen:n=!1}){const a=ce.useRef(null),l=ce.useRef(null),[r,o]=ce.useState(!1);return ce.useEffect(()=>{r||a.current===null||(a.current.open=s?!0:n)},[s,n,r]),ce.useEffect(()=>{const c=l.current;c!==null&&c.scrollTop+c.clientHeight>=c.scrollHeight-40&&(c.scrollTop=c.scrollHeight)},[t]),e.jsxs("details",{className:"reasoning","data-streaming":s,ref:a,children:[e.jsx("summary",{onClick:()=>o(!0),className:s?"sweep-line":void 0,children:s?"思考中":`思考过程 · ${t.length} 字`}),e.jsx("div",{className:"body",ref:l,children:t})]})}function ai({tool:t,onDetach:s}){const n=sa(t.name),a=t.tail===void 0?[]:t.tail.split(`
302
+ `).filter(l=>l.trim()!=="").slice(-3);return e.jsxs("div",{className:"act","data-kind":n,"data-status":"run",children:[e.jsxs("div",{className:"act-row","data-status":"run",children:[e.jsx("span",{className:"act-st st-run","aria-hidden":!0,children:e.jsx(eh,{})}),e.jsx("span",{className:"sr-only",children:"进行中"}),e.jsx("span",{className:"act-verb",children:Hu(t.name)}),e.jsx("span",{className:"act-file",children:t.summary!==""?t.summary:t.name}),t.gating?e.jsxs("span",{className:"act-tail gating",children:[e.jsx(ae,{name:"shield",size:11})," 检查中"]}):null,s!==void 0&&t.callId!==void 0?e.jsx("button",{type:"button",className:"detach","aria-label":"把这个工具调用转入后台",title:"不再等待——调用转后台继续跑,完成后自动并入对话",onClick:()=>s(t.callId),children:"转入后台"}):null]}),a.length>0?e.jsx("div",{className:"act-tail-line",children:a.join(`
303
+ `)}):null]})}function li({text:t}){return e.jsx("div",{className:"live-answer",children:e.jsxs(Yr,{children:[e.jsx(Pu,{source:t}),e.jsx("span",{className:"caret","aria-hidden":!0,children:"▌"})]})})}function th({live:t,queued:s,onRecall:n,onDetachTool:a}){const l=t.busyTools,r=l.length>0||t.reasoning!==""||s.length>0;return e.jsxs(e.Fragment,{children:[r?e.jsxs("div",{className:"panel",children:[e.jsxs("div",{className:"panel-head",children:[e.jsx("span",{className:"panel-title",children:"工具流"}),e.jsx("span",{className:"panel-count",children:`${l.length} 项`})]}),e.jsxs("div",{className:"panel-list",children:[t.reasoning!==""?e.jsx(aa,{text:t.reasoning,streaming:t.thinking??!1,defaultOpen:!0}):null,l.map((o,c)=>e.jsx(ai,{tool:o,onDetach:a},`${o.name}:${o.summary}:${c}`)),s.map((o,c)=>e.jsxs("div",{className:"steer",children:[e.jsx(ae,{name:"hourglass",size:11}),` 将在下一步前注入:${Xr(Vs(o),60)}`,n!==void 0?e.jsx("button",{type:"button",className:"recall","aria-label":"撤回这条排队消息",title:"趁还没被读取,撤回这条",onClick:()=>n(c,o),children:"↩ 撤回"}):null]},c))]})]}):null,t.answer!==""?e.jsx(li,{text:t.answer}):null]})}function sh(t){for(const s of[Jt.done,Jt.inProgress,Jt.pending])if(t.startsWith(s))return t.slice(s.length);return t}function nh({done:t,total:s,lines:n}){const a=s===0?0:t/s*100;return e.jsxs("div",{className:"todo",children:[e.jsx("div",{className:"todo-bar",role:"progressbar","aria-label":`${t}/${s}`,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":s,style:{width:`${a}%`}}),n.map((l,r)=>{const o=_u(l);return e.jsxs("div",{className:"todo-item",children:[e.jsx("span",{className:`todo-box${o==="done"?" done":""}`,children:o==="done"?e.jsx(ut,{size:12}):null}),e.jsx("span",{children:sh(l)})]},r)})]})}const ri=9,ah=20*1024*1024;function ns(t){return 4*Math.ceil(t/3)}let _l=0;function ii(){const t=globalThis.crypto;return typeof t?.randomUUID=="function"?t.randomUUID():(_l+=1,`draft-${_l}`)}function oi(t){return ns(t.byteLength)}function lh(t,s){return t.type.startsWith("image/")?s.length>=ri?"count":s.reduce((a,l)=>a+oi(l),0)+ns(t.size)>ah?"budget":null:"type"}function ci(t,s){const n=[],a=[...s],l=new Map;let r=null;for(const c of t){const d=lh(c,a);d===null?(n.push(c),a.push({byteLength:c.size})):(l.set(d,(l.get(d)??0)+1),d==="type"&&r===null&&(r=c.type===""?"该文件":c.type))}if(l.size===0)return{accepted:n,notice:null};const o=[];for(const c of["type","count","budget"]){const d=l.get(c);d!==void 0&&(c==="type"?o.push(`${d} 张不是图片(${r})—— 只能附加图片`):c==="count"?o.push(`${d} 张超出数量上限(最多同时附加 ${ri} 张)`):o.push(`${d} 张超过 20MiB 上限`))}return{accepted:n,notice:`⚠️ ${o.join(" · ")}`}}const rh=[{code:"TOO_MANY_IMAGES",re:/TOO_MANY_IMAGES|exceed the per-request cap/i,zh:"图片数量超出上限"},{code:"IMAGES_TOO_LARGE",re:/IMAGES_TOO_LARGE|over the \d+-byte request budget/i,zh:"图片体积超出上限"}];function ih(t){for(const s of rh)if(s.re.test(t))return`${s.zh}(${s.code})`;return t}function di(t){return{id:ii(),name:t.name,mediaType:t.type,byteLength:t.size,url:URL.createObjectURL(t),file:t}}function Ls(t){URL.revokeObjectURL(t.url)}function Fl(t){return new Promise((s,n)=>{const a=new FileReader;a.onerror=()=>n(new Error(`read failed: ${t.name}`)),a.onload=()=>{const l=String(a.result??""),r=l.indexOf(",");s(r===-1?l:l.slice(r+1))},a.readAsDataURL(t)})}const Ys=9,ui=50*1024*1024;function oh(t,s){return s.length>=Ys?"count":s.reduce((a,l)=>a+oi(l),0)+ns(t.size)>ui?"budget":null}function hi(t,s){const n=[],a=[...s],l=new Map;for(const o of t){const c=oh(o,a);c===null?(n.push(o),a.push({byteLength:o.size})):l.set(c,(l.get(c)??0)+1)}if(l.size===0)return{accepted:n,notice:null};const r=[];for(const o of["count","budget"]){const c=l.get(o);c!==void 0&&(o==="count"?r.push(`${c} 个超出数量上限(最多同时附加 ${Ys} 个)`):r.push(`${c} 个超过 50MiB 上限`))}return{accepted:n,notice:`⚠️ ${r.join(" · ")}`}}function la(t){return{id:ii(),name:t.name,byteLength:t.size,file:t}}const ch=[{code:"TOO_MANY_FILES",re:/TOO_MANY_FILES|files exceed the per-request cap/i,zh:"文件数量超出上限"},{code:"FILES_TOO_LARGE",re:/FILES_TOO_LARGE|over the \d+-byte request budget/i,zh:"文件体积超出上限"}];function dh(t){for(const s of ch)if(s.re.test(t))return`${s.zh}(${s.code})`;return t}const uh=50;class hh{generation=0;session=null;entries=new Map;inFlight=new Map;ensureSession(s){return this.session!==s&&(this.dispose(),this.session=s),this.generation}peek(s){const n=this.entries.get(s);if(n!==void 0)return this.entries.delete(s),this.entries.set(s,n),n.url}async resolve(s,n,a){const l=this.peek(n.attachmentId);if(l!==void 0)return l;const r=this.inFlight.get(n.attachmentId);if(r!==void 0)return r;const o=(async()=>{const c=await a(n),d=mh(c.data),m=URL.createObjectURL(new Blob([d],{type:c.mediaType}));return s!==this.generation?(URL.revokeObjectURL(m),null):(this.entries.set(n.attachmentId,{url:m}),this.evictOverCap(),m)})();this.inFlight.set(n.attachmentId,o);try{return await o}finally{this.inFlight.delete(n.attachmentId)}}evictOverCap(){for(;this.entries.size>uh;){const s=this.entries.keys().next();if(s.done===!0)return;const n=this.entries.get(s.value);this.entries.delete(s.value),n!==void 0&&URL.revokeObjectURL(n.url)}}dispose(){for(const[,s]of this.entries)URL.revokeObjectURL(s.url);this.entries.clear(),this.inFlight.clear(),this.generation+=1}}const Cn=new hh;function mh(t){const s=atob(t),n=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)n[a]=s.charCodeAt(a);return n}const mi=i.createContext(null);function ph(t,s){const[n,a]=i.useState({phase:"loading"});return i.useEffect(()=>{if(s===null)return;let l=!1;const r=Cn.ensureSession(s.sessionId),o=Cn.peek(t.ref.attachmentId);if(o!==void 0){a({phase:"ready",url:o});return}return a({phase:"loading"}),Cn.resolve(r,t.ref,c=>s.client.attachmentGet(c)).then(c=>{l||c!==null&&a({phase:"ready",url:c})}).catch(c=>{l||a({phase:"error",message:c instanceof Error?c.message:String(c)})}),()=>{l=!0}},[s,t.ref.attachmentId,t.ref.mediaType,t.ref.byteLength]),n}function fh({block:t,index:s}){const n=i.useContext(mi),a=ph(t,n);return a.phase==="ready"?e.jsx("img",{className:"img-bub",src:a.url,alt:`图片 ${s+1}`,loading:"lazy"}):a.phase==="error"?e.jsxs("span",{className:"img-bub err",title:a.message,role:"img","aria-label":"图片加载失败",children:[e.jsx(ae,{name:"image",size:16}),"?"]}):e.jsx("span",{className:"img-bub pending","aria-hidden":!0})}function xh({images:t}){return t.length===0?e.jsx(e.Fragment,{}):e.jsx("div",{className:"img-rail",children:t.map((s,n)=>e.jsx(fh,{block:s,index:n},`${s.ref.attachmentId}#${n}`))})}function vh({files:t}){return t.length===0?e.jsx(e.Fragment,{}):e.jsx("div",{className:"hist-file-rail",children:t.map((s,n)=>e.jsxs("span",{className:"hist-file-chip",title:`${s.name} · ${s.attachmentId.slice(0,19)}…`,children:[e.jsx("span",{"aria-hidden":!0,children:e.jsx(ae,{name:"file-text",size:12})}),e.jsx("span",{className:"name",children:s.name}),e.jsx("span",{className:"size",children:gh(s.bytes)})]},`${s.attachmentId}#${n}`))})}function gh(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const jh=[["warn",/^⚠️?\s*/u],["ok",/^✅\s*/u],["info",/^ℹ️?\s*/u]];function At(t){for(const[s,n]of jh)if(n.test(t))return{variant:s,text:t.replace(n,"")};return{variant:"info",text:t}}function pi(t){const s=t.toLowerCase();return/截断|truncat|finish_reason|too long|超出.*长度|length limit/.test(s)||/截断/.test(t)?{hint:"回复被截断了——内容太长,模型只写了一半。",action:{label:"发送「继续」让模型接着写",text:"继续"}}:/\b401\b|\b403\b|unauthorized|api[ -]?key|密钥|鉴权|认证|invalid key/.test(s)?{hint:"模型服务的 Key 可能无效或过期——打开右上角「设置」检查密钥后重试。"}:/\b429\b|rate.?limit|限流|too many requests/.test(s)?{hint:"请求太频繁——稍等一会儿再发送。"}:/timeout|timed out|econn|enotfound|network|fetch failed|connection|网络/.test(s)?{hint:"连不上模型服务——检查网络后重试。"}:{hint:"可以重试一次;若再次失败,把任务拆小一点、换个说法再描述。"}}function bh({text:t,onAction:s}){const{lines:n,total:a}=Us(t),l=pi(t);return e.jsxs("div",{className:"simple-error",role:"alert",children:[e.jsxs("div",{className:"err-head",children:[e.jsx(ae,{name:"triangle-alert",size:13})," 出错了"]}),e.jsx("div",{className:"err-text",children:n.join(`
304
+ `)}),a>We?e.jsx("div",{className:"activity-foot",children:`⋯ 共 ${a} 行,已显示前 ${We} 行`}):null,e.jsxs("div",{className:"err-recovery",children:[e.jsx("span",{className:"label",children:"怎么办:"}),e.jsx("span",{children:l.hint}),l.action!==void 0&&s!==void 0?e.jsx("button",{type:"button",className:"wudao action",onClick:()=>s(l.action?.text??""),children:l.action.label}):null]})]})}const yh="[wudao-perm:accessibility]",Nh="[wudao-perm:screen-recording]",fi={kind:"accessibility",steps:["打开 系统设置 → 隐私与安全性 → 辅助功能","在列表里勾选 wudao(桌面版是 wudao-harness-desktop;终端里运行就勾选那个终端)","回到 wudao,点下面的「重试」"],retryText:"我已经开启了辅助功能权限,请再试一次刚才的电脑操作"},kh={kind:"screen-recording",steps:["打开 系统设置 → 隐私与安全性 → 屏幕录制","勾选 wudao(桌面版是 wudao-harness-desktop),然后完全退出并重新打开它","回到 wudao,点下面的「重试」"],retryText:"我已经开启了屏幕录制权限并重启了应用,请再截一次屏幕"};function ra(t){return t.includes(yh)?fi:t.includes(Nh)?kh:null}const wh={accessibility:"辅助功能","screen-recording":"屏幕录制"};function xi({text:t,onRetry:s}){const n=ra(t)??fi;return e.jsxs("div",{className:"perm-guide",role:"note","data-perm-kind":n.kind,children:[e.jsx("div",{className:"perm-head",children:`需要一次「${wh[n.kind]}」授权——按下面三步开:`}),e.jsx("ol",{className:"perm-steps",children:n.steps.map((a,l)=>e.jsx("li",{children:a},l))}),s!==void 0?e.jsx("button",{type:"button",className:"wudao action perm-retry",onClick:()=>s(n.retryText),children:"重试"}):null]})}function vi(t){return t.split(`
305
+ `).map(s=>({text:s,kind:Sh(s)}))}function Sh(t){return t.startsWith("diff --git ")||t.startsWith("new file")||t.startsWith("--- ")||t.startsWith("+++ ")?"file-header":t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"context"}const Ch={"file-header":"file",hunk:"hunk",add:"add",del:"del",context:"context"};function gi(t){if(!t.startsWith("diff --git "))return;const s=t.slice(13);let n=s.indexOf(" b/");for(;n>=0;){if(s.slice(0,n)===s.slice(n+3))return s.slice(0,n);n=s.indexOf(" b/",n+1)}const a=s.lastIndexOf(" b/");return a>=0?s.slice(0,a):s}function Eh(t){const s=new Set;for(const n of vi(t)){if(n.kind!=="file-header")continue;const a=gi(n.text);a!==void 0&&s.add(a)}return s}function ji({detail:t,className:s,as:n="div"}){const a=vi(t),l=n;return e.jsx(l,{className:`${s} dtx`,children:a.map((r,o)=>{const c=r.kind==="file-header"?gi(r.text):void 0;return e.jsxs(ce.Fragment,{children:[o>0?`
306
+ `:null,e.jsx("span",{className:`dtx-line dtx-${Ch[r.kind]}`,...c!==void 0?{"data-dtx-file":c}:{},children:r.text})]},o)})})}const zl=60,$h=60;function bi(t){const[s,n]=i.useState(zl),a=i.useRef(null),l=i.useRef(t);i.useEffect(()=>{t<l.current&&n(zl),l.current=t},[t]);const r=i.useCallback(()=>{n(d=>d+$h)},[]),o=t>s;i.useEffect(()=>{if(!o)return;const d=a.current;if(d===null||typeof IntersectionObserver>"u")return;const m=new IntersectionObserver(p=>{for(const g of p)g.isIntersecting&&r()});return m.observe(d),()=>m.disconnect()},[o,r,s]);const c=Math.min(s,t);return{visible:c,hidden:t-c,sentinelRef:a,hydrate:r}}function yi(t){return`(还有 ${t} 条更早的消息——向上滚动或点击加载)`}const Xs=ce.memo(function({entry:s,onAction:n,onOpenFile:a,forkN:l,fork:r,onForkTurn:o,running:c}){switch(s.kind){case"user":return e.jsxs("div",{className:"msg-user",children:[r===!0?e.jsx("span",{className:"fork-badge",children:"⑂"}):null,l!=null&&o!==void 0?e.jsx("button",{type:"button",className:"fork-act",title:"以这轮为起点开一条新线(原文带回输入框,可改后发送)",onClick:()=>o(l),children:"从这里岔开"}):null,s.images!==void 0&&s.images.length>0?e.jsx(xh,{images:s.images}):null,s.files!==void 0&&s.files.length>0?e.jsx(vh,{files:s.files}):null,s.text.trim()!==""?e.jsx("div",{className:"bub",children:Vs(s.text)}):null]});case"assistant":return e.jsxs(Yr,{children:[s.reasoning!==void 0&&s.reasoning!==""?e.jsx(aa,{text:s.reasoning,defaultOpen:!0}):null,e.jsx(Vr,{source:s.text}),s.durationMs!==void 0?e.jsx("div",{className:"reply-meta",children:`· ${Sr(s.durationMs)}`}):null,s.servedBy!==void 0?e.jsx("div",{className:"reply-meta","data-served-by":s.servedBy.model,children:`· 本轮由 ${s.servedBy.model}(降级)作答`}):null]});case"tool":return e.jsx(Dh,{entry:s,onOpenFile:a,onAction:n});case"edit":return e.jsx(si,{entry:s,running:c===!0,onOpenFile:a});case"board":return e.jsx(nh,{done:s.done,total:s.total,lines:s.lines});case"notice":return s.card===!0?e.jsx(Rh,{entry:s}):e.jsx(Mh,{entry:s});case"divider":return e.jsx("div",{className:"entry-divider",children:`${Rs}${Rs} ${s.text} ${Rs}${Rs}`});case"error":{const d=pi(s.text);return e.jsxs("div",{className:"entry-error-block",children:[e.jsx("div",{className:"entry-error",children:s.text}),e.jsxs("div",{className:"entry-error-hint",children:[e.jsx("span",{children:d.hint}),d.action!==void 0&&n!==void 0?e.jsx("button",{type:"button",className:"wudao action",onClick:()=>n(d.action?.text??""),children:d.action.label}):null]})]})}}});function Rh({entry:t}){const[s,n]=i.useState(!1),a=t.detail!==void 0&&t.detail.length>0,l=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inject-line",children:t.text}),a?e.jsx("span",{className:"inject-chev",children:s?e.jsx(et,{size:12}):e.jsx(bt,{size:12})}):null]});return e.jsxs("div",{className:"msg-a msg-inject",children:[e.jsxs("div",{className:"msg-sig",children:[e.jsx("span",{className:"sig-glyph",children:"注"}),e.jsx("span",{className:"sig-name",children:t.source??"系统注入"})]}),e.jsxs("div",{className:"reply-card",children:[a?e.jsx("button",{type:"button",className:"inject-head","aria-expanded":s,"aria-label":s?"收起注入全文":"展开注入全文",onClick:()=>n(!s),children:l}):e.jsx("div",{className:"inject-head",children:l}),s&&a?e.jsx("div",{className:"notice-detail",children:t.detail}):null]})]})}function Mh({entry:t}){const[s,n]=i.useState(!1),a=t.detail!==void 0&&t.detail.length>0,l=t.changes!==void 0&&t.changes.length>0,r=At(t.text);return e.jsxs("div",{className:"entry-notice",children:[e.jsxs("span",{className:"notice-bub","data-variant":r.variant,children:[r.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):r.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,r.text,a?e.jsx("button",{type:"button",className:"notice-exp","aria-expanded":s,"aria-label":s?"收起通知全文":"展开通知全文",onClick:()=>n(!s),children:s?e.jsx(et,{size:12}):e.jsx(bt,{size:12})}):null]}),s&&a?l?e.jsx(ji,{detail:t.detail??"",className:"notice-detail"}):e.jsx("div",{className:"notice-detail",children:t.detail}):null]})}function Th({entry:t,onAction:s}){const[n,a]=i.useState(!1),l=t.resultPreview??"",o=(t.isError===!0&&l!==""?ra(l):null)!==null?e.jsx(xi,{text:l,onRetry:s}):null;if(l==="")return t.isError?e.jsxs("div",{className:"result err",children:[" ↳ [error]",o]}):null;const{lines:c,total:d}=Us(l,n?Ws:We);return e.jsxs("div",{className:`result${t.isError?" err":""}`,"data-truncated":d>We,children:[` ↳ ${t.isError?"[error] ":""}${c.join(`
307
+ `)}`,d>We||n?e.jsx(na,{total:d,expanded:n,onToggle:()=>a(m=>!m)}):null,o]})}function Dh({entry:t,onOpenFile:s,onAction:n}){const[a,l]=i.useState(!0),r=t.isError?"err":"ok",o={ok:"✓",run:"◐",err:"✕"};return e.jsxs("div",{className:`toolcard${t.isError?" err":""}`,"data-status":r,"data-open":a,children:[e.jsxs("button",{type:"button",className:"head","aria-expanded":a,onClick:()=>l(!a),children:[e.jsx("span",{className:"mark",children:`${o[r]} `}),e.jsx("span",{className:"name",children:t.name}),t.summary?e.jsxs("span",{className:"args",children:["(",Bl[t.name]!==void 0?e.jsx(ct,{text:t.summary,lang:Bl[t.name]}):Oh.has(t.name)&&s!==void 0?e.jsx("button",{type:"button",className:"fv-chip",title:t.summary,onClick:c=>{c.stopPropagation(),s(t.summary??"")},children:t.summary}):t.summary,")"]}):null,e.jsx("span",{className:"chev","aria-hidden":!0,children:a?"▾":"▸"})]}),a?e.jsx(Th,{entry:t,onAction:n}):null]})}const Ah=new Set(["read_file","grep","glob","web_search","web_fetch"]),Bl={shell:"shell"},Oh=new Set(["write_file","read_file"]);function Tt(t,s){const n=(t.kind==="tool"?`${t.name}:${t.summary}`:t.kind==="edit"?t.path:t.kind==="board"?`${t.done}/${t.total}`:"text"in t?t.text:"").slice(0,8);return`${t.kind}#${s}#${n}`}function Ih(t){return t.kind==="tool"&&t.isError!==!0&&Ah.has(t.name)}function Lh(t,s){const n=t[s];if(n===void 0||n.kind!=="user"||n.text.startsWith("["))return null;let a=0;for(let l=s;l<t.length;l+=1){const r=t[l];r!==void 0&&r.kind==="user"&&!r.text.startsWith("[")&&(a+=1)}return a}function Ph(t){const s=[];let n=0;for(;n<t.length;){const a=t[n];if(Ih(a)){let l=n+1;for(;l<t.length;){const o=t[l];if(!(o.kind==="tool"&&o.isError!==!0&&o.name===a.name))break;l++}const r=t.slice(n,l);s.push(r.length>=2?{kind:"toolgroup",name:a.name,entries:r}:{kind:"entry",entry:a}),n=l}else if(a.kind==="notice"&&a.card!==!0){let l=n+1;for(;l<t.length;){const o=t[l];if(!(o.kind==="notice"&&o.card!==!0&&o.text===a.text))break;l++}const r=t.slice(n,l);s.push(r.length>=2?{kind:"noticegroup",text:a.text,entries:r}:{kind:"entry",entry:a}),n=l}else s.push({kind:"entry",entry:a}),n++}return s}function _h({name:t,entries:s,onOpenFile:n}){const[a,l]=i.useState(!1);return e.jsxs("div",{className:"toolgroup","data-open":a,children:[e.jsxs("button",{type:"button",className:"grp-head act-row","aria-expanded":a,onClick:()=>l(!a),children:[e.jsx("span",{className:"mark",children:"✓ "}),e.jsx("span",{className:"name",children:t}),e.jsx("span",{className:"count act-tail",children:` ×${s.length}`}),e.jsx("span",{className:"exp act-chev",children:a?e.jsx(et,{size:12}):e.jsx(bt,{size:12})})]}),a?s.map((r,o)=>e.jsx(Xs,{entry:r,onOpenFile:n},Tt(r,o))):null]})}function Fh({text:t,entries:s}){const[n,a]=i.useState(!1),l=At(t);return e.jsxs("div",{className:"noticegroup","data-open":n,children:[e.jsxs("button",{type:"button",className:"grp-head","data-variant":l.variant,"aria-expanded":n,onClick:()=>a(!n),children:[l.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):l.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,e.jsx("span",{className:"text",children:l.text}),e.jsx("span",{className:"count",children:` ×${s.length}`}),e.jsx("span",{className:"exp",children:n?e.jsx(et,{size:12}):e.jsx(bt,{size:12})})]}),n?s.map((r,o)=>e.jsx(Xs,{entry:r},Tt(r,o))):null]})}const zh=ce.memo(function({history:s,onAction:n,onOpenFile:a,onForkTurn:l,forkBadgeKeys:r,runningEditPaths:o}){const c=i.useMemo(()=>Ph(s),[s]),d=i.useMemo(()=>{const S=[];let R=0;for(const j of c)S.push(R),R+=j.kind==="entry"?1:j.entries.length;return S},[c]),m=bi(c.length),p=m.hidden,[g,v]=i.useState(null),N=S=>S.kind!=="entry"?null:S.entry.kind==="user"||S.entry.kind==="assistant"?S.entry.text:null;return e.jsxs(e.Fragment,{children:[p>0?e.jsx("div",{ref:m.sentinelRef,className:"history-hydrate-sentinel",onClick:m.hydrate,role:"button",tabIndex:0,onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&m.hydrate()},children:yi(p)}):null,c.slice(p).map((S,R)=>{const j=p+R,f=N(S),A=S.kind==="entry"?Tt(S.entry,j):S.kind==="toolgroup"?`grp#${S.name}#${j}#${S.entries.length}`:`ngrp#${S.text.slice(0,8)}#${j}#${S.entries.length}`;return e.jsxs(ce.Fragment,{children:[R>0?e.jsx("div",{className:"entry-gap"}):null,e.jsx("div",{className:"entry",onContextMenu:f===null?void 0:$=>{$.preventDefault(),v({x:$.clientX,y:$.clientY,text:f})},children:S.kind==="toolgroup"?e.jsx(_h,{name:S.name,entries:S.entries,onOpenFile:a}):S.kind==="noticegroup"?e.jsx(Fh,{text:S.text,entries:S.entries}):e.jsx(Xs,{entry:S.entry,onAction:n,onOpenFile:a,forkN:l!==void 0&&S.entry.kind==="user"?Lh(s,d[j]??j):null,fork:r!==void 0&&S.entry.kind==="user"?r.has(Tt(S.entry,d[j]??j)):void 0,onForkTurn:l,running:o!==void 0&&S.entry.kind==="edit"?o.has(S.entry.path):void 0})})]},A)}),g!==null?e.jsx(qr,{x:g.x,y:g.y,items:[{label:"复制文本",onSelect:()=>Ks(g.text)}],onClose:()=>v(null)}):null]})});function Bh({n:t,onCancel:s}){return e.jsxs("div",{className:"armed-branch",role:"status",children:[e.jsx("span",{className:"armed-text",children:`将从第 ${t} 轮开分支(原消息已带入,可修改后发送);发送即岔开,主线保留`}),e.jsx("button",{type:"button",className:"wudao action",onClick:s,children:"取消"})]})}function Kh({client:t,refreshTick:s}){const[n,a]=i.useState(null),[l,r]=i.useState(!1),[o,c]=i.useState(null),d=i.useCallback(()=>{t.branchLeaves().then(v=>{a(v)}).catch(()=>{a(null)})},[t]),m=i.useRef(!0);i.useEffect(()=>{if(m.current){m.current=!1;const v=setTimeout(d,0);return()=>{clearTimeout(v)}}d()},[d,s]),i.useEffect(()=>{l&&d()},[l,d]);const p=i.useCallback(v=>{c(null),t.switchBranch(v.n).then(N=>{c(N),d()}).catch(N=>{c(`⚠️ 切换失败:${N instanceof Error?N.message:String(N)}`)})},[t,d]);if(n===null||n.length<2&&!l)return null;const g=n.find(v=>v.isCurrent)??null;return e.jsxs("div",{className:"branch-bar",children:[e.jsx("button",{type:"button",className:"branch-chip","aria-expanded":l,onClick:()=>{r(v=>!v),c(null)},children:`⑂ ${g!==null?`第 ${g.n}/${n.length} 条线`:`${n.length} 条线`}`}),l?e.jsxs("div",{className:"branch-panel",children:[n.map(v=>e.jsxs("div",{className:`branch-row${v.isCurrent?" cur":""}`,children:[e.jsx("span",{className:"row-n",children:`${v.n}.`}),e.jsx("span",{className:"row-main",children:v.forkPreview!==""?`分叉自 “${v.forkPreview}”`:"从头开始"}),e.jsx("span",{className:"row-count",children:`${v.messageCount} 条消息`}),v.isCurrent?e.jsx("span",{className:"row-cur",children:"当前"}):e.jsx("button",{type:"button",className:"wudao action",onClick:()=>p(v),children:"切到这里"})]},v.leafKey)),o!==null?(()=>{const v=At(o);return e.jsxs("div",{className:"branch-note","data-variant":v.variant,children:[v.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):v.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,v.text]})})():null]}):null]})}const Wh=t=>t instanceof Error?t.message:String(t);function Ni(t){switch(t){case"fact":return"事实";case"preference":return"偏好";case"skill_note":return"技能心得";case"harness":return"协作心得";default:return t}}function ki(t){switch(t){case"project":return"本项目";case"user":return"个人";default:return t}}function Kl(t,s=Date.now()){const n=Date.parse(t);if(Number.isNaN(n))return"";const a=s-n;if(a<6e4)return"刚刚";const l=Math.floor(a/6e4);if(l<60)return`${l} 分钟前`;const r=Math.floor(l/60);if(r<24)return`${r} 小时前`;const o=Math.floor(r/24);return o<=30?`${o} 天前`:t.slice(0,10)}const Uh=(t,s=80)=>t.length<=s?t:`${t.slice(0,s-1)}…`;function wi(t){return typeof t!="object"||t===null||!Array.isArray(t.entries)?null:t.entries}function Hh({client:t,memorySignature:s}){const[n,a]=i.useState(null),[l,r]=i.useState(0),[o,c]=i.useState(!1),[d,m]=i.useState(null),[p,g]=i.useState(null),v=i.useCallback(()=>{t.memoryList().then(f=>{a(wi(f)),r(typeof f.blocked=="number"&&f.blocked>0?f.blocked:0)}).catch(()=>{a(null)})},[t]),N=i.useRef(!0);i.useEffect(()=>{if(N.current){N.current=!1;const f=setTimeout(v,0);return()=>{clearTimeout(f)}}v()},[v]);const S=i.useRef({sig:void 0,armed:!1});i.useEffect(()=>{const f=S.current;if(!f.armed){S.current={sig:s,armed:!0};return}s!==f.sig&&(S.current={sig:s,armed:!0},v())},[s,v]);const R=n?.filter(f=>f.status==="pending")??[];if(n===null||o||R.length===0)return null;const j=(f,A)=>{m(f),g(null),t.memoryDecide(f,A).then(()=>v()).catch($=>{g(`⚠️ 记忆操作失败:${Wh($)}`)}).finally(()=>m(null))};return e.jsxs("div",{className:"memory-review-card",role:"status",children:[e.jsxs("div",{className:"memory-review-head",children:[e.jsxs("span",{className:"memory-review-title",children:[e.jsx(ae,{name:"brain",size:13})," ",`有 ${R.length} 条记忆待你确认`]}),e.jsx("button",{type:"button",className:"wudao action",onClick:()=>c(!0),children:"稍后"})]}),e.jsx("div",{className:"hint",children:"模型替你记下的内容,确认后才会参与回忆"}),l>0?e.jsx("div",{className:"hint mem-blocked","data-blocked-count":l,children:`已拦 ${l} 条可疑学习输入(未入库——明细在 .wudao/memory-blocked.jsonl)`}):null,R.map(f=>e.jsxs("div",{className:"mem-row","data-mem-id":f.id,children:[e.jsx("span",{className:"mem-badge",children:"待审"}),e.jsxs("span",{className:"mem-main",children:[e.jsx("span",{className:"mem-kind",children:`${Ni(f.kind)} · ${ki(f.scope)}`}),e.jsx("span",{className:"mem-content",children:Uh(f.content)})]}),e.jsxs("span",{className:"mem-acts",children:[e.jsx("button",{type:"button",className:"wudao action",disabled:d!==null,onClick:()=>j(f.id,"ok"),children:"确认"}),e.jsx("button",{type:"button",className:"wudao danger",disabled:d!==null,onClick:()=>j(f.id,"del"),children:"丢弃"})]})]},f.id)),p!==null?(()=>{const f=At(p);return e.jsxs("div",{className:"mem-note","data-variant":f.variant,children:[f.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):f.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,f.text]})})():null]})}function Si(t){return t.busyTools.length>0?"tools":t.answer!==""?"answering":t.reasoning!==""?"thinking":"working"}const qh={thinking:"正在思考",tools:"正在执行操作",answering:"正在回复",working:"正在处理"},Gh=15e3;function Ci(t,s){const[n,a]=i.useState(null),l=i.useRef(null);return i.useEffect(()=>{if(!t){l.current=null,a(null);return}l.current=Date.now();let r=null;const o=()=>{l.current!==null&&a(Math.floor((Date.now()-l.current)/1e3))},c=setTimeout(()=>{o(),r=setInterval(o,1e3)},s);return()=>{clearTimeout(c),r!==null&&clearInterval(r)}},[t,s]),n}function Vh(t){return`已进行 ${t} 秒`}function Yh({busy:t,live:s,queued:n=[],onRecall:a}){const l=Ci(t,Gh);if(!t)return null;const r=Si(s),o=r==="thinking"||r==="working";return e.jsxs("div",{className:"turnstatus","data-phase":r,children:[e.jsxs("div",{className:"ts-head",children:[e.jsx("span",{className:o?"label shimmer":"label",children:qh[r]}),l!==null?e.jsx("span",{className:"clock",children:Vh(l)}):null]}),n.map((c,d)=>e.jsxs("div",{className:"queue-line",children:[e.jsx(ae,{name:"hourglass",size:11}),` 将在下一步前注入:${Xr(Vs(c),48)}`,a!==void 0?e.jsx("button",{type:"button",className:"recall","aria-label":"撤回这条排队消息",title:"趁还没被读取,撤回这条",onClick:()=>a(d,c),children:"↩ 撤回"}):null]},`q${d}`))]})}const Xh={thinking:"思考中",tools:"执行中",answering:"回复中",working:"处理中"},Jh=1e3,Qh=t=>[`系统提示 ~${Ae(t.systemTokens)}`,`工具定义 ~${Ae(t.toolsTokens)}`,`消息历史 ~${Ae(t.messagesTokens)}`,...t.imagesTokens!==void 0&&t.imagesTokens>0?[`图片 ~${Ae(t.imagesTokens)}`]:[],`可用 ~${Ae(t.availableTokens)}`].join(`
308
+ `);function Zh({status:t,ctxInfo:s,stale:n,sessionName:a,buddy:l,workspaceName:r,workspacePath:o}){const[c,d]=i.useState(null),m=i.useRef(s);m.current=s;const p=i.useRef(null),g=t?.ctxTokens?.used??null,v=t!==null&&t.busy&&t.pendingPermission===null,N=Ci(t!==null&&t.busy,Jh),S=v?Xh[Si(t.live)]:null;i.useEffect(()=>{if(l===!0)return;const j=m.current;if(j===void 0||g===null)return;const f=p.current;if(f!==null&&Math.abs(g-f)<=1e3)return;let A=!1;return j().then($=>{A||(p.current=g,d($))},()=>{A||d(null)}),()=>{A=!0}},[g]);const R=[];if(t!==null){if(l===!0)r!==void 0&&r!==""&&(R.push(e.jsx("span",{title:o,children:`工作区 ${r}`},"workspace")),typeof t.gitBranch=="string"&&t.gitBranch!==""&&R.push(e.jsx("span",{className:"seg-branch",title:"当前工作分支",children:t.gitBranch},"branch")));else if(R.push(`wudao · ${a!==void 0&&a!==""?a:t.sessionId.slice(0,8)}`),typeof t.gitBranch=="string"&&t.gitBranch!==""&&R.push(e.jsx("span",{className:"seg-branch",title:"当前工作分支",children:t.gitBranch},"branch")),t.ctxTokens!==null&&R.push(e.jsxs("span",{className:"seg-ctx",title:c!==null?Qh(c):"上下文使用量",children:[`ctx ${t.ctxTokens.used===null?"…":Ae(t.ctxTokens.used)}/${Ae(t.ctxTokens.window)}`,t.ctxTokens.nearLimit?e.jsx("span",{className:"warn",children:e.jsx(ae,{name:"triangle-alert",size:11})}):null]},"ctx")),typeof t.cachePercent=="number"&&R.push(e.jsx("span",{className:"cache",children:`cache ${Math.round(t.cachePercent)}%`},"cache")),t.goal!=null){const j=t.goal,f=j.budgetTokens!==void 0?`已花 ${Ae(j.usedTokens)} / 预算 ${Ae(j.budgetTokens)}`:`已花 ${Ae(j.usedTokens)}`;R.push(e.jsx("span",{className:j.status==="budget_limited"?"seg-goal warn":"seg-goal",title:`目标:${j.objective}
309
+ ${f}(输入 ${Ae(j.inputTokens)} · 输出 ${Ae(j.outputTokens)})
310
+ 任务进度 ${j.progress.done}/${j.progress.total}`,children:j.status==="budget_limited"?`目标预算已尽 · ${j.objective.slice(0,24)}${j.objective.length>24?"…":""}(${f},任务 ${j.progress.done}/${j.progress.total})`:`目标 ${j.objective.slice(0,24)}${j.objective.length>24?"…":""}(${f},任务 ${j.progress.done}/${j.progress.total})`},"goal"))}t.boardProgress!==null&&R.push(e.jsxs("span",{className:"board",children:[e.jsx(ae,{name:"list-checks",size:11})," ",`${t.boardProgress.done}/${t.boardProgress.total}`]},"board")),t.bg.spawned>0&&R.push(`bg ${t.bg.active}/${t.bg.spawned}`),t.sidecar!==null&&t.sidecar.checks>0&&(R.push(`sidecar ${t.sidecar.checks}`),t.sidecar.breakerOpen&&R.push(e.jsx("span",{className:"warn",children:e.jsx(ae,{name:"shield-x",size:11})},"breaker")))}return R.length===0?null:e.jsxs("div",{className:"statusline","data-stale":n===!0?"":void 0,children:[R.map((j,f)=>e.jsxs(ce.Fragment,{children:[f>0?e.jsx("span",{className:"sep",children:Oc}):null,j]},f)),v&&N!==null&&S!==null?e.jsx("span",{className:"seg-busy",children:`▌${S} · ${N}s`}):null]})}const Wl=100;function em(){return{entries:[],pointer:0,draft:null}}function En(t,s){if(s===""||t.entries[t.entries.length-1]===s)return{entries:t.entries,pointer:t.entries.length,draft:null};const n=[...t.entries,s];return n.length>Wl&&n.splice(0,n.length-Wl),{entries:n,pointer:n.length,draft:null}}function tm(t,s){return t.pointer<=0?null:{entries:t.entries,pointer:t.pointer-1,draft:t.pointer===t.entries.length?s:t.draft}}function sm(t){return t.pointer>=t.entries.length?null:{entries:t.entries,pointer:t.pointer+1,draft:t.draft}}function Ul(t){return t.pointer<t.entries.length?t.entries[t.pointer]??"":t.draft??""}function Un(t,s){const a=t.slice(0,Math.max(0,Math.min(s,t.length))).split(`
311
+ `);return{row:a.length-1,col:(a[a.length-1]??"").length}}function nm(t,s){const{row:n}=Un(t,s);return t.split(`
312
+ `)[n]??""}function am(t,s){const n=Math.max(0,Math.min(s,t.length));return n>0&&t[n-1]==="\\"?{kind:"newline",value:t.slice(0,n-1)+`
313
+ `+t.slice(n),caret:n}:{kind:"submit",text:t}}const lm=[{label:"总结要点",text:"总结这个文件的要点"},{label:"提炼待办",text:"从这个文件里提炼出我的待办事项"},{label:"看看这是啥",text:"这个文件是讲什么的"}],rm=[{label:"看看数据",text:"看看这份数据有什么值得注意的"},{label:"总结要点",text:"总结这个文件的要点"},{label:"提炼待办",text:"从这个文件里提炼出我的待办事项"}],Hl=[{label:"帮我处理",text:"帮我处理这个文件"},{label:"总结要点",text:"总结这个文件的要点"},{label:"看看这是啥",text:"这个文件是讲什么的"}],im=new Set(["txt","md","pdf","docx"]),om=new Set(["xlsx","csv"]);function cm(t){const s=t.lastIndexOf(".");return s===-1?"":t.slice(s+1).toLowerCase()}function dm(t){const s=t[0];if(s===void 0)return Hl;const n=cm(s);return im.has(n)?lm:om.has(n)?rm:Hl}const $n=[{mode:"ask",label:"ask",hint:"每次询问:每个工具执行前都会确认,最安全",risky:!1},{mode:"workspace",label:"accept",hint:"默认·接受编辑:工作区内读写与只读命令(git status 等)放行;其余命令、网络、MCP 仍确认",risky:!1},{mode:"auto",label:"auto",hint:"全自动:全部放行,不再询问",risky:!0},{mode:"plan",label:"plan",hint:"只读探查:只允许读取与只读命令(git status 等);写文件/其余命令一律拒绝,完成方案后切回 accept/auto 执行",risky:!1}],um="我了解风险:完全访问会不经确认执行写入和命令";function Ei(t){return t==="auto"?"auto":t==="ask"?"ask":t==="plan"?"plan":"workspace"}function ia({value:t,onChange:s,disabled:n=!1,direction:a="up"}){const[l,r]=i.useState(!1),[o,c]=i.useState(!1),d=i.useRef(null),m=i.useRef(null),p=(v=!0)=>{r(!1),c(!1),v&&setTimeout(()=>{document.activeElement===document.body&&m.current?.focus()},0)};i.useEffect(()=>{if(!l)return;const v=N=>{d.current!==null&&!d.current.contains(N.target)&&p(!1)};return document.addEventListener("pointerdown",v),()=>document.removeEventListener("pointerdown",v)},[l]);const g=$n.find(v=>v.mode===t)??$n[0];return e.jsxs("div",{className:a==="down"?"pop down":"pop",ref:d,onKeyDown:v=>{v.key==="Escape"&&(v.preventDefault(),p())},children:[e.jsxs("button",{type:"button",ref:m,className:`chip${t!=="workspace"?" sel":""}`,"data-mode":t,disabled:n,"aria-haspopup":"menu","aria-expanded":l,title:"权限档(四档可选)",onClick:()=>{c(!1),r(!l)},children:[g.label,e.jsx("span",{className:"caret","aria-hidden":!0,children:"▾"})]}),l?e.jsx("div",{className:"menu",role:"menu","aria-label":"权限档",children:$n.map(v=>{const N=t===v.mode,S=v.risky&&!N,R=S&&o;return e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":N,className:`mi${N?" on":""}`,"data-mode":v.mode,title:v.hint,onClick:()=>{if(S&&!o){c(!0);return}s(v.mode),p()},children:[R?e.jsx("span",{className:"confirm",children:um}):e.jsx("span",{className:"mlabel",children:v.label}),v.risky?e.jsx("span",{className:"warned",children:R?"再点一次确认":"需确认"}):null]},v.mode)})}):null]})}const Rn="\0recent";function hm({label:t,provider:s,choices:n,recent:a,disabled:l=!1,onPick:r,onPersistDefault:o}){const[c,d]=i.useState(!1),[m,p]=i.useState(null),g=i.useRef(null),v=i.useRef(null),N=(y=!0)=>{d(!1),p(null),y&&setTimeout(()=>{document.activeElement===document.body&&v.current?.focus()},0)};i.useEffect(()=>{if(!c)return;const y=q=>{g.current!==null&&!g.current.contains(q.target)&&N(!1)};return document.addEventListener("pointerdown",y),()=>document.removeEventListener("pointerdown",y)},[c]);const S=[],R=new Map;for(const y of n){let q=R.get(y.provider);q===void 0&&(q=[],R.set(y.provider,q),S.push(y.provider)),q.push(y)}const j=new Set,f=[];for(const y of a??[]){const q=`${y.provider}/${y.model}`;j.has(q)||R.get(y.provider)?.some(D=>D.model===y.model)===!0&&(j.add(q),f.push(y))}const A=m??(s!==void 0&&R.has(s)?s:void 0)??S[0],$=f.length>0&&A===Rn;return e.jsxs("div",{className:"pop",ref:g,onKeyDown:y=>{y.key==="Escape"&&(y.preventDefault(),N())},children:[e.jsxs("button",{type:"button",ref:v,className:"chip model",disabled:l,"aria-haspopup":"menu","aria-expanded":c,title:`${t} — 切换模型(会话内,下一轮生效;跨供应商行经 /provider 切换端点,缓存全冷)`,onClick:()=>{p(null),d(!c)},children:[e.jsx("span",{className:"chip-label",children:t}),e.jsx("span",{className:"caret","aria-hidden":!0,children:"▾"})]}),c?e.jsx("div",{className:"menu model-menu",role:"menu","aria-label":"切换模型",children:n.length===0||A===void 0?e.jsx("div",{className:"muted",children:"暂无可切换的模型"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mroot",role:"group","aria-label":"供应商",children:[f.length>0?e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":!1,className:`mi mprov mrec${$?" mfoc":""}`,"data-recent":"true",title:"最近使用的模型",onClick:()=>{p(Rn)},onMouseEnter:()=>{p(Rn)},children:[e.jsx("span",{className:"mlabel",children:"最近使用"}),e.jsx("span",{className:"msub",children:`${f.length} 个`})]},"recent"):null,S.map(y=>{const q=s!==void 0&&y===s;return e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":q,className:`mi mprov${q?" on":""}${y===A?" mfoc":""}`,"data-provider":y,title:`选择 ${y} 的模型`,onClick:()=>{p(y)},onMouseEnter:()=>{p(y)},children:[e.jsx("span",{className:"mlabel",children:y}),e.jsx("span",{className:"msub",children:`${R.get(y).length} 个模型`})]},y)})]}),e.jsxs("div",{className:"mpane",role:"group","aria-label":$?"最近使用的模型":`${A} 的模型`,children:[$?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mgroup","data-recent":"true",children:"最近使用"}),f.map(y=>{const q=!Fs(y,s),D=t===y.model&&(s===void 0||s===y.provider);return e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":D,className:`mi${D?" on":""}`,"data-model":y.model,"data-provider":y.provider,title:q?`submit /provider ${y.provider} — 切换端点,历史全量重处理(缓存全冷)`:`submit /model ${y.model}`,onClick:()=>{r(y.model,y.provider),N()},children:[e.jsx("span",{className:"mlabel",children:y.model}),e.jsx("span",{className:"msub",children:y.provider})]},`${y.provider}/${y.model}`)})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mgroup","data-provider":A,children:A}),R.get(A).map(y=>{const q=!Fs(y,s),D=t===y.model&&(s===void 0||s===y.provider);return e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":D,className:`mi${D?" on":""}`,"data-model":y.model,"data-provider":y.provider,title:q?`submit /provider ${y.provider} — 切换端点,历史全量重处理(缓存全冷)`:`submit /model ${y.model}`,onClick:()=>{r(y.model,y.provider),N()},children:[e.jsx("span",{className:"mlabel",children:y.model}),y.source==="env"?e.jsx("span",{className:"msub",children:"env"}):null]},`${y.provider}/${y.model}`)})]}),o!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"menu-sep"}),e.jsx("button",{type:"button",role:"menuitem",className:"mi foot","data-action":"persist-default",onClick:()=>{o(),N()},children:e.jsx("span",{className:"mlabel",children:"设为默认(下次启动)"})})]}):null]})]})}):null]})}function mm({efforts:t,current:s,disabled:n=!1,onPick:a,providerLabel:l,onPersistDefault:r}){const[o,c]=i.useState(!1),d=i.useRef(null),m=i.useRef(null),p=(g=!0)=>{c(!1),g&&setTimeout(()=>{document.activeElement===document.body&&m.current?.focus()},0)};return i.useEffect(()=>{if(!o)return;const g=v=>{d.current!==null&&!d.current.contains(v.target)&&p(!1)};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[o]),e.jsxs("div",{className:"pop",ref:d,onKeyDown:g=>{g.key==="Escape"&&(g.preventDefault(),p())},children:[e.jsxs("button",{type:"button",ref:m,className:`chip${s!==null?" sel":""}`,disabled:n,"aria-haspopup":"menu","aria-expanded":o,title:"推理强度(会话内,下一轮生效)",onClick:()=>{c(!o)},children:[e.jsx(Fo,{size:14}),s??"强度",e.jsx("span",{className:"caret","aria-hidden":!0,children:"▾"})]}),o?e.jsxs("div",{className:"menu",role:"menu","aria-label":"推理强度",children:[t.map(g=>{const v=g===s;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":v,className:`mi${v?" on":""}`,"data-effort":g,onClick:()=>{a(g),p()},children:e.jsx("span",{className:"mlabel",children:g})},g)}),r!==void 0&&l!==void 0?e.jsx("button",{type:"button",className:"mf","data-action":"persist-effort-default",title:"把当前强度存为该供应商的注册表绑定(覆盖跟随全局;模型不受影响)",onClick:()=>{r(),p()},children:`设为 ${l} 默认`}):null]}):null]})}const pt={token:"",selected:0,dismissed:null},pm=6,fm=80;function xm(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function vm(t){if(t!==null&&t.clientWidth>0){const s=Number.parseFloat(window.getComputedStyle(t).fontSize);return Math.max(16,Math.floor(t.clientWidth/((Number.isFinite(s)?s:13)*.62)))}return fm}function gm(t,s){let n=0;for(const a of t.split(`
314
+ `))n+=Math.max(1,Math.ceil(a.length/s));return Math.min(pm,Math.max(1,n))}function jm(t){return/(?:^|\s)@([^\s@]+)$/.exec(t)?.[1]}function $i(t){const{busy:s,mode:n,commands:a,connected:l,onSubmit:r,onInterrupt:o,onShield:c,onCycleMode:d,draft:m,onDraftApplied:p,mention:g,onMentionApplied:v,idlePlaceholder:N,busyPlaceholder:S,controlsLead:R,controlsPrefix:j,controlsSuffix:f,slashChip:A,onSideAsk:$,onBufferChange:y,onImagesChange:q,imageSeed:D,onImageSeedApplied:V,onFilesChange:H,fileSeed:X,onFileSeedApplied:W,modelLabel:z,modelProvider:F,modelChoices:M,modelRecent:P,onPickModel:T,onPersistModelDefault:U,effort:Q,efforts:se,onPickEffort:de,effortProviderLabel:le,onPersistEffortDefault:K}=t,[O,x]=i.useState(""),[b,k]=i.useState(em),[w,E]=i.useState(pt),[G,ee]=i.useState(!1),me=i.useRef(null),ye=i.useRef({composing:!1,endedAt:0}),Ne=i.useId(),[he,Ee]=i.useState([]),ve=i.useRef([]),Re=L=>{ve.current=L,Ee(L),q?.(L)},[qe,Fe]=i.useState(null),Ie=i.useRef(null),[pe,ze]=i.useState([]),Me=i.useRef([]),Le=L=>{Me.current=L,ze(L),H?.(L)},Ge=i.useRef(null),[$e,_]=i.useState(!1),Y=i.useRef(!1),J=i.useRef(0),[ie,ge]=i.useState(!1);i.useEffect(()=>{D!==void 0&&(Re(D.drafts),V?.())},[D?.nonce]),i.useEffect(()=>{X!==void 0&&(Le(X.drafts),W?.())},[X?.nonce]);const ne=L=>{if(Y.current)return;const te=L===null?[]:[...L];if(te.length===0)return;const{accepted:ue,notice:xe}=hi(te,Me.current);ue.length>0&&Le([...Me.current,...ue.map(oe=>la(oe))]),Fe(xe)},re=L=>{const te=Me.current;te[L]!==void 0&&(Le(te.filter((ue,xe)=>xe!==L)),Fe(null))},fe=L=>{if(Y.current)return;const te=L===null?[]:[...L];if(te.length===0)return;const{accepted:ue,notice:xe}=ci(te,ve.current);ue.length>0&&Re([...ve.current,...ue.map(oe=>di(oe))]),Fe(xe)},je=L=>{const te=ve.current,ue=te[L];ue!==void 0&&(Ls(ue),Re(te.filter((xe,oe)=>oe!==L)),Fe(null))};i.useEffect(()=>()=>{if(q===void 0)for(const L of ve.current)Ls(L)},[]);const Ve=L=>{x(L),y?.(L)};i.useEffect(()=>{m!==void 0&&(Ve(m.text),E(pt),me.current?.focus(),p?.())},[m?.nonce,m?.text]),i.useEffect(()=>{if(g===void 0)return;const L=O===""||/\s$/.test(O)?"":" ";Ve(`${O}${L}@${g.path}`),E(pt),me.current?.focus(),v?.()},[g?.nonce,g?.path]);const ht=(L,te)=>{Ve(L);const ue=te??L.length;requestAnimationFrame(()=>{me.current?.setSelectionRange(ue,ue)})},Ot=nm(O,me.current?.selectionStart??O.length),Be=pu(Ot),Pe=Be===void 0?[]:fu(a,Be),Je=w.token===Be?Math.min(w.selected,Math.max(0,Pe.length-1)):0,It=Be!==void 0&&Pe.length>0&&w.dismissed!==Be,ls=jm(Ot),Lt=L=>{const{row:te}=Un(O,me.current?.selectionStart??O.length),ue=O.split(`
315
+ `);ue[te]=xu(ue[te]??"",L);const xe=ue.join(`
316
+ `);ht(xe),E({token:L,selected:0,dismissed:null})},st=L=>{if(!l||Y.current)return;const te=L??O;if(te.trim()===""&&ve.current.length===0&&Me.current.length===0)return;if(G&&$!==void 0&&te.trim()!==""){Ve(""),E(pt),$(te.trim()),k(En(b,te)),ee(!1);return}if(G&&ee(!1),ve.current.length===0&&Me.current.length===0){Ve(""),E(pt),te.trim()!==""&&(r(te),k(En(b,te)));return}const ue=ve.current,xe=Me.current;Y.current=!0,_(!0),(async()=>{let oe=!1;try{const Ke=[];for(const Se of ue)Ke.push({data:await Fl(Se.file),mediaType:Se.mediaType});const Oe=[];for(const Se of xe)Oe.push({data:await Fl(Se.file),name:Se.name});const yt=Oe.length>0?[Oe]:[];oe=await r(te,Ke.length>0?Ke:void 0,...yt)!==!1}catch{oe=!1}if(Y.current=!1,_(!1),!!oe){for(const Ke of ue)Ls(Ke);Re([]),Le([]),Fe(null),Ve(""),E(pt),te.trim()!==""&&k(En(b,te))}})()},rs=()=>{me.current?.focus(),!O.startsWith("/")&&(ht(`/${O}`,1),E(pt))},Pt=pe.length>0&&O.trim()===""?dm(pe.map(L=>L.name)):[],is=L=>{Ve(L),st(L)},Js=L=>{if(!Ue(L.nativeEvent,ye.current,Date.now())){if(It){if(L.key==="Tab"&&!L.ctrlKey&&!L.metaKey||L.key==="Enter"&&Be!==Pe[Je]?.name){L.preventDefault();const te=Pe[Je]??Pe[0];te!==void 0&&Lt(te.name);return}if(L.key==="Escape"){L.preventDefault(),E({token:Be??"",selected:0,dismissed:Be});return}if(L.key==="ArrowUp"){L.preventDefault(),E({token:Be??"",selected:Math.max(0,Je-1),dismissed:null});return}if(L.key==="ArrowDown"){L.preventDefault(),E({token:Be??"",selected:Math.min(Pe.length-1,Je+1),dismissed:null});return}}if(L.key==="Tab"&&L.shiftKey&&!L.ctrlKey&&!L.metaKey){L.preventDefault(),d();return}if(L.key==="Enter"&&!L.shiftKey&&!L.metaKey&&!L.ctrlKey&&!L.altKey){L.preventDefault();const te=am(O,me.current?.selectionStart??O.length);te.kind==="submit"?st():ht(te.value,te.caret);return}if(L.key==="ArrowUp"||L.key==="ArrowDown"){const te=Un(O,me.current?.selectionStart??O.length),ue=O.split(`
317
+ `);if(L.key==="ArrowUp"&&te.row===0){const xe=tm(b,O);xe!==null&&(L.preventDefault(),k(xe),ht(Ul(xe)));return}if(L.key==="ArrowDown"&&te.row===ue.length-1){const xe=sm(b);xe!==null&&(L.preventDefault(),k(xe),ht(Ul(xe)))}return}if(L.key==="Escape"&&s){if(document.querySelector(".menu, .ctx-backdrop, .search-scrim, .ws-backdrop, .modal, .scrim")!==null)return;L.preventDefault(),o()}}};i.useEffect(()=>{me.current?.focus()},[]);const _t=L=>{L.preventDefault(),J.current+=1,ge(!0)},Qs=L=>{L.preventDefault(),ge(!0)},os=()=>{J.current=Math.max(0,J.current-1),J.current===0&&ge(!1)},nt=L=>{L.preventDefault(),J.current=0,ge(!1);const te=[...L.dataTransfer?.files??[]],ue=te.filter(oe=>oe.type.startsWith("image/")),xe=te.filter(oe=>!oe.type.startsWith("image/"));ue.length>0&&fe(ue),xe.length>0&&ne(xe)};return e.jsxs("div",{className:"inputarea",children:[It?e.jsx("div",{className:"slashmenu",role:"listbox","aria-activedescendant":Pe[Je]!==void 0?`${Ne}-opt-${Pe[Je].name}`:void 0,children:(()=>{const{start:L,rows:te}=ju(Pe.length,Je),ue=Pe.slice(L,L+te),xe=Pe.length-(L+te);return e.jsxs(e.Fragment,{children:[ue.map((oe,Ke)=>{const Oe=L+Ke===Je;return e.jsxs("div",{id:`${Ne}-opt-${oe.name}`,className:`row${Oe?" sel":""}`,role:"option","aria-selected":Oe,onMouseDown:yt=>{yt.preventDefault(),Lt(oe.name)},children:[`${Oe?"›":" "}/${oe.name}`,oe.args?e.jsx("span",{className:"args",children:`${oe.name.endsWith(":")?"":" "}${oe.isSensitive===!0?"<redacted>":oe.args}`}):null,oe.description?e.jsx("span",{className:"desc",children:` ${oe.description}`}):null]},oe.name)}),xe>0?e.jsx("div",{className:"more",children:` … 还有 ${xe} 项(↓ 滚动)`}):null]})})()}):null,e.jsxs("div",{className:`composer${ie?" dragover":""}`,onDragEnter:_t,onDragOver:Qs,onDragLeave:os,onDrop:nt,children:[he.length>0?e.jsx("div",{className:"img-rail","data-count":he.length,children:he.map((L,te)=>e.jsxs("div",{className:"img-thumb","data-name":L.name,children:[e.jsx("img",{src:L.url,alt:L.name}),e.jsx("button",{type:"button",className:"rm","aria-label":$e?"提交中,暂不能移除":`移除 ${L.name}`,title:$e?"提交中,暂不能移除":`移除 ${L.name}`,disabled:$e,onClick:()=>je(te),children:e.jsx(es,{size:11})})]},L.id))}):null,pe.length>0?e.jsx("div",{className:"file-rail","data-count":pe.length,children:pe.map((L,te)=>e.jsxs("div",{className:"file-card","data-name":L.name,children:[e.jsx("span",{className:"glyph","aria-hidden":!0,children:e.jsx(ae,{name:"file-text",size:13})}),e.jsxs("span",{className:"meta",children:[e.jsx("span",{className:"name",children:L.name}),e.jsx("span",{className:"size",children:xm(L.byteLength)})]}),e.jsx("button",{type:"button",className:"rm","aria-label":$e?"提交中,暂不能移除":`移除 ${L.name}`,title:$e?"提交中,暂不能移除":`移除 ${L.name}`,disabled:$e,onClick:()=>re(te),children:e.jsx(es,{size:11})})]},L.id))}):null,Pt.length>0?e.jsx("div",{className:"file-rail intent-row","data-count":Pt.length,children:Pt.map(L=>e.jsx("button",{type:"button",className:"chip intent",disabled:!l||$e,onClick:()=>is(L.text),children:L.label},L.label))}):null,e.jsx("textarea",{ref:me,className:"wudao-input composer-ta",value:O,rows:gm(O,vm(me.current)),placeholder:s?S??"它在忙,可继续打字插话(发送「排队」)":N??"吩咐悟道——/ 选命令,@ 引用文件",spellCheck:!1,onChange:L=>Ve(L.target.value),onCompositionStart:()=>{ye.current=He(ye.current)},onCompositionEnd:()=>{ye.current=_e(ye.current,Date.now())},onKeyDown:Js}),e.jsxs("div",{className:"composer-tools",children:[R,e.jsx("input",{ref:Ie,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:L=>{fe(L.target.files),L.target.value=""}}),e.jsx("input",{ref:Ge,type:"file","data-lane":"file",multiple:!0,hidden:!0,onChange:L=>{ne(L.target.files),L.target.value=""}}),e.jsxs("button",{type:"button",className:"chip attach",onClick:()=>Ie.current?.click(),disabled:!l,title:"添加图片(最多 9 张,总量 ≤ 20MiB;也可直接拖入)","aria-label":"添加图片",children:[e.jsx(zo,{size:14}),he.length>0?e.jsx("span",{className:"n",children:he.length}):null]}),e.jsxs("button",{type:"button",className:"chip attachfile",onClick:()=>Ge.current?.click(),disabled:!l,title:"添加文件(最多 9 个,总量 ≤ 50MiB;也可直接拖入)","aria-label":"添加文件",children:[e.jsx(Zn,{size:14}),pe.length>0?e.jsx("span",{className:"n",children:pe.length}):null]}),j,A===!0?e.jsx("button",{type:"button",className:"chip slash",onClick:rs,title:"命令菜单",children:"/"}):null,$!==void 0?e.jsx("button",{type:"button",className:`chip sideqa${G?" on":""}`,onClick:()=>{ee(L=>!L),me.current?.focus()},"aria-pressed":G,title:"顺便问:不打断主任务,旁路问一句(发送后自动切回主线)",children:"顺便问"}):null,e.jsx(ia,{value:Ei(n),onChange:c,disabled:!l}),z!=null&&M!=null?e.jsx(hm,{label:z,provider:F,choices:M,recent:P??void 0,disabled:!l,onPick:(L,te)=>T?.(L,te),onPersistDefault:U}):null,se!=null&&se.length>0?e.jsx(mm,{efforts:se,current:Q??null,disabled:!l,onPick:L=>de?.(L),...le!==void 0&&K!==void 0?{providerLabel:le,onPersistDefault:K}:{}}):null,s?e.jsxs("button",{type:"button",className:"chip interrupt",onClick:o,disabled:!l,children:[e.jsx(Bo,{size:12}),"停止 (Esc)"]}):null,e.jsxs("div",{className:"composer-right",children:[f,e.jsx("button",{type:"button",className:`send${O.trim()===""&&he.length===0?" off":""}`,onClick:()=>st(),disabled:!l||$e||O.trim()===""&&he.length===0,"aria-label":"发送",children:e.jsx(Ko,{size:14})})]})]})]}),ls!==void 0?e.jsx("div",{className:"hint",children:`@${ls} → 发送时会附上(相对工作区根)`}):null,qe!==null?e.jsx("span",{className:"hint img-notice",children:qe}):null,l?null:e.jsx("span",{className:"hint",children:"离线——正在等待服务恢复;草稿已保留"})]})}function bm(t){return`(旁路问答转入主线)
318
+ 问:${t.question}
319
+ 答:${t.answer}`}function Ri({qas:t,onPromote:s}){return t.length===0?null:e.jsx("div",{className:"sideqa-lane","data-sideqa-lane":!0,children:t.map(n=>e.jsxs("div",{className:"sideqa","data-sideqa":!0,children:[e.jsx("div",{className:"sideqa-tag",children:"旁路问答"}),e.jsx("div",{className:"sideqa-q",children:n.question}),e.jsx("div",{className:"sideqa-a",children:n.answer}),e.jsxs("div",{className:"sideqa-foot",children:[e.jsxs("span",{className:"sideqa-rounds",children:[n.rounds," 轮"]}),e.jsx("button",{type:"button",className:"sideqa-promote",onClick:()=>{s(n)},children:"转入主线"})]})]},n.id))})}function ym(t){const s=[],n=new Map;for(const a of t){const l=`${a.codepoint} ${a.nameZh}`;n.has(l)||s.push(l),n.set(l,(n.get(l)??0)+1)}return s.map(a=>[a,n.get(a)??0])}function Mi({spoof:t}){return t===void 0||t.text.length===0&&t.urls.length===0?null:e.jsxs("div",{className:"spoof",children:[e.jsxs("div",{className:"spoof-title",children:[e.jsx(ae,{name:"triangle-alert",size:12})," 视觉欺骗检查(仅显形,不影响按钮与按键)"]}),t.text.map(s=>e.jsxs("div",{className:"spoof-row",children:[e.jsx("span",{className:"spoof-key",children:s.key}),ym(s.issues).map(([n,a])=>e.jsx("span",{className:"spoof-badge",children:a>1?`${n}×${a}`:n},n)),s.more!==void 0&&s.more>0?e.jsx("span",{className:"spoof-badge spoof-more",children:`另 ${s.more} 处`}):null]},`t:${s.key}`)),t.urls.map(s=>e.jsxs("div",{className:"spoof-url",children:[e.jsx("span",{className:"spoof-key",children:s.key})," 真实指向:",e.jsx("code",{className:"spoof-target",children:s.normalizedUrl}),s.warnings.map((n,a)=>e.jsx("div",{className:"spoof-note",children:n},a))]},`u:${s.key}:${s.original}`))]})}function Ti(t){for(const s of["command","url","path","pattern","query"]){const n=t[s];if(typeof n=="string"&&n.trim()!=="")return ql(n)}try{return ql(JSON.stringify(t)??"")}catch{return""}}function ql(t){const s=t.replace(/\s+/g," ").trim();return s.length>300?`${s.slice(0,300)}…`:s}function Nm({ask:t,busy:s=!1,onChoose:n}){const a=c=>{s||n(c)},l=i.useRef(null);i.useEffect(()=>{l.current?.focus()},[]);const r=c=>{s||(c.key==="y"||c.key==="Y"?(c.preventDefault(),a({allow:!0})):c.key==="n"||c.key==="N"?(c.preventDefault(),a({allow:!1})):(c.key==="Escape"||c.key==="Enter")&&(c.preventDefault(),a({allow:!1})))},o=Ti(t.input);return e.jsxs("div",{className:"approval",role:"alertdialog","aria-label":"权限请求",ref:l,tabIndex:-1,onKeyDown:r,children:[e.jsxs("div",{className:"strip",children:[e.jsx(ae,{name:"hourglass",size:13})," ",`等待你的批准 —— 模型请求使用 ${t.toolName}`]}),e.jsxs("div",{className:"ap-scroll",children:[e.jsx("div",{className:"why",children:t.summary!==""?t.summary:`请求执行 ${t.toolName}`}),t.warning!==void 0?e.jsx("div",{className:"warn",children:t.warning}):null,t.sidecar!==void 0?e.jsx("div",{className:"sidecar",children:`风险提示:${t.sidecar}`}):null,t.settingsFile!==void 0?e.jsx("div",{className:"sidecar",children:`涉及运行时策略文件:${t.settingsFile}`}):null,o!==""?e.jsx("code",{className:"cmd",children:o}):null,e.jsx(Mi,{spoof:t.spoof})]}),e.jsxs("div",{className:"btns",children:[e.jsx("button",{type:"button",className:"deny",disabled:s,onClick:()=>a({allow:!1}),children:s?"发送中…":"拒绝"}),e.jsx("button",{type:"button",className:"allow",disabled:s,onClick:()=>a({allow:!0}),children:s?"发送中…":"允许一次"})]})]})}function km({ask:t,onChoose:s}){const[n,a]=i.useState(null),l=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),c=Ti(t.input),d=p=>{l.current||(l.current=!0,s(p))};tt(),i.useEffect(()=>{n!==null?r.current?.focus():o.current?.focus()},[n]);const m=p=>{n===null&&(p.key==="y"||p.key==="Y"?(p.preventDefault(),d({allow:!0})):(p.key==="a"||p.key==="A")&&t.settingsFile===void 0?(p.preventDefault(),d({allow:!0,scope:"session"})):(p.key==="p"||p.key==="P")&&t.settingsFile===void 0?(p.preventDefault(),d({allow:!0,scope:"always"})):p.key==="n"||p.key==="N"?(p.preventDefault(),a("")):(p.key==="Escape"||p.key==="Enter")&&(p.preventDefault(),d({allow:!1})))};return e.jsxs("div",{className:"permission-card",role:"dialog","aria-label":"permission ask",ref:o,tabIndex:-1,onKeyDown:m,children:[e.jsxs("div",{className:"strip",children:[e.jsx(ae,{name:"hourglass",size:13})," 等待你的批准"]}),n===null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pc-scroll",children:[t.warning!==void 0?e.jsx("div",{className:"warn",children:t.warning}):null,t.sidecar!==void 0?e.jsxs("div",{className:"warn",children:[e.jsx(ae,{name:"key",size:12})," ",`(sidecar: ${t.sidecar})`]}):null,e.jsx("h3",{children:t.settingsFile!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(ae,{name:"key",size:14})," 允许 ",t.toolName,":",e.jsxs("span",{className:"warn",children:["策略文件 ",t.settingsFile]}),t.summary&&t.summary!==t.settingsFile?` (${t.summary})`:"","?"]}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{name:"key",size:14})," 允许 ",t.toolName,t.summary?`:${t.summary}`:"","?"]})}),e.jsx("div",{className:"muted",children:t.settingsFile!==void 0?"y 仅本次 · n 拒绝(可填理由) · 策略文件无会话/持久选项":"y 仅本次 · a 本会话 · p 总是(写入 .wudao/settings.json) · n 拒绝(可填理由)"}),c!==""?e.jsx("code",{className:"cmd",children:c}):null,e.jsx(Mi,{spoof:t.spoof})]}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao primary",onClick:()=>d({allow:!0}),children:"y — 仅本次"}),t.settingsFile===void 0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"wudao",onClick:()=>d({allow:!0,scope:"session"}),children:"a — 本会话"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>d({allow:!0,scope:"always"}),children:"p — 总是"})]}):null,e.jsx("button",{type:"button",className:"wudao danger",onClick:()=>a(""),children:"n — 拒绝…"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pc-scroll",children:e.jsxs("h3",{children:[e.jsx(ae,{name:"key",size:14})," ",`拒绝 ${t.toolName} — 理由(可选)`]})}),e.jsx("input",{ref:r,className:"wudao-input",style:{width:"100%"},value:n,placeholder:"理由(会回传给模型)",onChange:p=>a(p.target.value),onKeyDown:p=>{if(p.key==="Enter"){p.preventDefault();const g=n.trim();d(g===""?{allow:!1}:{allow:!1,reason:g})}else p.key==="Escape"&&(p.preventDefault(),d({allow:!1}))}}),e.jsxs("div",{className:"btnrow",children:[e.jsxs("button",{type:"button",className:"wudao danger",onClick:()=>{const p=n.trim();d(p===""?{allow:!1}:{allow:!1,reason:p})},children:["拒绝 ",e.jsx(ae,{name:"corner-down-left",size:11})]}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>d({allow:!1}),children:"不带理由拒绝 (Esc)"})]})]})]})}function Di({question:t,options:s,onAnswer:n,onDismiss:a,inline:l=!1}){const[r,o]=i.useState(""),c=s!==void 0&&s.length>0;tt();const d=i.useRef(null),m=i.useRef(null),p=i.useRef({composing:!1,endedAt:0});i.useEffect(()=>{c?m.current?.focus():d.current?.focus()},[]);const g=e.jsxs("div",{className:l?"ask-card":"modal-card pop-in",role:"dialog","aria-label":"agent question",ref:m,tabIndex:-1,onCompositionStart:()=>{p.current=He(p.current)},onCompositionEnd:()=>{p.current=_e(p.current,Date.now())},onKeyDown:v=>{Ue(v.nativeEvent,p.current,Date.now())||v.key==="Escape"&&(v.preventDefault(),a())},children:[e.jsxs("h3",{children:[e.jsx(ae,{name:"circle-help",size:14})," ",t]}),c?e.jsxs("div",{className:"optioncards",onKeyDown:v=>{if(!/^[1-9]$/.test(v.key))return;const N=Number(v.key),S=s?.[N-1];S!==void 0&&(v.preventDefault(),n(S.label))},children:[s?.map((v,N)=>e.jsxs("button",{type:"button",className:"optioncard",onClick:()=>n(v.label),children:[`${N+1}) ${v.label}`,v.description!==void 0&&v.description!==""?e.jsx("span",{className:"desc",children:` — ${v.description}`}):null]},N)),e.jsx("div",{className:"muted",children:`(按 1-${s?.length} 选择 · Esc 取消并让 agent 自行决定)`})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:d,className:"wudao-input",style:{width:"100%"},value:r,placeholder:"输入回答…",onChange:v=>o(v.target.value),onCompositionStart:()=>{p.current=He(p.current)},onCompositionEnd:()=>{p.current=_e(p.current,Date.now())},onKeyDown:v=>{Ue(v.nativeEvent,p.current,Date.now())||v.key==="Enter"&&(v.preventDefault(),n(r.trim()))}}),e.jsx("div",{className:"muted",children:"(Enter 发送 · Esc 取消并让 agent 自行决定)"})]}),e.jsx("div",{className:"btnrow",children:e.jsx("button",{type:"button",className:"wudao",onClick:a,children:"Esc — 让 agent 自行决定"})})]});return l?g:e.jsx("div",{className:"scrim",onClick:v=>{v.target===v.currentTarget&&a()},children:g})}function Qt(t){return t.split("/").filter(s=>s!=="").slice(-1)[0]??t}function Ai({panelRoot:t,agentRoot:s,queued:n,onSwitch:a,onKeep:l}){const r=Qt(t),o=s!==""?Qt(s):null;return e.jsxs("div",{className:"approval agent-root",role:"alertdialog","aria-label":"agent 工作目录确认",children:[e.jsx("div",{className:"strip",children:n?"已排队 — 将在当前任务结束后切换":"文件面板已切换 · agent 工作目录待确认"}),e.jsx("div",{className:"why",children:n?`当前任务保持原工作目录;任务结束后 agent 工作目录将切换 → ${r} (${t})`:`文件面板已切换到 ${r}。agent 的工作目录仍为 ${o??"原目录"}。`}),n?null:e.jsxs("div",{className:"btns",children:[e.jsx("button",{type:"button",className:"deny",onClick:l,children:"保持现状"}),e.jsx("button",{type:"button",className:"allow",onClick:a,children:"切换 agent 目录"})]})]})}function wm(t){const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toISOString().slice(0,16).replace("T"," ")}function Sm({rows:t,onPick:s,onCancel:n,intent:a="resume"}){const l=i.useRef(null);return tt(),i.useEffect(()=>{l.current?.focus()},[]),e.jsx("div",{className:"scrim",onClick:r=>{r.target===r.currentTarget&&n()},children:e.jsxs("div",{className:"modal-card pop-in",role:"dialog","aria-label":"恢复会话",ref:l,tabIndex:-1,onKeyDown:r=>{if(r.key==="Escape"){r.preventDefault(),n();return}if(!/^[1-9]$/.test(r.key))return;const o=t[Number(r.key)-1];o!==void 0&&(r.preventDefault(),s(o.id))},children:[e.jsx("h3",{children:a==="followup"?"选择要追问的会话":"选择要恢复的会话"}),e.jsx("div",{className:"muted",children:a==="followup"?"选中后开一份副本继续问,原对话保持不变":"仅列出记录在当前工作区的会话"}),e.jsx("div",{className:"picker",children:t.map((r,o)=>e.jsxs("button",{type:"button",className:"pickrow",onClick:()=>s(r.id),children:[e.jsx("span",{className:"rank",children:`${o+1})`}),e.jsx("span",{children:r.id.slice(0,8)}),e.jsx("span",{className:"meta",children:wm(r.mtime)}),e.jsx("span",{className:"meta",children:`${r.messages} 条消息`}),e.jsx("span",{children:r.name??(r.firstUser!==""?r.firstUser:"暂无会话")})]},r.id))}),e.jsx("div",{className:"btnrow",children:e.jsx("button",{type:"button",className:"wudao",onClick:n,children:"取消 (Esc)"})})]})})}function Cm({onChoose:t}){const s=i.useRef(!1),n=i.useRef(null);tt(),i.useEffect(()=>{n.current?.focus()},[]);const a=l=>{s.current||(s.current=!0,t(l))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in",role:"dialog","aria-label":"清空历史",ref:n,tabIndex:-1,onKeyDown:l=>{l.key==="y"||l.key==="Y"?(l.preventDefault(),a(!0)):(l.key==="n"||l.key==="N"||l.key==="Enter"||l.key==="Escape")&&(l.preventDefault(),a(!1))},children:[e.jsxs("h3",{children:[e.jsx(ae,{name:"trash-2",size:14,className:"ic-danger"})," 清空历史 —— 清空当前会话?"]}),e.jsx("div",{className:"muted",children:"(y 清空当前会话并开始新对话 · n 保留 — 已保存的会话仍在磁盘,/resume 可恢复)"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao danger",onClick:()=>a(!0),children:"清空"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>a(!1),children:"保留 (Esc)"})]})]})})}function Oi({plan:t,busy:s,onSubmit:n}){const[a,l]=i.useState(!1),[r,o]=i.useState(""),c=i.useRef(null),d=i.useRef(null),m=i.useRef({composing:!1,endedAt:0}),p=i.useRef(!1);return i.useEffect(()=>{a?d.current?.focus():p.current&&c.current?.focus(),p.current=a},[a]),e.jsxs("div",{className:"planboard",children:[e.jsxs("div",{className:"label",children:[e.jsx(ae,{name:"clipboard-list",size:13})," plan — review before execution"]}),e.jsx("div",{className:"body",children:t}),a?e.jsxs("div",{className:"btnrow",children:[e.jsx("input",{ref:d,className:"wudao-input",style:{flex:1},value:r,placeholder:"改 — what to change",onChange:g=>o(g.target.value),onCompositionStart:()=>{m.current=He(m.current)},onCompositionEnd:()=>{m.current=_e(m.current,Date.now())},onKeyDown:g=>{Ue(g.nativeEvent,m.current,Date.now())||(g.key==="Enter"?(g.preventDefault(),n(r.trim()===""?"改":`改 ${r.trim()}`),l(!1),o("")):g.key==="Escape"&&(g.preventDefault(),l(!1)))}}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>{n(r.trim()===""?"改":`改 ${r.trim()}`),l(!1),o("")},children:"revise ↵"})]}):e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao primary",disabled:s,onClick:()=>n("ok"),children:"ok — execute"}),e.jsx("button",{type:"button",className:"wudao",disabled:s,ref:c,onClick:()=>l(!0),children:"改 — revise"})]})]})}const Gl=t=>t instanceof Error?t.message:String(t);function Em({client:t,notify:s,onAccentPicked:n}){const[a,l]=i.useState(null),r=zs(),o=_n(),c=m=>{const p=zs();vt(m),l("set:ui.theme"),t.settingsSet("ui.theme",m).then(()=>s(`主题 → ${m==="dark"?"暗色":"浅色"} —— 已保存`)).catch(g=>{vt(p),s(`⚠️ 主题未保存:${Gl(g)}`)}).finally(()=>l(null))},d=m=>{const p=_n();ss(m),n?.(),l("set:ui.accent"),t.settingsSet("ui.accent",m).then(()=>s(`主色 → ${m==="black"?"墨黑":m==="blue"?"蓝":"绿"} —— 已保存`)).catch(g=>{ss(p),s(`⚠️ 主色未保存:${Gl(g)}`)}).finally(()=>l(null))};return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"settings-section set-sec",children:[e.jsx("h3",{className:"section-title set-title",children:"外观"}),e.jsxs("div",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"主题"}),e.jsx("span",{className:"setrow-note",children:"立即生效,并写入全局设置 (~/.wudao/settings.json)"})]}),e.jsx("div",{className:"segctl",role:"radiogroup","aria-label":"主题",children:["dark","light"].map(m=>e.jsx("button",{type:"button",role:"radio","aria-checked":r===m,"data-appearance-theme":m,className:`segctl-opt${r===m?" on":""}`,disabled:a==="set:ui.theme",onClick:()=>c(m),children:m==="dark"?"暗色":"浅色"},m))})]}),e.jsxs("div",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"主色"}),e.jsx("span",{className:"setrow-note",children:"按钮与选中态的强调色"})]}),e.jsx("div",{className:"segctl",role:"radiogroup","aria-label":"主色",children:["black","blue","green"].map(m=>e.jsxs("button",{type:"button",role:"radio","aria-checked":o===m,"data-appearance-accent":m,"data-swatch":m,className:`segctl-opt${o===m?" on":""}`,disabled:a==="set:ui.accent",onClick:()=>d(m),children:[e.jsx("span",{className:"segctl-dot","aria-hidden":!0}),m==="black"?"墨黑":m==="blue"?"蓝":"绿"]},m))})]})]})})}const Hn=t=>t instanceof Error?t.message:String(t),$m=t=>{const s=Hn(t);return s.includes("unknown op: mcp")||s.includes("mcp ops not supported")},Rm=[{tier:"user",title:"用户级 —— 本机所有项目",file:"user",hint:"所有会话可用;Claude Code / wudao 两种格式都行(mcpServers 或 servers)"},{tier:"root",title:"项目根 .mcp.json —— Claude Code 项目文件",file:"root",hint:"Claude Code 的项目级配置,wudao 直接读取,零拷贝迁移"},{tier:"project",title:"项目级 .wudao/mcp.json —— 本工作区",file:"project",hint:"仅本项目;同名服务器整体替换上面两层(三层中优先级最高)"}];function Mm(t){return t.connected?`已连接 · ${t.tools} 个工具`:t.failure!==void 0?`连接失败 · ${t.failure.split(`
320
+ `)[0]??t.failure}`:"未连接(本次会话尚未启动)"}function Tm({client:t}){const[s,n]=i.useState(!1),[a,l]=i.useState(null),[r,o]=i.useState(null),[c,d]=i.useState(!1),m=i.useCallback(async()=>{o(await t.mcpList()),l(null)},[t]);i.useEffect(()=>{let v=!1;return d(!0),m().catch(N=>{v||($m(N)?n(!0):l(Hn(N)))}).finally(()=>{v||d(!1)}),()=>{v=!0}},[m]);const p=()=>{d(!0),m().catch(v=>l(Hn(v))).finally(()=>d(!1))};if(s)return e.jsxs("div",{className:"settings-section",children:[e.jsx("div",{className:"section-title",children:"MCP 服务器"}),e.jsx("div",{className:"hint",children:"升级 wudao 后可用"})]});const g=r?.servers??[];return e.jsxs("div",{className:"settings-section","data-testid":"mcp-tab",children:[e.jsx("div",{className:"section-title",children:"MCP 服务器"}),e.jsx("div",{className:"hint",children:"已配置的 MCP 服务器分三层生效:用户级 → 项目根 .mcp.json → 项目级(同名后者整体替换前者)。配置文件支持 Claude Code 的 mcpServers 格式,可直接粘贴。"}),e.jsxs("div",{className:"keyrow",children:[e.jsx("button",{type:"button",className:"wudao",disabled:c,onClick:p,"data-testid":"mcp-refresh",children:c?"刷新中…":"刷新"}),e.jsx("span",{className:"meta",children:`${g.length} 个服务器`})]}),a!==null?e.jsx("div",{className:"entry-error",children:`无法读取 MCP 配置:${a}`}):null,r!==null&&r.warnings.length>0?r.warnings.map(v=>e.jsxs("div",{className:"entry-error",children:[e.jsx(ae,{name:"triangle-alert",size:12})," ",v]},v)):null,r!==null&&g.length===0&&a===null?e.jsx("div",{className:"hint",children:"尚未配置任何 MCP 服务器——把配置写入下面任一文件即可(保存后新会话生效)"}):null,Rm.map(v=>{const N=g.filter(R=>R.tier===v.tier),S=r?.files[v.file];return e.jsxs("div",{className:"installed-group","data-mcp-tier":v.tier,children:[e.jsxs("div",{className:"group-title",children:[v.title,e.jsx("span",{className:"meta",children:S!==void 0?`(${S})`:""})]}),e.jsx("div",{className:"hint",children:v.hint}),N.length===0?e.jsx("div",{className:"muted",children:"(无)"}):N.map(R=>e.jsxs("div",{className:"installed-row","data-mcp-server":R.name,children:[e.jsx("span",{className:"plugin-name",children:R.name}),e.jsx("span",{className:"meta",children:R.transport==="http"?"http":"stdio"}),e.jsx("span",{className:"plugin-desc",children:R.command}),e.jsx("span",{className:"meta","data-mcp-status":R.name,children:Mm(R)}),R.replaces.length>0?e.jsx("span",{className:"meta",children:`替换了${R.replaces.map(j=>j==="user"?"用户级":"项目根").join("、")}的同名配置`}):null]},R.name))]},v.tier)}),e.jsx("div",{className:"hint",children:"提示:MCP 工具每次调用都会先征求确认(权限层设计);会话里输入 /mcp 可随时查看连接状态。"})]})}const Dm=t=>t instanceof Error?t.message:String(t);function Am({client:t,notify:s,status:n}){const[a,l]=i.useState("workspace");i.useEffect(()=>{let o=!0;return t.settingsStatus().then(c=>{o&&c.settings.permissionsDefaultMode&&l(c.settings.permissionsDefaultMode)}).catch(()=>{}),()=>{o=!1}},[t]);const r=o=>{t.settingsSet("permissions.defaultMode",o).then(()=>{l(o),s(`新会话默认权限档 → ${o}(已持久化;本会话仍为 ${Pn(n?.mode??"workspace")})`)}).catch(c=>s(`⚠️ 设置默认权限档失败:${Dm(c)}`))};return e.jsxs("div",{className:"settings-section set-sec",children:[e.jsx("h3",{className:"section-title set-title",children:"权限档(新会话默认)"}),e.jsx(ia,{value:Ei(a),onChange:r,direction:"down"}),e.jsxs("div",{className:"hint",children:["新会话以此档起步(CLI 旗标优先);当前会话档 = ",Pn(n?.mode??"workspace"),",由输入框旁的档位 chip / shift+tab 实时切换"]})]})}const Ps=t=>t instanceof Error?t.message:String(t),Gt=t=>t.startsWith("⚠️")?t:`⚠️ ${t}`,Om=t=>{const s=Ps(t);return s.includes("unknown op: plugin")||s.includes("plugin ops not supported")},Vt=t=>t===null?"—":`技能 ${t.skills} · 命令 ${t.commands} · Agents ${t.agents} · 钩子 ${t.hooks} · MCP ${t.mcp}`,Yt=t=>t===void 0?"":`;热重扫:技能 ${t.skills} · 插件 ${t.plugins} · 钩子 ${t.hooks}`,Im=[{scope:"user",title:"用户(user)——本机所有会话"},{scope:"project",title:"项目(project)——当前工作区"},{scope:"adhoc",title:"本会话挂载(adhoc)——随启动参数"}];function Lm({client:t,settings:s,notify:n,refresh:a}){const[l,r]=i.useState(!1),[o,c]=i.useState(null),[d,m]=i.useState(null),[p,g]=i.useState(null),[v,N]=i.useState(null),[S,R]=i.useState(""),[j,f]=i.useState("user"),[A,$]=i.useState(null),y=A!==null,[q,D]=i.useState(!1),V=b=>{D(!0),t.settingsSet("docSuite.enabled",b).then(()=>{n(`文档三件套已${b?"开启":"关闭"} —— 下会话生效`),a()}).catch(k=>n(`⚠️ ${Ps(k)}`)).finally(()=>D(!1))},H=i.useCallback(async()=>{const[b,k]=await Promise.all([t.pluginList(),t.pluginMarketList()]);g(b.installed),m(k.marketplaces),N(w=>{const E=k.marketplaces.map(G=>G.name);return w!==null&&E.includes(w)?w:E[0]??null}),c(null)},[t]);i.useEffect(()=>{let b=!1;return $("load"),H().catch(k=>{b||(Om(k)?r(!0):c(Ps(k)))}).finally(()=>{b||$(null)}),()=>{b=!0}},[H]);const X=(b,k)=>{$(b),k().catch(w=>n(Gt(Ps(w)))).finally(()=>$(null))},W=()=>{const b=S.trim();b!==""&&X("add",async()=>{const k=await t.pluginMarketAdd(b);R(""),n(`已添加市场 ${k.name}(${k.source})`),await H()})},[z,F]=i.useState(""),[M,P]=i.useState(null),T=()=>{const b=z.trim();b!==""&&X("spec-preview",async()=>{const k=await t.pluginInstallSpec(b,!0);P(k),n(k.preview?`预览 ${b}:${k.name??"未知名称"}(${Vt(k.detail)})`:"服务器未走预览路径——未安装")})},U=()=>{const b=z.trim();b!==""&&X("spec-install",async()=>{const k=await t.pluginInstallSpec(b,!1);P(null),F(""),n(`已安装 ${k.name??b} → ${k.dir??""}(${Vt(k.detail)})${Yt(k.rescan)}`);for(const w of k.warnings)n(Gt(w));await H()})},Q=b=>{X(`update:${b}`,async()=>{const k=await t.pluginMarketUpdate(b);n(`市场 ${k.name} 已更新(${k.source})`),await H()})},se=b=>{X(`remove:${b}`,async()=>{const k=await t.pluginMarketRemove(b);n(`已移除市场 ${b}${k.removedPlugins.length>0?`——连带卸载:${k.removedPlugins.join("、")}`:""}${Yt(k.rescan)}`);for(const w of k.warnings)n(Gt(w));await H()})},de=(b,k)=>{X(`install:${b}@${k}`,async()=>{const w=await t.pluginInstall(b,k,j);n(`已安装 ${b}@${k} → ${w.dir}(${Vt(w.detail)})${Yt(w.rescan)}`);for(const E of w.warnings)n(Gt(E));await H()})},le=b=>{const k=b.id;X(`toggle:${k}`,async()=>{const w=b.enabled?await t.pluginDisable(k):await t.pluginEnable(k);n(`${w.enabled?"已启用":"已停用"} ${w.id}${Yt(w.rescan)}`),await H()})},K=b=>{X(`uninstall:${b}`,async()=>{const k=await t.pluginUninstall(b);n(`已卸载 ${k.id}${Yt(k.rescan)}`);for(const w of k.warnings)n(Gt(w));await H()})};if(l)return e.jsxs("div",{className:"settings-section","data-plugin-unsupported":!0,children:[e.jsx("div",{className:"section-title",children:"插件"}),e.jsx("div",{className:"hint",children:"此 wudao 服务器不支持插件管理——升级 wudao 后可用"})]});const O=d??[],x=O.find(b=>b.name===v)??null;return e.jsxs("div",{className:"plugin-tab","data-plugin-tab":!0,children:[e.jsxs("div",{className:"settings-section","data-doc-suite-section":!0,children:[e.jsx("div",{className:"section-title",children:"内置"}),e.jsxs("label",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"文档三件套"}),e.jsx("span",{className:"setrow-note",children:"用自然语言创建和编辑 Excel、Word、PPT 文件(关闭后新会话生效)"})]}),e.jsx("input",{type:"checkbox",className:"wudao-switch","data-doc-suite-toggle":!0,checked:s?.settings.docSuiteEnabled??!0,disabled:q,onChange:b=>V(b.target.checked)})]})]}),e.jsxs("div",{className:"settings-section","data-plugin-spec-install":!0,children:[e.jsx("div",{className:"section-title",children:"从来源安装"}),e.jsx("div",{className:"hint",children:"直接安装一个插件包:本地目录(./dir)、GitHub 简写(owner/repo)、git URL(#ref 可选)——纯代码包(无可映射的技能/命令)会被拒绝"}),e.jsxs("div",{className:"keyrow",children:[e.jsx("input",{type:"text",className:"wudao-input plugin-spec-input",placeholder:"插件来源(./本地目录、owner/repo 或 git URL)","aria-label":"插件来源",value:z,onChange:b=>{F(b.target.value),P(null)}}),e.jsx("button",{type:"button",className:"wudao",disabled:z.trim()===""||y,onClick:T,children:"预览"})]}),M!==null?e.jsxs("div",{className:"market-row","data-plugin-spec-preview":!0,children:[e.jsxs("span",{className:"market-name",children:[M.name??"未知名称",M.format!==void 0?` · ${M.format==="ccb-family"?"上游包格式":"claude-plugin"}`:""]}),e.jsx("span",{className:"hint",children:`将映射:${Vt(M.detail)}`}),e.jsxs("span",{className:"keyrow",children:[e.jsx("button",{type:"button",className:"wudao",disabled:y,onClick:U,children:"安装"}),e.jsx("button",{type:"button",className:"wudao",disabled:y,onClick:()=>P(null),children:"取消"})]})]}):null]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("div",{className:"section-title",children:"市场"}),e.jsx("div",{className:"hint",children:"添加 CC 生态市场源:owner/repo · git URL(#ref)· 本地目录 · marketplace.json 路径——添加即克隆/复制到本机,不执行任何代码"}),e.jsxs("div",{className:"keyrow",children:[e.jsx("input",{type:"text",className:"wudao-input market-source-input",placeholder:"市场源(owner/repo、git URL、本地目录或 marketplace.json 路径)","aria-label":"市场源",value:S,onChange:b=>R(b.target.value)}),e.jsx("button",{type:"button",className:"wudao",disabled:S.trim()===""||y,onClick:W,children:"添加市场"})]}),A!==null?e.jsx("div",{className:"plugin-pending",children:"处理中…"}):null,d===null&&o===null?e.jsx("div",{className:"muted",children:"读取中…"}):null,o!==null?e.jsx("div",{className:"entry-error",children:`无法读取插件列表:${o}`}):null,d!==null&&O.length===0?e.jsx("div",{className:"hint",children:"尚未添加市场——在上方粘贴源添加(如 superpowers-market 或本地目录)"}):null,e.jsx("div",{className:"market-list",children:O.map(b=>e.jsxs("div",{className:"market-row","data-market":b.name,children:[e.jsxs("button",{type:"button",className:"wudao market-name","data-market-select":b.name,"aria-pressed":v===b.name,disabled:y,title:"在下方发现列表查看该市场的插件",onClick:()=>N(b.name),children:[b.name,v===b.name?" ←":""]}),e.jsx("span",{className:"meta",children:`${b.plugins.length} 个插件`}),b.description!==void 0?e.jsx("span",{className:"meta",children:b.description}):null,e.jsx("span",{className:"market-source",children:b.source}),e.jsx("button",{type:"button",className:"wudao",disabled:y,onClick:()=>Q(b.name),children:"更新"}),e.jsx("button",{type:"button",className:"wudao danger",disabled:y,onClick:()=>se(b.name),children:"移除"})]},b.name))})]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("div",{className:"section-title",children:`发现${x!==null?` —— ${x.name}`:""}`}),e.jsxs("div",{className:"prefrow",children:[e.jsx("span",{className:"pref-label",children:"安装作用域:"}),e.jsx("button",{type:"button","data-scope":"user",className:`wudao${j==="user"?" primary":""}`,disabled:y,onClick:()=>f("user"),children:"用户(本机)"}),e.jsx("button",{type:"button","data-scope":"project",className:`wudao${j==="project"?" primary":""}`,disabled:y,onClick:()=>f("project"),children:"项目(本工作区)"})]}),e.jsx("div",{className:"hint",children:"user = ~/.wudao/plugins(所有会话可用)· project = <工作区>/.wudao/plugins(仅本项目)"}),x===null?e.jsx("div",{className:"hint",children:"选择一个市场后,这里列出它的插件(名称/描述/版本/「将安装」明细)"}):x.plugins.length===0?e.jsx("div",{className:"hint",children:"该市场没有可列出的插件——若目录被手动改动,试一次「更新」"}):e.jsx("div",{className:"plugin-list",children:x.plugins.map(b=>e.jsxs("div",{className:"plugin-entry","data-plugin":b.name,children:[e.jsxs("div",{className:"plugin-head",children:[e.jsx("span",{className:"plugin-name",children:b.name}),b.version!==void 0?e.jsx("span",{className:"meta",children:b.version}):null]}),b.description!==void 0?e.jsx("div",{className:"plugin-desc",children:b.description}):null,e.jsx("div",{className:"plugin-detail",children:`将安装:${Vt(b.detail)}`}),e.jsx("div",{className:"plugin-actions",children:e.jsx("button",{type:"button",className:"wudao","data-install":`${b.name}@${x.name}`,disabled:y,onClick:()=>de(b.name,x.name),children:"安装"})})]},b.name))})]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("div",{className:"section-title",children:"已装插件"}),p===null?e.jsx("div",{className:"muted",children:"读取中…"}):p.length===0?e.jsx("div",{className:"hint",children:"尚未安装插件——在上方发现列表选择插件安装"}):Im.filter(b=>p.some(k=>k.scope===b.scope)).map(b=>e.jsxs("div",{className:"installed-group","data-scope":b.scope,children:[e.jsx("div",{className:"group-title",children:b.title}),p.filter(k=>k.scope===b.scope).map(k=>e.jsxs("div",{className:"installed-row","data-plugin-id":k.id,children:[e.jsx("span",{className:"plugin-name",children:k.name}),e.jsx("span",{className:"meta",children:k.market}),k.version!==void 0?e.jsx("span",{className:"meta",children:k.version}):null,e.jsx("span",{className:`meta state ${k.enabled?"on":"off"}`,children:k.enabled?"已启用":"已停用"}),k.scope==="adhoc"?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"wudao",disabled:y,onClick:()=>le(k),children:k.enabled?"停用":"启用"}),e.jsx("button",{type:"button",className:"wudao danger",disabled:y,onClick:()=>K(k.id),children:"卸载"})]})]},k.id))]},b.scope)),e.jsx("div",{className:"hint",children:"安装/启停/卸载后热重扫立即生效;停用保留安装记录(随时再启用),卸载删除目录"})]})]})}const Pm=["openai-chat","anthropic","responses"],_m={"openai-chat":["temperature","top_p","top_k","max_tokens","reasoning_effort","reasoning","stop","metadata"],anthropic:["temperature","top_p","top_k","max_tokens","thinking","stop_sequences","metadata"],responses:["temperature","top_p","max_completion_tokens","reasoning","instructions","store","metadata"]},Fm=new Set(["authorization","x-api-key","host","content-length","content-type","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","transfer-encoding","upgrade","cookie"]),oa=["{{sessionId}}","{{uuid}}","{{iso8601}}"];function zm(t){return t.split(/(\{\{[^}]*\}\})/).filter(s=>s.startsWith("{{")).filter(s=>!oa.includes(s))}const Bm=/^[a-z0-9]+(-[a-z0-9]+)*$/,ca=[{value:"",label:"全部层"},{value:"headers",label:"仅 headers"},{value:"prompt",label:"仅 prompt"},{value:"headers+prompt",label:"headers+prompt"}];function Xe(t){const s=t.indexOf(":");return s===-1?{id:t,layer:""}:{id:t.slice(0,s),layer:t.slice(s+1)}}function Dt(t,s){return s===""?t:`${t}:${s}`}function Km(t){return Fm.has(t.trim().toLowerCase())}const Ct=t=>t instanceof Error?t.message:String(t),dt=Pm,Vl={builtin:"内置",global:"全局",workspace:"工作区"};function Hs(t){return{"openai-chat":t(),anthropic:t(),responses:t()}}const da=()=>({key:"",value:""}),ua=()=>({key:"",value:""});function Yl(){return{id:"",displayName:"",promptText:"",headers:Hs(()=>[da()]),body:Hs(()=>[ua()])}}function Xl(t){const s=Hs(()=>[]),n=Hs(()=>[]);for(const a of dt){const l=t.headers[a];l!==void 0&&(s[a]=Object.entries(l).map(([o,c])=>({key:o,value:c}))),s[a].length===0&&(s[a]=[da()]);const r=t.body?.[a];r!==void 0&&(n[a]=Object.entries(r).map(([o,c])=>({key:o,value:JSON.stringify(c)??""}))),n[a].length===0&&(n[a]=[ua()])}return{id:t.id,displayName:t.displayName,promptText:t.prompt?.system?.text??"",headers:s,body:n}}function Wm(t){for(const s of dt)if(Object.keys(t.headers[s]??{}).length>0||Object.keys(t.body?.[s]??{}).length>0)return s;return dt[0]??"openai-chat"}function Um(t){const s=t.trim();if(s==="")return!1;try{return JSON.parse(s),!0}catch{return!1}}function Ii(t,s){const n=[],a=t.id.trim();s&&(a===""||!Bm.test(a))&&n.push("id: kebab-case required (/^[a-z0-9]+(-[a-z0-9]+)*$/)"),t.displayName.trim()===""&&n.push("displayName: 不能为空");for(const l of dt){for(const r of t.headers[l])if(r.key.trim()===""&&r.value!=="")n.push(`headers.${l}: 键不能为空`);else if(r.key.trim()!==""){Km(r.key)&&n.push(`headers.${l}.${r.key.trim()}: "${r.key.trim().toLowerCase()}" 是禁用键(鉴权/传输控制头由适配器持有,persona 不可控)`);for(const o of zm(r.value))n.push(`headers.${l}.${r.key.trim()}: unknown template slot ${o} (allowed: ${oa.join("|")})`)}for(const r of t.body[l])r.key!==""&&!Um(r.value)&&n.push(`body.${l}.${r.key}: 值必须是合法 JSON(如 0.7、"text"、false)`)}return n}function Hm(t,s){if(Ii(t,s).length>0)return null;const n={},a={};for(const r of dt){const o=t.headers[r].filter(d=>d.key.trim()!=="");o.length>0&&(n[r]=Object.fromEntries(o.map(d=>[d.key.trim(),d.value])));const c=t.body[r].filter(d=>d.key!==""&&d.value.trim()!=="");c.length>0&&(a[r]=Object.fromEntries(c.map(d=>[d.key,JSON.parse(d.value)])))}const l=t.promptText;return{id:t.id.trim(),displayName:t.displayName.trim(),source:{kind:"workspace-source",provenance:"user-defined (wudao settings persona tab)",pinnedVersion:"1"},headers:n,...Object.keys(a).length>0?{body:a}:{},...l.trim()!==""?{prompt:{system:{mode:"prefix",text:l}}}:{}}}const qm=Object.freeze({kind:"workspace-source",provenance:"user-defined (wudao settings persona tab)",pinnedVersion:"1"});function qs(t,s){if(Object.is(t,s))return!0;if(typeof t!="object"||typeof s!="object"||t===null||s===null||Array.isArray(t)!==Array.isArray(s))return!1;if(Array.isArray(t)&&Array.isArray(s))return t.length===s.length&&t.every((o,c)=>qs(o,s[c]??null));const n=Object.keys(t),a=Object.keys(s);if(n.length!==a.length)return!1;const l=s,r=t;return n.every(o=>Object.prototype.hasOwnProperty.call(l,o)&&qs(r[o],l[o]))}function Jl(t){const s=new Set(["id","displayName","source","headers","body","prompt"]);if(!Object.keys(t).every(n=>s.has(n))||!qs(t.source,qm)||t.id!==t.id.trim()||t.displayName!==t.displayName.trim())return!1;for(const n of dt){const a=t.headers[n];if(a!==void 0){if(Object.keys(a).length===0)return!1;for(const[r,o]of Object.entries(a))if(r.trim()!==r||typeof o!="string")return!1}const l=t.body?.[n];if(l!==void 0){if(Object.keys(l).length===0)return!1;for(const[r,o]of Object.entries(l)){if(r.trim()!==r)return!1;try{if(!qs(JSON.parse(JSON.stringify(o)),o))return!1}catch{return!1}}}}if(t.prompt!==void 0){const n=Object.keys(t.prompt);if(n.length!==1||n[0]!=="system")return!1;const a=t.prompt.system;if(a===void 0)return!1;const l=Object.keys(a);if(l.length!==2||!l.includes("mode")||!l.includes("text")||a.mode!=="prefix"||typeof a.text!="string"||a.text.trim()==="")return!1}return!0}function Gm({client:t,settings:s,notify:n,refresh:a}){const[l,r]=i.useState(null),[o,c]=i.useState(null),[d,m]=i.useState(!1),[p,g]=i.useState(null),[v,N]=i.useState(!1),[S,R]=i.useState(null),[j,f]=i.useState(null),[A,$]=i.useState(!1),[y,q]=i.useState("openai-chat"),[D,V]=i.useState([]),[H,X]=i.useState(null),[W,z]=i.useState(null),[F,M]=i.useState(!1),P=i.useRef(null);i.useEffect(()=>{F&&P.current?.focus()},[F]);const T=i.useRef({composing:!1,endedAt:0}),[U,Q]=i.useState(null),[se,de]=i.useState(null),le=U??s?.settings.personaId??"",K=Xe(le).id,O=se??Xe(le).layer,x=()=>{t.personaList().then(_=>{r(_.personas),c(null)}).catch(_=>{const Y=Ct(_);/unknown op|not supported/i.test(Y)?m(!0):c(Y)})};i.useEffect(()=>{x()},[t]);const b=()=>{g(null),N(!1),R(null),f(null),V([]),X(null),M(!1),$(!1)},k=_=>{$(!1),f(null),R(null),V([]),X(null),g(_),M(!0);const Y=(l??[]).find(J=>J.id===_);N(Y?.editable===!0),t.personaGet(_).then(J=>{R(J.definition),q(Wm(J.definition)),Y?.editable===!0&&Jl(J.definition)&&f(Xl(J.definition))}).catch(J=>{R(null),n(`⚠️ 读取失败:${Ct(J)}`)})},w=()=>{b(),$(!0),f(Yl()),q("openai-chat"),M(!0)},E=()=>{M(!1),$(!1)},G=()=>{if(j===null)return;const _=Hm(j,A);_!==null&&(z("save"),t.personaSave(_).then(Y=>{Y.ok?(n(`已保存 persona ${_.id}`),V([]),$(!1),g(_.id),N(!0),x(),a()):V(Y.errors)}).catch(Y=>n(`⚠️ 保存失败:${Ct(Y)}`)).finally(()=>z(null)))},ee=()=>{if(p===null)return;const _=p;z(`del:${_}`),t.personaDelete({id:_}).then(Y=>{Y.ok?(X(null),n(`已删除 persona ${_}`),b(),x(),a()):X({id:_,providers:Y.references.providers,isGlobalDefault:Y.references.isGlobalDefault})}).catch(Y=>n(`⚠️ 删除失败:${Ct(Y)}`)).finally(()=>z(null))},me=()=>{if(H===null)return;const _=H.id;z(`del:${_}`),t.personaDelete({id:_,unbind:!0}).then(Y=>{Y.ok?(X(null),n(`已解绑并删除 persona ${_}`),b(),x(),a()):n(`⚠️ 删除失败:仍被引用(${Y.references.providers.join(", ")})`)}).catch(Y=>n(`⚠️ 删除失败:${Ct(Y)}`)).finally(()=>z(null))},ye=_=>{z("default"),t.settingsSet("persona.id",_).then(()=>{n(_===""?"已清除全局默认 persona":`全局默认 persona → ${_}`),a()}).catch(Y=>n(`⚠️ 写入失败:${Ct(Y)}`)).finally(()=>z(null))},Ne=_=>{f(Y=>Y===null?Y:{...Y,..._})},he=(_,Y,J)=>{f(ie=>ie===null?ie:{...ie,headers:{...ie.headers,[_]:ie.headers[_].map((ge,ne)=>ne===Y?{...ge,...J}:ge)}})},Ee=(_,Y,J)=>{f(ie=>ie===null?ie:{...ie,body:{...ie.body,[_]:ie.body[_].map((ge,ne)=>ne===Y?{...ge,...J}:ge)}})},ve=_=>{f(Y=>Y===null?Y:{...Y,headers:{...Y.headers,[_]:[...Y.headers[_],da()]}})},Re=_=>{f(Y=>Y===null?Y:{...Y,body:{...Y.body,[_]:[...Y.body[_],ua()]}})},qe=(_,Y)=>{f(J=>J===null?J:{...J,headers:{...J.headers,[_]:J.headers[_].filter((ie,ge)=>ge!==Y)}})},Fe=(_,Y)=>{f(J=>J===null?J:{...J,body:{...J.body,[_]:J.body[_].filter((ie,ge)=>ge!==Y)}})};if(d)return e.jsxs("div",{className:"settings-section set-sec","data-persona-tab":!0,children:[e.jsx("h3",{className:"section-title set-title",children:"Persona"}),e.jsx("div",{className:"hint",children:"升级 wudao 后可用"})]});const Ie=j??(S!==null?Xl(S):null),pe=Ie!==null&&j===null,ze=v&&S!==null&&!Jl(S),Me=S?.prompt?.system?.mode??"prefix",Le=(l??[]).find(_=>_.id===p),Ge=_=>{const Y=[...Ii(_,A),...D],J=new Set;for(const ne of dt){for(const re of _.headers[ne])if(re.key.trim()!=="")for(const fe of Y)fe.startsWith(`headers.${ne}.${re.key.trim()}:`)&&J.add(fe);for(const re of _.body[ne])if(re.key!=="")for(const fe of Y)fe.startsWith(`body.${ne}.${re.key}:`)&&J.add(fe)}const ie=Y.filter(ne=>!J.has(ne)),ge=(ne,re,fe)=>fe===""?[]:Y.filter(je=>je.startsWith(`${ne}.${re}.${fe}:`));return e.jsxs("div",{className:"persona-form",children:[e.jsx("div",{className:"detail-head",children:A?e.jsx("strong",{children:"新建 persona"}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:_.displayName!==""?_.displayName:_.id}),e.jsx("span",{className:"meta persona-id",children:_.id}),Le!==void 0?e.jsx("span",{className:"meta",children:Vl[Le.source]}):null,pe?e.jsx("span",{className:"meta",children:"只读"}):null]})}),ie.length>0?e.jsx("div",{className:"entry-error",children:ie.join(`
321
+ `)}):null,e.jsxs("div",{className:"prefrow",children:[e.jsx("span",{className:"pref-label",children:"id:"}),e.jsx("input",{type:"text",className:"wudao-input ctl","aria-label":"id",placeholder:"kebab-case(仅创建时可改)",value:_.id,disabled:pe||!A,onChange:ne=>Ne({id:ne.target.value})})]}),e.jsxs("div",{className:"prefrow",children:[e.jsx("span",{className:"pref-label",children:"displayName:"}),e.jsx("input",{type:"text",className:"wudao-input ctl","aria-label":"displayName",value:_.displayName,disabled:pe,onChange:ne=>Ne({displayName:ne.target.value})})]}),e.jsxs("div",{className:"prefrow",children:[e.jsx("span",{className:"pref-label",children:"prompt:"}),e.jsxs("select",{className:"ctl","aria-label":"prompt mode",value:Me,disabled:!0,children:[e.jsx("option",{value:"prefix",children:"prefix"}),e.jsx("option",{value:"snapshot",children:"snapshot"})]})]}),e.jsx("textarea",{className:"wudao-input persona-prompt","aria-label":"prompt",rows:4,placeholder:"system 前缀文本(prefix 模式;空 = 不带 prompt 层)",value:_.promptText,disabled:pe,onChange:ne=>Ne({promptText:ne.target.value})}),e.jsx("div",{className:"persona-wire-tabs",role:"tablist","aria-label":"wire 协议分页",children:dt.map(ne=>{const re=_.headers[ne].filter(fe=>fe.key.trim()!=="").length+_.body[ne].filter(fe=>fe.key!=="").length;return e.jsxs("button",{type:"button",role:"tab","data-wire":ne,"aria-selected":y===ne,className:`segctl-opt${y===ne?" on":""}`,onClick:()=>q(ne),children:[ne,e.jsx("span",{className:`wire-count${re===0?" zero":""}`,children:re})]},ne)})}),e.jsxs("div",{className:"persona-layer",children:[e.jsx("div",{className:"pref-label",children:`headers(${y})`}),_.headers[y].map((ne,re)=>{const fe=ge("headers",y,ne.key.trim());return e.jsxs("div",{className:`row keyrow${fe.length>0?" error":""}`,children:[e.jsx("input",{type:"text",className:"wudao-input ctl","aria-label":re===0?`headers.${y}.key`:`headers.${y}.${re}.key`,placeholder:"header 名(如 user-agent)",value:ne.key,disabled:pe,onChange:je=>he(y,re,{key:je.target.value})}),e.jsx("input",{type:"text",className:"wudao-input ctl","aria-label":re===0?`headers.${y}.value`:`headers.${y}.${re}.value`,placeholder:"值",value:ne.value,disabled:pe,onChange:je=>he(y,re,{value:je.target.value})}),e.jsx("button",{type:"button",className:"ctl",disabled:pe,onClick:()=>qe(y,re),children:"移除"}),fe.map(je=>e.jsx("span",{className:"entry-error",children:je},je))]},re)}),e.jsx("button",{type:"button",className:"ctl",disabled:pe,onClick:()=>ve(y),children:"+ 添加头"})]}),e.jsxs("div",{className:"persona-layer",children:[e.jsx("div",{className:"pref-label",children:`body(${y})`}),_.body[y].map((ne,re)=>{const fe=ge("body",y,ne.key);return e.jsxs("div",{className:`row keyrow${fe.length>0?" error":""}`,children:[e.jsxs("select",{className:"ctl","aria-label":re===0?`body.${y}.key`:`body.${y}.${re}.key`,value:ne.key,disabled:pe,onChange:je=>Ee(y,re,{key:je.target.value}),children:[e.jsx("option",{value:"",children:"(选择键)"}),_m[y].map(je=>e.jsx("option",{value:je,children:je},je))]}),e.jsx("input",{type:"text",className:"wudao-input ctl","aria-label":re===0?`body.${y}.value`:`body.${y}.${re}.value`,placeholder:'JSON 值(如 0.7、"text"、false)',value:ne.value,disabled:pe,onChange:je=>Ee(y,re,{value:je.target.value})}),e.jsx("button",{type:"button",className:"ctl",disabled:pe,onClick:()=>Fe(y,re),children:"移除"}),fe.map(je=>e.jsx("span",{className:"entry-error",children:je},je))]},re)}),e.jsx("button",{type:"button",className:"ctl",disabled:pe,onClick:()=>Re(y),children:"+ 添加 body 键"})]}),pe?e.jsx("div",{className:"hint",children:ze?"此 persona 含高级字段(快照/工具名映射/默认层/置信度),由手工编写,仅支持查看":`${S?.source.kind==="external-research"?"社区逆向指纹(external-research)":"内置指纹(workspace-source)"} · 只读`}):e.jsxs("div",{className:"keyrow",children:[e.jsx("button",{type:"button",className:"ctl persona-save",disabled:W==="save",onClick:G,children:"保存"}),A?e.jsx("button",{type:"button",className:"ctl",onClick:b,children:"取消"}):e.jsx("button",{type:"button",className:"ctl persona-del",disabled:W!==null,onClick:ee,children:"删除"})]})]})},$e=F?A?{aria:"新建 persona",head:"新建 persona",body:Ge(Ie??Yl())}:p===null?null:{aria:`persona ${Le?.displayName??p}`,head:Le?.displayName??p,body:Ie!==null?Ge(Ie):e.jsx("div",{className:"muted",children:"读取中…"})}:null;return e.jsxs("div",{className:"settings-section set-sec","data-persona-tab":!0,children:[e.jsx("h3",{className:"section-title set-title",children:"Persona"}),e.jsx("div",{className:"hint",children:"persona = 三层请求指纹(headers / body / prompt)。内置指纹只读;全局 persona 在此新建与编辑;供应商绑定在各供应商详情处设置。"}),e.jsxs("div",{className:"prefrow persona-default",children:[e.jsx("span",{className:"pref-label",children:"全局默认:"}),e.jsxs("select",{className:"ctl persona-pick","aria-label":"全局默认 persona",title:"未设置时按供应商绑定回落;供应商绑定可在各供应商详情处设置",value:K,disabled:W==="default",onChange:_=>{const Y=_.target.value,J=Y===""?"":Dt(Y,O);Q(J),ye(J)},children:[e.jsx("option",{value:"",children:"(未设置)"}),(l??[]).map(_=>e.jsx("option",{value:_.id,children:_.displayName??_.id},_.id))]}),e.jsx("select",{className:"ctl persona-pick-layer","aria-label":"全局默认层",title:"限定该 persona 只作用于选中的层(全部层 = 完整指纹)",value:O,disabled:W==="default",onChange:_=>{const Y=_.target.value;if(de(Y),K!==""){const J=Dt(K,Y);Q(J),ye(J)}},children:ca.map(_=>e.jsx("option",{value:_.value,children:_.label},_.value))})]}),o!==null?e.jsx("div",{className:"entry-error",children:`无法读取 persona 列表:${o}`}):null,e.jsx("button",{type:"button",className:"ctl persona-add",onClick:w,children:"+ 新建"}),e.jsx("div",{className:"provider-master",children:e.jsxs("div",{className:"provider-cards",children:[l===null&&o===null?e.jsx("div",{className:"provider-empty",children:"读取中…"}):null,(l??[]).map(_=>e.jsxs("button",{type:"button",className:"persona-row","data-persona":_.id,"aria-current":p===_.id&&!A?"true":void 0,onClick:()=>k(_.id),children:[e.jsx("span",{className:"persona-name",children:_.displayName??_.id}),e.jsx("span",{className:"meta persona-id",children:_.id}),e.jsx("span",{className:"meta persona-layers",children:_.layers}),e.jsx("span",{className:"meta persona-src",children:Vl[_.source]})]},_.id))]})}),F&&$e!==null?e.jsx("div",{className:"scrim pvd-overlay",onClick:_=>{_.target===_.currentTarget&&E()},children:e.jsxs("div",{className:"modal-card pop-in pvd",role:"dialog","aria-modal":"true","aria-label":$e.aria,ref:P,tabIndex:-1,onCompositionStart:()=>{T.current=He(T.current)},onCompositionEnd:()=>{T.current=_e(T.current,Date.now())},onKeyDown:_=>{Ue(_.nativeEvent,T.current,Date.now())||_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),E())},children:[e.jsxs("div",{className:"pvd-head",children:[e.jsx("h3",{children:$e.head}),e.jsx("button",{type:"button",className:"ctl pvd-close","aria-label":"关闭",title:"关闭(丢弃未保存的修改)",onClick:E,children:"✕"})]}),e.jsx("div",{className:"pvd-body",children:H!==null&&!A?e.jsxs("div",{className:"persona-delete-confirm",children:[e.jsx("div",{children:"该 persona 正被引用,「解绑并删除」将同时清除:"}),e.jsxs("ul",{children:[H.providers.map(_=>e.jsx("li",{children:`供应商 ${_} 的 persona 绑定`},_)),H.isGlobalDefault?e.jsx("li",{children:"全局默认 persona(persona.id 清空)"}):null]}),e.jsxs("div",{className:"keyrow",children:[e.jsx("button",{type:"button",className:"ctl persona-del",disabled:W!==null,onClick:me,children:"解绑并删除"}),e.jsx("button",{type:"button",className:"ctl",onClick:()=>X(null),children:"取消"})]})]}):$e.body})]})}):null,e.jsx("div",{className:"hint",children:`头值模板槽:${oa.join(" ")}(逐请求解析;未知槽位在保存前即被拒)`})]})}const Li=[{mode:"auto",label:"自动"},{mode:"on",label:"中文"},{mode:"off",label:"不限"}],Ql=[{mode:"auto",label:"自动"},{mode:"zh",label:"中文"},{mode:"en",label:"EN"},{mode:"off",label:"不限"}],Zl=t=>Li.find(s=>s.mode===t)?.label??"语言";function Vm({value:t,disabled:s=!1,onPick:n,onPersistDefault:a}){const[l,r]=i.useState(!1),o=i.useRef(null),c=i.useRef(null),d=(g=!0)=>{r(!1),g&&setTimeout(()=>{document.activeElement===document.body&&c.current?.focus()},0)};i.useEffect(()=>{if(!l)return;const g=v=>{o.current!==null&&!o.current.contains(v.target)&&d(!1)};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[l]);const m=t??{reply:"auto",reasoning:"auto"},p=m.reply!=="auto"||m.reasoning!=="auto";return e.jsxs("div",{className:"pop",ref:o,onKeyDown:g=>{g.key==="Escape"&&(g.preventDefault(),d())},children:[e.jsxs("button",{type:"button",ref:c,className:`chip lang${p?" sel":""}`,disabled:s,"aria-haspopup":"menu","aria-expanded":l,title:`回答:${Zl(m.reply)} 思考:${Ql.find(g=>g.mode===m.reasoning)?.label??"自动"} — 会话内切换,下一轮生效`,onClick:()=>{r(!l)},children:[e.jsx(Wo,{size:14}),m.reply==="auto"?"语言":Zl(m.reply),e.jsx("span",{className:"caret","aria-hidden":!0,children:"▾"})]}),l?e.jsxs("div",{className:"menu lang-menu",role:"menu","aria-label":"语言",children:[e.jsx("div",{className:"lang-head",children:"回答"}),Li.map(g=>e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":g.mode===m.reply,className:`mi${g.mode===m.reply?" on":""}`,"data-knob":"reply","data-mode":g.mode,onClick:()=>{n("reply",g.mode),d()},children:e.jsx("span",{className:"mlabel",children:g.label})},g.mode)),a!==void 0?e.jsx("button",{type:"button",className:"mf","data-persist":"reply",title:"把当前回答语言存为全局默认(新会话起步值)",onClick:()=>{a("reply"),d()},children:"设为默认"}):null,e.jsx("div",{className:"lang-head",children:"思考"}),Ql.map(g=>e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":g.mode===m.reasoning,className:`mi${g.mode===m.reasoning?" on":""}`,"data-knob":"reasoning","data-mode":g.mode,onClick:()=>{n("reasoning",g.mode),d()},children:e.jsx("span",{className:"mlabel",children:g.label})},g.mode)),a!==void 0?e.jsx("button",{type:"button",className:"mf","data-persist":"reasoning",title:"把当前思考语言存为全局默认(新会话起步值)",onClick:()=>{a("reasoning"),d()},children:"设为默认"}):null]}):null]})}const Ym=t=>t instanceof Error?t.message:String(t),er={simple:"简洁模式",buddy:"Buddy 模式",advanced:"高级模式"};function Xm(t){switch(t){case"offered":return"待同意";case"proposing":return"生成中";case"gated":return"待激活";case"gate-failed":return"门禁未过";case"rejected":return"已驳回";case"ignored":return"已忽略";case"abandoned":return"已放弃";case"activated":return"已生效";case"undone":return"已撤销";default:return t}}function Jm({client:t,settings:s,notify:n,refresh:a,onModeApplied:l,language:r=null,memorySignature:o}){const[c,d]=i.useState(null),m=(x,b,k)=>{d(`set:${x}`),t.settingsSet(x,b).then(()=>{n(k),x==="ui.defaultMode"&&(b==="simple"||b==="buddy"||b==="advanced")&&l?.(b),a()}).catch(w=>n(`⚠️ ${Ym(w)}`)).finally(()=>d(null))},p=(x,b)=>{d(`set:${cl(x)}`),t.settingsSet(cl(x),b).then(()=>{n(`已设为默认:${x==="reply"?"回答":"思考"} ${b} —— 新会话生效`),a()}).catch(k=>n(`⚠️ 默认语言保存失败:${k instanceof Error?k.message:String(k)}`)).finally(()=>d(null))},[g,v]=i.useState(void 0),[N,S]=i.useState(void 0),[R,j]=i.useState(null),[f,A]=i.useState(0),[$,y]=i.useState(null),[q,D]=i.useState(null),[V,H]=i.useState(""),X=i.useCallback(()=>{if(typeof t.memoryList!="function"){v(null);return}t.memoryList().then(x=>{v(wi(x)),A(typeof x.blocked=="number"&&x.blocked>0?x.blocked:0)}).catch(()=>{v(null)})},[t]);i.useEffect(()=>{X()},[X]);const W=i.useCallback(()=>{if(typeof t.longtermMemoryList!="function"){S(null);return}t.longtermMemoryList().then(x=>{S(Array.isArray(x.entries)?x.entries:[])}).catch(()=>{S(null)})},[t]);i.useEffect(()=>{W()},[W]);const z=x=>{j(x),t.longtermMemoryForget(x).then(()=>{W()}).catch(()=>{W()}).finally(()=>j(null))},F=i.useRef({sig:void 0,armed:!1});i.useEffect(()=>{const x=F.current;if(!x.armed){F.current={sig:o,armed:!0};return}o!==x.sig&&(F.current={sig:o,armed:!0},X())},[o,X]);const M=x=>{n(`⚠️ 记忆操作失败:${x instanceof Error?x.message:String(x)}`)},[P,T]=i.useState(void 0),[U,Q]=i.useState(null),se=i.useCallback(()=>{if(typeof t.improvementFace!="function"){T(null);return}t.improvementFace("list").then(x=>{T(Array.isArray(x.records)?x.records:[])}).catch(()=>{T(null)})},[t]);i.useEffect(()=>{se()},[se]);const de=x=>{n(`⚠️ 改进提案操作失败:${x instanceof Error?x.message:String(x)}`)},le=(x,b)=>{Q(x),t.improvementFace(b,x).then(k=>{n(k.message),se()}).catch(de).finally(()=>Q(null))},K=(x,b)=>{y(x),t.memoryDecide(x,b).then(k=>{n(k.message),X()}).catch(M).finally(()=>y(null))},O=x=>{y(x),t.memoryEdit(x,V).then(b=>{n(b.message),D(null),H(""),X()}).catch(M).finally(()=>y(null))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"settings-section set-sec",children:[e.jsx("h3",{className:"section-title set-title",children:"偏好"}),e.jsxs("label",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"跨会话记忆"}),e.jsx("span",{className:"setrow-note",children:"会话间自动回忆与后台整理"})]}),e.jsx("input",{type:"checkbox",className:"wudao-switch",checked:s?.settings.memoryEnabled??!0,disabled:c==="set:memoryEnabled",onChange:x=>m("memoryEnabled",x.target.checked,`记忆已${x.target.checked?"开启":"关闭"} —— 下会话生效`)})]}),In()==="desktop"?e.jsxs("label",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"关闭窗口时保持后台运行"}),e.jsx("span",{className:"setrow-note",children:"关窗不退出应用,正在跑的活继续推进;点程序坞图标或托盘「打开主窗口」随时回来;合盖休眠时活同样暂停"})]}),e.jsx("input",{type:"checkbox",className:"wudao-switch","data-background-on-close":!0,checked:s?.settings.desktopBackgroundOnClose??!1,disabled:c==="set:desktop.backgroundOnClose",onChange:x=>m("desktop.backgroundOnClose",x.target.checked,x.target.checked?"关窗后台运行已开启 —— 关窗不退出,活继续跑":"关窗后台运行已关闭 —— 关窗即退出应用")})]}):null,In()==="desktop"&&(s?.settings.schedulesLaunchAgentSupported??!0)?e.jsxs("label",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"定时任务离线唤起"}),e.jsx("span",{className:"setrow-note",children:"应用没开着,到点也会自动打开应用执行;合盖休眠时等唤醒后立即补跑"})]}),e.jsx("input",{type:"checkbox",className:"wudao-switch","data-schedule-launch-agent":!0,checked:s?.settings.schedulesLaunchAgent??!1,disabled:c==="set:schedules.launchAgent",onChange:x=>m("schedules.launchAgent",x.target.checked,x.target.checked?"定时任务离线唤起已开启 —— 应用没开着,到点也会自动唤起执行":"定时任务离线唤起已关闭 —— 定时任务只在应用开着时执行")})]}):null,e.jsxs("div",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"默认界面"}),e.jsx("span",{className:"setrow-note",children:"下次打开应用进入的界面;立即切换,重载后完全生效"})]}),e.jsx("div",{className:"segctl",role:"radiogroup","aria-label":"默认界面",children:["simple","buddy","advanced"].map(x=>e.jsx("button",{type:"button",role:"radio","aria-checked":(s?.settings.uiDefaultMode??"advanced")===x,"data-default-mode":x,className:`segctl-opt${(s?.settings.uiDefaultMode??"advanced")===x?" on":""}`,disabled:c==="set:ui.defaultMode",onClick:()=>m("ui.defaultMode",x,`默认界面 → ${er[x]} —— 已切换,重载后完全生效`),children:er[x]},x))})]}),e.jsxs("div",{className:"setrow",children:[e.jsxs("span",{className:"setrow-main",children:[e.jsx("span",{className:"setrow-title",children:"默认推理档"}),e.jsx("span",{className:"setrow-note",children:"新会话生效;当前会话用输入框下方的强度 chip 切"})]}),e.jsx("div",{className:"segctl",role:"radiogroup","aria-label":"默认推理档",children:(s?.efforts??[]).map(x=>e.jsx("button",{type:"button",role:"radio","aria-checked":s?.defaultEffort===x,"data-default-effort":x,className:`segctl-opt${s?.defaultEffort===x?" on":""}`,disabled:c==="set:model.defaultEffort",onClick:()=>m("model.defaultEffort",x,`默认推理档 → ${x} —— 新会话生效`),children:x},x))})]}),e.jsx("div",{className:"hint",children:"写入全局设置(~/.wudao/settings.json)"})]}),N!=null?e.jsxs("div",{className:"settings-section set-sec memory-manage","data-lt-memory":!0,children:[e.jsx("h3",{className:"section-title set-title",children:"长期记忆"}),e.jsx("div",{className:"hint",children:"跨会话记住的偏好与经验——新会话自动带上,删掉就忘"}),N.length===0?e.jsx("div",{className:"mem-empty",children:"还没有长期记忆——对话中让它记住的事会存在这里"}):N.map(x=>e.jsxs("div",{className:"mem-row","data-lt-entry":x.id,children:[e.jsx("span",{className:"mem-kind",children:`${x.kind} · 用过 ${x.useCount} 次`}),e.jsx("span",{className:"mem-text",children:x.text}),e.jsx("button",{type:"button",className:"wudao mem-del",disabled:R===x.id,onClick:()=>z(x.id),children:R===x.id?"删除中…":"忘掉"})]},x.id))]}):null,g!=null?e.jsxs("div",{className:"settings-section set-sec memory-manage",children:[e.jsx("h3",{className:"section-title set-title",children:"管理记忆"}),e.jsx("div",{className:"hint",children:"模型替你记下的内容都在这里——确认后参与回忆,丢弃即删除该条"}),f>0?e.jsx("div",{className:"hint mem-blocked","data-blocked-count":f,children:`已拦 ${f} 条可疑学习输入(含密钥或指令注入形状,未入库——明细在 .wudao/memory-blocked.jsonl)`}):null,g.length===0?e.jsx("div",{className:"mem-empty",children:"还没有记忆——用得越久攒得越多"}):g.map(x=>{const b=x.status==="pending",k=Kl(x.created);return q===x.id?e.jsxs("div",{className:"mem-row editing","data-mem-id":x.id,children:[e.jsx("span",{className:`mem-badge${b?"":" ok"}`,children:b?"待审":"生效"}),e.jsxs("span",{className:"mem-main mem-edit",children:[e.jsx("textarea",{value:V,disabled:$!==null,onChange:w=>H(w.target.value)}),e.jsxs("span",{className:"mem-acts",children:[e.jsx("button",{type:"button",className:"wudao action",disabled:$!==null||V.trim()==="",onClick:()=>O(x.id),children:"保存"}),e.jsx("button",{type:"button",className:"wudao",disabled:$!==null,onClick:()=>{D(null),H("")},children:"取消"})]})]})]},x.id):e.jsxs("div",{className:"mem-row","data-mem-id":x.id,children:[e.jsx("span",{className:`mem-badge${b?"":" ok"}`,children:b?"待审":"生效"}),e.jsxs("span",{className:"mem-main",children:[e.jsx("span",{className:"mem-kind",children:`${Ni(x.kind)} · ${ki(x.scope)}${k!==""?` · ${k}`:""} · 被想起 ${x.hits} 次`}),e.jsx("span",{className:"mem-content",children:x.content})]}),e.jsxs("span",{className:"mem-acts",children:[e.jsx("button",{type:"button",className:"wudao",disabled:$!==null,onClick:()=>{D(x.id),H(x.content)},children:"改写"}),b?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"wudao action",disabled:$!==null,onClick:()=>K(x.id,"ok"),children:"确认"}),e.jsx("button",{type:"button",className:"wudao danger",disabled:$!==null,onClick:()=>K(x.id,"del"),children:"丢弃"})]}):null]})]},x.id)})]}):null,P!=null?e.jsxs("div",{className:"settings-section set-sec memory-manage",children:[e.jsx("h3",{className:"section-title set-title",children:"改进提案"}),e.jsx("div",{className:"hint",children:"失败反复出现时,助手会提议把它总结成一条工作规则——规则在激活前经过自动门禁和你的两次确认,随时可撤销"}),P.length===0?e.jsx("div",{className:"mem-empty",children:"还没有改进提案——同一个失败出现三次后会在这里提议"}):P.map(x=>{const b=Kl(x.createdAt),k=x.subject.length>60?`${x.subject.slice(0,59)}…`:x.subject;return e.jsxs("div",{className:"mem-row","data-improve-id":x.id,"data-improve-status":x.status,children:[e.jsx("span",{className:`mem-badge${x.status==="gated"||x.status==="activated"?" ok":""}`,children:Xm(x.status)}),e.jsxs("span",{className:"mem-main",children:[e.jsx("span",{className:"mem-kind",children:`${k} · 已出现 ${x.count} 次${b!==""?` · ${b}`:""}`}),x.status==="offered"?e.jsxs(e.Fragment,{children:[x.preview!==void 0&&x.preview!==""?e.jsx("span",{className:"mem-content",children:x.preview}):null,x.attempts>0&&x.lastError!==void 0?e.jsx("span",{className:"hint",children:`上次生成失败:${x.lastError}`}):null]}):null,x.status==="proposing"?e.jsx("span",{className:"hint",children:"正在生成提案并自动过门禁——完成或失败后这里更新"}):null,(x.status==="gated"||x.status==="activated"||x.status==="undone"||x.status==="gate-failed")&&x.ruleText!==void 0?e.jsxs(e.Fragment,{children:[x.problemSummary!==void 0?e.jsx("span",{className:"mem-content",children:x.problemSummary}):null,e.jsx("span",{className:"mem-content",children:x.ruleText}),e.jsx("span",{className:"hint",children:`适用范围:${x.scope??"全工作区"}${x.paths!==void 0?`(${x.paths.join("、")})`:""}${x.gate!==void 0?` · 门禁${x.gate.ok?"已过":"未过"}(${x.gate.suites.filter(w=>w.status==="pass").length}/${x.gate.suites.length} 项套件全绿)`:""}`}),x.status==="activated"&&x.ruleFile!==void 0?e.jsx("span",{className:"hint",children:`已写入 ${x.ruleFile}——下次会话生效`}):null,x.status==="gate-failed"&&x.lastError!==void 0?e.jsx("span",{className:"hint",children:`未激活(${x.lastError})——原样留档`}):null]}):null,(x.status==="rejected"||x.status==="ignored"||x.status==="abandoned")&&x.lastError!==void 0?e.jsx("span",{className:"hint",children:x.lastError}):null]}),e.jsxs("span",{className:"mem-acts",children:[x.status==="offered"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"wudao action",disabled:U!==null,onClick:()=>le(x.id,"consent"),children:"生成提案"}),e.jsx("button",{type:"button",className:"wudao",disabled:U!==null,onClick:()=>le(x.id,"ignore"),children:"忽略"})]}):null,x.status==="gated"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"wudao action",disabled:U!==null,onClick:()=>le(x.id,"activate"),children:"激活"}),e.jsx("button",{type:"button",className:"wudao danger",disabled:U!==null,onClick:()=>le(x.id,"reject"),children:"驳回"})]}):null,x.status==="activated"?e.jsx("button",{type:"button",className:"wudao",disabled:U!==null,onClick:()=>le(x.id,"undo"),children:"撤销"}):null,x.status==="undone"?e.jsx("button",{type:"button",className:"wudao",disabled:U!==null,onClick:()=>le(x.id,"activate"),children:"重新激活"}):null]})]},x.id)})]}):null,r!=null?e.jsxs("div",{className:"settings-section set-sec",children:[e.jsx("h3",{className:"section-title set-title",children:"语言"}),e.jsx("div",{className:"prefrow",children:e.jsx(Vm,{value:r,disabled:c!==null&&c.startsWith("set:language."),onPick:(x,b)=>p(x,b),onPersistDefault:x=>p(x,r[x])})}),e.jsx("div",{className:"hint",children:"回答与思考的语言偏好(新会话默认生效;当前会话临时切换可用 /language 命令)。"})]}):null]})}const tr=t=>t instanceof Error?t.message:String(t);function Pi(t){return t.map(s=>({name:s.name.trim(),ctx:s.ctx.trim()})).filter(s=>s.name!=="").map(s=>{const n=Number.parseInt(s.ctx,10);return s.ctx!==""&&Number.isInteger(n)&&n>0?{name:s.name,contextLength:n}:{name:s.name}})}function Qm({client:t,card:s,keyDraft:n,fallbackWindow:a,notify:l,refresh:r,onClose:o,onSaved:c}){const[d,m]=i.useState(()=>s.models.map(K=>({name:K.name,ctx:K.contextLength!=null?String(K.contextLength):""}))),[p,g]=i.useState(""),[v,N]=i.useState(""),[S,R]=i.useState(!1),[j,f]=i.useState(null),[A,$]=i.useState(null),[y,q]=i.useState(!1),[D,V]=i.useState(!1),H=i.useRef(null),X=i.useRef(null),W=i.useRef({composing:!1,endedAt:0});i.useEffect(()=>{H.current?.focus()},[]);const z=()=>{q(!0),$(null),t.settingsListModels(s.provider,n.trim()!==""?{key:n.trim()}:void 0).then(K=>{if(!K.ok){$({state:K.state,message:K.message});return}const O=new Set;f(K.models.filter(x=>x.name===""||O.has(x.name)?!1:(O.add(x.name),!0)))}).catch(K=>$({state:"network",message:tr(K)})).finally(()=>q(!1))};i.useEffect(()=>{z()},[]);const F=new Set(d.map(K=>K.name.trim()).filter(K=>K!=="")),M=p.trim(),P=M!==""&&!F.has(M),T=p.trim().toLowerCase(),U=j===null?[]:T===""?j:j.filter(K=>K.name.toLowerCase().includes(T)),Q=K=>{g(K.name),K.contextLength!=null&&N(String(K.contextLength)),R(!1)},se=()=>{P&&(m(K=>[...K,{name:M,ctx:v.trim()}]),g(""),N(""),R(!1))},de=(K,O)=>{m(x=>x.map((b,k)=>k===K?{...b,...O}:b))},le=()=>{V(!0);const K=Pi(d),O=s.custom?{...s.label.trim()!==""?{label:s.label.trim()}:{},baseUrl:(s.baseUrl??"").trim(),...s.defaultModel!==""?{defaultModel:s.defaultModel}:{},...s.defaultContextLength!=null?{defaultContextLength:s.defaultContextLength}:{},...s.reasoningFormat!==void 0?{reasoningFormat:s.reasoningFormat}:{},...(s.wire??"")!==""?{wire:s.wire}:{},...s.persona!==void 0?{persona:s.persona}:{},...s.effort!==void 0?{effort:s.effort}:{},models:K}:{models:K,...s.reasoningFormat!==void 0?{reasoningFormat:s.reasoningFormat}:{},...s.wire!==void 0?{wire:s.wire}:{},...s.persona!==void 0?{persona:s.persona}:{},...s.effort!==void 0?{effort:s.effort}:{}};t.settingsSaveProvider(s.provider,O).then(x=>{x.ok?(l(`已保存供应商 ${x.provider} 的模型配置`),c(d),r(),o()):l(`⚠️ 保存失败:${x.error}`)}).catch(x=>l(`⚠️ 保存失败:${tr(x)}`)).finally(()=>V(!1))};return e.jsx("div",{className:"scrim",onClick:K=>{K.target===K.currentTarget&&o()},children:e.jsxs("div",{className:"modal-card pop-in mcm",role:"dialog","aria-modal":"true","aria-label":`配置模型 ${s.provider}`,ref:X,tabIndex:-1,onCompositionStart:()=>{W.current=He(W.current)},onCompositionEnd:()=>{W.current=_e(W.current,Date.now())},onKeyDown:K=>{Ue(K.nativeEvent,W.current,Date.now())||K.key==="Escape"&&(K.preventDefault(),K.stopPropagation(),o())},children:[e.jsxs("div",{className:"mcm-head",children:[e.jsx("h3",{children:`配置模型 · ${s.provider}`}),e.jsx("button",{type:"button",className:"ctl mcm-close","aria-label":"关闭",title:"关闭(丢弃未保存的修改)",onClick:o,children:"✕"})]}),e.jsxs("div",{className:"mcm-add",children:[e.jsxs("div",{className:"mcm-add-name",children:[e.jsx("input",{ref:H,type:"text",className:"wudao-input ctl mcm-name","aria-label":"模型名称",placeholder:"模型名称(手输,或从下拉选择)",value:p,onChange:K=>g(K.target.value)}),e.jsx("button",{type:"button",className:"ctl mcm-drop-toggle","aria-label":"选择模型","aria-expanded":S,title:y?"正在拉取 /models…":j===null?"拉取 /models 目录":"展开 /models 目录(输入框文字为过滤词)",disabled:y,onClick:()=>{if(j===null){R(!0),z();return}R(K=>!K)},children:S?"收起 ▴":"选择 ▾"}),e.jsx("button",{type:"button",className:"ctl mcm-refresh","aria-label":"刷新模型列表",title:"重新拉取 /models",disabled:y,onClick:z,children:"⟳"}),S&&j!==null?e.jsxs("div",{className:"mcm-drop",role:"listbox","aria-label":"可用模型",children:[U.map(K=>{const O=F.has(K.name);return e.jsxs("button",{type:"button",role:"option","aria-selected":"false",className:"mcm-opt",disabled:O,onClick:()=>Q(K),children:[e.jsx("span",{className:"mcm-opt-name",children:K.name}),K.contextLength!=null?e.jsx("span",{className:"mcm-opt-ctx",children:K.contextLength}):null,O?e.jsx("span",{className:"mcm-opt-tag",children:"已配置"}):null]},K.name)}),U.length===0?e.jsx("div",{className:"mcm-drop-empty",children:"无匹配模型"}):null]}):null]}),e.jsx("input",{type:"text",className:"wudao-input ctl mcm-ctx","aria-label":"上下文窗口",inputMode:"numeric",placeholder:a!=null?`留空 = 继承 ${a}`:"留空 = 继承供应商默认",title:"上下文窗口(token);留空 = 继承供应商默认窗口",value:v,onChange:K=>N(K.target.value)}),e.jsx("button",{type:"button",className:"ctl",disabled:!P,onClick:se,children:"添加"})]}),y?e.jsx("div",{className:"muted mcm-pulling",children:"正在拉取 /models…"}):null,A!==null?e.jsxs("div",{className:"mcm-pull-error test-result fail","data-state":A.state,children:[e.jsx("span",{children:A.message}),e.jsx("button",{type:"button",className:"ctl",onClick:z,children:"重试"})]}):null,e.jsx("div",{className:"mcm-list-head",title:"上下文窗口留空 = 继承供应商默认",children:`已配置(${d.length})`}),e.jsx("div",{className:"mcm-rows",children:d.length===0?e.jsx("div",{className:"muted mcm-empty",children:"从上方添加模型(手输或 /models 下拉选择)"}):d.map((K,O)=>{const x=K.name.trim()!==""?K.name:`第${O+1}行`;return e.jsxs("div",{className:"mcm-row",children:[e.jsx("input",{type:"text",className:"wudao-input ctl mcm-name","aria-label":`模型名 ${x}`,value:K.name,onChange:b=>de(O,{name:b.target.value})}),e.jsx("input",{type:"text",className:"wudao-input ctl mcm-ctx","aria-label":`上下文 ${x}`,inputMode:"numeric",placeholder:a!=null?`继承 ${a}`:"继承供应商默认",value:K.ctx,onChange:b=>de(O,{ctx:b.target.value})}),e.jsx("button",{type:"button",className:"ctl mcm-del","aria-label":`删除模型 ${x}`,title:"删除该行",onClick:()=>m(b=>b.filter((k,w)=>w!==O)),children:"✕"})]},O)})}),e.jsxs("div",{className:"btnrow mcm-foot",children:[e.jsx("button",{type:"button",className:"ctl",onClick:o,children:"取消"}),e.jsx("button",{type:"button",className:"ctl wudao primary",disabled:D,onClick:le,children:"保存"})]})]})})}const Zm={id:"",label:"",baseUrl:"",reasoningFormat:"none",wire:""};function ep({client:t,notify:s,refresh:n,onCreated:a,onCancel:l}){const[r,o]=i.useState(Zm),[c,d]=i.useState(!1),[m,p]=i.useState(void 0),[g,v]=i.useState(null),[N,S]=i.useState("");i.useEffect(()=>{let j=!0;return t.personaList().then(f=>{j&&v(f.personas)}).catch(()=>{}),()=>{j=!1}},[t]);const R=()=>{const j=r.id.trim(),f=r.baseUrl.trim();j===""||f===""||(d(!0),t.settingsSaveProvider(j,{...r.label.trim()!==""?{label:r.label.trim()}:{},baseUrl:f,reasoningFormat:r.reasoningFormat,...r.wire!==""?{wire:r.wire}:{},...m!==void 0?{persona:m}:{},models:[]}).then(A=>{A.ok?(a(j),s(`已添加供应商 ${A.provider} —— 保存 Key 后即可使用`),n()):s(`⚠️ 添加失败:${A.error}`)}).catch(A=>s(`⚠️ 添加失败:${ft(A)}`)).finally(()=>d(!1)))};return e.jsxs("div",{className:"provider-detail new-provider-detail",children:[e.jsxs("div",{className:"detail-head",children:[e.jsx("span",{className:"dot draft",title:"未保存"}),e.jsx("strong",{children:"新增供应商"}),e.jsx("span",{className:"meta",children:"未保存"})]}),e.jsxs("div",{className:"detail-group",children:[e.jsx("div",{className:"detail-group-title",children:"基本信息"}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"id"}),e.jsx("input",{type:"text",className:"wudao-input ctl add-id","aria-label":"新供应商 id",placeholder:"id(字母开头,如 my-gateway)",value:r.id,onChange:j=>o(f=>({...f,id:j.target.value}))})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"显示名称"}),e.jsx("input",{type:"text",className:"wudao-input ctl add-label","aria-label":"显示名称",placeholder:"显示名称(可空 = id)",value:r.label,onChange:j=>o(f=>({...f,label:j.target.value}))})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"Base URL"}),e.jsx("input",{type:"text",className:"wudao-input ctl add-baseurl","aria-label":"Base URL",placeholder:"https://…(必填)",value:r.baseUrl,onChange:j=>o(f=>({...f,baseUrl:j.target.value}))})]})]}),e.jsxs("div",{className:"detail-group",children:[e.jsx("div",{className:"detail-group-title",children:"协议与格式"}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"推理格式"}),e.jsx("select",{className:"ctl add-format","aria-label":"推理格式",value:r.reasoningFormat,onChange:j=>o(f=>({...f,reasoningFormat:j.target.value})),children:Uo.map(j=>e.jsx("option",{value:j,children:j},j))})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"协议"}),e.jsx("select",{className:"ctl add-wire","aria-label":"协议",value:r.wire,onChange:j=>o(f=>({...f,wire:j.target.value})),children:jr.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{className:"detail-group",children:[e.jsx("div",{className:"detail-group-title",children:"Persona"}),e.jsxs("div",{className:"detail-field pair",children:[e.jsx("span",{className:"detail-field-label",children:"Persona 绑定"}),e.jsxs("select",{className:"ctl detail-persona","aria-label":"Persona 绑定",title:"跟随全局 = 用全局默认 persona;强制无 = 显式不挂 persona;其余 = 绑定该 persona",value:m===void 0?$t:m===null?Rt:Xe(m).id,onChange:j=>{const f=j.target.value;p(f===$t?void 0:f===Rt?null:Dt(f,N))},children:[e.jsx("option",{value:$t,children:"跟随全局"}),(g??[]).map(j=>e.jsx("option",{value:j.id,children:j.displayName!=null?`${j.displayName} (${j.id})`:j.id},j.id)),e.jsx("option",{value:Rt,children:"强制无"})]}),e.jsx("select",{className:"ctl detail-persona-layer","aria-label":"Persona 层",title:"限定绑定的 persona 只作用于选中的层(全部层 = 完整指纹)",value:N,onChange:j=>{const f=j.target.value;S(f),p(A=>typeof A=="string"?Dt(Xe(A).id,f):A)},children:ca.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{className:"detail-actions",children:[e.jsx("button",{type:"button",className:"ctl",disabled:r.id.trim()===""||r.baseUrl.trim()===""||c,onClick:R,children:"创建"}),e.jsx("button",{type:"button",className:"ctl",onClick:l,children:"取消"})]})]})}function tp({client:t,card:s,models:n,currentProvider:a,currentModel:l,defaultModel:r,notify:o,refresh:c}){const[d,m]=i.useState(()=>vn(s)),[p,g]=i.useState(!1),[v,N]=i.useState(!1),[S,R]=i.useState(!0),[j,f]=i.useState(null),[A,$]=i.useState(""),[y,q]=i.useState(null),[D,V]=i.useState(null),[H,X]=i.useState(null),[W,z]=i.useState(()=>typeof s.persona=="string"?Xe(s.persona).layer:"");i.useEffect(()=>{let w=!0;return t.personaList().then(E=>{w&&X(E.personas)}).catch(()=>{}),()=>{w=!1}},[t]),i.useEffect(()=>{S&&(m(vn(s)),z(typeof s.persona=="string"?Xe(s.persona).layer:""))},[s]);const F=w=>{R(!1),m(w)},M=()=>{m(vn(s)),z(typeof s.persona=="string"?Xe(s.persona).layer:""),R(!0),$(""),g(!1)},P=()=>{const w=A.trim(),E=n[0],G=w!==""?{key:w,...E!==void 0?{model:E}:{}}:E!==void 0?{model:E}:void 0;q("test"),t.settingsTestConnection(s.provider,G).then(ee=>{V(ee)}).catch(ee=>o(`⚠️ 测试失败:${ft(ee)}`)).finally(()=>q(null))},T=(w,E)=>{t.submit(w).then(()=>o(E)).catch(G=>o(`⚠️ ${ft(G)}`))},U=w=>{t.settingsSet("model.defaultModel",{provider:s.provider,model:w}).then(()=>{o(`已设为默认:${s.provider}/${w} —— 下次启动 wudao ui 生效`),c()}).catch(E=>o(`⚠️ 默认模型保存失败:${ft(E)}`))},Q=()=>{f("save");const w=A.trim();w!==""&&(q("save"),t.settingsSaveKey(s.provider,w).then(ee=>{$(""),o(`已保存 ${ee.provider} 的 Key(凭据文件现有 ${ee.keyCount} 个,权限 0600)——下会话可用`),c()}).catch(ee=>o(`⚠️ 保存失败:${ft(ee)}`)).finally(()=>q(null)));const E=Pi(d.rows),G=s.custom?{...d.label.trim()!==""?{label:d.label.trim()}:{},baseUrl:d.baseUrl.trim(),...s.defaultModel!==""?{defaultModel:s.defaultModel}:{},...s.defaultContextLength!=null?{defaultContextLength:s.defaultContextLength}:{},...s.reasoningFormat!==void 0?{reasoningFormat:s.reasoningFormat}:{},...d.wire!==""?{wire:d.wire}:{},...d.persona!==void 0?{persona:d.persona}:{},...d.effort!==void 0?{effort:d.effort}:{},models:E}:{models:E,...d.label.trim()!==""&&d.label.trim()!==s.label?{label:d.label.trim()}:{},...d.baseUrl.trim()!==""?{baseUrl:d.baseUrl.trim()}:{},...s.reasoningFormat!==void 0?{reasoningFormat:s.reasoningFormat}:{},...s.wire!==void 0?{wire:s.wire}:{},...d.persona!==void 0?{persona:d.persona}:{},...d.effort!==void 0?{effort:d.effort}:{}};t.settingsSaveProvider(s.provider,G).then(ee=>{ee.ok?(R(!0),g(!1),o(`已保存供应商 ${ee.provider} 的注册表配置`),c()):o(`⚠️ 保存失败:${ee.error}`)}).catch(ee=>o(`⚠️ 保存失败:${ft(ee)}`)).finally(()=>f(null))},se=()=>{f("del"),t.settingsDeleteProvider(s.provider).then(w=>{w.ok?(o(`已删除供应商 ${s.provider}`),c()):o(`⚠️ 删除失败:${w.error}`)}).catch(w=>o(`⚠️ 删除失败:${ft(w)}`)).finally(()=>f(null))},de=w=>s.provider===a&&w===l,le=w=>r!=null&&r.provider===s.provider&&r.model===w,K=s.defaultContextLength??s.windowFallback,O=!Fs({provider:s.provider},a),x=typeof d.persona=="string"?Xe(d.persona).id:null,b=s.persona===void 0?"跟随全局":s.persona===null?"强制无":(()=>{const{id:w,layer:E}=Xe(s.persona),G=E===""?w:`${w}:${E}`,ee=(H??[]).find(me=>me.id===w)?.displayName;return ee!=null?`${ee} (${G})`:G})(),k=s.effort===void 0?"跟随全局":s.effort===null?"强制不发送":s.effort;return e.jsxs("div",{className:"provider-detail",children:[e.jsxs("div",{className:"detail-head",children:[e.jsxs("div",{className:"detail-head-id",children:[e.jsx("span",{className:`dot ${s.status}`,title:qn[s.status]}),e.jsx("strong",{children:s.provider==="wudao"?"兼容端点(wudao)":s.label})]}),e.jsxs("div",{className:"detail-head-tags",children:[e.jsx("span",{className:"meta mono-id",children:s.provider}),e.jsx("span",{className:"meta tag",children:s.custom?"自定义":"内置"})]})]}),e.jsxs("div",{className:"detail-group",children:[e.jsx("div",{className:"detail-group-title",children:"接入"}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"名称"}),p?e.jsx("input",{type:"text",className:"wudao-input ctl detail-label-input","aria-label":`${s.label} 显示名称`,value:d.label,onChange:w=>F(E=>({...E,label:w.target.value}))}):e.jsx("span",{className:"detail-read-text",children:s.label})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"baseUrl"}),p?e.jsx("input",{type:"text",className:"wudao-input ctl detail-baseurl","aria-label":`${s.label} Base URL`,placeholder:s.custom?void 0:"留空 = 使用编译内置端点;填入则覆盖",value:d.baseUrl,onChange:w=>F(E=>({...E,baseUrl:w.target.value}))}):e.jsx("span",{className:"card-endpoint",children:s.baseUrl??"(使用编译内置端点)"})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"协议"}),p&&s.custom?e.jsx("select",{className:"ctl detail-wire","aria-label":`${s.label} 协议`,title:"选 Anthropic 协议后,该供应商走 /v1/messages 适配器(无需再设 WUDAO_WIRE)",value:d.wire,onChange:w=>F(E=>({...E,wire:w.target.value})),children:jr.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))}):e.jsx("span",{className:"card-endpoint detail-wire-fixed",children:Ho(s.wire)})]}),e.jsxs("div",{className:"detail-field key-field",children:[e.jsx("span",{className:"detail-field-label",children:"API Key"}),p?e.jsxs("div",{className:"keyrow",children:[e.jsx("input",{type:"password",className:"wudao-input key-input ctl",placeholder:"粘贴 API Key — 随「保存修改」写入本机凭据文件(0600)","aria-label":`${s.label} API Key`,value:A,onChange:w=>$(w.target.value)}),e.jsx("button",{type:"button",className:"ctl",disabled:y!==null,onClick:P,children:"测试连接"})]}):e.jsxs("div",{className:"keyrow",children:[e.jsx("span",{className:`key-badge ${Gn(s).cls}`,title:_i[s.keySource??"none"],children:Gn(s).text}),e.jsx("button",{type:"button",className:"ctl",disabled:y!==null,onClick:P,children:"测试连接"})]})]}),D!==null?e.jsx("div",{className:`test-result ${D.ok?"ok":`fail ${D.state}`}`,"data-state":D.state,children:D.message}):null]}),e.jsxs("div",{className:"model-manager",children:[e.jsxs("div",{className:"model-manager-head",children:["模型",e.jsx("button",{type:"button",className:"wudao primary model-config",onClick:()=>N(!0),children:"配置模型"})]}),d.rows.map((w,E)=>{const G=de(w.name);return e.jsxs("div",{className:`model-row model-read-row${G?" live":""}`,children:[e.jsx("span",{className:"model-row-name",children:w.name}),e.jsx("span",{className:"model-row-ctx",children:w.ctx.trim()!==""?w.ctx.trim():K!=null?`继承 ${K}`:"继承供应商默认"}),e.jsxs("span",{className:"model-row-state",children:[le(w.name)?e.jsx("button",{type:"button",className:"ctl model-star",disabled:!0,"aria-label":`已是默认模型 ${w.name}`,title:"启动默认模型(model.defaultModel)——下次启动 wudao ui 生效",children:e.jsx(ae,{name:"star",size:13,filled:!0})}):e.jsx("button",{type:"button",className:"ctl model-star","aria-label":`设为默认模型 ${w.name}`,title:"设为 wudao ui 的启动默认模型(model.defaultModel)——下次启动生效",disabled:w.name.trim()==="",onClick:()=>U(w.name.trim()),children:e.jsx(ae,{name:"star",size:13})}),G?e.jsx("span",{className:"model-badge live",title:"当前会话正在使用的模型",children:"当前"}):null,e.jsx("button",{type:"button",className:"ctl model-use","aria-label":`切换到 ${w.name}`,title:O?`submit /provider ${s.provider} (switches the endpoint)`:`submit /model ${w.name}`,disabled:!O&&w.name===l,onClick:()=>{const ee=wr({provider:s.provider,model:w.name},a);T(ee,O?`供应商 → ${s.provider} — 下一轮起切换端点,历史将全部重新处理(缓存全冷)`:`模型 → ${w.name} — 下一轮生效`)},children:"使用"})]})]},E)}),d.rows.length===0?e.jsx("div",{className:"model-empty muted",children:"尚未配置模型 —— 点击「配置模型」添加"}):null]}),e.jsxs("div",{className:"detail-group",children:[e.jsx("div",{className:"detail-group-title",children:"行为"}),e.jsxs("div",{className:"detail-field pair",children:[e.jsx("span",{className:"detail-field-label",children:"Persona 绑定"}),p?e.jsxs(e.Fragment,{children:[e.jsxs("select",{className:"ctl detail-persona","aria-label":"Persona 绑定",title:"跟随全局 = 用全局默认 persona;强制无 = 显式不挂 persona;其余 = 绑定该 persona",value:d.persona===void 0?$t:d.persona===null?Rt:Xe(d.persona).id,onChange:w=>{const E=w.target.value;F(G=>({...G,persona:E===$t?void 0:E===Rt?null:Dt(E,W)}))},children:[e.jsx("option",{value:$t,children:"跟随全局"}),(H??[]).map(w=>e.jsx("option",{value:w.id,children:w.displayName!=null?`${w.displayName} (${w.id})`:w.id},w.id)),x!==null&&!(H??[]).some(w=>w.id===x)?e.jsx("option",{value:x,children:`${x}(未注册)`}):null,e.jsx("option",{value:Rt,children:"强制无"})]}),e.jsx("select",{className:"ctl detail-persona-layer","aria-label":"Persona 层",title:"限定绑定的 persona 只作用于选中的层(全部层 = 完整指纹)",value:W,onChange:w=>{const E=w.target.value;z(E),F(G=>({...G,persona:typeof G.persona=="string"?Dt(Xe(G.persona).id,E):G.persona}))},children:ca.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]}):e.jsx("span",{className:"detail-read-text",children:b})]}),e.jsxs("div",{className:"detail-field",children:[e.jsx("span",{className:"detail-field-label",children:"推理档绑定"}),p?e.jsxs("select",{className:"ctl detail-effort","aria-label":"推理档绑定",title:"跟随全局 = 用全局默认推理档;强制不发送 = 该供应商不发送 reasoning_effort;其余 = 绑定该档位",value:d.effort===void 0?gn:d.effort===null?jn:d.effort,onChange:w=>{const E=w.target.value;F(G=>({...G,effort:E===gn?void 0:E===jn?null:E}))},children:[e.jsx("option",{value:gn,children:"跟随全局"}),qo.map(w=>e.jsx("option",{value:w,children:w},w)),e.jsx("option",{value:jn,children:"强制不发送"})]}):e.jsx("span",{className:"detail-read-text",children:k})]})]}),e.jsx("div",{className:"detail-actions",children:p?e.jsxs(e.Fragment,{children:[S?null:e.jsx("span",{className:"detail-unsaved",children:"未保存的修改"}),e.jsx("button",{type:"button",className:"ctl detail-save",disabled:j!==null,onClick:Q,children:"保存修改"}),e.jsx("button",{type:"button",className:"ctl detail-cancel",onClick:M,children:"取消编辑"}),s.custom?e.jsx("button",{type:"button",className:"ctl detail-del",disabled:j!==null,onClick:se,children:"删除供应商"}):null]}):e.jsx("button",{type:"button",className:"ctl detail-edit",onClick:()=>g(!0),children:"编辑"})}),v?e.jsx(Qm,{client:t,card:s,keyDraft:A,fallbackWindow:K,notify:o,refresh:c,onClose:()=>N(!1),onSaved:w=>m(E=>({...E,rows:w}))}):null]})}function _s(t,s){const n=(s?.model?.choices??[]).filter(a=>a.provider===t.provider).map(a=>a.model);return n.includes(t.defaultModel)?n:[...n,t.defaultModel]}const qn={ready:"可用","missing-key":"缺 Key","missing-endpoint":"缺端点"},_i={env:"key: 环境变量",credentials:"key: 凭据文件",none:"key: 未配置"},sr={env:{cls:"on",text:"已配 · 环境变量"},credentials:{cls:"on",text:"已配 · 凭据文件"},none:{cls:"off",text:"未配 Key"}},Gn=t=>sr[t.keySource??"none"]??sr.none,nr=t=>t instanceof Error?t.message:String(t);function sp({client:t,settings:s,status:n,notify:a,refresh:l,loadError:r}){const[o,c]=i.useState(null),[d,m]=i.useState(""),[p,g]=i.useState(null),[v,N]=i.useState(!1),[S,R]=i.useState(!1),j=i.useRef(null);i.useEffect(()=>{S&&j.current?.focus()},[S]);const f=i.useRef({composing:!1,endedAt:0}),A=(M,P)=>{t.submit(M).then(()=>a(P)).catch(T=>a(`⚠️ ${nr(T)}`))},$=M=>{c(`del:${M}`),t.settingsDeleteProvider(M).then(P=>{P.ok?(a(`已删除供应商 ${M}`),l()):a(`⚠️ 删除失败:${P.error}`)}).catch(P=>a(`⚠️ 删除失败:${nr(P)}`)).finally(()=>c(null))},y=n?.model?.provider??s?.current.provider,q=n?.model?.label??s?.current.model??"",D=s?.providers??[],V=D.filter(M=>M.invalidReason===void 0),H=d.trim().toLowerCase(),X=H===""?D:D.filter(M=>{const P=[...M.models.map(T=>T.name),..._s(M,n)];return[M.label,M.provider,M.baseUrl??"",M.endpoint??"",...P].join(`
322
+ `).toLowerCase().includes(H)}),W=v?null:V.find(M=>M.provider===p)??null,z=()=>{R(!1),N(!1)},F=s===null?null:v?{aria:"新增供应商",head:"新增供应商",body:e.jsx(ep,{client:t,notify:a,refresh:l,onCreated:M=>{g(M),N(!1)},onCancel:z})}:W!==null?{aria:`供应商 ${W.label}`,head:`供应商 · ${W.provider==="wudao"?"兼容端点(wudao)":W.label}`,body:e.jsx(tp,{client:t,card:W,models:_s(W,n),currentProvider:y,currentModel:q,defaultModel:s.defaultModel,notify:a,refresh:l},W.provider)}:null;return e.jsxs(e.Fragment,{children:[s?.envKey===!0?e.jsx("div",{className:"hint",children:"检测到环境变量 Key(WUDAO_API_KEY)——环境变量优先于凭据文件;保存到文件的 Key 只在没有环境变量时生效"}):null,e.jsxs("div",{className:"settings-section set-sec",children:[e.jsx("h3",{className:"section-title set-title",children:"供应商"}),s===null&&r!=null?e.jsxs("div",{className:"provider-load-error",role:"alert",children:[e.jsx("span",{className:"entry-error",children:`无法读取设置:${r}`}),e.jsx("button",{type:"button",className:"ctl",onClick:l,children:"重试"})]}):null,s===null&&r==null?e.jsx("div",{className:"muted",children:"读取中…"}):null,s!==null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"provider-toolbar",children:[e.jsx("input",{type:"text",className:"wudao-input ctl provider-search","aria-label":"搜索供应商",placeholder:"搜索:名称 / id / baseUrl / 模型名",value:d,onChange:M=>m(M.target.value)}),e.jsx("button",{type:"button",className:"ctl",onClick:()=>{N(!0),R(!0)},children:"+ 添加供应商"})]}),e.jsx("div",{className:"provider-master",children:e.jsxs("div",{className:"provider-cards",children:[v?e.jsxs("div",{className:"provider-card provider-draft","data-draft":"true","data-provider":"__draft__","aria-current":"true",children:[e.jsxs("div",{className:"card-head",children:[e.jsx("span",{className:"dot draft",title:"未保存"}),e.jsx("span",{className:"card-name",children:"新增供应商"}),e.jsx("span",{className:"meta",children:"未保存"}),e.jsx("button",{type:"button",className:"ctl draft-cancel",onClick:()=>N(!1),children:"✕ 取消草稿"})]}),e.jsx("div",{className:"card-status",children:"在右侧补全信息后创建"})]}):null,X.map(M=>{if(M.invalidReason!==void 0)return e.jsxs("div",{className:"provider-card invalid-card","data-status":M.status,"data-invalid":"true","data-provider":M.provider,children:[e.jsxs("div",{className:"card-head",children:[e.jsx("span",{className:`dot ${M.status}`,title:"注册表条目无效"}),e.jsx("button",{type:"button",className:"card-name",disabled:!0,children:M.label}),e.jsx("span",{className:"meta",children:"注册表条目无效"})]}),e.jsx("div",{className:"invalid-reason",children:M.invalidReason}),e.jsx("div",{className:"keyrow",children:e.jsx("button",{type:"button",className:"ctl",disabled:o===`del:${M.provider}`,onClick:()=>$(M.provider),children:"删除"})})]},M.provider);const P=y===M.provider,T=W?.provider===M.provider,U=Gn(M),Q=()=>{N(!1),g(M.provider),R(!0)};return e.jsxs("div",{className:"provider-card","data-status":M.status,"data-provider":M.provider,"aria-current":T?"true":void 0,onClick:Q,children:[e.jsxs("div",{className:"card-head",children:[e.jsx("span",{className:`dot ${M.status}`,title:qn[M.status]}),e.jsx("button",{type:"button",className:"card-name",title:"选中查看详情",onClick:Q,children:M.provider==="wudao"?"兼容端点(wudao)":M.label}),P?e.jsx("span",{className:"meta tag-default",children:"默认"}):null,e.jsx("span",{className:`key-badge ${U.cls}`,title:_i[M.keySource??"none"],children:U.text})]}),e.jsxs("div",{className:"card-status",children:[e.jsx("span",{className:"status-word",children:qn[M.status]}),e.jsx("span",{className:"meta card-id",children:M.provider}),M.custom?e.jsx("span",{className:"meta",children:"自定义"}):null]}),e.jsx("div",{className:"card-endpoint",title:M.endpoint??void 0,children:M.endpoint??"(未设置端点 —— 需要 WUDAO_BASE_URL)"}),e.jsx("div",{className:"card-model-count",children:`${_s(M,n).length} 个模型`}),e.jsx("div",{className:"card-actions",children:e.jsx("button",{type:"button",className:"ctl card-apply",disabled:P,title:P?"已是当前供应商":`submit /provider ${M.provider} (switches the endpoint)`,onClick:se=>{se.stopPropagation(),A(`/provider ${M.provider}`,`供应商 → ${M.provider} — 下一轮起切换端点,历史将全部重新处理(缓存全冷)`)},children:"应用"})})]},M.provider)}),X.length===0?e.jsx("div",{className:"provider-empty",children:"无匹配供应商"}):null]})}),S&&F!==null?e.jsx("div",{className:"scrim pvd-overlay",onClick:M=>{M.target===M.currentTarget&&z()},children:e.jsxs("div",{className:"modal-card pop-in pvd",role:"dialog","aria-modal":"true","aria-label":F.aria,ref:j,tabIndex:-1,onCompositionStart:()=>{f.current=He(f.current)},onCompositionEnd:()=>{f.current=_e(f.current,Date.now())},onKeyDown:M=>{Ue(M.nativeEvent,f.current,Date.now())||M.key==="Escape"&&(M.preventDefault(),M.stopPropagation(),z())},children:[e.jsxs("div",{className:"pvd-head",children:[e.jsx("h3",{children:F.head}),e.jsx("button",{type:"button",className:"ctl pvd-close","aria-label":"关闭",title:"关闭(丢弃未保存的修改)",onClick:z,children:"✕"})]}),e.jsx("div",{className:"pvd-body",children:F.body})]})}):null,e.jsx("div",{className:"hint",children:`凭据文件:${s.credentials.path}(现有 ${s.credentials.keyCount} 个 Key,仅本机)`})]}):null]})]})}const Et=[{id:"provider",label:"供应商"},{id:"permissions",label:"权限"},{id:"appearance",label:"外观"},{id:"preferences",label:"偏好"},{id:"persona",label:"Persona"},{id:"mcp",label:"MCP"},{id:"plugins",label:"插件"}],np=t=>t instanceof Error?t.message:String(t),ap=4e3;function lp({client:t,status:s,onClose:n,onModeApplied:a,onAccentPicked:l,pendingAsk:r=!1,language:o=null}){const[c,d]=i.useState(null),[m,p]=i.useState(null),[g,v]=i.useState([]),N=i.useRef(0),S=i.useRef(new Map),[R,j]=i.useState("provider"),f=i.useRef([]),A=z=>{if(!["ArrowRight","ArrowLeft","Home","End"].includes(z.key))return;z.preventDefault();const M=Et.findIndex(T=>T.id===R);let P;z.key==="Home"?P=0:z.key==="End"?P=Et.length-1:P=(M+(z.key==="ArrowRight"?1:-1)+Et.length)%Et.length,j(Et[P].id),f.current[P]?.focus()},$=i.useRef(null),y=i.useRef({composing:!1,endedAt:0});tt(),i.useEffect(()=>{$.current?.focus()},[]);const q=i.useCallback(z=>{const F=S.current.get(z);F!==void 0&&(clearTimeout(F),S.current.delete(z)),v(M=>M.filter(P=>P.id!==z))},[]),D=i.useCallback(z=>{const F=++N.current;v(M=>[...M,{id:F,text:z}].slice(-3)),S.current.set(F,setTimeout(()=>{S.current.delete(F),v(M=>M.filter(P=>P.id!==F))},ap))},[]);i.useEffect(()=>{const z=S.current;return()=>{for(const F of z.values())clearTimeout(F);z.clear()}},[]);const V=i.useCallback(()=>{t.settingsStatus().then(z=>{d(z),p(null)}).catch(z=>p(np(z)))},[t]);i.useEffect(()=>{V()},[V]);const H=r?e.jsxs("div",{className:"settings-pending-ask",role:"status",children:[e.jsx(ae,{name:"triangle-alert",size:12})," 有权限请求待确认 — 关闭设置后处理"]}):null,X=m!==null?e.jsx("div",{className:"entry-error",children:`无法读取设置:${m}`}):null,W=e.jsxs(e.Fragment,{children:[X,H]});return e.jsxs("div",{className:"settings-page",ref:$,tabIndex:-1,onCompositionStart:()=>{y.current=He(y.current)},onCompositionEnd:()=>{y.current=_e(y.current,Date.now())},onKeyDown:z=>{Ue(z.nativeEvent,y.current,Date.now())||z.key==="Escape"&&(z.preventDefault(),n())},children:[e.jsxs("div",{className:"set",children:[e.jsxs("div",{className:"set-nav",children:[e.jsxs("div",{className:"settings-head",children:[e.jsx("h3",{children:"设置"}),e.jsx("button",{type:"button",className:"ctl",onClick:n,children:"返回会话"})]}),e.jsx("div",{className:"settings-tabs",role:"tablist","aria-label":"设置分区",onKeyDown:A,children:Et.map((z,F)=>e.jsx("button",{type:"button",role:"tab",id:`settings-tab-${z.id}`,"aria-controls":`settings-panel-${z.id}`,"aria-selected":R===z.id,"data-settings-tab":z.id,className:`sb-i${R===z.id?" on":""}`,onClick:()=>j(z.id),ref:M=>{f.current[F]=M},children:z.label},z.id))})]}),R==="provider"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-provider","aria-labelledby":"settings-tab-provider",className:"set-body",children:[H,e.jsx(sp,{client:t,settings:c,status:s,notify:D,refresh:V,loadError:m})]}):null,R==="permissions"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-permissions","aria-labelledby":"settings-tab-permissions",className:"set-body",children:[W,e.jsx(Am,{client:t,notify:D,status:s})]}):null,R==="appearance"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-appearance","aria-labelledby":"settings-tab-appearance",className:"set-body",children:[W,e.jsx(Em,{client:t,notify:D,onAccentPicked:l})]}):null,R==="preferences"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-preferences","aria-labelledby":"settings-tab-preferences",className:"set-body",children:[W,e.jsx(Jm,{client:t,settings:c,notify:D,refresh:V,onModeApplied:a,language:o,memorySignature:s?.memorySignature})]}):null,R==="persona"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-persona","aria-labelledby":"settings-tab-persona",className:"set-body",children:[W,e.jsx(Gm,{client:t,settings:c,notify:D,refresh:V})]}):null,R==="mcp"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-mcp","aria-labelledby":"settings-tab-mcp",className:"set-body",children:[W,e.jsx(Tm,{client:t})]}):null,R==="plugins"?e.jsxs("div",{role:"tabpanel",id:"settings-panel-plugins","aria-labelledby":"settings-tab-plugins",className:"set-body",children:[W,e.jsx(Lm,{client:t,settings:c,notify:D,refresh:V})]}):null]}),g.length>0?e.jsx("div",{className:"settings-toasts",role:"status","aria-live":"polite",children:g.map(z=>{const F=At(z.text);return e.jsxs("div",{className:"settings-toast","data-variant":F.variant,children:[F.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):F.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,e.jsx("span",{className:"settings-toast-text",children:F.text}),e.jsx("button",{type:"button",className:"settings-toast-close","aria-label":"关闭",onClick:()=>q(z.id),children:"×"})]},z.id)})}):null]})}const ar={ready:"可用","missing-key":"缺 Key","missing-endpoint":"缺端点"},rp=["读懂你的代码库 —— 直接读文件、检索、解释这段代码在做什么","动手干活 —— 修 bug、写页面、跑命令和测试,任何写入先征求你的同意","从一句话开始 —— 用大白话描述你想构建什么,它自己规划步骤并完成"],Mn=["欢迎","选择供应商","粘贴 Key","选择模型","权限","完成"],lt=t=>t instanceof Error?t.message:String(t);function ip({client:t,status:s,settings:n,onDone:a,step:l,total:r}){const[o,c]=i.useState(1),[d,m]=i.useState(null),[p,g]=i.useState(""),[v,N]=i.useState(!1),[S,R]=i.useState(null),[j,f]=i.useState(!1),[A,$]=i.useState(null),[y,q]=i.useState("workspace"),[D,V]=i.useState([]),[H,X]=i.useState([]),[W,z]=i.useState(!1),F=i.useRef(null),M=i.useRef({composing:!1,endedAt:0}),P=n.providers.find(E=>E.provider===d)??null,T=P!==null?_s(P,s).filter(E=>E!==""):[],U=P?.status==="missing-endpoint",Q=l??o,se=Math.max(1,r??Mn.length),de=Mn[Math.min(Math.max(Q,1),Mn.length)-1]??"",le=`${String(Q).padStart(2,"0")}/${String(se).padStart(2,"0")}`,K=`${Math.min(100,Math.round(Q/se*100))}%`;tt(),i.useEffect(()=>{F.current?.focus()},[]);const O=E=>{V(G=>[...G.slice(-4),E])},x=()=>{t.settingsSet("wizard.completedVersion",Fn).catch(E=>{}),a()},b=E=>{X(G=>[...G,E])},k=()=>{if(d===null)return;const E=p.trim();if(E!==""){if(N(!0),R(null),U){t.settingsSaveKey(d,E).then(()=>{f(!0),g(""),O("Key 已保存到凭据文件(权限 0600)—— 仅保存在本机")}).catch(G=>{R({ok:!1,state:"http",message:`Key 保存失败:${lt(G)}`})}).finally(()=>N(!1));return}t.settingsTestConnection(d,{key:E,...P!==null?{model:P.defaultModel}:{}}).then(G=>{if(R(G),G.ok)return t.settingsSaveKey(d,E).then(()=>{f(!0),g(""),O("Key 已保存到凭据文件(权限 0600)—— 仅保存在本机")}).catch(ee=>O(`⚠️ Key 保存失败:${lt(ee)}`))}).catch(G=>R({ok:!1,state:"http",message:`测试失败:${lt(G)}`})).finally(()=>N(!1))}},w=()=>{if(d===null)return;const E=A??P?.defaultModel??"";t.settingsSet("permissions.defaultMode",y).then(()=>O(`新会话默认权限档 → ${y==="workspace"?"accept(默认档)":y}(已持久化)`)).catch(G=>b(`默认权限档写入失败:${lt(G)}`)),t.setMode(y).then(()=>O(`本会话权限档 → ${y==="workspace"?"accept(默认档)":y}`)).catch(G=>b(`权限档设置失败:${lt(G)}`)),t.settingsSet("ui.defaultMode","simple").then(()=>O("默认界面 → 简洁模式 —— 下次打开生效")).catch(G=>b(`默认界面写入失败:${lt(G)}`)),t.settingsSet("wizard.completedVersion",Fn).catch(G=>b(`向导标记写入失败:${lt(G)}`)),t.submit(`/provider ${d}`).then(()=>O(`供应商 → ${d} — 本会话即刻生效(历史将在新端点重算,缓存全冷)`)).catch(G=>b(`provider 切换失败:${lt(G)} —— 请重新选择供应商后重试(保存的 Key 已生效)`)),E!==""&&t.submit(`/model ${E}`).then(()=>O(`模型 → ${E} — 下一轮生效`)).catch(G=>O(`⚠️ model 切换失败:${lt(G)}`)),c(6)};return e.jsxs("div",{className:"wizard-overlay",role:"dialog","aria-label":"新手向导",ref:F,tabIndex:-1,onCompositionStart:()=>{M.current=He(M.current)},onCompositionEnd:()=>{M.current=_e(M.current,Date.now())},onKeyDown:E=>{Ue(E.nativeEvent,M.current,Date.now())||E.key==="Escape"&&(E.preventDefault(),o===6?a():z(!0))},children:[e.jsxs("div",{className:"wiz pop-in",children:[e.jsx("div",{className:"wiz-bar","aria-hidden":!0,style:{width:K}}),e.jsxs("div",{className:"wiz-head",children:[e.jsx("span",{className:"wiz-step",children:le}),e.jsx("span",{className:"wiz-title",children:de})]}),o===1?e.jsxs("div",{className:"wiz-body","data-step":"welcome",children:[e.jsx("h2",{children:"wudao · 你的 AI 编程助手"}),e.jsx("p",{className:"wizard-sub",children:"三次点击完成配置,马上开始。"}),e.jsx("ul",{className:"wizard-points",children:rp.map(E=>e.jsx("li",{children:E},E))})]}):null,o===2?e.jsxs("div",{className:"wiz-body","data-step":"provider",children:[e.jsx("h3",{children:"选择模型供应商"}),e.jsx("p",{className:"wizard-sub",children:"选一个你有 API Key 的供应商 —— 之后随时可以换或再加。"}),e.jsxs("div",{className:"wizard-cards",children:[n.providers.length===0?e.jsx("div",{className:"wizard-empty",role:"status",children:"暂无可用供应商 —— 可先跳过,稍后在设置的「供应商」中添加"}):null,n.providers.map(E=>e.jsxs("button",{type:"button",className:`wizard-provider-card${d===E.provider?" sel":""}`,"data-status":E.status,"data-selected":d===E.provider,onClick:()=>m(E.provider),children:[e.jsx("span",{className:`dot ${E.status}`,title:ar[E.status]}),e.jsx("span",{className:"card-name",children:E.provider==="wudao"?"兼容端点(wudao)":E.label}),E.status==="missing-endpoint"?e.jsx("span",{className:"wizard-badge",title:"该供应商需要先设置 WUDAO_BASE_URL 端点;向导中粘贴的 Key 将不经连接测试直接保存",children:"需 BASE_URL"}):null,e.jsx("span",{className:"meta",children:ar[E.status]}),e.jsx("span",{className:"meta",children:`推荐模型 ${E.defaultModel}`})]},E.provider))]})]}):null,o===3?e.jsxs("div",{className:"wiz-body","data-step":"key",children:[e.jsx("h3",{children:`粘贴 ${P?.label??d} 的 API Key`}),e.jsx("p",{className:"wizard-sub",children:"Key 只写入本机凭据文件(~/.wudao/.credentials.yaml,权限 0600),不会出现在任何配置或界面上。"}),U?e.jsx("div",{className:"hint","data-endpoint-warning":"",children:"未配置 BASE_URL,连接测试跳过 —— 可稍后在设置中配置"}):null,e.jsxs("div",{className:"keyrow",children:[e.jsx("input",{type:"password",className:"wudao-input key-input",placeholder:"粘贴 API Key","aria-label":"API Key",value:p,disabled:j,onChange:E=>{g(E.target.value),f(!1),R(null)}}),e.jsx("button",{type:"button",className:"wudao",disabled:p.trim()===""||v||j,onClick:k,children:v?U?"保存中…":"测试中…":U?"保存 Key":"测试连接"})]}),S!==null?e.jsx("div",{className:`test-result ${S.ok?"ok":`fail ${S.state}`}`,"data-state":S.state,children:S.message}):null,j?e.jsxs("div",{className:"hint",children:[U?"Key 已保存(未配置 BASE_URL,连接测试已跳过)—— 可以继续。":"测试通过,Key 已保存 —— 可以继续。",e.jsx("button",{type:"button",className:"wizard-skip",onClick:()=>{f(!1),R(null)},children:"重新粘贴另一个 Key"})]}):null]}):null,o===4?e.jsxs("div",{className:"wiz-body","data-step":"model",children:[e.jsx("h3",{children:"选择模型"}),e.jsx("p",{className:"wizard-sub",children:`推荐使用 ${P?.defaultModel??""}(该供应商默认);有其他需要也可以换。`}),e.jsxs("div",{className:"card-models",children:[T.length===0?e.jsx("div",{className:"wizard-empty",role:"status",children:"该供应商暂无可用模型 —— 可返回上一步重选,或稍后在设置的「供应商」中刷新模型列表"}):null,T.map(E=>e.jsxs("button",{type:"button",className:`model-chip${A===E?" primary":""}`,onClick:()=>$(E),children:[E,E===P?.defaultModel?"(推荐)":""]},E))]})]}):null,o===5?e.jsxs("div",{className:"wiz-body","data-step":"permission",children:[e.jsx("h3",{children:"权限默认:accept"}),e.jsx("p",{className:"wizard-sub",children:"accept(接受编辑):工作区内自由读写,只读命令(git status 等)放行,其他操作会询问 —— 你可以改为 ask(每次询问)、auto(全自动)或 plan(只读探查);这里是新会话的起步档,本会话也即刻生效,之后能随时在设置里调整。"}),e.jsx(ia,{value:y,onChange:q,direction:"down"})]}):null,o===6?e.jsxs("div",{className:"wiz-body","data-step":"done",children:[e.jsxs("h3",{children:["完成 ",e.jsx(ae,{name:"party-popper",size:15})]}),e.jsx("p",{className:"wizard-sub",children:`已配置 ${P?.label??d}/${A??""} —— 从一句话开始试试:描述你想构建什么。`}),D.length>0?e.jsx("div",{className:"settings-receipts",children:D.map((E,G)=>{const ee=At(E);return e.jsxs("div",{"data-variant":ee.variant,children:[ee.variant==="warn"?e.jsx(ae,{name:"triangle-alert",size:12}):ee.variant==="ok"?e.jsx(ut,{size:12,className:"ic"}):null,e.jsx("span",{children:ee.text})]},`${G}-${E.slice(0,12)}`)})}):null,H.length>0?e.jsxs("div",{className:"entry-error",children:[H.slice(-3).map((E,G)=>e.jsx("div",{children:E},`${G}-${E.slice(0,12)}`)),H.length>3?e.jsx("div",{children:`+${H.length-3} more`}):null]}):null]}):null,e.jsxs("div",{className:"wizard-actions",children:[o>1&&o<6?e.jsx("button",{type:"button",className:"wizard-skip",onClick:x,children:"跳过,先逛逛"}):e.jsx("span",{}),e.jsxs("span",{className:"wizard-nav",children:[o>=3&&o<=5?e.jsx("button",{type:"button",className:"wudao",onClick:()=>c(o-1),children:"上一步"}):null,o===1?e.jsx("button",{type:"button",className:"wudao primary",onClick:()=>c(2),children:"开始配置"}):null,o===2?e.jsx("button",{type:"button",className:"wudao primary",disabled:d===null,onClick:()=>{g(""),R(null),f(!1),c(3)},children:"下一步"}):null,o===3?e.jsx("button",{type:"button",className:"wudao primary",disabled:!j,onClick:()=>{$(P?.defaultModel??null),c(4)},children:"下一步"}):null,o===4?e.jsx("button",{type:"button",className:"wudao primary",onClick:()=>c(5),children:"下一步"}):null,o===5?e.jsx("button",{type:"button",className:"wudao primary",onClick:w,children:"完成"}):null,o===6?e.jsx("button",{type:"button",className:"wudao primary",onClick:a,children:"开始使用"}):null]})]})]}),W?e.jsx("div",{className:"scrim wizard-confirm",onClick:E=>{E.target===E.currentTarget&&z(!1)},children:e.jsxs("div",{className:"modal-card pop-in",role:"dialog","aria-label":"退出向导",tabIndex:-1,onKeyDown:E=>{E.key==="Escape"&&(E.preventDefault(),E.stopPropagation(),z(!1))},children:[e.jsx("h3",{children:"退出配置向导?"}),e.jsx("div",{className:"muted",children:"将标记为已跳过(只读浏览模式),之后可从顶部横幅的「去配置」重新进入。"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao danger",onClick:()=>{z(!1),x()},children:"跳过并退出"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>z(!1),children:"继续配置"})]})]})}):null]})}const Ze=12,Vn=4.5,lr=2*Math.PI*Vn;function op({ctx:t}){const[s,n]=i.useState(!1);if(i.useEffect(()=>{if(!s)return;const l=r=>{r.key==="Escape"&&n(!1)};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]),t===null)return null;const a=t.used===null?0:Math.max(0,Math.min(1,t.used/t.window));return e.jsxs("span",{className:"ctx",children:[e.jsxs("button",{type:"button",className:"ctx-btn","aria-label":"上下文用量","aria-expanded":s,title:"上下文用量(点击查看)",onClick:()=>n(!s),children:[e.jsxs("svg",{width:Ze,height:Ze,viewBox:`0 0 ${Ze} ${Ze}`,"aria-hidden":!0,children:[e.jsx("circle",{cx:Ze/2,cy:Ze/2,r:Vn,fill:"none",stroke:"var(--hair-2)",strokeWidth:"2"}),e.jsx("circle",{cx:Ze/2,cy:Ze/2,r:Vn,fill:"none",stroke:t.nearLimit?"var(--warn)":"var(--accent)",strokeWidth:"2",strokeDasharray:`${a*lr} ${lr}`,transform:`rotate(-90 ${Ze/2} ${Ze/2})`})]}),e.jsx("span",{className:"ctx-num","aria-hidden":!0,children:`▲${t.used===null?"…":Ae(t.used)}`})]}),s?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"ctxmeter-backdrop",onClick:()=>n(!1)}),e.jsxs("span",{className:"ctxmeter-legend",role:"note",children:[e.jsx("span",{className:"row",children:t.used===null?"已用 …(本轮未回报)":`已用 ${Ae(t.used)}`}),e.jsx("span",{className:"row",children:`窗口 ${Ae(t.window)}`}),e.jsx("span",{className:"row",children:t.used===null?"占比 …":`占比 ${Math.round(a*100)}%`}),t.nearLimit?e.jsxs("span",{className:"row warn",children:[e.jsx(ae,{name:"triangle-alert",size:11})," 接近上限——过长时历史会自动压缩"]}):null]})]}):null]})}function cp(t){const{busy:s,mode:n,commands:a,connected:l,ctx:r,lane:o,onLane:c,parked:d,onDropParked:m,onSubmit:p,onSideAsk:g,onInterrupt:v,onCycleMode:N,onShield:S,onDraftApplied:R,draft:j,onBufferChange:f,onImagesChange:A,imageSeed:$,onImageSeedApplied:y,onFilesChange:q,fileSeed:D,onFileSeedApplied:V,modelLabel:H,modelProvider:X,modelChoices:W,modelRecent:z,onPickModel:F,onPersistModelDefault:M,effort:P,efforts:T,onPickEffort:U,effortProviderLabel:Q,onPersistEffortDefault:se,controlsLead:de}=t;return e.jsx("div",{className:"simple-composer",children:e.jsx($i,{busy:s,mode:n,commands:a,connected:l,onSubmit:p,onSideAsk:g,onInterrupt:v,onShield:S,onCycleMode:N,idlePlaceholder:"用大白话描述你想构建什么",busyPlaceholder:o==="queue"?"排队发送 —— 当前任务结束后处理":"注入当前运行的任务……",controlsLead:de,controlsPrefix:e.jsxs(e.Fragment,{children:[s?e.jsxs("div",{className:"lane-toggle",role:"radiogroup","aria-label":"发送方式",children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":o==="queue",className:`chip${o==="queue"?" on":""}`,"data-lane":"queue",onClick:()=>c("queue"),title:"不打扰当前任务,等它结束后作为新任务发送 —— 当前任务结束后再处理你的消息",children:[e.jsx(ae,{name:"hourglass",size:13})," 排队"]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":o==="steer",className:`chip${o==="steer"?" on":""}`,"data-lane":"steer",onClick:()=>c("steer"),title:"在下一次思考前插入,立即影响当前任务 —— 消息会在下一步前插入当前任务",children:[e.jsx(ae,{name:"zap",size:13})," 注入当前轮"]})]}):null,d.length>0?e.jsx("div",{className:"parked-row",children:d.map((le,K)=>e.jsxs("span",{className:"parked-chip",children:[e.jsx(ae,{name:"hourglass",size:12}),`${le.slice(0,24)}${le.length>24?"…":""}`,e.jsx("button",{type:"button",className:"drop","aria-label":"放弃这条排队消息",onClick:()=>m(K),children:"×"})]},K))}):null]}),controlsSuffix:e.jsx(op,{ctx:r}),onDraftApplied:R,onBufferChange:f,onImagesChange:A,onImageSeedApplied:y,onFilesChange:q,onFileSeedApplied:V,modelLabel:H,modelProvider:X,modelChoices:W,modelRecent:z,onPickModel:F,onPersistModelDefault:M,effort:P,efforts:T,onPickEffort:U,...Q!==void 0?{effortProviderLabel:Q}:{},...se!==void 0?{onPersistEffortDefault:se}:{},...$!==void 0?{imageSeed:$}:{},...D!==void 0?{fileSeed:D}:{},...j!==void 0?{draft:j}:{}})})}function Fi({awaiting:t,onOpenSession:s,onResumeLatest:n,onAskFromHistory:a}={}){const l=t!==void 0&&s!==void 0&&t.length>0?t:null;return e.jsxs("div",{className:"hero",children:[e.jsx("h1",{children:"你好呀,我是悟道Harness"}),e.jsx("p",{children:"你的桌面 AI 搭子——读文件、写代码、改 bug、查资料,都能直接在你电脑上替你干完;聊出来的东西也能顺手做成文档和表格。"}),e.jsx("p",{className:"hero-hint",children:"想到什么,直接打字吩咐我就行。"}),n!==void 0||a!==void 0?e.jsxs("div",{className:"hero-actions",children:[n!==void 0?e.jsx("button",{type:"button",className:"hero-act",onClick:n,children:"继续上次会话"}):null,a!==void 0?e.jsx("button",{type:"button",className:"hero-act",onClick:a,children:"从历史会话提问"}):null]}):null,l!==null?e.jsxs("p",{className:"hero-await",role:"status",children:["有 ",l.length," 个会话在等你授权:",l.map((r,o)=>e.jsxs(i.Fragment,{children:[o>0?"、":"",e.jsx("button",{type:"button",className:"hero-await-name",title:`回到「${r.title}」`,onClick:()=>s?.(r.id),children:r.title})]},r.id))]}):null]})}function zi(t,s){const[n,a]=i.useState(null),l=i.useRef(t);return l.current=t,i.useEffect(()=>{if(!s)return;const r=l.current.recentWorkspaces;if(r===void 0)return;let o=!1;return r.call(l.current).then(c=>{o||a((c.workspaces??[]).slice(0,5))},()=>{o||a(c=>c??[])}),()=>{o=!0}},[s]),n}function Bi({client:t,root:s,connected:n,bootRoot:a,onPick:l,onOpenOther:r,labelName:o,labelPath:c}){const[d,m]=i.useState(!1),p=zi(t,d);return e.jsxs("div",{className:"ws-chip-wrap",children:[e.jsxs("button",{type:"button",className:"chip work",title:c??s,"aria-haspopup":"menu","aria-expanded":d,disabled:!n,onClick:()=>m(g=>!g),children:[e.jsx(ts,{size:14})," ",o??Qt(s)," ",e.jsx(et,{size:12})]}),d?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ws-backdrop",onClick:()=>m(!1)}),e.jsxs("div",{className:"ws-menu",role:"menu",children:[a!==void 0&&a!==""?e.jsxs("button",{type:"button",className:"ws-item ws-default",role:"menuitem",title:a,onClick:()=>{m(!1),l(a)},children:["默认空间 · ",Qt(a)]}):null,(p??[]).map(g=>e.jsx("button",{type:"button",className:"ws-item",role:"menuitem",title:g.path,onClick:()=>{m(!1),l(g.path)},children:Qt(g.path)},g.path)),p===null?e.jsx("div",{className:"ws-loading",children:"加载中…"}):null,e.jsx("button",{type:"button",className:"ws-item ws-open-other",role:"menuitem",onClick:()=>{m(!1),r()},children:"打开其他目录…"})]})]}):null]})}function Ki(t){return!t.some(s=>s.kind==="user"||s.kind==="assistant"||s.kind==="tool"||s.kind==="edit"||s.kind==="error")}function dp(t){const{status:s,history:n,connected:a,commands:l,onSubmit:r,onInterrupt:o,onCycleMode:c,onAnswerPermission:d,onRecallSteer:m,onDetachTool:p,pendingAsk:g,onAnswerAskUser:v,onShield:N,notify:S,parked:R,onPark:j,onDropParked:f,onDraftApplied:A,draft:$,onBufferChange:y,onImagesChange:q,imageSeed:D,onImageSeedApplied:V,onFilesChange:H,fileSeed:X,onFileSeedApplied:W,modelLabel:z,modelProvider:F,modelChoices:M,modelRecent:P,onPickModel:T,onPersistModelDefault:U,effort:Q,efforts:se,onPickEffort:de,effortProviderLabel:le,onPersistEffortDefault:K,workspaceRoot:O,bootRoot:x,onSwitchWorkspace:b,onOpenOtherWorkspace:k,rootCard:w,onAgentRootSwitch:E,onAgentRootKeep:G,fileOpsClient:ee,onSideAsk:me,sideQas:ye,onPromoteSideQa:Ne}=t,he=s?.busy??!1,Ee=s?.pendingPermission??null,ve=i.useRef(null),[Re,qe]=i.useState("queue"),Fe=i.useCallback((J,ie,ge)=>{if(he&&Re==="queue"){if(ie!==void 0&&ie.length>0)return S("⚠️ 排队消息暂不支持图片 —— 请等当前任务结束后再发"),!1;if(ge!==void 0&&ge.length>0)return S("⚠️ 排队消息暂不支持文件 —— 请等当前任务结束后再发"),!1;j(J);return}return r(J,ie,ge)},[he,Re,S,j,r]),[Ie,pe]=i.useState(!1),ze=i.useRef(!1),Me=i.useRef(!1),Le=i.useCallback(J=>{ze.current||(ze.current=!0,pe(!0),d(J).then(ie=>{ie&&(Me.current=!0)}).catch(ie=>{S(`⚠️ 回答未送达(${ie instanceof Error?ie.message:String(ie)})——请再选一次`)}).finally(()=>{ze.current=!1,pe(!1)}))},[S,d]),Ge=i.useRef(null);i.useEffect(()=>{const J=Ge.current;J!==null&&Ee===null&&!Me.current&&S("⚠️ 权限请求已结束(未被允许)——如需继续,请重新描述要做的事"),Ee!==null&&J===null&&(Me.current=!1),Ge.current=Ee},[Ee,S]);const{onScroll:$e,jump:_,show:Y}=Mr(ve);return e.jsxs("div",{className:"simple","data-mode":"simple",children:[e.jsxs("div",{className:"chat",ref:ve,onScroll:$e,children:[Ki(n)?e.jsx(Fi,{}):null,e.jsx(hp,{history:n,onSubmit:r,busyTools:s?.live.busyTools??[]}),s?.planBoard!=null?e.jsx(Oi,{plan:s.planBoard,busy:he,onSubmit:r}):null,s!==null&&he&&Ee===null?e.jsxs("div",{className:"turnlive",children:[e.jsx(Yh,{busy:he,live:s.live,queued:s.queued,onRecall:m}),s.live.reasoning!==""?e.jsx(aa,{text:s.live.reasoning,streaming:s.live.thinking??!1,defaultOpen:!0}):null,s.live.answer!==""?e.jsx(li,{text:s.live.answer}):null,s.live.busyTools.filter(J=>!up(J,n)).map((J,ie)=>e.jsx(ai,{tool:J,onDetach:p},`${J.name}:${J.summary}:${ie}`))]}):null,Ee===null&&g!=null&&v!==void 0?e.jsx(Di,{inline:!0,question:g.question,options:g.options,onAnswer:J=>{v(J).catch(()=>{})},onDismiss:()=>{v().catch(()=>{})}}):null]}),e.jsx(Tr,{show:Y,onJump:_}),w!==null?e.jsx(Ai,{panelRoot:w.panelRoot,agentRoot:w.agentRoot,queued:w.queued,onSwitch:E,onKeep:G}):null,(ye?.length??0)>0&&Ne!==void 0?e.jsx(Ri,{qas:ye??[],onPromote:Ne}):null,Ee===null?e.jsx(cp,{busy:he,mode:s?.mode??"workspace",commands:l,connected:a,ctx:s?.ctxTokens??null,lane:Re,onLane:qe,parked:R,onDropParked:f,onSubmit:Fe,onSideAsk:me,onInterrupt:o,onCycleMode:c,onShield:N,onDraftApplied:A,onBufferChange:y,onImagesChange:q,onImageSeedApplied:V,onFilesChange:H,onFileSeedApplied:W,modelLabel:z,modelProvider:F,modelChoices:M,modelRecent:P,onPickModel:T,onPersistModelDefault:U,effort:Q,efforts:se,onPickEffort:de,...le!==void 0?{effortProviderLabel:le}:{},...K!==void 0?{onPersistEffortDefault:K}:{},controlsLead:e.jsx(Bi,{client:ee,root:O,bootRoot:x,connected:a,onPick:b,onOpenOther:k,labelName:w!==null&&w.agentRoot!==""?xt(w.agentRoot):void 0,labelPath:w!==null&&w.agentRoot!==""?w.agentRoot:void 0}),...D!==void 0?{imageSeed:D}:{},...X!==void 0?{fileSeed:X}:{},...$!==void 0?{draft:$}:{}}):e.jsxs(e.Fragment,{children:[e.jsx(Nm,{ask:Ee,busy:Ie,onChoose:J=>Le(J.allow)}),e.jsx("div",{className:"approval-note",children:"权限卡临时接管输入位置 · 处理后自动恢复"})]})]})}function up(t,s){return t.name==="edit"?!0:t.name==="write_file"?s.some(n=>n.kind==="edit"&&n.path===t.summary):!1}function hp({history:t,onSubmit:s,busyTools:n=[]}){const a=bi(t.length),l=a.hidden;return e.jsxs(e.Fragment,{children:[l>0?e.jsx("div",{ref:a.sentinelRef,className:"history-hydrate-sentinel",onClick:a.hydrate,role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&a.hydrate()},children:yi(l)}):null,t.slice(l).map((r,o)=>{const c=l+o;return e.jsxs(i.Fragment,{children:[o>0?e.jsx("div",{className:"entry-gap"}):null,e.jsx("div",{className:"entry",children:r.kind==="tool"||r.kind==="edit"?e.jsxs(e.Fragment,{children:[e.jsx(si,{entry:r,running:r.kind==="edit"?Gu(r,n):!1}),r.kind==="tool"&&r.isError===!0&&ra(r.resultPreview??"")!==null?e.jsx(xi,{text:r.resultPreview??"",onRetry:s}):null]}):r.kind==="error"?e.jsx(bh,{text:r.text,onAction:s}):e.jsx(Xs,{entry:r})})]},Tt(r,c))})]})}const mp=["model","tool","agent","ui","system"],Ye=t=>typeof t=="number"&&Number.isFinite(t)?t:0,Xt=t=>t>=1e3?`${(t/1e3).toFixed(1)}s`:`${Math.round(t)}ms`,rt=t=>t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t);function pp(t,s){const n={};let a=0,l=0,r=0,o=0,c=0,d=0;const m=new Map;let p=0,g=0,v=0,N=0,S=0,R=0;const j=1e3,f=60,A=new Array(f).fill(0);for(const $ of t){n[$.cat]=(n[$.cat]??0)+1;const y=Math.floor((s-$.ts)/j);if(y>=0&&y<f&&(A[f-1-y]=(A[f-1-y]??0)+1),$.cat==="model"&&$.name==="model.call")a+=1,l+=Ye($.dur),r+=Ye($.data?.tokensIn),o+=Ye($.data?.tokensOut),c+=Ye($.data?.cacheHitTokens),$.data?.ok===!1&&(d+=1);else if($.cat==="tool"&&$.name==="tool.finish"){const q=String($.data?.name??"?"),D=m.get(q)??{count:0,dur:0,errs:0,bytes:0};D.count+=1,D.dur+=Ye($.dur),D.bytes=Math.max(D.bytes,Ye($.data?.resultBytes??0)),$.data?.ok===!1&&(D.errs+=1),m.set(q,D)}else $.cat==="agent"&&$.name==="agent.turn"?(p+=1,g+=Ye($.dur),v+=Ye($.data?.toolCalls),N+=Ye($.data?.reasoningChars),S+=Ye($.data?.answerChars)):$.cat==="agent"&&$.name==="agent.retry"&&(R+=1)}return{byCat:n,model:{count:a,avgDur:a===0?0:l/a,tokensIn:r,tokensOut:o,cacheHit:c,errs:d},tools:[...m.entries()].map(([$,y])=>({name:$,count:y.count,avgDur:y.dur/y.count,errs:y.errs,bytes:y.bytes})).sort(($,y)=>y.count-$.count).slice(0,12),turns:{count:p,avgDur:p===0?0:g/p,toolCalls:v,reasoningChars:N,answerChars:S,retries:R},buckets:A}}function fp(t){const s=Math.max(1,...t);return t.map((n,a)=>`${(a/(t.length-1)*100).toFixed(2)},${(40-n/s*38).toFixed(2)}`).join(" ")}function xp({client:t,status:s,connected:n,onClose:a}){const l=ce.useRef([]),[r,o]=ce.useState(0),[c,d]=ce.useState("*"),[m,p]=ce.useState(!1),[g,v]=ce.useState("unknown"),[N,S]=ce.useState(null),R=ce.useRef([]),[j,f]=ce.useState("events"),A=ce.useRef(!1);A.current=m,ce.useEffect(()=>{if(!n)return;let D=!0;t.probeRecent(void 0,200).then(W=>{!D||!Array.isArray(W)||(l.current=[...W.slice(-500).map(z=>z),...l.current].slice(-500),o(z=>z+1))}).catch(()=>{}),t.probeStats().then(W=>{if(!D)return;const z=Object.values(W??{}).reduce((F,M)=>F+(typeof M=="object"&&M!==null&&"count"in M?Ye(M.count):0),0);v(z===0&&l.current.length===0?"off":"on")}).catch(()=>{}),t.probeStream().catch(()=>{});const V=t.onProbe(W=>{A.current||(l.current.push(W),l.current.length>500&&l.current.splice(0,l.current.length-500))});t.sessionAnatomy().then(W=>{D&&S({systemPrompt:W.systemPrompt,messages:W.messages??[]})}).catch(()=>{});const H=t.onLoopEvent((W,z)=>{if(A.current)return;const F=W,M=R.current;if(F.type==="reasoning_delta"||F.type==="assistant_delta"){const P=M[M.length-1];P!==void 0&&P.kind==="turn"&&P.turn===(F.turn??0)?F.type==="reasoning_delta"?P.reasoning+=F.text??"":P.answer+=F.text??"":M.push({kind:"turn",at:z,turn:F.turn??0,reasoning:F.type==="reasoning_delta"?F.text??"":"",answer:F.type==="assistant_delta"?F.text??"":""})}else if(F.type==="tool_call_started")M.push({kind:"tool",at:z,id:F.toolCallId??"?",name:F.toolName??"?",input:Yn(F.input)});else if(F.type==="tool_call_finished"){const P=[...M].reverse().find(T=>T.kind==="tool"&&T.id===F.toolCallId);P!==void 0&&P.kind==="tool"&&(P.output=typeof F.result=="string"?F.result:Yn(F.result),P.isError=F.isError===!0,P.durMs=F.durationMs)}M.length>300&&M.splice(0,M.length-300)}),X=setInterval(()=>o(W=>W+1),250);return()=>{D=!1,V(),H(),clearInterval(X),t.probeStream("off").catch(()=>{})}},[t,n]);const $=ce.useMemo(()=>pp(l.current,Date.now()),[r]),y=ce.useMemo(()=>l.current.filter(D=>c==="*"||D.cat===c).slice(-60).reverse(),[r,c]),q=()=>{t.probeEnable(!0).then(()=>{v("on"),l.current=[],o(D=>D+1)}).catch(()=>{})};return e.jsxs("div",{className:"dash","data-testid":"dash",children:[e.jsxs("div",{className:"dash-head",children:[e.jsx("h2",{children:"监控"}),e.jsxs("span",{className:"k",style:{color:"var(--text-2)"},children:[s?.model?.label??"-"," · ",s?.busy?"运行中":"空闲",s?.cachePercent!=null?` · 缓存 ${s.cachePercent}%`:"",s?.ctxTokens!=null&&s.ctxTokens.used!=null?` · ctx ${rt(s.ctxTokens.used)}/${rt(s.ctxTokens.window)}`:""]}),e.jsx("span",{className:"spacer"}),e.jsxs("div",{className:"dash-cat-chips",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":j==="events",className:j==="events"?"on":void 0,onClick:()=>f("events"),children:"探针"}),e.jsx("button",{type:"button",role:"tab","aria-selected":j==="anatomy",className:j==="anatomy"?"on":void 0,onClick:()=>f("anatomy"),children:"会话解剖"})]}),e.jsx("button",{type:"button",className:"icobtn","aria-label":"返回会话",title:"返回会话",onClick:a,children:e.jsx(es,{})})]}),j==="events"&&g==="off"?e.jsxs("div",{className:"dash-banner",role:"status",children:["探针总闸未开启(WUDAO_PROBE)——开启后 agent/工具事件下一轮起可见;model.call 计量需带 WUDAO_PROBE=on 重启生效。",e.jsx("button",{type:"button",onClick:q,children:"现在开启"})]}):null,j==="events"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dash-kpis",children:[e.jsxs("div",{className:"dash-kpi",children:[e.jsx("span",{className:"k",children:"模型调用"}),e.jsx("span",{className:"v",children:$.model.count}),e.jsxs("span",{className:"s",children:["均 ",Xt($.model.avgDur),$.model.errs>0?` · 败 ${$.model.errs}`:""]})]}),e.jsxs("div",{className:"dash-kpi",children:[e.jsx("span",{className:"k",children:"Token 流量"}),e.jsx("span",{className:"v",children:rt($.model.tokensIn+$.model.tokensOut)}),e.jsxs("span",{className:"s",children:["入 ",rt($.model.tokensIn)," · 出 ",rt($.model.tokensOut)," · 缓存命中 ",rt($.model.cacheHit)]})]}),e.jsxs("div",{className:"dash-kpi",children:[e.jsx("span",{className:"k",children:"工具调用"}),e.jsx("span",{className:"v",children:($.byCat.tool??0)/2>=0?Math.round(($.byCat.tool??0)/2):0}),e.jsxs("span",{className:"s",children:["完成 ",($.byCat.tool??0)%2===0?($.byCat.tool??0)/2:Math.floor(($.byCat.tool??0)/2),"(start+finish 合计 ",$.byCat.tool??0," 帧)"]})]}),e.jsxs("div",{className:"dash-kpi",children:[e.jsx("span",{className:"k",children:"回合"}),e.jsx("span",{className:"v",children:$.turns.count}),e.jsxs("span",{className:"s",children:["均 ",Xt($.turns.avgDur)," · 工具 ",$.turns.toolCalls," · 重试 ",$.turns.retries]})]}),e.jsxs("div",{className:"dash-kpi",children:[e.jsx("span",{className:"k",children:"思考/正文"}),e.jsxs("span",{className:"v",children:[rt($.turns.reasoningChars),"/",rt($.turns.answerChars)]}),e.jsx("span",{className:"s",children:"累计字符"})]})]}),e.jsxs("div",{className:"dash-chart",children:[e.jsx("span",{className:"k",children:"事件速率 · 近 60s(每秒一格)"}),e.jsx("svg",{viewBox:"0 0 100 40",preserveAspectRatio:"none","aria-hidden":"true",children:e.jsx("polyline",{fill:"none",stroke:"currentColor",strokeWidth:"1",points:fp($.buckets)})})]}),e.jsxs("div",{className:"dash-cols",children:[e.jsxs("div",{className:"dash-panel",children:[e.jsx("div",{className:"dash-panel-head",children:"工具聚合(按完成次数)"}),e.jsx("div",{className:"dash-scroll",children:$.tools.length===0?e.jsx("div",{className:"dash-empty",children:"暂无工具事件"}):e.jsxs("table",{className:"dash-tools",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"工具"}),e.jsx("th",{children:"次数"}),e.jsx("th",{children:"均耗时"}),e.jsx("th",{children:"错误"}),e.jsx("th",{children:"结果B"})]})}),e.jsx("tbody",{children:$.tools.map(D=>e.jsxs("tr",{children:[e.jsx("td",{children:D.name}),e.jsx("td",{children:D.count}),e.jsx("td",{children:Xt(D.avgDur)}),e.jsx("td",{children:D.errs>0?D.errs:""}),e.jsx("td",{children:D.bytes>0?rt(D.bytes):""})]},D.name))})]})})]}),e.jsxs("div",{className:"dash-panel",children:[e.jsxs("div",{className:"dash-panel-head",children:["实时事件",e.jsx("span",{className:"spacer"}),e.jsx("div",{className:"dash-cat-chips",children:["*",...mp].map(D=>e.jsx("button",{type:"button",className:c===D?"on":void 0,onClick:()=>d(D),children:D==="*"?"全部":D},D))}),e.jsx("button",{type:"button",className:"icobtn","aria-label":m?"继续":"暂停",title:m?"继续":"暂停",onClick:()=>p(D=>!D),children:m?"继续":"暂停"})]}),e.jsx("div",{className:"dash-scroll dash-stream",children:y.length===0?e.jsx("div",{className:"dash-empty",children:"等待事件…(发一条消息试试)"}):y.map((D,V)=>e.jsxs("div",{className:`dash-row cat-${D.cat}`,children:[e.jsx("span",{className:"t",children:new Date(D.ts).toLocaleTimeString("zh-CN",{hour12:!1})}),e.jsx("span",{className:`c cat-${D.cat}`,children:D.cat}),e.jsx("span",{className:"n",children:D.name}),e.jsxs("span",{className:"d",children:[D.dur!==void 0?`${Xt(D.dur)} `:"",D.data!==void 0?gp(D):""]})]},`${D.ts}:${D.name}:${V}`))})]})]})]}):null,j==="anatomy"?e.jsxs("div",{className:"dash-cols dash-anatomy",children:[e.jsxs("div",{className:"dash-panel",children:[e.jsxs("div",{className:"dash-panel-head",children:["持久上下文(",N?.messages.length??0," 条)",e.jsx("span",{className:"spacer"}),e.jsx("button",{type:"button",className:"icobtn","aria-label":"刷新",title:"刷新",onClick:()=>{t.sessionAnatomy().then(D=>S({systemPrompt:D.systemPrompt,messages:D.messages??[]})).catch(()=>{})},children:e.jsx(br,{})})]}),e.jsxs("div",{className:"dash-scroll",children:[e.jsxs("details",{className:"dash-prompt",children:[e.jsxs("summary",{children:["系统提示词 · ",N?.systemPrompt.length??0," 字"]}),e.jsx("pre",{children:N?.systemPrompt??"(暂无——老 server 或无缝)"})]}),N===null?e.jsx("div",{className:"dash-empty",children:"读取中…"}):N.messages.length===0?e.jsx("div",{className:"dash-empty",children:"(空会话)"}):N.messages.map((D,V)=>e.jsx(vp,{row:D},V))]})]}),e.jsxs("div",{className:"dash-panel",children:[e.jsx("div",{className:"dash-panel-head",children:"实时时间线(思考 / 工具入参·出参·异常)"}),e.jsx("div",{className:"dash-scroll dash-stream",children:R.current.length===0?e.jsx("div",{className:"dash-empty",children:"等待事件…(发一条消息,思考与工具调用会实时出现在这里)"}):[...R.current].reverse().map((D,V)=>D.kind==="turn"?e.jsxs("div",{className:"dash-row",children:[e.jsx("span",{className:"t",children:new Date(D.at).toLocaleTimeString("zh-CN",{hour12:!1})}),e.jsxs("span",{className:"c",children:["turn",D.turn]}),D.reasoning!==""?e.jsxs("details",{className:"dash-detail",children:[e.jsxs("summary",{children:["思考 · ",D.reasoning.length," 字"]}),e.jsx("pre",{children:D.reasoning})]}):null,D.answer!==""?e.jsxs("details",{className:"dash-detail",open:!0,children:[e.jsxs("summary",{children:["正文 · ",D.answer.length," 字"]}),e.jsx("pre",{children:D.answer})]}):null]},`t${V}`):e.jsxs("div",{className:"dash-row",children:[e.jsx("span",{className:"t",children:new Date(D.at).toLocaleTimeString("zh-CN",{hour12:!1})}),e.jsx("span",{className:"c",style:D.isError===!0?{color:"var(--danger)"}:void 0,children:D.isError===!0?"异常":"工具"}),e.jsxs("details",{className:"dash-detail",children:[e.jsxs("summary",{children:[D.name,D.durMs!==void 0?` · ${Xt(D.durMs)}`:"",D.isError===!0?" · 异常":""]}),D.input!==void 0?e.jsx("pre",{children:`入参
323
+ ${D.input}`}):null,D.output!==void 0?e.jsx("pre",{children:`出参
324
+ ${D.output}`}):null]})]},`t${V}`))})]})]}):null]})}function vp({row:t}){const s=t.role??"?";return e.jsxs("div",{className:`dash-msg role-${s}`,children:[e.jsxs("div",{className:"dash-msg-head",children:[e.jsx("span",{className:"role",children:s==="tool"?`tool·${t.name??t.toolCallId??"?"}`:s}),t.isError===!0?e.jsx("span",{className:"err",children:"异常"}):null]}),typeof t.reasoning=="string"&&t.reasoning!==""?e.jsxs("details",{className:"dash-detail",children:[e.jsxs("summary",{children:["思考 · ",t.reasoning.length," 字"]}),e.jsx("pre",{children:t.reasoning})]}):null,t.toolCalls!==void 0&&t.toolCalls.length>0?e.jsxs("details",{className:"dash-detail",open:!0,children:[e.jsxs("summary",{children:["工具调用 · ",t.toolCalls.length," 个"]}),t.toolCalls.map((n,a)=>e.jsx("pre",{children:`${n.name??"?"}(${Yn(n.arguments)})`},a))]}):null,typeof t.content=="string"&&t.content!==""?e.jsxs("details",{className:"dash-detail",open:s==="user",children:[e.jsxs("summary",{children:[s==="user"?"用户提示词":"内容"," · ",t.content.length," 字"]}),e.jsx("pre",{children:t.content})]}):null]})}const Yn=t=>{try{return JSON.stringify(t)??""}catch{return String(t)}};function gp(t){const s=t.data??{},n=[];typeof s.model=="string"&&n.push(s.model),typeof s.name=="string"&&n.push(s.name),typeof s.toolCalls=="number"&&n.push(`工具×${s.toolCalls}`),typeof s.reasoningChars=="number"&&s.reasoningChars>0&&n.push(`思${s.reasoningChars}字`),typeof s.answerChars=="number"&&s.answerChars>0&&n.push(`文${s.answerChars}字`),typeof s.reason=="string"&&n.push(s.reason),s.ok===!1&&n.push("失败");const a=n.join(" ");return a.length>60?`${a.slice(0,60)}…`:a}function Xn(t){return[...t].sort((s,n)=>s.type!==n.type?s.type==="dir"?-1:1:s.name<n.name?-1:s.name>n.name?1:0)}const jp=new Set(["node_modules","__pycache__","dist","target"]);function bp(t){return t.hidden===!0||t.name.startsWith(".")||jp.has(t.name)}function Tn(t){const s=t.split("/").filter(n=>n!=="");return s[s.length-1]??t}const rr=t=>t instanceof Error?t.message:String(t);function Ts(t,s){return t===""?s:`${t}/${s}`}function yp(t,s){if(!t.startsWith("/"))return null;const n=s.replace(/^\/+/,"");return n===""?t:`${t}/${n}`}const ir=(t,s)=>{const n=yp(t,s);n!==null&&Zt("reveal_path",{path:n})};function or(){return e.jsxs("div",{className:"tree-loading",role:"status",children:[e.jsx("span",{className:"tree-spin","aria-hidden":!0}),"加载中…"]})}function cr({message:t,onRetry:s}){return e.jsx("div",{className:"tree-err",role:"button",tabIndex:0,title:t,onClick:s,onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),s())},children:"加载失败 · 点击重试"})}function Np({client:t,workspaceRoot:s,bootRoot:n,selectedPath:a,onSelect:l,onAtMention:r,refreshKey:o,onSwitchWorkspace:c,onOpenOtherWorkspace:d,onPathsChange:m,modifiedPaths:p,modifiedKey:g,onManualRefresh:v}){const[N,S]=i.useState(new Map),[R,j]=i.useState(new Set),[f,A]=i.useState(!1),[$,y]=i.useState(0),[q,D]=i.useState(""),[V,H]=i.useState(!1),X=zi(t,V),[W,z]=i.useState(null),F=i.useRef(t);F.current=t;const M=i.useRef(R);M.current=R;const P=O=>{F.current.fileTree(O).then(x=>S(b=>new Map(b).set(O,{entries:Xn(x.entries),error:null})),x=>S(b=>new Map(b).set(O,{entries:[],error:rr(x)})))},T=`${o}#${$}`;i.useEffect(()=>{let O=!1;S(new Map);const x=[...M.current];return Promise.all(["",...x].map(async b=>{try{const k=await F.current.fileTree(b);return[b,{entries:Xn(k.entries),error:null}]}catch(k){return[b,{entries:[],error:rr(k)}]}})).then(b=>{O||S(new Map(b))}),()=>{O=!0}},[T]);const U=O=>{const x=R.has(O);j(b=>{const k=new Set(b);return x?k.delete(O):k.add(O),k}),!x&&!N.has(O)&&P(O),l(O,!0)},Q=(O,x)=>x?[{label:"复制路径",onSelect:()=>Ks(O)},{label:"在 viewer 打开目录列表",onSelect:()=>l(O,!0)},{label:"在访达中显示",onSelect:()=>ir(s,O)}]:[{label:"复制路径",onSelect:()=>Ks(O)},{label:"@-mention 到输入",onSelect:()=>r(O)},{label:"在 viewer 打开",onSelect:()=>l(O,!1)},{label:"在访达中显示",onSelect:()=>ir(s,O)}],se=q.trim().toLowerCase(),de=(O,x)=>{if(O.name.toLowerCase().includes(se))return!0;if(O.type!=="dir")return!1;const b=N.get(x);return b!==void 0&&b.entries.some(k=>de(k,Ts(x,k.name)))};i.useEffect(()=>{if(m===void 0)return;const O=[],x=(k,w)=>{for(const E of w){const G=Ts(k,E.name);O.push(G);const ee=E.type==="dir"?N.get(G):void 0;ee!==void 0&&x(G,ee.entries)}},b=N.get("");b!==void 0&&b.error===null&&x("",b.entries),m(O)},[N,m]);const le=(O,x,b)=>O.filter(k=>f||!bp(k)).filter(k=>se===""||de(k,Ts(x,k.name))).map(k=>{const w=Ts(x,k.name),E=k.type==="dir",G=E&&R.has(w),ee=E&&G?N.get(w):void 0,me=!E&&(p?.has(w)??!1),ye=()=>{E?U(w):l(w,!1)};return e.jsxs("div",{className:`tree-node ${k.type}${me?" modified":""}`,"data-path":w,children:[e.jsxs("div",{className:`ft-row${a===w?" on":""}`,role:"button",tabIndex:0,onKeyDown:Ne=>{(Ne.key==="Enter"||Ne.key===" ")&&(Ne.preventDefault(),ye())},onClick:ye,onContextMenu:Ne=>{Ne.preventDefault(),z({x:Ne.clientX,y:Ne.clientY,path:w,isDir:E})},children:[Array.from({length:b},(Ne,he)=>e.jsx("span",{className:"ft-indent"},he)),e.jsx("span",{className:"caret",children:E?G?e.jsx(et,{size:12}):e.jsx(bt,{size:12}):null}),e.jsx("span",{className:"ico",children:E?G?e.jsx(Vo,{size:14}):e.jsx(ts,{size:14}):e.jsx(Zn,{size:14})}),e.jsx("span",{className:"name",children:k.name}),E?null:e.jsx("button",{type:"button",className:"at-btn",title:`@ ${w}`,onClick:Ne=>{Ne.stopPropagation(),r(w)},children:"@"})]}),E&&G?e.jsx("div",{className:"kids",children:ee===void 0?e.jsx(or,{}):ee.error!==null?e.jsx(cr,{message:ee.error,onRetry:()=>P(w)}):le(ee.entries,w,b+1)}):null]},k.name)}),K=N.get("");return e.jsxs("div",{className:"filetree",children:[e.jsxs("div",{className:"tree-top",children:[e.jsx("button",{type:"button",className:"ws-switcher",title:s,"aria-haspopup":"menu","aria-expanded":V,onClick:()=>H(O=>!O),children:e.jsxs("span",{className:"tree-root",children:[e.jsx(ts,{size:14})," ",Tn(s)," ",e.jsx(et,{size:12})]})}),e.jsx("button",{type:"button",className:"tree-toggle","aria-pressed":f,"aria-label":f?"隐藏隐藏项":"显示隐藏项",title:f?"隐藏隐藏项":"显示隐藏项",onClick:()=>A(O=>!O),children:e.jsx(Go,{size:14})}),e.jsx("button",{type:"button",className:"tree-refresh","aria-label":"刷新",title:"刷新",onClick:()=>{y(O=>O+1),v?.()},children:e.jsx(br,{size:14})}),V?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ws-backdrop",onClick:()=>H(!1)}),e.jsxs("div",{className:"ws-menu",role:"menu",children:[n!==void 0&&n!==""?e.jsxs("button",{type:"button",className:"ws-item ws-default",role:"menuitem",title:n,onClick:()=>{H(!1),c?.(n)},children:["默认空间 · ",Tn(n)]}):null,(X??[]).map(O=>e.jsx("button",{type:"button",className:"ws-item",role:"menuitem",title:O.path,onClick:()=>{H(!1),c?.(O.path)},children:Tn(O.path)},O.path)),X===null?e.jsx("div",{className:"ws-loading",children:"加载中…"}):null,e.jsx("button",{type:"button",className:"ws-item ws-open-other",role:"menuitem",onClick:()=>{H(!1),d?.()},children:"打开其他目录…"})]})]}):null]}),e.jsx("div",{className:"tree-filter",children:e.jsx("input",{type:"text",value:q,placeholder:"过滤…","aria-label":"过滤文件树",onChange:O=>D(O.target.value)})}),e.jsx("div",{className:"tree-body",children:K===void 0?e.jsx(or,{}):K.error!==null?e.jsx(cr,{message:K.error,onRetry:()=>P("")}):K.entries.length===0?e.jsx("div",{className:"tree-empty",role:"status",children:"空目录"}):le(K.entries,"",0)}),W!==null?e.jsx(qr,{x:W.x,y:W.y,items:Q(W.path,W.isDir),onClose:()=>z(null)}):null]})}function kp({path:t,value:s,language:n,dirty:a,saving:l,conflict:r,onChange:o,onSave:c,onOverwrite:d,onReopen:m,onDiscard:p}){const g=i.useRef(null),v=i.useRef(null),N=i.useRef(null),S=s.split(`
325
+ `),R=()=>{const f=g.current;f!==null&&(v.current!==null&&(v.current.scrollTop=f.scrollTop,v.current.scrollLeft=f.scrollLeft),N.current!==null&&(N.current.scrollTop=f.scrollTop))},j=f=>{if(f.key==="Tab"){f.preventDefault();const A=f.currentTarget,$=A.selectionStart;o(`${s.slice(0,$)} ${s.slice(A.selectionEnd)}`);const y=$+2;requestAnimationFrame(()=>A.setSelectionRange(y,y))}else f.key==="Escape"&&!a&&(f.preventDefault(),p())};return e.jsxs("div",{className:"editor-root",children:[e.jsxs("div",{className:"fv-edit",children:[e.jsx("button",{type:"button",className:"fv-btn primary",disabled:!a||l,onClick:c,children:"保存"}),e.jsx("button",{type:"button",className:"fv-btn",disabled:l,onClick:p,children:"放弃"}),e.jsx("span",{className:"grow"}),e.jsx("span",{className:"fv-edit-path",children:t})]}),r!==null?e.jsxs("div",{className:"fv-conflict",role:"alert",children:[e.jsxs("span",{children:[e.jsx(ae,{name:"triangle-alert",size:12})," 文件已被外部修改"]}),e.jsx("button",{type:"button",className:"fv-btn",disabled:l,onClick:()=>m(r),children:"用磁盘内容重开"}),e.jsx("button",{type:"button",className:"fv-btn primary",disabled:l,onClick:d,children:"覆盖保存"})]}):null,e.jsxs("div",{className:"editor-wrap",children:[e.jsx("div",{className:"editor-gutter",ref:N,"aria-hidden":!0,children:S.map((f,A)=>e.jsx("div",{children:A+1},A))}),e.jsxs("div",{className:"editor-stack",children:[e.jsx("pre",{className:"editor-hl",ref:v,"aria-hidden":!0,children:S.map((f,A)=>e.jsxs(ce.Fragment,{children:[A>0?`
326
+ `:null,e.jsx(ct,{text:f,lang:n})]},A))}),e.jsx("textarea",{className:"editor-ta",ref:g,value:s,spellCheck:!1,"aria-label":`编辑 ${t}`,wrap:"off",onChange:f=>o(f.target.value),onScroll:R,onKeyDown:j})]})]})]})}function dr(t,s){let n=t instanceof HTMLElement?t:t?.parentElement??null;for(;n!==null;){if(n===s)return null;const a=n.getAttribute("data-line");if(a!==null){const l=Number(a);return Number.isFinite(l)&&l>=1?l:null}n=n.parentElement}return null}function wp(t,s){if(s===null)return null;const n=dr(s.anchorNode,t),a=dr(s.focusNode,t);if(n===null||a===null)return null;const l=s.toString().split(`
327
+ `).map(r=>r.replace(/\s+$/,"")).join(`
328
+ `).trim();return l===""?null:{first:Math.min(n,a),last:Math.max(n,a),text:l}}function Sp(t,s,n,a){const l=s===n?`第 ${s} 行`:`第 ${s}-${n} 行`,r=a.length>3e3?`${a.slice(0,1400)}
329
+ …(中略)
330
+ ${a.slice(-1400)}`:a;return`请修改 ${t} ${l}:
331
+
332
+ \`\`\`
333
+ ${r}
334
+ \`\`\`
335
+
336
+ 我的要求:`}const Cp=100*1024,ur=2e3,Dn=t=>t instanceof Error?t.message:String(t),Ep=t=>t.endsWith(".md");function $p(t){if(t==="")return[];const s=t.split(`
337
+ `);return s.length>1&&s[s.length-1]===""&&s.pop(),s}function Rp({client:t,path:s,isDir:n,onOpenPath:a,onReadFailed:l,refreshEpoch:r,onClose:o,onPrefill:c}){const[d,m]=i.useState({s:"loading"}),[p,g]=i.useState("preview"),[v,N]=i.useState(null),[S,R]=i.useState(!1),[j,f]=i.useState(null),[A,$]=i.useState(null),[y,q]=i.useState(null),[D,V]=i.useState(0),[H,X]=i.useState(null);i.useEffect(()=>{s!==null&&(g("preview"),N(null),f(null),$(null),q(null))},[t,s,n,l,r]),i.useEffect(()=>{if(s===null)return;let P=!1;return m({s:"loading"}),X(null),n?t.fileTree(s).then(T=>{P||m({s:"dir",entries:Xn(T.entries)})},T=>{P||(m({s:"error",message:Dn(T)}),l?.(s))}):t.fileRead(s).then(T=>{P||m({s:"file",r:T})},T=>{P||(m({s:"error",message:Dn(T)}),l?.(s))}),()=>{P=!0}},[t,s,n,l,r,D]);const W=s===null?[]:s.split("/").filter(P=>P!==""),z=s!==null&&!n&&Ep(s)&&d.s==="file"&&d.r.binary!==!0&&v===null,F=e.jsx("button",{type:"button",className:"fv-close","aria-label":"关闭",title:"关闭",onClick:()=>o?.(),children:e.jsx(es,{size:14})});let M;if(s===null)M=e.jsx("div",{className:"viewer-empty",children:"从左侧选择文件查看内容"});else if(d.s==="loading")M=e.jsx("div",{className:"viewer-empty",children:"加载中…"});else if(d.s==="error")M=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fv-head",children:[e.jsx("span",{className:"fv-file",children:s}),F]}),e.jsxs("div",{className:"viewer-err",children:[e.jsx(ae,{name:"triangle-alert",size:13})," ",d.message]})]});else if(d.s==="dir")M=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fv-head",children:[e.jsx("span",{className:"fv-file",children:s}),F]}),e.jsx("div",{className:"viewer-dirwrap",children:e.jsxs("table",{className:"viewer-dir",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"名称"}),e.jsx("th",{children:"类型"}),e.jsx("th",{children:"大小"})]})}),e.jsx("tbody",{children:d.entries.map(P=>e.jsxs("tr",{children:[e.jsx("td",{className:"viewer-entry-name",children:P.type==="dir"?e.jsxs(e.Fragment,{children:[e.jsx(ts,{size:14})," ",P.name]}):e.jsxs(e.Fragment,{children:[e.jsx(Zn,{size:14})," ",P.name]})}),e.jsx("td",{children:P.type==="dir"?"目录":"文件"}),e.jsx("td",{children:P.type==="file"&&P.size!==void 0?`${P.size} bytes`:"—"})]},P.name))})]})})]});else{const P=d.r;if(P.binary===!0)M=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fv-head",children:[e.jsx("span",{className:"fv-file",children:s}),F]}),e.jsx("div",{className:"viewer-binary",children:`二进制文件 · ${P.totalBytes} bytes · 不支持预览`})]});else{const T=P.truncated||P.totalBytes>Cp,U=$p(P.content),Q=T?U.slice(0,ur):U,se=!T&&t.fileWrite!==void 0,de=()=>{N({base:P.content,value:P.content}),f(null),$(null),q(null)},le=O=>{if(c===void 0||s===null){X(null);return}const x=window.getSelection(),b=wp(O.currentTarget,x);if(b===null){X(null);return}let k=0,w=0;try{const E=x?.getRangeAt(0).getBoundingClientRect();k=E?.right??0,w=E?.top??0}catch{}X({...b,path:s,x:k,y:w})},K=O=>{v===null||s===null||t.fileWrite===void 0||(R(!0),t.fileWrite(s,v.value,O).then(x=>{R(!1),"written"in x?(q(`已保存 ${s} · ${v.value.split(`
338
+ `).length} 行`),N(null),f(null),$(null),V(b=>b+1)):f(x.current)},x=>{R(!1),$(Dn(x))}))};M=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fv-head",children:[e.jsx("span",{className:"fv-file",children:s}),v===null&&se?e.jsx("button",{type:"button",className:"fv-btn",onClick:de,children:"编辑"}):null,F]}),y!==null&&v===null?e.jsx("div",{className:"fv-saved",children:y}):null,v!==null?e.jsxs(e.Fragment,{children:[A!==null?e.jsxs("div",{className:"viewer-err",children:[e.jsx(ae,{name:"triangle-alert",size:13})," ",A]}):null,e.jsx(kp,{path:s,value:v.value,language:Wn(s)??P.language,dirty:v.value!==v.base,saving:S,conflict:j,onChange:O=>N({...v,value:O}),onSave:()=>K(v.base),onOverwrite:()=>K(j??v.base),onReopen:O=>{N({base:O,value:O}),f(null),$(null)},onDiscard:()=>{N(null),f(null),$(null)}})]}):z&&p==="preview"?e.jsx("div",{className:"viewer-md",children:e.jsx(Vr,{source:P.content})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"viewer-code",onMouseUp:le,children:Q.map((O,x)=>e.jsxs("div",{className:"viewer-line","data-line":x+1,children:[e.jsx("span",{className:"viewer-gutter",children:x+1}),e.jsx("span",{className:"viewer-src",children:e.jsx(ct,{text:O,lang:Wn(s)??P.language})})]},x))}),H!==null&&c!==void 0?e.jsx("button",{type:"button",className:"fv-selchip",style:{left:`${H.x}px`,top:`${H.y}px`},onClick:()=>{c(Sp(H.path,H.first,H.last,H.text));try{window.getSelection()?.removeAllRanges()}catch{}X(null)},children:"改这段"}):null,T?e.jsx("div",{className:"viewer-truncated",children:`截断:文件 ${P.totalBytes} bytes,仅显示前 ${ur} 行`}):null]})]})}}return e.jsxs("div",{className:"fileviewer",children:[s===null?null:e.jsxs("div",{className:"breadcrumb",children:[W.map((P,T)=>{const U=T===W.length-1,Q=W.slice(0,T+1).join("/");return e.jsxs(ce.Fragment,{children:[T>0?e.jsx("span",{className:"crumb-sep",children:"/"}):null,U?e.jsx("span",{className:"crumb current","aria-current":"page",children:P}):e.jsx("span",{className:"crumb",role:"button",tabIndex:0,title:Q,onKeyDown:se=>{(se.key==="Enter"||se.key===" ")&&(se.preventDefault(),a?.(Q,!0))},onClick:()=>a?.(Q,!0),children:P})]},Q)}),z?e.jsxs("span",{className:"md-toggle",children:[e.jsx("button",{type:"button",className:"mdmode","data-mode":"source","aria-pressed":p==="source",title:"渲染后的 markdown 源码",onClick:()=>g("source"),children:"源码"}),e.jsx("button",{type:"button",className:"mdmode","data-mode":"preview","aria-pressed":p==="preview",title:"markdown 渲染预览",onClick:()=>g("preview"),children:"预览"})]}):null]}),M]})}function Mp(t){const s=[],n=new Set;for(const a of t)if(!(a.kind!=="notice"||a.changes===void 0||a.changes.length===0)){s.push({files:a.changes,detail:a.detail});for(const l of a.changes)n.add(l.path)}return{runs:s,fileCount:n.size}}function Tp(t){const s=[];for(const n of t){if(n.cmd===void 0){s.push({kind:"plain",file:n});continue}const a=s[s.length-1];a!==void 0&&a.kind==="cmd"&&a.cmd===n.cmd?s[s.length-1]={kind:"cmd",cmd:a.cmd,files:[...a.files,n]}:s.push({kind:"cmd",cmd:n.cmd,files:[n]})}return s}function Dp(t){return t.plus===void 0||t.minus===void 0||t.plus<=0&&t.minus<=0?null:{plus:t.plus,minus:t.minus}}function Ap(t){return t.plus!==void 0&&t.minus!==void 0&&t.plus<=0&&t.minus<=0?"这一轮结束时,这个文件的内容没有变化":"这份文件的改动明细过长,明细中已省略——完整记录可用 /rewind 回看"}function hr({f:t}){const s=Dp(t);return e.jsxs("span",{className:"chg-badge","data-op":t.op,children:[t.op==="created"?"新建":`修改 ×${t.writes}`,s!==null&&s.plus>0?e.jsx("span",{className:"chg-cnt chg-cnt-plus",children:` +${s.plus}`}):null,s!==null&&s.minus>0?e.jsx("span",{className:"chg-cnt chg-cnt-minus",children:` −${s.minus}`}):null]})}function Op({path:t,onChoose:s}){const n=i.useRef(!1),a=i.useRef(null);i.useEffect(()=>{a.current?.focus()},[]);const l=r=>{n.current||(n.current=!0,s(r))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in revert-confirm",role:"dialog","aria-label":"恢复文件",ref:a,tabIndex:-1,onKeyDown:r=>{r.key==="Escape"||r.key==="n"||r.key==="N"||r.key==="Enter"?(r.preventDefault(),l(!1)):(r.key==="y"||r.key==="Y")&&(r.preventDefault(),l(!0))},children:[e.jsxs("h3",{children:["↩ 恢复 ",t]}),e.jsx("div",{className:"muted",children:"这一轮开始前它是这个样子。"}),e.jsx("div",{className:"revert-warn",children:"如果这一轮之后你又改过它,恢复会覆盖这些改动——覆盖前会自动再留一份快照,随时可以再恢复回来。"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!0),children:"恢复"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!1),children:"取消 (Esc)"})]})]})})}function Ip({count:t,onChoose:s}){const n=i.useRef(!1),a=i.useRef(null);i.useEffect(()=>{a.current?.focus()},[]);const l=r=>{n.current||(n.current=!0,s(r))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in revert-confirm",role:"dialog","aria-label":"撤销命令改动",ref:a,tabIndex:-1,onKeyDown:r=>{r.key==="Escape"||r.key==="n"||r.key==="N"||r.key==="Enter"?(r.preventDefault(),l(!1)):(r.key==="y"||r.key==="Y")&&(r.preventDefault(),l(!0))},children:[e.jsx("h3",{children:"↩ 撤销这条命令的改动"}),e.jsx("div",{className:"muted",children:`这条命令改了 ${t} 个文件,会把它们恢复到命令开始前的样子。`}),e.jsx("div",{className:"revert-warn",children:"如果这之后你又改过其中某个文件,恢复会覆盖这些改动——覆盖前每个文件都会自动再留一份快照,随时可以再恢复回来。"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!0),children:"撤销"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!1),children:"取消 (Esc)"})]})]})})}function Lp({run:t,ordinal:s,onRevert:n,onGroupRevert:a}){const[l,r]=i.useState(!1),[o,c]=i.useState(null),[d,m]=i.useState(null),p=i.useRef(null),g=t.detail!==void 0&&t.detail.length>0,v=i.useMemo(()=>g?Eh(t.detail??""):new Set,[g,t.detail]);i.useEffect(()=>{if(!l||o===null)return;[...p.current?.querySelectorAll("[data-dtx-file]")??[]].find(A=>A.getAttribute("data-dtx-file")===o)?.scrollIntoView({block:"start"}),c(null)},[l,o]);const N=f=>f.beforeSha!==void 0&&n!==void 0?e.jsx("span",{className:"chg-revert",role:"button",tabIndex:0,"data-path":f.path,title:"这一轮开始前它是这个样子","aria-label":`恢复 ${f.path} 到这一轮开始前的样子`,onClick:()=>n(f.path,f.beforeSha),onKeyDown:A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),n(f.path,f.beforeSha))},children:"恢复到这里"}):null,S=f=>f.cmd!==void 0?e.jsx("span",{className:"chg-cmd-badge",title:f.cmd,children:"命令改动"}):null,R=f=>e.jsxs("div",{className:"chg-file-wrap",children:[g&&v.has(f.path)?e.jsxs("button",{type:"button",className:"chg-file",title:`在改动明细中定位 ${f.path}`,onClick:()=>{r(!0),c(f.path)},children:[e.jsx("span",{className:"chg-path",children:f.path}),e.jsx(hr,{f})]}):e.jsxs("div",{className:"chg-file",title:g?Ap(f):void 0,children:[e.jsx("span",{className:"chg-path",children:f.path}),e.jsx(hr,{f})]}),S(f),N(f)]},f.path),j=f=>{const A=f.files.filter(y=>y.beforeSha!==void 0),$=A.length===0;return e.jsx("span",{className:"chg-cmd-undo",role:"button",tabIndex:0,"aria-disabled":$?"true":void 0,title:$?"首次改动暂无可恢复快照":`撤销这条命令的改动(${A.length} 个文件)`,"aria-label":$?"首次改动暂无可恢复快照":`撤销这条命令改的 ${A.length} 个文件`,onClick:()=>{$||a===void 0||m({cmd:f.cmd,files:A})},onKeyDown:y=>{if(y.key==="Enter"||y.key===" "){if(y.preventDefault(),$||a===void 0)return;m({cmd:f.cmd,files:A})}},children:"撤销这条命令的改动"})};return e.jsxs("div",{className:"chg-run",ref:p,children:[e.jsx("div",{className:"chg-run-h",children:`第 ${s} 轮 · ${t.files.length} 文件`}),e.jsx("div",{className:"chg-files",children:Tp(t.files).map((f,A)=>f.kind==="plain"?R(f.file):e.jsxs("div",{className:"chg-cmdgroup",children:[e.jsxs("div",{className:"chg-cmd-h",title:f.cmd,children:[e.jsx("span",{className:"chg-cmd-label",children:`这条命令改了 ${f.files.length} 个文件`}),j(f)]}),f.files.map(R)]},`cmd-${A}-${f.cmd.length}`))}),g?e.jsxs("button",{type:"button",className:"chg-exp","aria-expanded":l,"aria-label":l?`收起第 ${s} 轮改动明细`:`展开第 ${s} 轮改动明细`,onClick:()=>r(!l),children:[e.jsx("span",{children:l?"收起改动明细":"展开改动明细"}),l?e.jsx(et,{size:12}):e.jsx(bt,{size:12})]}):null,l&&g?e.jsx(ji,{detail:t.detail??"",className:"chg-detail",as:"pre"}):null,d!==null&&a!==void 0?e.jsx(Ip,{count:d.files.length,onChoose:f=>{const A=d;m(null),f&&A.files.forEach($=>a($.path,$.beforeSha))}}):null]})}function Pp({agg:t,onClose:s,onRevert:n}){const a=i.useRef(null),[l,r]=i.useState(null);return i.useEffect(()=>{a.current?.focus()},[]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in changes-panel",role:"dialog","aria-label":"会话改动",ref:a,tabIndex:-1,onKeyDown:o=>{o.key==="Escape"&&l===null&&(o.preventDefault(),s())},children:[e.jsx("h3",{children:"会话改动"}),e.jsx("div",{className:"chg-head muted",children:`共改动 ${t.fileCount} 个文件 · ${t.runs.length} 轮`}),e.jsx("div",{className:"chg-runs",children:t.runs.map((o,c)=>e.jsx(Lp,{run:o,ordinal:c+1,onRevert:n!==void 0?(d,m)=>r({path:d,sha:m}):void 0,onGroupRevert:n},`${c}-${o.files.length}`))}),e.jsx("div",{className:"btnrow",children:e.jsx("button",{type:"button",className:"wudao",onClick:s,children:"关闭"})})]})}),l!==null&&n!==void 0?e.jsx(Op,{path:l.path,onChoose:o=>{const c=l;r(null),o&&n(c.path,c.sha)}}):null]})}const _p=new Set(["screen.capture","computer.type","computer.key","computer.click","app.activate","app.list","computer.scroll","computer.drag","screen.observe","computer.wait"]);function Fp(t){const s=[];let n=[],a=0,l=()=>{n.length>0&&(s.push({actions:n}),n=[])};for(const r of t){if(r.kind==="user"){l();continue}if(r.kind!=="tool"||!_p.has(r.name))continue;a++;const o=n[n.length-1];if(o!==void 0&&o.name===r.name&&o.summary===r.summary){const c=o.durationMs!==void 0&&r.durationMs!==void 0?o.durationMs+r.durationMs:void 0;n[n.length-1]={...o,isError:o.isError||r.isError===!0,durationMs:c,count:o.count+1,preview:r.resultPreview??""};continue}n.push({name:r.name,summary:r.summary,isError:r.isError===!0,durationMs:r.durationMs,count:1,preview:r.resultPreview??""})}return l(),{runs:s,totalSteps:a}}const zp={"screen.capture":"截了一张全屏图","computer.type":"输入了","computer.key":"按键","computer.click":"点击","app.activate":"打开了","app.list":"看了当前打开的应用","computer.scroll":"滚动了","computer.drag":"拖动了","screen.observe":"观察了","computer.wait":"等待了"},Bp=new Set(["computer.type","computer.key","computer.click","app.activate","computer.scroll","computer.drag","screen.observe","computer.wait"]);function Kp({row:t}){const s=zp[t.name]??t.name,n=t.summary!=="";return e.jsxs("div",{className:"cap-act","data-err":t.isError?"true":void 0,children:[e.jsx("span",{className:"cap-verb",children:n?s:t.name}),n&&Bp.has(t.name)?e.jsx("span",{className:"cap-text",children:t.summary}):null,t.count>1?e.jsx("span",{className:"cap-badge",children:`×${t.count}`}):null,t.durationMs!==void 0?e.jsx("span",{className:"cap-dur",children:`· ${Sr(t.durationMs)}`}):null,!n&&t.preview!==""?e.jsx("div",{className:"cap-preview",children:t.preview}):null]})}function Wp({agg:t,onClose:s}){const n=i.useRef(null);return i.useEffect(()=>{n.current?.focus()},[]),e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in computer-panel",role:"dialog","aria-label":"电脑操作",ref:n,tabIndex:-1,onKeyDown:a=>{a.key==="Escape"&&(a.preventDefault(),s())},children:[e.jsx("h3",{children:"电脑操作"}),e.jsx("div",{className:"cap-head muted",children:`共电脑操作 ${t.totalSteps} 步 · ${t.runs.length} 轮`}),e.jsx("div",{className:"cap-runs",children:t.runs.map((a,l)=>e.jsxs("div",{className:"cap-run",children:[e.jsx("div",{className:"cap-run-h",children:`第 ${l+1} 轮 · ${a.actions.reduce((r,o)=>r+o.count,0)} 步`}),e.jsx("div",{className:"cap-acts",children:a.actions.map((r,o)=>e.jsx(Kp,{row:r},`${r.name}-${o}`))})]},`${l}-${a.actions.length}`))}),e.jsx("div",{className:"btnrow",children:e.jsx("button",{type:"button",className:"wudao",onClick:s,children:"关闭"})})]})})}function An(t){const s=new Date(t),n=a=>String(a).padStart(2,"0");return`${s.getMonth()+1}月${s.getDate()}日 ${n(s.getHours())}:${n(s.getMinutes())}`}function Up(t,s,n=Date.now){const a=l=>{if(l===void 0||s===null)return null;const r=s.find(c=>c.id===l);if(r===void 0)return null;const o=r.name?.trim()??"";return o!==""?o:r.firstUser};return t.map(l=>{const r=l.paused===!0,o=l.enabled!==!1,c=l.consecutiveFailures??0,d=r?"paused":o?"active":"breaker",m=d==="paused"?"已暂停":d==="breaker"?"已停用":"生效中",p=n(),g=l.triggerKind==="event",v=l.triggerKind==="idle";let N;d==="paused"?N="已暂停——恢复后按计划继续":d==="breaker"?N="已停用——恢复或试跑可重开":g?N="等信号到达":v?N=l.nextRunAt!==null&&l.nextRunAt!==void 0&&l.nextRunAt<=p?"等用户空闲":"等空闲":l.nextRunAt===null||l.nextRunAt===void 0?N="无待跑":N=l.nextRunAt<=p?"马上":An(l.nextRunAt);let S;if(d==="breaker")S=`连败 ${c} 次没跑成,已自动停用`;else if(l.lastRun!==void 0&&l.lastRun!==null){const R=l.lastRun.mode==="skipped"?"会话忙,跳过了":l.lastRun.ok?"跑成了":"没跑成";S=`上次 ${An(l.lastRun.at)} ${R}`,c>0&&(S+=`——已连败 ${c} 次`)}else l.lastFiredAt!==void 0&&l.lastFiredAt!==null?S=`上次触发 ${An(l.lastFiredAt)}`:S=l.kind==="reminder"?"还没响过":"还没跑过";return{id:l.id,kind:l.kind,promptText:l.prompt.slice(0,80),trigger:l.trigger,triggerKind:g?"event":v?"idle":"calendar",state:d,stateText:m,nextText:N,lastText:S,sessionName:a(l.sessionId),breaker:d==="breaker",paused:r,failures:c}})}function Hp({promptText:t,onChoose:s}){const n=i.useRef(!1),a=i.useRef(null);i.useEffect(()=>{a.current?.focus()},[]);const l=r=>{n.current||(n.current=!0,s(r))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in remove-confirm",role:"dialog","aria-label":"删除定时任务",ref:a,tabIndex:-1,onKeyDown:r=>{r.key==="Escape"||r.key==="n"||r.key==="N"||r.key==="Enter"?(r.preventDefault(),l(!1)):(r.key==="y"||r.key==="Y")&&(r.preventDefault(),l(!0))},children:[e.jsx("h3",{children:"删除这条定时任务?"}),e.jsx("div",{className:"muted",children:t}),e.jsx("div",{className:"revert-warn",children:"删除后它不会再到点跑——这是唯一入口,删了要重新设。"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!0),children:"删除"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>l(!1),children:"取消 (Esc)"})]})]})})}function qp({failures:t,promptText:s,onChoose:n}){const a=i.useRef(!1),l=i.useRef(null);i.useEffect(()=>{l.current?.focus()},[]);const r=o=>{a.current||(a.current=!0,n(o))};return e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in run-confirm",role:"dialog","aria-label":"试跑熔断任务",ref:l,tabIndex:-1,onKeyDown:o=>{o.key==="Escape"||o.key==="n"||o.key==="N"||o.key==="Enter"?(o.preventDefault(),r(!1)):(o.key==="y"||o.key==="Y")&&(o.preventDefault(),r(!0))},children:[e.jsxs("h3",{children:["连败 ",t," 次已熔断,仍要试跑?"]}),e.jsx("div",{className:"muted",children:s}),e.jsx("div",{className:"revert-warn",children:"试跑前会清零连败计数并重新打开它——跑成跑不成都会如实告诉你。"}),e.jsxs("div",{className:"btnrow",children:[e.jsx("button",{type:"button",className:"wudao",onClick:()=>r(!0),children:"试跑"}),e.jsx("button",{type:"button",className:"wudao",onClick:()=>r(!1),children:"取消 (Esc)"})]})]})})}function Gp({rows:t,onClose:s,onToggle:n,onRemove:a,onRun:l}){const r=i.useRef(null),[o,c]=i.useState(null),[d,m]=i.useState(null);return i.useEffect(()=>{r.current?.focus()},[]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scrim",children:e.jsxs("div",{className:"modal-card pop-in schedules-panel",role:"dialog","aria-label":"定时任务",ref:r,tabIndex:-1,onKeyDown:p=>{p.key==="Escape"&&o===null&&d===null&&(p.preventDefault(),s())},children:[e.jsx("h3",{children:"定时任务"}),e.jsx("div",{className:"sch-head muted",children:`共 ${t.length} 条`}),e.jsx("div",{className:"sch-rows",children:t.length===0?e.jsx("div",{className:"muted",children:"没有定时任务了"}):t.map(p=>e.jsxs("div",{className:"sch-row","data-state":p.state,children:[e.jsxs("div",{className:"sch-main",children:[e.jsx("span",{className:"sch-prompt",children:p.promptText}),e.jsx("span",{className:"sch-badge sch-state","data-state":p.state,children:p.stateText})]}),e.jsxs("div",{className:"sch-meta",children:[e.jsx("span",{className:"sch-trig",children:p.trigger}),e.jsx("span",{className:"sch-next",children:p.triggerKind==="event"?p.nextText:`下次 ${p.nextText}`}),e.jsx("span",{className:"sch-last","data-ok":p.lastText.includes("跑成了")||void 0,children:p.lastText}),p.sessionName!==null?e.jsx("span",{className:"sch-session",children:`绑定会话 ${p.sessionName}`}):null]}),e.jsxs("div",{className:"sch-acts",children:[e.jsx("button",{type:"button",className:"sch-act","data-act":"toggle",onClick:()=>n(p.id,p.paused),children:p.paused?"恢复":"暂停"}),e.jsx("button",{type:"button",className:"sch-act","data-act":"run",onClick:()=>{p.breaker?m(p):l(p.id,!1)},children:"试跑"}),e.jsx("button",{type:"button",className:"sch-act sch-del","data-act":"remove",onClick:()=>c(p.id),children:"删除"})]})]},p.id))}),e.jsx("div",{className:"btnrow",children:e.jsx("button",{type:"button",className:"wudao",onClick:s,children:"关闭"})})]})}),o!==null?e.jsx(Hp,{promptText:t.find(p=>p.id===o)?.promptText??o,onChoose:p=>{const g=o;c(null),p&&a(g)}}):null,d!==null?e.jsx(qp,{failures:d.failures,promptText:d.promptText,onChoose:p=>{const g=d;m(null),p&&l(g.id,!0)}}):null]})}const Vp="wudao-screenshot",Yp="截图.png";function Xp(t){if(typeof t!="object"||t===null)return null;const s=t;return typeof s.data!="string"||s.data===""||typeof s.mediaType!="string"||!s.mediaType.startsWith("image/")?null:{data:s.data,mediaType:s.mediaType}}function Jp(t){const s=atob(t),n=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)n[a]=s.charCodeAt(a);return n}function Qp(t){const s=Xp(t);if(s===null)return null;try{return new File([Jp(s.data)],Yp,{type:s.mediaType})}catch{return null}}const Zp="pet-file-drop",ef=20*1024*1024;function tf(t){if(typeof t!="object"||t===null)return null;const s=t.paths;if(!Array.isArray(s)||s.length===0)return null;const n=[];for(const a of s){if(typeof a!="object"||a===null)continue;const{path:l,name:r,bytes:o}=a;typeof l!="string"||typeof r!="string"||typeof o!="number"||n.push({path:l,name:r,bytes:o})}return n.length>0?n:null}function sf(t,s){return t.bytes>ef?"oversize":s.length>=Ys?"count":s.reduce((a,l)=>a+ns(l.byteLength),0)+ns(t.bytes)>ui?"budget":null}function nf(t,s){const n=[],a=[...s],l=new Map;for(const o of t){const c=sf(o,a);c===null?(n.push(o),a.push({byteLength:o.bytes})):l.set(c,(l.get(c)??0)+1)}if(l.size===0)return{accepted:n,notice:null};const r=[];for(const o of["oversize","count","budget"]){const c=l.get(o);c!==void 0&&(o==="oversize"?r.push(`${c} 个超出单文件 20MiB 上限`):o==="count"?r.push(`${c} 个超出数量上限(最多同时附加 ${Ys} 个)`):r.push(`${c} 个超出批量 50MiB 上限`))}return{accepted:n,notice:`⚠️ ${r.join(" · ")}`}}function af(t){const s=atob(t),n=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)n[a]=s.charCodeAt(a);return n}async function lf(t,s){const n=[];for(const a of s)try{const l=await t.readDroppedFile(a.path);n.push(la(new File([af(l)],a.name)))}catch(l){t.warn(`pet drop: skipping ${a.name} (${l instanceof Error?l.message:String(l)})`)}if(n.length!==0)try{t.onStaged(n)}catch(a){t.warn(`pet drop: onStaged failed (${a instanceof Error?a.message:String(a)})`)}}async function rf(t){const s=await Zt("read_dropped_file",{path:t});if(typeof s!="string")throw new Error(`read_dropped_file refused ${t}`);return s}let Jn=null;function mr(t){Jn=t}function of(t,s){const n=(...c)=>console.warn(...c),a={readDroppedFile:rf,onStaged:c=>{if(Jn===null){n("pet drop: no stage sink (App not mounted)");return}Jn(c)},warn:n,listen:(c,d)=>Mt(c,d)};let l=null,r=!1,o=Promise.resolve();return Promise.resolve(a.listen(Zp,c=>{const d=tf(c);if(d===null)return;const{accepted:m,notice:p}=nf(d,[]);if(p!==null&&a.warn(`pet drop: ${p}`),m.length===0)return;const g=m;o=o.then(()=>lf(a,g)).catch(()=>{})})).then(c=>{r?c?.():l=c}),()=>{r=!0,l?.()}}const Ds="input-pointer";function cf(){i.useEffect(()=>{const t=document.documentElement;t.classList.remove(Ds);const s=()=>{t.classList.add(Ds)},n=()=>{t.classList.remove(Ds)};return window.addEventListener("pointerdown",s),window.addEventListener("keydown",n),()=>{window.removeEventListener("pointerdown",s),window.removeEventListener("keydown",n),t.classList.remove(Ds)}},[])}function df({client:t}){const s=Lc(t),n=s.status,{view:a,setViewLane:l}=md(s),r=pd(),o=r.slot(a.key),c=a.busy,d=n?.busy??!1,m=a.viewingMain,p=i.useRef(a);p.current=a;const g=i.useRef(r);g.current=r;const[v,N]=i.useState([]),S=o.notes,[R,j]=i.useState(null),[f,A]=i.useState("resume"),[$,y]=i.useState(!1),[q,D]=i.useState(null),[V,H]=i.useState(!1),[X,W]=i.useState(!1),[z,F]=i.useState("checking"),[M,P]=i.useState(null),[T,U]=i.useState("advanced"),[Q]=i.useState(td),se=i.useRef(!1),de=i.useRef(!1),le=i.useRef(null),K=i.useRef(null);K.current===null&&(K.current=ud());const O=K.current,[x,b]=i.useState(()=>gl(O)),[k,w]=i.useState(()=>{const u=gl(O).length;return typeof O.activeTabIndex=="number"?Math.min(Math.max(Math.trunc(O.activeTabIndex),0),Math.max(u-1,0)):0}),[E,G]=i.useState(()=>typeof O.centerCollapsed=="boolean"?O.centerCollapsed:!1),[ee,me]=i.useState(()=>typeof O.leftCollapsed=="boolean"?O.leftCollapsed:yn()),[ye,Ne]=i.useState(()=>typeof O.rightCollapsed=="boolean"?O.rightCollapsed:!1),[he,Ee]=i.useState(()=>typeof O.treeW=="number"&&Number.isFinite(O.treeW)?ot(O.treeW):fl),[ve,Re]=i.useState(()=>typeof O.chatW=="number"&&Number.isFinite(O.chatW)?ot(O.chatW):xl),[qe,Fe]=i.useState(!1),Ie=i.useRef(null),pe=i.useCallback(()=>{Ie.current={leftCollapsed:ee,chatW:ve},Fe(!0),me(!0),Re(nd)},[ee,ve]),ze=i.useCallback(()=>{const u=Ie.current;Fe(!1),u!==null&&(me(u.leftCollapsed),Re(u.chatW)),Ie.current=null},[]),Me=i.useCallback(()=>{qe?ze():pe()},[qe,pe,ze]);i.useEffect(()=>{T!=="advanced"&&ze()},[T,ze]);const[Le,Ge]=i.useState(0),[$e,_]=i.useState(null),[Y,J]=i.useState(!1),ie=i.useRef([]),[ge,ne]=i.useState(!1),[re,fe]=i.useState(!1),[je,Ve]=i.useState(null),[ht,Ot]=i.useState(null),[Be,Pe]=i.useState(0),[Je,It]=i.useState(!1),[ls,Lt]=i.useState(!1),[st,rs]=i.useState(null),[Pt,is]=i.useState(null),[Js,_t]=i.useState(0),[Qs,os]=i.useState(!1),[nt,L]=i.useState(()=>O?.buddyCollapsed===!0||kn()),[te,ue]=i.useState(ed),xe=i.useRef(!1),[oe,Ke]=i.useState(""),[Oe,yt]=i.useState(""),[Se,cs]=i.useState(null),Ft=i.useRef(""),ha=i.useCallback(u=>{Ft.current=u},[]),it=i.useRef([]),ma=i.useCallback(u=>{it.current=u},[]),[ds,Zs]=i.useState(null),pa=i.useCallback(()=>{Zs(null)},[]),mt=i.useRef([]),fa=i.useCallback(u=>{mt.current=u},[]),[us,en]=i.useState(null),xa=i.useCallback(()=>{en(null)},[]),[hs,ms]=i.useState(null),I=i.useCallback(u=>{const h=t.getSnapshot(),C=p.current,B=C.sid!==null?h.lanes?.[C.sid]:void 0;g.current.stampNote(C.key,u,B!==void 0?B.history.length:h.history.length,B!==void 0?B.historyEpoch:h.historyEpoch)},[t]),[ps,zt]=i.useState(0),Wi=i.useCallback((u,h)=>{if(u!==(n?.sessionId??null)){I("命名只对当前打开的会话生效:先打开它再命名");return}t.submit(`/rename ${h}`).then(()=>{zt(C=>C+1),I(`会话已命名:${h}`)}).catch(C=>I(`⚠️ 命名失败:${C instanceof Error?C.message:String(C)}`))},[t,I,n?.sessionId]),Ui=i.useCallback(u=>t.sessionDelete(u).then(h=>h.deleted?(zt(C=>C+1),I("已删除会话"),!0):(h.reason==="active"?I("会话正在使用中,暂不能删除"):I("没有找到这个会话(可能已删除)"),!1),h=>(I(`⚠️ 删除失败:${h instanceof Error?h.message:String(h)}`),!1)),[t,I]),Hi=i.useCallback(u=>t.sessionRestore(u).then(h=>h.restored?(zt(C=>C+1),Pe(C=>C+1),I("已恢复,回到列表可继续"),!0):(h.reason==="target-exists"?I("已存在同名会话"):I("回收站里已没有这条"),!1),h=>(I(`⚠️ 恢复失败:${h instanceof Error?h.message:String(h)}`),!1)),[t,I]),tn=i.useRef({name:null,armed:!1});i.useEffect(()=>{const u=tn.current,h=n?.sessionName??null;if(!u.armed){tn.current={name:h,armed:!0};return}h!==u.name&&(tn.current={name:h,armed:!0},zt(C=>C+1))},[n?.sessionName]),i.useEffect(()=>{let u=!1,h=null;return Mt(yr,()=>{zt(C=>C+1)}).then(C=>{u?C?.():h=C}),()=>{u=!0,h?.()}},[]),i.useEffect(()=>{let u=!1,h=null;return Mt(Vp,C=>{const B=Qp(C);if(B===null)return;const{accepted:Z,notice:be}=ci([B],it.current);if(be!==null&&I(be),Z.length===0)return;const ke=[...it.current,...Z.map(we=>di(we))];it.current=ke,Zs(we=>({drafts:ke,nonce:(we?.nonce??0)+1}))}).then(C=>{u?C?.():h=C}),()=>{u=!0,h?.()}},[I]),i.useEffect(()=>(mr(u=>{const{accepted:h,notice:C}=hi(u.map(Z=>Z.file),mt.current);if(C!==null&&I(C),h.length===0)return;const B=[...mt.current,...h.map(Z=>la(Z))];mt.current=B,en(Z=>({drafts:B,nonce:(Z?.nonce??0)+1}))}),()=>mr(null)),[I]),i.useEffect(()=>{if(s.connection!=="connected")return;let u=!1;return t.listSlashCommands().then(h=>{u||N(h)}).catch(()=>{}),()=>{u=!0}},[t,s.connection]),i.useEffect(()=>{vt(zs()),ss(_n())},[]),i.useEffect(()=>{if(s.connection!=="connected")return;let u=!1;return t.settingsStatus().then(h=>{u||(P(h),F(C=>C==="checking"?Ic({providers:h.providers,wizardCompletedVersion:h.settings.wizardCompletedVersion})?"show":"done":C),U(h.settings.uiDefaultMode??"advanced"),se.current||vt(h.settings.uiTheme??"dark"),de.current||ss(h.settings.uiAccent??"green"))}).catch(()=>{u||F(h=>h==="checking"?"done":h)}),()=>{u=!0}},[t,s.connection]);const Nt=i.useCallback(()=>{t.settingsStatus().then(P).catch(()=>{})},[t]),va=i.useCallback((u,h)=>{const C=wr({provider:h,model:u},n?.model?.provider),B=C.startsWith("/provider");t.submit(C).then(()=>I(B?`供应商 → ${h} — 历史在新端点重新处理,下一轮生效(缓存全冷)`:`模型 → ${u} — 下一轮生效`)).catch(Z=>I(`⚠️ ${C.split(" ")[0]} 失败:${Z instanceof Error?Z.message:String(Z)}`))},[t,I,n]),ga=i.useCallback(()=>{const u=n?.model;if(u==null||u.label==="")return;const h=u.provider??"deepseek";t.settingsSet("model.defaultModel",{provider:h,model:u.label}).then(()=>I(`已设为默认:${h}/${u.label} —— 下次启动 wudao ui 生效`)).catch(C=>I(`⚠️ 默认模型保存失败:${C instanceof Error?C.message:String(C)}`))},[t,I,n]),ja=i.useCallback(()=>{const u=n?.model?.provider,h=M?.current?.effort;if(u==null||u===""||h==null||h===""){I("⚠️ 当前会话没有生效的推理档,无法设为默认");return}const C=(M?.providers??[]).find(B=>B.provider===u);if(C===void 0){I(`⚠️ 找不到供应商 ${u} 的注册表卡片,无法保存`);return}t.settingsSaveProvider(u,$c(C,h)).then(B=>{B.ok?(I(`已设为 ${C.label} 默认推理档:${h} —— 新会话生效`),Nt()):I(`⚠️ 保存失败:${B.error}`)}).catch(B=>I(`⚠️ 保存失败:${B instanceof Error?B.message:String(B)}`))},[t,I,n,M,Nt]);i.useEffect(()=>{if(s.connection!=="connected")return;let u=!1;return t.agentRootStatus().then(h=>{u||(typeof h?.agentRoot=="string"&&h.agentRoot!==""&&Ke(h.agentRoot),typeof h?.bootRoot=="string"&&h.bootRoot!==""&&yt(h.bootRoot),!xe.current&&typeof h?.panelRoot=="string"&&h.panelRoot!==""&&ue(h.panelRoot))}).catch(()=>{}),()=>{u=!0}},[t,s.connection]),i.useEffect(()=>{if(Se===null||!Se.queued||n===null||d)return;let u=!1;return t.agentRootStatus().then(h=>{u||(typeof h?.agentRoot=="string"&&h.agentRoot!==""&&Ke(h.agentRoot),typeof h?.bootRoot=="string"&&h.bootRoot!==""&&yt(h.bootRoot),h?.aligned===!0&&cs(null))}).catch(()=>{}),()=>{u=!0}},[t,n,d,Se]),i.useEffect(()=>{if(!re)return;Ve(null);let u=!1;return t.sessions().then(h=>{u||Ve(h)}).catch(h=>{u||(fe(!1),I(`⚠️ 会话列表加载失败:${h instanceof Error?h.message:String(h)}`))}),()=>{u=!0}},[t,re,I,ps]),i.useEffect(()=>{if(!re)return;Ot(null);let u=!1;return t.sessionTrashList().then(h=>{u||Ot(h)}).catch(()=>{}),()=>{u=!0}},[t,re,Be]);const[fs,ba]=i.useState(null),[ya,Na]=i.useState(null);i.useEffect(()=>{const u=n?.sessionId;if(u===void 0)return;let h=!1;return t.sessions().then(C=>{if(h)return;const B=C.find(Z=>Z.id===u);ba(B!==void 0&&B.name!==void 0&&B.name!==""?B.name:null),h||is(C),h||Na(C)}).catch(()=>{h||ba(null),h||is(null),h||Na([])}),()=>{h=!0}},[t,n?.sessionId,ps]),i.useEffect(()=>{let u=!1;return t.schedulesList().then(h=>{u||rs(h)}).catch(()=>{u||rs(null)}),()=>{u=!0}},[t,n?.sessionId,Js,ps]);const kt=i.useCallback(u=>{I(`⚠️ 定时任务操作没成功:${u instanceof Error?u.message:String(u)}`)},[I]),qi=i.useCallback((u,h)=>{t.schedulesSetEnabled(u,h).then(C=>{I(C.message),_t(B=>B+1)},kt)},[t,I,kt]),Gi=i.useCallback(u=>{t.schedulesRemove(u).then(h=>{I(h.message),_t(C=>C+1)},kt)},[t,I,kt]),Vi=i.useCallback((u,h)=>{t.schedulesRunNow(u,h?{resetBreaker:!0}:void 0).then(C=>{I(C.message),_t(B=>B+1)},kt)},[t,I,kt]),Qe=i.useMemo(()=>dd(a.history,S.filter(u=>u.epoch===a.historyEpoch)),[a.history,S,a.historyEpoch]),ka=i.useRef(null),Yi=i.useMemo(()=>{const u=new Set((n?.live.busyTools??[]).filter(C=>C.name==="edit"||C.name==="write_file").map(C=>C.summary)),h=ka.current;return h!==null&&h.size===u.size&&[...u].every(C=>h.has(C))?h:(ka.current=u,u)},[n?.live.busyTools]),sn=o.armedEdit,[Xi,wa]=i.useState(0),Bt=o.forkBadges,nn=o.forkEcho,xs=i.useRef(null);xs.current=sn;const Sa=i.useRef(null);i.useEffect(()=>{const u=Sa.current;u!==null&&u.key===a.key&&u.epoch!==a.historyEpoch&&(r.setArmedEdit(a.key,null),r.setForkBadges(a.key,new Set),wa(h=>h+1)),Sa.current={key:a.key,epoch:a.historyEpoch}},[a.key,a.historyEpoch,r]);const Ca=i.useRef(null);i.useEffect(()=>{const u=Ca.current;u!==null&&u.key===a.key&&u.epoch!==a.historyEpoch&&r.filterNotes(a.key,h=>h.epoch===a.historyEpoch),Ca.current={key:a.key,epoch:a.historyEpoch}},[a.key,a.historyEpoch,r]),i.useEffect(()=>{if(nn!==null)for(let u=Qe.length-1;u>=0;u-=1){const h=Qe[u];if(h===void 0||h.kind!=="user")continue;if(h.text!==nn)return;const C=Tt(h,u);r.setForkBadges(a.key,Bt.has(C)?Bt:new Set([...Bt,C])),r.setForkEcho(a.key,null);return}},[Qe,nn,a.key,r,Bt]);const vs=i.useCallback(u=>{if(!m){I("⚠️ 岔开仅支持主车道(当前在副车道视图)");return}if(c){I("⚠️ 运行中无法岔开(任务进行中)");return}t.edit(u).then(h=>{if(h===null){I(`无法从第 ${u} 轮岔开——没有这条消息`);return}D(C=>({text:h,nonce:(C?.nonce??0)+1})),r.setArmedEdit(p.current.key,{n:u})}).catch(h=>I(`⚠️ 岔开失败:${h instanceof Error?h.message:String(h)}`))},[c,t,I,m]),Ea=i.useRef(vs);Ea.current=vs;const Ji=i.useCallback(u=>{Ea.current(u)},[]),Qi=i.useCallback(()=>{const u=xs.current;t.disarmEdit().then(()=>{r.setArmedEdit(p.current.key,null)}).catch(h=>{I(`⚠️ 解除岔开失败:${h instanceof Error?h.message:String(h)}——下次发送仍将${u!==null?`从第 ${u.n} 轮`:""}开分支`)})},[t,I]),an=i.useCallback(u=>{xs.current!==null&&(xs.current=null,g.current.setArmedEdit(p.current.key,null),g.current.setForkEcho(p.current.key,u),wa(h=>h+1))},[]),ln=i.useMemo(()=>Mp(a.history),[a.history]),rn=i.useMemo(()=>Fp(a.history),[a.history]),on=iu({client:t,sessionId:a.sessionId,history:a.history,historyEpoch:a.historyEpoch}),{line:$a,morning:cn,awaiting:Zi}=Jd(t,n?.sessionId,s.historyEpoch),Ra=tu(t,Zi),eo=Ra.names,to=Ra.set,[dn,so]=i.useState(uu),Ma=i.useRef(dn),Ta=i.useRef(null);i.useEffect(()=>{const u=n?.model;if(u==null||u.label===""||u.provider===void 0||u.provider==="")return;const h={provider:u.provider,model:u.label},C=Ta.current;if(C!==null&&C.provider===h.provider&&C.model===h.model)return;Ta.current=h;const B=hu(mu(Ma.current,h));Ma.current=B,so(B)},[n?.model?.label,n?.model?.provider]);const Da=i.useRef(-1),Aa=i.useRef(""),Kt=i.useRef(0),gs=i.useRef(new Set),[no,Oa]=i.useState(0);i.useEffect(()=>{const u=a.history.filter(ad);if(Aa.current!==a.key||Da.current!==a.historyEpoch){Aa.current=a.key,Da.current=a.historyEpoch,Kt.current=u.length;return}if(u.length>Kt.current){for(const h of u.slice(Kt.current))h.summary!==""&&gs.current.add(h.summary);Oa(h=>h+1),Ge(h=>h+1)}Kt.current=Math.max(Kt.current,u.length)},[a.history,a.historyEpoch,a.key]);const Ia=i.useRef(null);i.useEffect(()=>{const u=Ia.current??(Ia.current={at:a.historyEpoch,changes:0});u.at!==a.historyEpoch&&(u.at=a.historyEpoch,u.changes+=1,u.changes>1&&Ge(h=>h+1))},[a.historyEpoch]);const un=i.useCallback(()=>{gs.current.size!==0&&(gs.current.clear(),Oa(u=>u+1))},[]),hn=V||(n?.pendingPermission??null)!==null||R!==null||$,La=i.useRef({hidden:!1,mode:"advanced",session:null});i.useEffect(()=>{const u=La.current,h=u.hidden&&!hn,C=u.mode!==T,B=u.session!==a.sessionId;if(h&&B){Ft.current="";for(const Z of it.current)Ls(Z);it.current=[],mt.current=[]}else(h||C)&&Ft.current.trim()!==""&&ms(Z=>({text:Ft.current,nonce:(Z?.nonce??0)+1})),(h||C)&&it.current.length>0&&Zs(Z=>({drafts:it.current,nonce:(Z?.nonce??0)+1})),(h||C)&&mt.current.length>0&&en(Z=>({drafts:mt.current,nonce:(Z?.nonce??0)+1}));La.current={hidden:hn,mode:T,session:a.sessionId}},[hn,T,a.sessionId]);const Pa=i.useRef(yn()),_a=i.useRef(kn());i.useEffect(()=>{const u=()=>{const h=yn();h&&!Pa.current&&me(!0),Pa.current=h;const C=kn();C&&!_a.current&&L(!0),_a.current=C,Ee(B=>{const Z=ot(B);return Z!==B?Z:B}),Re(B=>{const Z=ot(B);return Z!==B?Z:B})};return window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)},[]),i.useEffect(()=>{try{window.localStorage.setItem(Dr,JSON.stringify({treeW:he,chatW:ve,leftCollapsed:ee,centerCollapsed:E,rightCollapsed:ye,buddyCollapsed:nt,tabs:x.map(({path:u,isDir:h})=>({path:u,isDir:h})),activeTabIndex:k}))}catch{}},[he,ve,ee,E,ye,nt,x,k]);const js=x[k]??null,bs=(u,h)=>{const C=x.findIndex(Z=>Z.path===u);if(C>=0){w(C);return}if(x.length>=zn){const Z=k===0?1:0,be=x[Z];if(be!==void 0){const ke=x.filter((we,Ce)=>Ce!==Z).concat({path:u,name:xt(u),isDir:h});b(ke),w(ke.length-1),I(`标签已满(${zn} 个):已关闭「${be.name}」`);return}}const B=[...x,{path:u,name:xt(u),isDir:h}];b(B),w(B.length-1)},ys=u=>{const h=x.filter((C,B)=>B!==u);b(h),w(C=>h.length===0?0:u<C?C-1:u===C?Math.min(C,h.length-1):C)},ao=()=>{js!==null&&ys(k)},lo=(u,h)=>{bs(u,h===!0)},Fa=i.useRef(()=>{});Fa.current=u=>{const h=x.findIndex(C=>C.path===u);h>=0&&ys(h)};const ro=i.useCallback(u=>{Fa.current(u)},[]),za=i.useRef(()=>{});za.current=u=>{bs(u,!1)};const io=i.useCallback(u=>{za.current(u)},[]),oo=i.useCallback(u=>{_(h=>({path:u,nonce:(h?.nonce??0)+1}))},[]),co=i.useCallback(()=>{_(null)},[]),uo=i.useCallback(u=>{ie.current=u},[]),ho=i.useCallback(()=>ie.current,[]),mo=u=>{J(!1),bs(u,!1)};i.useEffect(()=>{const u=h=>{if(!(!h.ctrlKey||h.metaKey)){if(h.key==="w"||h.key==="W"){if(x.length===0)return;h.preventDefault(),ys(k);return}if(h.key==="Tab"){if(x.length<2)return;h.preventDefault(),w(C=>(C+(h.shiftKey?-1:1)+x.length)%x.length);return}if(/^[1-9]$/.test(h.key)){const C=Number(h.key)-1;if(C>=x.length)return;h.preventDefault(),w(C)}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[x,k]),i.useEffect(()=>{const u=h=>{if(h.altKey)return;const C=h.target;if(!(C instanceof HTMLInputElement&&C.classList.contains("search-input")&&h.ctrlKey&&(h.key==="p"||h.key==="P"))){if(h.ctrlKey&&(h.key==="p"||h.key==="P")){h.preventDefault(),J(B=>!B);return}if((h.metaKey||h.ctrlKey)&&h.key===","){h.preventDefault(),H(!0);return}if(h.ctrlKey&&(h.key==="b"||h.key==="B")){h.preventDefault(),me(B=>!B);return}if(h.ctrlKey&&h.shiftKey&&h.code==="Backslash"){h.preventDefault(),Me();return}h.ctrlKey&&!h.shiftKey&&h.key==="\\"&&(h.preventDefault(),G(B=>!B))}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[Me]);const Ba=i.useCallback(u=>h=>{h.preventDefault();const C=h.clientX,B=u==="left"?he:ve,Z=u==="left"?Ee:Re,be=we=>{const Ce=we.clientX-C;Z(ot(u==="left"?B+Ce:B-Ce))},ke=()=>{window.removeEventListener("mousemove",be),window.removeEventListener("mouseup",ke)};window.addEventListener("mousemove",be),window.addEventListener("mouseup",ke)},[he,ve]),Ka=i.useCallback(u=>()=>{u==="left"?Ee(fl):Re(xl)},[]),Wa=i.useCallback(u=>h=>{const C=u==="left"?Ee:Re;if(h.key==="ArrowLeft"||h.key==="ArrowRight"){h.preventDefault();const B=(h.key==="ArrowRight"?1:-1)*(u==="left"?1:-1);C(ot((u==="left"?he:ve)+16*B));return}if(h.key==="Home"){h.preventDefault(),C(ot(As));return}h.key==="End"&&(h.preventDefault(),C(ot(Os())))},[he,ve]),{onScroll:po,jump:fo,show:xo}=Mr(le);cf();const at=i.useCallback((u,h,C)=>{const B=h!==void 0&&h.length>0,Z=C!==void 0&&C.length>0;R!==null&&j(null);const be=yu(u);if(be.kind==="noop"&&!B&&!Z)return;const ke=be.kind==="pass"?be:{kind:"pass",text:""};if((B||Z)&&be.kind!=="pass"&&be.kind!=="noop")return I(`⚠️ ${u.trim().split(/\s+/)[0]??"该命令"} 是界面命令,不支持附加图片或文件 —— 未发送`),!1;if(be.kind==="exit"){t.close();return}if(be.kind==="help"){I(bu(v,{mode:Pn(n?.mode??"workspace")}));return}if(be.kind==="clear"){if(c){I("⚠️ 运行中无法 /clear(任务进行中)");return}y(!0);return}if(be.kind==="resume"){if(c&&!a.capable){I("⚠️ 运行中无法 /resume(任务进行中)");return}t.sessions().then(we=>{if(we.length===0){I("(暂无可恢复的会话)");return}A("resume"),j(we)}).catch(we=>I(`⚠️ /resume 失败:${we instanceof Error?we.message:String(we)}`));return}if(be.kind==="edit"){if(c){I("⚠️ 运行中无法 /edit(任务进行中)");return}vs(be.n);return}if(D(null),!B&&!Z){const we=()=>{ms(Ce=>({text:ke.text,nonce:(Ce?.nonce??0)+1}))};t.submit(ke.text,a.sid===null?void 0:{sid:a.sid}).then(Ce=>{Ce==="frontend"?I(hl):Ce==="notice"||Ce==="noop"?we():an(ke.text)}).catch(Ce=>{I(`⚠️ submit 失败:${Ce instanceof Error?Ce.message:String(Ce)}`),we()});return}return(async()=>{let we,Ce;try{we=B?(await t.attachmentSave(h)).map(Te=>({kind:"image",ref:Te})):void 0}catch(Te){return I(`⚠️ 图片发送失败:${ih(Te instanceof Error?Te.message:String(Te))}`),!1}try{Ce=Z?await t.fileSave(C):void 0}catch(Te){return I(`⚠️ 文件发送失败:${dh(Te instanceof Error?Te.message:String(Te))}`),!1}try{const Te=await t.submit(ke.text,{...we!==void 0&&we.length>0?{images:we}:{},...Ce!==void 0&&Ce.length>0?{files:Ce}:{},...a.sid!==null?{sid:a.sid}:{}});Te==="frontend"&&I(hl);const il=Te==="started"||Te==="steered";return il&&an(ke.text),il}catch(Te){return I(`⚠️ submit 失败:${Te instanceof Error?Te.message:String(Te)}`),!1}})()},[t,v,c,I,R,n?.mode,vs,an,a.capable,a.sid]),Ua=i.useCallback(()=>{t.interrupt(a.sid===null?void 0:a.sid).catch(()=>{})},[t,a.sid]),Ha=i.useRef(at);Ha.current=at;const vo=i.useCallback(u=>{Ha.current(u)},[]),[Ns,mn]=i.useState([]),pn=i.useRef(!1),go=i.useCallback(u=>{mn(h=>[...h,u])},[]),jo=i.useCallback(u=>{mn(h=>h.filter((C,B)=>B!==u))},[]);i.useEffect(()=>{if(s.connection!=="connected")return;if(d){pn.current=!1;return}if(!m||Ns.length===0||pn.current)return;const u=Ns[0];u!==void 0&&(pn.current=!0,mn(h=>h.slice(1)),at(u))},[s.connection,d,m,Ns,at]);const[qa,ks]=i.useState([]),Wt=a.sessionId??void 0;i.useEffect(()=>{ks([])},[Wt]);const Ga=i.useCallback(u=>{if(Wt===void 0||Wt===""){I("⚠️ 旁问需要已连接的会话");return}const h=`sq-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;t.sideQuestion(Wt,u).then(C=>{ks(B=>[...B,{id:h,question:u,answer:C.answer,rounds:C.rounds}])}).catch(C=>{ks(B=>[...B,{id:h,question:u,answer:`⚠️ 旁问失败:${C instanceof Error?C.message:String(C)}`,rounds:0}])})},[t,Wt,I]),Va=i.useCallback(u=>{ks(h=>h.filter(C=>C.id!==u.id)),at(bm(u))},[at]),bo=i.useCallback(u=>t.answerPermission(u),[t]),Ya=i.useCallback((u,h)=>{t.recallSteer(u,h).catch(()=>{})},[t]),Xa=i.useCallback(Mc(t,I),[t,I]),yo=i.useCallback(u=>t.answerAskUser(u),[t]),Ja=i.useCallback(u=>{t.setMode(u).then(()=>I(`权限档 → ${pl(u)}`)).catch(h=>I(`⚠️ 权限档切换失败:${h instanceof Error?h.message:String(h)}`))},[t,I]),No=i.useCallback(u=>{D(h=>({text:u,nonce:(h?.nonce??0)+1}))},[]),Qa=i.useCallback(()=>{D(null),ms(null)},[]),Za=i.useCallback(()=>{const u=Ec(n?.mode??"workspace");t.setMode(u).then(()=>I(`权限档 → ${pl(u)}`)).catch(h=>I(`⚠️ setMode 失败:${h instanceof Error?h.message:String(h)}`))},[t,I,n?.mode]),ws=i.useCallback(u=>{t.panelRootSet(u).then(h=>{const C=typeof h?.root=="string"&&h.root!==""?h.root:u;xe.current=!0,ue(C),b([]),w(0),ie.current=[],un(),t.agentRootSwitch(C).then(B=>{Ke(C),I(B?.applied===!1?`工作区切换已排队——当前任务结束后生效 → ${C}`:`工作区已切换(agent 工作目录已跟随)→ ${C}`)},B=>{I(`⚠️ agent 工作目录切换失败:${B instanceof Error?B.message:String(B)}——文件面板已切到 ${C}`)})},h=>{I(`⚠️ 切换失败:${h instanceof Error?h.message:String(h)}`)})},[t,I,un]),el=ws,fn=i.useCallback(()=>{if(ea()===void 0){I("浏览器模式无法选择目录 — 请通过命令行启动 wudao ui --dir <path>");return}Nr().then(u=>{u!==null&&ws(u)})},[I,ws]),Ss=i.useRef(!1),tl=i.useCallback(()=>{const u=Se;u===null||Ss.current||(Ss.current=!0,t.agentRootSwitch(u.panelRoot).then(h=>{Ss.current=!1,h?.applied===!0?(Ke(u.panelRoot),cs(null)):cs({...u,queued:!0})},h=>{Ss.current=!1,I(`⚠️ 切换 agent 工作目录失败:${h instanceof Error?h.message:String(h)}`)}))},[t,I,Se]),sl=i.useCallback(()=>{if(Se===null)return;const u=Se.agentRoot;cs(null),I(u!==""?`agent 工作目录保持不变 → ${xt(u)} (${u})`:"agent 工作目录保持不变")},[I,Se]);i.useEffect(()=>{document.title="悟道Harness"},[n?.sessionId]);const nl=i.useMemo(()=>{if(m&&fs!==null)return fs;for(const u of Qe){if(u.kind!=="user")continue;const h=u.text,C=h.indexOf(`
339
+ `),B=(C===-1?h:h.slice(0,C)).trim();if(B!=="")return B}return"悟道Harness"},[m,fs,Qe]),ko=i.useMemo(()=>new Set(Qe.flatMap(u=>u.kind==="tool"?[u.name]:[])).size,[Qe]),al=n!==null&&n.ctxTokens!==null&&n.ctxTokens.used!==null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"ok",children:"✓"}),` ${ko} tools`]}):null;Gd(d,n?.sessionId??null);const xn=i.useCallback(()=>{se.current=!0;const u=zs(),h=u==="dark"?"light":"dark";vt(h),t.settingsSet("ui.theme",h).then(()=>I(`主题 → ${h==="dark"?"暗色":"浅色"}`)).catch(C=>{vt(u),I(`⚠️ 主题切换未保存:${C instanceof Error?C.message:String(C)}`)})},[t,I]);i.useEffect(()=>{const u=h=>{const C=h.detail;C==="new-chat"?ne(!0):C==="settings"?H(!0):C==="toggle-left"?me(B=>!B):C==="toggle-theme"&&xn()};return window.addEventListener("wudao:menu-action",u),()=>window.removeEventListener("wudao:menu-action",u)},[xn]);const wt=i.useCallback(u=>{const h=(B,Z)=>{if(!B.ok){if(Z?.(),B.reason==="occupied"){I(`⚠️ 会话正被另一个 wudao 进程(#${B.holderPid})占用——请关闭旧窗口,或稍候重试`);return}I("(会话不存在 —— 可能已被删除)")}},C=B=>I(`⚠️ resume 失败:${B instanceof Error?B.message:String(B)}`);if(a.capable){j(null);const B=xd(n,s.lanes,u);if(B.kind==="view-main"){l(null);return}if(B.kind==="view-lane"){l(B.laneId);return}const Z=B.laneId;l(Z);const be=()=>l(ke=>ke===Z?null:ke);t.resume(u,Z).then(ke=>h(ke,be)).catch(ke=>{be(),C(ke)});return}if(c){I("⚠️ 运行中无法 切换会话(任务进行中)");return}j(null),t.resume(u).then(h,C)},[a.capable,n,s.lanes,c,t,I,l]),wo=i.useMemo(()=>fd(n,s.lanes),[n,s.lanes]),Cs=i.useMemo(()=>{const u=[...ya??[]].filter(h=>h.lane!=="pet");return u.sort((h,C)=>h.mtime<C.mtime?1:h.mtime>C.mtime?-1:0),u[0]??null},[ya]),ll=i.useCallback(u=>{j(null),t.resumeFork(u).then(h=>{if(h.ok){l(null),I("已基于这段对话开了新篇——直接输入你的问题,原对话保持不变"),ms(C=>({text:Ft.current,nonce:(C?.nonce??0)+1}));return}if(h.reason==="busy"){I("⚠️ 任务进行中——等它跑完再追问");return}if(h.reason==="occupied"){I(`⚠️ 会话正被另一个 wudao 进程(#${h.holderPid})占用——请关闭旧窗口,或稍候重试`);return}I("(会话不存在 —— 可能已被删除)")},h=>I(`⚠️ 追问失败:${h instanceof Error?h.message:String(h)}`))},[t,I,l]),So=i.useCallback(()=>{Cs!==null&&wt(Cs.id)},[Cs,wt]),Co=i.useCallback(()=>{if(c&&!a.capable){I("⚠️ 运行中无法 切换会话(任务进行中)");return}t.sessions().then(u=>{if(u.length===0){I("(暂无可追问的会话)");return}A("followup"),j(u)}).catch(u=>I(`⚠️ 打开会话列表失败:${u instanceof Error?u.message:String(u)}`))},[c,a.capable,t,I]),Es=i.useCallback((u=!1)=>{const h=u?"已开启新会话":"历史已清空",C=u?"原会话已保留在列表,随时点开切回":"已保存的历史仍在磁盘,可 /resume 恢复",B=Z=>{t.clearView(),r.filterNotes(a.key,()=>!1),I(Z)};if(s.connection!=="connected"){if(!m){I(`(${h} —— 离线且副车道无法本地清空;${C})`);return}B(`(${h} —— 离线:仅视图;${C})`);return}t.submit("/clear",a.sid===null?void 0:{sid:a.sid}).then(Z=>{Z==="cleared"?I(`(${h} —— 全新会话;${C})`):Z==="frontend"&&B(`(${h} —— 仅重置视图;${C})`)},Z=>{B(`(${h} —— /clear 未被接受: ${Z instanceof Error?Z.message:String(Z)};仅视图)`)})},[t,I,s.connection,r,a.key,a.sid,m]),Eo=i.useCallback(()=>{if(c&&a.capable){const u=`wudao-${Date.now().toString(36)}-${Math.random().toString(16).slice(2,6)}`,h=`L-${u}`;l(h),t.resume(u,h).catch(C=>{l(null),I(`⚠️ 新会话创建失败:${C instanceof Error?C.message:String(C)}`)});return}if(c&&!a.capable){I("⚠️ 任务进行中,稍后再开新对话");return}Es(!0)},[c,I,Es,a.capable,t,l]),$o=i.useMemo(()=>({client:t,sessionId:a.sessionId??""}),[t,a.sessionId]),Ro=m||n===null?n:{...n,busy:a.busy,planBoard:null,queued:[],live:{reasoning:"",answer:"",busyTools:[]}};if(s.connection!=="connected"&&s.connection!=="reconnecting"&&s.connection!=="gave-up"){const u=s.connection;return e.jsx("div",{className:"app",children:e.jsx("div",{className:"connect-shell",children:e.jsxs("div",{className:"connect-card",role:u==="auth-failed"?"alert":"status",children:[e.jsx("div",{className:"logo","aria-hidden":!0}),u==="auth-failed"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"connect-title",children:"认证失败"}),e.jsx("div",{className:"connect-msg err",children:"Token 无效或已过期 —— 请重新打开启动时打印的 URL 完成认证"})]}):u==="closed"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"connect-title",children:"连接已断开"}),e.jsx("div",{className:"connect-msg",children:"若刷新后仍连不上,请从 wudao 桌面应用重新打开会话(旧地址可能已失效)。"}),e.jsx("button",{type:"button",className:"wudao action",onClick:()=>window.location.reload(),children:"刷新页面重连"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"connect-row",children:[e.jsx(Gs,{className:"spin"}),e.jsx("span",{className:"connect-title",children:"正在连接 wudao 服务…"})]}),e.jsx("div",{className:"connect-msg",children:"若长时间停留在此,请重新打开 wudao 桌面应用。"})]}),e.jsx("div",{className:"connect-meta",children:`wudao ui · ${u}${s.lastClose!==null?` · close ${s.lastClose.code}`:""}`})]})})})}const St=n?.pendingPermission??null,$s=n?.pendingAskUser??null,Ut=s.connection==="connected",rl=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"chat",ref:le,onScroll:po,children:[m?e.jsx(Kh,{client:t,refreshTick:Xi}):null,on.payload!==null?e.jsx(du,{payload:on.payload,now:Date.now(),onClose:on.onDismiss}):null,m&&cn!==null?e.jsx(eu,{line:cn}):null,m&&cn===null&&$a!==null?e.jsx(Qd,{line:$a}):null,e.jsx(Hh,{client:t,memorySignature:n?.memorySignature}),Ki(Qe)?e.jsx(Fi,{awaiting:eo,onOpenSession:wt,...Cs!==null?{onResumeLatest:So,onAskFromHistory:Co}:{}}):null,e.jsx(zh,{history:Qe,onAction:vo,onOpenFile:io,onForkTurn:Ji,forkBadgeKeys:Bt,runningEditPaths:Yi}),m&&n?.planBoard!=null?e.jsx(Oi,{plan:n.planBoard,busy:c,onSubmit:at}):null,n!==null&&m&&c&&St===null?e.jsx(th,{live:n.live,queued:n.queued,onRecall:Ya,onDetachTool:Xa}):null]}),e.jsx(Tr,{show:xo,onJump:fo}),sn!==null?e.jsx(Bh,{n:sn.n,onCancel:Qi}):null,Se!==null?e.jsx(Ai,{panelRoot:Se.panelRoot,agentRoot:Se.agentRoot,queued:Se.queued,onSwitch:tl,onKeep:sl}):null,St!==null?e.jsx(km,{ask:St,onChoose:u=>{t.answerPermission(u.allow,u.reason,u.scope).catch(()=>{})}}):null,St===null&&$s!==null?e.jsx(Di,{inline:!0,question:$s.question,options:$s.options,onAnswer:u=>{t.answerAskUser(u).catch(()=>{})},onDismiss:()=>{t.answerAskUser().catch(()=>{})}}):null,St===null&&R===null&&!$?e.jsxs(e.Fragment,{children:[e.jsx(Ri,{qas:qa,onPromote:Va}),e.jsx($i,{busy:c,mode:n?.mode??"workspace",commands:v,connected:Ut,onSubmit:at,onInterrupt:Ua,onShield:Ja,onCycleMode:Za,onDraftApplied:Qa,onMentionApplied:co,onBufferChange:ha,onImagesChange:ma,onImageSeedApplied:pa,onFilesChange:fa,onFileSeedApplied:xa,idlePlaceholder:Q,slashChip:!0,modelLabel:n?.model?.label??null,modelProvider:n?.model?.provider,modelChoices:n?.model?.choices,modelRecent:dn,onPickModel:va,onPersistModelDefault:ga,effort:M?.current?.effort??null,efforts:M!=null?[...M.efforts??[]]:void 0,onPickEffort:u=>{t.submit(`/effort ${u}`).then(()=>{I(`effort → ${u} — 下一轮生效`),Nt()}).catch(h=>I(`⚠️ /effort 失败:${h instanceof Error?h.message:String(h)}`))},effortProviderLabel:Tl(M,n?.model?.provider),onPersistEffortDefault:ja,...T==="buddy"?{controlsLead:e.jsx(Bi,{client:t,root:te,bootRoot:Oe!==""?Oe:void 0,connected:Ut,onPick:el,onOpenOther:fn,labelName:oe!==""?xt(oe):void 0,labelPath:oe!==""?oe:void 0})}:{},...q!==null?{draft:q}:hs!==null?{draft:hs}:{},...ds!==null?{imageSeed:ds}:{},...us!==null?{fileSeed:us}:{},...$e!==null?{mention:$e}:{},onSideAsk:Ga})]}):null]});return e.jsx(mi.Provider,{value:$o,children:e.jsxs("div",{className:"app",children:[e.jsxs("div",{className:"topbar","data-tauri-drag-region":"",onMouseDown:u=>{if(u.target.closest("button")===null){if(u.detail===2){ec();return}tc()}},children:[e.jsxs("span",{className:"sp","data-tauri-drag-region":"",children:[e.jsx("span",{className:"tb-name","data-tauri-drag-region":"",title:nl,children:nl}),T!=="simple"&&al!==null?e.jsx("span",{className:"tb-run","data-tauri-drag-region":"",children:al}):null]}),T!=="buddy"?e.jsx("button",{type:"button",className:"icobtn new-chat","aria-label":"新对话",title:"新对话(清空当前会话)",onClick:()=>{if(c){I("⚠️ 运行中无法 /clear(任务进行中)");return}ne(!0)},children:e.jsx(xr,{})}):null,ln.fileCount>0?e.jsx("button",{type:"button",className:"tb-changes","aria-label":"查看会话改动",title:"本会话改了哪些文件",onClick:()=>It(!0),children:`改动 ${ln.fileCount} 文件`}):null,rn.totalSteps>0?e.jsx("button",{type:"button",className:"tb-changes tb-computer","aria-label":"查看电脑操作",title:"本会话在电脑上做了什么",onClick:()=>Lt(!0),children:`电脑操作 ${rn.totalSteps} 步`}):null,st!==null&&st.length>0?e.jsx("button",{type:"button",className:"tb-changes tb-sched","aria-label":"查看定时任务",title:"定时任务与提醒",onClick:()=>os(!0),children:`定时 ${st.length}`}):null,T!=="buddy"?e.jsx("button",{type:"button",className:"icobtn sessions","aria-label":"会话列表",title:"切换会话",onClick:()=>{if(c&&!a.capable){I("⚠️ 运行中无法 切换会话(任务进行中)");return}fe(!0)},children:e.jsx(Yo,{})}):null,T==="advanced"?e.jsx("button",{type:"button",className:"icobtn","aria-pressed":qe,"aria-label":"审查专注",title:qe?"退出审查专注 (Ctrl+Shift+\\)":"审查专注 (Ctrl+Shift+\\)",onClick:Me,children:e.jsx(Xo,{})}):null,e.jsx("button",{type:"button",className:"icobtn","aria-label":"切换主题",title:"切换主题(浅色/暗色)",onClick:xn,children:e.jsx(Jo,{})}),e.jsx("button",{type:"button",className:"icobtn","aria-label":"监控",title:"监控(探针仪表盘)",onClick:()=>W(!0),children:e.jsx(Qo,{})}),e.jsx("button",{type:"button",className:"icobtn","aria-label":"设置",title:"设置",onClick:()=>H(!0),children:e.jsx(Zo,{})})]}),z!=="show"&&M!==null&&!Cr(M.providers)?e.jsxs("div",{className:"no-key-banner",role:"status",children:["未配置任何模型 Key —— 当前为只读浏览模式",e.jsx("button",{type:"button",className:"wudao action",onClick:()=>F("show"),children:"去配置"})]}):null,s.connection==="reconnecting"?e.jsxs("div",{className:"banner quiet",role:"status",children:["连接断开",s.lastClose!==null?`(close ${s.lastClose.code})`:""," — 正在重连",s.reconnectAttempt>1?`(第 ${s.reconnectAttempt}/${Ln} 次)`:"","… 重连后自动回放历史"]}):null,s.connection==="gave-up"?e.jsxs("div",{className:"banner",role:"alert",children:[`连接已断开 — 已连续重连 ${Ln} 次未成功。在 wudao 桌面应用窗口里遇到时,重启应用即可;在浏览器标签里,请从 wudao 桌面应用重新打开会话(这个旧页面的地址可能已失效)。`,e.jsx("button",{type:"button",className:"wudao action",onClick:()=>t.reconnect(),children:"重连"})]}):null,X?e.jsx(xp,{client:t,status:n,connected:Ut,onClose:()=>W(!1)}):null,V?e.jsx(lp,{client:t,status:n,pendingAsk:St!==null,onClose:()=>{H(!1),Nt()},onModeApplied:u=>{U(u),I(`已切换到${u==="simple"?"简洁模式":u==="buddy"?"Buddy 模式":"高级模式"} — 重载后完全生效`)},onAccentPicked:()=>{de.current=!0},language:M?.language??null}):T==="simple"?e.jsx(dp,{status:Ro,history:Qe,connected:Ut,commands:v,onSubmit:at,onSideAsk:Ga,sideQas:qa,onPromoteSideQa:Va,onInterrupt:Ua,onCycleMode:Za,onAnswerPermission:bo,onRecallSteer:Ya,onDetachTool:Xa,pendingAsk:$s,onAnswerAskUser:yo,onShield:Ja,notify:I,parked:Ns,onPark:go,onDropParked:jo,onDraftApplied:Qa,onBufferChange:ha,onImagesChange:ma,onImageSeedApplied:pa,onFilesChange:fa,onFileSeedApplied:xa,modelLabel:n?.model?.label??null,modelProvider:n?.model?.provider,modelChoices:n?.model?.choices,modelRecent:dn,onPickModel:va,onPersistModelDefault:ga,effort:M?.current?.effort??null,efforts:M!=null?[...M.efforts??[]]:void 0,onPickEffort:u=>{t.submit(`/effort ${u}`).then(()=>{I(`effort → ${u} — 下一轮生效`),Nt()}).catch(h=>I(`⚠️ /effort 失败:${h instanceof Error?h.message:String(h)}`))},effortProviderLabel:Tl(M,n?.model?.provider),onPersistEffortDefault:ja,workspaceRoot:te,bootRoot:Oe!==""?Oe:void 0,onSwitchWorkspace:ws,onOpenOtherWorkspace:fn,rootCard:Se,onAgentRootSwitch:tl,onAgentRootKeep:sl,fileOpsClient:t,...q!==null?{draft:q}:hs!==null?{draft:hs}:{},...ds!==null?{imageSeed:ds}:{},...us!==null?{fileSeed:us}:{}}):T==="buddy"?e.jsxs("div",{className:"buddy",style:{"--buddy-w":nt?"0px":`${sd}px`},children:[e.jsx("div",{className:"buddy-cell buddy-left",children:nt?null:e.jsx(Bd,{client:t,activeSessionId:a.sessionId,onResume:wt,onNewChat:Eo,onOpenSearch:()=>{if(c&&!a.capable){I("⚠️ 运行中无法 切换会话(任务进行中)");return}fe(!0)},onRenameSession:Wi,sessionsEpoch:ps,awaitingIds:to,busySessionIds:wo,onFollowUp:ll})}),e.jsx("div",{className:"buddy-cell buddy-main",children:rl}),e.jsx("button",{type:"button",className:"ide-toggle buddy-toggle","aria-label":nt?"展开会话列表":"折叠会话列表",title:nt?"展开会话列表":"折叠会话列表",onClick:()=>L(u=>!u),children:nt?"▸":"◂"})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"ide",style:{"--tree-w":ee?"0px":`${he}px`,"--mid-w":E?"0px":"1fr","--chat-w":ye?"0px":`${ve}px`},children:[e.jsx("div",{className:"ide-cell ide-left",children:z!=="checking"?e.jsx(Np,{client:t,workspaceRoot:te,bootRoot:Oe!==""?Oe:void 0,selectedPath:js?.path??null,onSelect:lo,onAtMention:oo,refreshKey:Le,onSwitchWorkspace:el,onOpenOtherWorkspace:fn,onPathsChange:uo,modifiedPaths:gs.current,modifiedKey:no,onManualRefresh:un},te):null}),e.jsxs("div",{className:"ide-cell ide-center",children:[e.jsxs("div",{className:"tabbar",role:"tablist",children:[x.length===0?e.jsx("span",{className:"tab-empty",title:"从左侧选择文件打开标签",children:"+"}):x.map((u,h)=>e.jsxs("div",{className:`tab${h===k?" active":""}`,"data-path":u.path,role:"tab","aria-selected":h===k,title:u.path,tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),w(h))},onClick:()=>w(h),children:[u.isDir?e.jsx(ts,{size:12}):e.jsx(gr,{size:12}),e.jsx("span",{className:"tname",children:u.name}),e.jsx("button",{type:"button",className:"tclose","aria-label":`关闭 ${u.name}`,title:`关闭 ${u.name}`,onClick:C=>{C.stopPropagation(),ys(h)},children:e.jsx(es,{size:12})})]},u.path)),E?null:e.jsx("button",{type:"button",className:"tabbar-collapse","aria-label":"折叠中栏",title:"折叠中栏",onClick:()=>G(!0),children:"◂"})]}),e.jsx(Rp,{client:t,path:js?.path??null,isDir:js?.isDir??!1,onOpenPath:bs,onReadFailed:ro,refreshEpoch:a.historyEpoch,onClose:ao,onPrefill:No})]}),e.jsx("div",{className:"ide-cell ide-right",children:rl}),e.jsx("button",{type:"button",className:"ide-toggle","data-side":"left","aria-label":ee?"展开文件树":"折叠文件树",title:ee?"展开文件树":"折叠文件树",onClick:()=>me(u=>!u),children:ee?"▸":"◂"}),e.jsx("button",{type:"button",className:"ide-toggle","data-side":"right","aria-label":ye?"展开会话栏":"折叠会话栏",title:ye?"展开会话栏":"折叠会话栏",onClick:()=>Ne(u=>!u),children:ye?"◂":"▸"}),E?e.jsx("button",{type:"button",className:"ide-toggle","data-side":"center","aria-label":"展开中栏",title:"展开中栏",onClick:()=>G(!1),children:"▸"}):null,ee?null:e.jsx("div",{className:"ide-drag","data-side":"left",role:"separator","aria-orientation":"vertical","aria-label":"文件树宽度",title:"拖动调整宽度 · 双击重置",tabIndex:0,"aria-valuemin":As,"aria-valuemax":Os(),"aria-valuenow":he,onKeyDown:Wa("left"),onMouseDown:Ba("left"),onDoubleClick:Ka("left")}),ye?null:e.jsx("div",{className:"ide-drag","data-side":"right",role:"separator","aria-orientation":"vertical","aria-label":"会话栏宽度",title:"拖动调整宽度 · 双击重置",tabIndex:0,"aria-valuemin":As,"aria-valuemax":Os(),"aria-valuenow":ve,onKeyDown:Wa("right"),onMouseDown:Ba("right"),onDoubleClick:Ka("right")})]})}),T!=="simple"?e.jsx(Zh,{status:n,ctxInfo:()=>t.ctxInfo(),stale:!Ut,sessionName:fs??void 0,buddy:T==="buddy",workspaceName:oe!==""?xt(oe):void 0,workspacePath:oe!==""?oe:void 0}):null,Y?e.jsx(hd,{getAllKnownPaths:ho,onOpenPath:mo,onClose:()=>J(!1)}):null,re?e.jsx(Wd,{rows:je,onPick:u=>{fe(!1),wt(u)},onClose:()=>fe(!1),onSearch:u=>t.sessionSearch(u),activeId:a.sessionId,onDelete:Ui,trashRows:ht,onRestore:Hi}):null,Je?e.jsx(Pp,{agg:ln,onClose:()=>It(!1),onRevert:(u,h)=>{t.fileRevert(u,h).then(C=>I(C.message),C=>I(`恢复没成功:${C instanceof Error?C.message:String(C)}`))}}):null,ls?e.jsx(Wp,{agg:rn,onClose:()=>Lt(!1)}):null,Qs&&st!==null?e.jsx(Gp,{rows:Up(st,Pt),onClose:()=>os(!1),onToggle:qi,onRemove:Gi,onRun:Vi}):null,R!==null?e.jsx(Sm,{rows:R,intent:f,onPick:f==="followup"?ll:wt,onCancel:()=>{j(null),A("resume")}}):null,$?e.jsx(Cm,{onChoose:u=>{y(!1),u?Es():I("(已取消清空)")}}):null,ge?e.jsx(qd,{onChoose:u=>{ne(!1),u&&Es()}}):null,e.jsx("div",{className:"sr-only","aria-live":"polite",role:"status",children:`${c?"生成中…":"空闲"}${S.length>0?` · ${S[S.length-1].text}`:""}`}),z==="show"&&M!==null?e.jsx(ip,{client:t,status:n,settings:M,onDone:()=>{F("done"),Nt()}}):null]})})}function uf(t,s){return pc(t,s)}function hf(t,s=mc){let n=null,a=-1/0,l=null,r=null,o=!1;const c=()=>{r=null;const d=l;l=null,d!==null&&(n=d,a=t.now(),Promise.resolve(t.emit(ol,d)).catch(()=>{}))};return{push(d){if(o)return;if(n!==null&&uf(d,n)){l=null,r!==null&&(clearTimeout(r),r=null);return}const m=a+s-t.now();if(m<=0){r!==null&&(clearTimeout(r),r=null),l=null,n=d,a=t.now(),Promise.resolve(t.emit(ol,d)).catch(()=>{});return}l=d,r===null&&(r=setTimeout(c,m))},cancel(){o=!0,l=null,r!==null&&(clearTimeout(r),r=null)}}}function mf(t,s){const n={emit:(j,f)=>fr(j,f),listen:(j,f)=>Mt(j,f),now:()=>Date.now(),submit:j=>t.submit(j),pickDirectory:()=>Nr()},a=()=>t.getSnapshot().pet!==void 0,l=j=>{if(j.startsWith("/")){Promise.resolve(n.emit(hc,{text:"精灵窗口不支持斜杠命令——直接提问,或到主窗口输入命令"})).catch(()=>{});return}t.petSubmit(j).catch(()=>{})},r=hf(n);let o=!1,c=null;const d=()=>{const j=t.getSnapshot(),f=dc(j.pet!==void 0?{status:j.pet}:j,{recentWorkspaces:c});if(f!==null){if(j.connection==="connected"){o=!0,r.push(f);return}o&&r.push(uc)}},m=t.subscribe(d);Promise.resolve(t.recentWorkspaces.call(t)).then(j=>{const f=(j.workspaces??[]).map(A=>A.path).slice(0,5);c=f.length>0?f:null,d()},()=>{});let p=null,g=null,v=null,N=!1;Promise.resolve(n.listen(sc,j=>{const f=String(j?.text??"").trim();f!==""&&(a()?l(f):n.submit(f).catch(()=>{}))})).then(j=>{N?j?.():p=j}),Promise.resolve(n.listen(nc,j=>{const f=ac(j);f!==null&&(a()?t.petAnswerPermission(f.allow,void 0,f.scope):t.answerPermission(f.allow,void 0,f.scope)).catch(()=>{})})).then(j=>{N?j?.():g=j}),Promise.resolve(n.listen(lc,j=>{const f=j?.text;if(typeof f!="string")return;const A=f.trim();A!==""&&(a()?l(A):n.submit(A).catch(()=>{}))})).then(j=>{N?j?.():v=j});let S=null;Promise.resolve(n.listen(rc,()=>{a()&&t.petHistory().then(j=>{Promise.resolve(n.emit(ic,{turns:j})).catch(()=>{})},()=>{})})).then(j=>{N?j?.():S=j});let R=null;return Promise.resolve(n.listen(oc,j=>{const f=cc(j);if(f!==null&&a())switch(f.kind){case"new-session":t.petNewSession().then(A=>{A!==null&&Promise.resolve(n.emit(yr,{archivedId:A})).catch(()=>{})},()=>{});break;case"set-model":t.petSetModel(f.provider,f.model,f.effort).catch(()=>{});break;case"set-effort":t.petSetEffort(f.effort).catch(()=>{});break;case"set-workspace":t.petSetWorkspace(f.path).catch(()=>{});break;case"pick-workspace":n.pickDirectory().then(A=>{A!==null&&t.petSetWorkspace(A).catch(()=>{})});break}})).then(j=>{N?j?.():R=j}),()=>{N=!0,m(),p?.(),g?.(),v?.(),S?.(),R?.(),r.cancel()}}const pf="tauri://close-requested",pr="main";function ff(t){return t===!0?"hide":"close"}function xf(t=window){if(typeof t!="object"||t===null)return null;const s=t.__TAURI_INTERNALS__;if(typeof s!="object"||s===null)return null;const n=s.metadata;if(typeof n!="object"||n===null)return null;const a=n.currentWindow?.label;return typeof a=="string"&&a!==""?a:null}async function vf(){const t=ea();if(!t)return!1;try{return await t("plugin:window|hide"),!0}catch{return!1}}async function gf(){const t=ea();if(!t)return!1;try{return await t("plugin:window|destroy"),!0}catch{return!1}}async function jf(t){let s;try{s=await t.readSetting()}catch{s=void 0}return ff(s)==="hide"&&await(t.hide??vf)()?"hidden":(await(t.destroy??gf)(),"closed")}function bf(t){xf()===pr&&Mt(pf,()=>{jf({readSetting:async()=>(await t.settingsStatus())?.settings?.desktopBackgroundOnClose})},{kind:"Window",label:pr})}const Qn=In();Qn!==null&&(document.documentElement.dataset.shell=Qn);Qn==="desktop"&&document.documentElement.classList.add("glass");Ac();Zt("get_pet_skin",{}).then(t=>{document.documentElement.dataset.petSkin=kr(t)});Mt(vc,t=>{if(typeof t!="object"||t===null)return;const s=t.skin;if(typeof s!="string")return;const n=kr(s);n===s&&(document.documentElement.dataset.petSkin=n)});const yf=Nc(),as=new Rc({url:kc(),token:yf});as.connect();mf(as);of();bf(as);fc(as);const Nf=xc.createRoot(document.getElementById("root")??document.body);Nf.render(e.jsx(i.StrictMode,{children:e.jsx(df,{client:as})}));