agentroam 0.2.0-preview.5 → 0.2.0-preview.6

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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +1 -1
  3. package/dist/cloudflared/bundled-asset.test.js +1 -1
  4. package/dist/cloudflared/manifest.js +1 -1
  5. package/dist/tunnel/public-readiness.js +1 -1
  6. package/package.json +2 -2
  7. package/runtime/.next/BUILD_ID +1 -1
  8. package/runtime/.next/app-build-manifest.json +4 -4
  9. package/runtime/.next/app-path-routes-manifest.json +1 -1
  10. package/runtime/.next/build-manifest.json +5 -5
  11. package/runtime/.next/prerender-manifest.json +1 -1
  12. package/runtime/.next/react-loadable-manifest.json +2 -2
  13. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  14. package/runtime/.next/server/app/_not-found.html +1 -1
  15. package/runtime/.next/server/app/_not-found.rsc +1 -1
  16. package/runtime/.next/server/app/api/agent/abort/route.js +2 -2
  17. package/runtime/.next/server/app/api/agent/abort/route.js.nft.json +1 -1
  18. package/runtime/.next/server/app/api/agent/answer/route.js +2 -2
  19. package/runtime/.next/server/app/api/agent/answer/route.js.nft.json +1 -1
  20. package/runtime/.next/server/app/api/agent/run/route.js +2 -2
  21. package/runtime/.next/server/app/api/agent/run/route.js.nft.json +1 -1
  22. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  23. package/runtime/.next/server/app/api/agent/runtime-health/route.js.nft.json +1 -1
  24. package/runtime/.next/server/app/api/agent/steer/route.js +2 -2
  25. package/runtime/.next/server/app/api/agent/steer/route.js.nft.json +1 -1
  26. package/runtime/.next/server/app/api/agent/stream/route.js +2 -2
  27. package/runtime/.next/server/app/api/agent/stream/route.js.nft.json +1 -1
  28. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
  29. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js.nft.json +1 -1
  30. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
  31. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js.nft.json +1 -1
  32. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
  33. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js.nft.json +1 -1
  34. package/runtime/.next/server/app/api/sessions/[id]/route.js +2 -2
  35. package/runtime/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -1
  36. package/runtime/.next/server/app/api/sessions/route.js +2 -2
  37. package/runtime/.next/server/app/api/sessions/route.js.nft.json +1 -1
  38. package/runtime/.next/server/app/web/page.js +1 -1
  39. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  40. package/runtime/.next/server/app/web.html +1 -1
  41. package/runtime/.next/server/app/web.rsc +2 -2
  42. package/runtime/.next/server/app-paths-manifest.json +15 -15
  43. package/runtime/.next/server/chunks/{809.js → 988.js} +10 -10
  44. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  45. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  46. package/runtime/.next/server/pages/404.html +1 -1
  47. package/runtime/.next/server/pages/500.html +1 -1
  48. package/runtime/.next/server/server-reference-manifest.json +1 -1
  49. package/runtime/.next/static/chunks/404.829f96e7395dbd79.js +1 -0
  50. package/runtime/.next/static/chunks/app/web/page-8747e21600303a2a.js +1 -0
  51. package/runtime/.next/static/chunks/{webpack-8bcef6486c3ddc96.js → webpack-96381cef391af02d.js} +1 -1
  52. package/runtime/node_modules/@agent/core/dist/domain/web-console/WebArtifactBridge.d.ts +9 -0
  53. package/runtime/node_modules/@agent/core/dist/domain/web-console/WebArtifactBridge.d.ts.map +1 -0
  54. package/runtime/node_modules/@agent/core/dist/domain/web-console/WebArtifactBridge.test.d.ts +2 -0
  55. package/runtime/node_modules/@agent/core/dist/domain/web-console/WebArtifactBridge.test.d.ts.map +1 -0
  56. package/runtime/node_modules/@agent/core/dist/domain/web-console/index.d.ts +1 -0
  57. package/runtime/node_modules/@agent/core/dist/domain/web-console/index.d.ts.map +1 -1
  58. package/runtime/node_modules/@agent/core/dist/index.js +24 -1
  59. package/runtime/node_modules/@agent/core/dist/index.js.map +4 -3
  60. package/runtime/webapp/dist/assets/{App-XUxeDI8P.js → App-C4wiUXZC.js} +62 -62
  61. package/runtime/webapp/dist/assets/index-D7slQOD-.css +1 -0
  62. package/runtime/webapp/dist/assets/{index-BdHtZjnb.js → index-DhS2YvqH.js} +1 -1
  63. package/runtime/webapp/dist/index.html +2 -2
  64. package/runtime/.next/static/chunks/604.749f141c00996f2f.js +0 -1
  65. package/runtime/.next/static/chunks/app/web/page-7d24c8b46d41da35.js +0 -1
  66. package/runtime/webapp/dist/assets/index-DeGogWCH.css +0 -1
  67. /package/runtime/.next/static/{mZZGSYMLIZnVm0gc5PXky → HvOq-7Qqu9K-QSMSBbbdj}/_buildManifest.js +0 -0
  68. /package/runtime/.next/static/{mZZGSYMLIZnVm0gc5PXky → HvOq-7Qqu9K-QSMSBbbdj}/_ssgManifest.js +0 -0
@@ -1,150 +1,150 @@
1
- import{R as $s,c as as,j as e,r as c,u as ke,a as zt,i as Us,b as Os,S as Hs,L as Vs}from"./index-BdHtZjnb.js";function qs(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||t===null||typeof r!="object"||r===null)return!1;if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(const[s,o]of t)if(!Object.is(o,r.get(s)))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(const s of t)if(!r.has(s))return!1;return!0}const n=Object.keys(t);if(n.length!==Object.keys(r).length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(r,s)||!Object.is(t[s],r[s]))return!1;return!0}const{useRef:Ks}=$s;function Gs(t){const r=Ks();return n=>{const s=t(n);return qs(r.current,s)?r.current:r.current=s}}function Mr(t,r){const n=t??[],s=n.findIndex(a=>a.itemId===r.itemId&&a.sectionIndex===r.sectionIndex);return(s<0?[...n,{itemId:r.itemId,sectionIndex:r.sectionIndex,text:r.delta}]:n.map((a,d)=>d===s?{...a,text:a.text+r.delta}:a)).sort((a,d)=>a.sectionIndex-d.sectionIndex)}function Lr(t){let r=[];for(const n of t)if(n.type==="runtime_progress"){const{type:s,...o}=n;r=ls(r,o)}else(n.type==="done"||n.type==="turn_aborted"||n.type==="error")&&(r=[]);return r}function ls(t,r){const n=t.findIndex(s=>s.progressId===r.progressId);return n<0?[...t,r]:t.map((s,o)=>o===n?r:s)}function Qs(t,r){return[...t].reverse().find(n=>n.toolCallId===r)}function Js(t){return[...t].reverse().find(r=>!r.toolCallId)}function Er(t){for(let r=t.length-1;r>=0;r--)if(t[r].type==="context_usage"&&t[r].usage)return t[r].usage}function Wr(t){var n;const r=new Map;for(const s of t)s.type==="native_subagent_update"&&((n=s.activity)!=null&&n.parentToolCallId)&&r.set(s.activity.parentToolCallId,s.activity);return[...r.values()]}function Br(t,r){var n,s;if(r.role==="assistant"&&((n=r.toolCalls)!=null&&n.length)){const o=t[t.length-1];if(o&&o.role==="assistant"&&!((s=o.toolCalls)!=null&&s.length))return[...t.slice(0,-1),{...o,content:o.content,toolCalls:r.toolCalls}]}return[...t,r]}function Nr(t,r){var s;if(!r)return t;const n=t[t.length-1];if(n&&n.role==="assistant"&&!((s=n.toolCalls)!=null&&s.length)&&!n.askUser&&!n.isCompactionSummary){const o=[...t];return o[o.length-1]={...n,content:n.content+r},o}return[...t,{id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()}]}function Pr(t,r,n,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(d=>d.id===r?{...d,result:n,isError:s}:d);return{...o,toolCalls:a}})}function Dr(t,r,n,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(d=>d.name==="dispatch_agent"&&d.arguments.subSessionId===r?{...d,arguments:{...d.arguments,subAgentStatus:n,subAgentDetail:s}}:d);return{...o,toolCalls:a}})}function _r(t,r,n){return t.map(s=>{if(!s.toolCalls)return s;const o=s.toolCalls.map(a=>a.name==="dispatch_agent"&&a.arguments.subSessionId===r?{...a,arguments:{...a.arguments,subAgentProgress:(a.arguments.subAgentProgress?a.arguments.subAgentProgress+`
2
- `+n:n).split(`
3
- `).slice(-30).join(`
4
- `)}}:a);return{...s,toolCalls:o}})}function Fr(t,r,n){return t.map(s=>s.id===r?n(s):s)}function $r(t,r){const n=t.findIndex(s=>{var o,a;return(a=(o=s.presentation)==null?void 0:o.reasoning)==null?void 0:a.some(d=>d.itemId===r.itemId)});return n<0?[...t,{id:`native-reasoning:${r.itemId}`,role:"assistant",content:"",presentation:{reasoning:Mr(void 0,r)},timestamp:Date.now()}]:t.map((s,o)=>{var a;return o===n?{...s,presentation:{...s.presentation,reasoning:Mr((a=s.presentation)==null?void 0:a.reasoning,r)}}:s})}const xe=as((t,r)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(n,s)=>t(o=>{const a=s??o.sessionId??void 0,d=a&&a!==o.sessionId?o.messages:Br(o.messages,n),u=a?{...o.messagesBySession,[a]:Br(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:d,messagesBySession:u,currentText:a&&a!==o.sessionId?o.currentText:""}}),appendText:(n,s)=>t(o=>{if(!n)return o;const a=s??o.sessionId??void 0,d=a&&a!==o.sessionId?o.messages:Nr(o.messages,n),u=a?{...o.messagesBySession,[a]:Nr(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:d,messagesBySession:u,currentText:a&&a!==o.sessionId?o.currentText:o.currentText+n}}),setRunningSession:n=>t({runningSessionId:n}),setSessionId:n=>t({sessionId:n}),updateToolResult:(n,s,o,a)=>t(d=>{const u=a??d.sessionId??void 0,f=u&&u!==d.sessionId?d.messages:Pr(d.messages,n,s,o),p=u?{...d.messagesBySession,[u]:Pr(d.messagesBySession[u]??(u===d.sessionId?d.messages:[]),n,s,o)}:d.messagesBySession;return{messages:f,messagesBySession:p}}),setMessages:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return{messages:n,messagesBySession:a?{...o.messagesBySession,[a]:n}:o.messagesBySession,currentText:""}}),getMessagesForSession:n=>r().messagesBySession[n]??[],setContextUsage:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{contextUsageBySession:{...o.contextUsageBySession,[a]:n}}:o}),getContextUsageForSession:n=>r().contextUsageBySession[n],applyRuntimeProgress:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:ls(o.runtimeProgressBySession[a]??[],n)}}:o}),setRuntimeProgress:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:n}}:o}),clearRuntimeProgress:n=>t(s=>{var u;const o=n??s.sessionId??void 0;if(!o||!((u=s.runtimeProgressBySession[o])!=null&&u.length))return s;const{[o]:a,...d}=s.runtimeProgressBySession;return{runtimeProgressBySession:d}}),applyNativeSubagentActivity:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:{...o.nativeSubagentsBySession[a]??{},[n.parentToolCallId]:n}}}:o}),setNativeSubagentActivities:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:Object.fromEntries(n.map(d=>[d.parentToolCallId,d]))}}:o}),applyReasoningSummary:(n,s)=>t(o=>{const a=s??o.sessionId??void 0,d=a&&a!==o.sessionId?o.messages:$r(o.messages,n),u=a?{...o.messagesBySession,[a]:$r(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:d,messagesBySession:u}}),updateMessage:(n,s,o)=>t(a=>{const d=o??a.sessionId??void 0,u=d&&d!==a.sessionId?a.messages:Fr(a.messages,n,s),f=d?{...a.messagesBySession,[d]:Fr(a.messagesBySession[d]??(d===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:u,messagesBySession:f}}),updateSubAgentStatus:(n,s,o,a)=>t(d=>{const u=a??d.sessionId??void 0,f=u&&u!==d.sessionId?d.messages:Dr(d.messages,n,s,o),p=u?{...d.messagesBySession,[u]:Dr(d.messagesBySession[u]??(u===d.sessionId?d.messages:[]),n,s,o)}:d.messagesBySession;return{messages:f,messagesBySession:p}}),updateSubAgentProgress:(n,s,o)=>t(a=>{const d=o??a.sessionId??void 0,u=d&&d!==a.sessionId?a.messages:_r(a.messages,n,s),f=d?{...a.messagesBySession,[d]:_r(a.messagesBySession[d]??(d===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:u,messagesBySession:f}}),clearMessages:n=>t(s=>{const o=n??s.sessionId??void 0;if(!o)return{messages:[],currentText:""};const{[o]:a,...d}=s.messagesBySession,{[o]:u,...f}=s.contextUsageBySession,{[o]:p,...b}=s.runtimeProgressBySession,{[o]:h,...w}=s.nativeSubagentsBySession;return{messages:o===s.sessionId?[]:s.messages,messagesBySession:d,contextUsageBySession:f,runtimeProgressBySession:b,nativeSubagentsBySession:w,currentText:o===s.sessionId?"":s.currentText}}),setTodos:n=>t({todos:n}),setCronTasks:n=>t({cronTasks:n})}));function hr(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function ds(){if(typeof window>"u")return null;const t=window.agentApi;return typeof(t==null?void 0:t.dictationStart)!="function"||typeof t.dictationStop!="function"||typeof t.onDictation!="function"||typeof t.onDictationError!="function"?null:t}function Xs(){return ds()!==null||hr()!==null}function Ys(t){var a,d;const r=ds();if(r){let u=!1,f=()=>{},p=()=>{};const b=()=>{var h;u||(u=!0,f(),p(),(h=t.onEnd)==null||h.call(t))};return f=r.onDictation(({text:h,isFinal:w})=>{const S=h.trim();S&&(w?(t.onFinal(S),b()):t.onInterim(S))}),p=r.onDictationError(h=>{var w;(w=t.onError)==null||w.call(t,h),b()}),r.dictationStart().then(h=>{var w;h.ok||((w=t.onError)==null||w.call(t,h.reason||"无法启动语音识别"),b())}).catch(()=>{var h;(h=t.onError)==null||h.call(t,"无法启动语音识别"),b()}),{stop:()=>{r.dictationStop()}}}const n=hr();if(!n)return(a=t.onError)==null||a.call(t,"当前环境不支持语音识别"),null;const s=new n;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let o="";s.onresult=u=>{let f="";for(let p=u.resultIndex;p<u.results.length;p++){const b=u.results[p];b.isFinal?o+=b[0].transcript:f+=b[0].transcript}f&&t.onInterim(o+f)},s.onerror=u=>{var f;u.error!=="no-speech"&&u.error!=="aborted"&&((f=t.onError)==null||f.call(t,`语音识别失败:${u.error??"未知错误"}`))},s.onend=()=>{var u;o&&t.onFinal(o.trim()),(u=t.onEnd)==null||u.call(t)};try{s.start()}catch{return(d=t.onEnd)==null||d.call(t),null}return{stop:()=>s.stop()}}function Zs(t){var d;const r=hr();if(!r)return(d=t.onError)==null||d.call(t,"当前环境不支持语音唤醒"),null;let n=!1,s=null,o=null;const a=()=>{if(!n){s=new r,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=u=>{var b,h,w;const f=u.results[u.results.length-1],p=(h=(b=f==null?void 0:f[0])==null?void 0:b.transcript)==null?void 0:h.trim();p&&(f.isFinal&&((w=t.onHeard)==null||w.call(t,p)),p.includes(t.wakeWord)&&t.onWake(p))},s.onerror=u=>{var f;u.error==="not-allowed"&&((f=t.onError)==null||f.call(t,"麦克风权限被拒绝,语音唤醒已停用"),n=!0)},s.onend=()=>{n||(o=setTimeout(a,400))};try{s.start()}catch{o=setTimeout(a,800)}}};return a(),{stop:()=>{n=!0,o&&clearTimeout(o);try{s==null||s.abort()}catch{}}}}function wn(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function Wn(t,r){return r(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const eo={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function to(t){const r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(r.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const n=new Float32Array(r.byteLength/2),s=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let o=0;o<n.length;o+=1)n[o]=s.getInt16(o*2,!0)/32768;return n}class no{constructor(r,n=eo){this.api=r,this.dependencies=n,this.context=null,this.node=null,this.ready=null,this.current=null}start(r){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const n={metadata:r,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=n,this.ensureReady().then(()=>{if(!(this.current!==n||!this.node)){this.node.port.postMessage({type:"start",generation:r.generation,sampleRate:r.sampleRate});for(const o of n.pending)this.postSamples(r.generation,o);n.pending=[],n.pendingSamples=0,n.finished&&this.node.port.postMessage({type:"finish",generation:r.generation})}}).catch(o=>this.fail(n,o))}enqueue(r,n){const s=this.current;if(!s||s.metadata.generation!==r||s.acknowledged)return;let o;try{o=to(n)}catch(a){this.fail(s,a);return}if(this.node){this.postSamples(r,o);return}if(s.pendingSamples+o.length>s.metadata.sampleRate){this.fail(s,new Error("TTS PCM queue overflow"));return}s.pending.push(o),s.pendingSamples+=o.length}finish(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||(n.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:r}))}flush(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:r}),n.pending=[],n.pendingSamples=0,this.acknowledge(n))}dispose(){var r,n;this.current&&this.flush(this.current.metadata.generation),(r=this.node)==null||r.disconnect(),this.node=null,(n=this.context)==null||n.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const r=this.dependencies.createContext();this.context=r,await r.audioWorklet.addModule(this.dependencies.workletUrl);const n=this.dependencies.createNode(r);n.port.onmessage=s=>this.onWorkletMessage(s.data),n.connect(r.destination),this.node=n,r.state!=="running"&&await r.resume()})(),this.ready)}postSamples(r,n){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:r,samples:n},[n.buffer])}onWorkletMessage(r){const n=this.current;if(!(!n||r.generation!==n.metadata.generation)){if(r.type==="drained"||r.type==="stopped"){this.acknowledge(n);return}r.type==="overflow"&&this.fail(n,new Error("TTS AudioWorklet buffer overflow"))}}fail(r,n){this.current!==r||r.acknowledged||(console.error("[tts] PCM playback failed",n),r.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(r.metadata.generation))}acknowledge(r){this.current!==r||r.acknowledged||(r.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(r.metadata.generation))}}function Jn(t){var b;const r=(t==null?void 0:t.messages)??[],n=(t==null?void 0:t.events)??[],s=new Set(n.filter(h=>h.type==="approval_resolved"&&h.questionId).map(h=>h.questionId)),o=new Map;for(const h of n)h.type==="tool_result"&&((b=h.result)!=null&&b.toolCallId)&&o.set(h.result.toolCallId,{content:h.result.content??"",isError:h.result.isError});const a=r.filter(h=>(h.role==="user"||h.role==="assistant"||h.role==="tool")&&h.name!=="__interrupt__").map(so),d=new Map;for(const h of a)h.role==="tool"&&h.toolCallId&&d.set(h.toolCallId,h);let u=a.filter(h=>h.role!=="tool").map(h=>{var w;return h.isCompactionSummary?h:h.role==="assistant"&&((w=h.toolCalls)!=null&&w.length)?{...h,toolCalls:h.toolCalls.map(S=>{const D=d.get(S.id);if(D)return{...S,result:D.content};const H=o.get(S.id);return H?{...S,result:H.content,isError:H.isError}:S})}:h.role==="user"&&h.name&&h.name!=="__compaction_checkpoint__"?{...h,agentName:h.name}:h});const f=oo(n);if(!u.some(h=>h.role==="assistant"&&!h.isCompactionSummary)&&f){const h=u.findLastIndex(w=>w.role==="user"&&!w.isCompactionSummary);u=h>=0?[...u.slice(0,h+1),f,...u.slice(h+1)]:[...u,f]}const p=new Set(u.flatMap(h=>{var w;return(w=h.askUser)!=null&&w.questionId?[h.askUser.questionId]:[]}));for(const h of n)h.type!=="ask_user"||!h.questionId||s.has(h.questionId)||p.has(h.questionId)||(p.add(h.questionId),u.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:h.questionId,question:h.question??"",options:h.options,fields:h.fields,multiSelect:h.multiSelect},timestamp:Date.now()}));return u}function ro(t,r){if(r.length===0)return t;if(t.length===0)return r;const n=t.map(Xn),s=r.map(Xn),o=Math.max(0,t.length-r.length);let a={currentStart:o,length:0,distance:1/0};for(let f=0;f<n.length;f++)for(let p=0;p<s.length;p++){if(n[f]!==s[p])continue;const b=f-p;if(b<0)continue;let h=0;for(;f+h<n.length&&p+h<s.length&&n[f+h]===s[p+h];)h+=1;const w=Math.abs(b-o);(h>a.length||h===a.length&&w<a.distance)&&(a={currentStart:b,length:h,distance:w})}const d=a.length>0?a.currentStart:o,u=r.map((f,p)=>{const b=t[d+p];return!b||Xn(b)!==s[p]?f:{...f,id:b.id,timestamp:b.timestamp}});return[...t.slice(0,d),...u]}function Xn(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,name:t.name,agentName:t.agentName,presentation:t.presentation,isCompactionSummary:t.isCompactionSummary})}function so(t){var r;if(t.name==="__compaction_checkpoint__"){let n="";try{n=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:n,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(r=t.toolCalls)!=null&&r.length?t.toolCalls:void 0,toolCallId:t.toolCallId,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function oo(t){var o;let r="";const n=[],s=new Map;for(const a of t){if(a.type==="text_chunk"&&a.text&&(r+=a.text),a.type==="tool_call"&&a.toolCall){const d={id:a.toolCall.id,name:a.toolCall.name,arguments:a.toolCall.arguments};n.push(d),s.set(d.id,d)}if(a.type==="tool_result"&&((o=a.result)!=null&&o.toolCallId)){const d=s.get(a.result.toolCallId);d&&(d.result=a.result.content??"",d.isError=a.result.isError)}}return!r.trim()&&n.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:n.length>0?n:void 0,timestamp:Date.now()}}function io(t){return t==="customer-agent"||t==="claude-code"}function ao(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),Object.assign(r.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(r);try{return r.focus(),r.select(),r.setSelectionRange(0,r.value.length),document.execCommand("copy")}catch{return!1}finally{r.remove()}}async function lo(t){const r=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(r==null?void 0:r.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await r.writeText(t),!0}catch{}return ao(t)}const co="agentroam:draft:";function _n(t){return`${co}${t}`}function uo(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(_n(t))??""}catch{return""}}function Yn(t,r){if(!(!t||typeof window>"u"))try{r?window.localStorage.setItem(_n(t),r):window.localStorage.removeItem(_n(t))}catch{}}function po(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(_n(t))}catch{}}function Bn(t,r){return t.find(n=>n.id===r)??null}const Fn=as((t,r)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(n,s)=>t(o=>{const a={...o,[n]:s};return a.isConfigured=!!(a.apiKey&&a.modelId),a}),loadFromSystem:async()=>{if(window.agentApi)try{const n=await window.agentApi.getSettings(),s=n.profiles??[],o=n.activeProfileId??"",a=Bn(s,o);t({modelProvider:(a==null?void 0:a.provider)??n.modelProvider??"anthropic",modelId:(a==null?void 0:a.modelId)??n.modelId??"claude-sonnet-4-6",apiKey:(a==null?void 0:a.apiKey)??n.apiKey??"",baseUrl:(a==null?void 0:a.baseUrl)??n.baseUrl??"",maxIterations:n.maxIterations??10,contextWindow:n.contextWindow??100,workingDirectory:n.workingDirectory??"/",isConfigured:!!(((a==null?void 0:a.apiKey)??n.apiKey)&&((a==null?void 0:a.modelId)??n.modelId)),profiles:s,activeProfileId:o,reasoningEffort:["off","low","medium","high"].includes(n.reasoningEffort??"")?n.reasoningEffort:"off"})}catch(n){console.error("Failed to load settings:",n)}},saveToSystem:async()=>{if(!window.agentApi)return;const n=r();await window.agentApi.saveSettings({modelProvider:n.modelProvider,modelId:n.modelId,apiKey:n.apiKey,baseUrl:n.baseUrl,maxIterations:n.maxIterations,contextWindow:n.contextWindow,workingDirectory:n.workingDirectory,isConfigured:n.isConfigured,profiles:n.profiles,activeProfileId:n.activeProfileId,reasoningEffort:n.reasoningEffort})},addProfile:n=>{const o={id:crypto.randomUUID(),...n};t(a=>({profiles:[...a.profiles,o]}))},updateProfile:(n,s)=>{t(a=>({profiles:a.profiles.map(d=>d.id===n?{...d,...s}:d)}));const o=r();if(o.activeProfileId===n){const a=Bn(o.profiles,n);a&&t({modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})}},deleteProfile:n=>{t(s=>{var u;const o=s.profiles.filter(f=>f.id!==n),a=s.activeProfileId===n?((u=o[0])==null?void 0:u.id)??"":s.activeProfileId,d=Bn(o,a);return{profiles:o,activeProfileId:a,...d?{modelProvider:d.provider,modelId:d.modelId,apiKey:d.apiKey,baseUrl:d.baseUrl,isConfigured:!!(d.apiKey&&d.modelId)}:{}}})},setActiveProfileLocal:n=>{const s=r(),o=Bn(s.profiles,n);o&&t({activeProfileId:n,modelProvider:o.provider,modelId:o.modelId,apiKey:o.apiKey,baseUrl:o.baseUrl,isConfigured:!!(o.apiKey&&o.modelId)})},switchActiveProfile:async n=>{r().setActiveProfileLocal(n),window.agentApi&&await window.agentApi.setActiveProfile(n)}}));function tn(t){return t.result!==void 0}function Ur(t){return t.every(tn)}const cs=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),us=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),go=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]);function ps(t){return cs.has(t)?"command":us.has(t)?"file":go.has(t)?"search":"generic"}function fr(t){switch(t){case"shell":case"bash":case"Bash":case"execute_command":case"run_command":return{done:"运行了命令",doing:"运行命令中"};case"BashOutput":case"KillShell":return{done:"查看了命令输出",doing:"查看输出中"};case"Read":case"read_file":return{done:"读取了文件",doing:"读取文件中"};case"Write":case"write_file":return{done:"写入了文件",doing:"写入文件中"};case"Edit":case"MultiEdit":case"str_replace":case"apply_patch":return{done:"修改了文件",doing:"修改文件中"};case"Glob":case"glob_search":return{done:"搜索了文件",doing:"搜索文件中"};case"Grep":case"grep_search":return{done:"搜索了内容",doing:"搜索内容中"};case"Skill":return{done:"调用了技能",doing:"调用技能中"};case"Task":return{done:"启动了子任务",doing:"启动子任务中"};case"WebSearch":return{done:"搜索了网络",doing:"搜索网络中"};case"WebFetch":return{done:"读取了网页",doing:"读取网页中"};case"TodoWrite":return{done:"更新了任务清单",doing:"更新任务清单中"};case"NotebookEdit":return{done:"编辑了 Notebook",doing:"编辑 Notebook 中"};default:return t.startsWith("mcp__")||t.includes(":")?{done:"调用了工具",doing:"调用工具中"}:null}}function ho(t){var r;return((r=fr(t))==null?void 0:r.done)??null}function Or(t){return t.replace(/\\/g,"/").split("/").pop()??t}function Zn(t,r=60){const n=(t??"").split(`
5
- `)[0].trim();return n.length>r?n.slice(0,r)+"…":n}function fo(t,r){if(cs.has(t))return Zn(String(r.command??""));if(t==="apply_patch"){const s=(Array.isArray(r.changes)?r.changes:[]).map(o=>Or(String((o==null?void 0:o.path)??""))).filter(Boolean);return s.length?s.length<=3?s.join("、"):`${s.slice(0,3).join("、")} 等 ${s.length} 个文件`:null}return us.has(t)?r.file_path?Or(String(r.file_path)):null:t==="Glob"||t==="glob_search"?String(r.pattern??"")||null:t==="Grep"||t==="grep_search"?String(r.pattern??r.query??"")||null:t==="Skill"?String(r.skill??"")||null:t==="Task"?Zn(String(r.description??r.task??""),80)||null:t==="WebSearch"?Zn(String(r.query??"")):t==="WebFetch"?String(r.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function gs({progress:t,compact:r=!1}){const n=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),s=[t.label,n].filter(Boolean).join(",");return e.jsxs("div",{className:`runtime-progress-row${r?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":s,children:[e.jsx("span",{className:"runtime-progress-row__spinner","aria-hidden":"true"}),e.jsx("span",{className:"runtime-progress-row__label",children:t.label}),n&&e.jsx("span",{className:"runtime-progress-row__detail",children:n})]})}function nn({isDone:t,isError:r,color:n,size:s=11}){return t?r?e.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}):e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"spin 1s linear infinite",flexShrink:0},children:e.jsx("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"})})}function hs({family:t,color:r,size:n=12}){return t==="command"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):t==="search"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}):t==="file"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}):e.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})})}function $n({statusColor:t,isDone:r,expanded:n,onToggle:s,header:o,children:a,maxBodyHeight:d=600}){return e.jsxs("div",{className:"tool-call-shell",style:{marginTop:4,borderRadius:9,border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-deepest)",fontSize:12,minWidth:0},children:[e.jsxs("div",{className:"tool-call-shell__row",style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{className:"tool-call-shell__status",style:{width:3,flexShrink:0,background:t,animation:r?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),e.jsxs("button",{className:"tool-call-shell__header",onClick:s,style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:u=>u.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:u=>u.currentTarget.style.background="var(--bg-deep)",children:[o,e.jsx("svg",{className:"tool-call-shell__chevron",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(180deg)":"rotate(0deg)",flexShrink:0},children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})]}),n&&e.jsx("div",{className:"tool-call-shell__body",style:{overflow:"hidden",maxHeight:d,opacity:1,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{className:"tool-call-shell__body-content",style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:a})})]})}function Cn({label:t,color:r="var(--text-muted)",bg:n="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:n,color:r,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function xr(t){return t.replace(/\\/g,"/").split("/").pop()??t}function fs(t){return t?t.split(`
6
- `).length:0}function xs(t,r){const n=t.split(`
7
- `),s=r.split(`
8
- `);if(n.length*s.length>2e5)return s.map((S,D)=>({type:"added",text:S,lineNo:D+1}));const o=n.length,a=s.length,d=Array.from({length:o+1},()=>new Array(a+1).fill(0));for(let S=1;S<=o;S++)for(let D=1;D<=a;D++)d[S][D]=n[S-1]===s[D-1]?d[S-1][D-1]+1:Math.max(d[S-1][D],d[S][D-1]);const u=[];let f=o,p=a;for(;f>0&&p>0;)n[f-1]===s[p-1]?(u.unshift([f-1,p-1]),f--,p--):d[f-1][p]>=d[f][p-1]?f--:p--;const b=[];let h=0,w=0;for(const[S,D]of u){for(;h<S;)b.push({type:"removed",text:n[h],lineNo:h+1}),h++;for(;w<D;)b.push({type:"added",text:s[w],lineNo:w+1}),w++;b.push({type:"same",text:n[h],lineNo:h+1}),h++,w++}for(;h<o;)b.push({type:"removed",text:n[h],lineNo:h+1}),h++;for(;w<a;)b.push({type:"added",text:s[w],lineNo:w+1}),w++;return b}function ms({content:t,maxHeight:r=320}){const n=t.split(`
9
- `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:n.map((s,o)=>e.jsxs("tr",{children:[e.jsx("td",{style:{padding:"0 8px",color:"var(--text-muted)",textAlign:"right",userSelect:"none",borderRight:"1px solid var(--border-subtle)",background:"var(--bg-deep)",fontSize:10,minWidth:36},children:o+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:s||" "})]},o))})]})})}function bs({diff:t,maxHeight:r=360}){if(t.filter(u=>u.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const s=new Set(t.map((u,f)=>u.type!=="same"?f:-1).filter(u=>u>=0)),o=new Set;s.forEach(u=>{for(let f=Math.max(0,u-3);f<=Math.min(t.length-1,u+3);f++)o.add(f)});const a=[];let d=-1;return[...o].sort((u,f)=>u-f).forEach(u=>{d>=0&&u>d+1&&a.push("ellipsis"),a.push({diffLine:t[u],diffIdx:u}),d=u}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:a.map((u,f)=>{if(u==="ellipsis")return e.jsx("tr",{children:e.jsx("td",{colSpan:3,style:{padding:"2px 12px",color:"var(--text-muted)",fontSize:10,background:"var(--bg-deep)",textAlign:"center"},children:"⋯"})},`e${f}`);const{diffLine:p}=u,b=p.type==="added"?"rgba(5,150,105,0.08)":p.type==="removed"?"rgba(220,38,38,0.07)":"transparent",h=p.type==="added"?"+":p.type==="removed"?"−":" ",w=p.type==="added"?"var(--success)":p.type==="removed"?"var(--danger)":"transparent",S=p.type==="added"?"#059669":p.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:b},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:w,fontWeight:700,userSelect:"none"},children:h}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:p.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:S,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:p.text||" "})]},f)})})]})})}function xo({toolCall:t,beforeContent:r}){const[n,s]=c.useState(!1),[o,a]=c.useState("content"),d=t.arguments.file_path??"",u=t.arguments.content??"",f=fs(u),p=t.isError,b=tn(t),h=b?p?"var(--danger)":"var(--success)":"var(--accent)",w=c.useMemo(()=>r&&u?xs(r,u):null,[r,u]),S=c.useMemo(()=>w?{added:w.filter(V=>V.type==="added").length,removed:w.filter(V=>V.type==="removed").length}:null,[w]),D=b?p?"错误":"已写入":"写入中",H=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:b?p?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:h,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:d,children:xr(d)}),e.jsx(Cn,{label:`${f} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),S&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[S.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",S.added]}),S.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",S.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:h,flexShrink:0},children:[e.jsx(nn,{isDone:b,isError:p,color:h}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:D})]})]});return e.jsxs($n,{statusColor:h,isDone:b,expanded:n,onToggle:()=>s(!n),header:H,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:d}),w&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(V=>e.jsx("button",{onClick:()=>a(V),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:o===V?"var(--accent-dim)":"transparent",color:o===V?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:V==="content"?"文件内容":"变更行"},V))}),o==="diff"&&w?e.jsx(bs,{diff:w}):e.jsx(ms,{content:u}),p&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function mo({toolCall:t}){const[r,n]=c.useState(!1),s=t.arguments.file_path??"",o=t.arguments.startLine,a=t.arguments.endLine,d=t.arguments.offset,u=t.arguments.limit,f=t.result??"",p=fs(f),b=t.isError,h=tn(t),w=h?b?"var(--danger)":"var(--success)":"var(--accent)",S=o!==void 0?`L${o}–${a??"?"}`:d!==void 0?`第${d}行起${u?` ×${u}`:""}`:null,D=h?b?"错误":"已读取":"读取中",H=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:h?b?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:w,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s,children:xr(s)}),S&&e.jsx(Cn,{label:S,color:"var(--accent)",bg:"var(--accent-dim)"}),h&&!b&&e.jsx(Cn,{label:`${p} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:w,flexShrink:0},children:[e.jsx(nn,{isDone:h,isError:b,color:w}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:D})]})]});return e.jsxs($n,{statusColor:w,isDone:h,expanded:r,onToggle:()=>n(!r),header:H,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s}),h&&!b?e.jsx(ms,{content:f}):h&&b&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:f})]})}function bo({toolCall:t}){const[r,n]=c.useState(!1),s=t.arguments.file_path??"",o=t.arguments.old_string??"",a=t.arguments.new_string??"",d=t.isError,u=tn(t),f=u?d?"var(--danger)":"var(--success)":"var(--accent)",p=u?d?"错误":"已替换":"替换中",b=c.useMemo(()=>o&&a?xs(o,a):null,[o,a]),h=c.useMemo(()=>b?{added:b.filter(S=>S.type==="added").length,removed:b.filter(S=>S.type==="removed").length}:null,[b]),w=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:u?d?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:f,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s,children:xr(s)}),h&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[h.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",h.added]}),h.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",h.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:f,flexShrink:0},children:[e.jsx(nn,{isDone:u,isError:d,color:f}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:p})]})]});return e.jsxs($n,{statusColor:f,isDone:u,expanded:r,onToggle:()=>n(!r),header:w,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s}),b?e.jsx(bs,{diff:b}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:o}),e.jsx("pre",{style:{fontSize:11,color:"var(--success)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(5,150,105,0.04)",border:"1px solid rgba(5,150,105,0.12)",borderLeft:"3px solid var(--success)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a})]}),d&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function en({label:t,content:r,error:n,maxPreviewLines:s=8,maxPreviewHeight:o=200,maxExpandedHeight:a=2e3}){const[d,u]=c.useState(!1),f=r.split(`
10
- `),p=f.length>s,b=p&&!d?f.slice(0,s).join(`
11
- `)+`
12
- ...`:r;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:n?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:n?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:n?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:n?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:d?a:o,overflow:"auto",margin:0,lineHeight:1.6},children:b}),p&&e.jsx("button",{onClick:()=>u(!d),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:d?"收起":`展开全部 (${f.length} 行)`})]})}function vo({arguments:t}){var n;const r=t.task??"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 0"},children:[e.jsxs("div",{style:{display:"flex",gap:8,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",flexWrap:"wrap"},children:[e.jsx(Cn,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(Cn,{label:`sid: ${(n=t.subSessionId)==null?void 0:n.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),r&&e.jsx(en,{label:"任务",content:r,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function yo({raw:t}){const[r,n]=c.useState(!1);let s;try{const f=JSON.parse(t);delete f.subAgentProgress,delete f.subAgentStatus,delete f.subAgentDetail,s=JSON.stringify(f,null,2)}catch{s=t}const o=8,a=s.split(`
13
- `),d=a.length>o,u=d&&!r?a.slice(0,o).join(`
14
- `)+`
15
- ...`:s;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"参数"}),e.jsx("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",maxHeight:r?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:u}),d&&e.jsx("button",{onClick:()=>n(!r),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:r?"收起":`展开全部 (${a.length} 行)`})]})}function wo({activity:t}){const r=new Map(t.messages.flatMap(n=>n.role==="tool"&&n.toolCallId?[[n.toolCallId,{content:n.content,isError:n.name==="error"}]]:[]));return e.jsxs("div",{className:"native-subagent-activity",children:[e.jsxs("div",{className:"native-subagent-activity__meta",children:[t.elapsedSeconds!==void 0&&e.jsxs("span",{children:[t.elapsedSeconds," 秒"]}),t.toolUses!==void 0&&e.jsxs("span",{children:[t.toolUses," 次工具调用"]}),t.lastToolName&&e.jsxs("span",{children:["正在使用 ",t.lastToolName]})]}),t.messages.map((n,s)=>{var o;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[n.role==="assistant"&&n.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:n.content}),n.role==="assistant"&&((o=n.toolCalls)==null?void 0:o.map(a=>{const d=r.get(a.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(mr,{toolCall:{...a,...d?{result:d.content,isError:d.isError}:{}}}),d&&e.jsx("pre",{className:`native-subagent-activity__tool-result${d.isError?" native-subagent-activity__tool-result--error":""}`,children:d.content})]},a.id)})),n.role==="tool"&&n.toolCallId&&!t.messages.some(a=>{var d;return(d=a.toolCalls)==null?void 0:d.some(u=>u.id===n.toolCallId)})&&e.jsx(en,{label:"工具结果",content:n.content,error:n.name==="error",maxPreviewHeight:180})]},`${n.role}-${s}`)}),t.summary&&e.jsx(en,{label:t.status==="failed"?"错误信息":"执行摘要",content:t.summary,error:t.status==="failed",maxPreviewHeight:180}),t.status==="running"&&t.messages.length===0&&!t.summary&&e.jsxs("div",{className:"native-subagent-activity__waiting",children:[e.jsx(nn,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function jo({toolCall:t,onSelectSession:r,nativeSubagent:n}){const s=xe(R=>R.runningSessionId),[o,a]=c.useState(()=>!!n),d=t.name==="dispatch_agent",u=t.name==="Agent"&&!!n,f=t.arguments.subAgentStatus,p=t.arguments.subAgentDetail,b=t.arguments.subAgentProgress,h=tn(t);c.useEffect(()=>{d&&!f&&b&&a(!0),u&&(n.messages.length>0||n.summary)&&a(!0)},[d,u,n,f,b]);const w=d?f==="failed":u?n.status==="failed":t.isError,S=d?!!f||h&&!s:u?n.status!=="running":h,D=S?w?"var(--danger)":"var(--success)":"var(--accent)",H=d?null:fr(t.name),V=w?"错误":H?"":u?n.status==="stopped"?"已停止":S?"已完成":"运行中":d?f==="failed"?"失败":S?"已完成":"运行中":S?"完成":"执行中",_=u?n.description:d?(()=>{const C=(t.arguments.task??"").split(`
16
- `)[0];return C.length>80?C.slice(0,80)+"…":C})():fo(t.name,t.arguments),m=u?`@${n.agentName??"agent"}`:d?`@${t.arguments.agentName??"agent"}`:H?H.done:t.name,j=ps(t.name),A=d||u?e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:D,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}):e.jsx(hs,{family:j,color:D,size:11}),P=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:S?w?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:A}),e.jsx("span",{title:H?t.name:void 0,style:{fontFamily:H?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:m}),_&&e.jsx("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_}),!_&&e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:D,flexShrink:0},children:[e.jsx(nn,{isDone:S,isError:!!w,color:D}),V&&e.jsx("span",{style:{fontSize:10,fontWeight:500},children:V})]})]});return e.jsxs($n,{statusColor:D,isDone:S,expanded:o,onToggle:()=>a(!o),header:P,maxBodyHeight:800,children:[u?e.jsx(wo,{activity:n}):d?e.jsx(vo,{arguments:t.arguments}):j==="command"&&typeof t.arguments.command=="string"?e.jsxs(e.Fragment,{children:[typeof t.arguments.cwd=="string"&&t.arguments.cwd&&e.jsxs("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:["工作目录 ",t.arguments.cwd]}),e.jsx(en,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(yo,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!d&&!u&&e.jsx(en,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),d&&f&&p&&e.jsx(en,{label:f==="failed"?"错误信息":"执行摘要",content:p,error:f==="failed",maxPreviewHeight:180}),d&&!f&&b&&(!!s||!h)&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"实时输出"}),e.jsxs("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderLeft:"3px solid var(--accent)",maxHeight:240,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:[b,e.jsx("span",{style:{display:"inline-block",width:"0.5em",height:"1em",background:"var(--accent)",verticalAlign:"text-bottom",animation:"blink 1s step-end infinite"},children:"​"})]})]}),d&&!f&&!b&&!!s&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 0",fontSize:11,color:"var(--text-muted)",fontStyle:"italic"},children:[[0,1,2].map(R=>e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--accent)",display:"inline-block",animation:"wave 1.1s ease-in-out infinite",animationDelay:`${R*.16}s`}},R)),"等待子 agent 响应..."]}),d&&t.arguments.subSessionId&&r&&e.jsxs("button",{onClick:()=>r(t.arguments.subSessionId),style:{alignSelf:"flex-start",padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--accent-dim)",color:"var(--accent)",fontSize:11,fontWeight:500,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s"},onMouseEnter:R=>{R.currentTarget.style.background="var(--accent)",R.currentTarget.style.color="white"},onMouseLeave:R=>{R.currentTarget.style.background="var(--accent-dim)",R.currentTarget.style.color="var(--accent)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}),"查看子会话"]})]})}function ko({items:t,onSelectSession:r}){var h;const[n,s]=c.useState(!1),o=(h=t[0])==null?void 0:h.toolCall,a=o?fr(o.name):null;if(!o||!a||t.length<2)return null;const d=t.every(({toolCall:w})=>tn(w)),u=t.filter(({toolCall:w})=>w.isError).length,f=u>0?"var(--danger)":d?"var(--text-muted)":"var(--accent)",p=a.done,b=`${p},${t.length} 项,${n?"收起":"展开"}`;return e.jsxs("div",{className:"tool-call-group",children:[e.jsxs("button",{type:"button",className:"tool-call-group__summary","aria-expanded":n,"aria-label":b,onClick:()=>s(w=>!w),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(hs,{family:ps(o.name),color:f,size:13})}),e.jsx("span",{className:"tool-call-group__label",children:p}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),u>0&&e.jsxs("span",{className:"tool-call-group__error",children:[u," 项失败"]}),!d&&e.jsx(nn,{isDone:!1,color:f,size:11}),e.jsx("svg",{className:"tool-call-group__chevron",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]}),n&&e.jsx("div",{className:"tool-call-group__items",children:t.map(({toolCall:w,beforeContent:S,progress:D,nativeSubagent:H})=>e.jsx(mr,{toolCall:w,beforeContent:S,progress:D,nativeSubagent:H,onSelectSession:r},w.id))})]})}function mr({toolCall:t,onSelectSession:r,beforeContent:n,progress:s,nativeSubagent:o}){const a=t.name==="write_file"?e.jsx(xo,{toolCall:t,beforeContent:n}):t.name==="read_file"?e.jsx(mo,{toolCall:t}):t.name==="str_replace"?e.jsx(bo,{toolCall:t}):e.jsx(jo,{toolCall:t,onSelectSession:r,nativeSubagent:o});return e.jsxs("div",{className:"tool-call-with-progress",children:[a,s&&e.jsx(gs,{progress:s,compact:!0})]})}function So({question:t,options:r,fields:n,multiSelect:s,answered:o,answer:a,onAnswer:d}){const[u,f]=c.useState(new Set),[p,b]=c.useState(""),[h,w]=c.useState({}),S=!!(r!=null&&r.length),D=!!(n!=null&&n.length),H=j=>{o||f(A=>{const P=new Set(A);return s?P.has(j)?P.delete(j):P.add(j):(P.clear(),P.add(j)),P})},V=()=>{if(u.size===0)return;const j=Array.from(u).map(A=>r[A].label);d(j.join(", "),Array.from(u))},_=()=>{const j=Array.from(u).map(P=>r[P].label),A=Object.fromEntries((n??[]).map(P=>{var R;return[P.name,((R=h[P.name])==null?void 0:R.trim())??""]}));!A.model&&j.length>0&&(A.model=j[0]),!(!Object.values(A).some(Boolean)&&j.length===0)&&d(JSON.stringify({fields:A,selectedOptions:j}),Array.from(u))},m=()=>{p.trim()&&d(p.trim())};return e.jsx("div",{style:{marginBottom:12},children:e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:o?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:o?"var(--bg-deep)":"linear-gradient(135deg, rgba(79,110,247,0.04) 0%, var(--bg-deep) 100%)",overflow:"hidden",transition:"border-color 0.2s ease"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",borderBottom:o?"1px solid var(--border-subtle)":"1px solid rgba(79,110,247,0.15)"},children:[e.jsx("div",{style:{width:24,height:24,borderRadius:6,background:o?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:o?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),e.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:o?"var(--text-muted)":"var(--accent)",flex:1},children:o?"已回答":"向你提问"}),s&&!o&&e.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:10,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:500},children:"可多选"})]}),e.jsx("div",{style:{padding:"12px 14px 8px",fontSize:13,color:"var(--text-primary)",lineHeight:1.6,fontWeight:500,whiteSpace:"pre-wrap"},children:t}),o&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),D?"配置已提交(敏感字段已隐藏)":a]}),S&&!o&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[r.map((j,A)=>{const P=u.has(A);return e.jsxs("button",{onClick:()=>H(A),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:P?"var(--accent)":"var(--border-subtle)",background:P?"rgba(79,110,247,0.06)":"var(--bg-surface)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-body)",transition:"all 0.15s ease",width:"100%"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:s?4:8,border:`2px solid ${P?"var(--accent)":"var(--border-subtle)"}`,background:P?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:P&&e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:P?600:500,color:P?"var(--text-primary)":"var(--text-secondary)"},children:j.label}),j.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:j.description})]})]},A)}),!D&&e.jsx("button",{onClick:V,disabled:u.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:u.size>0?"var(--accent)":"var(--bg-surface)",color:u.size>0?"white":"var(--text-muted)",cursor:u.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),D&&!o&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[n.map(j=>e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:"var(--text-secondary)"},children:j.label}),e.jsx("input",{type:j.type==="secret"?"password":"text",value:h[j.name]??"",onChange:A=>w(P=>({...P,[j.name]:A.target.value})),placeholder:j.description,autoComplete:j.type==="secret"?"off":void 0,style:{padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none"}}),j.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:j.description})]},j.name)),e.jsx("button",{onClick:_,style:{padding:"8px 16px",borderRadius:8,border:"none",background:"var(--accent)",color:"white",cursor:"pointer",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end"},children:"确认配置"})]}),!o&&!D&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:S?"1px solid var(--border-subtle)":"none",marginTop:S?2:0},children:[e.jsx("input",{type:"text",value:p,onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),m())},placeholder:S?"或输入自定义回答…":"输入你的回答…",style:{flex:1,padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",transition:"border-color 0.15s ease"},onFocus:j=>{j.currentTarget.style.borderColor="var(--accent)"},onBlur:j=>{j.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:m,disabled:!p.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:p.trim()?"var(--accent)":"var(--bg-surface)",color:p.trim()?"white":"var(--text-muted)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})})}const er={systemBase:{label:"系统基础提示",group:"system"},environment:{label:"运行环境",group:"system"},projectContext:{label:"项目上下文",group:"system"},skills:{label:"技能指令",group:"system"},memory:{label:"Memory",group:"system"},embeddedTools:{label:"系统内嵌工具定义",group:"system"},conversationHistory:{label:"历史用户消息",group:"messages"},currentUserMessage:{label:"当前用户消息",group:"messages"},assistantMessages:{label:"AI 历史回复",group:"messages"},compactionSummary:{label:"上下文压缩摘要",group:"messages"},toolCalls:{label:"工具调用",group:"tools"},toolResults:{label:"工具结果",group:"tools"},nativeToolDefinitions:{label:"原生工具定义",group:"tools"},images:{label:"图片",group:"images"},messageOverhead:{label:"协议与消息开销",group:"overhead"}},tr={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},Hr=["system","messages","tools","images","overhead"];function Co(t,r){const n=(t==null?void 0:t.maxTokens)??Math.max(1,r*1e3),s=(t==null?void 0:t.totalTokens)??0,o=Object.fromEntries(Hr.map(d=>[d,0]));for(const d of(t==null?void 0:t.segments)??[]){const u=er[d.category];u&&(o[u.group]+=d.tokens)}const a=Math.min(s/n,1);return{hasUsage:!!t,totalTokens:s,maxTokens:n,ratio:a,percent:Math.round(a*100),groups:Hr.map(d=>({key:d,label:tr[d].label,color:tr[d].color,tokens:o[d]})),details:((t==null?void 0:t.segments)??[]).filter(d=>d.tokens>0).map(d=>{var u,f;return{category:d.category,label:((u=er[d.category])==null?void 0:u.label)??d.category,color:tr[((f=er[d.category])==null?void 0:f.group)??"overhead"].color,tokens:d.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function ur(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function Vr(t,r){return r?`${t.percent}%`:t.hasUsage?`${ur(t.totalTokens)} / ${ur(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Io({usage:t,contextWindowK:r,compact:n=!1}){const[s,o]=c.useState(!1),[a,d]=c.useState(null),u=c.useRef(null),f=c.useMemo(()=>Co(t,r),[t,r]),p=f.ratio>=.85?"var(--danger)":f.ratio>=.6?"#f59e0b":"var(--accent)",b=typeof window>"u"?1024:window.innerWidth;return e.jsxs("div",{className:"context-usage-ribbon",style:{position:"relative",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("button",{className:"context-usage-ribbon__button",ref:u,type:"button",onClick:()=>{var w;const h=((w=u.current)==null?void 0:w.getBoundingClientRect())??null;d(h),o(S=>!S)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:n?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"context-usage-ribbon__ring",width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:"currentColor",strokeWidth:"4",opacity:"0.14"}),e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:f.hasUsage?p:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${f.ratio*62.832} 62.832`,transform:"rotate(-90 14 14)"})]}),e.jsx("span",{className:"context-usage-ribbon__summary context-usage-ribbon__summary--compact",children:Vr(f,!0)})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"context-usage-ribbon__label",style:{fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap"},children:"上下文"}),e.jsx("div",{className:"context-usage-ribbon__meter",style:{flex:1,height:6,borderRadius:999,overflow:"hidden",background:"rgba(0,0,0,0.06)",display:"flex"},children:f.groups.map(h=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(h.tokens/f.maxTokens*100,100))}%`,background:h.color,opacity:h.key==="overhead"?.65:1,minWidth:h.tokens>0?1:0}},h.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:f.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:Vr(f,!1)})]})}),s&&a&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>o(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:n?Math.min(Math.max(8,a.left),Math.max(8,b-Math.min(340,b-16)-8)):Math.max(8,a.left),top:a.top-8,transform:"translateY(-100%)",width:Math.min(n?340:a.width,b-16),maxHeight:"min(520px, calc(100vh - 32px))",overflowY:"auto",zIndex:9999,padding:12,borderRadius:12,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-lg)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)"},children:"完整请求上下文估算"}),e.jsx("div",{style:{fontSize:11,color:f.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:f.hasUsage?`${f.percent}%`:"暂无"})]}),f.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:f.requestLabel}),f.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:f.details.map(h=>{const w=f.totalTokens>0?Math.round(h.tokens/f.totalTokens*100):0;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:h.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:h.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[ur(h.tokens)," · ",w,"%"]})]},h.category)})}):e.jsx("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:"发送第一条消息后,将显示最新一次模型请求的完整上下文组成。"}),e.jsx("div",{style:{marginTop:10,fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:"基于最新一次实际发送前请求的完整组成估算,包含系统提示、环境、项目上下文、技能、memory、历史消息、工具定义/调用/结果、图片和压缩摘要。不同模型的 tokenizer 与协议存在差异,因此不是账单精确值。"})]})]})]})}function qr(){return e.jsxs("div",{className:"agent-activity-indicator",role:"status","aria-live":"polite",children:[e.jsx("span",{children:"思考中"}),e.jsx("span",{className:"agent-activity-dots","aria-hidden":"true",children:[0,1,2].map(t=>e.jsx("span",{style:{animationDelay:`${t*.16}s`}},t))})]})}function Ro({sections:t,streaming:r=!1,renderContent:n}){const s=c.useMemo(()=>[...t].sort((d,u)=>d.sectionIndex-u.sectionIndex).map(d=>d.text.trim()).filter(Boolean).join(`
17
-
18
- `),[t]),[o,a]=c.useState(r);return c.useEffect(()=>{a(r)},[r]),s?e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":o,onClick:()=>a(d=>!d),children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{children:"思考摘要"}),r&&e.jsx("span",{className:"reasoning-summary__live",children:"生成中"})]}),o&&e.jsx("div",{className:"reasoning-summary__content",children:n(s)})]}):null}function Ao({appearanceOpen:t,settingsOpen:r,hideToBackgroundTitle:n="隐藏到后台",onHideToBackground:s,onToggleAppearance:o,onOpenSettings:a}){return e.jsxs("div",{className:"chat-header-actions",children:[e.jsx("button",{type:"button",onClick:s,title:n,"aria-label":"隐藏后台",className:"ui-icon-button chat-header-action chat-header-action--background",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"m9 11 3 3 3-3M12 7v7M8 21h8"})]})}),e.jsx("button",{type:"button",onClick:d=>o(d.currentTarget.getBoundingClientRect()),title:"皮肤与布局","aria-label":"皮肤与布局","aria-expanded":t,className:`ui-icon-button chat-header-action chat-header-action--appearance ${t?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]})}),e.jsx("button",{type:"button",onClick:a,title:"设置","aria-label":"设置","aria-expanded":r,className:`ui-icon-button chat-header-action chat-header-action--settings ${r?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]})}const To={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function zo(t){const{title:r="视频工作台",shots:n=[],status:s="generating",composedVideoUrl:o}=t,[a,d]=c.useState(!1),[u,f]=c.useState(null);return e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-surface)",overflow:"hidden",maxWidth:600},children:[e.jsxs("div",{onClick:()=>d(!a),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:a?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",r]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[n.filter(p=>p.status==="done").length,"/",n.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:a?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!a&&e.jsxs("div",{style:{padding:"12px 16px"},children:[e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13,marginBottom:12},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"var(--bg-deep)"},children:[e.jsx("th",{style:jn,children:"#"}),e.jsx("th",{style:{...jn,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:jn,children:"时长"}),e.jsx("th",{style:jn,children:"状态"}),e.jsx("th",{style:jn,children:"预览"})]})}),e.jsx("tbody",{children:n.map(p=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:kn,children:p.index}),e.jsx("td",{style:{...kn,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.description,children:p.description}),e.jsxs("td",{style:kn,children:[p.duration,"s"]}),e.jsxs("td",{style:kn,children:[To[p.status]??"⏳",p.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:p.error,children:"!"})]}),e.jsx("td",{style:kn,children:p.videoUrl?e.jsx("button",{onClick:()=>f(p.videoUrl),style:{background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:6,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"▶ 播放"}):p.previewImageUrl?e.jsx("img",{src:p.previewImageUrl,alt:`shot-${p.index}`,style:{width:48,height:32,objectFit:"cover",borderRadius:4,border:"1px solid var(--border-subtle)"}}):e.jsx("span",{style:{color:"var(--text-muted)",fontSize:11},children:"—"})})]},p.index))})]}),u&&e.jsx("video",{src:u,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),o&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"完整视频"}),e.jsx("video",{src:o,controls:!0,style:{width:"100%",borderRadius:8,border:"1px solid var(--border-subtle)"}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[s==="generating"&&e.jsx("span",{children:"🔄 生成中..."}),s==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),s==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),s==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const jn={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},kn={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},Mo={storyboard_workbench:zo};function Lo(t,r,n){return!t||r!==t?!1:n===null||n===t}function Eo(t,r,n=Date.now()){return!t||t.sessionId!==r?t:{...t,until:n+9e4}}async function Wo(t){const{text:r,projectId:n,createSession:s,activateSession:o,showUserMessage:a,onSessionCreated:d,isCancelled:u}=t,f=!t.sessionId;let p=t.sessionId??null;if(!p){const b=await s(r.slice(0,60)||"语音任务",n||void 0);if(u!=null&&u())return null;p=b.id}return o(p),a(r,p),f&&d&&await d(p),p}async function Bo(t){var o,a;const r=((o=t.sessionId)==null?void 0:o.trim())||null,n=!r,s=r??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!s)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(s),t.showUserMessage(t.text,s),n&&await((a=t.onSessionCreated)==null?void 0:a.call(t,s)),s}const No=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/gi;function Po(t){const r=[];let n=0;for(const s of t.matchAll(No)){const o=s.index??0;o>n&&r.push({type:"text",value:t.slice(n,o)}),r.push({type:"link",label:s[1],href:s[2]}),n=o+s[0].length}return n<t.length&&r.push({type:"text",value:t.slice(n)}),r.length>0?r:[{type:"text",value:t}]}function vs(t){var r,n;return t.role==="assistant"&&!!((r=t.toolCalls)!=null&&r.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((n=t.images)!=null&&n.length)&&!t.presentation}function Do(t){return vs(t)&&t.content.trim().length===0}function _o(t){const r=[];for(const n of t){const s=r[r.length-1];if(s&&vs(s)&&Do(n)){r[r.length-1]={...s,toolCalls:[...s.toolCalls,...n.toolCalls],timestamp:n.timestamp};continue}r.push(n)}return r}function Fo(t){const r=[];for(const n of t){const s=ho(n.toolCall.name),o=r[r.length-1];s&&(o==null?void 0:o.action)===s?o.items.push(n):r.push({action:s,items:[n]})}return r}function $o(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function Uo(t){var r,n,s;return t.role==="assistant"&&!!(t.content.trim()||(r=t.toolCalls)!=null&&r.length||(s=(n=t.presentation)==null?void 0:n.reasoning)!=null&&s.length||t.askUser||t.widget)}function Oo(t,r,n){var a;const s=t[r];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(a=s.toolCalls)!=null&&a.length||s.isCompactionSummary)return!1;let o=!n;for(let d=r+1;d<t.length;d++){const u=t[d];if(!u.isCompactionSummary){if($o(u)){o=!0;break}if(Uo(u))return!1}}return o}function Ho(t,r,n){const s=t[r];if(!s)return{showCopy:!1,showSpeak:!1,compact:!1};if(s.role==="user")return{showCopy:!!s.content,showSpeak:!1,compact:!1};const o=Oo(t,r,n);return{showCopy:o,showSpeak:o,compact:s.role==="assistant"&&!o&&!s.isCompactionSummary}}function Kr(t,r){return(t==null?void 0:t.agentType)==="codex"&&(t.occupancy==="owned-externally"||r==="SESSION_OCCUPIED")}async function Vo(t){const r=await t.forkSession(t.sourceSessionId);return t.activateSession(r.id),await t.refreshAndSelect(r.id),r}const nr=50;function rr(t){const n=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(n){const a=parseFloat(n[1]),d=n[2].toLowerCase(),u=d==="s"||d==="sec"||d==="秒"?a*1e3:d==="m"||d==="min"||d==="分"||d==="分钟"?a*6e4:a*36e5;return u>=36e5&&u%36e5===0?`每 ${u/36e5} 小时`:u>=6e4&&u%6e4===0?`每 ${u/6e4} 分钟`:`每 ${u/1e3} 秒`}const[s,o]=t.trim().split(/\s+/);return s==="0"&&o&&o!=="*"&&!o.includes("/")&&!o.includes(",")?`每天 ${o.padStart(2,"0")}:00`:`cron: ${t}`}function qo(t){const r=t.split(/(`[^`\n]+`)/g);return r.length<=1?t:e.jsx(e.Fragment,{children:r.map((n,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.slice(1,-1)},s):e.jsx("span",{children:n},s))})}function Ko(t,r){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,o)=>{const a=`${r}-${o}`;return s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:s.slice(2,-2)},a):s.startsWith("*")&&s.endsWith("*")&&s.length>2?e.jsx("em",{children:s.slice(1,-1)},a):e.jsx("span",{children:s},a)})}function pr(t){return t.split(/(`[^`\n]+`)/g).map((n,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.slice(1,-1)},s):Po(n).map((o,a)=>o.type==="link"?e.jsx("a",{className:"chat-message-link",href:o.href,target:"_blank",rel:"noopener noreferrer",children:o.label},`${s}-${a}`):Ko(o.value,`${s}-${a}`)))}function Go(t){if(t.length<2)return null;const r=a=>a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(d=>d.trim()),n=r(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const o=t.slice(2).map(r);return{headers:n,rows:o}}function Qo(t,r){const n=s=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:s?600:400,color:s?"var(--text-primary)":"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"pre-wrap",wordBreak:"break-word"});return e.jsx("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"auto",background:"var(--bg-surface)"},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"var(--bg-deep)"},children:t.map((s,o)=>e.jsx("th",{style:n(!0),children:pr(s)},o))})}),e.jsx("tbody",{children:r.map((s,o)=>e.jsx("tr",{style:{background:o%2===0?"transparent":"rgba(0,0,0,0.015)"},children:s.map((a,d)=>e.jsx("td",{style:n(!1),children:pr(a)},d))},o))})]})})}function Jo(t,r){return e.jsxs("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"4px 10px",background:"var(--bg-deep)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em"},children:t||"code"}),e.jsx("pre",{style:{margin:0,padding:"10px 12px",fontSize:12,lineHeight:1.6,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto",maxHeight:420},children:r})]})}function sr(t){const r=t.split(`
19
- `),n=[];let s=0,o=0;const a=u=>u.trimStart().startsWith("```"),d=u=>r[u].trimStart().startsWith("|")&&u+1<r.length&&/^\|[\s\-:|]+\|$/.test(r[u+1].trim());for(;s<r.length;){if(a(r[s])){const u=r[s].trim().slice(3).trim();s++;const f=[];for(;s<r.length&&!a(r[s]);)f.push(r[s]),s++;s++,n.push(e.jsx("div",{children:Jo(u,f.join(`
20
- `))},`code-${o++}`));continue}if(d(s)){const u=[];for(;s<r.length&&r[s].trimStart().startsWith("|");)u.push(r[s].trim()),s++;const f=Go(u);f?n.push(e.jsx("div",{children:Qo(f.headers,f.rows)},`tbl-${o++}`)):n.push(e.jsx("span",{children:u.map((p,b)=>e.jsxs("span",{children:[qo(p),b<u.length-1?`
21
- `:null]},b))},`tbl-fb-${o++}`))}else{const u=[];for(;s<r.length&&!d(s)&&!a(r[s]);)u.push(r[s]),s++;u.length>0&&n.push(e.jsx("span",{children:u.map((f,p)=>e.jsxs("span",{children:[pr(f),p<u.length-1?`
22
- `:null]},p))},`txt-${o++}`))}}return e.jsx(e.Fragment,{children:n})}const ys=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Gr=Object.fromEntries(ys.map(t=>[t.value,t.label])),Dn=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function Qr(t){return Dn.some(r=>r.value===t)?t:"full-access"}function Xo({selectedProjectId:t=null,selectedSessionId:r=null,onSessionCreated:n,onMessageSent:s,onSubSessionCreated:o,onSelectSession:a,onSubAgentEvent:d,onRunComplete:u,sessionTitle:f,sessionSummary:p,onOpenSettings:b,settingsOpen:h=!1,onHideToBackground:w,onToggleAppearance:S,appearanceOpen:D=!1,hideToBackgroundTitle:H,voiceCommand:V=null}){var Rr,Ar,Tr;const{messages:_,runningSessionId:m,appendText:j,addMessage:A,setRunningSession:P,setSessionId:R,updateToolResult:C,updateSubAgentStatus:L,updateSubAgentProgress:I,updateMessage:T,setMessages:Q,getMessagesForSession:Z,contextUsageBySession:pe,runtimeProgressBySession:Y,nativeSubagentsBySession:Se,setContextUsage:we,applyRuntimeProgress:nt,setRuntimeProgress:Ut,clearRuntimeProgress:rt,applyNativeSubagentActivity:Xe,setNativeSubagentActivities:Ot,applyReasoningSummary:Ht,clearMessages:st,sessionId:y,todos:$,setTodos:le,cronTasks:ee,setCronTasks:X}=xe(),te=c.useMemo(()=>_o(_),[_]),{isConfigured:Ce,profiles:ge,activeProfileId:ot,switchActiveProfile:In,loadFromSystem:Vt,contextWindow:pt,reasoningEffort:Ye,setField:gt,saveToSystem:Un}=Fn(),[Pe,rn]=c.useState(),[sn,on]=c.useState(),[ht,an]=c.useState(!1),ze=!!(p&&p.agentType!=="customer-agent"),Rn=io(p==null?void 0:p.agentType),ft=(p==null?void 0:p.occupancy)==="owned-externally",An=Pe==="SESSION_OCCUPIED",De=Ce||ze,Mt=De&&!ft&&!An,Ve=c.useRef(new Set),re=r||y,be=!!(re&&(m===re||Ve.current.has(re))),Lt=re?Y[re]??[]:[],Tn=re?Se[re]??{}:{},qt=Js(Lt);c.useEffect(()=>{Vt()},[]),c.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(i=>X(i))},[]);const[Ie,Re]=c.useState(""),[ln,_e]=c.useState(!1),[Fe,dn]=c.useState(!1),[Et,qe]=c.useState(!1),[Ke,xt]=c.useState("full-access"),[cn,it]=c.useState(!1),Ge=c.useRef(null),mt=c.useRef(null);c.useEffect(()=>{if(!Fe)return;const i=g=>{Ge.current&&!Ge.current.contains(g.target)&&dn(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Fe]),c.useEffect(()=>{if(!Et)return;const i=g=>{mt.current&&!mt.current.contains(g.target)&&qe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Et]),c.useEffect(()=>{qe(!1),xt(Qr(p==null?void 0:p.permissionMode))},[ze,r,p==null?void 0:p.permissionMode]);const[un,de]=c.useState(null),[zn,at]=c.useState([]),[Kt,Qe]=c.useState([]),$e=c.useRef(null),Me=c.useRef(null),bt=c.useRef(null),Gt=c.useRef(()=>{}),Ue=c.useRef(null),Ze=c.useRef(null),et=c.useRef(null),Wt=c.useRef(null),Bt=c.useRef(!1),lt=c.useRef(!1),vt=c.useRef(new Set),Qt=c.useRef(null),yt=c.useRef(!1),wt=c.useRef(!1),pn=c.useRef(null),jt=c.useRef(null),[he,Jt]=c.useState(!1),[Ae,Nt]=c.useState(null),[gn,kt]=c.useState(!1),[hn,St]=c.useState(!1),Le=c.useRef(null),Xt=c.useRef(null),fn=c.useRef(null),[tt,xn]=c.useState(null),[On,Mn]=c.useState([]),[mn,Ln]=c.useState([]),[l,k]=c.useState([]),[z,U]=c.useState(null),[M,q]=c.useState(null),[se,Te]=c.useState(new Set),[Oe,K]=c.useState("idle");c.useEffect(()=>{if(!ze||!re){Qt.current=null;return}if(Qt.current!==re){Qt.current=re,Re(uo(re));return}if(yt.current&&Ie===""){yt.current=!1;return}Yn(re,Ie)},[Ie,ze,re]);const ue=()=>{const i=$e.current;i&&(i.scrollTop<=240&&Gt.current(),i.classList.add("is-scrolling"),bt.current!==null&&window.clearTimeout(bt.current),bt.current=window.setTimeout(()=>{i.classList.remove("is-scrolling"),bt.current=null},700))};c.useEffect(()=>()=>{bt.current!==null&&window.clearTimeout(bt.current)},[]),c.useLayoutEffect(()=>{const i=pn.current,g=$e.current;!i||!g||(g.scrollTop=i.scrollTop+(g.scrollHeight-i.scrollHeight),pn.current=null)},[_]);const[J,ve]=c.useState(!1),[Ee,We]=c.useState(null),Be=c.useRef(null);c.useEffect(()=>{const i=window.agentApi;if(!(i!=null&&i.onTtsStart)||!i.onTtsPcm||!i.onTtsStreamEnd||!i.onTtsFlush)return;const g=new no(i),x=[i.onTtsStart(v=>g.start(v)),i.onTtsPcm(({generation:v,pcm:B})=>g.enqueue(v,B)),i.onTtsStreamEnd(({generation:v})=>g.finish(v)),i.onTtsFlush(({generation:v})=>g.flush(v)),i.onTtsEnd(()=>We(null))];return()=>{for(const v of x)v();g.dispose()}},[]);const je=()=>{var x;if(J){(x=Be.current)==null||x.stop(),Be.current=null,ve(!1);return}Wn(window.agentApi,wn);const i=Ie?`${Ie.trimEnd()} `:"",g=Ys({onInterim:v=>Re(i+v),onFinal:v=>{var B;Re(i+v),(B=Xt.current)==null||B.focus()},onError:v=>de(v),onEnd:()=>{ve(!1),Be.current=null}});g&&(Be.current=g,ve(!0))},dt=async(i,g)=>{var x;if(Ee===i){await Wn(window.agentApi,wn),We(null);return}if(await Wn(window.agentApi,wn),!((x=window.agentApi)!=null&&x.ttsSpeak)){de("TTS 模型服务不可用");return}We(i);try{(await window.agentApi.ttsSpeak(g)).ok||(We(null),de("TTS 模型播报失败"))}catch(v){We(null),de(v instanceof Error?v.message:"TTS 模型播报失败")}},He=c.useRef(null),Hn=c.useRef(!1),wr=c.useRef(new Set),bn=c.useRef(r??null),Ct=c.useRef(null),En=c.useRef(0);c.useEffect(()=>{bn.current=r??null},[r]),c.useEffect(()=>{Ct.current=y},[y]),c.useEffect(()=>{rn(void 0),on(void 0),an(!1)},[r]),c.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(i=>Mn(i)),window.agentApi.listSkills().then(i=>Ln(i.filter(g=>g.name))).catch(i=>console.error("[listSkills] mount error:",i)))},[]);const jr=z===null?[]:On.filter(i=>z===""||i.name.toLowerCase().includes(z.toLowerCase())),Vn=M===null?[]:[...[{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(i=>M===""||i.name.toLowerCase().includes(M.toLowerCase())),...mn.filter(i=>M===""||i.name.toLowerCase().includes(M.toLowerCase()))],Cs=i=>{k(g=>g.find(x=>x.id===i.id)?g:[...g,i]),Re(g=>g.replace(/@[\w\u4e00-\u9fff]*$/,"")),U(null),setTimeout(()=>{var g;return(g=Xt.current)==null?void 0:g.focus()},0)},Is=i=>{k(g=>g.filter(x=>x.id!==i))},Rs=i=>{Re(g=>g.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${i.name} `)),q(null),setTimeout(()=>{var g;return(g=Xt.current)==null?void 0:g.focus()},0)},As=i=>{var v,B;Re(i);const g=i.match(/@([\w\u4e00-\u9fff]*)$/);if(g){window.agentApi&&window.agentApi.listAgentDefs().then(G=>Mn(G)),xn(((v=fn.current)==null?void 0:v.getBoundingClientRect())??null),U(g[1]),q(null);return}const x=i.match(/\/([-\w\u4e00-\u9fff]*)$/);if(x){window.agentApi&&window.agentApi.listSkills().then(G=>Ln(G.filter(E=>E.name))).catch(G=>console.error("[listSkills] slash error:",G)),xn(((B=fn.current)==null?void 0:B.getBoundingClientRect())??null),q(x[1]),U(null);return}U(null),q(null)},Ts=i=>{i.key==="Escape"&&(z!==null||M!==null)?(i.preventDefault(),U(null),q(null)):i.key==="Escape"&&be?(i.preventDefault(),Sr()):i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),Ir())},zs=i=>{const g=Array.from(i.target.files??[]);g.length>0&&at(x=>[...x,...g]),i.target.value=""},Ms=i=>{at(g=>g.filter((x,v)=>v!==i))},Ls=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Es=i=>Ls.test(i),Ws=i=>{Qe(g=>[...g,i])},Bs=i=>{Qe(g=>g.filter((x,v)=>v!==i))},Ns=i=>new Promise((g,x)=>{const v=new FileReader;v.onload=()=>g(v.result),v.onerror=x,v.readAsDataURL(i)});c.useEffect(()=>{const i=async g=>{if(!g.clipboardData)return;const x=Array.from(g.clipboardData.items).find(B=>B.type.startsWith("image/"));if(!x)return;g.preventDefault();const v=x.getAsFile();v&&Ws(await Ns(v))};return window.addEventListener("paste",i),()=>window.removeEventListener("paste",i)},[ge,ot]),c.useEffect(()=>{var g;const i=jt.current;jt.current=null,i!=="skip"&&((g=Me.current)==null||g.scrollIntoView({behavior:i==="instant"?"auto":"smooth"}))},[_]),c.useEffect(()=>window.agentApi?window.agentApi.onEvent(g=>Ps(g)):void 0,[y]),c.useEffect(()=>{const i=++En.current,g=r;let x=null;const v=()=>En.current===i&&bn.current===g;return(async()=>{var E,W,F;if(!window.agentApi||Lo(He.current,Ct.current,g))return;if(!g){if(!v())return;st(),de(null),Ue.current=null,Ze.current=null,Nt(null),kt(!1),St(!1),et.current=null,Ct.current=null,R(""),xt("full-access");return}de(null),Nt(null),Ue.current=null,Ze.current=null,kt(!0),St(!1),et.current=g,Ct.current=g,R(g);const G=Z(g);Q(G,g),x=window.setTimeout(()=>{v()&&St(!0)},500);try{const N=await window.agentApi.getSession(g,{limit:nr}),oe=N,ne=Er((N==null?void 0:N.events)??[]),ce=Lr((N==null?void 0:N.events)??[]),ie=Wr((N==null?void 0:N.events)??[]),ye=Jn(N);if(!v())return;xt(Qr((oe==null?void 0:oe.permissionMode)??((E=oe==null?void 0:oe.metadata)==null?void 0:E.permissionMode)));const Pt=((W=N==null?void 0:N.history)==null?void 0:W.nextCursor)??null;Ue.current=Pt,Ze.current=Pt;const vn=Z(g),Yt=vn.length>0&&xe.getState().runningSessionId===g?vn:ye;jt.current="instant",Q(Yt,g),Ut(ce,g),Ot(ie,g),(N==null?void 0:N.agentType)!=="customer-agent"&&(N==null?void 0:N.status)==="running"?(He.current=g,P(g)):He.current===g&&(He.current=null,P(null)),ne&&we(ne,g);const O=Yt[Yt.length-1];if((O==null?void 0:O.role)==="assistant"&&((F=O.toolCalls)!=null&&F.length)){const fe=Ur(O.toolCalls);K(fe?"thinking":"tools")}else K((N==null?void 0:N.agentType)!=="customer-agent"&&(N==null?void 0:N.status)==="running"?"thinking":"idle")}catch(N){if(!v())return;console.error("[chat] failed to restore session",{sessionId:g,error:N}),de(N instanceof Error?N.message:"会话加载失败")}finally{x!==null&&window.clearTimeout(x),v()&&(kt(!1),St(!1))}})(),()=>{x!==null&&window.clearTimeout(x),En.current===i&&(En.current+=1)}},[st,Z,m,r,we,Q,R]);const kr=c.useCallback(async i=>{var g,x;if(!(!window.agentApi||document.visibilityState==="hidden")){if(Wt.current!==i&&(Wt.current=i,Bt.current=!1,lt.current=!1),Bt.current){lt.current=!0;return}Bt.current=!0;try{do{lt.current=!1;const v=await window.agentApi.getSession(i,{limit:nr});if(bn.current!==i||et.current!==i)return;const B=Jn(v),G=Z(i),E=ro(G,B),W=$e.current,F=!W||W.scrollHeight-W.scrollTop-W.clientHeight<80;jt.current=F?null:"skip",Q(E,i);const N=Ze.current,oe=((g=v==null?void 0:v.history)==null?void 0:g.nextCursor)??null;Ue.current===N&&(Ue.current=oe),Ze.current=oe;const ne=Er((v==null?void 0:v.events)??[]);Ut(Lr((v==null?void 0:v.events)??[]),i),Ot(Wr((v==null?void 0:v.events)??[]),i),ne&&we(ne,i);const ce=E[E.length-1];(ce==null?void 0:ce.role)==="assistant"&&((x=ce.toolCalls)!=null&&x.length)?K(Ur(ce.toolCalls)?"thinking":"tools"):K("idle")}while(lt.current)}catch(v){console.error("[chat] failed to refresh native session history",{sessionId:i,error:v})}finally{Wt.current===i&&(Bt.current=!1)}}},[Z,we,Q]);c.useEffect(()=>{const i=r,g=!!(i&&p&&(p==null?void 0:p.agentType)!=="customer-agent"&&m!==i),x=(p==null?void 0:p.occupancy)==="owned-externally"||(p==null?void 0:p.status)==="running";if(!i||!g||!window.agentApi)return;let v=null,B=null,G=!1;const E=()=>{!G&&document.visibilityState!=="hidden"&&kr(i)},W=()=>{v==null||v(),v=null,B!==null&&window.clearInterval(B),B=null},F=()=>{G||B!==null||document.visibilityState==="hidden"||(E(),B=window.setInterval(E,2e3))},N=()=>{if(!(G||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){x&&F();return}try{v=window.agentApi.observeSession(i,E,()=>{v=null,x&&F()})}catch{x&&F()}}},oe=()=>{W(),document.visibilityState!=="hidden"&&(E(),N())};return N(),document.addEventListener("visibilitychange",oe),()=>{G=!0,document.removeEventListener("visibilitychange",oe),W(),Wt.current===i&&(Wt.current=null,lt.current=!1)}},[kr,r,m,p==null?void 0:p.agentType,p==null?void 0:p.occupancy,p==null?void 0:p.status]);const qn=c.useCallback(async()=>{var v;const i=et.current,g=Ue.current;if(!window.agentApi||!i||!g||wt.current)return;wt.current=!0,Nt(null);const x=window.setTimeout(()=>{et.current===i&&wt.current&&Jt(!0)},500);try{const B=await window.agentApi.getSession(i,{before:g,limit:nr});if(et.current!==i||bn.current!==i)return;const G=Jn(B),E=Z(i),W=$e.current;W&&G.length>0&&(pn.current={scrollHeight:W.scrollHeight,scrollTop:W.scrollTop},jt.current="skip");const F=((v=B==null?void 0:B.history)==null?void 0:v.nextCursor)??null;Ue.current=F,G.length>0&&Q([...G,...E],i)}catch(B){if(et.current!==i)return;console.error("[chat] failed to load older history",{sessionId:i,error:B}),Nt(B instanceof Error?B.message:"历史消息加载失败")}finally{window.clearTimeout(x),wt.current=!1,et.current===i&&Jt(!1)}},[Z,Q]);c.useEffect(()=>{Gt.current=()=>{qn()}},[qn]);const Ps=i=>{var B,G;const g=bn.current||Ct.current,x=i._sid||g||void 0;if(i._nativeRunId&&Number.isSafeInteger(i._nativeSequence)){const E=`${i._nativeRunId}:${i._nativeSequence}`;if(vt.current.has(E))return;vt.current.add(E),vt.current.size>2e3&&(vt.current=new Set([...vt.current].slice(-1e3)))}const v=!x||x===g;switch(i.type){case"run_admitted":x&&x===g&&po(x);break;case"context_usage":i.usage&&we(i.usage,x);break;case"text_chunk":i.text&&(j(i.text,x),v&&K("thinking"));break;case"reasoning_summary_delta":typeof i.itemId=="string"&&Number.isSafeInteger(i.sectionIndex)&&typeof i.delta=="string"&&(Ht({type:"reasoning_summary_delta",itemId:i.itemId,sectionIndex:i.sectionIndex,delta:i.delta},x),v&&K("thinking"));break;case"runtime_progress":if(typeof i.progressId=="string"&&typeof i.label=="string"&&["thinking","tool","retry","status"].includes(i.phase??"")){const E={progressId:i.progressId,phase:i.phase,label:i.label,...i.detail===void 0?{}:{detail:i.detail},...i.toolCallId===void 0?{}:{toolCallId:i.toolCallId},...i.elapsedSeconds===void 0?{}:{elapsedSeconds:i.elapsedSeconds},...i.current===void 0?{}:{current:i.current},...i.total===void 0?{}:{total:i.total}};nt(E,x),v&&K(E.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(B=i.activity)!=null&&B.parentToolCallId&&(Xe(i.activity,x),v&&i.activity.status==="running"&&K("tools"));break;case"tool_call":v&&K("tools"),i.toolCall&&i.toolCall.name!=="dispatch_agent"&&i.toolCall.name!=="ask_user"&&i.toolCall.name!=="show_widget"&&A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:i.toolCall.id,name:i.toolCall.name,arguments:i.toolCall.arguments}],timestamp:Date.now()},x);break;case"tool_result":i.result&&C(i.result.toolCallId,i.result.content,i.result.isError,x);break;case"todo_update":i.todos&&le(i.todos);break;case"cron_update":i.tasks&&X(i.tasks);break;case"agent_dispatch":if(A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:i.agentName,task:i.task??"",subSessionId:i.subSessionId}}],timestamp:Date.now()},x),i.subSessionId){Ve.current.add(i.subSessionId);const E=He.current||y;E&&o&&o(E)}d==null||d({type:"started",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_done":i.subSessionId&&(Ve.current.delete(i.subSessionId),L(i.subSessionId,i.status??"completed",i.status==="failed"?i.error:i.summary,x)),d==null||d({type:i.status==="failed"?"failed":"completed",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_progress":i.subSessionId&&i.text&&I(i.subSessionId,i.text,x);break;case"compacted":A({id:crypto.randomUUID(),role:"assistant",content:i.summary??"",isCompactionSummary:!0,timestamp:Date.now()},x);break;case"show_widget":{const E=i.data??i.widgetData,W={widgetId:i.widgetId,widgetType:i.widgetType,data:E??{}},N=(x?xe.getState().getMessagesForSession(x):xe.getState().messages).find(oe=>{var ne;return((ne=oe.widget)==null?void 0:ne.widgetId)===W.widgetId});N?T(N.id,oe=>({...oe,widget:W}),x):A({id:crypto.randomUUID(),role:"assistant",content:"",widget:W,timestamp:Date.now()},x);break}case"ask_user":if(i.questionId&&(x?xe.getState().getMessagesForSession(x):xe.getState().messages).some(W=>{var F;return((F=W.askUser)==null?void 0:F.questionId)===i.questionId}))break;A({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:i.questionId??"",question:i.question??"",options:i.options,fields:i.fields,multiSelect:i.multiSelect},timestamp:Date.now()},x);break;case"approval_resolved":{if(!i.questionId)break;const W=(x?xe.getState().getMessagesForSession(x):xe.getState().messages).find(F=>{var N;return((N=F.askUser)==null?void 0:N.questionId)===i.questionId});W&&T(W.id,F=>({...F,askUser:F.askUser?{...F.askUser,answered:!0,answer:"已处理"}:F.askUser}),x);break}case"text_done":break;case"thinking":v&&K("thinking");break;case"done":if(rt(x),v&&!xe.getState().messages.some(E=>E.isQueued)&&P(null),v&&(K("idle"),ke.getState().autoSpeak)){const W=[...xe.getState().messages].reverse().find(F=>F.role==="assistant"&&F.content&&!F.isCompactionSummary);W!=null&&W.content&&(G=window.agentApi)!=null&&G.ttsSpeak&&(wn(),window.agentApi.ttsSpeak(W.content.slice(0,600)).then(F=>{F.ok||de("TTS 模型播报失败")}).catch(F=>{de(F instanceof Error?F.message:"TTS 模型播报失败")}))}break;case"error":if(i._preserveActiveRun||rt(x),v){if(i._preserveActiveRun&&x&&(wr.current.add(x),He.current=x,P(x),K("thinking")),i.code==="SESSION_OCCUPIED"){const W=[...x?xe.getState().getMessagesForSession(x):xe.getState().messages].reverse().find(F=>F.role==="user"&&!F.isQueued);on(W==null?void 0:W.content),W!=null&&W.content&&(Re(W.content),x&&Yn(x,W.content)),rn(i.code),de(null)}else{de(i.message??"Unknown error");const W=[...x?xe.getState().getMessagesForSession(x):xe.getState().messages].reverse().find(F=>F.role==="user"&&!F.isQueued);ze&&(W!=null&&W.content)&&(Re(W.content),x&&Yn(x,W.content))}i._preserveActiveRun||(P(null),K("idle"))}break;case"turn_aborted":rt(x),v&&(P(null),K("idle"));break}},Ds=async i=>{var x;if(!re||!((x=window.agentApi)!=null&&x.setSessionPermissionMode)||cn)return;const g=Ke;xt(i),qe(!1),it(!0);try{await window.agentApi.setSessionPermissionMode(re,i)}catch(v){xt(g),de(v instanceof Error?v.message:"权限模式更新失败")}finally{it(!1)}},_s=async()=>{var i;if(!(!re||!((i=window.agentApi)!=null&&i.handoffSession)))try{await window.agentApi.handoffSession(re),de(null)}catch(g){de(g instanceof Error?g.message:"交接到 Desktop 失败")}},Fs=async()=>{var i;if(!(!re||!((i=window.agentApi)!=null&&i.forkSession)||ht)){an(!0);try{await Vo({sourceSessionId:re,forkSession:g=>window.agentApi.forkSession(g),activateSession:g=>{Ct.current=g,R(g)},refreshAndSelect:async g=>{n?await n(g):a==null||a(g)}}),sn&&Re(sn),on(void 0),rn(void 0),de(null)}catch(g){de(g instanceof Error?g.message:"创建会话副本失败")}finally{an(!1)}}},Sr=()=>{Hn.current=!0,window.agentApi&&window.agentApi.abort(re||void 0),He.current=null,P(null),Ve.current.clear()},Cr=async i=>{const g=r||y;if(!g||!window.agentApi)return;const x=xe.getState().messages.find(v=>v.id===i);if(!(!x||!x.isQueued))try{await window.agentApi.steer(x.content,g,x.agentName),T(i,v=>({...v,isQueued:!1,isSteered:!0}))}catch(v){de(v instanceof Error?v.message:"引导失败")}},Kn=async(i,g,x)=>{Hn.current=!1,He.current=g,P(g);try{window.agentApi&&await window.agentApi.run(i.content,g,x,i.agentName,i.images)}catch(v){de(v instanceof Error?v.message:"Agent run failed")}finally{if(wr.current.delete(g)){He.current=g,P(g);return}const B=Hn.current?void 0:xe.getState().messages.find(G=>G.isQueued);B?(T(B.id,G=>({...G,isQueued:!1})),u&&u(t,g),Kn(B,g)):(He.current=null,P(null),u&&u(t,g))}},Ir=async()=>{if(!Ie.trim()||!Mt)return;Wn(window.agentApi,wn),de(null);const i=Ie.trim();if(/^\/loop\b/i.test(i)){const E=i.slice(5).trim();if(Re(""),A({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),/^stop$/i.test(E)){window.agentApi&&(await window.agentApi.cronDeleteAll(),X([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(E)||E===""){if(window.agentApi){const ne=await window.agentApi.cronList();X(ne);const ce=ne.length===0?"当前没有定时任务。":ne.map((ie,ye)=>`**${ye+1}.** \`${ie.id.slice(0,6)}\` · ${rr(ie.cron)} · ${ie.enabled?"▶ 启用":"⏸ 已暂停"}
23
- ${ie.prompt}`).join(`
24
-
25
- `);A({id:crypto.randomUUID(),role:"assistant",content:ce,timestamp:Date.now()})}return}const W=E.match(/^(?:pause|暂停)\s+(\S+)$/i);if(W){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(W[1])),ce=await window.agentApi.cronPause((ne==null?void 0:ne.id)??W[1]);if(ce){const ie=await window.agentApi.cronList();X(ie),A({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${ce.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${W[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const F=E.match(/^(?:resume|恢复)\s+(\S+)$/i);if(F){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(F[1])),ce=await window.agentApi.cronResume((ne==null?void 0:ne.id)??F[1]);if(ce){const ie=await window.agentApi.cronList();X(ie),A({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${ce.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${F[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const N=E.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(N){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(N[1]));if(await window.agentApi.cronDelete((ne==null?void 0:ne.id)??N[1])){const ie=await window.agentApi.cronList();X(ie),A({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${N[1]}\` 已删除。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${N[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const oe=E.match(/^(\S+)\s+(.+)$/s);if(oe){const ne=oe[1],ce=oe[2].trim();if(window.agentApi){let ie=r||y;if(!ie){const ye=await window.agentApi.createSession(ce.slice(0,60)||"定时任务",t||void 0);ie=ye.id,R(ye.id),n&&await n(ye.id)}try{const ye=await window.agentApi.cronCreate(ne,ce,{sessionId:ie}),Pt=await window.agentApi.cronList();X(Pt),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${ye.id.slice(0,6)}\`),${rr(ne)}执行:${ce}`,timestamp:Date.now()})}catch(ye){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${ye instanceof Error?ye.message:String(ye)}`,timestamp:Date.now()})}}return}A({id:crypto.randomUUID(),role:"assistant",content:"**定时任务用法:**\n- `/loop <间隔/cron> <任务>` — 创建,如 `/loop 5m 检查系统状态` 或 `/loop 0 9 * * * 早报`\n- `/loop list` — 查看所有定时任务\n- `/loop pause <id>` — 暂停\n- `/loop resume <id>` — 恢复\n- `/loop delete <id>` — 删除\n- `/loop stop` — 删除全部\n\n间隔支持:`30s`、`5m`、`2h`;也支持 5 字段 cron 表达式。",timestamp:Date.now()});return}const g=i.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(g){const E=g[1]+g[2],W=g[3].trim();if(W&&window.agentApi){let F=r||y;if(!F){const N=await window.agentApi.createSession(W.slice(0,60)||"定时任务",t||void 0);F=N.id,R(N.id),n&&await n(N.id)}try{const N=await window.agentApi.cronCreate(E,W,{sessionId:F}),oe=await window.agentApi.cronList();X(oe),Re(""),A({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${N.id.slice(0,6)}\`),${rr(E)}执行:${W}`,timestamp:Date.now()})}catch(N){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${N instanceof Error?N.message:String(N)}`,timestamp:Date.now()})}return}}const x=(()=>{const E=Ie.trim().match(/^\/([\w-]+)\s*(.*)$/);if(E){const W=E[1],F=E[2].trim(),N=mn.find(oe=>oe.name===W);if(N)return F?`请使用「${N.name}」技能协助完成:${F}(技能说明:${N.description})`:`请使用「${N.name}」技能协助:${N.description}`}return Ie.trim()})(),v=l.length>0?l.map(E=>E.name).join(", "):void 0,B=Kt.length>0?[...Kt]:void 0,G=l.map(E=>E.id);if(k([]),ze&&(r||y)&&(yt.current=!0),Re(""),at([]),Qe([]),be){A({id:crypto.randomUUID(),role:"user",content:x,timestamp:Date.now(),agentName:v,images:B,isQueued:!0});return}le([]);try{const E=await Bo({text:x,projectId:t??null,sessionId:r||y,createSession:async(W,F)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(W,F)},activateSession:W=>{Ct.current=W,R(W),He.current=W,P(W)},showUserMessage:(W,F)=>A({id:crypto.randomUUID(),role:"user",content:W,timestamp:Date.now(),agentName:v,images:B},F),onSessionCreated:n});s&&s(E,x),await Kn({content:x,agentName:v,images:B},E,G.length>0?G:void 0)}catch(E){de(E instanceof Error?E.message:"Agent run failed")}};return c.useEffect(()=>{if(!V||!window.agentApi)return;const{text:i,projectId:g,sessionId:x}=V;let v=!1;return(async()=>{try{le([]);const B=await Wo({text:i,projectId:g,sessionId:x,createSession:async(G,E)=>await window.agentApi.createSession(G,E),activateSession:G=>{Ct.current=G,R(G),He.current=G,P(G)},showUserMessage:(G,E)=>A({id:crypto.randomUUID(),role:"user",content:G,timestamp:Date.now()},E),onSessionCreated:n,isCancelled:()=>v});if(!B)return;s&&s(B,i),await Kn({content:i},B)}catch(B){de(B instanceof Error?B.message:"语音指令执行失败")}})(),()=>{v=!0}},[V==null?void 0:V.nonce]),e.jsxs("div",{className:"chat-view chat-view--codex-history",style:{display:"flex",flexDirection:"column",height:"100%",maxWidth:"var(--chat-max-width)",margin:"0 auto"},children:[e.jsxs("div",{className:"chat-top-bar",style:{display:"flex",alignItems:"center",padding:"var(--chat-header-padding)",height:"var(--chat-header-height)",flexShrink:0,borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"no-drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:f?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:f||"会话"}),b&&w&&S&&e.jsx(Ao,{appearanceOpen:D,settingsOpen:h,hideToBackgroundTitle:H,onHideToBackground:w,onToggleAppearance:S,onOpenSettings:b})]}),e.jsxs("div",{ref:$e,className:"chat-messages",onScroll:ue,style:{flex:1,overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[_.length>0&&(he||Ae)&&e.jsx("div",{className:"chat-history-page-status",role:Ae?"alert":"status",style:{position:"absolute",top:8,left:"50%",transform:"translateX(-50%)",zIndex:2,minHeight:32,display:"flex",alignItems:"center",justifyContent:"center",gap:7,color:Ae?"var(--danger)":"var(--text-muted)",fontSize:12},children:he?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载更早消息"})]}):e.jsxs("button",{type:"button",onClick:()=>void qn(),className:"chat-history-retry",style:{border:"1px solid color-mix(in srgb, var(--danger) 30%, transparent)",background:"color-mix(in srgb, var(--danger) 7%, transparent)",color:"var(--danger)",borderRadius:6,padding:"5px 10px",cursor:"pointer",fontSize:12},children:[Ae,",点击重试"]})}),_.length===0&&gn&&hn&&e.jsxs("div",{className:"chat-history-initial-loading",role:"status",style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:9,color:"var(--text-muted)",fontSize:13},children:[e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载历史消息"})]}),_.length===0&&!gn&&!un&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:16},children:[e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"linear-gradient(135deg, var(--accent-dim) 0%, transparent 100%)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:28,color:"var(--accent)",marginBottom:8},children:"◇"}),e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:26,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"智能助手"}),e.jsx("p",{style:{fontSize:14,color:"var(--text-muted)",textAlign:"center",lineHeight:1.7},children:De?"有什么我能帮你的?工具、记忆和技能随时待命。":"请先在设置中配置 API Key 以开始使用。"})]}),te.map((i,g)=>{var ce,ie,ye,Pt,vn,Gn,Yt;const x=i;if(x.isQueued)return null;const v=i.role==="user",B=Ho(te,g,be);if(x.isCompactionSummary)return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,margin:"20px 0",color:"var(--text-muted)",fontSize:12},children:[e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",borderRadius:20,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:11,cursor:"default",userSelect:"none"},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"17 1 21 5 17 9"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("polyline",{points:"7 23 3 19 7 15"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),"上下文已压缩"]}),e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}})]},i.id);if(x.widget){const O=Mo[x.widget.widgetType];return O?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(O,{...x.widget.data,widgetId:x.widget.widgetId})},i.id):e.jsx("div",{style:{marginBottom:16,padding:12,borderRadius:8,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono, monospace)",fontSize:12,whiteSpace:"pre-wrap",maxHeight:300,overflow:"auto"},children:JSON.stringify(x.widget.data,null,2)},i.id)}if(x.askUser)return e.jsx(So,{questionId:x.askUser.questionId,question:x.askUser.question,options:x.askUser.options,fields:x.askUser.fields,multiSelect:x.askUser.multiSelect,answered:x.askUser.answered,answer:x.askUser.answer,onAnswer:(O,fe)=>{var Ne;T(i.id,ae=>({...ae,askUser:{...ae.askUser,answered:!0,answer:O}})),(Ne=window.agentApi)==null||Ne.answerQuestion(x.askUser.questionId,O,fe)}},i.id);const G=x.agentName?x.agentName.charAt(0).toUpperCase():"你",E=!v&&g===te.length-1,W=be&&E&&Oe!=="tools"&&!qt,F=te[g+1],N=F&&F.role!==i.role&&!F.isCompactionSummary,oe=(i.toolCalls??[]).map((O,fe)=>{let Ne;if(O.name==="write_file"&&O.arguments.file_path){const ae=O.arguments.file_path;e:for(let Je=g;Je>=0;Je--){const It=te[Je].toolCalls;if(!It)continue;const ct=Je===g?fe-1:It.length-1;for(let Dt=ct;Dt>=0;Dt--){const ut=It[Dt];if(ut.name==="read_file"&&ut.arguments.file_path===ae&&ut.result&&!ut.isError){Ne=ut.result;break e}}}}return{toolCall:O,beforeContent:Ne,progress:Qs(Lt,O.id),nativeSubagent:Tn[O.id]}}),ne=Fo(oe);return e.jsxs("div",{className:`chat-message-group${B.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:B.compact?0:N?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:[W&&e.jsx("div",{className:"chat-message-activity",style:{display:"flex",marginBottom:4},children:e.jsx(qr,{})}),e.jsxs("div",{className:`chat-message-row chat-message-row--${v?"user":"assistant"}`,style:{display:"flex",flexDirection:v?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[v?e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--accent)",color:"#fff",fontSize:12,fontWeight:700,letterSpacing:0,userSelect:"none"},children:G}):e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("path",{d:"M12 11V7"}),e.jsx("circle",{cx:"12",cy:"5",r:"2"}),e.jsx("circle",{cx:"8",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"16",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M8 20h8"})]})}),e.jsxs("div",{className:`chat-message-content chat-message-content--${v?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:v?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${v?"user":"assistant"} ${i.role==="assistant"&&i.content?"message-card":""}`,style:{padding:i.content||v&&((ce=x.images)!=null&&ce.length)?v?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:v?"14px 4px 14px 14px":"4px 14px 14px 14px",background:i.content||v&&((ie=x.images)!=null&&ie.length)?v?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:i.content||v&&((ye=x.images)!=null&&ye.length)?v?"1px solid rgba(79, 110, 247, 0.18)":void 0:"none",fontSize:"var(--chat-bubble-font-size)",lineHeight:"var(--chat-bubble-line-height)",color:"var(--text-primary)",letterSpacing:"0.01em"},children:[i.role==="assistant"&&((Pt=i.presentation)==null?void 0:Pt.reasoning)&&e.jsx(Ro,{sections:i.presentation.reasoning,streaming:be&&g>te.findLastIndex(O=>O.role==="user"),renderContent:sr}),v&&x.agentName?e.jsxs("div",{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:10,fontWeight:700,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:10,padding:"1px 7px 1px 5px",letterSpacing:"0.04em",marginRight:7,verticalAlign:"middle"},children:[e.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),x.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:i.content})]}):i.role==="assistant"&&i.content?(()=>{const fe=i.content.length>500,Ne=se.has(i.id),ae=fe&&!Ne?i.content.slice(0,500):i.content,Je=Ne?"收起全文":`展开全文,还有 ${i.content.length-500} 字`;return e.jsxs("div",{className:fe?"chat-message-long-content":void 0,children:[fe&&e.jsx("button",{type:"button",className:"chat-message-disclosure","aria-expanded":Ne,"aria-label":Je,title:Je,onClick:()=>Te(It=>{const ct=new Set(It);return Ne?ct.delete(i.id):ct.add(i.id),ct}),children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),e.jsxs("div",{className:fe?"chat-message-long-content__body":void 0,style:{whiteSpace:"pre-wrap",wordBreak:"break-word",position:"relative"},children:[v?ae:sr(ae),fe&&!Ne&&e.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:40,background:v?"linear-gradient(transparent, rgba(232, 236, 254, 0.95))":"linear-gradient(transparent, var(--chat-assistant-fade-end))",pointerEvents:"none"}})]})]})})():i.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:v?i.content:sr(i.content)}),v&&x.images&&x.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:i.content?8:0},children:x.images.map((O,fe)=>e.jsx("img",{src:O,alt:`attachment-${fe}`,style:{maxWidth:220,maxHeight:180,objectFit:"cover",borderRadius:6,border:"1px solid var(--border-subtle)",display:"block",cursor:"zoom-in"},onClick:()=>window.open(O,"_blank")},fe))}),v&&((vn=x.presentation)==null?void 0:vn.attachments)&&x.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:x.presentation.attachments.map((O,fe)=>O.dataUrl?e.jsx("img",{className:"chat-message-attachment-image",src:O.dataUrl,alt:O.name,title:O.name,onClick:()=>window.open(O.dataUrl,"_blank")},`${O.name}-${fe}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${O.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:O.name}),e.jsx("span",{children:"图片已失效"})]},`${O.name}-${fe}`))}),v&&((Gn=x.presentation)==null?void 0:Gn.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:x.presentation.rawContent})]}),ne.map(O=>O.action&&O.items.length>1?e.jsx(ko,{items:O.items,onSelectSession:a},`group-${O.items[0].toolCall.id}`):e.jsx(mr,{toolCall:O.items[0].toolCall,beforeContent:O.items[0].beforeContent,progress:O.items[0].progress,nativeSubagent:O.items[0].nativeSubagent,onSelectSession:a},O.items[0].toolCall.id)),(()=>{const O=(i.toolCalls??[]).filter(ae=>ae.name==="write_file"&&ae.result&&!ae.isError);if(O.length===0)return null;const fe=new Map;for(const ae of O){const Je=ae.arguments.file_path??"",It=ae.arguments.content??"",ct=It?It.split(`
26
- `).length:0;let Dt=0;e:for(let ut=g;ut>=0;ut--){const zr=te[ut].toolCalls??[];for(let Qn=zr.length-1;Qn>=0;Qn--){const yn=zr[Qn];if(yn.name==="read_file"&&yn.arguments.file_path===Je&&yn.result&&!yn.isError){Dt=yn.result.split(`
27
- `).length;break e}}}fe.set(Je,{path:Je,lines:ct,added:Math.max(0,ct-Dt),removed:Math.max(0,Dt-ct)})}const Ne=[...fe.values()];return e.jsxs("div",{style:{marginTop:10,padding:"8px 12px",borderRadius:8,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)",display:"flex",flexWrap:"wrap",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",flexShrink:0},children:"变更汇总"}),Ne.map(ae=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:"var(--font-mono)",background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"2px 8px"},children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:ae.path,children:ae.path.replace(/\\/g,"/").split("/").pop()}),ae.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",ae.added]}),ae.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",ae.removed]}),ae.added===0&&ae.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[ae.lines,"行"]})]},ae.path))]})})()]}),(B.showCopy||B.showSpeak)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[B.showSpeak&&typeof((Yt=window.agentApi)==null?void 0:Yt.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>dt(i.id,i.content),title:Ee===i.id?"停止播报":"语音播报","aria-label":Ee===i.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${Ee===i.id?"is-active":""}`,children:Ee===i.id?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]})}),B.showCopy&&e.jsx("button",{type:"button",onClick:()=>{lo(i.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),e.jsx("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]})})]}),v&&(x.isQueued||x.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[x.isQueued&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--text-muted)",padding:"2px 8px",borderRadius:20,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"排队中"]}),Rn&&e.jsxs("button",{onClick:()=>void Cr(i.id),title:"将此消息引导到当前对话",style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)",padding:"2px 10px",borderRadius:20,border:"1px solid rgba(79,110,247,0.3)",background:"var(--accent-dim)",cursor:"pointer",transition:"all 0.15s",fontFamily:"var(--font-body)"},onMouseEnter:O=>{O.currentTarget.style.background="rgba(79,110,247,0.18)",O.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:O=>{O.currentTarget.style.background="var(--accent-dim)",O.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"}),e.jsx("path",{d:"M12 3v18",opacity:"0.3"})]}),"引导"]})]}),x.isSteered&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--success)",padding:"2px 8px",borderRadius:20,background:"rgba(34,197,94,0.08)",border:"1px solid rgba(34,197,94,0.2)"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"已引导"]})]})]})]})]},i.id)}),be&&qt&&e.jsx(gs,{progress:qt}),be&&!qt&&Oe!=="tools"&&_.length>0&&_[_.length-1].role==="user"&&!_[_.length-1].isQueued&&e.jsx("div",{style:{display:"flex",alignItems:"flex-start",padding:"4px 0 4px",animation:"fadeInUp 0.3s var(--ease-out)"},children:e.jsx(qr,{})}),un&&e.jsx("div",{style:{padding:12,margin:"8px 0",borderRadius:"var(--radius-sm)",background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",color:"var(--danger)",fontSize:13,animation:"fadeIn 0.2s var(--ease-out)",fontFamily:"var(--font-mono)"},children:un}),e.jsx("div",{ref:Me})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[(ft||An)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:9,padding:"8px 10px",border:"1px solid var(--border-default)",borderRadius:6,background:"var(--bg-surface)",color:"var(--text-muted)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2"}),e.jsx("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]}),e.jsx("span",{style:{flex:1},children:Kr(p,Pe)?"此会话仍由原客户端持有,可创建副本继续。":`此会话正在被 ${(p==null?void 0:p.sourceLabel)||"原客户端"} 使用,当前只读;原客户端释放后会自动恢复输入。`}),Kr(p,Pe)&&e.jsx("button",{type:"button",onClick:()=>void Fs(),disabled:ht,style:{flexShrink:0,border:"1px solid var(--border-default)",borderRadius:5,padding:"5px 9px",background:"var(--bg-workspace)",color:"var(--text-primary)",fontSize:12,fontWeight:600,cursor:ht?"wait":"pointer",opacity:ht?.65:1},children:ht?"正在创建…":"以副本继续"})]}),$.length>0&&e.jsxs("div",{style:{marginBottom:10,padding:"8px 12px",borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-sm)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,marginBottom:6,fontSize:10,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),"任务列表"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(()=>{const i=new Set($.filter(g=>g.status==="completed").map(g=>g.title.toLowerCase()));return $.map(g=>{const x=g.status==="pending",v=g.status==="in-progress",B=g.status==="completed",G=x&&(g.dependsOn??[]).some(E=>!i.has(E.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:B?.65:1,transition:"opacity 0.3s"},children:[e.jsxs("div",{style:{width:16,height:16,borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:B?"rgba(52,211,153,0.15)":v?"var(--accent-dim)":G?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:B?"1.5px solid rgba(52,211,153,0.6)":v?"1.5px solid var(--accent)":G?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[B&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(52,211,153,0.9)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})}),v&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),G&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(239,68,68,0.8)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})}),x&&!G&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:B?"var(--text-muted)":G?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:B?"line-through":"none",flex:1},children:g.title}),G&&e.jsx("span",{title:`等待: ${(g.dependsOn??[]).join(", ")}`,style:{fontSize:10,color:"rgba(239,68,68,0.9)",background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:"等待前置"}),g.agentName&&e.jsxs("span",{style:{fontSize:10,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.2)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:["@",g.agentName]})]},g.id)})})()})]}),ee.length>0&&e.jsxs("div",{style:{marginBottom:10,borderRadius:10,background:"var(--bg-surface)",border:"1px solid rgba(251,191,36,0.25)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderBottom:"1px solid rgba(251,191,36,0.15)",background:"rgba(251,191,36,0.06)"},children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#d97706",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",textTransform:"uppercase",letterSpacing:"0.07em",flex:1},children:"定时任务"}),e.jsx("button",{onClick:async()=>{window.agentApi&&(await window.agentApi.cronDeleteAll(),X([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}))},title:"删除全部",style:{background:"none",border:"1px solid rgba(251,191,36,0.35)",borderRadius:6,color:"#d97706",cursor:"pointer",padding:"1px 7px",fontSize:10},children:"全部删除"})]}),ee.map(i=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:i.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:i.enabled?"#22c55e":"#9ca3af",boxShadow:i.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:i.enabled?"pulse 2s ease-in-out infinite":"none"}}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.25)",borderRadius:6,padding:"1px 6px",flexShrink:0,fontFamily:"var(--font-mono)"},children:i.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.label||i.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:i.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[i.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="#d97706",g.currentTarget.style.color="#d97706"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="#22c55e",g.currentTarget.style.color="#22c55e"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="var(--danger)",g.currentTarget.style.color="var(--danger)"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},i.id))]}),zn.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:zn.map((i,g)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"3px 10px 3px 8px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.18)",fontSize:12,color:"var(--accent)",maxWidth:220},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),e.jsx("button",{onClick:()=>Ms(g),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,marginLeft:2,fontSize:13,lineHeight:1,display:"flex"},children:"✕"})]},g))}),Kt.length>0&&(()=>{const i=ge.find(x=>x.id===ot),g=!i||!Es(i.modelId);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[g&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:"rgba(234,179,8,0.1)",border:"1px solid rgba(234,179,8,0.4)",color:"rgba(202,138,4,1)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"当前模型(",(i==null?void 0:i.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Kt.map((x,v)=>e.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[e.jsx("img",{src:x,alt:`image-${v}`,style:{width:72,height:72,objectFit:"cover",borderRadius:8,border:"1.5px solid var(--border-default)",display:"block"}}),e.jsx("button",{onClick:()=>Bs(v),style:{position:"absolute",top:-6,right:-6,width:18,height:18,borderRadius:"50%",background:"var(--danger, #e53e3e)",border:"none",color:"#fff",fontSize:11,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},children:"✕"})]},v))})]})})(),(()=>{const i=_.filter(g=>g.isQueued);return i.length===0?null:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8,padding:"8px 12px",borderRadius:12,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,fontWeight:600,color:"var(--text-muted)",letterSpacing:"0.03em"},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M3 9h18"}),e.jsx("path",{d:"M9 21V9"})]}),"排队消息(",i.length,")"]}),i.map(g=>{const x=g,v=x.content.length>80?x.content.slice(0,80)+"…":x.content;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 8px",borderRadius:8,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{flex:1,fontSize:13,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:[x.agentName&&e.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"var(--accent-dim)",borderRadius:10,padding:"1px 5px",marginRight:5,verticalAlign:"middle"},children:["@",x.agentName]}),v]}),Rn&&e.jsxs("button",{onClick:()=>void Cr(g.id),title:"将此消息引导到当前对话",style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:11,fontWeight:600,color:"var(--accent)",padding:"3px 10px",borderRadius:20,border:"1px solid rgba(79,110,247,0.3)",background:"var(--accent-dim)",cursor:"pointer",transition:"all 0.15s",fontFamily:"var(--font-body)",whiteSpace:"nowrap",flexShrink:0},onMouseEnter:B=>{B.currentTarget.style.background="rgba(79,110,247,0.18)",B.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:B=>{B.currentTarget.style.background="var(--accent-dim)",B.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"}),e.jsx("path",{d:"M12 3v18",opacity:"0.3"})]}),"引导"]})]},g.id)})]})})(),e.jsx("div",{ref:fn,style:{position:"relative"},children:e.jsx("div",{className:"composer-shell",style:{display:"flex",flexDirection:"column",gap:0,background:"var(--bg-surface)",borderRadius:14,overflow:"visible"},children:e.jsxs("div",{className:"composer-input-row",style:{display:"flex",alignItems:"center",gap:8,padding:"var(--composer-row-padding)"},children:[e.jsx("input",{ref:Le,type:"file",multiple:!0,style:{display:"none"},onChange:zs}),l.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:l.map(i=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"2px 7px 2px 6px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.25)",fontSize:12,color:"var(--accent)",flexShrink:0,whiteSpace:"nowrap"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),"@",i.name,e.jsx("button",{onClick:()=>Is(i.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},i.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:Xt,rows:3,value:Ie,onChange:i=>As(i.target.value),onBlur:()=>setTimeout(()=>{U(null),q(null)},120),onKeyDown:Ts,placeholder:ft?"原客户端使用中,当前只读":De?be?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!Mt}),e.jsxs("div",{className:"web-native-composer-toolbar",children:[e.jsxs("div",{className:"web-native-add-wrap",children:[e.jsx("button",{type:"button",className:"web-native-add-button","aria-label":"添加附件、图片或语音","aria-expanded":ln,onClick:()=>_e(i=>!i),children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})}),ln&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var i;_e(!1),(i=Le.current)==null||i.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{_e(!1),je()},children:"语音输入"})]})]}),e.jsxs("div",{className:"web-native-permission-wrap",ref:mt,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${Ke}`,"aria-label":`会话权限:${(Rr=Dn.find(i=>i.value===Ke))==null?void 0:Rr.label}`,"aria-haspopup":"menu","aria-expanded":Et,title:`会话权限:${(Ar=Dn.find(i=>i.value===Ke))==null?void 0:Ar.label}`,disabled:!re||cn,onClick:()=>qe(i=>!i),children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),Et&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:Dn.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ke===i.value,className:Ke===i.value?"is-active":"",onClick:()=>{Ds(i.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:Ke===i.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:i.label}),e.jsx("small",{children:i.description})]})]},i.value))})]}),ze&&(p==null?void 0:p.controller)==="web"&&typeof((Tr=window.agentApi)==null?void 0:Tr.handoffSession)=="function"&&e.jsx("button",{type:"button",className:"web-native-runtime-status",onClick:()=>{_s()},title:"交接到 Desktop",children:"交接到 Desktop"}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Io,{usage:re?pe[re]:void 0,contextWindowK:pt,compact:!0})}),e.jsx("label",{className:"web-native-model-control",title:"切换模型",children:e.jsx("select",{"aria-label":"当前模型",value:ze?"":ot,disabled:ze||ge.length===0,onChange:i=>{In(i.target.value)},children:ze?e.jsx("option",{value:"",children:(p==null?void 0:p.agentType)??"本地 Agent"}):ge.length===0?e.jsx("option",{value:"",children:"未配置模型"}):ge.map(i=>e.jsx("option",{value:i.id,children:i.name||i.modelId},i.id))})}),be?e.jsx("button",{type:"button",onClick:Sr,className:"web-native-stop-button","aria-label":"停止生成",title:"停止生成",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):ze?e.jsxs("span",{className:"web-native-agent-status",role:"status","aria-label":"Agent 空闲",title:"Agent 空闲",children:[e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]}),e.jsx("span",{"aria-hidden":"true"})]}):e.jsxs("div",{className:"web-native-effort-wrap",ref:Ge,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Fe,"aria-label":`推理强度:${Gr[Ye]}`,title:`推理强度:${Gr[Ye]}(点击切换)`,onClick:()=>dn(i=>!i),children:e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]})}),Fe&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:ys.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ye===i.value,className:Ye===i.value?"is-active":void 0,onClick:()=>{gt("reasoningEffort",i.value),Un(),dn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Ye===i.value?"✓":""}),i.label]},i.value))})]}),e.jsx("button",{type:"button",onClick:Ir,disabled:!Mt||!Ie.trim(),className:"web-native-send-button","aria-label":be?"排队发送":"发送",title:be?"排队发送":"发送",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 19V5M5 12l7-7 7 7"})})})]})]})})}),e.jsxs("div",{className:"chat-composer-hint",style:{textAlign:"center",marginTop:7,fontSize:11,color:"var(--text-muted)",letterSpacing:"0.03em",opacity:.6},children:["Enter 发送",be?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",J?" · 🎤 正在聆听…":""]})]}),tt&&z!==null&&jr.length>0&&zt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-tt.top+8,left:tt.left,width:tt.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",overflow:"hidden",zIndex:99999},children:[e.jsx("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em"},children:"智能体"}),jr.map(i=>e.jsxs("button",{onMouseDown:g=>{g.preventDefault(),Cs(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:g=>{g.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:g=>{g.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:i.description})]},i.id))]}),document.body),tt&&M!==null&&Vn.length>0&&zt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-tt.top+8,left:tt.left,width:tt.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",zIndex:99999,display:"flex",flexDirection:"column",maxHeight:320},children:[e.jsxs("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",flexShrink:0},children:["技能 (",Vn.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:Vn.map(i=>e.jsxs("button",{onMouseDown:g=>{g.preventDefault(),Rs(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:g=>{g.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:g=>{g.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.description})]},i.name))})]}),document.body)]})}function Yo({status:t,isRunning:r,needsInput:n}){return t==="failed"||t==="error"?"error":r?n?"needs-input":"running":"completed"}const Zo={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function ws(t,r){return t.map((n,s)=>({session:n,index:s})).sort((n,s)=>r(n.session,s.session)||n.index-s.index).map(({session:n})=>n)}function br(t){return ws(t,(r,n)=>n.created.localeCompare(r.created))}function ei(t,r){return ws(br(t),(n,s)=>Number(r(s))-Number(r(n)))}const ti=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Jr={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function Xr(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function ni(){const{maxIterations:t,contextWindow:r,isConfigured:n,profiles:s,activeProfileId:o,setField:a,loadFromSystem:d,saveToSystem:u,addProfile:f,updateProfile:p,deleteProfile:b,switchActiveProfile:h}=Fn(),[w,S]=c.useState(null),[D,H]=c.useState("success"),[V,_]=c.useState(null),[m,j]=c.useState(!1),[A,P]=c.useState(Xr());c.useEffect(()=>{d()},[]);const R=()=>{j(!0),_(null),P(Xr())},C=Y=>{j(!1),_(Y.id),P({name:Y.name,provider:Y.provider,modelId:Y.modelId,apiKey:Y.apiKey,baseUrl:Y.baseUrl})},L=()=>{_(null),j(!1)},I=async()=>{if(!A.name.trim()||!A.apiKey.trim()||!A.modelId.trim()){S("名称、API Key 和模型 ID 为必填项"),H("error");return}m?f(A):V&&p(V,A),_(null),j(!1),S(null),setTimeout(()=>u(),0)},T=async Y=>{b(Y),setTimeout(()=>u(),0)},Q=async Y=>{await h(Y),S("已切换模型"),H("success"),setTimeout(()=>S(null),1500)},Z=async()=>{S(null);try{await u(),S("设置保存成功"),H("success")}catch(Y){S(Y instanceof Error?Y.message:"保存失败"),H("error")}},pe=m||V!==null;return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:640,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"设置"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:36},children:"管理模型提供商和运行参数。工作目录在项目设置中配置。"}),e.jsxs("section",{style:{marginBottom:40},children:[e.jsxs("div",{className:"settings-head-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:14},children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",margin:0},children:"模型提供商"}),e.jsx("button",{onClick:R,style:si,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.length===0&&!pe&&e.jsx("div",{style:{padding:"20px 16px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),s.map(Y=>{const Se=Y.id===o,we=Y.id===V;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${Se?"var(--accent)":"var(--border-default)"}`,background:Se?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{className:"profile-row",style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px"},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",padding:"2px 7px",borderRadius:4,background:Se?"var(--accent)":"var(--bg-deep)",color:Se?"#fff":"var(--text-muted)",flexShrink:0},children:Y.provider}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Y.name||Y.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[Y.modelId," ",Y.baseUrl?`· ${Y.baseUrl}`:""]})]}),Se&&e.jsx("span",{style:{fontSize:11,color:"var(--accent)",fontWeight:600,flexShrink:0},children:"● 使用中"}),e.jsxs("div",{className:"profile-row-actions",style:{display:"flex",gap:6,flexShrink:0},children:[!Se&&e.jsx("button",{onClick:()=>Q(Y.id),style:or,children:"切换"}),e.jsx("button",{onClick:()=>we?L():C(Y),style:or,children:we?"收起":"编辑"}),e.jsx("button",{onClick:()=>T(Y.id),style:{...or,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),we&&e.jsx(Yr,{draft:A,setDraft:P,onSave:I,onCancel:L})]},Y.id)}),m&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--accent)",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"10px 14px 0",fontSize:13,fontWeight:600,color:"var(--accent)"},children:"新建提供商"}),e.jsx(Yr,{draft:A,setDraft:P,onSave:I,onCancel:L})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},children:"常规"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Ft,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:Y=>a("maxIterations",parseInt(Y.target.value)||10),min:1,max:50,style:$t})}),e.jsx(Ft,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:r??100,onChange:Y=>a("contextWindow",parseInt(Y.target.value)||100),min:8,max:2e3,style:$t})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:Z,style:js,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:n?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:n?"var(--success)":"var(--text-muted)",border:`1px solid ${n?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:n?"● 已连接":"○ 未配置"})]}),w&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:D==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:D==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:D==="success"?"var(--success)":"var(--danger)",fontSize:13},children:w})]})}function Yr({draft:t,setDraft:r,onSave:n,onCancel:s}){const o=(a,d)=>r(u=>{const f={...u,[a]:d};return a==="provider"&&!u.modelId&&(f.modelId=Jr[d]??""),f});return e.jsxs("div",{style:{padding:"12px 14px 14px",display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(Ft,{label:"名称",children:e.jsx("input",{value:t.name,onChange:a=>o("name",a.target.value),placeholder:"我的 Claude",style:$t})}),e.jsx(Ft,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:a=>{o("provider",a.target.value),o("modelId",Jr[a.target.value]??"")},style:$t,children:ti.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})})]}),e.jsx(Ft,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:a=>o("modelId",a.target.value),placeholder:"claude-sonnet-4-6",style:$t})}),e.jsx(Ft,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:a=>o("apiKey",a.target.value),placeholder:"sk-...",style:$t})}),e.jsx(Ft,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:a=>o("baseUrl",a.target.value),placeholder:"https://api.anthropic.com",style:$t})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:n,style:js,children:"保存"}),e.jsx("button",{onClick:s,style:ri,children:"取消"})]})]})}function Ft({label:t,children:r}){return e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:"var(--text-secondary)",marginBottom:6,fontWeight:500,textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),r]})}const $t={width:"100%",padding:"9px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",boxSizing:"border-box"},js={padding:"11px 28px",borderRadius:"var(--radius-sm)",border:"1px solid transparent",background:"var(--accent)",color:"var(--text-inverse)",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)",boxShadow:"0 2px 16px var(--accent-glow)",transition:"transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out)"},ri={padding:"11px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:14,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",whiteSpace:"nowrap",transition:"all 0.15s var(--ease-out)"},si={padding:"6px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},or={padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)"},ir={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function oi(){const[t,r]=c.useState([]),[n,s]=c.useState("stdio"),[o,a]=c.useState(ir),[d,u]=c.useState(!1),[f,p]=c.useState({id:!1,command:!1,url:!1}),[b,h]=c.useState({}),[w,S]=c.useState({}),[D,H]=c.useState(new Set),[V,_]=c.useState(null),[m,j]=c.useState(""),[A,P]=c.useState(!1),R=async y=>{var le;if(!((le=window.agentApi)!=null&&le.mcpProbe))return;H(ee=>new Set([...ee,y.id])),S(ee=>{const X={...ee};return delete X[y.id],X});const $=new Promise((ee,X)=>setTimeout(()=>X(new Error("连接超时(15s)")),15e3));try{const ee=await Promise.race([window.agentApi.mcpProbe(y),$]);h(X=>({...X,[y.id]:ee}))}catch(ee){const X=ee instanceof Error?ee.message:String(ee);console.warn(`[MCP] probe failed for ${y.id}:`,X),h(te=>{const Ce={...te};return delete Ce[y.id],Ce}),S(te=>({...te,[y.id]:X})),(y.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(X))&&(j(""),_({server:y}))}finally{H(ee=>{const X=new Set(ee);return X.delete(y.id),X})}};c.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(y=>{r(y),y.filter($=>$.enabled!==!1).forEach($=>R($))}).catch(console.error)},[]);const[C,L]=c.useState(""),[I,T]=c.useState(""),[Q,Z]=c.useState(!1),pe=async()=>{T("");let y;try{y=JSON.parse(C.trim());const $=y.mcpServers??y,le=Object.entries($);if(le.length===0){T("未找到任何服务器");return}Z(!0);const ee=[];for(const[te,Ce]of le){const ge=Ce,ot=ge.name||te,Vt=ge.disabled!==!0;let pt;if(ge.url||ge.type==="streamableHttp"||ge.type==="sse"){const Ye=ge.type==="sse"?"sse":"streamableHttp";pt={id:te,name:ot,transport:Ye,url:ge.url,headers:ge.headers??{},env:ge.env??{},enabled:Vt}}else pt={id:te,name:ot,transport:"stdio",command:ge.command,args:ge.args??[],env:ge.env??{},enabled:Vt};await window.agentApi.mcpSave(pt),ee.push(pt)}const X=await window.agentApi.mcpList();r(X),L(""),ee.filter(te=>te.enabled!==!1).forEach(te=>R(te))}catch($){T($ instanceof Error?$.message:"JSON 解析失败")}finally{Z(!1)}},Y=()=>o.id.trim()!==""&&o.command.trim()!=="",Se=()=>o.id.trim()!==""&&o.url.trim()!=="",we=y=>{const $={};for(const le of y.split(`
28
- `)){const ee=le.indexOf(":");if(ee<1)continue;const X=le.slice(0,ee).trim(),te=le.slice(ee+1).trim();X&&($[X]=te)}return $},nt=async()=>{if(p({id:!0,command:!0,url:!0}),!(n==="stdio"&&!Y())&&!((n==="sse"||n==="streamableHttp")&&!Se())){u(!0);try{const y=n==="sse"||n==="streamableHttp"?we(o.headersRaw):{},$=n==="stdio"?{id:o.id,name:o.name||o.id,transport:"stdio",command:o.command,args:o.args.split(" ").filter(Boolean),enabled:!0}:{id:o.id,name:o.name||o.id,transport:n,url:o.url,headers:y,enabled:!0};await window.agentApi.mcpSave($);const le=await window.agentApi.mcpList();r(le),a(ir),p({id:!1,command:!1,url:!1}),R($)}catch(y){console.error("Failed to save MCP server",y)}finally{u(!1)}}},Ut=async y=>{await window.agentApi.mcpDelete(y),r(t.filter($=>$.id!==y))},rt=async(y,$)=>{await window.agentApi.mcpSetEnabled(y,$),r(t.map(le=>le.id===y?{...le,enabled:$}:le))},Xe=async()=>{if(!(!V||!m.trim())){P(!0);try{const y=V.server.transport==="streamableHttp"?{...V.server,headers:{...V.server.headers??{},Authorization:`Bearer ${m.trim()}`}}:{...V.server,env:{...V.server.env??{},Authorization:`Bearer ${m.trim()}`}};await window.agentApi.mcpSave(y);const $=await window.agentApi.mcpList();r($),_(null),j("");const le=$.find(ee=>ee.id===y.id)??y;R(le)}finally{P(!1)}}},Ot=y=>y==="stdio"?"本地":y==="streamableHttp"?"HTTP":"SSE",Ht=y=>y==="stdio"?"#68d391":y==="streamableHttp"?"#f6ad55":"#63b3ed",st=y=>y==="stdio"?"rgba(154,230,180,0.15)":y==="streamableHttp"?"rgba(246,173,85,0.15)":"rgba(99,179,237,0.15)";return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:660,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"MCP 服务器"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:32},children:"通过模型上下文协议连接外部工具。"}),e.jsxs("div",{style:{padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",marginBottom:28,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:0},children:"添加服务器"}),e.jsx("div",{style:{display:"flex",background:"var(--bg-surface)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden"},children:["stdio","sse","streamableHttp"].map(y=>e.jsx("button",{onClick:()=>{s(y),p({id:!1,command:!1,url:!1}),a($=>({...ir,id:$.id,name:$.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:n===y?"var(--accent)":"transparent",color:n===y?"var(--text-inverse)":"var(--text-muted)"},children:y==="stdio"?"本地 stdio":y==="sse"?"远程 SSE":"HTTP"},y))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.id,onChange:y=>a($=>({...$,id:y.target.value})),onBlur:()=>p(y=>({...y,id:!0})),placeholder:"服务器 ID *",style:{...Rt,...f.id&&!o.id?ar:{}}}),f.id&&!o.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.name,onChange:y=>a($=>({...$,name:y.target.value})),placeholder:"显示名称",style:{...Rt,flex:1}})]}),n==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.command,onChange:y=>a($=>({...$,command:y.target.value})),onBlur:()=>p(y=>({...y,command:!0})),placeholder:"命令(如 npx)*",style:{...Rt,...f.command&&!o.command?ar:{}}}),f.command&&!o.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.args,onChange:y=>a($=>({...$,args:y.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...Rt,flex:2}})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.url,onChange:y=>a($=>({...$,url:y.target.value})),onBlur:()=>p(y=>({...y,url:!0})),placeholder:n==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...Rt,...f.url&&!o.url?ar:{}}}),f.url&&!o.url&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("label",{style:{fontSize:12,color:"var(--text-muted)"},children:"请求头(每行 key: value)"}),e.jsx("textarea",{value:o.headersRaw,onChange:y=>a($=>({...$,headersRaw:y.target.value})),placeholder:`access_token: abc123
29
- Authorization: Bearer sk-...`,rows:3,style:{...Rt,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:nt,disabled:d,style:{alignSelf:"flex-start",padding:"10px 22px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:d?"not-allowed":"pointer",fontFamily:"var(--font-body)"},children:d?"保存中…":"添加服务器"})]})]}),e.jsxs("div",{style:{marginBottom:28,padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:"0 0 8px"},children:"导入 JSON 配置"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",margin:"0 0 10px"},children:"兼容 Claude Desktop / Cursor 格式,粘贴后点导入。"}),e.jsx("textarea",{value:C,onChange:y=>{L(y.target.value),T("")},placeholder:`{
30
- "my-server": {
31
- "command": "npx",
32
- "args": ["-y", "some-mcp"]
33
- }
34
- }`,rows:5,style:{...Rt,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),I&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:I}),e.jsx("button",{onClick:pe,disabled:!C.trim()||Q,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:C.trim()&&!Q?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:C.trim()&&!Q?1:.5},children:Q?"导入中…":"导入"})]}),t.filter(y=>y.transport===n).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",n==="stdio"?"本地 stdio":n==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(y=>y.transport===n).map(y=>e.jsxs("div",{style:{padding:"14px 16px",background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",display:"flex",justifyContent:"space-between",alignItems:"center",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("div",{style:{fontSize:14,fontWeight:500,color:"var(--text-primary)"},children:y.name||y.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:st(y.transport),color:Ht(y.transport),fontWeight:600},children:Ot(y.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[y.transport==="stdio"?`${y.command} ${(y.args??[]).join(" ")}`:y.url,y.transport!=="stdio"&&y.headers&&Object.keys(y.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(y.headers).length," 个请求头"]})]}),D.has(y.id)?e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6,display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",border:"2px solid var(--accent)",borderTopColor:"transparent",animation:"spin 0.8s linear infinite"}}),"探测工具中…"]}):w[y.id]?e.jsxs("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:w[y.id]}),y.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(w[y.id])?e.jsx("button",{onClick:()=>{j(""),_({server:y})},style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid rgba(251,191,36,0.4)",background:"rgba(251,191,36,0.1)",color:"#fbbf24",cursor:"pointer",fontFamily:"var(--font-body)"},children:"输入 Token"}):null,e.jsx("button",{onClick:()=>R(y),style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontFamily:"var(--font-body)"},children:"重试"})]}):b[y.id]&&b[y.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:b[y.id].map($=>e.jsx("span",{title:$.description,style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"rgba(168,85,247,0.12)",color:"#c084fc",border:"1px solid rgba(168,85,247,0.2)",fontFamily:"var(--font-mono)",cursor:"default"},children:$.name},$.name))}):b[y.id]!==void 0?e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6},children:"无可用工具"}):null]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("label",{style:{fontSize:12,color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",gap:4},children:[e.jsx("input",{type:"checkbox",checked:y.enabled!==!1,onChange:$=>rt(y.id,$.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Ut(y.id),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(248,113,113,0.2)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500,transition:"background 0.15s"},onMouseEnter:$=>{$.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:$=>{$.currentTarget.style.background="transparent"},children:"移除"})]})]},y.id))}),V&&e.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},onClick:y=>{y.target===y.currentTarget&&_(null)},children:e.jsxs("div",{style:{width:420,background:"var(--bg-surface)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-default)",padding:28,boxShadow:"0 24px 48px rgba(0,0,0,0.4)"},children:[e.jsx("h3",{style:{margin:"0 0 6px",fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:"需要认证"}),e.jsxs("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-muted)"},children:["服务器 ",e.jsx("strong",{style:{color:"var(--text-primary)"},children:V.server.name||V.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:m,onChange:y=>j(y.target.value),onKeyDown:y=>{y.key==="Enter"&&Xe(),y.key==="Escape"&&_(null)},placeholder:"sk-… 或 Bearer token",style:{...Rt,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>_(null),style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:13,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"}),e.jsx("button",{onClick:Xe,disabled:!m.trim()||A,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:m.trim()&&!A?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:m.trim()&&!A?1:.5},children:A?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const Rt={padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",fontFamily:"var(--font-body)"},ar={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function ii(){const[t,r]=c.useState([]),[n,s]=c.useState(""),[o,a]=c.useState(null),[d,u]=c.useState(!1),[f,p]=c.useState(""),[b,h]=c.useState(""),[w,S]=c.useState("user"),[D,H]=c.useState(""),[V,_]=c.useState(null),[m,j]=c.useState("success"),A=async()=>{if(window.agentApi){const L=await window.agentApi.listMemories();r(L)}};c.useEffect(()=>{A()},[]);const P=async()=>{if(!n.trim()){A();return}if(window.agentApi){const L=await window.agentApi.searchMemories(n);r(L.map(I=>I.entry))}},R=async()=>{if(!(!f.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:f.trim(),description:b,type:w,content:D,created:(o==null?void 0:o.created)??new Date().toISOString(),updated:new Date().toISOString()}),u(!1),a(null),p(""),h(""),H(""),S("user"),_("保存成功"),j("success"),await A()}catch(L){_(L instanceof Error?L.message:"保存失败"),j("error")}},C=L=>{a(L),p(L.name),h(L.description),S(L.type),H(L.content),u(!0)};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"记忆"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginTop:4},children:"跨会话的持久化知识库。"})]}),e.jsx("button",{onClick:()=>{u(!0),a(null),p(""),h(""),H(""),S("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:n,onChange:L=>s(L.target.value),onKeyDown:L=>L.key==="Enter"&&P(),placeholder:"搜索记忆...",style:{flex:1,padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)"}}),e.jsx("button",{onClick:P,style:Zr,children:"搜索"})]}),V&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:m==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:m==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:m==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:V}),d&&e.jsxs("div",{style:{padding:20,marginBottom:24,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("input",{value:f,onChange:L=>p(L.target.value),placeholder:"名称",style:{...Nn,marginBottom:10},disabled:!!o}),e.jsx("input",{value:b,onChange:L=>h(L.target.value),placeholder:"描述",style:{...Nn,marginBottom:10}}),e.jsxs("select",{value:w,onChange:L=>S(L.target.value),style:{...Nn,marginBottom:10},children:[e.jsx("option",{value:"user",children:"用户"}),e.jsx("option",{value:"feedback",children:"反馈"}),e.jsx("option",{value:"project",children:"项目"}),e.jsx("option",{value:"reference",children:"参考"})]}),e.jsx("textarea",{value:D,onChange:L=>H(L.target.value),placeholder:"内容",rows:5,style:{...Nn,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:R,style:{padding:"9px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--success)",color:"#000",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"保存"}),e.jsx("button",{onClick:()=>u(!1),style:Zr,children:"取消"})]})]}),t.map(L=>e.jsxs("div",{style:{padding:"14px 16px",marginBottom:8,background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{color:"var(--text-primary)",fontWeight:600,fontSize:14},children:L.name}),e.jsx("span",{style:{fontSize:10,padding:"2px 8px",borderRadius:10,background:"rgba(255,255,255,0.04)",color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:500},children:L.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>C(L),style:es,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(L.name),_("删除成功"),j("success"),await A()}catch(I){_(I instanceof Error?I.message:"删除失败"),j("error")}},style:{...es,color:"var(--danger)"},children:"删除"})]})]}),L.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:L.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[L.content.slice(0,180),L.content.length>180?"…":""]})]},L.name)),t.length===0&&!d&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Nn={width:"100%",padding:"11px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"},Zr={padding:"10px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},es={padding:"4px 10px",borderRadius:6,fontSize:11,border:"none",background:"rgba(255,255,255,0.05)",color:"var(--text-secondary)",cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500},ai=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function li(){const[t,r]=c.useState([]),[n,s]=c.useState(null),[o,a]=c.useState(!1),[d,u]=c.useState(null),[f,p]=c.useState("success"),[b,h]=c.useState(""),w=(C,L="success")=>{u(C),p(L),setTimeout(()=>u(null),3e3)},S=async()=>{if(!window.agentApi)return;const C=await window.agentApi.listSkills();r(C)};c.useEffect(()=>{S()},[]);const D=C=>{s({...C}),h((C.triggers??[]).join(", ")),a(!1)},H=()=>{s(ai()),h(""),a(!0)},V=()=>{s(null),a(!1)},_=async()=>{if(!n||!window.agentApi)return;if(!n.name.trim()){w("名称不能为空","error");return}const C=b.split(",").map(L=>L.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:n.name.trim(),description:n.description,triggers:C,prompt:n.prompt,filePath:n.filePath??""}),w(o?"技能已创建":"技能已保存"),s(null),await S()}catch(L){w(L instanceof Error?L.message:"保存失败","error")}},m=async C=>{if(window.agentApi)try{await window.agentApi.deleteSkill(C),w("已删除"),(n==null?void 0:n.name)===C&&s(null),await S()}catch(L){w(L instanceof Error?L.message:"删除失败","error")}},j=async C=>{if(!window.agentApi)return;const L=!C.enabled;await window.agentApi.setSkillEnabled(C.name,L),await S()},A=async()=>{if(window.agentApi)try{const C=await window.agentApi.importSkill();if(!C)return;w(`已导入技能「${C.name}」,本次会话立即生效`),await S()}catch(C){w(C instanceof Error?C.message:"导入失败","error")}},P={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},R={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"技能管理"}),e.jsx("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:"配置触发词和提示词,让 Agent 自动激活专属技能"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer"},children:"↓ 导入技能"}),e.jsx("button",{onClick:H,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"+ 新建技能"})]})]}),d&&e.jsx("div",{style:{marginBottom:16,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:f==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:f==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:f==="success"?"var(--success)":"var(--danger)",fontSize:13},children:d}),n&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:o?"新建技能":`编辑:${n.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:R,children:"名称"}),e.jsx("input",{style:P,value:n.name,disabled:!o,onChange:C=>s({...n,name:C.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"描述"}),e.jsx("input",{style:P,value:n.description,onChange:C=>s({...n,description:C.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"触发词(逗号分隔)"}),e.jsx("input",{style:P,value:b,onChange:C=>h(C.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"提示词"}),e.jsx("textarea",{style:{...P,minHeight:120,resize:"vertical"},value:n.prompt,onChange:C=>s({...n,prompt:C.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:_,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"保存"}),e.jsx("button",{onClick:V,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!n&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(C=>{var L;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:"14px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-glass)",opacity:C.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>j(C),title:C.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:C.enabled===!1?"var(--border-default)":"var(--accent)",cursor:"pointer",position:"relative",transition:"background 0.2s"},children:e.jsx("span",{style:{position:"absolute",top:2,left:C.enabled===!1?2:14,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:C.name}),((L=C.triggers)==null?void 0:L.length)>0&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["触发词:",C.triggers.slice(0,3).join(" · "),C.triggers.length>3?" ...":""]})]}),C.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:C.description}),C.prompt&&e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",opacity:.7},children:[C.prompt.slice(0,80),C.prompt.length>80?"...":""]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>D(C),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:12,cursor:"pointer"},children:"编辑"}),e.jsx("button",{onClick:()=>m(C.name),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(244,63,94,0.3)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer"},children:"删除"})]})]},C.name)})]})]})}const Pn=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function ks(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function di(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:ks(),maxIterations:0,isDefault:!1}}const gr={padding:"5px 12px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-secondary)",fontSize:12,fontWeight:500,cursor:"pointer"},Sn={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},Tt={width:"100%",padding:"7px 10px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",boxSizing:"border-box"},At={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function ci({ph:t,onChange:r,onDelete:n}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:Tt,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>r({...t,key:s.target.value})}),e.jsx("input",{style:Tt,placeholder:"说明",value:t.description,onChange:s=>r({...t,description:s.target.value})}),e.jsx("input",{style:Tt,placeholder:"默认值",value:t.defaultValue,onChange:s=>r({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:n,style:{...Sn,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function ts({initial:t,activeAgentId:r,onSave:n,onCancel:s}){const{profiles:o}=Fn(),[a,d]=c.useState([]),[u,f]=c.useState([]),[p,b]=c.useState({...di(),...t,capabilities:{...ks(),...t.capabilities??{}}}),[h,w]=c.useState(null),[S,D]=c.useState(!1);c.useEffect(()=>{var I,T;window.agentApi&&(window.agentApi.listSkills().then(Q=>{d(Q.filter(Z=>Z.name))}),(T=(I=window.agentApi).listMCPServers)==null||T.call(I).then(Q=>{f(Q??[])}).catch(()=>{}))},[]);const H=I=>b(T=>({...T,capabilities:{...T.capabilities,...I}})),V=I=>{const T=p.capabilities.enabledTools;if(T.length===0){const Q=Pn.map(Z=>Z.name).filter(Z=>Z!==I);H({enabledTools:Q})}else if(T.includes(I)){const Q=T.filter(Z=>Z!==I);H({enabledTools:Q})}else{const Q=[...T,I];Q.length===Pn.length?H({enabledTools:[]}):H({enabledTools:Q})}},_=I=>{const T=p.capabilities.enabledSkills;H({enabledSkills:T.includes(I)?T.filter(Q=>Q!==I):[...T,I]})},m=I=>{const T=p.capabilities.enabledMCPServers;H({enabledMCPServers:T.includes(I)?T.filter(Q=>Q!==I):[...T,I]})},j=()=>b(I=>({...I,contextPlaceholders:[...I.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),A=(I,T)=>b(Q=>{const Z=[...Q.contextPlaceholders];return Z[I]=T,{...Q,contextPlaceholders:Z}}),P=I=>b(T=>({...T,contextPlaceholders:T.contextPlaceholders.filter((Q,Z)=>Z!==I)})),R=async()=>{if(!p.name.trim()){w("名称为必填项");return}D(!0);try{await n(p)}catch(I){w(I instanceof Error?I.message:"保存失败")}finally{D(!1)}},C=I=>p.capabilities.enabledTools.length===0||p.capabilities.enabledTools.includes(I),L={fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:10,marginTop:22,paddingBottom:5,borderBottom:"1px solid var(--border-subtle)"};return e.jsxs("div",{style:{padding:"24px 28px",background:"transparent",borderTop:"1px solid var(--border-subtle)"},children:[h&&e.jsx("div",{style:{marginBottom:12,padding:"8px 12px",borderRadius:7,background:"rgba(244,63,94,0.08)",border:"1px solid rgba(244,63,94,0.25)",color:"var(--danger)",fontSize:12},children:h}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:At,children:"名称 *"}),e.jsx("input",{style:Tt,value:p.name,onChange:I=>b(T=>({...T,name:I.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:At,children:"描述"}),e.jsx("input",{style:Tt,value:p.description,onChange:I=>b(T=>({...T,description:I.target.value})),placeholder:"一句话描述"})]})]}),e.jsxs("div",{style:{marginTop:14},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:5},children:[e.jsx("label",{style:{...At,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:p.systemPrompt,onChange:I=>b(T=>({...T,systemPrompt:I.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
35
-
36
- 当前项目:{{project_name}}`,rows:6,style:{...Tt,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:L,children:"上下文占位符"}),p.contextPlaceholders.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6},children:["变量名","说明","默认值",""].map(I=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:I},I))}),p.contextPlaceholders.map((I,T)=>e.jsx(ci,{ph:I,onChange:Q=>A(T,Q),onDelete:()=>P(T)},T))]}),e.jsx("button",{onClick:j,style:{...Sn,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:L,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:At,children:"模型"}),e.jsxs("select",{value:p.capabilities.profileId,onChange:I=>H({profileId:I.target.value}),style:{...Tt,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),o.map(I=>e.jsxs("option",{value:I.id,children:[I.name||I.modelId," (",I.provider,")"]},I.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:At,children:["内置工具 ",p.capabilities.enabledTools.length===0?"(全部启用)":`(${p.capabilities.enabledTools.length}/${Pn.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Pn.map(I=>{const T=C(I.name);return e.jsx("button",{onClick:()=>V(I.name),style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.label},I.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),a.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:At,children:["技能 ",p.capabilities.enabledSkills.length===0?"(全部)":`(${p.capabilities.enabledSkills.length}/${a.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(I=>{const T=p.capabilities.enabledSkills.length===0||p.capabilities.enabledSkills.includes(I.name);return e.jsx("button",{onClick:()=>_(I.name),title:I.description,style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.name},I.name)})})]}),u.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:At,children:["MCP 服务器 ",p.capabilities.enabledMCPServers.length===0?"(全部)":`(${p.capabilities.enabledMCPServers.length}/${u.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:u.map(I=>{const T=p.capabilities.enabledMCPServers.length===0||p.capabilities.enabledMCPServers.includes(I.id);return e.jsx("button",{onClick:()=>m(I.id),style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.name},I.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:At,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:Tt,value:p.maxIterations,min:0,max:100,onChange:I=>b(T=>({...T,maxIterations:Number(I.target.value)}))})]}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",paddingBottom:2},children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:"var(--text-secondary)"},children:[e.jsx("input",{type:"checkbox",checked:p.isDefault,onChange:I=>b(T=>({...T,isDefault:I.target.checked})),style:{width:14,height:14,accentColor:"var(--accent)",cursor:"pointer"}}),"新会话默认使用此智能体"]})})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:R,disabled:S,style:{...gr,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:S?.6:1},children:S?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:gr,children:"取消"})]})]})}function ui(){const[t,r]=c.useState([]),[n,s]=c.useState([]),[o,a]=c.useState(null),[d,u]=c.useState(!1),[f,p]=c.useState(null),[b,h]=c.useState("success"),w=(m,j="success")=>{p(m),h(j),setTimeout(()=>p(null),2e3)},S=async()=>{if(!window.agentApi)return;const m=await window.agentApi.listAgentDefs();r(m);const j=await window.agentApi.getSettings();s(j.activeAgentIds??[])};c.useEffect(()=>{S()},[]);const D=async m=>{await window.agentApi.createAgentDef(m),u(!1),w("智能体已创建"),await S()},H=async(m,j)=>{await window.agentApi.updateAgentDef(m,j),a(null),w("保存成功"),await S()},V=async m=>{await window.agentApi.deleteAgentDef(m),o===m&&a(null),w("已删除"),await S()},_=async m=>{const A=(await window.agentApi.setActiveAgentDef(m)).activeAgentIds??[];s(A),w(A.includes(m)?"已激活":"已取消激活")};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"智能体"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:28},children:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),f&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,border:b==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:b==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:b==="success"?"var(--success)":"var(--danger)",fontSize:13},children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{u(!0),a(null)},style:{...gr,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600},children:"+ 新建智能体"})}),d&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden",marginBottom:16},children:[e.jsx("div",{style:{padding:"10px 16px",background:"var(--bg-surface)",display:"flex",alignItems:"center",gap:8},children:e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)"},children:"新建智能体"})}),e.jsx(ts,{initial:{},activeAgentId:n[0]??"",onSave:D,onCancel:()=>u(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!d&&e.jsx("div",{style:{padding:"28px 20px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无智能体配置,点击「新建智能体」开始创建"}),t.map(m=>{const j=n.includes(m.id),A=m.id===o;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${j?"var(--accent)":"var(--border-default)"}`,background:j?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s, background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 16px"},children:[e.jsx("div",{style:{width:34,height:34,borderRadius:8,flexShrink:0,background:j?"var(--accent)":"var(--bg-deep)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:j?"#fff":"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:m.name}),j&&e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"rgba(79,110,247,0.12)",padding:"1px 6px",borderRadius:4,letterSpacing:"0.05em"},children:"激活"}),m.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),m.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[m.capabilities.profileId&&e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"rgba(79,110,247,0.08)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.15)"},children:"自定义模型"}),m.capabilities.enabledTools.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.capabilities.enabledTools.length," 工具"]}),m.capabilities.enabledSkills.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.capabilities.enabledSkills.length," 技能"]}),m.contextPlaceholders.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>_(m.id),style:{...Sn,color:j?"var(--accent)":"var(--text-muted)",borderColor:j?"var(--accent)":"var(--border-default)",background:j?"var(--accent-dim)":"transparent"},children:j?"取消激活":"激活"}),e.jsx("button",{onClick:()=>a(A?null:m.id),style:Sn,children:A?"收起":"编辑"}),e.jsx("button",{onClick:()=>V(m.id),style:{...Sn,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),A&&e.jsx(ts,{initial:m,activeAgentId:n[0]??"",onSave:P=>H(m.id,P),onCancel:()=>a(null)})]},m.id)})]})]})}const pi=[{label:"TypeScript / JavaScript",language:"typescript",fileTypes:".ts,.tsx,.js,.jsx",command:"typescript-language-server",args:"--stdio"},{label:"Python (pylsp)",language:"python",fileTypes:".py",command:"pylsp",args:""},{label:"Python (pyright)",language:"python",fileTypes:".py",command:"pyright-langserver",args:"--stdio"},{label:"Rust (rust-analyzer)",language:"rust",fileTypes:".rs",command:"rust-analyzer",args:""},{label:"Go (gopls)",language:"go",fileTypes:".go",command:"gopls",args:""},{label:"C/C++ (clangd)",language:"cpp",fileTypes:".c,.cpp,.cc,.h,.hpp",command:"clangd",args:""},{label:"Java (jdtls via brew)",language:"java",fileTypes:".java",command:"jdtls",args:"--data /tmp/jdtls-workspace"}],lr={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function gi(){const[t,r]=c.useState([]),[n,s]=c.useState(lr),[o,a]=c.useState(!1),[d,u]=c.useState(null),[f,p]=c.useState(null),b=async()=>{var m;if((m=window.agentApi)!=null&&m.lspList)try{const j=await window.agentApi.lspList();r(j)}catch(j){console.error("[LSP] load error",j)}};c.useEffect(()=>{b()},[]);const h=m=>{s(j=>({...j,name:m.label,language:m.language,fileTypes:m.fileTypes,command:m.command,args:m.args}))},w=m=>{u(m.id),s({id:m.id,name:m.name,language:m.language,fileTypes:m.fileTypes.join(","),command:m.command,args:m.args.join(" "),envRaw:m.env?Object.entries(m.env).map(([j,A])=>`${j}=${A}`).join(`
37
- `):""}),p(null)},S=()=>{u(null),s(lr)},D=async()=>{var R;if(!((R=window.agentApi)!=null&&R.lspSave))return;const m=n.name.trim(),j=n.command.trim();if(!m||!j)return;let A;if(n.envRaw.trim()){A={};for(const C of n.envRaw.split(`
38
- `)){const L=C.indexOf("=");L>0&&(A[C.slice(0,L).trim()]=C.slice(L+1).trim())}}const P={id:d??crypto.randomUUID(),name:m,language:n.language.trim(),fileTypes:n.fileTypes.split(",").map(C=>C.trim()).filter(Boolean),command:j,args:n.args.trim()?n.args.trim().split(/\s+/):[],env:A,enabled:!0};a(!0);try{await window.agentApi.lspSave(P),await b(),S()}finally{a(!1)}},H=async m=>{var j;(j=window.agentApi)!=null&&j.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(m),await b())},V=async m=>{var j;(j=window.agentApi)!=null&&j.lspSetEnabled&&(await window.agentApi.lspSetEnabled(m.id,!m.enabled),await b())},_=d!==null;return _&&d===null||!d&&n.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!_&&e.jsx("button",{onClick:()=>{u(""),s(lr)},style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",flexShrink:0},children:"+ 添加服务器"})]}),t.length===0&&!_&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:"尚未配置任何 LSP 服务器"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:_?24:0},children:t.map(m=>e.jsxs("div",{style:{background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",cursor:"pointer"},onClick:()=>p(f===m.id?null:m.id),children:[e.jsx("div",{onClick:j=>{j.stopPropagation(),V(m)},style:{width:32,height:18,borderRadius:9,background:m.enabled?"var(--success, #34d399)":"var(--border-default)",position:"relative",cursor:"pointer",flexShrink:0,transition:"background 0.2s"},children:e.jsx("div",{style:{position:"absolute",top:2,left:m.enabled?16:2,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:500,fontSize:13,color:"var(--text-primary)"},children:m.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[m.language,m.fileTypes.length>0?` · ${m.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[m.command,m.args.length?" "+m.args.join(" "):""]}),e.jsx("button",{onClick:j=>{j.stopPropagation(),w(m)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"编辑"}),e.jsx("button",{onClick:j=>{j.stopPropagation(),H(m.id)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--danger, #f43f5e)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"删除"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{flexShrink:0,transition:"transform 0.2s",transform:f===m.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),f===m.id&&e.jsxs("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-muted)",borderTop:"1px solid var(--border-subtle)",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"命令:"}),e.jsxs("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:[m.command," ",m.args.join(" ")]})]}),m.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),m.fileTypes.join(", ")]}),m.env&&Object.keys(m.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(m.env).map(([j,A])=>`${j}=${A}`).join(", ")]})]})]},m.id))}),_&&e.jsxs("div",{style:{padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:d?"编辑 LSP 服务器":"添加 LSP 服务器"}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:_t,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:pi.map(m=>e.jsx("button",{onClick:()=>h(m),style:{background:"var(--bg-deep)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:"pointer",color:"var(--text-secondary)",fontFamily:"var(--font-body)"},children:m.label},m.label))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.name,onChange:m=>s(j=>({...j,name:m.target.value})),placeholder:"TypeScript Language Server",style:Zt})]}),e.jsxs("div",{children:[e.jsx("label",{style:_t,children:"语言"}),e.jsx("input",{value:n.language,onChange:m=>s(j=>({...j,language:m.target.value})),placeholder:"typescript",style:Zt})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:n.fileTypes,onChange:m=>s(j=>({...j,fileTypes:m.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:Zt})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.command,onChange:m=>s(j=>({...j,command:m.target.value})),placeholder:"typescript-language-server",style:{...Zt,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:n.args,onChange:m=>s(j=>({...j,args:m.target.value})),placeholder:"--stdio",style:{...Zt,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:n.envRaw,onChange:m=>s(j=>({...j,envRaw:m.target.value})),placeholder:`NODE_ENV=production
39
- TSPROTOCOL_LOG=verbose`,rows:3,style:{...Zt,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),n.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void D(),disabled:o||!n.name.trim()||!n.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:o||!n.name.trim()||!n.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:o?"保存中…":"保存"}),e.jsx("button",{onClick:S,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"})]})]})]})}const Zt={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},_t={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function hi({trigger:t,heardText:r}){const[n,s]=c.useState(!1);return c.useEffect(()=>{if(t<=0)return;s(!0);const o=setTimeout(()=>s(!1),2400);return()=>clearTimeout(o)},[t]),n?zt.createPortal(e.jsxs("div",{style:{position:"fixed",inset:0,zIndex:3e4,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:22,background:"radial-gradient(circle at 50% 50%, var(--accent-glow), transparent 60%)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",animation:"fadeIn 0.3s var(--ease-out)",pointerEvents:"none",WebkitAppRegion:"no-drag"},children:[e.jsxs("div",{style:{position:"relative",width:120,height:120},children:[[0,.45,.9].map(o=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${o}s var(--ease-out) infinite`}},o)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),r&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",r.slice(0,40),"”"]})]},t),document.body):null}const fi=[{agentType:"customer-agent",mark:"CA",label:"Customer Agent"},{agentType:"codex",mark:"CX",label:"Codex"},{agentType:"claude-code",mark:"CC",label:"Claude Code"}],dr=220,ns=138;function xi({health:t,disabled:r,onSelect:n}){const[s,o]=c.useState(!1),[a,d]=c.useState(null),u=c.useRef(null),f=c.useRef(null);return c.useEffect(()=>{if(!s)return;const p=b=>{var w,S;const h=b.target;(w=u.current)!=null&&w.contains(h)||(S=f.current)!=null&&S.contains(h)||o(!1)};return window.addEventListener("pointerdown",p),()=>window.removeEventListener("pointerdown",p)},[s]),e.jsxs("div",{style:{position:"relative",flexShrink:0},children:[e.jsx("button",{ref:u,type:"button",onClick:p=>{var h;p.stopPropagation();const b=(h=u.current)==null?void 0:h.getBoundingClientRect();if(b){const w=Math.min(Math.max(b.right-dr,8),Math.max(8,window.innerWidth-dr-8));let S=b.bottom+4;S+ns>window.innerHeight-8&&(S=Math.max(8,b.top-ns-4)),d({top:S,left:w})}o(w=>!w)},disabled:r,title:"新建会话","aria-label":"新建会话","aria-expanded":s,className:"sidebar-row-action sidebar-row-action--accent sidebar-project-add-action ui-icon-button ui-icon-button--small",style:{fontSize:16,lineHeight:1},children:"+"}),s&&a&&zt.createPortal(e.jsx("div",{ref:f,role:"menu",style:{position:"fixed",top:a.top,left:a.left,zIndex:10020,width:dr,padding:5,border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-surface)",boxShadow:"var(--shadow-md)"},children:fi.map(p=>{const b=t.find(w=>w.agentType===p.agentType),h=(b==null?void 0:b.available)??p.agentType==="customer-agent";return e.jsxs("button",{type:"button",role:"menuitem",disabled:!h,title:h?`使用 ${p.label}`:(b==null?void 0:b.error)||`${p.label} 不可用`,onClick:()=>{o(!1),n(p.agentType)},style:{width:"100%",minHeight:36,display:"flex",alignItems:"center",gap:9,padding:"6px 8px",border:0,borderRadius:5,background:"transparent",color:h?"var(--text-secondary)":"var(--text-muted)",cursor:h?"pointer":"not-allowed",opacity:h?1:.5,textAlign:"left"},children:[e.jsx("span",{style:{width:25,height:19,display:"grid",placeItems:"center",borderRadius:4,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)",color:"var(--text-muted)",fontSize:9,fontWeight:700},children:p.mark}),e.jsx("span",{style:{flex:1,fontSize:12},children:p.label}),e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:h?"var(--success)":"var(--danger)"}})]},p.agentType)})}),document.body)]})}const mi=[["style",new Set(["css","scss","sass","less","styl"])],["image",new Set(["png","jpg","jpeg","gif","webp","avif","bmp","ico","svg","tif","tiff"])],["video",new Set(["mp4","mov","m4v","webm","mkv","avi","wmv","flv","mpeg","mpg"])],["audio",new Set(["mp3","wav","m4a","aac","ogg","flac","opus"])],["markdown",new Set(["md","mdx","markdown"])],["json",new Set(["json","jsonc","geojson"])],["archive",new Set(["zip","tar","gz","tgz","bz2","xz","7z","rar"])],["spreadsheet",new Set(["csv","tsv","xls","xlsx","ods"])],["presentation",new Set(["ppt","pptx","key","odp"])],["database",new Set(["db","sqlite","sqlite3"])],["text",new Set(["txt","log","rtf","ini","cfg","conf","env","yaml","yml","toml","xml","pdf","doc","docx","odt"])],["code",new Set(["js","jsx","mjs","cjs","ts","tsx","vue","svelte","java","kt","kts","py","rb","go","rs","php","c","cc","cpp","h","hpp","cs","swift","scala","sh","bash","zsh","fish","sql","html"])]],bi=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function vi(t){var o;const r=t.toLocaleLowerCase(),n=bi.get(r);if(n)return n;if(r.startsWith(".env")||r===".gitignore"||r===".npmrc")return"text";const s=r.includes(".")&&r.split(".").pop()||"";return((o=mi.find(([,a])=>a.has(s)))==null?void 0:o[0])??"file"}/**
1
+ import{R as Hs,r as c,c as ls,j as e,u as ke,a as zt,i as ds,b as Vs,S as qs,L as Ks}from"./index-DhS2YvqH.js";function Gs(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||t===null||typeof r!="object"||r===null)return!1;if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(const[s,o]of t)if(!Object.is(o,r.get(s)))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(const s of t)if(!r.has(s))return!1;return!0}const n=Object.keys(t);if(n.length!==Object.keys(r).length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(r,s)||!Object.is(t[s],r[s]))return!1;return!0}const{useRef:Qs}=Hs;function Js(t){const r=Qs();return n=>{const s=t(n);return Gs(r.current,s)?r.current:r.current=s}}/**
40
2
  * @license lucide-react v0.468.0 - ISC
41
3
  *
42
4
  * This source code is licensed under the ISC license.
43
5
  * See the LICENSE file in the root directory of this source tree.
44
- */const yi=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ss=(...t)=>t.filter((r,n,s)=>!!r&&r.trim()!==""&&s.indexOf(r)===n).join(" ").trim();/**
6
+ */const Xs=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),cs=(...t)=>t.filter((r,n,s)=>!!r&&r.trim()!==""&&s.indexOf(r)===n).join(" ").trim();/**
45
7
  * @license lucide-react v0.468.0 - ISC
46
8
  *
47
9
  * This source code is licensed under the ISC license.
48
10
  * See the LICENSE file in the root directory of this source tree.
49
- */var wi={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
11
+ */var Ys={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
50
12
  * @license lucide-react v0.468.0 - ISC
51
13
  *
52
14
  * This source code is licensed under the ISC license.
53
15
  * See the LICENSE file in the root directory of this source tree.
54
- */const ji=c.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:n=2,absoluteStrokeWidth:s,className:o="",children:a,iconNode:d,...u},f)=>c.createElement("svg",{ref:f,...wi,width:r,height:r,stroke:t,strokeWidth:s?Number(n)*24/Number(r):n,className:Ss("lucide",o),...u},[...d.map(([p,b])=>c.createElement(p,b)),...Array.isArray(a)?a:[a]]));/**
16
+ */const Zs=c.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:n=2,absoluteStrokeWidth:s,className:o="",children:a,iconNode:l,...u},f)=>c.createElement("svg",{ref:f,...Ys,width:r,height:r,stroke:t,strokeWidth:s?Number(n)*24/Number(r):n,className:cs("lucide",o),...u},[...l.map(([p,b])=>c.createElement(p,b)),...Array.isArray(a)?a:[a]]));/**
55
17
  * @license lucide-react v0.468.0 - ISC
56
18
  *
57
19
  * This source code is licensed under the ISC license.
58
20
  * See the LICENSE file in the root directory of this source tree.
59
- */const me=(t,r)=>{const n=c.forwardRef(({className:s,...o},a)=>c.createElement(ji,{ref:a,iconNode:r,className:Ss(`lucide-${yi(t)}`,s),...o}));return n.displayName=`${t}`,n};/**
21
+ */const me=(t,r)=>{const n=c.forwardRef(({className:s,...o},a)=>c.createElement(Zs,{ref:a,iconNode:r,className:cs(`lucide-${Xs(t)}`,s),...o}));return n.displayName=`${t}`,n};/**
60
22
  * @license lucide-react v0.468.0 - ISC
61
23
  *
62
24
  * This source code is licensed under the ISC license.
63
25
  * See the LICENSE file in the root directory of this source tree.
64
- */const ki=me("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
26
+ */const eo=me("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
65
27
  * @license lucide-react v0.468.0 - ISC
66
28
  *
67
29
  * This source code is licensed under the ISC license.
68
30
  * See the LICENSE file in the root directory of this source tree.
69
- */const Si=me("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
31
+ */const to=me("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
70
32
  * @license lucide-react v0.468.0 - ISC
71
33
  *
72
34
  * This source code is licensed under the ISC license.
73
35
  * See the LICENSE file in the root directory of this source tree.
74
- */const Ci=me("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
36
+ */const no=me("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
75
37
  * @license lucide-react v0.468.0 - ISC
76
38
  *
77
39
  * This source code is licensed under the ISC license.
78
40
  * See the LICENSE file in the root directory of this source tree.
79
- */const Ii=me("FileArchive",[["path",{d:"M10 12v-1",key:"v7bkov"}],["path",{d:"M10 18v-2",key:"1cjy8d"}],["path",{d:"M10 7V6",key:"dljcrl"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01",key:"gkbcor"}],["circle",{cx:"10",cy:"20",r:"2",key:"1xzdoj"}]]);/**
41
+ */const ro=me("FileArchive",[["path",{d:"M10 12v-1",key:"v7bkov"}],["path",{d:"M10 18v-2",key:"1cjy8d"}],["path",{d:"M10 7V6",key:"dljcrl"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01",key:"gkbcor"}],["circle",{cx:"10",cy:"20",r:"2",key:"1xzdoj"}]]);/**
80
42
  * @license lucide-react v0.468.0 - ISC
81
43
  *
82
44
  * This source code is licensed under the ISC license.
83
45
  * See the LICENSE file in the root directory of this source tree.
84
- */const Ri=me("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);/**
46
+ */const so=me("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);/**
85
47
  * @license lucide-react v0.468.0 - ISC
86
48
  *
87
49
  * This source code is licensed under the ISC license.
88
50
  * See the LICENSE file in the root directory of this source tree.
89
- */const Ai=me("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
51
+ */const oo=me("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
90
52
  * @license lucide-react v0.468.0 - ISC
91
53
  *
92
54
  * This source code is licensed under the ISC license.
93
55
  * See the LICENSE file in the root directory of this source tree.
94
- */const Ti=me("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]);/**
56
+ */const io=me("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]);/**
95
57
  * @license lucide-react v0.468.0 - ISC
96
58
  *
97
59
  * This source code is licensed under the ISC license.
98
60
  * See the LICENSE file in the root directory of this source tree.
99
- */const zi=me("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
61
+ */const ao=me("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
100
62
  * @license lucide-react v0.468.0 - ISC
101
63
  *
102
64
  * This source code is licensed under the ISC license.
103
65
  * See the LICENSE file in the root directory of this source tree.
104
- */const Mi=me("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);/**
66
+ */const lo=me("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);/**
105
67
  * @license lucide-react v0.468.0 - ISC
106
68
  *
107
69
  * This source code is licensed under the ISC license.
108
70
  * See the LICENSE file in the root directory of this source tree.
109
- */const Li=me("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/**
71
+ */const us=me("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/**
110
72
  * @license lucide-react v0.468.0 - ISC
111
73
  *
112
74
  * This source code is licensed under the ISC license.
113
75
  * See the LICENSE file in the root directory of this source tree.
114
- */const Ei=me("FileVideo2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["rect",{width:"8",height:"6",x:"2",y:"12",rx:"1",key:"1a6c1e"}],["path",{d:"m10 15.5 4 2.5v-6l-4 2.5",key:"t7cp39"}]]);/**
76
+ */const co=me("FileVideo2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["rect",{width:"8",height:"6",x:"2",y:"12",rx:"1",key:"1a6c1e"}],["path",{d:"m10 15.5 4 2.5v-6l-4 2.5",key:"t7cp39"}]]);/**
115
77
  * @license lucide-react v0.468.0 - ISC
116
78
  *
117
79
  * This source code is licensed under the ISC license.
118
80
  * See the LICENSE file in the root directory of this source tree.
119
- */const Wi=me("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
81
+ */const uo=me("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
120
82
  * @license lucide-react v0.468.0 - ISC
121
83
  *
122
84
  * This source code is licensed under the ISC license.
123
85
  * See the LICENSE file in the root directory of this source tree.
124
- */const Bi=me("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
86
+ */const po=me("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
125
87
  * @license lucide-react v0.468.0 - ISC
126
88
  *
127
89
  * This source code is licensed under the ISC license.
128
90
  * See the LICENSE file in the root directory of this source tree.
129
- */const Ni=me("NotebookText",[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M9.5 8h5",key:"11mslq"}],["path",{d:"M9.5 12H16",key:"ktog6x"}],["path",{d:"M9.5 16H14",key:"p1seyn"}]]);/**
91
+ */const go=me("NotebookText",[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M9.5 8h5",key:"11mslq"}],["path",{d:"M9.5 12H16",key:"ktog6x"}],["path",{d:"M9.5 16H14",key:"p1seyn"}]]);/**
130
92
  * @license lucide-react v0.468.0 - ISC
131
93
  *
132
94
  * This source code is licensed under the ISC license.
133
95
  * See the LICENSE file in the root directory of this source tree.
134
- */const Pi=me("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
96
+ */const ho=me("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
135
97
  * @license lucide-react v0.468.0 - ISC
136
98
  *
137
99
  * This source code is licensed under the ISC license.
138
100
  * See the LICENSE file in the root directory of this source tree.
139
- */const Di=me("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]);/**
101
+ */const fo=me("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]);/**
140
102
  * @license lucide-react v0.468.0 - ISC
141
103
  *
142
104
  * This source code is licensed under the ISC license.
143
105
  * See the LICENSE file in the root directory of this source tree.
144
- */const _i=me("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
106
+ */const xo=me("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
145
107
  * @license lucide-react v0.468.0 - ISC
146
108
  *
147
109
  * This source code is licensed under the ISC license.
148
110
  * See the LICENSE file in the root directory of this source tree.
149
- */const Fi=me("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),$i={folder:{icon:Bi,label:"文件夹"},code:{icon:Ai,label:"代码文件"},style:{icon:Pi,label:"样式文件"},image:{icon:Ti,label:"图片文件"},video:{icon:Ei,label:"视频文件"},audio:{icon:Ri,label:"音频文件"},markdown:{icon:Ni,label:"Markdown 文件"},text:{icon:Li,label:"文本文件"},json:{icon:zi,label:"JSON 文件"},archive:{icon:Ii,label:"压缩文件"},spreadsheet:{icon:Mi,label:"表格文件"},presentation:{icon:Di,label:"演示文件"},database:{icon:Ci,label:"数据库文件"},file:{icon:Wi,label:"文件"}};function Ui(t,r){return r==="directory"?"folder":vi(t)}const rs=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function Oi(t,r){const n=rs(t),s=rs(r),a=[{label:n==="/"?"/":n.split("/").filter(Boolean).pop()||n,path:n}];if(s===n)return a;const d=s.slice(n==="/"?1:n.length+1);let u=n;for(const f of d.split("/").filter(Boolean))u=u==="/"?`/${f}`:`${u}/${f}`,a.push({label:f,path:u});return a}function Hi({open:t,onCancel:r,onConfirm:n}){const[s,o]=c.useState([]),[a,d]=c.useState(""),[u,f]=c.useState(""),[p,b]=c.useState([]),[h,w]=c.useState(!1),[S,D]=c.useState(""),[H,V]=c.useState(!1),_=c.useMemo(()=>Oi(a||"/",u||a||"/"),[a,u]),m=async R=>{if(window.agentApi){w(!0),D("");try{const C=await window.agentApi.listProjectDirectories(R);b(C),f(R)}catch(C){D(C instanceof Error?C.message:"无法读取目录")}finally{w(!1)}}};if(c.useEffect(()=>{if(!t||!window.agentApi)return;let R=!1;return w(!0),D(""),window.agentApi.listProjectRoots().then(async C=>{if(R)return;o(C);const L=C[0]??"";d(L),L?await m(L):D("未配置可用的宿主机目录")}).catch(C=>{R||D(C instanceof Error?C.message:"无法读取宿主机目录")}).finally(()=>{R||w(!1)}),()=>{R=!0}},[t]),c.useEffect(()=>{if(!t)return;const R=C=>{C.key==="Escape"&&r()};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[t,r]),!t)return null;const j=R=>{d(R),m(R)},A=()=>{_.length<=1||m(_[_.length-2].path)},P=async()=>{if(!(!u||H)){V(!0),D("");try{await n(u)}catch(R){D(R instanceof Error?R.message:"项目导入失败")}finally{V(!1)}}};return zt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:R=>{R.target===R.currentTarget&&r()},children:e.jsxs("section",{className:"host-project-picker",role:"dialog","aria-modal":"true","aria-labelledby":"host-project-picker-title",children:[e.jsxs("header",{className:"host-project-picker-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"host-project-picker-title",children:"选择宿主机项目"}),e.jsx("p",{children:"文件将直接在运行 AgentRoam 的机器上读写"})]}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(Fi,{size:16,"aria-hidden":"true"})})]}),s.length>1&&e.jsxs("label",{className:"host-project-picker-root",children:[e.jsx("span",{children:"根目录"}),e.jsx("select",{value:a,onChange:R=>j(R.target.value),children:s.map(R=>e.jsx("option",{value:R,children:R},R))})]}),e.jsxs("nav",{className:"host-project-picker-nav","aria-label":"当前目录",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:A,disabled:_.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(ki,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:_.map((R,C)=>e.jsxs("span",{children:[C>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void m(R.path),children:R.label})]},R.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>u&&void m(u),disabled:!u||h,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(_i,{size:15,"aria-hidden":"true"})})]}),a==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":h,children:h?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):S?e.jsx("div",{className:"host-project-picker-state is-error",children:S}):p.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):p.map(R=>{const C=Ui(R.name,R.kind),{icon:L,label:I}=$i[C],T=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${C}`,"aria-hidden":"true",children:e.jsx(L,{size:18,strokeWidth:1.8})}),e.jsx("span",{className:"host-project-picker-name",children:R.name})]});return R.kind==="file"?e.jsx("div",{className:"host-project-picker-row is-file",title:I,children:T},`${R.name}:${R.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void m(R.path),title:I,children:[T,R.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(Si,{size:16})})]},`${R.name}:${R.path}`)})}),e.jsxs("footer",{className:"host-project-picker-footer",children:[e.jsx("code",{title:u,children:u}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:r,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!u||h||H,onClick:()=>void P(),children:H?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const ss={"customer-agent":"CA",codex:"CX","claude-code":"CC"},os={"claude-code":"Claude Code",codex:"Codex","customer-agent":"Customer Agent"},is=["customer-agent","claude-code","codex"],vr="agentroam.session-index.v1";function yr(){try{const t=JSON.parse(localStorage.getItem(vr)??"{}");return!t||typeof t!="object"||Array.isArray(t)?{}:Object.fromEntries(Object.entries(t).filter(([,r])=>Array.isArray(r)))}catch{return{}}}function Vi(t,r){try{localStorage.setItem(vr,JSON.stringify({...yr(),[t]:r}))}catch{}}function qi(t){try{const r=yr(),n=Object.fromEntries(Object.entries(r).filter(([s])=>t.has(s)));localStorage.setItem(vr,JSON.stringify(n))}catch{}}function Ki(t){var s;const r={},n={};for(const[o,a]of Object.entries(t)){r[o]=br(a.filter(d=>!d.parentSessionId));for(const d of a.filter(u=>u.parentSessionId))(n[s=d.parentSessionId]??(n[s]=[])).push(d)}for(const o of Object.values(n))o.sort((a,d)=>a.created.localeCompare(d.created));return{roots:r,children:n,projectIds:new Set(Object.keys(t))}}function cr(){return e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M8 6V4h8v2"}),e.jsx("path",{d:"M19 6l-1 14H6L5 6"}),e.jsx("path",{d:"M10 11v5M14 11v5"})]})}function Ji(){const[t]=c.useState(()=>Ki(yr())),[r,n]=c.useState([]),[s,o]=c.useState(!1),[a,d]=c.useState(t.roots),[u,f]=c.useState([]),[p,b]=c.useState(""),[h,w]=c.useState(!1),[S,D]=c.useState(10),[H,V]=c.useState([]),[_,m]=c.useState(t.children),[j,A]=c.useState(t.projectIds),[P,R]=c.useState(new Set),[C,L]=c.useState({}),I=c.useRef(new Map),[T,Q]=c.useState(null),[Z,pe]=c.useState(null),[Y,Se]=c.useState(new Set),[we,nt]=c.useState(new Set),[Ut,rt]=c.useState(new Set),[Xe,Ot]=c.useState(new Set),[Ht,st]=c.useState(!1),[y,$]=c.useState("settings"),le=xe(l=>l.setTodos),ee=ke(l=>l.skin),X=ke(l=>l.layout),te=ke(l=>l.wakeEnabled),Ce=ke(l=>l.wakeWord),ge=ke(l=>l.setSkin),ot=ke(l=>l.setLayout),In=ke(l=>l.setWakeEnabled),Vt=ke(l=>l.setWakeWord),pt=ke(l=>l.autoSpeak),Ye=ke(l=>l.setAutoSpeak),gt=ke(l=>l.runningFirst),Un=ke(l=>l.setRunningFirst),Pe=ke(l=>l.groupByBot),rn=ke(l=>l.setGroupByBot),sn=xe(l=>l.runningSessionId),on=xe(Gs(l=>Object.entries(l.messagesBySession).filter(([,k])=>k.some(z=>z.askUser&&!z.askUser.answered)).map(([k])=>k))),ht=c.useCallback(l=>l.status==="running"||sn===l.id,[sn]),an=c.useCallback(()=>{const l=[];for(const k of r){const z=a[k.id]??[];for(const U of is)z.some(M=>M.agentType===U)&&l.push(`${k.id}::${U}`)}return l},[r,a]),ze=()=>{nt(new Set),rt(new Set(an())),Se(new Set(Object.keys(_)))},Rn=()=>{const l=r.filter(k=>!Xe.has(k.id)).map(k=>k.id);nt(new Set(l)),rt(new Set),Se(new Set);for(const k of l){if(Ge.current.has(k))continue;const z=it.current.has(k);Le(k,{refresh:z,background:z})}},ft=Us(),An=Os(),De=ft&&An,[Mt,Ve]=c.useState(!1),[re,be]=c.useState(!1),[Lt,Tn]=c.useState(null),[qt,Ie]=c.useState(0),[Re,ln]=c.useState(void 0),_e=c.useRef(null),Fe=c.useRef(!1),[dn,Et]=c.useState(null),qe=c.useRef(null),Ke=c.useRef(!1),xt=c.useRef(r);xt.current=r;const cn=c.useRef(Xe);cn.current=Xe;const it=c.useRef(j);it.current=j;const Ge=c.useRef(P);Ge.current=P,c.useEffect(()=>{document.documentElement.setAttribute("data-skin",ee)},[ee]),c.useEffect(()=>{document.body.classList.toggle("layout-compact",X==="compact")},[X]);const mt=c.useCallback(()=>{if(!window.agentApi||!te||Fe.current||_e.current)return;const l=()=>{Xs()&&!_e.current&&(_e.current=Zs({wakeWord:Ce,onWake:k=>{var z;ln(k),Ie(U=>U+1),(z=window.agentApi)==null||z.showWindow()},onError:k=>console.warn("[wake]",k)}))};typeof window.agentApi.wakeStart=="function"?(Fe.current=!0,window.agentApi.wakeStart(Ce).then(k=>{k.ok||(Fe.current=!1,l())}).catch(()=>{Fe.current=!1,l()})):l()},[te,Ce]);c.useEffect(()=>{var l;if((l=window.agentApi)!=null&&l.onWake)return window.agentApi.onWake(k=>{Fe.current=!1,ln(k),Ie(z=>z+1)})},[]),c.useEffect(()=>{var l;if((l=window.agentApi)!=null&&l.onWakeCommand)return window.agentApi.onWakeCommand(k=>{var q;const z=((k==null?void 0:k.text)||"").trim();if(!z)return;const U=qe.current&&Date.now()<qe.current.until?qe.current:null;if(U){U.until=Date.now()+9e4,pe(U.sessionId),(q=window.agentApi)==null||q.wakeConversation(!0),Et({text:z,projectId:null,sessionId:U.sessionId,nonce:Date.now()}),he(`语音追问:${z.length>40?z.slice(0,40)+"…":z}`),Ae("success"),setTimeout(()=>he(null),4e3);return}const M=xt.current.find(se=>se.name&&z.includes(se.name)&&!cn.current.has(se.id));M&&(Q(M.id),nt(se=>{const Te=new Set(se);return Te.add(M.id),Te})),pe(null),Ke.current=!0,Ye(!0),Et({text:z,projectId:(M==null?void 0:M.id)??null,nonce:Date.now()}),he(`语音指令:${z.length>40?z.slice(0,40)+"…":z}${M?`(项目:${M.name})`:""}`),Ae("success"),setTimeout(()=>he(null),4e3)})},[]);const un=c.useCallback(async()=>{window.agentApi&&(mt(),await window.agentApi.hideWindow())},[mt]),de=c.useCallback(l=>{st(!1),Tn({right:l.right,bottom:l.bottom}),be(k=>!k)},[]),zn=c.useCallback(()=>{be(!1),st(l=>!l)},[]);c.useEffect(()=>{if(!re)return;const l=()=>{const z=document.querySelector(".chat-header-action--appearance");if(!z)return;const U=z.getBoundingClientRect();Tn(M=>(M==null?void 0:M.right)===U.right&&M.bottom===U.bottom?M:{right:U.right,bottom:U.bottom})},k=window.requestAnimationFrame(l);return window.addEventListener("resize",l),()=>{window.cancelAnimationFrame(k),window.removeEventListener("resize",l)}},[X,re]),c.useEffect(()=>{window.agentApi&&mt()},[mt]),c.useEffect(()=>{const l=()=>{var k;(k=_e.current)==null||k.stop(),_e.current=null};return window.addEventListener("focus",l),()=>window.removeEventListener("focus",l)},[]),c.useEffect(()=>{var l,k;te||((l=_e.current)==null||l.stop(),_e.current=null,Fe.current=!1,(k=window.agentApi)==null||k.wakeStop())},[te]),c.useEffect(()=>{!te||!window.agentApi||Fe.current&&window.agentApi.wakeStart(Ce)},[Ce]),c.useEffect(()=>()=>{var l;(l=_e.current)==null||l.stop()},[]);const at=Object.values(a).flat(),Kt=[...at,...u],Qe=p.trim().toLowerCase(),$e=Qe?at.filter(l=>l.title.toLowerCase().includes(Qe)||(l.cwd||"").toLowerCase().includes(Qe)):null,Me=Z?Kt.find(l=>l.id===Z):void 0,bt=Me==null?void 0:Me.title,Gt=r.filter(l=>!Xe.has(l.id)).map(l=>l.id),Ue=Gt.length>0&&Gt.every(l=>!we.has(l)),[Ze,et]=c.useState(300),[Wt,Bt]=c.useState(!1),lt=c.useRef(!1),vt=c.useRef(0),Qt=c.useRef(0),yt=c.useCallback(l=>{if(!lt.current)return;const k=Math.min(480,Math.max(160,Qt.current+l.clientX-vt.current));et(k)},[]),wt=c.useCallback(()=>{lt.current=!1,Bt(!1),document.removeEventListener("mousemove",yt),document.removeEventListener("mouseup",wt)},[yt]),pn=c.useCallback(l=>{lt.current=!0,Bt(!0),vt.current=l.clientX,Qt.current=Ze,document.addEventListener("mousemove",yt),document.addEventListener("mouseup",wt)},[Ze,yt,wt]),[jt,he]=c.useState(null),[Jt,Ae]=c.useState("success"),[Nt,gn]=c.useState([]),kt=c.useCallback(l=>{gn(k=>k.filter(z=>z.id!==l))},[]),hn=c.useCallback(l=>{const k=crypto.randomUUID();gn(z=>[...z,{...l,id:k}]),setTimeout(()=>kt(k),12e3)},[kt]);async function St(){if(!window.agentApi)return;const l=await window.agentApi.listProjects();n(l);const k=new Set(l.map(M=>M.id)),z=new Set([...it.current].filter(M=>k.has(M)));qi(k),d(M=>Object.fromEntries(Object.entries(M).filter(([q])=>k.has(q)))),A(M=>{const q=new Set([...M].filter(se=>k.has(se)));return it.current=q,q}),R(M=>{const q=new Set([...M].filter(se=>k.has(se)));return Ge.current=q,q}),L(M=>Object.fromEntries(Object.entries(M).filter(([q])=>k.has(q))));const U=new Set;await Promise.all(l.map(async M=>{M.description&&!await window.agentApi.checkProjectPath(M.description)&&U.add(M.id)})),Ot(U);for(const M of z)U.has(M)||Ge.current.has(M)||Le(M,{refresh:!0,background:!0})}async function Le(l,k={}){var U;if(!window.agentApi)return;const z=(I.current.get(l)??0)+1;I.current.set(l,z),R(M=>{const q=new Set(M).add(l);return Ge.current=q,q}),L(M=>{if(!(l in M))return M;const q={...M};return delete q[l],q});try{const M=k.refresh?await window.agentApi.refreshSessions(l):await window.agentApi.listSessions(l);if(I.current.get(l)!==z)return;const q=new Set((a[l]??[]).map(K=>K.id)),se=br(M.filter(K=>!K.parentSessionId)),Te=(a[l]??[]).find(K=>K.id===Z&&K.agentType!=="customer-agent"&&!se.some(ue=>ue.id===K.id));Te&&se.unshift(Te);const Oe={};for(const K of M.filter(ue=>ue.parentSessionId))(Oe[U=K.parentSessionId]??(Oe[U]=[])).push(K);for(const K of Object.values(Oe))K.sort((ue,J)=>ue.created.localeCompare(J.created));Vi(l,[...se,...Object.values(Oe).flat()]),d(K=>({...K,[l]:se})),m(K=>{const ue={...K};for(const J of q)delete ue[J];for(const[J,ve]of Object.entries(Oe))ue[J]=ve;return ue}),A(K=>{const ue=new Set(K).add(l);return it.current=ue,ue})}catch(M){if(I.current.get(l)!==z)return;L(q=>({...q,[l]:M instanceof Error?M.message:"会话加载失败"}))}finally{I.current.get(l)===z&&R(M=>{const q=new Set(M);return q.delete(l),Ge.current=q,q})}}const Xt=async l=>{if(!window.agentApi)return;const k=await window.agentApi.listChildSessions(l);m(z=>({...z,[l]:k.sort((U,M)=>U.created<M.created?-1:1)}))},fn=async(l,k)=>{if(!window.agentApi)return;const z=await window.agentApi.createSession("新会话",l,k);if(k==="customer-agent"){await Le(l),Q(l),pe(z.id),De&&Ve(!1);return}const U=z.projectId===l?z:{...z,projectId:l};d(M=>({...M,[l]:[U,...(M[l]??[]).filter(q=>q.id!==z.id)]})),f(M=>M.filter(q=>q.id!==z.id)),Q(l),pe(z.id),De&&Ve(!1)};c.useEffect(()=>{window.agentApi&&(St(),Fn.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(V).catch(()=>{}))},[]),c.useEffect(()=>{if(!T||!Z||(Me==null?void 0:Me.agentType)==="customer-agent"||!window.agentApi)return;let l=!1;const k=async()=>{document.visibilityState==="visible"&&(l||await Le(T,{refresh:!0,background:!0}))},z=window.setInterval(()=>void k(),1e4);return()=>{l=!0,window.clearInterval(z)}},[T,Z,Me==null?void 0:Me.agentType]),c.useEffect(()=>{if(!T||!window.agentApi)return;const l=r.find(z=>z.id===T),k=l==null?void 0:l.description;k&&window.agentApi.setProjectWorkingDir(k)},[T,r]);const tt=l=>{const k=!we.has(l);if(nt(z=>{const U=new Set(z);return k?U.add(l):U.delete(l),U}),T!==l&&(Q(l),pe(null)),k&&!Ge.current.has(l)){const z=it.current.has(l);Le(l,{refresh:z,background:z})}},xn=async l=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const k=l.replace(/\\/g,"/"),z=k.split("/").filter(Boolean),U=z[z.length-1]||k||"导入的项目",M=await window.agentApi.createProject(U,k);await St(),Q(M.id),pe(null),await Le(M.id),nt(q=>{const se=new Set(q);return se.add(M.id),se}),he(`已导入:${U}`),Ae("success"),setTimeout(()=>he(null),3e3)},On=async()=>{try{if(!window.agentApi){he("agentApi 未就绪,请重启应用"),Ae("error");return}if(ft){o(!0);return}const l=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",l),!l)return;await xn(l)}catch(l){console.error("[import] error:",l),he(l instanceof Error?l.message:String(l)),Ae("error"),setTimeout(()=>he(null),5e3)}},Mn=async l=>{if(window.agentApi)try{await window.agentApi.deleteProject(l),T===l&&(Q(null),pe(null),le([])),he("项目删除成功"),Ae("success"),setTimeout(()=>he(null),2500),await St()}catch(k){he(k instanceof Error?k.message:"项目删除失败"),Ae("error"),setTimeout(()=>he(null),4e3)}},mn=async l=>{if(window.agentApi)try{await window.agentApi.deleteSession(l),Z===l&&(pe(null),le([])),he("会话删除成功"),Ae("success"),setTimeout(()=>he(null),2500),T&&await Le(T)}catch(k){he(k instanceof Error?k.message:"会话删除失败"),Ae("error"),setTimeout(()=>he(null),4e3)}},Ln=[{id:"settings",label:"设置"},{id:"mcp",label:"MCP"},{id:"memory",label:"记忆"},{id:"skill",label:"技能"},{id:"agent",label:"智能体"},{id:"lsp",label:"LSP"}];return e.jsxs("div",{className:"app-shell",style:{display:"flex",height:ft?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[De&&Mt&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>Ve(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),De&&!Mt&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>Ve(!0),"aria-label":"会话列表","aria-expanded":!1,style:{position:"fixed",top:"calc(env(safe-area-inset-top) + 8px)",left:10,zIndex:1250,width:34,height:34,borderRadius:9,border:"1px solid var(--border-default)",background:"var(--bg-glass, rgba(18,20,28,.82))",color:"var(--text-secondary)",display:"grid",placeItems:"center",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag",cursor:"pointer"},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})})}),e.jsx("div",{className:"app-drag-region",style:{position:"fixed",top:0,left:0,right:0,height:52,zIndex:9999,WebkitAppRegion:"drag",pointerEvents:"none"}}),e.jsx("div",{className:"app-accent-glow",style:{position:"absolute",top:"-120px",left:"-80px",width:320,height:320,borderRadius:"50%",background:"radial-gradient(circle, var(--accent-glow) 0%, transparent 70%)",pointerEvents:"none",zIndex:0}}),X!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:Ze,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 20px",position:"relative",zIndex:10,overflow:"hidden",...De?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:Mt?"translateX(0)":"translateX(-103%)",transition:"transform .24s ease",boxShadow:"12px 0 32px rgba(0,0,0,.5)",padding:"calc(env(safe-area-inset-top) + 12px) 0 20px"}:{}},children:[e.jsx("div",{className:"app-sidebar-brand",style:{padding:"0 20px 10px"},children:e.jsxs("div",{className:"sidebar-brand-row",children:[e.jsx("div",{className:"sidebar-brand-mark","aria-hidden":"true",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15a4 4 0 0 1-4 4H8l-5 3V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4z"}),e.jsx("path",{d:"M7 9h10M7 13h7"})]})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsxs("div",{className:"sidebar-project-toolbar",children:[e.jsx("span",{className:"sidebar-project-title",children:"项目"}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:()=>{w(!0),D(10)},title:"搜索会话","aria-label":"搜索会话",className:"ui-icon-button",children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]})}),e.jsx("button",{type:"button",onClick:()=>rn(!Pe),title:"会话按 Agent 分组","aria-label":"会话按 Agent 分组","aria-pressed":Pe,className:`ui-icon-button${Pe?" is-active":""}`,children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9 6h11M9 12h11M9 18h11"}),e.jsx("path",{d:"M4 6h.01M4 12h.01M4 18h.01"})]})}),e.jsx("button",{type:"button",onClick:Ue?Rn:ze,title:Ue?"展开全部会话":"折叠全部会话","aria-label":Ue?"展开全部会话":"折叠全部会话",disabled:Gt.length===0,className:"ui-icon-button",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Ue?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m7 6 5 5 5-5"}),e.jsx("path",{d:"m7 13 5 5 5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m17 11-5-5-5 5"}),e.jsx("path",{d:"m17 18-5-5-5 5"})]})})}),e.jsx("button",{type:"button",onClick:()=>Un(!gt),title:gt?"按新建时间排序":"进行中会话优先","aria-label":gt?"按新建时间排序":"进行中会话优先","aria-pressed":gt,className:`ui-icon-button sidebar-session-sort${gt?" is-active":""}`,children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h10M3 12h7M3 18h4"}),e.jsx("path",{d:"m15 9 3-3 3 3M18 6v12"})]})}),e.jsx("button",{type:"button",onClick:()=>void On(),title:"导入项目","aria-label":"导入项目",className:"ui-icon-button",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]})]}),jt&&e.jsx("div",{style:{margin:"0 12px 10px",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:Jt==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:Jt==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:Jt==="success"?"var(--success)":"var(--danger)",fontSize:12},children:jt}),e.jsx("div",{className:"app-sidebar-scroll",style:{flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[r.map(l=>{const k=T===l.id&&!Z,z=we.has(l.id),U=j.has(l.id),M=P.has(l.id),q=C[l.id],se=a[l.id]??[],Te=gt?ei(se,ht):se,Oe=Te.length>10,K=Xe.has(l.id);return e.jsxs("div",{className:"sidebar-project-block","aria-busy":M,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${k&&!K?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:K?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{K||tt(l.id)},disabled:K,"aria-expanded":z,title:K?`路径不存在:${l.description}`:l.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:K?"var(--text-muted)":k?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:k&&!K?600:400,cursor:K?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[K?e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:k?1:.5},children:z?e.jsx("path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6A2 2 0 0 1 18.46 20H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}):e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.name}),Te.length>0&&Pe&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:k&&!K?"var(--accent)":"var(--text-muted)",background:k&&!K?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"15px",opacity:.8},children:Te.length})]}),!ft&&e.jsx("button",{onClick:ue=>{ue.stopPropagation(),Mn(l.id)},title:"删除项目","aria-label":`删除项目:${l.name}`,className:"sidebar-project-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{flexShrink:0},children:e.jsx(cr,{})}),e.jsx(xi,{health:H,disabled:K,onSelect:ue=>fn(l.id,ue)})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:z?Oe?300:800:0,opacity:z?1:0,transition:"max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease"},children:e.jsxs("div",{className:`sidebar-project-sessions${Pe?" is-grouped":""}`,style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...Oe?{maxHeight:280,overflowY:"auto"}:{}},children:[(()=>{const ue=J=>{const ve=Z===J.id,Ee=ht(J),We=Yo({status:J.status,isRunning:Ee,needsInput:Ee&&on.includes(J.id)}),Be=_[J.id]??[];return e.jsxs("div",{children:[e.jsxs("div",{className:`sidebar-row sidebar-session-row ${ve?"sidebar-row-active":""}`,style:{paddingRight:4},children:[e.jsxs("button",{className:"sidebar-session-button",onClick:()=>{De&&Ve(!1),Q(l.id),pe(J.id),Be.length>0&&Se(je=>{const dt=new Set(je);return dt.has(J.id)?dt.delete(J.id):dt.add(J.id),dt})},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"6px 10px",border:"none",background:"transparent",color:ve?"var(--accent)":"var(--text-secondary)",fontSize:12,cursor:"pointer",textAlign:"left",transition:"color 0.15s"},children:[e.jsx("span",{className:`sidebar-status-dot is-${We}`,title:Zo[We]}),e.jsx("span",{title:J.sourceLabel,style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:J.title}),J.occupancy==="owned-externally"&&e.jsx("span",{className:"sidebar-occupancy-badge",title:"原客户端正在使用,只读",children:"占用"}),Be.length>0&&Pe&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:ve?"var(--accent)":"var(--text-muted)",background:ve?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"16px",opacity:.8},children:Be.length}),Be.length>0&&e.jsx("svg",{className:`sidebar-session-disclosure${Y.has(J.id)?"":" is-expanded"}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]}),J.canDelete&&e.jsx("button",{onClick:()=>void mn(J.id),title:"删除会话","aria-label":`删除会话:${J.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(cr,{})}),!Pe&&e.jsx("span",{className:`sidebar-runtime-mark sidebar-runtime-mark--${J.agentType}`,children:ss[J.agentType]})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:Y.has(J.id)?0:Be.length*40,opacity:Y.has(J.id)?0:1,transition:"max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease"},children:Be.map(je=>{const dt=Z===je.id;return e.jsxs("div",{className:`sidebar-row ${dt?"sidebar-row-active":""}`,style:{paddingRight:4,marginLeft:14,borderLeft:"1px solid var(--border-subtle)"},children:[e.jsxs("button",{className:"sidebar-session-button",onClick:()=>{Q(l.id),pe(je.id)},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"5px 8px",border:"none",background:"transparent",color:dt?"var(--accent)":"var(--text-muted)",fontSize:11,cursor:"pointer",textAlign:"left",transition:"color 0.15s"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:je.title})]}),e.jsx("button",{onClick:()=>void mn(je.id),title:"删除子会话","aria-label":`删除子会话:${je.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(cr,{})})]},je.id)})})]},J.id)};return Pe?is.map(J=>[J,Te.filter(ve=>ve.agentType===J)]).filter(([,J])=>J.length>0).map(([J,ve])=>{const Ee=`${l.id}::${J}`,We=!Ut.has(Ee);return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:"sidebar-agent-group",onClick:()=>rt(Be=>{const je=new Set(Be);return je.has(Ee)?je.delete(Ee):je.add(Ee),je}),"aria-expanded":We,title:os[J],style:{width:"100%",display:"flex",alignItems:"center",gap:7,padding:"5px 10px 2px 12px",border:0,background:"transparent",color:"var(--text-muted)",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",cursor:"pointer",textAlign:"left"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,transform:We?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.2s ease"},"aria-hidden":"true",children:e.jsx("path",{d:"M6 9l6 6 6-6"})}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:os[J]}),e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,background:"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"15px",opacity:.8},children:ve.length})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:We?ve.length*44+8:0,opacity:We?1:0,transition:"max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease"},children:ve.map(ue)})]},J)}):Te.map(ue)})(),M&&!U&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),q&&e.jsxs("div",{title:q,style:{display:"flex",alignItems:"center",gap:8,color:"var(--danger)",fontSize:11,padding:"4px 10px"},children:[e.jsx("span",{style:{flex:1},children:"会话加载失败"}),e.jsx("button",{type:"button",onClick:()=>void Le(l.id,{refresh:U,background:U}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),Te.length===0&&U&&!M&&!q&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},l.id)}),r.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:"暂无项目"})]})})]}),!De&&e.jsx("div",{className:`app-sidebar-resizer${Wt?" is-dragging":""}`,onMouseDown:pn,style:{left:Ze}}),h&&e.jsx("div",{onClick:()=>w(!1),style:{position:"fixed",inset:0,zIndex:1300,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"12vh 16px 16px"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{width:"min(560px, 100%)",maxHeight:"64vh",display:"flex",flexDirection:"column",borderRadius:12,border:"1px solid var(--border-default)",background:"var(--bg-surface)",boxShadow:"0 18px 48px rgba(17,24,39,0.28)",overflow:"hidden"},children:[e.jsx("div",{style:{padding:10,borderBottom:"1px solid var(--border-subtle)"},children:e.jsx("input",{autoFocus:!0,value:p,onChange:l=>b(l.target.value),onKeyDown:l=>{l.key==="Escape"&&w(!1)},placeholder:"搜索所有会话(标题或目录)…","aria-label":"搜索所有会话",style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"}})}),e.jsxs("div",{style:{overflowY:"auto",padding:8},children:[Qe&&$e&&$e.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[$e.length," 个结果"]}),Qe&&$e&&$e.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!Qe&&at.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),($e??at.slice(0,S)).map(l=>{const k=Z===l.id;return e.jsx("div",{className:`sidebar-row ${k?"sidebar-row-active":""}`,children:e.jsxs("button",{type:"button",onClick:()=>{Q(l.projectId&&r.some(z=>z.id===l.projectId)?l.projectId:null),pe(l.id),w(!1),De&&Ve(!1)},title:`${l.sourceLabel}
150
- ${l.cwd}`,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"6px 10px",border:0,background:"transparent",color:k?"var(--accent)":"var(--text-secondary)",fontSize:12,cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{style:{flexShrink:0,minWidth:22,padding:"1px 3px",borderRadius:3,border:"1px solid var(--border-subtle)",color:k?"var(--accent)":"var(--text-muted)",fontSize:8,fontWeight:700,textAlign:"center"},children:ss[l.agentType]}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.title}),l.occupancy==="owned-externally"&&e.jsx("span",{title:"原客户端正在使用,只读","aria-label":"只读",style:{display:"flex",flexShrink:0},children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2"}),e.jsx("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]})})]})},l.id)}),!Qe&&at.length>S&&e.jsx("button",{type:"button",onClick:()=>D(l=>l+10),style:{width:"100%",padding:"8px 10px",border:0,borderTop:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",textAlign:"center"},children:"更多…"})]})]})})]}),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[X==="focus"&&e.jsx("button",{onClick:()=>ot("standard"),title:"返回标准布局",style:{position:"absolute",top:12,left:12,zIndex:100,padding:"5px 10px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag"},children:"← 侧边栏"}),e.jsx("div",{style:{height:"100%",paddingTop:0},children:e.jsx(Xo,{selectedProjectId:T,selectedSessionId:Z,sessionTitle:bt,sessionSummary:Me,voiceCommand:dn,onOpenSettings:zn,settingsOpen:Ht,onHideToBackground:()=>void un(),onToggleAppearance:de,appearanceOpen:re,hideToBackgroundTitle:te?`隐藏到后台(说“${Ce}”唤醒)`:"隐藏到后台",onSessionCreated:async l=>{var k;pe(l),Ke.current&&(Ke.current=!1,qe.current={sessionId:l,until:Date.now()+9e4},(k=window.agentApi)==null||k.wakeConversation(!0)),T&&await Le(T)},onSubSessionCreated:async l=>{await Xt(l)},onSelectSession:l=>{pe(l)},onSubAgentEvent:l=>{l.type==="started"?hn({type:"info",title:"子会话已启动",body:`${l.agentName}:${l.task.slice(0,60)}`,sessionId:l.subSessionId}):l.type==="completed"?hn({type:"success",title:"子会话已完成",body:`${l.agentName}:${l.task.slice(0,60)}`,sessionId:l.subSessionId}):hn({type:"error",title:"子会话出错",body:`${l.agentName}:${l.task.slice(0,60)}`,sessionId:l.subSessionId})},onMessageSent:(l,k)=>{d(z=>{const U={};for(const[M,q]of Object.entries(z))U[M]=q.map(se=>se.id===l?{...se,title:k.slice(0,60)||se.title}:se);return U}),f(z=>z.map(U=>U.id===l?{...U,title:k.slice(0,60)||U.title}:U))},onRunComplete:async(l,k)=>{var q;const z=qe.current,U=Eo(z,k);qe.current=U,U!==z&&((q=window.agentApi)==null||q.wakeConversation(!0));const M=l||T;M&&await Le(M,{refresh:!0,background:!0})}})})]}),Ht&&zt.createPortal(e.jsx("div",{onClick:()=>st(!1),style:{position:"fixed",inset:0,zIndex:10001,background:"rgba(17,24,39,0.18)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.2s var(--ease-out)",WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{width:"min(920px, calc(100vw - 48px))",height:"min(760px, calc(100vh - 48px))",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:"var(--shadow-md)",overflow:"hidden",display:"flex",flexDirection:"column",animation:"fadeInUp 0.25s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border-subtle)",padding:"8px 10px",background:"var(--bg-deepest)"},children:[e.jsx("div",{style:{display:"flex",gap:6},children:Ln.map(l=>e.jsx("button",{onClick:()=>$(l.id),className:`settings-tab ${y===l.id?"settings-tab-active":""}`,children:l.label},l.id))}),e.jsx("button",{onClick:()=>st(!1),title:"关闭",className:"ui-icon-button ui-icon-button--close ui-icon-button--danger",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[y==="settings"&&e.jsx(ni,{}),y==="mcp"&&e.jsx(oi,{}),y==="memory"&&e.jsx(ii,{}),y==="skill"&&e.jsx(li,{}),y==="agent"&&e.jsx(ui,{}),y==="lsp"&&e.jsx(gi,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),re&&Lt&&zt.createPortal(e.jsx("div",{onClick:()=>be(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(Lt.right-320,window.innerWidth-332)),top:Lt.bottom+8,width:320,maxHeight:`calc(100vh - ${Lt.bottom+20}px)`,overflowY:"auto",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"16px",display:"flex",flexDirection:"column",gap:16,animation:"fadeInUp 0.2s var(--ease-out)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"皮肤"}),e.jsx("div",{className:"appearance-choices",children:Hs.map(l=>e.jsxs("button",{onClick:()=>ge(l.id),className:`appearance-choice ${ee===l.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${l.preview[0]} 55%, ${l.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:ee===l.id?600:400},children:l.label}),ee===l.id&&e.jsx("svg",{className:"appearance-choice-check",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m5 12 4 4L19 6"})})]},l.id))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"布局"}),e.jsx("div",{className:"appearance-segmented",children:Vs.map(l=>e.jsx("button",{onClick:()=>ot(l.id),title:l.description,className:`appearance-segment ${X===l.id?"appearance-segment-active":""}`,children:l.label},l.id))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,borderTop:"1px solid var(--border-subtle)",paddingTop:12},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em"},children:"语音"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["助手回复自动播报",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:pt,onChange:l=>Ye(l.target.checked)})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["隐藏后语音唤醒",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:te,onChange:l=>In(l.target.checked)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{flexShrink:0},children:"唤醒词"}),e.jsx("input",{value:Ce,onChange:l=>Vt(l.target.value||"小智"),style:{flex:1,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-primary)",fontSize:12}})]})]})]})}),document.body),e.jsx(Hi,{open:s,onCancel:()=>o(!1),onConfirm:async l=>{await xn(l),o(!1)}}),e.jsx(hi,{trigger:qt,heardText:Re}),Nt.length>0&&zt.createPortal(e.jsx("div",{style:{position:"fixed",bottom:24,right:24,zIndex:2e4,display:"flex",flexDirection:"column",gap:10,alignItems:"flex-end",pointerEvents:"none"},children:Nt.map(l=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${l.type==="error"?"rgba(220,38,38,0.25)":l.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${l.type==="error"?"var(--danger)":l.type==="success"?"var(--success)":"var(--accent)"}`,borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"12px 14px",animation:"fadeInUp 0.22s var(--ease-out)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsxs("span",{style:{fontSize:12,fontWeight:600,color:l.type==="error"?"var(--danger)":l.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[l.type==="error"?"✕":l.type==="success"?"✓":"◎"," ",l.title]}),e.jsx("button",{onClick:()=>kt(l.id),title:"关闭",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:14,lineHeight:1,padding:"2px 4px",borderRadius:4,transition:"color 0.15s"},onMouseEnter:k=>k.currentTarget.style.color="var(--text-primary)",onMouseLeave:k=>k.currentTarget.style.color="var(--text-muted)",children:"×"})]}),e.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)",lineHeight:1.5,wordBreak:"break-all"},children:l.body}),l.sessionId&&e.jsx("button",{onClick:()=>{pe(l.sessionId),kt(l.id)},style:{marginTop:8,padding:"4px 10px",fontSize:11,fontWeight:500,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid var(--border-glow)",borderRadius:6,cursor:"pointer",transition:"background 0.15s",WebkitAppRegion:"no-drag"},onMouseEnter:k=>k.currentTarget.style.background="var(--accent-glow)",onMouseLeave:k=>k.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},l.id))}),document.body)]})}export{Ji as default};
111
+ */const mo=me("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function Mr(t,r){const n=t??[],s=n.findIndex(a=>a.itemId===r.itemId&&a.sectionIndex===r.sectionIndex);return(s<0?[...n,{itemId:r.itemId,sectionIndex:r.sectionIndex,text:r.delta}]:n.map((a,l)=>l===s?{...a,text:a.text+r.delta}:a)).sort((a,l)=>a.sectionIndex-l.sectionIndex)}function Lr(t){let r=[];for(const n of t)if(n.type==="runtime_progress"){const{type:s,...o}=n;r=ps(r,o)}else(n.type==="done"||n.type==="turn_aborted"||n.type==="error")&&(r=[]);return r}function ps(t,r){const n=t.findIndex(s=>s.progressId===r.progressId);return n<0?[...t,r]:t.map((s,o)=>o===n?r:s)}function bo(t,r){return[...t].reverse().find(n=>n.toolCallId===r)}function vo(t){return[...t].reverse().find(r=>!r.toolCallId)}function Wr(t){for(let r=t.length-1;r>=0;r--)if(t[r].type==="context_usage"&&t[r].usage)return t[r].usage}function Er(t){var n;const r=new Map;for(const s of t)s.type==="native_subagent_update"&&((n=s.activity)!=null&&n.parentToolCallId)&&r.set(s.activity.parentToolCallId,s.activity);return[...r.values()]}function Br(t,r){var n,s;if(r.role==="assistant"&&((n=r.toolCalls)!=null&&n.length)){const o=t[t.length-1];if(o&&o.role==="assistant"&&!((s=o.toolCalls)!=null&&s.length))return[...t.slice(0,-1),{...o,content:o.content,toolCalls:r.toolCalls}]}return[...t,r]}function Nr(t,r){var s;if(!r)return t;const n=t[t.length-1];if(n&&n.role==="assistant"&&!((s=n.toolCalls)!=null&&s.length)&&!n.askUser&&!n.isCompactionSummary){const o=[...t];return o[o.length-1]={...n,content:n.content+r},o}return[...t,{id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()}]}function Pr(t,r,n,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(l=>l.id===r?{...l,result:n,isError:s}:l);return{...o,toolCalls:a}})}function Dr(t,r,n,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(l=>l.name==="dispatch_agent"&&l.arguments.subSessionId===r?{...l,arguments:{...l.arguments,subAgentStatus:n,subAgentDetail:s}}:l);return{...o,toolCalls:a}})}function _r(t,r,n){return t.map(s=>{if(!s.toolCalls)return s;const o=s.toolCalls.map(a=>a.name==="dispatch_agent"&&a.arguments.subSessionId===r?{...a,arguments:{...a.arguments,subAgentProgress:(a.arguments.subAgentProgress?a.arguments.subAgentProgress+`
112
+ `+n:n).split(`
113
+ `).slice(-30).join(`
114
+ `)}}:a);return{...s,toolCalls:o}})}function Fr(t,r,n){return t.map(s=>s.id===r?n(s):s)}function $r(t,r){const n=t.findIndex(s=>{var o,a;return(a=(o=s.presentation)==null?void 0:o.reasoning)==null?void 0:a.some(l=>l.itemId===r.itemId)});return n<0?[...t,{id:`native-reasoning:${r.itemId}`,role:"assistant",content:"",presentation:{reasoning:Mr(void 0,r)},timestamp:Date.now()}]:t.map((s,o)=>{var a;return o===n?{...s,presentation:{...s.presentation,reasoning:Mr((a=s.presentation)==null?void 0:a.reasoning,r)}}:s})}const xe=ls((t,r)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(n,s)=>t(o=>{const a=s??o.sessionId??void 0,l=a&&a!==o.sessionId?o.messages:Br(o.messages,n),u=a?{...o.messagesBySession,[a]:Br(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:l,messagesBySession:u,currentText:a&&a!==o.sessionId?o.currentText:""}}),appendText:(n,s)=>t(o=>{if(!n)return o;const a=s??o.sessionId??void 0,l=a&&a!==o.sessionId?o.messages:Nr(o.messages,n),u=a?{...o.messagesBySession,[a]:Nr(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:l,messagesBySession:u,currentText:a&&a!==o.sessionId?o.currentText:o.currentText+n}}),setRunningSession:n=>t({runningSessionId:n}),setSessionId:n=>t({sessionId:n}),updateToolResult:(n,s,o,a)=>t(l=>{const u=a??l.sessionId??void 0,f=u&&u!==l.sessionId?l.messages:Pr(l.messages,n,s,o),p=u?{...l.messagesBySession,[u]:Pr(l.messagesBySession[u]??(u===l.sessionId?l.messages:[]),n,s,o)}:l.messagesBySession;return{messages:f,messagesBySession:p}}),setMessages:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return{messages:n,messagesBySession:a?{...o.messagesBySession,[a]:n}:o.messagesBySession,currentText:""}}),getMessagesForSession:n=>r().messagesBySession[n]??[],setContextUsage:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{contextUsageBySession:{...o.contextUsageBySession,[a]:n}}:o}),getContextUsageForSession:n=>r().contextUsageBySession[n],applyRuntimeProgress:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:ps(o.runtimeProgressBySession[a]??[],n)}}:o}),setRuntimeProgress:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:n}}:o}),clearRuntimeProgress:n=>t(s=>{var u;const o=n??s.sessionId??void 0;if(!o||!((u=s.runtimeProgressBySession[o])!=null&&u.length))return s;const{[o]:a,...l}=s.runtimeProgressBySession;return{runtimeProgressBySession:l}}),applyNativeSubagentActivity:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:{...o.nativeSubagentsBySession[a]??{},[n.parentToolCallId]:n}}}:o}),setNativeSubagentActivities:(n,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:Object.fromEntries(n.map(l=>[l.parentToolCallId,l]))}}:o}),applyReasoningSummary:(n,s)=>t(o=>{const a=s??o.sessionId??void 0,l=a&&a!==o.sessionId?o.messages:$r(o.messages,n),u=a?{...o.messagesBySession,[a]:$r(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),n)}:o.messagesBySession;return{messages:l,messagesBySession:u}}),updateMessage:(n,s,o)=>t(a=>{const l=o??a.sessionId??void 0,u=l&&l!==a.sessionId?a.messages:Fr(a.messages,n,s),f=l?{...a.messagesBySession,[l]:Fr(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:u,messagesBySession:f}}),updateSubAgentStatus:(n,s,o,a)=>t(l=>{const u=a??l.sessionId??void 0,f=u&&u!==l.sessionId?l.messages:Dr(l.messages,n,s,o),p=u?{...l.messagesBySession,[u]:Dr(l.messagesBySession[u]??(u===l.sessionId?l.messages:[]),n,s,o)}:l.messagesBySession;return{messages:f,messagesBySession:p}}),updateSubAgentProgress:(n,s,o)=>t(a=>{const l=o??a.sessionId??void 0,u=l&&l!==a.sessionId?a.messages:_r(a.messages,n,s),f=l?{...a.messagesBySession,[l]:_r(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:u,messagesBySession:f}}),clearMessages:n=>t(s=>{const o=n??s.sessionId??void 0;if(!o)return{messages:[],currentText:""};const{[o]:a,...l}=s.messagesBySession,{[o]:u,...f}=s.contextUsageBySession,{[o]:p,...b}=s.runtimeProgressBySession,{[o]:h,...w}=s.nativeSubagentsBySession;return{messages:o===s.sessionId?[]:s.messages,messagesBySession:l,contextUsageBySession:f,runtimeProgressBySession:b,nativeSubagentsBySession:w,currentText:o===s.sessionId?"":s.currentText}}),setTodos:n=>t({todos:n}),setCronTasks:n=>t({cronTasks:n})}));function hr(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function gs(){if(typeof window>"u")return null;const t=window.agentApi;return typeof(t==null?void 0:t.dictationStart)!="function"||typeof t.dictationStop!="function"||typeof t.onDictation!="function"||typeof t.onDictationError!="function"?null:t}function yo(){return gs()!==null||hr()!==null}function wo(t){var a,l;const r=gs();if(r){let u=!1,f=()=>{},p=()=>{};const b=()=>{var h;u||(u=!0,f(),p(),(h=t.onEnd)==null||h.call(t))};return f=r.onDictation(({text:h,isFinal:w})=>{const S=h.trim();S&&(w?(t.onFinal(S),b()):t.onInterim(S))}),p=r.onDictationError(h=>{var w;(w=t.onError)==null||w.call(t,h),b()}),r.dictationStart().then(h=>{var w;h.ok||((w=t.onError)==null||w.call(t,h.reason||"无法启动语音识别"),b())}).catch(()=>{var h;(h=t.onError)==null||h.call(t,"无法启动语音识别"),b()}),{stop:()=>{r.dictationStop()}}}const n=hr();if(!n)return(a=t.onError)==null||a.call(t,"当前环境不支持语音识别"),null;const s=new n;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let o="";s.onresult=u=>{let f="";for(let p=u.resultIndex;p<u.results.length;p++){const b=u.results[p];b.isFinal?o+=b[0].transcript:f+=b[0].transcript}f&&t.onInterim(o+f)},s.onerror=u=>{var f;u.error!=="no-speech"&&u.error!=="aborted"&&((f=t.onError)==null||f.call(t,`语音识别失败:${u.error??"未知错误"}`))},s.onend=()=>{var u;o&&t.onFinal(o.trim()),(u=t.onEnd)==null||u.call(t)};try{s.start()}catch{return(l=t.onEnd)==null||l.call(t),null}return{stop:()=>s.stop()}}function jo(t){var l;const r=hr();if(!r)return(l=t.onError)==null||l.call(t,"当前环境不支持语音唤醒"),null;let n=!1,s=null,o=null;const a=()=>{if(!n){s=new r,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=u=>{var b,h,w;const f=u.results[u.results.length-1],p=(h=(b=f==null?void 0:f[0])==null?void 0:b.transcript)==null?void 0:h.trim();p&&(f.isFinal&&((w=t.onHeard)==null||w.call(t,p)),p.includes(t.wakeWord)&&t.onWake(p))},s.onerror=u=>{var f;u.error==="not-allowed"&&((f=t.onError)==null||f.call(t,"麦克风权限被拒绝,语音唤醒已停用"),n=!0)},s.onend=()=>{n||(o=setTimeout(a,400))};try{s.start()}catch{o=setTimeout(a,800)}}};return a(),{stop:()=>{n=!0,o&&clearTimeout(o);try{s==null||s.abort()}catch{}}}}function wn(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function En(t,r){return r(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const ko={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function So(t){const r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(r.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const n=new Float32Array(r.byteLength/2),s=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let o=0;o<n.length;o+=1)n[o]=s.getInt16(o*2,!0)/32768;return n}class Co{constructor(r,n=ko){this.api=r,this.dependencies=n,this.context=null,this.node=null,this.ready=null,this.current=null}start(r){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const n={metadata:r,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=n,this.ensureReady().then(()=>{if(!(this.current!==n||!this.node)){this.node.port.postMessage({type:"start",generation:r.generation,sampleRate:r.sampleRate});for(const o of n.pending)this.postSamples(r.generation,o);n.pending=[],n.pendingSamples=0,n.finished&&this.node.port.postMessage({type:"finish",generation:r.generation})}}).catch(o=>this.fail(n,o))}enqueue(r,n){const s=this.current;if(!s||s.metadata.generation!==r||s.acknowledged)return;let o;try{o=So(n)}catch(a){this.fail(s,a);return}if(this.node){this.postSamples(r,o);return}if(s.pendingSamples+o.length>s.metadata.sampleRate){this.fail(s,new Error("TTS PCM queue overflow"));return}s.pending.push(o),s.pendingSamples+=o.length}finish(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||(n.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:r}))}flush(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:r}),n.pending=[],n.pendingSamples=0,this.acknowledge(n))}dispose(){var r,n;this.current&&this.flush(this.current.metadata.generation),(r=this.node)==null||r.disconnect(),this.node=null,(n=this.context)==null||n.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const r=this.dependencies.createContext();this.context=r,await r.audioWorklet.addModule(this.dependencies.workletUrl);const n=this.dependencies.createNode(r);n.port.onmessage=s=>this.onWorkletMessage(s.data),n.connect(r.destination),this.node=n,r.state!=="running"&&await r.resume()})(),this.ready)}postSamples(r,n){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:r,samples:n},[n.buffer])}onWorkletMessage(r){const n=this.current;if(!(!n||r.generation!==n.metadata.generation)){if(r.type==="drained"||r.type==="stopped"){this.acknowledge(n);return}r.type==="overflow"&&this.fail(n,new Error("TTS AudioWorklet buffer overflow"))}}fail(r,n){this.current!==r||r.acknowledged||(console.error("[tts] PCM playback failed",n),r.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(r.metadata.generation))}acknowledge(r){this.current!==r||r.acknowledged||(r.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(r.metadata.generation))}}function Jn(t){var b;const r=(t==null?void 0:t.messages)??[],n=(t==null?void 0:t.events)??[],s=new Set(n.filter(h=>h.type==="approval_resolved"&&h.questionId).map(h=>h.questionId)),o=new Map;for(const h of n)h.type==="tool_result"&&((b=h.result)!=null&&b.toolCallId)&&o.set(h.result.toolCallId,{content:h.result.content??"",isError:h.result.isError});const a=r.filter(h=>(h.role==="user"||h.role==="assistant"||h.role==="tool")&&h.name!=="__interrupt__").map(Ao),l=new Map;for(const h of a)h.role==="tool"&&h.toolCallId&&l.set(h.toolCallId,h);let u=a.filter(h=>h.role!=="tool").map(h=>{var w;return h.isCompactionSummary?h:h.role==="assistant"&&((w=h.toolCalls)!=null&&w.length)?{...h,toolCalls:h.toolCalls.map(S=>{const D=l.get(S.id);if(D)return{...S,result:D.content};const H=o.get(S.id);return H?{...S,result:H.content,isError:H.isError}:S})}:h.role==="user"&&h.name&&h.name!=="__compaction_checkpoint__"?{...h,agentName:h.name}:h});const f=Ro(n);if(!u.some(h=>h.role==="assistant"&&!h.isCompactionSummary)&&f){const h=u.findLastIndex(w=>w.role==="user"&&!w.isCompactionSummary);u=h>=0?[...u.slice(0,h+1),f,...u.slice(h+1)]:[...u,f]}const p=new Set(u.flatMap(h=>{var w;return(w=h.askUser)!=null&&w.questionId?[h.askUser.questionId]:[]}));for(const h of n)h.type!=="ask_user"||!h.questionId||s.has(h.questionId)||p.has(h.questionId)||(p.add(h.questionId),u.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:h.questionId,question:h.question??"",options:h.options,fields:h.fields,multiSelect:h.multiSelect},timestamp:Date.now()}));return u}function Io(t,r){if(r.length===0)return t;if(t.length===0)return r;const n=t.map(Xn),s=r.map(Xn),o=Math.max(0,t.length-r.length);let a={currentStart:o,length:0,distance:1/0};for(let f=0;f<n.length;f++)for(let p=0;p<s.length;p++){if(n[f]!==s[p])continue;const b=f-p;if(b<0)continue;let h=0;for(;f+h<n.length&&p+h<s.length&&n[f+h]===s[p+h];)h+=1;const w=Math.abs(b-o);(h>a.length||h===a.length&&w<a.distance)&&(a={currentStart:b,length:h,distance:w})}const l=a.length>0?a.currentStart:o,u=r.map((f,p)=>{const b=t[l+p];return!b||Xn(b)!==s[p]?f:{...f,id:b.id,timestamp:b.timestamp}});return[...t.slice(0,l),...u]}function Xn(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,name:t.name,agentName:t.agentName,presentation:t.presentation,isCompactionSummary:t.isCompactionSummary})}function Ao(t){var r;if(t.name==="__compaction_checkpoint__"){let n="";try{n=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:n,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(r=t.toolCalls)!=null&&r.length?t.toolCalls:void 0,toolCallId:t.toolCallId,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function Ro(t){var o;let r="";const n=[],s=new Map;for(const a of t){if(a.type==="text_chunk"&&a.text&&(r+=a.text),a.type==="tool_call"&&a.toolCall){const l={id:a.toolCall.id,name:a.toolCall.name,arguments:a.toolCall.arguments};n.push(l),s.set(l.id,l)}if(a.type==="tool_result"&&((o=a.result)!=null&&o.toolCallId)){const l=s.get(a.result.toolCallId);l&&(l.result=a.result.content??"",l.isError=a.result.isError)}}return!r.trim()&&n.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:n.length>0?n:void 0,timestamp:Date.now()}}function To(t){return t==="customer-agent"||t==="claude-code"}function zo(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),Object.assign(r.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(r);try{return r.focus(),r.select(),r.setSelectionRange(0,r.value.length),document.execCommand("copy")}catch{return!1}finally{r.remove()}}async function Mo(t){const r=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(r==null?void 0:r.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await r.writeText(t),!0}catch{}return zo(t)}const Lo="agentroam:draft:";function _n(t){return`${Lo}${t}`}function Wo(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(_n(t))??""}catch{return""}}function Yn(t,r){if(!(!t||typeof window>"u"))try{r?window.localStorage.setItem(_n(t),r):window.localStorage.removeItem(_n(t))}catch{}}function Eo(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(_n(t))}catch{}}const Bo="agent-webapp:artifact-open:v1";let Ur=0;function No(t,r=window){return r.parent===r?!1:(Ur+=1,r.parent.postMessage({type:Bo,requestId:Ur,path:t},r.location.origin),!0)}function Bn(t,r){return t.find(n=>n.id===r)??null}const Fn=ls((t,r)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(n,s)=>t(o=>{const a={...o,[n]:s};return a.isConfigured=!!(a.apiKey&&a.modelId),a}),loadFromSystem:async()=>{if(window.agentApi)try{const n=await window.agentApi.getSettings(),s=n.profiles??[],o=n.activeProfileId??"",a=Bn(s,o);t({modelProvider:(a==null?void 0:a.provider)??n.modelProvider??"anthropic",modelId:(a==null?void 0:a.modelId)??n.modelId??"claude-sonnet-4-6",apiKey:(a==null?void 0:a.apiKey)??n.apiKey??"",baseUrl:(a==null?void 0:a.baseUrl)??n.baseUrl??"",maxIterations:n.maxIterations??10,contextWindow:n.contextWindow??100,workingDirectory:n.workingDirectory??"/",isConfigured:!!(((a==null?void 0:a.apiKey)??n.apiKey)&&((a==null?void 0:a.modelId)??n.modelId)),profiles:s,activeProfileId:o,reasoningEffort:["off","low","medium","high"].includes(n.reasoningEffort??"")?n.reasoningEffort:"off"})}catch(n){console.error("Failed to load settings:",n)}},saveToSystem:async()=>{if(!window.agentApi)return;const n=r();await window.agentApi.saveSettings({modelProvider:n.modelProvider,modelId:n.modelId,apiKey:n.apiKey,baseUrl:n.baseUrl,maxIterations:n.maxIterations,contextWindow:n.contextWindow,workingDirectory:n.workingDirectory,isConfigured:n.isConfigured,profiles:n.profiles,activeProfileId:n.activeProfileId,reasoningEffort:n.reasoningEffort})},addProfile:n=>{const o={id:crypto.randomUUID(),...n};t(a=>({profiles:[...a.profiles,o]}))},updateProfile:(n,s)=>{t(a=>({profiles:a.profiles.map(l=>l.id===n?{...l,...s}:l)}));const o=r();if(o.activeProfileId===n){const a=Bn(o.profiles,n);a&&t({modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})}},deleteProfile:n=>{t(s=>{var u;const o=s.profiles.filter(f=>f.id!==n),a=s.activeProfileId===n?((u=o[0])==null?void 0:u.id)??"":s.activeProfileId,l=Bn(o,a);return{profiles:o,activeProfileId:a,...l?{modelProvider:l.provider,modelId:l.modelId,apiKey:l.apiKey,baseUrl:l.baseUrl,isConfigured:!!(l.apiKey&&l.modelId)}:{}}})},setActiveProfileLocal:n=>{const s=r(),o=Bn(s.profiles,n);o&&t({activeProfileId:n,modelProvider:o.provider,modelId:o.modelId,apiKey:o.apiKey,baseUrl:o.baseUrl,isConfigured:!!(o.apiKey&&o.modelId)})},switchActiveProfile:async n=>{r().setActiveProfileLocal(n),window.agentApi&&await window.agentApi.setActiveProfile(n)}}));function tn(t){return t.result!==void 0}function Or(t){return t.every(tn)}const hs=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),fs=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),Po=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]);function xs(t){return hs.has(t)?"command":fs.has(t)?"file":Po.has(t)?"search":"generic"}function fr(t){switch(t){case"shell":case"bash":case"Bash":case"execute_command":case"run_command":return{done:"运行了命令",doing:"运行命令中"};case"BashOutput":case"KillShell":return{done:"查看了命令输出",doing:"查看输出中"};case"Read":case"read_file":return{done:"读取了文件",doing:"读取文件中"};case"Write":case"write_file":return{done:"写入了文件",doing:"写入文件中"};case"Edit":case"MultiEdit":case"str_replace":case"apply_patch":return{done:"修改了文件",doing:"修改文件中"};case"Glob":case"glob_search":return{done:"搜索了文件",doing:"搜索文件中"};case"Grep":case"grep_search":return{done:"搜索了内容",doing:"搜索内容中"};case"Skill":return{done:"调用了技能",doing:"调用技能中"};case"Task":return{done:"启动了子任务",doing:"启动子任务中"};case"WebSearch":return{done:"搜索了网络",doing:"搜索网络中"};case"WebFetch":return{done:"读取了网页",doing:"读取网页中"};case"TodoWrite":return{done:"更新了任务清单",doing:"更新任务清单中"};case"NotebookEdit":return{done:"编辑了 Notebook",doing:"编辑 Notebook 中"};default:return t.startsWith("mcp__")||t.includes(":")?{done:"调用了工具",doing:"调用工具中"}:null}}function Do(t){var r;return((r=fr(t))==null?void 0:r.done)??null}function Hr(t){return t.replace(/\\/g,"/").split("/").pop()??t}function Zn(t,r=60){const n=(t??"").split(`
115
+ `)[0].trim();return n.length>r?n.slice(0,r)+"…":n}function _o(t,r){if(hs.has(t))return Zn(String(r.command??""));if(t==="apply_patch"){const s=(Array.isArray(r.changes)?r.changes:[]).map(o=>Hr(String((o==null?void 0:o.path)??""))).filter(Boolean);return s.length?s.length<=3?s.join("、"):`${s.slice(0,3).join("、")} 等 ${s.length} 个文件`:null}return fs.has(t)?r.file_path?Hr(String(r.file_path)):null:t==="Glob"||t==="glob_search"?String(r.pattern??"")||null:t==="Grep"||t==="grep_search"?String(r.pattern??r.query??"")||null:t==="Skill"?String(r.skill??"")||null:t==="Task"?Zn(String(r.description??r.task??""),80)||null:t==="WebSearch"?Zn(String(r.query??"")):t==="WebFetch"?String(r.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function ms({progress:t,compact:r=!1}){const n=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),s=[t.label,n].filter(Boolean).join(",");return e.jsxs("div",{className:`runtime-progress-row${r?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":s,children:[e.jsx("span",{className:"runtime-progress-row__spinner","aria-hidden":"true"}),e.jsx("span",{className:"runtime-progress-row__label",children:t.label}),n&&e.jsx("span",{className:"runtime-progress-row__detail",children:n})]})}function nn({isDone:t,isError:r,color:n,size:s=11}){return t?r?e.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}):e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"spin 1s linear infinite",flexShrink:0},children:e.jsx("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"})})}function bs({family:t,color:r,size:n=12}){return t==="command"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):t==="search"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}):t==="file"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}):e.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})})}function $n({statusColor:t,isDone:r,expanded:n,onToggle:s,header:o,children:a,maxBodyHeight:l=600}){return e.jsxs("div",{className:"tool-call-shell",style:{marginTop:4,borderRadius:9,border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-deepest)",fontSize:12,minWidth:0},children:[e.jsxs("div",{className:"tool-call-shell__row",style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{className:"tool-call-shell__status",style:{width:3,flexShrink:0,background:t,animation:r?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),e.jsxs("button",{className:"tool-call-shell__header",onClick:s,style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:u=>u.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:u=>u.currentTarget.style.background="var(--bg-deep)",children:[o,e.jsx("svg",{className:"tool-call-shell__chevron",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(180deg)":"rotate(0deg)",flexShrink:0},children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})]}),n&&e.jsx("div",{className:"tool-call-shell__body",style:{overflow:"hidden",maxHeight:l,opacity:1,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{className:"tool-call-shell__body-content",style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:a})})]})}function Cn({label:t,color:r="var(--text-muted)",bg:n="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:n,color:r,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function xr(t){return t.replace(/\\/g,"/").split("/").pop()??t}function vs(t){return t?t.split(`
116
+ `).length:0}function ys(t,r){const n=t.split(`
117
+ `),s=r.split(`
118
+ `);if(n.length*s.length>2e5)return s.map((S,D)=>({type:"added",text:S,lineNo:D+1}));const o=n.length,a=s.length,l=Array.from({length:o+1},()=>new Array(a+1).fill(0));for(let S=1;S<=o;S++)for(let D=1;D<=a;D++)l[S][D]=n[S-1]===s[D-1]?l[S-1][D-1]+1:Math.max(l[S-1][D],l[S][D-1]);const u=[];let f=o,p=a;for(;f>0&&p>0;)n[f-1]===s[p-1]?(u.unshift([f-1,p-1]),f--,p--):l[f-1][p]>=l[f][p-1]?f--:p--;const b=[];let h=0,w=0;for(const[S,D]of u){for(;h<S;)b.push({type:"removed",text:n[h],lineNo:h+1}),h++;for(;w<D;)b.push({type:"added",text:s[w],lineNo:w+1}),w++;b.push({type:"same",text:n[h],lineNo:h+1}),h++,w++}for(;h<o;)b.push({type:"removed",text:n[h],lineNo:h+1}),h++;for(;w<a;)b.push({type:"added",text:s[w],lineNo:w+1}),w++;return b}function ws({content:t,maxHeight:r=320}){const n=t.split(`
119
+ `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:n.map((s,o)=>e.jsxs("tr",{children:[e.jsx("td",{style:{padding:"0 8px",color:"var(--text-muted)",textAlign:"right",userSelect:"none",borderRight:"1px solid var(--border-subtle)",background:"var(--bg-deep)",fontSize:10,minWidth:36},children:o+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:s||" "})]},o))})]})})}function js({diff:t,maxHeight:r=360}){if(t.filter(u=>u.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const s=new Set(t.map((u,f)=>u.type!=="same"?f:-1).filter(u=>u>=0)),o=new Set;s.forEach(u=>{for(let f=Math.max(0,u-3);f<=Math.min(t.length-1,u+3);f++)o.add(f)});const a=[];let l=-1;return[...o].sort((u,f)=>u-f).forEach(u=>{l>=0&&u>l+1&&a.push("ellipsis"),a.push({diffLine:t[u],diffIdx:u}),l=u}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:a.map((u,f)=>{if(u==="ellipsis")return e.jsx("tr",{children:e.jsx("td",{colSpan:3,style:{padding:"2px 12px",color:"var(--text-muted)",fontSize:10,background:"var(--bg-deep)",textAlign:"center"},children:"⋯"})},`e${f}`);const{diffLine:p}=u,b=p.type==="added"?"rgba(5,150,105,0.08)":p.type==="removed"?"rgba(220,38,38,0.07)":"transparent",h=p.type==="added"?"+":p.type==="removed"?"−":" ",w=p.type==="added"?"var(--success)":p.type==="removed"?"var(--danger)":"transparent",S=p.type==="added"?"#059669":p.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:b},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:w,fontWeight:700,userSelect:"none"},children:h}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:p.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:S,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:p.text||" "})]},f)})})]})})}function Fo({toolCall:t,beforeContent:r}){const[n,s]=c.useState(!1),[o,a]=c.useState("content"),l=t.arguments.file_path??"",u=t.arguments.content??"",f=vs(u),p=t.isError,b=tn(t),h=b?p?"var(--danger)":"var(--success)":"var(--accent)",w=c.useMemo(()=>r&&u?ys(r,u):null,[r,u]),S=c.useMemo(()=>w?{added:w.filter(V=>V.type==="added").length,removed:w.filter(V=>V.type==="removed").length}:null,[w]),D=b?p?"错误":"已写入":"写入中",H=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:b?p?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:h,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:xr(l)}),e.jsx(Cn,{label:`${f} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),S&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[S.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",S.added]}),S.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",S.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:h,flexShrink:0},children:[e.jsx(nn,{isDone:b,isError:p,color:h}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:D})]})]});return e.jsxs($n,{statusColor:h,isDone:b,expanded:n,onToggle:()=>s(!n),header:H,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:l}),w&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(V=>e.jsx("button",{onClick:()=>a(V),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:o===V?"var(--accent-dim)":"transparent",color:o===V?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:V==="content"?"文件内容":"变更行"},V))}),o==="diff"&&w?e.jsx(js,{diff:w}):e.jsx(ws,{content:u}),p&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function $o({toolCall:t}){const[r,n]=c.useState(!1),s=t.arguments.file_path??"",o=t.arguments.startLine,a=t.arguments.endLine,l=t.arguments.offset,u=t.arguments.limit,f=t.result??"",p=vs(f),b=t.isError,h=tn(t),w=h?b?"var(--danger)":"var(--success)":"var(--accent)",S=o!==void 0?`L${o}–${a??"?"}`:l!==void 0?`第${l}行起${u?` ×${u}`:""}`:null,D=h?b?"错误":"已读取":"读取中",H=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:h?b?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:w,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s,children:xr(s)}),S&&e.jsx(Cn,{label:S,color:"var(--accent)",bg:"var(--accent-dim)"}),h&&!b&&e.jsx(Cn,{label:`${p} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:w,flexShrink:0},children:[e.jsx(nn,{isDone:h,isError:b,color:w}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:D})]})]});return e.jsxs($n,{statusColor:w,isDone:h,expanded:r,onToggle:()=>n(!r),header:H,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s}),h&&!b?e.jsx(ws,{content:f}):h&&b&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:f})]})}function Uo({toolCall:t}){const[r,n]=c.useState(!1),s=t.arguments.file_path??"",o=t.arguments.old_string??"",a=t.arguments.new_string??"",l=t.isError,u=tn(t),f=u?l?"var(--danger)":"var(--success)":"var(--accent)",p=u?l?"错误":"已替换":"替换中",b=c.useMemo(()=>o&&a?ys(o,a):null,[o,a]),h=c.useMemo(()=>b?{added:b.filter(S=>S.type==="added").length,removed:b.filter(S=>S.type==="removed").length}:null,[b]),w=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:u?l?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:f,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s,children:xr(s)}),h&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[h.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",h.added]}),h.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",h.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:f,flexShrink:0},children:[e.jsx(nn,{isDone:u,isError:l,color:f}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:p})]})]});return e.jsxs($n,{statusColor:f,isDone:u,expanded:r,onToggle:()=>n(!r),header:w,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s}),b?e.jsx(js,{diff:b}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:o}),e.jsx("pre",{style:{fontSize:11,color:"var(--success)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(5,150,105,0.04)",border:"1px solid rgba(5,150,105,0.12)",borderLeft:"3px solid var(--success)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a})]}),l&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function en({label:t,content:r,error:n,maxPreviewLines:s=8,maxPreviewHeight:o=200,maxExpandedHeight:a=2e3}){const[l,u]=c.useState(!1),f=r.split(`
120
+ `),p=f.length>s,b=p&&!l?f.slice(0,s).join(`
121
+ `)+`
122
+ ...`:r;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:n?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:n?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:n?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:n?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:l?a:o,overflow:"auto",margin:0,lineHeight:1.6},children:b}),p&&e.jsx("button",{onClick:()=>u(!l),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:l?"收起":`展开全部 (${f.length} 行)`})]})}function Oo({arguments:t}){var n;const r=t.task??"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 0"},children:[e.jsxs("div",{style:{display:"flex",gap:8,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",flexWrap:"wrap"},children:[e.jsx(Cn,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(Cn,{label:`sid: ${(n=t.subSessionId)==null?void 0:n.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),r&&e.jsx(en,{label:"任务",content:r,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Ho({raw:t}){const[r,n]=c.useState(!1);let s;try{const f=JSON.parse(t);delete f.subAgentProgress,delete f.subAgentStatus,delete f.subAgentDetail,s=JSON.stringify(f,null,2)}catch{s=t}const o=8,a=s.split(`
123
+ `),l=a.length>o,u=l&&!r?a.slice(0,o).join(`
124
+ `)+`
125
+ ...`:s;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"参数"}),e.jsx("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",maxHeight:r?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:u}),l&&e.jsx("button",{onClick:()=>n(!r),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:r?"收起":`展开全部 (${a.length} 行)`})]})}function Vo({activity:t}){const r=new Map(t.messages.flatMap(n=>n.role==="tool"&&n.toolCallId?[[n.toolCallId,{content:n.content,isError:n.name==="error"}]]:[]));return e.jsxs("div",{className:"native-subagent-activity",children:[e.jsxs("div",{className:"native-subagent-activity__meta",children:[t.elapsedSeconds!==void 0&&e.jsxs("span",{children:[t.elapsedSeconds," 秒"]}),t.toolUses!==void 0&&e.jsxs("span",{children:[t.toolUses," 次工具调用"]}),t.lastToolName&&e.jsxs("span",{children:["正在使用 ",t.lastToolName]})]}),t.messages.map((n,s)=>{var o;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[n.role==="assistant"&&n.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:n.content}),n.role==="assistant"&&((o=n.toolCalls)==null?void 0:o.map(a=>{const l=r.get(a.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(mr,{toolCall:{...a,...l?{result:l.content,isError:l.isError}:{}}}),l&&e.jsx("pre",{className:`native-subagent-activity__tool-result${l.isError?" native-subagent-activity__tool-result--error":""}`,children:l.content})]},a.id)})),n.role==="tool"&&n.toolCallId&&!t.messages.some(a=>{var l;return(l=a.toolCalls)==null?void 0:l.some(u=>u.id===n.toolCallId)})&&e.jsx(en,{label:"工具结果",content:n.content,error:n.name==="error",maxPreviewHeight:180})]},`${n.role}-${s}`)}),t.summary&&e.jsx(en,{label:t.status==="failed"?"错误信息":"执行摘要",content:t.summary,error:t.status==="failed",maxPreviewHeight:180}),t.status==="running"&&t.messages.length===0&&!t.summary&&e.jsxs("div",{className:"native-subagent-activity__waiting",children:[e.jsx(nn,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function qo({toolCall:t,onSelectSession:r,nativeSubagent:n}){const s=xe(A=>A.runningSessionId),[o,a]=c.useState(()=>!!n),l=t.name==="dispatch_agent",u=t.name==="Agent"&&!!n,f=t.arguments.subAgentStatus,p=t.arguments.subAgentDetail,b=t.arguments.subAgentProgress,h=tn(t);c.useEffect(()=>{l&&!f&&b&&a(!0),u&&(n.messages.length>0||n.summary)&&a(!0)},[l,u,n,f,b]);const w=l?f==="failed":u?n.status==="failed":t.isError,S=l?!!f||h&&!s:u?n.status!=="running":h,D=S?w?"var(--danger)":"var(--success)":"var(--accent)",H=l?null:fr(t.name),V=w?"错误":H?"":u?n.status==="stopped"?"已停止":S?"已完成":"运行中":l?f==="failed"?"失败":S?"已完成":"运行中":S?"完成":"执行中",_=u?n.description:l?(()=>{const C=(t.arguments.task??"").split(`
126
+ `)[0];return C.length>80?C.slice(0,80)+"…":C})():_o(t.name,t.arguments),m=u?`@${n.agentName??"agent"}`:l?`@${t.arguments.agentName??"agent"}`:H?H.done:t.name,j=xs(t.name),R=l||u?e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:D,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}):e.jsx(bs,{family:j,color:D,size:11}),P=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:S?w?"rgba(220,38,38,0.1)":"rgba(5,150,105,0.1)":"var(--accent-dim)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:R}),e.jsx("span",{title:H?t.name:void 0,style:{fontFamily:H?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:m}),_&&e.jsx("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_}),!_&&e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:D,flexShrink:0},children:[e.jsx(nn,{isDone:S,isError:!!w,color:D}),V&&e.jsx("span",{style:{fontSize:10,fontWeight:500},children:V})]})]});return e.jsxs($n,{statusColor:D,isDone:S,expanded:o,onToggle:()=>a(!o),header:P,maxBodyHeight:800,children:[u?e.jsx(Vo,{activity:n}):l?e.jsx(Oo,{arguments:t.arguments}):j==="command"&&typeof t.arguments.command=="string"?e.jsxs(e.Fragment,{children:[typeof t.arguments.cwd=="string"&&t.arguments.cwd&&e.jsxs("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:["工作目录 ",t.arguments.cwd]}),e.jsx(en,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(Ho,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!l&&!u&&e.jsx(en,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),l&&f&&p&&e.jsx(en,{label:f==="failed"?"错误信息":"执行摘要",content:p,error:f==="failed",maxPreviewHeight:180}),l&&!f&&b&&(!!s||!h)&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"实时输出"}),e.jsxs("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderLeft:"3px solid var(--accent)",maxHeight:240,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:[b,e.jsx("span",{style:{display:"inline-block",width:"0.5em",height:"1em",background:"var(--accent)",verticalAlign:"text-bottom",animation:"blink 1s step-end infinite"},children:"​"})]})]}),l&&!f&&!b&&!!s&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 0",fontSize:11,color:"var(--text-muted)",fontStyle:"italic"},children:[[0,1,2].map(A=>e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--accent)",display:"inline-block",animation:"wave 1.1s ease-in-out infinite",animationDelay:`${A*.16}s`}},A)),"等待子 agent 响应..."]}),l&&t.arguments.subSessionId&&r&&e.jsxs("button",{onClick:()=>r(t.arguments.subSessionId),style:{alignSelf:"flex-start",padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--accent-dim)",color:"var(--accent)",fontSize:11,fontWeight:500,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s"},onMouseEnter:A=>{A.currentTarget.style.background="var(--accent)",A.currentTarget.style.color="white"},onMouseLeave:A=>{A.currentTarget.style.background="var(--accent-dim)",A.currentTarget.style.color="var(--accent)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}),"查看子会话"]})]})}function Ko({items:t,onSelectSession:r}){var h;const[n,s]=c.useState(!1),o=(h=t[0])==null?void 0:h.toolCall,a=o?fr(o.name):null;if(!o||!a||t.length<2)return null;const l=t.every(({toolCall:w})=>tn(w)),u=t.filter(({toolCall:w})=>w.isError).length,f=u>0?"var(--danger)":l?"var(--text-muted)":"var(--accent)",p=a.done,b=`${p},${t.length} 项,${n?"收起":"展开"}`;return e.jsxs("div",{className:"tool-call-group",children:[e.jsxs("button",{type:"button",className:"tool-call-group__summary","aria-expanded":n,"aria-label":b,onClick:()=>s(w=>!w),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(bs,{family:xs(o.name),color:f,size:13})}),e.jsx("span",{className:"tool-call-group__label",children:p}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),u>0&&e.jsxs("span",{className:"tool-call-group__error",children:[u," 项失败"]}),!l&&e.jsx(nn,{isDone:!1,color:f,size:11}),e.jsx("svg",{className:"tool-call-group__chevron",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]}),n&&e.jsx("div",{className:"tool-call-group__items",children:t.map(({toolCall:w,beforeContent:S,progress:D,nativeSubagent:H})=>e.jsx(mr,{toolCall:w,beforeContent:S,progress:D,nativeSubagent:H,onSelectSession:r},w.id))})]})}function mr({toolCall:t,onSelectSession:r,beforeContent:n,progress:s,nativeSubagent:o}){const a=t.name==="write_file"?e.jsx(Fo,{toolCall:t,beforeContent:n}):t.name==="read_file"?e.jsx($o,{toolCall:t}):t.name==="str_replace"?e.jsx(Uo,{toolCall:t}):e.jsx(qo,{toolCall:t,onSelectSession:r,nativeSubagent:o});return e.jsxs("div",{className:"tool-call-with-progress",children:[a,s&&e.jsx(ms,{progress:s,compact:!0})]})}function Go({question:t,options:r,fields:n,multiSelect:s,answered:o,answer:a,onAnswer:l}){const[u,f]=c.useState(new Set),[p,b]=c.useState(""),[h,w]=c.useState({}),S=!!(r!=null&&r.length),D=!!(n!=null&&n.length),H=j=>{o||f(R=>{const P=new Set(R);return s?P.has(j)?P.delete(j):P.add(j):(P.clear(),P.add(j)),P})},V=()=>{if(u.size===0)return;const j=Array.from(u).map(R=>r[R].label);l(j.join(", "),Array.from(u))},_=()=>{const j=Array.from(u).map(P=>r[P].label),R=Object.fromEntries((n??[]).map(P=>{var A;return[P.name,((A=h[P.name])==null?void 0:A.trim())??""]}));!R.model&&j.length>0&&(R.model=j[0]),!(!Object.values(R).some(Boolean)&&j.length===0)&&l(JSON.stringify({fields:R,selectedOptions:j}),Array.from(u))},m=()=>{p.trim()&&l(p.trim())};return e.jsx("div",{style:{marginBottom:12},children:e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:o?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:o?"var(--bg-deep)":"linear-gradient(135deg, rgba(79,110,247,0.04) 0%, var(--bg-deep) 100%)",overflow:"hidden",transition:"border-color 0.2s ease"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",borderBottom:o?"1px solid var(--border-subtle)":"1px solid rgba(79,110,247,0.15)"},children:[e.jsx("div",{style:{width:24,height:24,borderRadius:6,background:o?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:o?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),e.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:o?"var(--text-muted)":"var(--accent)",flex:1},children:o?"已回答":"向你提问"}),s&&!o&&e.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:10,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:500},children:"可多选"})]}),e.jsx("div",{style:{padding:"12px 14px 8px",fontSize:13,color:"var(--text-primary)",lineHeight:1.6,fontWeight:500,whiteSpace:"pre-wrap"},children:t}),o&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),D?"配置已提交(敏感字段已隐藏)":a]}),S&&!o&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[r.map((j,R)=>{const P=u.has(R);return e.jsxs("button",{onClick:()=>H(R),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:P?"var(--accent)":"var(--border-subtle)",background:P?"rgba(79,110,247,0.06)":"var(--bg-surface)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-body)",transition:"all 0.15s ease",width:"100%"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:s?4:8,border:`2px solid ${P?"var(--accent)":"var(--border-subtle)"}`,background:P?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:P&&e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:P?600:500,color:P?"var(--text-primary)":"var(--text-secondary)"},children:j.label}),j.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:j.description})]})]},R)}),!D&&e.jsx("button",{onClick:V,disabled:u.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:u.size>0?"var(--accent)":"var(--bg-surface)",color:u.size>0?"white":"var(--text-muted)",cursor:u.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),D&&!o&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[n.map(j=>e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:"var(--text-secondary)"},children:j.label}),e.jsx("input",{type:j.type==="secret"?"password":"text",value:h[j.name]??"",onChange:R=>w(P=>({...P,[j.name]:R.target.value})),placeholder:j.description,autoComplete:j.type==="secret"?"off":void 0,style:{padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none"}}),j.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:j.description})]},j.name)),e.jsx("button",{onClick:_,style:{padding:"8px 16px",borderRadius:8,border:"none",background:"var(--accent)",color:"white",cursor:"pointer",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end"},children:"确认配置"})]}),!o&&!D&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:S?"1px solid var(--border-subtle)":"none",marginTop:S?2:0},children:[e.jsx("input",{type:"text",value:p,onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),m())},placeholder:S?"或输入自定义回答…":"输入你的回答…",style:{flex:1,padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",transition:"border-color 0.15s ease"},onFocus:j=>{j.currentTarget.style.borderColor="var(--accent)"},onBlur:j=>{j.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:m,disabled:!p.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:p.trim()?"var(--accent)":"var(--bg-surface)",color:p.trim()?"white":"var(--text-muted)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})})}const er={systemBase:{label:"系统基础提示",group:"system"},environment:{label:"运行环境",group:"system"},projectContext:{label:"项目上下文",group:"system"},skills:{label:"技能指令",group:"system"},memory:{label:"Memory",group:"system"},embeddedTools:{label:"系统内嵌工具定义",group:"system"},conversationHistory:{label:"历史用户消息",group:"messages"},currentUserMessage:{label:"当前用户消息",group:"messages"},assistantMessages:{label:"AI 历史回复",group:"messages"},compactionSummary:{label:"上下文压缩摘要",group:"messages"},toolCalls:{label:"工具调用",group:"tools"},toolResults:{label:"工具结果",group:"tools"},nativeToolDefinitions:{label:"原生工具定义",group:"tools"},images:{label:"图片",group:"images"},messageOverhead:{label:"协议与消息开销",group:"overhead"}},tr={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},Vr=["system","messages","tools","images","overhead"];function Qo(t,r){const n=(t==null?void 0:t.maxTokens)??Math.max(1,r*1e3),s=(t==null?void 0:t.totalTokens)??0,o=Object.fromEntries(Vr.map(l=>[l,0]));for(const l of(t==null?void 0:t.segments)??[]){const u=er[l.category];u&&(o[u.group]+=l.tokens)}const a=Math.min(s/n,1);return{hasUsage:!!t,totalTokens:s,maxTokens:n,ratio:a,percent:Math.round(a*100),groups:Vr.map(l=>({key:l,label:tr[l].label,color:tr[l].color,tokens:o[l]})),details:((t==null?void 0:t.segments)??[]).filter(l=>l.tokens>0).map(l=>{var u,f;return{category:l.category,label:((u=er[l.category])==null?void 0:u.label)??l.category,color:tr[((f=er[l.category])==null?void 0:f.group)??"overhead"].color,tokens:l.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function ur(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function qr(t,r){return r?`${t.percent}%`:t.hasUsage?`${ur(t.totalTokens)} / ${ur(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Jo({usage:t,contextWindowK:r,compact:n=!1}){const[s,o]=c.useState(!1),[a,l]=c.useState(null),u=c.useRef(null),f=c.useMemo(()=>Qo(t,r),[t,r]),p=f.ratio>=.85?"var(--danger)":f.ratio>=.6?"#f59e0b":"var(--accent)",b=typeof window>"u"?1024:window.innerWidth;return e.jsxs("div",{className:"context-usage-ribbon",style:{position:"relative",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("button",{className:"context-usage-ribbon__button",ref:u,type:"button",onClick:()=>{var w;const h=((w=u.current)==null?void 0:w.getBoundingClientRect())??null;l(h),o(S=>!S)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:n?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"context-usage-ribbon__ring",width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:"currentColor",strokeWidth:"4",opacity:"0.14"}),e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:f.hasUsage?p:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${f.ratio*62.832} 62.832`,transform:"rotate(-90 14 14)"})]}),e.jsx("span",{className:"context-usage-ribbon__summary context-usage-ribbon__summary--compact",children:qr(f,!0)})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"context-usage-ribbon__label",style:{fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap"},children:"上下文"}),e.jsx("div",{className:"context-usage-ribbon__meter",style:{flex:1,height:6,borderRadius:999,overflow:"hidden",background:"rgba(0,0,0,0.06)",display:"flex"},children:f.groups.map(h=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(h.tokens/f.maxTokens*100,100))}%`,background:h.color,opacity:h.key==="overhead"?.65:1,minWidth:h.tokens>0?1:0}},h.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:f.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:qr(f,!1)})]})}),s&&a&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>o(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:n?Math.min(Math.max(8,a.left),Math.max(8,b-Math.min(340,b-16)-8)):Math.max(8,a.left),top:a.top-8,transform:"translateY(-100%)",width:Math.min(n?340:a.width,b-16),maxHeight:"min(520px, calc(100vh - 32px))",overflowY:"auto",zIndex:9999,padding:12,borderRadius:12,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-lg)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)"},children:"完整请求上下文估算"}),e.jsx("div",{style:{fontSize:11,color:f.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:f.hasUsage?`${f.percent}%`:"暂无"})]}),f.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:f.requestLabel}),f.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:f.details.map(h=>{const w=f.totalTokens>0?Math.round(h.tokens/f.totalTokens*100):0;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:h.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:h.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[ur(h.tokens)," · ",w,"%"]})]},h.category)})}):e.jsx("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:"发送第一条消息后,将显示最新一次模型请求的完整上下文组成。"}),e.jsx("div",{style:{marginTop:10,fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:"基于最新一次实际发送前请求的完整组成估算,包含系统提示、环境、项目上下文、技能、memory、历史消息、工具定义/调用/结果、图片和压缩摘要。不同模型的 tokenizer 与协议存在差异,因此不是账单精确值。"})]})]})]})}function Kr(){return e.jsxs("div",{className:"agent-activity-indicator",role:"status","aria-live":"polite",children:[e.jsx("span",{children:"思考中"}),e.jsx("span",{className:"agent-activity-dots","aria-hidden":"true",children:[0,1,2].map(t=>e.jsx("span",{style:{animationDelay:`${t*.16}s`}},t))})]})}function Xo({sections:t,streaming:r=!1,renderContent:n}){const s=c.useMemo(()=>[...t].sort((l,u)=>l.sectionIndex-u.sectionIndex).map(l=>l.text.trim()).filter(Boolean).join(`
127
+
128
+ `),[t]),[o,a]=c.useState(r);return c.useEffect(()=>{a(r)},[r]),s?e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":o,onClick:()=>a(l=>!l),children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{children:"思考摘要"}),r&&e.jsx("span",{className:"reasoning-summary__live",children:"生成中"})]}),o&&e.jsx("div",{className:"reasoning-summary__content",children:n(s)})]}):null}function Yo({appearanceOpen:t,settingsOpen:r,hideToBackgroundTitle:n="隐藏到后台",onHideToBackground:s,onToggleAppearance:o,onOpenSettings:a}){return e.jsxs("div",{className:"chat-header-actions",children:[e.jsx("button",{type:"button",onClick:s,title:n,"aria-label":"隐藏后台",className:"ui-icon-button chat-header-action chat-header-action--background",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"m9 11 3 3 3-3M12 7v7M8 21h8"})]})}),e.jsx("button",{type:"button",onClick:l=>o(l.currentTarget.getBoundingClientRect()),title:"皮肤与布局","aria-label":"皮肤与布局","aria-expanded":t,className:`ui-icon-button chat-header-action chat-header-action--appearance ${t?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]})}),e.jsx("button",{type:"button",onClick:a,title:"设置","aria-label":"设置","aria-expanded":r,className:`ui-icon-button chat-header-action chat-header-action--settings ${r?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]})}const Zo={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function ei(t){const{title:r="视频工作台",shots:n=[],status:s="generating",composedVideoUrl:o}=t,[a,l]=c.useState(!1),[u,f]=c.useState(null);return e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-surface)",overflow:"hidden",maxWidth:600},children:[e.jsxs("div",{onClick:()=>l(!a),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:a?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",r]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[n.filter(p=>p.status==="done").length,"/",n.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:a?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!a&&e.jsxs("div",{style:{padding:"12px 16px"},children:[e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13,marginBottom:12},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"var(--bg-deep)"},children:[e.jsx("th",{style:jn,children:"#"}),e.jsx("th",{style:{...jn,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:jn,children:"时长"}),e.jsx("th",{style:jn,children:"状态"}),e.jsx("th",{style:jn,children:"预览"})]})}),e.jsx("tbody",{children:n.map(p=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:kn,children:p.index}),e.jsx("td",{style:{...kn,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.description,children:p.description}),e.jsxs("td",{style:kn,children:[p.duration,"s"]}),e.jsxs("td",{style:kn,children:[Zo[p.status]??"⏳",p.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:p.error,children:"!"})]}),e.jsx("td",{style:kn,children:p.videoUrl?e.jsx("button",{onClick:()=>f(p.videoUrl),style:{background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:6,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"▶ 播放"}):p.previewImageUrl?e.jsx("img",{src:p.previewImageUrl,alt:`shot-${p.index}`,style:{width:48,height:32,objectFit:"cover",borderRadius:4,border:"1px solid var(--border-subtle)"}}):e.jsx("span",{style:{color:"var(--text-muted)",fontSize:11},children:"—"})})]},p.index))})]}),u&&e.jsx("video",{src:u,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),o&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"完整视频"}),e.jsx("video",{src:o,controls:!0,style:{width:"100%",borderRadius:8,border:"1px solid var(--border-subtle)"}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[s==="generating"&&e.jsx("span",{children:"🔄 生成中..."}),s==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),s==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),s==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const jn={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},kn={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},ti={storyboard_workbench:ei};function ni(t,r,n){return!t||r!==t?!1:n===null||n===t}function ri(t,r,n=Date.now()){return!t||t.sessionId!==r?t:{...t,until:n+9e4}}async function si(t){const{text:r,projectId:n,createSession:s,activateSession:o,showUserMessage:a,onSessionCreated:l,isCancelled:u}=t,f=!t.sessionId;let p=t.sessionId??null;if(!p){const b=await s(r.slice(0,60)||"语音任务",n||void 0);if(u!=null&&u())return null;p=b.id}return o(p),a(r,p),f&&l&&await l(p),p}async function oi(t){var o,a;const r=((o=t.sessionId)==null?void 0:o.trim())||null,n=!r,s=r??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!s)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(s),t.showUserMessage(t.text,s),n&&await((a=t.onSessionCreated)==null?void 0:a.call(t,s)),s}const ii=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|\/[^)\n]+)\)/gi;function ai(t){if(!t.startsWith("/")||t.includes("?")||t.includes("#")||t.includes("\0"))return null;const r=t.match(/^(\/.*):([1-9]\d*)$/);return r?{path:r[1],line:Number(r[2])}:{path:t}}function li(t){const r=[];let n=0;for(const s of t.matchAll(ii)){const o=s.index??0;o>n&&r.push({type:"text",value:t.slice(n,o)});const a=s[2];if(/^https?:\/\//i.test(a))r.push({type:"link",label:s[1],href:a});else{const l=ai(a);l?r.push({type:"artifact",label:s[1],path:l.path,...l.line?{line:l.line}:{},raw:s[0]}):r.push({type:"text",value:s[0]})}n=o+s[0].length}return n<t.length&&r.push({type:"text",value:t.slice(n)}),r.length>0?r:[{type:"text",value:t}]}function ks(t){var r,n;return t.role==="assistant"&&!!((r=t.toolCalls)!=null&&r.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((n=t.images)!=null&&n.length)&&!t.presentation}function di(t){return ks(t)&&t.content.trim().length===0}function ci(t){const r=[];for(const n of t){const s=r[r.length-1];if(s&&ks(s)&&di(n)){r[r.length-1]={...s,toolCalls:[...s.toolCalls,...n.toolCalls],timestamp:n.timestamp};continue}r.push(n)}return r}function ui(t){const r=[];for(const n of t){const s=Do(n.toolCall.name),o=r[r.length-1];s&&(o==null?void 0:o.action)===s?o.items.push(n):r.push({action:s,items:[n]})}return r}function pi(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function gi(t){var r,n,s;return t.role==="assistant"&&!!(t.content.trim()||(r=t.toolCalls)!=null&&r.length||(s=(n=t.presentation)==null?void 0:n.reasoning)!=null&&s.length||t.askUser||t.widget)}function hi(t,r,n){var a;const s=t[r];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(a=s.toolCalls)!=null&&a.length||s.isCompactionSummary)return!1;let o=!n;for(let l=r+1;l<t.length;l++){const u=t[l];if(!u.isCompactionSummary){if(pi(u)){o=!0;break}if(gi(u))return!1}}return o}function fi(t,r,n){const s=t[r];if(!s)return{showCopy:!1,showSpeak:!1,compact:!1};if(s.role==="user")return{showCopy:!!s.content,showSpeak:!1,compact:!1};const o=hi(t,r,n);return{showCopy:o,showSpeak:o,compact:s.role==="assistant"&&!o&&!s.isCompactionSummary}}function Gr(t,r){return(t==null?void 0:t.agentType)==="codex"&&(t.occupancy==="owned-externally"||r==="SESSION_OCCUPIED")}async function xi(t){const r=await t.forkSession(t.sourceSessionId);return t.activateSession(r.id),await t.refreshAndSelect(r.id),r}const nr=50;function rr(t){const n=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(n){const a=parseFloat(n[1]),l=n[2].toLowerCase(),u=l==="s"||l==="sec"||l==="秒"?a*1e3:l==="m"||l==="min"||l==="分"||l==="分钟"?a*6e4:a*36e5;return u>=36e5&&u%36e5===0?`每 ${u/36e5} 小时`:u>=6e4&&u%6e4===0?`每 ${u/6e4} 分钟`:`每 ${u/1e3} 秒`}const[s,o]=t.trim().split(/\s+/);return s==="0"&&o&&o!=="*"&&!o.includes("/")&&!o.includes(",")?`每天 ${o.padStart(2,"0")}:00`:`cron: ${t}`}function mi(t){const r=t.split(/(`[^`\n]+`)/g);return r.length<=1?t:e.jsx(e.Fragment,{children:r.map((n,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.slice(1,-1)},s):e.jsx("span",{children:n},s))})}function bi(t,r){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,o)=>{const a=`${r}-${o}`;return s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:s.slice(2,-2)},a):s.startsWith("*")&&s.endsWith("*")&&s.length>2?e.jsx("em",{children:s.slice(1,-1)},a):e.jsx("span",{children:s},a)})}function pr(t){return t.split(/(`[^`\n]+`)/g).map((n,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.slice(1,-1)},s):li(n).map((o,a)=>{if(o.type==="link")return e.jsx("a",{className:"chat-message-link",href:o.href,target:"_blank",rel:"noopener noreferrer",children:o.label},`${s}-${a}`);if(o.type==="artifact"){if(!ds())return e.jsx("span",{children:o.raw},`${s}-${a}`);const l=o.line?`${o.path}:${o.line}`:o.path;return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:l,"aria-label":`打开交付物 ${o.label}`,onClick:()=>No(o.path),children:[e.jsx(us,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:o.label})]},`${s}-${a}`)}return bi(o.value,`${s}-${a}`)}))}function vi(t){if(t.length<2)return null;const r=a=>a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim()),n=r(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const o=t.slice(2).map(r);return{headers:n,rows:o}}function yi(t,r){const n=s=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:s?600:400,color:s?"var(--text-primary)":"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"pre-wrap",wordBreak:"break-word"});return e.jsx("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"auto",background:"var(--bg-surface)"},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"var(--bg-deep)"},children:t.map((s,o)=>e.jsx("th",{style:n(!0),children:pr(s)},o))})}),e.jsx("tbody",{children:r.map((s,o)=>e.jsx("tr",{style:{background:o%2===0?"transparent":"rgba(0,0,0,0.015)"},children:s.map((a,l)=>e.jsx("td",{style:n(!1),children:pr(a)},l))},o))})]})})}function wi(t,r){return e.jsxs("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"4px 10px",background:"var(--bg-deep)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em"},children:t||"code"}),e.jsx("pre",{style:{margin:0,padding:"10px 12px",fontSize:12,lineHeight:1.6,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto",maxHeight:420},children:r})]})}function sr(t){const r=t.split(`
129
+ `),n=[];let s=0,o=0;const a=u=>u.trimStart().startsWith("```"),l=u=>r[u].trimStart().startsWith("|")&&u+1<r.length&&/^\|[\s\-:|]+\|$/.test(r[u+1].trim());for(;s<r.length;){if(a(r[s])){const u=r[s].trim().slice(3).trim();s++;const f=[];for(;s<r.length&&!a(r[s]);)f.push(r[s]),s++;s++,n.push(e.jsx("div",{children:wi(u,f.join(`
130
+ `))},`code-${o++}`));continue}if(l(s)){const u=[];for(;s<r.length&&r[s].trimStart().startsWith("|");)u.push(r[s].trim()),s++;const f=vi(u);f?n.push(e.jsx("div",{children:yi(f.headers,f.rows)},`tbl-${o++}`)):n.push(e.jsx("span",{children:u.map((p,b)=>e.jsxs("span",{children:[mi(p),b<u.length-1?`
131
+ `:null]},b))},`tbl-fb-${o++}`))}else{const u=[];for(;s<r.length&&!l(s)&&!a(r[s]);)u.push(r[s]),s++;u.length>0&&n.push(e.jsx("span",{children:u.map((f,p)=>e.jsxs("span",{children:[pr(f),p<u.length-1?`
132
+ `:null]},p))},`txt-${o++}`))}}return e.jsx(e.Fragment,{children:n})}const Ss=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Qr=Object.fromEntries(Ss.map(t=>[t.value,t.label])),Dn=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function Jr(t){return Dn.some(r=>r.value===t)?t:"full-access"}function ji({selectedProjectId:t=null,selectedSessionId:r=null,onSessionCreated:n,onMessageSent:s,onSubSessionCreated:o,onSelectSession:a,onSubAgentEvent:l,onRunComplete:u,sessionTitle:f,sessionSummary:p,onOpenSettings:b,settingsOpen:h=!1,onHideToBackground:w,onToggleAppearance:S,appearanceOpen:D=!1,hideToBackgroundTitle:H,voiceCommand:V=null}){var Ar,Rr,Tr;const{messages:_,runningSessionId:m,appendText:j,addMessage:R,setRunningSession:P,setSessionId:A,updateToolResult:C,updateSubAgentStatus:L,updateSubAgentProgress:I,updateMessage:T,setMessages:Q,getMessagesForSession:Z,contextUsageBySession:pe,runtimeProgressBySession:Y,nativeSubagentsBySession:Se,setContextUsage:we,applyRuntimeProgress:nt,setRuntimeProgress:Ut,clearRuntimeProgress:rt,applyNativeSubagentActivity:Xe,setNativeSubagentActivities:Ot,applyReasoningSummary:Ht,clearMessages:st,sessionId:y,todos:$,setTodos:le,cronTasks:ee,setCronTasks:X}=xe(),te=c.useMemo(()=>ci(_),[_]),{isConfigured:Ce,profiles:ge,activeProfileId:ot,switchActiveProfile:In,loadFromSystem:Vt,contextWindow:pt,reasoningEffort:Ye,setField:gt,saveToSystem:Un}=Fn(),[Pe,rn]=c.useState(),[sn,on]=c.useState(),[ht,an]=c.useState(!1),ze=!!(p&&p.agentType!=="customer-agent"),An=To(p==null?void 0:p.agentType),ft=(p==null?void 0:p.occupancy)==="owned-externally",Rn=Pe==="SESSION_OCCUPIED",De=Ce||ze,Mt=De&&!ft&&!Rn,Ve=c.useRef(new Set),re=r||y,be=!!(re&&(m===re||Ve.current.has(re))),Lt=re?Y[re]??[]:[],Tn=re?Se[re]??{}:{},qt=vo(Lt);c.useEffect(()=>{Vt()},[]),c.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(i=>X(i))},[]);const[Ie,Ae]=c.useState(""),[ln,_e]=c.useState(!1),[Fe,dn]=c.useState(!1),[Wt,qe]=c.useState(!1),[Ke,xt]=c.useState("full-access"),[cn,it]=c.useState(!1),Ge=c.useRef(null),mt=c.useRef(null);c.useEffect(()=>{if(!Fe)return;const i=g=>{Ge.current&&!Ge.current.contains(g.target)&&dn(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Fe]),c.useEffect(()=>{if(!Wt)return;const i=g=>{mt.current&&!mt.current.contains(g.target)&&qe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Wt]),c.useEffect(()=>{qe(!1),xt(Jr(p==null?void 0:p.permissionMode))},[ze,r,p==null?void 0:p.permissionMode]);const[un,de]=c.useState(null),[zn,at]=c.useState([]),[Kt,Qe]=c.useState([]),$e=c.useRef(null),Me=c.useRef(null),bt=c.useRef(null),Gt=c.useRef(()=>{}),Ue=c.useRef(null),Ze=c.useRef(null),et=c.useRef(null),Et=c.useRef(null),Bt=c.useRef(!1),lt=c.useRef(!1),vt=c.useRef(new Set),Qt=c.useRef(null),yt=c.useRef(!1),wt=c.useRef(!1),pn=c.useRef(null),jt=c.useRef(null),[he,Jt]=c.useState(!1),[Re,Nt]=c.useState(null),[gn,kt]=c.useState(!1),[hn,St]=c.useState(!1),Le=c.useRef(null),Xt=c.useRef(null),fn=c.useRef(null),[tt,xn]=c.useState(null),[On,Mn]=c.useState([]),[mn,Ln]=c.useState([]),[d,k]=c.useState([]),[z,U]=c.useState(null),[M,q]=c.useState(null),[se,Te]=c.useState(new Set),[Oe,K]=c.useState("idle");c.useEffect(()=>{if(!ze||!re){Qt.current=null;return}if(Qt.current!==re){Qt.current=re,Ae(Wo(re));return}if(yt.current&&Ie===""){yt.current=!1;return}Yn(re,Ie)},[Ie,ze,re]);const ue=()=>{const i=$e.current;i&&(i.scrollTop<=240&&Gt.current(),i.classList.add("is-scrolling"),bt.current!==null&&window.clearTimeout(bt.current),bt.current=window.setTimeout(()=>{i.classList.remove("is-scrolling"),bt.current=null},700))};c.useEffect(()=>()=>{bt.current!==null&&window.clearTimeout(bt.current)},[]),c.useLayoutEffect(()=>{const i=pn.current,g=$e.current;!i||!g||(g.scrollTop=i.scrollTop+(g.scrollHeight-i.scrollHeight),pn.current=null)},[_]);const[J,ve]=c.useState(!1),[We,Ee]=c.useState(null),Be=c.useRef(null);c.useEffect(()=>{const i=window.agentApi;if(!(i!=null&&i.onTtsStart)||!i.onTtsPcm||!i.onTtsStreamEnd||!i.onTtsFlush)return;const g=new Co(i),x=[i.onTtsStart(v=>g.start(v)),i.onTtsPcm(({generation:v,pcm:B})=>g.enqueue(v,B)),i.onTtsStreamEnd(({generation:v})=>g.finish(v)),i.onTtsFlush(({generation:v})=>g.flush(v)),i.onTtsEnd(()=>Ee(null))];return()=>{for(const v of x)v();g.dispose()}},[]);const je=()=>{var x;if(J){(x=Be.current)==null||x.stop(),Be.current=null,ve(!1);return}En(window.agentApi,wn);const i=Ie?`${Ie.trimEnd()} `:"",g=wo({onInterim:v=>Ae(i+v),onFinal:v=>{var B;Ae(i+v),(B=Xt.current)==null||B.focus()},onError:v=>de(v),onEnd:()=>{ve(!1),Be.current=null}});g&&(Be.current=g,ve(!0))},dt=async(i,g)=>{var x;if(We===i){await En(window.agentApi,wn),Ee(null);return}if(await En(window.agentApi,wn),!((x=window.agentApi)!=null&&x.ttsSpeak)){de("TTS 模型服务不可用");return}Ee(i);try{(await window.agentApi.ttsSpeak(g)).ok||(Ee(null),de("TTS 模型播报失败"))}catch(v){Ee(null),de(v instanceof Error?v.message:"TTS 模型播报失败")}},He=c.useRef(null),Hn=c.useRef(!1),wr=c.useRef(new Set),bn=c.useRef(r??null),Ct=c.useRef(null),Wn=c.useRef(0);c.useEffect(()=>{bn.current=r??null},[r]),c.useEffect(()=>{Ct.current=y},[y]),c.useEffect(()=>{rn(void 0),on(void 0),an(!1)},[r]),c.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(i=>Mn(i)),window.agentApi.listSkills().then(i=>Ln(i.filter(g=>g.name))).catch(i=>console.error("[listSkills] mount error:",i)))},[]);const jr=z===null?[]:On.filter(i=>z===""||i.name.toLowerCase().includes(z.toLowerCase())),Vn=M===null?[]:[...[{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(i=>M===""||i.name.toLowerCase().includes(M.toLowerCase())),...mn.filter(i=>M===""||i.name.toLowerCase().includes(M.toLowerCase()))],Rs=i=>{k(g=>g.find(x=>x.id===i.id)?g:[...g,i]),Ae(g=>g.replace(/@[\w\u4e00-\u9fff]*$/,"")),U(null),setTimeout(()=>{var g;return(g=Xt.current)==null?void 0:g.focus()},0)},Ts=i=>{k(g=>g.filter(x=>x.id!==i))},zs=i=>{Ae(g=>g.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${i.name} `)),q(null),setTimeout(()=>{var g;return(g=Xt.current)==null?void 0:g.focus()},0)},Ms=i=>{var v,B;Ae(i);const g=i.match(/@([\w\u4e00-\u9fff]*)$/);if(g){window.agentApi&&window.agentApi.listAgentDefs().then(G=>Mn(G)),xn(((v=fn.current)==null?void 0:v.getBoundingClientRect())??null),U(g[1]),q(null);return}const x=i.match(/\/([-\w\u4e00-\u9fff]*)$/);if(x){window.agentApi&&window.agentApi.listSkills().then(G=>Ln(G.filter(W=>W.name))).catch(G=>console.error("[listSkills] slash error:",G)),xn(((B=fn.current)==null?void 0:B.getBoundingClientRect())??null),q(x[1]),U(null);return}U(null),q(null)},Ls=i=>{i.key==="Escape"&&(z!==null||M!==null)?(i.preventDefault(),U(null),q(null)):i.key==="Escape"&&be?(i.preventDefault(),Sr()):i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),Ir())},Ws=i=>{const g=Array.from(i.target.files??[]);g.length>0&&at(x=>[...x,...g]),i.target.value=""},Es=i=>{at(g=>g.filter((x,v)=>v!==i))},Bs=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Ns=i=>Bs.test(i),Ps=i=>{Qe(g=>[...g,i])},Ds=i=>{Qe(g=>g.filter((x,v)=>v!==i))},_s=i=>new Promise((g,x)=>{const v=new FileReader;v.onload=()=>g(v.result),v.onerror=x,v.readAsDataURL(i)});c.useEffect(()=>{const i=async g=>{if(!g.clipboardData)return;const x=Array.from(g.clipboardData.items).find(B=>B.type.startsWith("image/"));if(!x)return;g.preventDefault();const v=x.getAsFile();v&&Ps(await _s(v))};return window.addEventListener("paste",i),()=>window.removeEventListener("paste",i)},[ge,ot]),c.useEffect(()=>{var g;const i=jt.current;jt.current=null,i!=="skip"&&((g=Me.current)==null||g.scrollIntoView({behavior:i==="instant"?"auto":"smooth"}))},[_]),c.useEffect(()=>window.agentApi?window.agentApi.onEvent(g=>Fs(g)):void 0,[y]),c.useEffect(()=>{const i=++Wn.current,g=r;let x=null;const v=()=>Wn.current===i&&bn.current===g;return(async()=>{var W,E,F;if(!window.agentApi||ni(He.current,Ct.current,g))return;if(!g){if(!v())return;st(),de(null),Ue.current=null,Ze.current=null,Nt(null),kt(!1),St(!1),et.current=null,Ct.current=null,A(""),xt("full-access");return}de(null),Nt(null),Ue.current=null,Ze.current=null,kt(!0),St(!1),et.current=g,Ct.current=g,A(g);const G=Z(g);Q(G,g),x=window.setTimeout(()=>{v()&&St(!0)},500);try{const N=await window.agentApi.getSession(g,{limit:nr}),oe=N,ne=Wr((N==null?void 0:N.events)??[]),ce=Lr((N==null?void 0:N.events)??[]),ie=Er((N==null?void 0:N.events)??[]),ye=Jn(N);if(!v())return;xt(Jr((oe==null?void 0:oe.permissionMode)??((W=oe==null?void 0:oe.metadata)==null?void 0:W.permissionMode)));const Pt=((E=N==null?void 0:N.history)==null?void 0:E.nextCursor)??null;Ue.current=Pt,Ze.current=Pt;const vn=Z(g),Yt=vn.length>0&&xe.getState().runningSessionId===g?vn:ye;jt.current="instant",Q(Yt,g),Ut(ce,g),Ot(ie,g),(N==null?void 0:N.agentType)!=="customer-agent"&&(N==null?void 0:N.status)==="running"?(He.current=g,P(g)):He.current===g&&(He.current=null,P(null)),ne&&we(ne,g);const O=Yt[Yt.length-1];if((O==null?void 0:O.role)==="assistant"&&((F=O.toolCalls)!=null&&F.length)){const fe=Or(O.toolCalls);K(fe?"thinking":"tools")}else K((N==null?void 0:N.agentType)!=="customer-agent"&&(N==null?void 0:N.status)==="running"?"thinking":"idle")}catch(N){if(!v())return;console.error("[chat] failed to restore session",{sessionId:g,error:N}),de(N instanceof Error?N.message:"会话加载失败")}finally{x!==null&&window.clearTimeout(x),v()&&(kt(!1),St(!1))}})(),()=>{x!==null&&window.clearTimeout(x),Wn.current===i&&(Wn.current+=1)}},[st,Z,m,r,we,Q,A]);const kr=c.useCallback(async i=>{var g,x;if(!(!window.agentApi||document.visibilityState==="hidden")){if(Et.current!==i&&(Et.current=i,Bt.current=!1,lt.current=!1),Bt.current){lt.current=!0;return}Bt.current=!0;try{do{lt.current=!1;const v=await window.agentApi.getSession(i,{limit:nr});if(bn.current!==i||et.current!==i)return;const B=Jn(v),G=Z(i),W=Io(G,B),E=$e.current,F=!E||E.scrollHeight-E.scrollTop-E.clientHeight<80;jt.current=F?null:"skip",Q(W,i);const N=Ze.current,oe=((g=v==null?void 0:v.history)==null?void 0:g.nextCursor)??null;Ue.current===N&&(Ue.current=oe),Ze.current=oe;const ne=Wr((v==null?void 0:v.events)??[]);Ut(Lr((v==null?void 0:v.events)??[]),i),Ot(Er((v==null?void 0:v.events)??[]),i),ne&&we(ne,i);const ce=W[W.length-1];(ce==null?void 0:ce.role)==="assistant"&&((x=ce.toolCalls)!=null&&x.length)?K(Or(ce.toolCalls)?"thinking":"tools"):K("idle")}while(lt.current)}catch(v){console.error("[chat] failed to refresh native session history",{sessionId:i,error:v})}finally{Et.current===i&&(Bt.current=!1)}}},[Z,we,Q]);c.useEffect(()=>{const i=r,g=!!(i&&p&&(p==null?void 0:p.agentType)!=="customer-agent"&&m!==i),x=(p==null?void 0:p.occupancy)==="owned-externally"||(p==null?void 0:p.status)==="running";if(!i||!g||!window.agentApi)return;let v=null,B=null,G=!1;const W=()=>{!G&&document.visibilityState!=="hidden"&&kr(i)},E=()=>{v==null||v(),v=null,B!==null&&window.clearInterval(B),B=null},F=()=>{G||B!==null||document.visibilityState==="hidden"||(W(),B=window.setInterval(W,2e3))},N=()=>{if(!(G||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){x&&F();return}try{v=window.agentApi.observeSession(i,W,()=>{v=null,x&&F()})}catch{x&&F()}}},oe=()=>{E(),document.visibilityState!=="hidden"&&(W(),N())};return N(),document.addEventListener("visibilitychange",oe),()=>{G=!0,document.removeEventListener("visibilitychange",oe),E(),Et.current===i&&(Et.current=null,lt.current=!1)}},[kr,r,m,p==null?void 0:p.agentType,p==null?void 0:p.occupancy,p==null?void 0:p.status]);const qn=c.useCallback(async()=>{var v;const i=et.current,g=Ue.current;if(!window.agentApi||!i||!g||wt.current)return;wt.current=!0,Nt(null);const x=window.setTimeout(()=>{et.current===i&&wt.current&&Jt(!0)},500);try{const B=await window.agentApi.getSession(i,{before:g,limit:nr});if(et.current!==i||bn.current!==i)return;const G=Jn(B),W=Z(i),E=$e.current;E&&G.length>0&&(pn.current={scrollHeight:E.scrollHeight,scrollTop:E.scrollTop},jt.current="skip");const F=((v=B==null?void 0:B.history)==null?void 0:v.nextCursor)??null;Ue.current=F,G.length>0&&Q([...G,...W],i)}catch(B){if(et.current!==i)return;console.error("[chat] failed to load older history",{sessionId:i,error:B}),Nt(B instanceof Error?B.message:"历史消息加载失败")}finally{window.clearTimeout(x),wt.current=!1,et.current===i&&Jt(!1)}},[Z,Q]);c.useEffect(()=>{Gt.current=()=>{qn()}},[qn]);const Fs=i=>{var B,G;const g=bn.current||Ct.current,x=i._sid||g||void 0;if(i._nativeRunId&&Number.isSafeInteger(i._nativeSequence)){const W=`${i._nativeRunId}:${i._nativeSequence}`;if(vt.current.has(W))return;vt.current.add(W),vt.current.size>2e3&&(vt.current=new Set([...vt.current].slice(-1e3)))}const v=!x||x===g;switch(i.type){case"run_admitted":x&&x===g&&Eo(x);break;case"context_usage":i.usage&&we(i.usage,x);break;case"text_chunk":i.text&&(j(i.text,x),v&&K("thinking"));break;case"reasoning_summary_delta":typeof i.itemId=="string"&&Number.isSafeInteger(i.sectionIndex)&&typeof i.delta=="string"&&(Ht({type:"reasoning_summary_delta",itemId:i.itemId,sectionIndex:i.sectionIndex,delta:i.delta},x),v&&K("thinking"));break;case"runtime_progress":if(typeof i.progressId=="string"&&typeof i.label=="string"&&["thinking","tool","retry","status"].includes(i.phase??"")){const W={progressId:i.progressId,phase:i.phase,label:i.label,...i.detail===void 0?{}:{detail:i.detail},...i.toolCallId===void 0?{}:{toolCallId:i.toolCallId},...i.elapsedSeconds===void 0?{}:{elapsedSeconds:i.elapsedSeconds},...i.current===void 0?{}:{current:i.current},...i.total===void 0?{}:{total:i.total}};nt(W,x),v&&K(W.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(B=i.activity)!=null&&B.parentToolCallId&&(Xe(i.activity,x),v&&i.activity.status==="running"&&K("tools"));break;case"tool_call":v&&K("tools"),i.toolCall&&i.toolCall.name!=="dispatch_agent"&&i.toolCall.name!=="ask_user"&&i.toolCall.name!=="show_widget"&&R({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:i.toolCall.id,name:i.toolCall.name,arguments:i.toolCall.arguments}],timestamp:Date.now()},x);break;case"tool_result":i.result&&C(i.result.toolCallId,i.result.content,i.result.isError,x);break;case"todo_update":i.todos&&le(i.todos);break;case"cron_update":i.tasks&&X(i.tasks);break;case"agent_dispatch":if(R({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:i.agentName,task:i.task??"",subSessionId:i.subSessionId}}],timestamp:Date.now()},x),i.subSessionId){Ve.current.add(i.subSessionId);const W=He.current||y;W&&o&&o(W)}l==null||l({type:"started",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_done":i.subSessionId&&(Ve.current.delete(i.subSessionId),L(i.subSessionId,i.status??"completed",i.status==="failed"?i.error:i.summary,x)),l==null||l({type:i.status==="failed"?"failed":"completed",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_progress":i.subSessionId&&i.text&&I(i.subSessionId,i.text,x);break;case"compacted":R({id:crypto.randomUUID(),role:"assistant",content:i.summary??"",isCompactionSummary:!0,timestamp:Date.now()},x);break;case"show_widget":{const W=i.data??i.widgetData,E={widgetId:i.widgetId,widgetType:i.widgetType,data:W??{}},N=(x?xe.getState().getMessagesForSession(x):xe.getState().messages).find(oe=>{var ne;return((ne=oe.widget)==null?void 0:ne.widgetId)===E.widgetId});N?T(N.id,oe=>({...oe,widget:E}),x):R({id:crypto.randomUUID(),role:"assistant",content:"",widget:E,timestamp:Date.now()},x);break}case"ask_user":if(i.questionId&&(x?xe.getState().getMessagesForSession(x):xe.getState().messages).some(E=>{var F;return((F=E.askUser)==null?void 0:F.questionId)===i.questionId}))break;R({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:i.questionId??"",question:i.question??"",options:i.options,fields:i.fields,multiSelect:i.multiSelect},timestamp:Date.now()},x);break;case"approval_resolved":{if(!i.questionId)break;const E=(x?xe.getState().getMessagesForSession(x):xe.getState().messages).find(F=>{var N;return((N=F.askUser)==null?void 0:N.questionId)===i.questionId});E&&T(E.id,F=>({...F,askUser:F.askUser?{...F.askUser,answered:!0,answer:"已处理"}:F.askUser}),x);break}case"text_done":break;case"thinking":v&&K("thinking");break;case"done":if(rt(x),v&&!xe.getState().messages.some(W=>W.isQueued)&&P(null),v&&(K("idle"),ke.getState().autoSpeak)){const E=[...xe.getState().messages].reverse().find(F=>F.role==="assistant"&&F.content&&!F.isCompactionSummary);E!=null&&E.content&&(G=window.agentApi)!=null&&G.ttsSpeak&&(wn(),window.agentApi.ttsSpeak(E.content.slice(0,600)).then(F=>{F.ok||de("TTS 模型播报失败")}).catch(F=>{de(F instanceof Error?F.message:"TTS 模型播报失败")}))}break;case"error":if(i._preserveActiveRun||rt(x),v){if(i._preserveActiveRun&&x&&(wr.current.add(x),He.current=x,P(x),K("thinking")),i.code==="SESSION_OCCUPIED"){const E=[...x?xe.getState().getMessagesForSession(x):xe.getState().messages].reverse().find(F=>F.role==="user"&&!F.isQueued);on(E==null?void 0:E.content),E!=null&&E.content&&(Ae(E.content),x&&Yn(x,E.content)),rn(i.code),de(null)}else{de(i.message??"Unknown error");const E=[...x?xe.getState().getMessagesForSession(x):xe.getState().messages].reverse().find(F=>F.role==="user"&&!F.isQueued);ze&&(E!=null&&E.content)&&(Ae(E.content),x&&Yn(x,E.content))}i._preserveActiveRun||(P(null),K("idle"))}break;case"turn_aborted":rt(x),v&&(P(null),K("idle"));break}},$s=async i=>{var x;if(!re||!((x=window.agentApi)!=null&&x.setSessionPermissionMode)||cn)return;const g=Ke;xt(i),qe(!1),it(!0);try{await window.agentApi.setSessionPermissionMode(re,i)}catch(v){xt(g),de(v instanceof Error?v.message:"权限模式更新失败")}finally{it(!1)}},Us=async()=>{var i;if(!(!re||!((i=window.agentApi)!=null&&i.handoffSession)))try{await window.agentApi.handoffSession(re),de(null)}catch(g){de(g instanceof Error?g.message:"交接到 Desktop 失败")}},Os=async()=>{var i;if(!(!re||!((i=window.agentApi)!=null&&i.forkSession)||ht)){an(!0);try{await xi({sourceSessionId:re,forkSession:g=>window.agentApi.forkSession(g),activateSession:g=>{Ct.current=g,A(g)},refreshAndSelect:async g=>{n?await n(g):a==null||a(g)}}),sn&&Ae(sn),on(void 0),rn(void 0),de(null)}catch(g){de(g instanceof Error?g.message:"创建会话副本失败")}finally{an(!1)}}},Sr=()=>{Hn.current=!0,window.agentApi&&window.agentApi.abort(re||void 0),He.current=null,P(null),Ve.current.clear()},Cr=async i=>{const g=r||y;if(!g||!window.agentApi)return;const x=xe.getState().messages.find(v=>v.id===i);if(!(!x||!x.isQueued))try{await window.agentApi.steer(x.content,g,x.agentName),T(i,v=>({...v,isQueued:!1,isSteered:!0}))}catch(v){de(v instanceof Error?v.message:"引导失败")}},Kn=async(i,g,x)=>{Hn.current=!1,He.current=g,P(g);try{window.agentApi&&await window.agentApi.run(i.content,g,x,i.agentName,i.images)}catch(v){de(v instanceof Error?v.message:"Agent run failed")}finally{if(wr.current.delete(g)){He.current=g,P(g);return}const B=Hn.current?void 0:xe.getState().messages.find(G=>G.isQueued);B?(T(B.id,G=>({...G,isQueued:!1})),u&&u(t,g),Kn(B,g)):(He.current=null,P(null),u&&u(t,g))}},Ir=async()=>{if(!Ie.trim()||!Mt)return;En(window.agentApi,wn),de(null);const i=Ie.trim();if(/^\/loop\b/i.test(i)){const W=i.slice(5).trim();if(Ae(""),R({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),/^stop$/i.test(W)){window.agentApi&&(await window.agentApi.cronDeleteAll(),X([]),R({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(W)||W===""){if(window.agentApi){const ne=await window.agentApi.cronList();X(ne);const ce=ne.length===0?"当前没有定时任务。":ne.map((ie,ye)=>`**${ye+1}.** \`${ie.id.slice(0,6)}\` · ${rr(ie.cron)} · ${ie.enabled?"▶ 启用":"⏸ 已暂停"}
133
+ ${ie.prompt}`).join(`
134
+
135
+ `);R({id:crypto.randomUUID(),role:"assistant",content:ce,timestamp:Date.now()})}return}const E=W.match(/^(?:pause|暂停)\s+(\S+)$/i);if(E){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(E[1])),ce=await window.agentApi.cronPause((ne==null?void 0:ne.id)??E[1]);if(ce){const ie=await window.agentApi.cronList();X(ie),R({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${ce.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else R({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${E[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const F=W.match(/^(?:resume|恢复)\s+(\S+)$/i);if(F){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(F[1])),ce=await window.agentApi.cronResume((ne==null?void 0:ne.id)??F[1]);if(ce){const ie=await window.agentApi.cronList();X(ie),R({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${ce.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else R({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${F[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const N=W.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(N){if(window.agentApi){const ne=ee.find(ie=>ie.id.startsWith(N[1]));if(await window.agentApi.cronDelete((ne==null?void 0:ne.id)??N[1])){const ie=await window.agentApi.cronList();X(ie),R({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${N[1]}\` 已删除。`,timestamp:Date.now()})}else R({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${N[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const oe=W.match(/^(\S+)\s+(.+)$/s);if(oe){const ne=oe[1],ce=oe[2].trim();if(window.agentApi){let ie=r||y;if(!ie){const ye=await window.agentApi.createSession(ce.slice(0,60)||"定时任务",t||void 0);ie=ye.id,A(ye.id),n&&await n(ye.id)}try{const ye=await window.agentApi.cronCreate(ne,ce,{sessionId:ie}),Pt=await window.agentApi.cronList();X(Pt),R({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${ye.id.slice(0,6)}\`),${rr(ne)}执行:${ce}`,timestamp:Date.now()})}catch(ye){R({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${ye instanceof Error?ye.message:String(ye)}`,timestamp:Date.now()})}}return}R({id:crypto.randomUUID(),role:"assistant",content:"**定时任务用法:**\n- `/loop <间隔/cron> <任务>` — 创建,如 `/loop 5m 检查系统状态` 或 `/loop 0 9 * * * 早报`\n- `/loop list` — 查看所有定时任务\n- `/loop pause <id>` — 暂停\n- `/loop resume <id>` — 恢复\n- `/loop delete <id>` — 删除\n- `/loop stop` — 删除全部\n\n间隔支持:`30s`、`5m`、`2h`;也支持 5 字段 cron 表达式。",timestamp:Date.now()});return}const g=i.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(g){const W=g[1]+g[2],E=g[3].trim();if(E&&window.agentApi){let F=r||y;if(!F){const N=await window.agentApi.createSession(E.slice(0,60)||"定时任务",t||void 0);F=N.id,A(N.id),n&&await n(N.id)}try{const N=await window.agentApi.cronCreate(W,E,{sessionId:F}),oe=await window.agentApi.cronList();X(oe),Ae(""),R({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),R({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${N.id.slice(0,6)}\`),${rr(W)}执行:${E}`,timestamp:Date.now()})}catch(N){R({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${N instanceof Error?N.message:String(N)}`,timestamp:Date.now()})}return}}const x=(()=>{const W=Ie.trim().match(/^\/([\w-]+)\s*(.*)$/);if(W){const E=W[1],F=W[2].trim(),N=mn.find(oe=>oe.name===E);if(N)return F?`请使用「${N.name}」技能协助完成:${F}(技能说明:${N.description})`:`请使用「${N.name}」技能协助:${N.description}`}return Ie.trim()})(),v=d.length>0?d.map(W=>W.name).join(", "):void 0,B=Kt.length>0?[...Kt]:void 0,G=d.map(W=>W.id);if(k([]),ze&&(r||y)&&(yt.current=!0),Ae(""),at([]),Qe([]),be){R({id:crypto.randomUUID(),role:"user",content:x,timestamp:Date.now(),agentName:v,images:B,isQueued:!0});return}le([]);try{const W=await oi({text:x,projectId:t??null,sessionId:r||y,createSession:async(E,F)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(E,F)},activateSession:E=>{Ct.current=E,A(E),He.current=E,P(E)},showUserMessage:(E,F)=>R({id:crypto.randomUUID(),role:"user",content:E,timestamp:Date.now(),agentName:v,images:B},F),onSessionCreated:n});s&&s(W,x),await Kn({content:x,agentName:v,images:B},W,G.length>0?G:void 0)}catch(W){de(W instanceof Error?W.message:"Agent run failed")}};return c.useEffect(()=>{if(!V||!window.agentApi)return;const{text:i,projectId:g,sessionId:x}=V;let v=!1;return(async()=>{try{le([]);const B=await si({text:i,projectId:g,sessionId:x,createSession:async(G,W)=>await window.agentApi.createSession(G,W),activateSession:G=>{Ct.current=G,A(G),He.current=G,P(G)},showUserMessage:(G,W)=>R({id:crypto.randomUUID(),role:"user",content:G,timestamp:Date.now()},W),onSessionCreated:n,isCancelled:()=>v});if(!B)return;s&&s(B,i),await Kn({content:i},B)}catch(B){de(B instanceof Error?B.message:"语音指令执行失败")}})(),()=>{v=!0}},[V==null?void 0:V.nonce]),e.jsxs("div",{className:"chat-view chat-view--codex-history",style:{display:"flex",flexDirection:"column",height:"100%",maxWidth:"var(--chat-max-width)",margin:"0 auto"},children:[e.jsxs("div",{className:"chat-top-bar",style:{display:"flex",alignItems:"center",padding:"var(--chat-header-padding)",height:"var(--chat-header-height)",flexShrink:0,borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"no-drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:f?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:f||"会话"}),b&&w&&S&&e.jsx(Yo,{appearanceOpen:D,settingsOpen:h,hideToBackgroundTitle:H,onHideToBackground:w,onToggleAppearance:S,onOpenSettings:b})]}),e.jsxs("div",{ref:$e,className:"chat-messages",onScroll:ue,style:{flex:1,overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[_.length>0&&(he||Re)&&e.jsx("div",{className:"chat-history-page-status",role:Re?"alert":"status",style:{position:"absolute",top:8,left:"50%",transform:"translateX(-50%)",zIndex:2,minHeight:32,display:"flex",alignItems:"center",justifyContent:"center",gap:7,color:Re?"var(--danger)":"var(--text-muted)",fontSize:12},children:he?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载更早消息"})]}):e.jsxs("button",{type:"button",onClick:()=>void qn(),className:"chat-history-retry",style:{border:"1px solid color-mix(in srgb, var(--danger) 30%, transparent)",background:"color-mix(in srgb, var(--danger) 7%, transparent)",color:"var(--danger)",borderRadius:6,padding:"5px 10px",cursor:"pointer",fontSize:12},children:[Re,",点击重试"]})}),_.length===0&&gn&&hn&&e.jsxs("div",{className:"chat-history-initial-loading",role:"status",style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:9,color:"var(--text-muted)",fontSize:13},children:[e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载历史消息"})]}),_.length===0&&!gn&&!un&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:16},children:[e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"linear-gradient(135deg, var(--accent-dim) 0%, transparent 100%)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:28,color:"var(--accent)",marginBottom:8},children:"◇"}),e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:26,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"智能助手"}),e.jsx("p",{style:{fontSize:14,color:"var(--text-muted)",textAlign:"center",lineHeight:1.7},children:De?"有什么我能帮你的?工具、记忆和技能随时待命。":"请先在设置中配置 API Key 以开始使用。"})]}),te.map((i,g)=>{var ce,ie,ye,Pt,vn,Gn,Yt;const x=i;if(x.isQueued)return null;const v=i.role==="user",B=fi(te,g,be);if(x.isCompactionSummary)return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,margin:"20px 0",color:"var(--text-muted)",fontSize:12},children:[e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",borderRadius:20,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:11,cursor:"default",userSelect:"none"},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"17 1 21 5 17 9"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("polyline",{points:"7 23 3 19 7 15"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),"上下文已压缩"]}),e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}})]},i.id);if(x.widget){const O=ti[x.widget.widgetType];return O?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(O,{...x.widget.data,widgetId:x.widget.widgetId})},i.id):e.jsx("div",{style:{marginBottom:16,padding:12,borderRadius:8,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono, monospace)",fontSize:12,whiteSpace:"pre-wrap",maxHeight:300,overflow:"auto"},children:JSON.stringify(x.widget.data,null,2)},i.id)}if(x.askUser)return e.jsx(Go,{questionId:x.askUser.questionId,question:x.askUser.question,options:x.askUser.options,fields:x.askUser.fields,multiSelect:x.askUser.multiSelect,answered:x.askUser.answered,answer:x.askUser.answer,onAnswer:(O,fe)=>{var Ne;T(i.id,ae=>({...ae,askUser:{...ae.askUser,answered:!0,answer:O}})),(Ne=window.agentApi)==null||Ne.answerQuestion(x.askUser.questionId,O,fe)}},i.id);const G=x.agentName?x.agentName.charAt(0).toUpperCase():"你",W=!v&&g===te.length-1,E=be&&W&&Oe!=="tools"&&!qt,F=te[g+1],N=F&&F.role!==i.role&&!F.isCompactionSummary,oe=(i.toolCalls??[]).map((O,fe)=>{let Ne;if(O.name==="write_file"&&O.arguments.file_path){const ae=O.arguments.file_path;e:for(let Je=g;Je>=0;Je--){const It=te[Je].toolCalls;if(!It)continue;const ct=Je===g?fe-1:It.length-1;for(let Dt=ct;Dt>=0;Dt--){const ut=It[Dt];if(ut.name==="read_file"&&ut.arguments.file_path===ae&&ut.result&&!ut.isError){Ne=ut.result;break e}}}}return{toolCall:O,beforeContent:Ne,progress:bo(Lt,O.id),nativeSubagent:Tn[O.id]}}),ne=ui(oe);return e.jsxs("div",{className:`chat-message-group${B.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:B.compact?0:N?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:[E&&e.jsx("div",{className:"chat-message-activity",style:{display:"flex",marginBottom:4},children:e.jsx(Kr,{})}),e.jsxs("div",{className:`chat-message-row chat-message-row--${v?"user":"assistant"}`,style:{display:"flex",flexDirection:v?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[v?e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--accent)",color:"#fff",fontSize:12,fontWeight:700,letterSpacing:0,userSelect:"none"},children:G}):e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("path",{d:"M12 11V7"}),e.jsx("circle",{cx:"12",cy:"5",r:"2"}),e.jsx("circle",{cx:"8",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"16",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M8 20h8"})]})}),e.jsxs("div",{className:`chat-message-content chat-message-content--${v?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:v?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${v?"user":"assistant"} ${i.role==="assistant"&&i.content?"message-card":""}`,style:{padding:i.content||v&&((ce=x.images)!=null&&ce.length)?v?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:v?"14px 4px 14px 14px":"4px 14px 14px 14px",background:i.content||v&&((ie=x.images)!=null&&ie.length)?v?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:i.content||v&&((ye=x.images)!=null&&ye.length)?v?"1px solid rgba(79, 110, 247, 0.18)":void 0:"none",fontSize:"var(--chat-bubble-font-size)",lineHeight:"var(--chat-bubble-line-height)",color:"var(--text-primary)",letterSpacing:"0.01em"},children:[i.role==="assistant"&&((Pt=i.presentation)==null?void 0:Pt.reasoning)&&e.jsx(Xo,{sections:i.presentation.reasoning,streaming:be&&g>te.findLastIndex(O=>O.role==="user"),renderContent:sr}),v&&x.agentName?e.jsxs("div",{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:10,fontWeight:700,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:10,padding:"1px 7px 1px 5px",letterSpacing:"0.04em",marginRight:7,verticalAlign:"middle"},children:[e.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),x.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:i.content})]}):i.role==="assistant"&&i.content?(()=>{const fe=i.content.length>500,Ne=se.has(i.id),ae=fe&&!Ne?i.content.slice(0,500):i.content,Je=Ne?"收起全文":`展开全文,还有 ${i.content.length-500} 字`;return e.jsxs("div",{className:fe?"chat-message-long-content":void 0,children:[fe&&e.jsx("button",{type:"button",className:"chat-message-disclosure","aria-expanded":Ne,"aria-label":Je,title:Je,onClick:()=>Te(It=>{const ct=new Set(It);return Ne?ct.delete(i.id):ct.add(i.id),ct}),children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),e.jsxs("div",{className:fe?"chat-message-long-content__body":void 0,style:{whiteSpace:"pre-wrap",wordBreak:"break-word",position:"relative"},children:[v?ae:sr(ae),fe&&!Ne&&e.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:40,background:v?"linear-gradient(transparent, rgba(232, 236, 254, 0.95))":"linear-gradient(transparent, var(--chat-assistant-fade-end))",pointerEvents:"none"}})]})]})})():i.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:v?i.content:sr(i.content)}),v&&x.images&&x.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:i.content?8:0},children:x.images.map((O,fe)=>e.jsx("img",{src:O,alt:`attachment-${fe}`,style:{maxWidth:220,maxHeight:180,objectFit:"cover",borderRadius:6,border:"1px solid var(--border-subtle)",display:"block",cursor:"zoom-in"},onClick:()=>window.open(O,"_blank")},fe))}),v&&((vn=x.presentation)==null?void 0:vn.attachments)&&x.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:x.presentation.attachments.map((O,fe)=>O.dataUrl?e.jsx("img",{className:"chat-message-attachment-image",src:O.dataUrl,alt:O.name,title:O.name,onClick:()=>window.open(O.dataUrl,"_blank")},`${O.name}-${fe}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${O.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:O.name}),e.jsx("span",{children:"图片已失效"})]},`${O.name}-${fe}`))}),v&&((Gn=x.presentation)==null?void 0:Gn.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:x.presentation.rawContent})]}),ne.map(O=>O.action&&O.items.length>1?e.jsx(Ko,{items:O.items,onSelectSession:a},`group-${O.items[0].toolCall.id}`):e.jsx(mr,{toolCall:O.items[0].toolCall,beforeContent:O.items[0].beforeContent,progress:O.items[0].progress,nativeSubagent:O.items[0].nativeSubagent,onSelectSession:a},O.items[0].toolCall.id)),(()=>{const O=(i.toolCalls??[]).filter(ae=>ae.name==="write_file"&&ae.result&&!ae.isError);if(O.length===0)return null;const fe=new Map;for(const ae of O){const Je=ae.arguments.file_path??"",It=ae.arguments.content??"",ct=It?It.split(`
136
+ `).length:0;let Dt=0;e:for(let ut=g;ut>=0;ut--){const zr=te[ut].toolCalls??[];for(let Qn=zr.length-1;Qn>=0;Qn--){const yn=zr[Qn];if(yn.name==="read_file"&&yn.arguments.file_path===Je&&yn.result&&!yn.isError){Dt=yn.result.split(`
137
+ `).length;break e}}}fe.set(Je,{path:Je,lines:ct,added:Math.max(0,ct-Dt),removed:Math.max(0,Dt-ct)})}const Ne=[...fe.values()];return e.jsxs("div",{style:{marginTop:10,padding:"8px 12px",borderRadius:8,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)",display:"flex",flexWrap:"wrap",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",flexShrink:0},children:"变更汇总"}),Ne.map(ae=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:"var(--font-mono)",background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"2px 8px"},children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:ae.path,children:ae.path.replace(/\\/g,"/").split("/").pop()}),ae.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",ae.added]}),ae.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",ae.removed]}),ae.added===0&&ae.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[ae.lines,"行"]})]},ae.path))]})})()]}),(B.showCopy||B.showSpeak)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[B.showSpeak&&typeof((Yt=window.agentApi)==null?void 0:Yt.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>dt(i.id,i.content),title:We===i.id?"停止播报":"语音播报","aria-label":We===i.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${We===i.id?"is-active":""}`,children:We===i.id?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]})}),B.showCopy&&e.jsx("button",{type:"button",onClick:()=>{Mo(i.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),e.jsx("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]})})]}),v&&(x.isQueued||x.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[x.isQueued&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--text-muted)",padding:"2px 8px",borderRadius:20,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"排队中"]}),An&&e.jsxs("button",{onClick:()=>void Cr(i.id),title:"将此消息引导到当前对话",style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)",padding:"2px 10px",borderRadius:20,border:"1px solid rgba(79,110,247,0.3)",background:"var(--accent-dim)",cursor:"pointer",transition:"all 0.15s",fontFamily:"var(--font-body)"},onMouseEnter:O=>{O.currentTarget.style.background="rgba(79,110,247,0.18)",O.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:O=>{O.currentTarget.style.background="var(--accent-dim)",O.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"}),e.jsx("path",{d:"M12 3v18",opacity:"0.3"})]}),"引导"]})]}),x.isSteered&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--success)",padding:"2px 8px",borderRadius:20,background:"rgba(34,197,94,0.08)",border:"1px solid rgba(34,197,94,0.2)"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"已引导"]})]})]})]})]},i.id)}),be&&qt&&e.jsx(ms,{progress:qt}),be&&!qt&&Oe!=="tools"&&_.length>0&&_[_.length-1].role==="user"&&!_[_.length-1].isQueued&&e.jsx("div",{style:{display:"flex",alignItems:"flex-start",padding:"4px 0 4px",animation:"fadeInUp 0.3s var(--ease-out)"},children:e.jsx(Kr,{})}),un&&e.jsx("div",{style:{padding:12,margin:"8px 0",borderRadius:"var(--radius-sm)",background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",color:"var(--danger)",fontSize:13,animation:"fadeIn 0.2s var(--ease-out)",fontFamily:"var(--font-mono)"},children:un}),e.jsx("div",{ref:Me})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[(ft||Rn)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:9,padding:"8px 10px",border:"1px solid var(--border-default)",borderRadius:6,background:"var(--bg-surface)",color:"var(--text-muted)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2"}),e.jsx("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]}),e.jsx("span",{style:{flex:1},children:Gr(p,Pe)?"此会话仍由原客户端持有,可创建副本继续。":`此会话正在被 ${(p==null?void 0:p.sourceLabel)||"原客户端"} 使用,当前只读;原客户端释放后会自动恢复输入。`}),Gr(p,Pe)&&e.jsx("button",{type:"button",onClick:()=>void Os(),disabled:ht,style:{flexShrink:0,border:"1px solid var(--border-default)",borderRadius:5,padding:"5px 9px",background:"var(--bg-workspace)",color:"var(--text-primary)",fontSize:12,fontWeight:600,cursor:ht?"wait":"pointer",opacity:ht?.65:1},children:ht?"正在创建…":"以副本继续"})]}),$.length>0&&e.jsxs("div",{style:{marginBottom:10,padding:"8px 12px",borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-sm)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,marginBottom:6,fontSize:10,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),"任务列表"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(()=>{const i=new Set($.filter(g=>g.status==="completed").map(g=>g.title.toLowerCase()));return $.map(g=>{const x=g.status==="pending",v=g.status==="in-progress",B=g.status==="completed",G=x&&(g.dependsOn??[]).some(W=>!i.has(W.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:B?.65:1,transition:"opacity 0.3s"},children:[e.jsxs("div",{style:{width:16,height:16,borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:B?"rgba(52,211,153,0.15)":v?"var(--accent-dim)":G?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:B?"1.5px solid rgba(52,211,153,0.6)":v?"1.5px solid var(--accent)":G?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[B&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(52,211,153,0.9)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})}),v&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),G&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(239,68,68,0.8)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})}),x&&!G&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:B?"var(--text-muted)":G?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:B?"line-through":"none",flex:1},children:g.title}),G&&e.jsx("span",{title:`等待: ${(g.dependsOn??[]).join(", ")}`,style:{fontSize:10,color:"rgba(239,68,68,0.9)",background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:"等待前置"}),g.agentName&&e.jsxs("span",{style:{fontSize:10,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.2)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:["@",g.agentName]})]},g.id)})})()})]}),ee.length>0&&e.jsxs("div",{style:{marginBottom:10,borderRadius:10,background:"var(--bg-surface)",border:"1px solid rgba(251,191,36,0.25)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderBottom:"1px solid rgba(251,191,36,0.15)",background:"rgba(251,191,36,0.06)"},children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#d97706",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",textTransform:"uppercase",letterSpacing:"0.07em",flex:1},children:"定时任务"}),e.jsx("button",{onClick:async()=>{window.agentApi&&(await window.agentApi.cronDeleteAll(),X([]),R({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}))},title:"删除全部",style:{background:"none",border:"1px solid rgba(251,191,36,0.35)",borderRadius:6,color:"#d97706",cursor:"pointer",padding:"1px 7px",fontSize:10},children:"全部删除"})]}),ee.map(i=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:i.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:i.enabled?"#22c55e":"#9ca3af",boxShadow:i.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:i.enabled?"pulse 2s ease-in-out infinite":"none"}}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.25)",borderRadius:6,padding:"1px 6px",flexShrink:0,fontFamily:"var(--font-mono)"},children:i.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.label||i.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:i.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[i.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="#d97706",g.currentTarget.style.color="#d97706"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="#22c55e",g.currentTarget.style.color="#22c55e"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(i.id);const g=await window.agentApi.cronList();X(g)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:g=>{g.currentTarget.style.borderColor="var(--danger)",g.currentTarget.style.color="var(--danger)"},onMouseLeave:g=>{g.currentTarget.style.borderColor="var(--border-default)",g.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},i.id))]}),zn.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:zn.map((i,g)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"3px 10px 3px 8px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.18)",fontSize:12,color:"var(--accent)",maxWidth:220},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),e.jsx("button",{onClick:()=>Es(g),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,marginLeft:2,fontSize:13,lineHeight:1,display:"flex"},children:"✕"})]},g))}),Kt.length>0&&(()=>{const i=ge.find(x=>x.id===ot),g=!i||!Ns(i.modelId);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[g&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:"rgba(234,179,8,0.1)",border:"1px solid rgba(234,179,8,0.4)",color:"rgba(202,138,4,1)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"当前模型(",(i==null?void 0:i.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Kt.map((x,v)=>e.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[e.jsx("img",{src:x,alt:`image-${v}`,style:{width:72,height:72,objectFit:"cover",borderRadius:8,border:"1.5px solid var(--border-default)",display:"block"}}),e.jsx("button",{onClick:()=>Ds(v),style:{position:"absolute",top:-6,right:-6,width:18,height:18,borderRadius:"50%",background:"var(--danger, #e53e3e)",border:"none",color:"#fff",fontSize:11,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},children:"✕"})]},v))})]})})(),(()=>{const i=_.filter(g=>g.isQueued);return i.length===0?null:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8,padding:"8px 12px",borderRadius:12,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,fontWeight:600,color:"var(--text-muted)",letterSpacing:"0.03em"},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M3 9h18"}),e.jsx("path",{d:"M9 21V9"})]}),"排队消息(",i.length,")"]}),i.map(g=>{const x=g,v=x.content.length>80?x.content.slice(0,80)+"…":x.content;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 8px",borderRadius:8,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{flex:1,fontSize:13,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:[x.agentName&&e.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"var(--accent-dim)",borderRadius:10,padding:"1px 5px",marginRight:5,verticalAlign:"middle"},children:["@",x.agentName]}),v]}),An&&e.jsxs("button",{onClick:()=>void Cr(g.id),title:"将此消息引导到当前对话",style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:11,fontWeight:600,color:"var(--accent)",padding:"3px 10px",borderRadius:20,border:"1px solid rgba(79,110,247,0.3)",background:"var(--accent-dim)",cursor:"pointer",transition:"all 0.15s",fontFamily:"var(--font-body)",whiteSpace:"nowrap",flexShrink:0},onMouseEnter:B=>{B.currentTarget.style.background="rgba(79,110,247,0.18)",B.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:B=>{B.currentTarget.style.background="var(--accent-dim)",B.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"}),e.jsx("path",{d:"M12 3v18",opacity:"0.3"})]}),"引导"]})]},g.id)})]})})(),e.jsx("div",{ref:fn,style:{position:"relative"},children:e.jsx("div",{className:"composer-shell",style:{display:"flex",flexDirection:"column",gap:0,background:"var(--bg-surface)",borderRadius:14,overflow:"visible"},children:e.jsxs("div",{className:"composer-input-row",style:{display:"flex",alignItems:"center",gap:8,padding:"var(--composer-row-padding)"},children:[e.jsx("input",{ref:Le,type:"file",multiple:!0,style:{display:"none"},onChange:Ws}),d.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:d.map(i=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"2px 7px 2px 6px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.25)",fontSize:12,color:"var(--accent)",flexShrink:0,whiteSpace:"nowrap"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),"@",i.name,e.jsx("button",{onClick:()=>Ts(i.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},i.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:Xt,rows:3,value:Ie,onChange:i=>Ms(i.target.value),onBlur:()=>setTimeout(()=>{U(null),q(null)},120),onKeyDown:Ls,placeholder:ft?"原客户端使用中,当前只读":De?be?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!Mt}),e.jsxs("div",{className:"web-native-composer-toolbar",children:[e.jsxs("div",{className:"web-native-add-wrap",children:[e.jsx("button",{type:"button",className:"web-native-add-button","aria-label":"添加附件、图片或语音","aria-expanded":ln,onClick:()=>_e(i=>!i),children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})}),ln&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var i;_e(!1),(i=Le.current)==null||i.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{_e(!1),je()},children:"语音输入"})]})]}),e.jsxs("div",{className:"web-native-permission-wrap",ref:mt,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${Ke}`,"aria-label":`会话权限:${(Ar=Dn.find(i=>i.value===Ke))==null?void 0:Ar.label}`,"aria-haspopup":"menu","aria-expanded":Wt,title:`会话权限:${(Rr=Dn.find(i=>i.value===Ke))==null?void 0:Rr.label}`,disabled:!re||cn,onClick:()=>qe(i=>!i),children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),Wt&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:Dn.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ke===i.value,className:Ke===i.value?"is-active":"",onClick:()=>{$s(i.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:Ke===i.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:i.label}),e.jsx("small",{children:i.description})]})]},i.value))})]}),ze&&(p==null?void 0:p.controller)==="web"&&typeof((Tr=window.agentApi)==null?void 0:Tr.handoffSession)=="function"&&e.jsx("button",{type:"button",className:"web-native-runtime-status",onClick:()=>{Us()},title:"交接到 Desktop",children:"交接到 Desktop"}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Jo,{usage:re?pe[re]:void 0,contextWindowK:pt,compact:!0})}),e.jsx("label",{className:"web-native-model-control",title:"切换模型",children:e.jsx("select",{"aria-label":"当前模型",value:ze?"":ot,disabled:ze||ge.length===0,onChange:i=>{In(i.target.value)},children:ze?e.jsx("option",{value:"",children:(p==null?void 0:p.agentType)??"本地 Agent"}):ge.length===0?e.jsx("option",{value:"",children:"未配置模型"}):ge.map(i=>e.jsx("option",{value:i.id,children:i.name||i.modelId},i.id))})}),be?e.jsx("button",{type:"button",onClick:Sr,className:"web-native-stop-button","aria-label":"停止生成",title:"停止生成",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):ze?e.jsxs("span",{className:"web-native-agent-status",role:"status","aria-label":"Agent 空闲",title:"Agent 空闲",children:[e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]}),e.jsx("span",{"aria-hidden":"true"})]}):e.jsxs("div",{className:"web-native-effort-wrap",ref:Ge,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Fe,"aria-label":`推理强度:${Qr[Ye]}`,title:`推理强度:${Qr[Ye]}(点击切换)`,onClick:()=>dn(i=>!i),children:e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]})}),Fe&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:Ss.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ye===i.value,className:Ye===i.value?"is-active":void 0,onClick:()=>{gt("reasoningEffort",i.value),Un(),dn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Ye===i.value?"✓":""}),i.label]},i.value))})]}),e.jsx("button",{type:"button",onClick:Ir,disabled:!Mt||!Ie.trim(),className:"web-native-send-button","aria-label":be?"排队发送":"发送",title:be?"排队发送":"发送",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 19V5M5 12l7-7 7 7"})})})]})]})})}),e.jsxs("div",{className:"chat-composer-hint",style:{textAlign:"center",marginTop:7,fontSize:11,color:"var(--text-muted)",letterSpacing:"0.03em",opacity:.6},children:["Enter 发送",be?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",J?" · 🎤 正在聆听…":""]})]}),tt&&z!==null&&jr.length>0&&zt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-tt.top+8,left:tt.left,width:tt.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",overflow:"hidden",zIndex:99999},children:[e.jsx("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em"},children:"智能体"}),jr.map(i=>e.jsxs("button",{onMouseDown:g=>{g.preventDefault(),Rs(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:g=>{g.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:g=>{g.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:i.description})]},i.id))]}),document.body),tt&&M!==null&&Vn.length>0&&zt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-tt.top+8,left:tt.left,width:tt.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",zIndex:99999,display:"flex",flexDirection:"column",maxHeight:320},children:[e.jsxs("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",flexShrink:0},children:["技能 (",Vn.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:Vn.map(i=>e.jsxs("button",{onMouseDown:g=>{g.preventDefault(),zs(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:g=>{g.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:g=>{g.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.description})]},i.name))})]}),document.body)]})}function ki({status:t,isRunning:r,needsInput:n}){return t==="failed"||t==="error"?"error":r?n?"needs-input":"running":"completed"}const Si={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function Cs(t,r){return t.map((n,s)=>({session:n,index:s})).sort((n,s)=>r(n.session,s.session)||n.index-s.index).map(({session:n})=>n)}function br(t){return Cs(t,(r,n)=>n.created.localeCompare(r.created))}function Ci(t,r){return Cs(br(t),(n,s)=>Number(r(s))-Number(r(n)))}const Ii=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Xr={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function Yr(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function Ai(){const{maxIterations:t,contextWindow:r,isConfigured:n,profiles:s,activeProfileId:o,setField:a,loadFromSystem:l,saveToSystem:u,addProfile:f,updateProfile:p,deleteProfile:b,switchActiveProfile:h}=Fn(),[w,S]=c.useState(null),[D,H]=c.useState("success"),[V,_]=c.useState(null),[m,j]=c.useState(!1),[R,P]=c.useState(Yr());c.useEffect(()=>{l()},[]);const A=()=>{j(!0),_(null),P(Yr())},C=Y=>{j(!1),_(Y.id),P({name:Y.name,provider:Y.provider,modelId:Y.modelId,apiKey:Y.apiKey,baseUrl:Y.baseUrl})},L=()=>{_(null),j(!1)},I=async()=>{if(!R.name.trim()||!R.apiKey.trim()||!R.modelId.trim()){S("名称、API Key 和模型 ID 为必填项"),H("error");return}m?f(R):V&&p(V,R),_(null),j(!1),S(null),setTimeout(()=>u(),0)},T=async Y=>{b(Y),setTimeout(()=>u(),0)},Q=async Y=>{await h(Y),S("已切换模型"),H("success"),setTimeout(()=>S(null),1500)},Z=async()=>{S(null);try{await u(),S("设置保存成功"),H("success")}catch(Y){S(Y instanceof Error?Y.message:"保存失败"),H("error")}},pe=m||V!==null;return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:640,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"设置"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:36},children:"管理模型提供商和运行参数。工作目录在项目设置中配置。"}),e.jsxs("section",{style:{marginBottom:40},children:[e.jsxs("div",{className:"settings-head-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:14},children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",margin:0},children:"模型提供商"}),e.jsx("button",{onClick:A,style:Ti,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.length===0&&!pe&&e.jsx("div",{style:{padding:"20px 16px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),s.map(Y=>{const Se=Y.id===o,we=Y.id===V;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${Se?"var(--accent)":"var(--border-default)"}`,background:Se?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{className:"profile-row",style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px"},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",padding:"2px 7px",borderRadius:4,background:Se?"var(--accent)":"var(--bg-deep)",color:Se?"#fff":"var(--text-muted)",flexShrink:0},children:Y.provider}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Y.name||Y.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[Y.modelId," ",Y.baseUrl?`· ${Y.baseUrl}`:""]})]}),Se&&e.jsx("span",{style:{fontSize:11,color:"var(--accent)",fontWeight:600,flexShrink:0},children:"● 使用中"}),e.jsxs("div",{className:"profile-row-actions",style:{display:"flex",gap:6,flexShrink:0},children:[!Se&&e.jsx("button",{onClick:()=>Q(Y.id),style:or,children:"切换"}),e.jsx("button",{onClick:()=>we?L():C(Y),style:or,children:we?"收起":"编辑"}),e.jsx("button",{onClick:()=>T(Y.id),style:{...or,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),we&&e.jsx(Zr,{draft:R,setDraft:P,onSave:I,onCancel:L})]},Y.id)}),m&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--accent)",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"10px 14px 0",fontSize:13,fontWeight:600,color:"var(--accent)"},children:"新建提供商"}),e.jsx(Zr,{draft:R,setDraft:P,onSave:I,onCancel:L})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},children:"常规"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Ft,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:Y=>a("maxIterations",parseInt(Y.target.value)||10),min:1,max:50,style:$t})}),e.jsx(Ft,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:r??100,onChange:Y=>a("contextWindow",parseInt(Y.target.value)||100),min:8,max:2e3,style:$t})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:Z,style:Is,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:n?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:n?"var(--success)":"var(--text-muted)",border:`1px solid ${n?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:n?"● 已连接":"○ 未配置"})]}),w&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:D==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:D==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:D==="success"?"var(--success)":"var(--danger)",fontSize:13},children:w})]})}function Zr({draft:t,setDraft:r,onSave:n,onCancel:s}){const o=(a,l)=>r(u=>{const f={...u,[a]:l};return a==="provider"&&!u.modelId&&(f.modelId=Xr[l]??""),f});return e.jsxs("div",{style:{padding:"12px 14px 14px",display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(Ft,{label:"名称",children:e.jsx("input",{value:t.name,onChange:a=>o("name",a.target.value),placeholder:"我的 Claude",style:$t})}),e.jsx(Ft,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:a=>{o("provider",a.target.value),o("modelId",Xr[a.target.value]??"")},style:$t,children:Ii.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})})]}),e.jsx(Ft,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:a=>o("modelId",a.target.value),placeholder:"claude-sonnet-4-6",style:$t})}),e.jsx(Ft,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:a=>o("apiKey",a.target.value),placeholder:"sk-...",style:$t})}),e.jsx(Ft,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:a=>o("baseUrl",a.target.value),placeholder:"https://api.anthropic.com",style:$t})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:n,style:Is,children:"保存"}),e.jsx("button",{onClick:s,style:Ri,children:"取消"})]})]})}function Ft({label:t,children:r}){return e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:"var(--text-secondary)",marginBottom:6,fontWeight:500,textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),r]})}const $t={width:"100%",padding:"9px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",boxSizing:"border-box"},Is={padding:"11px 28px",borderRadius:"var(--radius-sm)",border:"1px solid transparent",background:"var(--accent)",color:"var(--text-inverse)",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)",boxShadow:"0 2px 16px var(--accent-glow)",transition:"transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out)"},Ri={padding:"11px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:14,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",whiteSpace:"nowrap",transition:"all 0.15s var(--ease-out)"},Ti={padding:"6px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},or={padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)"},ir={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function zi(){const[t,r]=c.useState([]),[n,s]=c.useState("stdio"),[o,a]=c.useState(ir),[l,u]=c.useState(!1),[f,p]=c.useState({id:!1,command:!1,url:!1}),[b,h]=c.useState({}),[w,S]=c.useState({}),[D,H]=c.useState(new Set),[V,_]=c.useState(null),[m,j]=c.useState(""),[R,P]=c.useState(!1),A=async y=>{var le;if(!((le=window.agentApi)!=null&&le.mcpProbe))return;H(ee=>new Set([...ee,y.id])),S(ee=>{const X={...ee};return delete X[y.id],X});const $=new Promise((ee,X)=>setTimeout(()=>X(new Error("连接超时(15s)")),15e3));try{const ee=await Promise.race([window.agentApi.mcpProbe(y),$]);h(X=>({...X,[y.id]:ee}))}catch(ee){const X=ee instanceof Error?ee.message:String(ee);console.warn(`[MCP] probe failed for ${y.id}:`,X),h(te=>{const Ce={...te};return delete Ce[y.id],Ce}),S(te=>({...te,[y.id]:X})),(y.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(X))&&(j(""),_({server:y}))}finally{H(ee=>{const X=new Set(ee);return X.delete(y.id),X})}};c.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(y=>{r(y),y.filter($=>$.enabled!==!1).forEach($=>A($))}).catch(console.error)},[]);const[C,L]=c.useState(""),[I,T]=c.useState(""),[Q,Z]=c.useState(!1),pe=async()=>{T("");let y;try{y=JSON.parse(C.trim());const $=y.mcpServers??y,le=Object.entries($);if(le.length===0){T("未找到任何服务器");return}Z(!0);const ee=[];for(const[te,Ce]of le){const ge=Ce,ot=ge.name||te,Vt=ge.disabled!==!0;let pt;if(ge.url||ge.type==="streamableHttp"||ge.type==="sse"){const Ye=ge.type==="sse"?"sse":"streamableHttp";pt={id:te,name:ot,transport:Ye,url:ge.url,headers:ge.headers??{},env:ge.env??{},enabled:Vt}}else pt={id:te,name:ot,transport:"stdio",command:ge.command,args:ge.args??[],env:ge.env??{},enabled:Vt};await window.agentApi.mcpSave(pt),ee.push(pt)}const X=await window.agentApi.mcpList();r(X),L(""),ee.filter(te=>te.enabled!==!1).forEach(te=>A(te))}catch($){T($ instanceof Error?$.message:"JSON 解析失败")}finally{Z(!1)}},Y=()=>o.id.trim()!==""&&o.command.trim()!=="",Se=()=>o.id.trim()!==""&&o.url.trim()!=="",we=y=>{const $={};for(const le of y.split(`
138
+ `)){const ee=le.indexOf(":");if(ee<1)continue;const X=le.slice(0,ee).trim(),te=le.slice(ee+1).trim();X&&($[X]=te)}return $},nt=async()=>{if(p({id:!0,command:!0,url:!0}),!(n==="stdio"&&!Y())&&!((n==="sse"||n==="streamableHttp")&&!Se())){u(!0);try{const y=n==="sse"||n==="streamableHttp"?we(o.headersRaw):{},$=n==="stdio"?{id:o.id,name:o.name||o.id,transport:"stdio",command:o.command,args:o.args.split(" ").filter(Boolean),enabled:!0}:{id:o.id,name:o.name||o.id,transport:n,url:o.url,headers:y,enabled:!0};await window.agentApi.mcpSave($);const le=await window.agentApi.mcpList();r(le),a(ir),p({id:!1,command:!1,url:!1}),A($)}catch(y){console.error("Failed to save MCP server",y)}finally{u(!1)}}},Ut=async y=>{await window.agentApi.mcpDelete(y),r(t.filter($=>$.id!==y))},rt=async(y,$)=>{await window.agentApi.mcpSetEnabled(y,$),r(t.map(le=>le.id===y?{...le,enabled:$}:le))},Xe=async()=>{if(!(!V||!m.trim())){P(!0);try{const y=V.server.transport==="streamableHttp"?{...V.server,headers:{...V.server.headers??{},Authorization:`Bearer ${m.trim()}`}}:{...V.server,env:{...V.server.env??{},Authorization:`Bearer ${m.trim()}`}};await window.agentApi.mcpSave(y);const $=await window.agentApi.mcpList();r($),_(null),j("");const le=$.find(ee=>ee.id===y.id)??y;A(le)}finally{P(!1)}}},Ot=y=>y==="stdio"?"本地":y==="streamableHttp"?"HTTP":"SSE",Ht=y=>y==="stdio"?"#68d391":y==="streamableHttp"?"#f6ad55":"#63b3ed",st=y=>y==="stdio"?"rgba(154,230,180,0.15)":y==="streamableHttp"?"rgba(246,173,85,0.15)":"rgba(99,179,237,0.15)";return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:660,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"MCP 服务器"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:32},children:"通过模型上下文协议连接外部工具。"}),e.jsxs("div",{style:{padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",marginBottom:28,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:0},children:"添加服务器"}),e.jsx("div",{style:{display:"flex",background:"var(--bg-surface)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden"},children:["stdio","sse","streamableHttp"].map(y=>e.jsx("button",{onClick:()=>{s(y),p({id:!1,command:!1,url:!1}),a($=>({...ir,id:$.id,name:$.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:n===y?"var(--accent)":"transparent",color:n===y?"var(--text-inverse)":"var(--text-muted)"},children:y==="stdio"?"本地 stdio":y==="sse"?"远程 SSE":"HTTP"},y))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.id,onChange:y=>a($=>({...$,id:y.target.value})),onBlur:()=>p(y=>({...y,id:!0})),placeholder:"服务器 ID *",style:{...At,...f.id&&!o.id?ar:{}}}),f.id&&!o.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.name,onChange:y=>a($=>({...$,name:y.target.value})),placeholder:"显示名称",style:{...At,flex:1}})]}),n==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.command,onChange:y=>a($=>({...$,command:y.target.value})),onBlur:()=>p(y=>({...y,command:!0})),placeholder:"命令(如 npx)*",style:{...At,...f.command&&!o.command?ar:{}}}),f.command&&!o.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.args,onChange:y=>a($=>({...$,args:y.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...At,flex:2}})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.url,onChange:y=>a($=>({...$,url:y.target.value})),onBlur:()=>p(y=>({...y,url:!0})),placeholder:n==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...At,...f.url&&!o.url?ar:{}}}),f.url&&!o.url&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("label",{style:{fontSize:12,color:"var(--text-muted)"},children:"请求头(每行 key: value)"}),e.jsx("textarea",{value:o.headersRaw,onChange:y=>a($=>({...$,headersRaw:y.target.value})),placeholder:`access_token: abc123
139
+ Authorization: Bearer sk-...`,rows:3,style:{...At,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:nt,disabled:l,style:{alignSelf:"flex-start",padding:"10px 22px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:l?"not-allowed":"pointer",fontFamily:"var(--font-body)"},children:l?"保存中…":"添加服务器"})]})]}),e.jsxs("div",{style:{marginBottom:28,padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:"0 0 8px"},children:"导入 JSON 配置"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",margin:"0 0 10px"},children:"兼容 Claude Desktop / Cursor 格式,粘贴后点导入。"}),e.jsx("textarea",{value:C,onChange:y=>{L(y.target.value),T("")},placeholder:`{
140
+ "my-server": {
141
+ "command": "npx",
142
+ "args": ["-y", "some-mcp"]
143
+ }
144
+ }`,rows:5,style:{...At,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),I&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:I}),e.jsx("button",{onClick:pe,disabled:!C.trim()||Q,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:C.trim()&&!Q?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:C.trim()&&!Q?1:.5},children:Q?"导入中…":"导入"})]}),t.filter(y=>y.transport===n).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",n==="stdio"?"本地 stdio":n==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(y=>y.transport===n).map(y=>e.jsxs("div",{style:{padding:"14px 16px",background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",display:"flex",justifyContent:"space-between",alignItems:"center",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("div",{style:{fontSize:14,fontWeight:500,color:"var(--text-primary)"},children:y.name||y.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:st(y.transport),color:Ht(y.transport),fontWeight:600},children:Ot(y.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[y.transport==="stdio"?`${y.command} ${(y.args??[]).join(" ")}`:y.url,y.transport!=="stdio"&&y.headers&&Object.keys(y.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(y.headers).length," 个请求头"]})]}),D.has(y.id)?e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6,display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",border:"2px solid var(--accent)",borderTopColor:"transparent",animation:"spin 0.8s linear infinite"}}),"探测工具中…"]}):w[y.id]?e.jsxs("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:w[y.id]}),y.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(w[y.id])?e.jsx("button",{onClick:()=>{j(""),_({server:y})},style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid rgba(251,191,36,0.4)",background:"rgba(251,191,36,0.1)",color:"#fbbf24",cursor:"pointer",fontFamily:"var(--font-body)"},children:"输入 Token"}):null,e.jsx("button",{onClick:()=>A(y),style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontFamily:"var(--font-body)"},children:"重试"})]}):b[y.id]&&b[y.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:b[y.id].map($=>e.jsx("span",{title:$.description,style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"rgba(168,85,247,0.12)",color:"#c084fc",border:"1px solid rgba(168,85,247,0.2)",fontFamily:"var(--font-mono)",cursor:"default"},children:$.name},$.name))}):b[y.id]!==void 0?e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6},children:"无可用工具"}):null]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("label",{style:{fontSize:12,color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",gap:4},children:[e.jsx("input",{type:"checkbox",checked:y.enabled!==!1,onChange:$=>rt(y.id,$.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Ut(y.id),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(248,113,113,0.2)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500,transition:"background 0.15s"},onMouseEnter:$=>{$.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:$=>{$.currentTarget.style.background="transparent"},children:"移除"})]})]},y.id))}),V&&e.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},onClick:y=>{y.target===y.currentTarget&&_(null)},children:e.jsxs("div",{style:{width:420,background:"var(--bg-surface)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-default)",padding:28,boxShadow:"0 24px 48px rgba(0,0,0,0.4)"},children:[e.jsx("h3",{style:{margin:"0 0 6px",fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:"需要认证"}),e.jsxs("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-muted)"},children:["服务器 ",e.jsx("strong",{style:{color:"var(--text-primary)"},children:V.server.name||V.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:m,onChange:y=>j(y.target.value),onKeyDown:y=>{y.key==="Enter"&&Xe(),y.key==="Escape"&&_(null)},placeholder:"sk-… 或 Bearer token",style:{...At,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>_(null),style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:13,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"}),e.jsx("button",{onClick:Xe,disabled:!m.trim()||R,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:m.trim()&&!R?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:m.trim()&&!R?1:.5},children:R?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const At={padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",fontFamily:"var(--font-body)"},ar={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function Mi(){const[t,r]=c.useState([]),[n,s]=c.useState(""),[o,a]=c.useState(null),[l,u]=c.useState(!1),[f,p]=c.useState(""),[b,h]=c.useState(""),[w,S]=c.useState("user"),[D,H]=c.useState(""),[V,_]=c.useState(null),[m,j]=c.useState("success"),R=async()=>{if(window.agentApi){const L=await window.agentApi.listMemories();r(L)}};c.useEffect(()=>{R()},[]);const P=async()=>{if(!n.trim()){R();return}if(window.agentApi){const L=await window.agentApi.searchMemories(n);r(L.map(I=>I.entry))}},A=async()=>{if(!(!f.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:f.trim(),description:b,type:w,content:D,created:(o==null?void 0:o.created)??new Date().toISOString(),updated:new Date().toISOString()}),u(!1),a(null),p(""),h(""),H(""),S("user"),_("保存成功"),j("success"),await R()}catch(L){_(L instanceof Error?L.message:"保存失败"),j("error")}},C=L=>{a(L),p(L.name),h(L.description),S(L.type),H(L.content),u(!0)};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"记忆"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginTop:4},children:"跨会话的持久化知识库。"})]}),e.jsx("button",{onClick:()=>{u(!0),a(null),p(""),h(""),H(""),S("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:n,onChange:L=>s(L.target.value),onKeyDown:L=>L.key==="Enter"&&P(),placeholder:"搜索记忆...",style:{flex:1,padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)"}}),e.jsx("button",{onClick:P,style:es,children:"搜索"})]}),V&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:m==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:m==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:m==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:V}),l&&e.jsxs("div",{style:{padding:20,marginBottom:24,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("input",{value:f,onChange:L=>p(L.target.value),placeholder:"名称",style:{...Nn,marginBottom:10},disabled:!!o}),e.jsx("input",{value:b,onChange:L=>h(L.target.value),placeholder:"描述",style:{...Nn,marginBottom:10}}),e.jsxs("select",{value:w,onChange:L=>S(L.target.value),style:{...Nn,marginBottom:10},children:[e.jsx("option",{value:"user",children:"用户"}),e.jsx("option",{value:"feedback",children:"反馈"}),e.jsx("option",{value:"project",children:"项目"}),e.jsx("option",{value:"reference",children:"参考"})]}),e.jsx("textarea",{value:D,onChange:L=>H(L.target.value),placeholder:"内容",rows:5,style:{...Nn,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,style:{padding:"9px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--success)",color:"#000",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"保存"}),e.jsx("button",{onClick:()=>u(!1),style:es,children:"取消"})]})]}),t.map(L=>e.jsxs("div",{style:{padding:"14px 16px",marginBottom:8,background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{color:"var(--text-primary)",fontWeight:600,fontSize:14},children:L.name}),e.jsx("span",{style:{fontSize:10,padding:"2px 8px",borderRadius:10,background:"rgba(255,255,255,0.04)",color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:500},children:L.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>C(L),style:ts,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(L.name),_("删除成功"),j("success"),await R()}catch(I){_(I instanceof Error?I.message:"删除失败"),j("error")}},style:{...ts,color:"var(--danger)"},children:"删除"})]})]}),L.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:L.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[L.content.slice(0,180),L.content.length>180?"…":""]})]},L.name)),t.length===0&&!l&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Nn={width:"100%",padding:"11px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"},es={padding:"10px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},ts={padding:"4px 10px",borderRadius:6,fontSize:11,border:"none",background:"rgba(255,255,255,0.05)",color:"var(--text-secondary)",cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500},Li=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function Wi(){const[t,r]=c.useState([]),[n,s]=c.useState(null),[o,a]=c.useState(!1),[l,u]=c.useState(null),[f,p]=c.useState("success"),[b,h]=c.useState(""),w=(C,L="success")=>{u(C),p(L),setTimeout(()=>u(null),3e3)},S=async()=>{if(!window.agentApi)return;const C=await window.agentApi.listSkills();r(C)};c.useEffect(()=>{S()},[]);const D=C=>{s({...C}),h((C.triggers??[]).join(", ")),a(!1)},H=()=>{s(Li()),h(""),a(!0)},V=()=>{s(null),a(!1)},_=async()=>{if(!n||!window.agentApi)return;if(!n.name.trim()){w("名称不能为空","error");return}const C=b.split(",").map(L=>L.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:n.name.trim(),description:n.description,triggers:C,prompt:n.prompt,filePath:n.filePath??""}),w(o?"技能已创建":"技能已保存"),s(null),await S()}catch(L){w(L instanceof Error?L.message:"保存失败","error")}},m=async C=>{if(window.agentApi)try{await window.agentApi.deleteSkill(C),w("已删除"),(n==null?void 0:n.name)===C&&s(null),await S()}catch(L){w(L instanceof Error?L.message:"删除失败","error")}},j=async C=>{if(!window.agentApi)return;const L=!C.enabled;await window.agentApi.setSkillEnabled(C.name,L),await S()},R=async()=>{if(window.agentApi)try{const C=await window.agentApi.importSkill();if(!C)return;w(`已导入技能「${C.name}」,本次会话立即生效`),await S()}catch(C){w(C instanceof Error?C.message:"导入失败","error")}},P={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},A={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"技能管理"}),e.jsx("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:"配置触发词和提示词,让 Agent 自动激活专属技能"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:R,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer"},children:"↓ 导入技能"}),e.jsx("button",{onClick:H,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"+ 新建技能"})]})]}),l&&e.jsx("div",{style:{marginBottom:16,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:f==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:f==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:f==="success"?"var(--success)":"var(--danger)",fontSize:13},children:l}),n&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:o?"新建技能":`编辑:${n.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:A,children:"名称"}),e.jsx("input",{style:P,value:n.name,disabled:!o,onChange:C=>s({...n,name:C.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"描述"}),e.jsx("input",{style:P,value:n.description,onChange:C=>s({...n,description:C.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"触发词(逗号分隔)"}),e.jsx("input",{style:P,value:b,onChange:C=>h(C.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"提示词"}),e.jsx("textarea",{style:{...P,minHeight:120,resize:"vertical"},value:n.prompt,onChange:C=>s({...n,prompt:C.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:_,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"保存"}),e.jsx("button",{onClick:V,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!n&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(C=>{var L;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:"14px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-glass)",opacity:C.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>j(C),title:C.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:C.enabled===!1?"var(--border-default)":"var(--accent)",cursor:"pointer",position:"relative",transition:"background 0.2s"},children:e.jsx("span",{style:{position:"absolute",top:2,left:C.enabled===!1?2:14,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:C.name}),((L=C.triggers)==null?void 0:L.length)>0&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["触发词:",C.triggers.slice(0,3).join(" · "),C.triggers.length>3?" ...":""]})]}),C.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:C.description}),C.prompt&&e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",opacity:.7},children:[C.prompt.slice(0,80),C.prompt.length>80?"...":""]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>D(C),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:12,cursor:"pointer"},children:"编辑"}),e.jsx("button",{onClick:()=>m(C.name),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(244,63,94,0.3)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer"},children:"删除"})]})]},C.name)})]})]})}const Pn=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function As(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function Ei(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:As(),maxIterations:0,isDefault:!1}}const gr={padding:"5px 12px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-secondary)",fontSize:12,fontWeight:500,cursor:"pointer"},Sn={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},Tt={width:"100%",padding:"7px 10px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",boxSizing:"border-box"},Rt={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function Bi({ph:t,onChange:r,onDelete:n}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:Tt,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>r({...t,key:s.target.value})}),e.jsx("input",{style:Tt,placeholder:"说明",value:t.description,onChange:s=>r({...t,description:s.target.value})}),e.jsx("input",{style:Tt,placeholder:"默认值",value:t.defaultValue,onChange:s=>r({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:n,style:{...Sn,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function ns({initial:t,activeAgentId:r,onSave:n,onCancel:s}){const{profiles:o}=Fn(),[a,l]=c.useState([]),[u,f]=c.useState([]),[p,b]=c.useState({...Ei(),...t,capabilities:{...As(),...t.capabilities??{}}}),[h,w]=c.useState(null),[S,D]=c.useState(!1);c.useEffect(()=>{var I,T;window.agentApi&&(window.agentApi.listSkills().then(Q=>{l(Q.filter(Z=>Z.name))}),(T=(I=window.agentApi).listMCPServers)==null||T.call(I).then(Q=>{f(Q??[])}).catch(()=>{}))},[]);const H=I=>b(T=>({...T,capabilities:{...T.capabilities,...I}})),V=I=>{const T=p.capabilities.enabledTools;if(T.length===0){const Q=Pn.map(Z=>Z.name).filter(Z=>Z!==I);H({enabledTools:Q})}else if(T.includes(I)){const Q=T.filter(Z=>Z!==I);H({enabledTools:Q})}else{const Q=[...T,I];Q.length===Pn.length?H({enabledTools:[]}):H({enabledTools:Q})}},_=I=>{const T=p.capabilities.enabledSkills;H({enabledSkills:T.includes(I)?T.filter(Q=>Q!==I):[...T,I]})},m=I=>{const T=p.capabilities.enabledMCPServers;H({enabledMCPServers:T.includes(I)?T.filter(Q=>Q!==I):[...T,I]})},j=()=>b(I=>({...I,contextPlaceholders:[...I.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),R=(I,T)=>b(Q=>{const Z=[...Q.contextPlaceholders];return Z[I]=T,{...Q,contextPlaceholders:Z}}),P=I=>b(T=>({...T,contextPlaceholders:T.contextPlaceholders.filter((Q,Z)=>Z!==I)})),A=async()=>{if(!p.name.trim()){w("名称为必填项");return}D(!0);try{await n(p)}catch(I){w(I instanceof Error?I.message:"保存失败")}finally{D(!1)}},C=I=>p.capabilities.enabledTools.length===0||p.capabilities.enabledTools.includes(I),L={fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:10,marginTop:22,paddingBottom:5,borderBottom:"1px solid var(--border-subtle)"};return e.jsxs("div",{style:{padding:"24px 28px",background:"transparent",borderTop:"1px solid var(--border-subtle)"},children:[h&&e.jsx("div",{style:{marginBottom:12,padding:"8px 12px",borderRadius:7,background:"rgba(244,63,94,0.08)",border:"1px solid rgba(244,63,94,0.25)",color:"var(--danger)",fontSize:12},children:h}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:Rt,children:"名称 *"}),e.jsx("input",{style:Tt,value:p.name,onChange:I=>b(T=>({...T,name:I.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:Rt,children:"描述"}),e.jsx("input",{style:Tt,value:p.description,onChange:I=>b(T=>({...T,description:I.target.value})),placeholder:"一句话描述"})]})]}),e.jsxs("div",{style:{marginTop:14},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:5},children:[e.jsx("label",{style:{...Rt,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:p.systemPrompt,onChange:I=>b(T=>({...T,systemPrompt:I.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
145
+
146
+ 当前项目:{{project_name}}`,rows:6,style:{...Tt,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:L,children:"上下文占位符"}),p.contextPlaceholders.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6},children:["变量名","说明","默认值",""].map(I=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:I},I))}),p.contextPlaceholders.map((I,T)=>e.jsx(Bi,{ph:I,onChange:Q=>R(T,Q),onDelete:()=>P(T)},T))]}),e.jsx("button",{onClick:j,style:{...Sn,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:L,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:Rt,children:"模型"}),e.jsxs("select",{value:p.capabilities.profileId,onChange:I=>H({profileId:I.target.value}),style:{...Tt,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),o.map(I=>e.jsxs("option",{value:I.id,children:[I.name||I.modelId," (",I.provider,")"]},I.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Rt,children:["内置工具 ",p.capabilities.enabledTools.length===0?"(全部启用)":`(${p.capabilities.enabledTools.length}/${Pn.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Pn.map(I=>{const T=C(I.name);return e.jsx("button",{onClick:()=>V(I.name),style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.label},I.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),a.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Rt,children:["技能 ",p.capabilities.enabledSkills.length===0?"(全部)":`(${p.capabilities.enabledSkills.length}/${a.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(I=>{const T=p.capabilities.enabledSkills.length===0||p.capabilities.enabledSkills.includes(I.name);return e.jsx("button",{onClick:()=>_(I.name),title:I.description,style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.name},I.name)})})]}),u.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Rt,children:["MCP 服务器 ",p.capabilities.enabledMCPServers.length===0?"(全部)":`(${p.capabilities.enabledMCPServers.length}/${u.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:u.map(I=>{const T=p.capabilities.enabledMCPServers.length===0||p.capabilities.enabledMCPServers.includes(I.id);return e.jsx("button",{onClick:()=>m(I.id),style:{padding:"4px 10px",borderRadius:20,border:T?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:T?"var(--accent-dim)":"transparent",color:T?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.name},I.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:Rt,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:Tt,value:p.maxIterations,min:0,max:100,onChange:I=>b(T=>({...T,maxIterations:Number(I.target.value)}))})]}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",paddingBottom:2},children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:"var(--text-secondary)"},children:[e.jsx("input",{type:"checkbox",checked:p.isDefault,onChange:I=>b(T=>({...T,isDefault:I.target.checked})),style:{width:14,height:14,accentColor:"var(--accent)",cursor:"pointer"}}),"新会话默认使用此智能体"]})})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,disabled:S,style:{...gr,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:S?.6:1},children:S?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:gr,children:"取消"})]})]})}function Ni(){const[t,r]=c.useState([]),[n,s]=c.useState([]),[o,a]=c.useState(null),[l,u]=c.useState(!1),[f,p]=c.useState(null),[b,h]=c.useState("success"),w=(m,j="success")=>{p(m),h(j),setTimeout(()=>p(null),2e3)},S=async()=>{if(!window.agentApi)return;const m=await window.agentApi.listAgentDefs();r(m);const j=await window.agentApi.getSettings();s(j.activeAgentIds??[])};c.useEffect(()=>{S()},[]);const D=async m=>{await window.agentApi.createAgentDef(m),u(!1),w("智能体已创建"),await S()},H=async(m,j)=>{await window.agentApi.updateAgentDef(m,j),a(null),w("保存成功"),await S()},V=async m=>{await window.agentApi.deleteAgentDef(m),o===m&&a(null),w("已删除"),await S()},_=async m=>{const R=(await window.agentApi.setActiveAgentDef(m)).activeAgentIds??[];s(R),w(R.includes(m)?"已激活":"已取消激活")};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"智能体"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:28},children:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),f&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,border:b==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:b==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:b==="success"?"var(--success)":"var(--danger)",fontSize:13},children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{u(!0),a(null)},style:{...gr,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600},children:"+ 新建智能体"})}),l&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden",marginBottom:16},children:[e.jsx("div",{style:{padding:"10px 16px",background:"var(--bg-surface)",display:"flex",alignItems:"center",gap:8},children:e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)"},children:"新建智能体"})}),e.jsx(ns,{initial:{},activeAgentId:n[0]??"",onSave:D,onCancel:()=>u(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!l&&e.jsx("div",{style:{padding:"28px 20px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无智能体配置,点击「新建智能体」开始创建"}),t.map(m=>{const j=n.includes(m.id),R=m.id===o;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${j?"var(--accent)":"var(--border-default)"}`,background:j?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s, background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 16px"},children:[e.jsx("div",{style:{width:34,height:34,borderRadius:8,flexShrink:0,background:j?"var(--accent)":"var(--bg-deep)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:j?"#fff":"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:m.name}),j&&e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"rgba(79,110,247,0.12)",padding:"1px 6px",borderRadius:4,letterSpacing:"0.05em"},children:"激活"}),m.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),m.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[m.capabilities.profileId&&e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"rgba(79,110,247,0.08)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.15)"},children:"自定义模型"}),m.capabilities.enabledTools.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.capabilities.enabledTools.length," 工具"]}),m.capabilities.enabledSkills.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.capabilities.enabledSkills.length," 技能"]}),m.contextPlaceholders.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[m.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>_(m.id),style:{...Sn,color:j?"var(--accent)":"var(--text-muted)",borderColor:j?"var(--accent)":"var(--border-default)",background:j?"var(--accent-dim)":"transparent"},children:j?"取消激活":"激活"}),e.jsx("button",{onClick:()=>a(R?null:m.id),style:Sn,children:R?"收起":"编辑"}),e.jsx("button",{onClick:()=>V(m.id),style:{...Sn,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),R&&e.jsx(ns,{initial:m,activeAgentId:n[0]??"",onSave:P=>H(m.id,P),onCancel:()=>a(null)})]},m.id)})]})]})}const Pi=[{label:"TypeScript / JavaScript",language:"typescript",fileTypes:".ts,.tsx,.js,.jsx",command:"typescript-language-server",args:"--stdio"},{label:"Python (pylsp)",language:"python",fileTypes:".py",command:"pylsp",args:""},{label:"Python (pyright)",language:"python",fileTypes:".py",command:"pyright-langserver",args:"--stdio"},{label:"Rust (rust-analyzer)",language:"rust",fileTypes:".rs",command:"rust-analyzer",args:""},{label:"Go (gopls)",language:"go",fileTypes:".go",command:"gopls",args:""},{label:"C/C++ (clangd)",language:"cpp",fileTypes:".c,.cpp,.cc,.h,.hpp",command:"clangd",args:""},{label:"Java (jdtls via brew)",language:"java",fileTypes:".java",command:"jdtls",args:"--data /tmp/jdtls-workspace"}],lr={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function Di(){const[t,r]=c.useState([]),[n,s]=c.useState(lr),[o,a]=c.useState(!1),[l,u]=c.useState(null),[f,p]=c.useState(null),b=async()=>{var m;if((m=window.agentApi)!=null&&m.lspList)try{const j=await window.agentApi.lspList();r(j)}catch(j){console.error("[LSP] load error",j)}};c.useEffect(()=>{b()},[]);const h=m=>{s(j=>({...j,name:m.label,language:m.language,fileTypes:m.fileTypes,command:m.command,args:m.args}))},w=m=>{u(m.id),s({id:m.id,name:m.name,language:m.language,fileTypes:m.fileTypes.join(","),command:m.command,args:m.args.join(" "),envRaw:m.env?Object.entries(m.env).map(([j,R])=>`${j}=${R}`).join(`
147
+ `):""}),p(null)},S=()=>{u(null),s(lr)},D=async()=>{var A;if(!((A=window.agentApi)!=null&&A.lspSave))return;const m=n.name.trim(),j=n.command.trim();if(!m||!j)return;let R;if(n.envRaw.trim()){R={};for(const C of n.envRaw.split(`
148
+ `)){const L=C.indexOf("=");L>0&&(R[C.slice(0,L).trim()]=C.slice(L+1).trim())}}const P={id:l??crypto.randomUUID(),name:m,language:n.language.trim(),fileTypes:n.fileTypes.split(",").map(C=>C.trim()).filter(Boolean),command:j,args:n.args.trim()?n.args.trim().split(/\s+/):[],env:R,enabled:!0};a(!0);try{await window.agentApi.lspSave(P),await b(),S()}finally{a(!1)}},H=async m=>{var j;(j=window.agentApi)!=null&&j.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(m),await b())},V=async m=>{var j;(j=window.agentApi)!=null&&j.lspSetEnabled&&(await window.agentApi.lspSetEnabled(m.id,!m.enabled),await b())},_=l!==null;return _&&l===null||!l&&n.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!_&&e.jsx("button",{onClick:()=>{u(""),s(lr)},style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",flexShrink:0},children:"+ 添加服务器"})]}),t.length===0&&!_&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:"尚未配置任何 LSP 服务器"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:_?24:0},children:t.map(m=>e.jsxs("div",{style:{background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",cursor:"pointer"},onClick:()=>p(f===m.id?null:m.id),children:[e.jsx("div",{onClick:j=>{j.stopPropagation(),V(m)},style:{width:32,height:18,borderRadius:9,background:m.enabled?"var(--success, #34d399)":"var(--border-default)",position:"relative",cursor:"pointer",flexShrink:0,transition:"background 0.2s"},children:e.jsx("div",{style:{position:"absolute",top:2,left:m.enabled?16:2,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:500,fontSize:13,color:"var(--text-primary)"},children:m.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[m.language,m.fileTypes.length>0?` · ${m.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[m.command,m.args.length?" "+m.args.join(" "):""]}),e.jsx("button",{onClick:j=>{j.stopPropagation(),w(m)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"编辑"}),e.jsx("button",{onClick:j=>{j.stopPropagation(),H(m.id)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--danger, #f43f5e)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"删除"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{flexShrink:0,transition:"transform 0.2s",transform:f===m.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),f===m.id&&e.jsxs("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-muted)",borderTop:"1px solid var(--border-subtle)",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"命令:"}),e.jsxs("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:[m.command," ",m.args.join(" ")]})]}),m.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),m.fileTypes.join(", ")]}),m.env&&Object.keys(m.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(m.env).map(([j,R])=>`${j}=${R}`).join(", ")]})]})]},m.id))}),_&&e.jsxs("div",{style:{padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:l?"编辑 LSP 服务器":"添加 LSP 服务器"}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:_t,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Pi.map(m=>e.jsx("button",{onClick:()=>h(m),style:{background:"var(--bg-deep)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:"pointer",color:"var(--text-secondary)",fontFamily:"var(--font-body)"},children:m.label},m.label))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.name,onChange:m=>s(j=>({...j,name:m.target.value})),placeholder:"TypeScript Language Server",style:Zt})]}),e.jsxs("div",{children:[e.jsx("label",{style:_t,children:"语言"}),e.jsx("input",{value:n.language,onChange:m=>s(j=>({...j,language:m.target.value})),placeholder:"typescript",style:Zt})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:n.fileTypes,onChange:m=>s(j=>({...j,fileTypes:m.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:Zt})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.command,onChange:m=>s(j=>({...j,command:m.target.value})),placeholder:"typescript-language-server",style:{...Zt,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:n.args,onChange:m=>s(j=>({...j,args:m.target.value})),placeholder:"--stdio",style:{...Zt,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:_t,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:n.envRaw,onChange:m=>s(j=>({...j,envRaw:m.target.value})),placeholder:`NODE_ENV=production
149
+ TSPROTOCOL_LOG=verbose`,rows:3,style:{...Zt,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),n.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void D(),disabled:o||!n.name.trim()||!n.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:o||!n.name.trim()||!n.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:o?"保存中…":"保存"}),e.jsx("button",{onClick:S,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"})]})]})]})}const Zt={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},_t={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function _i({trigger:t,heardText:r}){const[n,s]=c.useState(!1);return c.useEffect(()=>{if(t<=0)return;s(!0);const o=setTimeout(()=>s(!1),2400);return()=>clearTimeout(o)},[t]),n?zt.createPortal(e.jsxs("div",{style:{position:"fixed",inset:0,zIndex:3e4,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:22,background:"radial-gradient(circle at 50% 50%, var(--accent-glow), transparent 60%)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",animation:"fadeIn 0.3s var(--ease-out)",pointerEvents:"none",WebkitAppRegion:"no-drag"},children:[e.jsxs("div",{style:{position:"relative",width:120,height:120},children:[[0,.45,.9].map(o=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${o}s var(--ease-out) infinite`}},o)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),r&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",r.slice(0,40),"”"]})]},t),document.body):null}const Fi=[{agentType:"customer-agent",mark:"CA",label:"Customer Agent"},{agentType:"codex",mark:"CX",label:"Codex"},{agentType:"claude-code",mark:"CC",label:"Claude Code"}],dr=220,rs=138;function $i({health:t,disabled:r,onSelect:n}){const[s,o]=c.useState(!1),[a,l]=c.useState(null),u=c.useRef(null),f=c.useRef(null);return c.useEffect(()=>{if(!s)return;const p=b=>{var w,S;const h=b.target;(w=u.current)!=null&&w.contains(h)||(S=f.current)!=null&&S.contains(h)||o(!1)};return window.addEventListener("pointerdown",p),()=>window.removeEventListener("pointerdown",p)},[s]),e.jsxs("div",{style:{position:"relative",flexShrink:0},children:[e.jsx("button",{ref:u,type:"button",onClick:p=>{var h;p.stopPropagation();const b=(h=u.current)==null?void 0:h.getBoundingClientRect();if(b){const w=Math.min(Math.max(b.right-dr,8),Math.max(8,window.innerWidth-dr-8));let S=b.bottom+4;S+rs>window.innerHeight-8&&(S=Math.max(8,b.top-rs-4)),l({top:S,left:w})}o(w=>!w)},disabled:r,title:"新建会话","aria-label":"新建会话","aria-expanded":s,className:"sidebar-row-action sidebar-row-action--accent sidebar-project-add-action ui-icon-button ui-icon-button--small",style:{fontSize:16,lineHeight:1},children:"+"}),s&&a&&zt.createPortal(e.jsx("div",{ref:f,role:"menu",style:{position:"fixed",top:a.top,left:a.left,zIndex:10020,width:dr,padding:5,border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-surface)",boxShadow:"var(--shadow-md)"},children:Fi.map(p=>{const b=t.find(w=>w.agentType===p.agentType),h=(b==null?void 0:b.available)??p.agentType==="customer-agent";return e.jsxs("button",{type:"button",role:"menuitem",disabled:!h,title:h?`使用 ${p.label}`:(b==null?void 0:b.error)||`${p.label} 不可用`,onClick:()=>{o(!1),n(p.agentType)},style:{width:"100%",minHeight:36,display:"flex",alignItems:"center",gap:9,padding:"6px 8px",border:0,borderRadius:5,background:"transparent",color:h?"var(--text-secondary)":"var(--text-muted)",cursor:h?"pointer":"not-allowed",opacity:h?1:.5,textAlign:"left"},children:[e.jsx("span",{style:{width:25,height:19,display:"grid",placeItems:"center",borderRadius:4,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)",color:"var(--text-muted)",fontSize:9,fontWeight:700},children:p.mark}),e.jsx("span",{style:{flex:1,fontSize:12},children:p.label}),e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:h?"var(--success)":"var(--danger)"}})]},p.agentType)})}),document.body)]})}const Ui=[["style",new Set(["css","scss","sass","less","styl"])],["image",new Set(["png","jpg","jpeg","gif","webp","avif","bmp","ico","svg","tif","tiff"])],["video",new Set(["mp4","mov","m4v","webm","mkv","avi","wmv","flv","mpeg","mpg"])],["audio",new Set(["mp3","wav","m4a","aac","ogg","flac","opus"])],["markdown",new Set(["md","mdx","markdown"])],["json",new Set(["json","jsonc","geojson"])],["archive",new Set(["zip","tar","gz","tgz","bz2","xz","7z","rar"])],["spreadsheet",new Set(["csv","tsv","xls","xlsx","ods"])],["presentation",new Set(["ppt","pptx","key","odp"])],["database",new Set(["db","sqlite","sqlite3"])],["text",new Set(["txt","log","rtf","ini","cfg","conf","env","yaml","yml","toml","xml","pdf","doc","docx","odt"])],["code",new Set(["js","jsx","mjs","cjs","ts","tsx","vue","svelte","java","kt","kts","py","rb","go","rs","php","c","cc","cpp","h","hpp","cs","swift","scala","sh","bash","zsh","fish","sql","html"])]],Oi=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function Hi(t){var o;const r=t.toLocaleLowerCase(),n=Oi.get(r);if(n)return n;if(r.startsWith(".env")||r===".gitignore"||r===".npmrc")return"text";const s=r.includes(".")&&r.split(".").pop()||"";return((o=Ui.find(([,a])=>a.has(s)))==null?void 0:o[0])??"file"}const Vi={folder:{icon:po,label:"文件夹"},code:{icon:oo,label:"代码文件"},style:{icon:ho,label:"样式文件"},image:{icon:io,label:"图片文件"},video:{icon:co,label:"视频文件"},audio:{icon:so,label:"音频文件"},markdown:{icon:go,label:"Markdown 文件"},text:{icon:us,label:"文本文件"},json:{icon:ao,label:"JSON 文件"},archive:{icon:ro,label:"压缩文件"},spreadsheet:{icon:lo,label:"表格文件"},presentation:{icon:fo,label:"演示文件"},database:{icon:no,label:"数据库文件"},file:{icon:uo,label:"文件"}};function qi(t,r){return r==="directory"?"folder":Hi(t)}const ss=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function Ki(t,r){const n=ss(t),s=ss(r),a=[{label:n==="/"?"/":n.split("/").filter(Boolean).pop()||n,path:n}];if(s===n)return a;const l=s.slice(n==="/"?1:n.length+1);let u=n;for(const f of l.split("/").filter(Boolean))u=u==="/"?`/${f}`:`${u}/${f}`,a.push({label:f,path:u});return a}function Gi({open:t,onCancel:r,onConfirm:n}){const[s,o]=c.useState([]),[a,l]=c.useState(""),[u,f]=c.useState(""),[p,b]=c.useState([]),[h,w]=c.useState(!1),[S,D]=c.useState(""),[H,V]=c.useState(!1),_=c.useMemo(()=>Ki(a||"/",u||a||"/"),[a,u]),m=async A=>{if(window.agentApi){w(!0),D("");try{const C=await window.agentApi.listProjectDirectories(A);b(C),f(A)}catch(C){D(C instanceof Error?C.message:"无法读取目录")}finally{w(!1)}}};if(c.useEffect(()=>{if(!t||!window.agentApi)return;let A=!1;return w(!0),D(""),window.agentApi.listProjectRoots().then(async C=>{if(A)return;o(C);const L=C[0]??"";l(L),L?await m(L):D("未配置可用的宿主机目录")}).catch(C=>{A||D(C instanceof Error?C.message:"无法读取宿主机目录")}).finally(()=>{A||w(!1)}),()=>{A=!0}},[t]),c.useEffect(()=>{if(!t)return;const A=C=>{C.key==="Escape"&&r()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,r]),!t)return null;const j=A=>{l(A),m(A)},R=()=>{_.length<=1||m(_[_.length-2].path)},P=async()=>{if(!(!u||H)){V(!0),D("");try{await n(u)}catch(A){D(A instanceof Error?A.message:"项目导入失败")}finally{V(!1)}}};return zt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:A=>{A.target===A.currentTarget&&r()},children:e.jsxs("section",{className:"host-project-picker",role:"dialog","aria-modal":"true","aria-labelledby":"host-project-picker-title",children:[e.jsxs("header",{className:"host-project-picker-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"host-project-picker-title",children:"选择宿主机项目"}),e.jsx("p",{children:"文件将直接在运行 AgentRoam 的机器上读写"})]}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(mo,{size:16,"aria-hidden":"true"})})]}),s.length>1&&e.jsxs("label",{className:"host-project-picker-root",children:[e.jsx("span",{children:"根目录"}),e.jsx("select",{value:a,onChange:A=>j(A.target.value),children:s.map(A=>e.jsx("option",{value:A,children:A},A))})]}),e.jsxs("nav",{className:"host-project-picker-nav","aria-label":"当前目录",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:R,disabled:_.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(eo,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:_.map((A,C)=>e.jsxs("span",{children:[C>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void m(A.path),children:A.label})]},A.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>u&&void m(u),disabled:!u||h,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(xo,{size:15,"aria-hidden":"true"})})]}),a==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":h,children:h?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):S?e.jsx("div",{className:"host-project-picker-state is-error",children:S}):p.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):p.map(A=>{const C=qi(A.name,A.kind),{icon:L,label:I}=Vi[C],T=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${C}`,"aria-hidden":"true",children:e.jsx(L,{size:18,strokeWidth:1.8})}),e.jsx("span",{className:"host-project-picker-name",children:A.name})]});return A.kind==="file"?e.jsx("div",{className:"host-project-picker-row is-file",title:I,children:T},`${A.name}:${A.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void m(A.path),title:I,children:[T,A.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(to,{size:16})})]},`${A.name}:${A.path}`)})}),e.jsxs("footer",{className:"host-project-picker-footer",children:[e.jsx("code",{title:u,children:u}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:r,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!u||h||H,onClick:()=>void P(),children:H?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const os={"customer-agent":"CA",codex:"CX","claude-code":"CC"},is={"claude-code":"Claude Code",codex:"Codex","customer-agent":"Customer Agent"},as=["customer-agent","claude-code","codex"],vr="agentroam.session-index.v1";function yr(){try{const t=JSON.parse(localStorage.getItem(vr)??"{}");return!t||typeof t!="object"||Array.isArray(t)?{}:Object.fromEntries(Object.entries(t).filter(([,r])=>Array.isArray(r)))}catch{return{}}}function Qi(t,r){try{localStorage.setItem(vr,JSON.stringify({...yr(),[t]:r}))}catch{}}function Ji(t){try{const r=yr(),n=Object.fromEntries(Object.entries(r).filter(([s])=>t.has(s)));localStorage.setItem(vr,JSON.stringify(n))}catch{}}function Xi(t){var s;const r={},n={};for(const[o,a]of Object.entries(t)){r[o]=br(a.filter(l=>!l.parentSessionId));for(const l of a.filter(u=>u.parentSessionId))(n[s=l.parentSessionId]??(n[s]=[])).push(l)}for(const o of Object.values(n))o.sort((a,l)=>a.created.localeCompare(l.created));return{roots:r,children:n,projectIds:new Set(Object.keys(t))}}function cr(){return e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M8 6V4h8v2"}),e.jsx("path",{d:"M19 6l-1 14H6L5 6"}),e.jsx("path",{d:"M10 11v5M14 11v5"})]})}function ea(){const[t]=c.useState(()=>Xi(yr())),[r,n]=c.useState([]),[s,o]=c.useState(!1),[a,l]=c.useState(t.roots),[u,f]=c.useState([]),[p,b]=c.useState(""),[h,w]=c.useState(!1),[S,D]=c.useState(10),[H,V]=c.useState([]),[_,m]=c.useState(t.children),[j,R]=c.useState(t.projectIds),[P,A]=c.useState(new Set),[C,L]=c.useState({}),I=c.useRef(new Map),[T,Q]=c.useState(null),[Z,pe]=c.useState(null),[Y,Se]=c.useState(new Set),[we,nt]=c.useState(new Set),[Ut,rt]=c.useState(new Set),[Xe,Ot]=c.useState(new Set),[Ht,st]=c.useState(!1),[y,$]=c.useState("settings"),le=xe(d=>d.setTodos),ee=ke(d=>d.skin),X=ke(d=>d.layout),te=ke(d=>d.wakeEnabled),Ce=ke(d=>d.wakeWord),ge=ke(d=>d.setSkin),ot=ke(d=>d.setLayout),In=ke(d=>d.setWakeEnabled),Vt=ke(d=>d.setWakeWord),pt=ke(d=>d.autoSpeak),Ye=ke(d=>d.setAutoSpeak),gt=ke(d=>d.runningFirst),Un=ke(d=>d.setRunningFirst),Pe=ke(d=>d.groupByBot),rn=ke(d=>d.setGroupByBot),sn=xe(d=>d.runningSessionId),on=xe(Js(d=>Object.entries(d.messagesBySession).filter(([,k])=>k.some(z=>z.askUser&&!z.askUser.answered)).map(([k])=>k))),ht=c.useCallback(d=>d.status==="running"||sn===d.id,[sn]),an=c.useCallback(()=>{const d=[];for(const k of r){const z=a[k.id]??[];for(const U of as)z.some(M=>M.agentType===U)&&d.push(`${k.id}::${U}`)}return d},[r,a]),ze=()=>{nt(new Set),rt(new Set(an())),Se(new Set(Object.keys(_)))},An=()=>{const d=r.filter(k=>!Xe.has(k.id)).map(k=>k.id);nt(new Set(d)),rt(new Set),Se(new Set);for(const k of d){if(Ge.current.has(k))continue;const z=it.current.has(k);Le(k,{refresh:z,background:z})}},ft=ds(),Rn=Vs(),De=ft&&Rn,[Mt,Ve]=c.useState(!1),[re,be]=c.useState(!1),[Lt,Tn]=c.useState(null),[qt,Ie]=c.useState(0),[Ae,ln]=c.useState(void 0),_e=c.useRef(null),Fe=c.useRef(!1),[dn,Wt]=c.useState(null),qe=c.useRef(null),Ke=c.useRef(!1),xt=c.useRef(r);xt.current=r;const cn=c.useRef(Xe);cn.current=Xe;const it=c.useRef(j);it.current=j;const Ge=c.useRef(P);Ge.current=P,c.useEffect(()=>{document.documentElement.setAttribute("data-skin",ee)},[ee]),c.useEffect(()=>{document.body.classList.toggle("layout-compact",X==="compact")},[X]);const mt=c.useCallback(()=>{if(!window.agentApi||!te||Fe.current||_e.current)return;const d=()=>{yo()&&!_e.current&&(_e.current=jo({wakeWord:Ce,onWake:k=>{var z;ln(k),Ie(U=>U+1),(z=window.agentApi)==null||z.showWindow()},onError:k=>console.warn("[wake]",k)}))};typeof window.agentApi.wakeStart=="function"?(Fe.current=!0,window.agentApi.wakeStart(Ce).then(k=>{k.ok||(Fe.current=!1,d())}).catch(()=>{Fe.current=!1,d()})):d()},[te,Ce]);c.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWake)return window.agentApi.onWake(k=>{Fe.current=!1,ln(k),Ie(z=>z+1)})},[]),c.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWakeCommand)return window.agentApi.onWakeCommand(k=>{var q;const z=((k==null?void 0:k.text)||"").trim();if(!z)return;const U=qe.current&&Date.now()<qe.current.until?qe.current:null;if(U){U.until=Date.now()+9e4,pe(U.sessionId),(q=window.agentApi)==null||q.wakeConversation(!0),Wt({text:z,projectId:null,sessionId:U.sessionId,nonce:Date.now()}),he(`语音追问:${z.length>40?z.slice(0,40)+"…":z}`),Re("success"),setTimeout(()=>he(null),4e3);return}const M=xt.current.find(se=>se.name&&z.includes(se.name)&&!cn.current.has(se.id));M&&(Q(M.id),nt(se=>{const Te=new Set(se);return Te.add(M.id),Te})),pe(null),Ke.current=!0,Ye(!0),Wt({text:z,projectId:(M==null?void 0:M.id)??null,nonce:Date.now()}),he(`语音指令:${z.length>40?z.slice(0,40)+"…":z}${M?`(项目:${M.name})`:""}`),Re("success"),setTimeout(()=>he(null),4e3)})},[]);const un=c.useCallback(async()=>{window.agentApi&&(mt(),await window.agentApi.hideWindow())},[mt]),de=c.useCallback(d=>{st(!1),Tn({right:d.right,bottom:d.bottom}),be(k=>!k)},[]),zn=c.useCallback(()=>{be(!1),st(d=>!d)},[]);c.useEffect(()=>{if(!re)return;const d=()=>{const z=document.querySelector(".chat-header-action--appearance");if(!z)return;const U=z.getBoundingClientRect();Tn(M=>(M==null?void 0:M.right)===U.right&&M.bottom===U.bottom?M:{right:U.right,bottom:U.bottom})},k=window.requestAnimationFrame(d);return window.addEventListener("resize",d),()=>{window.cancelAnimationFrame(k),window.removeEventListener("resize",d)}},[X,re]),c.useEffect(()=>{window.agentApi&&mt()},[mt]),c.useEffect(()=>{const d=()=>{var k;(k=_e.current)==null||k.stop(),_e.current=null};return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[]),c.useEffect(()=>{var d,k;te||((d=_e.current)==null||d.stop(),_e.current=null,Fe.current=!1,(k=window.agentApi)==null||k.wakeStop())},[te]),c.useEffect(()=>{!te||!window.agentApi||Fe.current&&window.agentApi.wakeStart(Ce)},[Ce]),c.useEffect(()=>()=>{var d;(d=_e.current)==null||d.stop()},[]);const at=Object.values(a).flat(),Kt=[...at,...u],Qe=p.trim().toLowerCase(),$e=Qe?at.filter(d=>d.title.toLowerCase().includes(Qe)||(d.cwd||"").toLowerCase().includes(Qe)):null,Me=Z?Kt.find(d=>d.id===Z):void 0,bt=Me==null?void 0:Me.title,Gt=r.filter(d=>!Xe.has(d.id)).map(d=>d.id),Ue=Gt.length>0&&Gt.every(d=>!we.has(d)),[Ze,et]=c.useState(300),[Et,Bt]=c.useState(!1),lt=c.useRef(!1),vt=c.useRef(0),Qt=c.useRef(0),yt=c.useCallback(d=>{if(!lt.current)return;const k=Math.min(480,Math.max(160,Qt.current+d.clientX-vt.current));et(k)},[]),wt=c.useCallback(()=>{lt.current=!1,Bt(!1),document.removeEventListener("mousemove",yt),document.removeEventListener("mouseup",wt)},[yt]),pn=c.useCallback(d=>{lt.current=!0,Bt(!0),vt.current=d.clientX,Qt.current=Ze,document.addEventListener("mousemove",yt),document.addEventListener("mouseup",wt)},[Ze,yt,wt]),[jt,he]=c.useState(null),[Jt,Re]=c.useState("success"),[Nt,gn]=c.useState([]),kt=c.useCallback(d=>{gn(k=>k.filter(z=>z.id!==d))},[]),hn=c.useCallback(d=>{const k=crypto.randomUUID();gn(z=>[...z,{...d,id:k}]),setTimeout(()=>kt(k),12e3)},[kt]);async function St(){if(!window.agentApi)return;const d=await window.agentApi.listProjects();n(d);const k=new Set(d.map(M=>M.id)),z=new Set([...it.current].filter(M=>k.has(M)));Ji(k),l(M=>Object.fromEntries(Object.entries(M).filter(([q])=>k.has(q)))),R(M=>{const q=new Set([...M].filter(se=>k.has(se)));return it.current=q,q}),A(M=>{const q=new Set([...M].filter(se=>k.has(se)));return Ge.current=q,q}),L(M=>Object.fromEntries(Object.entries(M).filter(([q])=>k.has(q))));const U=new Set;await Promise.all(d.map(async M=>{M.description&&!await window.agentApi.checkProjectPath(M.description)&&U.add(M.id)})),Ot(U);for(const M of z)U.has(M)||Ge.current.has(M)||Le(M,{refresh:!0,background:!0})}async function Le(d,k={}){var U;if(!window.agentApi)return;const z=(I.current.get(d)??0)+1;I.current.set(d,z),A(M=>{const q=new Set(M).add(d);return Ge.current=q,q}),L(M=>{if(!(d in M))return M;const q={...M};return delete q[d],q});try{const M=k.refresh?await window.agentApi.refreshSessions(d):await window.agentApi.listSessions(d);if(I.current.get(d)!==z)return;const q=new Set((a[d]??[]).map(K=>K.id)),se=br(M.filter(K=>!K.parentSessionId)),Te=(a[d]??[]).find(K=>K.id===Z&&K.agentType!=="customer-agent"&&!se.some(ue=>ue.id===K.id));Te&&se.unshift(Te);const Oe={};for(const K of M.filter(ue=>ue.parentSessionId))(Oe[U=K.parentSessionId]??(Oe[U]=[])).push(K);for(const K of Object.values(Oe))K.sort((ue,J)=>ue.created.localeCompare(J.created));Qi(d,[...se,...Object.values(Oe).flat()]),l(K=>({...K,[d]:se})),m(K=>{const ue={...K};for(const J of q)delete ue[J];for(const[J,ve]of Object.entries(Oe))ue[J]=ve;return ue}),R(K=>{const ue=new Set(K).add(d);return it.current=ue,ue})}catch(M){if(I.current.get(d)!==z)return;L(q=>({...q,[d]:M instanceof Error?M.message:"会话加载失败"}))}finally{I.current.get(d)===z&&A(M=>{const q=new Set(M);return q.delete(d),Ge.current=q,q})}}const Xt=async d=>{if(!window.agentApi)return;const k=await window.agentApi.listChildSessions(d);m(z=>({...z,[d]:k.sort((U,M)=>U.created<M.created?-1:1)}))},fn=async(d,k)=>{if(!window.agentApi)return;const z=await window.agentApi.createSession("新会话",d,k);if(k==="customer-agent"){await Le(d),Q(d),pe(z.id),De&&Ve(!1);return}const U=z.projectId===d?z:{...z,projectId:d};l(M=>({...M,[d]:[U,...(M[d]??[]).filter(q=>q.id!==z.id)]})),f(M=>M.filter(q=>q.id!==z.id)),Q(d),pe(z.id),De&&Ve(!1)};c.useEffect(()=>{window.agentApi&&(St(),Fn.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(V).catch(()=>{}))},[]),c.useEffect(()=>{if(!T||!Z||(Me==null?void 0:Me.agentType)==="customer-agent"||!window.agentApi)return;let d=!1;const k=async()=>{document.visibilityState==="visible"&&(d||await Le(T,{refresh:!0,background:!0}))},z=window.setInterval(()=>void k(),1e4);return()=>{d=!0,window.clearInterval(z)}},[T,Z,Me==null?void 0:Me.agentType]),c.useEffect(()=>{if(!T||!window.agentApi)return;const d=r.find(z=>z.id===T),k=d==null?void 0:d.description;k&&window.agentApi.setProjectWorkingDir(k)},[T,r]);const tt=d=>{const k=!we.has(d);if(nt(z=>{const U=new Set(z);return k?U.add(d):U.delete(d),U}),T!==d&&(Q(d),pe(null)),k&&!Ge.current.has(d)){const z=it.current.has(d);Le(d,{refresh:z,background:z})}},xn=async d=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const k=d.replace(/\\/g,"/"),z=k.split("/").filter(Boolean),U=z[z.length-1]||k||"导入的项目",M=await window.agentApi.createProject(U,k);await St(),Q(M.id),pe(null),await Le(M.id),nt(q=>{const se=new Set(q);return se.add(M.id),se}),he(`已导入:${U}`),Re("success"),setTimeout(()=>he(null),3e3)},On=async()=>{try{if(!window.agentApi){he("agentApi 未就绪,请重启应用"),Re("error");return}if(ft){o(!0);return}const d=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",d),!d)return;await xn(d)}catch(d){console.error("[import] error:",d),he(d instanceof Error?d.message:String(d)),Re("error"),setTimeout(()=>he(null),5e3)}},Mn=async d=>{if(window.agentApi)try{await window.agentApi.deleteProject(d),T===d&&(Q(null),pe(null),le([])),he("项目删除成功"),Re("success"),setTimeout(()=>he(null),2500),await St()}catch(k){he(k instanceof Error?k.message:"项目删除失败"),Re("error"),setTimeout(()=>he(null),4e3)}},mn=async d=>{if(window.agentApi)try{await window.agentApi.deleteSession(d),Z===d&&(pe(null),le([])),he("会话删除成功"),Re("success"),setTimeout(()=>he(null),2500),T&&await Le(T)}catch(k){he(k instanceof Error?k.message:"会话删除失败"),Re("error"),setTimeout(()=>he(null),4e3)}},Ln=[{id:"settings",label:"设置"},{id:"mcp",label:"MCP"},{id:"memory",label:"记忆"},{id:"skill",label:"技能"},{id:"agent",label:"智能体"},{id:"lsp",label:"LSP"}];return e.jsxs("div",{className:"app-shell",style:{display:"flex",height:ft?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[De&&Mt&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>Ve(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),De&&!Mt&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>Ve(!0),"aria-label":"会话列表","aria-expanded":!1,style:{position:"fixed",top:"calc(env(safe-area-inset-top) + 8px)",left:10,zIndex:1250,width:34,height:34,borderRadius:9,border:"1px solid var(--border-default)",background:"var(--bg-glass, rgba(18,20,28,.82))",color:"var(--text-secondary)",display:"grid",placeItems:"center",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag",cursor:"pointer"},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})})}),e.jsx("div",{className:"app-drag-region",style:{position:"fixed",top:0,left:0,right:0,height:52,zIndex:9999,WebkitAppRegion:"drag",pointerEvents:"none"}}),e.jsx("div",{className:"app-accent-glow",style:{position:"absolute",top:"-120px",left:"-80px",width:320,height:320,borderRadius:"50%",background:"radial-gradient(circle, var(--accent-glow) 0%, transparent 70%)",pointerEvents:"none",zIndex:0}}),X!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:Ze,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 20px",position:"relative",zIndex:10,overflow:"hidden",...De?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:Mt?"translateX(0)":"translateX(-103%)",transition:"transform .24s ease",boxShadow:"12px 0 32px rgba(0,0,0,.5)",padding:"calc(env(safe-area-inset-top) + 12px) 0 20px"}:{}},children:[e.jsx("div",{className:"app-sidebar-brand",style:{padding:"0 20px 10px"},children:e.jsxs("div",{className:"sidebar-brand-row",children:[e.jsx("div",{className:"sidebar-brand-mark","aria-hidden":"true",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15a4 4 0 0 1-4 4H8l-5 3V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4z"}),e.jsx("path",{d:"M7 9h10M7 13h7"})]})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsxs("div",{className:"sidebar-project-toolbar",children:[e.jsx("span",{className:"sidebar-project-title",children:"项目"}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:()=>{w(!0),D(10)},title:"搜索会话","aria-label":"搜索会话",className:"ui-icon-button",children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]})}),e.jsx("button",{type:"button",onClick:()=>rn(!Pe),title:"会话按 Agent 分组","aria-label":"会话按 Agent 分组","aria-pressed":Pe,className:`ui-icon-button${Pe?" is-active":""}`,children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9 6h11M9 12h11M9 18h11"}),e.jsx("path",{d:"M4 6h.01M4 12h.01M4 18h.01"})]})}),e.jsx("button",{type:"button",onClick:Ue?An:ze,title:Ue?"展开全部会话":"折叠全部会话","aria-label":Ue?"展开全部会话":"折叠全部会话",disabled:Gt.length===0,className:"ui-icon-button",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Ue?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m7 6 5 5 5-5"}),e.jsx("path",{d:"m7 13 5 5 5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m17 11-5-5-5 5"}),e.jsx("path",{d:"m17 18-5-5-5 5"})]})})}),e.jsx("button",{type:"button",onClick:()=>Un(!gt),title:gt?"按新建时间排序":"进行中会话优先","aria-label":gt?"按新建时间排序":"进行中会话优先","aria-pressed":gt,className:`ui-icon-button sidebar-session-sort${gt?" is-active":""}`,children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h10M3 12h7M3 18h4"}),e.jsx("path",{d:"m15 9 3-3 3 3M18 6v12"})]})}),e.jsx("button",{type:"button",onClick:()=>void On(),title:"导入项目","aria-label":"导入项目",className:"ui-icon-button",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]})]}),jt&&e.jsx("div",{style:{margin:"0 12px 10px",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:Jt==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:Jt==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:Jt==="success"?"var(--success)":"var(--danger)",fontSize:12},children:jt}),e.jsx("div",{className:"app-sidebar-scroll",style:{flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[r.map(d=>{const k=T===d.id&&!Z,z=we.has(d.id),U=j.has(d.id),M=P.has(d.id),q=C[d.id],se=a[d.id]??[],Te=gt?Ci(se,ht):se,Oe=Te.length>10,K=Xe.has(d.id);return e.jsxs("div",{className:"sidebar-project-block","aria-busy":M,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${k&&!K?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:K?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{K||tt(d.id)},disabled:K,"aria-expanded":z,title:K?`路径不存在:${d.description}`:d.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:K?"var(--text-muted)":k?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:k&&!K?600:400,cursor:K?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[K?e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:k?1:.5},children:z?e.jsx("path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6A2 2 0 0 1 18.46 20H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}):e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),Te.length>0&&Pe&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:k&&!K?"var(--accent)":"var(--text-muted)",background:k&&!K?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"15px",opacity:.8},children:Te.length})]}),!ft&&e.jsx("button",{onClick:ue=>{ue.stopPropagation(),Mn(d.id)},title:"删除项目","aria-label":`删除项目:${d.name}`,className:"sidebar-project-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{flexShrink:0},children:e.jsx(cr,{})}),e.jsx($i,{health:H,disabled:K,onSelect:ue=>fn(d.id,ue)})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:z?Oe?300:800:0,opacity:z?1:0,transition:"max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease"},children:e.jsxs("div",{className:`sidebar-project-sessions${Pe?" is-grouped":""}`,style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...Oe?{maxHeight:280,overflowY:"auto"}:{}},children:[(()=>{const ue=J=>{const ve=Z===J.id,We=ht(J),Ee=ki({status:J.status,isRunning:We,needsInput:We&&on.includes(J.id)}),Be=_[J.id]??[];return e.jsxs("div",{children:[e.jsxs("div",{className:`sidebar-row sidebar-session-row ${ve?"sidebar-row-active":""}`,style:{paddingRight:4},children:[e.jsxs("button",{className:"sidebar-session-button",onClick:()=>{De&&Ve(!1),Q(d.id),pe(J.id),Be.length>0&&Se(je=>{const dt=new Set(je);return dt.has(J.id)?dt.delete(J.id):dt.add(J.id),dt})},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"6px 10px",border:"none",background:"transparent",color:ve?"var(--accent)":"var(--text-secondary)",fontSize:12,cursor:"pointer",textAlign:"left",transition:"color 0.15s"},children:[e.jsx("span",{className:`sidebar-status-dot is-${Ee}`,title:Si[Ee]}),e.jsx("span",{title:J.sourceLabel,style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:J.title}),J.occupancy==="owned-externally"&&e.jsx("span",{className:"sidebar-occupancy-badge",title:"原客户端正在使用,只读",children:"占用"}),Be.length>0&&Pe&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:ve?"var(--accent)":"var(--text-muted)",background:ve?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"16px",opacity:.8},children:Be.length}),Be.length>0&&e.jsx("svg",{className:`sidebar-session-disclosure${Y.has(J.id)?"":" is-expanded"}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]}),J.canDelete&&e.jsx("button",{onClick:()=>void mn(J.id),title:"删除会话","aria-label":`删除会话:${J.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(cr,{})}),!Pe&&e.jsx("span",{className:`sidebar-runtime-mark sidebar-runtime-mark--${J.agentType}`,children:os[J.agentType]})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:Y.has(J.id)?0:Be.length*40,opacity:Y.has(J.id)?0:1,transition:"max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease"},children:Be.map(je=>{const dt=Z===je.id;return e.jsxs("div",{className:`sidebar-row ${dt?"sidebar-row-active":""}`,style:{paddingRight:4,marginLeft:14,borderLeft:"1px solid var(--border-subtle)"},children:[e.jsxs("button",{className:"sidebar-session-button",onClick:()=>{Q(d.id),pe(je.id)},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"5px 8px",border:"none",background:"transparent",color:dt?"var(--accent)":"var(--text-muted)",fontSize:11,cursor:"pointer",textAlign:"left",transition:"color 0.15s"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:je.title})]}),e.jsx("button",{onClick:()=>void mn(je.id),title:"删除子会话","aria-label":`删除子会话:${je.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(cr,{})})]},je.id)})})]},J.id)};return Pe?as.map(J=>[J,Te.filter(ve=>ve.agentType===J)]).filter(([,J])=>J.length>0).map(([J,ve])=>{const We=`${d.id}::${J}`,Ee=!Ut.has(We);return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:"sidebar-agent-group",onClick:()=>rt(Be=>{const je=new Set(Be);return je.has(We)?je.delete(We):je.add(We),je}),"aria-expanded":Ee,title:is[J],style:{width:"100%",display:"flex",alignItems:"center",gap:7,padding:"5px 10px 2px 12px",border:0,background:"transparent",color:"var(--text-muted)",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",cursor:"pointer",textAlign:"left"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,transform:Ee?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.2s ease"},"aria-hidden":"true",children:e.jsx("path",{d:"M6 9l6 6 6-6"})}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:is[J]}),e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,background:"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"15px",opacity:.8},children:ve.length})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:Ee?ve.length*44+8:0,opacity:Ee?1:0,transition:"max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease"},children:ve.map(ue)})]},J)}):Te.map(ue)})(),M&&!U&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),q&&e.jsxs("div",{title:q,style:{display:"flex",alignItems:"center",gap:8,color:"var(--danger)",fontSize:11,padding:"4px 10px"},children:[e.jsx("span",{style:{flex:1},children:"会话加载失败"}),e.jsx("button",{type:"button",onClick:()=>void Le(d.id,{refresh:U,background:U}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),Te.length===0&&U&&!M&&!q&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},d.id)}),r.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:"暂无项目"})]})})]}),!De&&e.jsx("div",{className:`app-sidebar-resizer${Et?" is-dragging":""}`,onMouseDown:pn,style:{left:Ze}}),h&&e.jsx("div",{onClick:()=>w(!1),style:{position:"fixed",inset:0,zIndex:1300,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"12vh 16px 16px"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),style:{width:"min(560px, 100%)",maxHeight:"64vh",display:"flex",flexDirection:"column",borderRadius:12,border:"1px solid var(--border-default)",background:"var(--bg-surface)",boxShadow:"0 18px 48px rgba(17,24,39,0.28)",overflow:"hidden"},children:[e.jsx("div",{style:{padding:10,borderBottom:"1px solid var(--border-subtle)"},children:e.jsx("input",{autoFocus:!0,value:p,onChange:d=>b(d.target.value),onKeyDown:d=>{d.key==="Escape"&&w(!1)},placeholder:"搜索所有会话(标题或目录)…","aria-label":"搜索所有会话",style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"}})}),e.jsxs("div",{style:{overflowY:"auto",padding:8},children:[Qe&&$e&&$e.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[$e.length," 个结果"]}),Qe&&$e&&$e.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!Qe&&at.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),($e??at.slice(0,S)).map(d=>{const k=Z===d.id;return e.jsx("div",{className:`sidebar-row ${k?"sidebar-row-active":""}`,children:e.jsxs("button",{type:"button",onClick:()=>{Q(d.projectId&&r.some(z=>z.id===d.projectId)?d.projectId:null),pe(d.id),w(!1),De&&Ve(!1)},title:`${d.sourceLabel}
150
+ ${d.cwd}`,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"6px 10px",border:0,background:"transparent",color:k?"var(--accent)":"var(--text-secondary)",fontSize:12,cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{style:{flexShrink:0,minWidth:22,padding:"1px 3px",borderRadius:3,border:"1px solid var(--border-subtle)",color:k?"var(--accent)":"var(--text-muted)",fontSize:8,fontWeight:700,textAlign:"center"},children:os[d.agentType]}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.title}),d.occupancy==="owned-externally"&&e.jsx("span",{title:"原客户端正在使用,只读","aria-label":"只读",style:{display:"flex",flexShrink:0},children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2"}),e.jsx("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]})})]})},d.id)}),!Qe&&at.length>S&&e.jsx("button",{type:"button",onClick:()=>D(d=>d+10),style:{width:"100%",padding:"8px 10px",border:0,borderTop:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",textAlign:"center"},children:"更多…"})]})]})})]}),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[X==="focus"&&e.jsx("button",{onClick:()=>ot("standard"),title:"返回标准布局",style:{position:"absolute",top:12,left:12,zIndex:100,padding:"5px 10px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag"},children:"← 侧边栏"}),e.jsx("div",{style:{height:"100%",paddingTop:0},children:e.jsx(ji,{selectedProjectId:T,selectedSessionId:Z,sessionTitle:bt,sessionSummary:Me,voiceCommand:dn,onOpenSettings:zn,settingsOpen:Ht,onHideToBackground:()=>void un(),onToggleAppearance:de,appearanceOpen:re,hideToBackgroundTitle:te?`隐藏到后台(说“${Ce}”唤醒)`:"隐藏到后台",onSessionCreated:async d=>{var k;pe(d),Ke.current&&(Ke.current=!1,qe.current={sessionId:d,until:Date.now()+9e4},(k=window.agentApi)==null||k.wakeConversation(!0)),T&&await Le(T)},onSubSessionCreated:async d=>{await Xt(d)},onSelectSession:d=>{pe(d)},onSubAgentEvent:d=>{d.type==="started"?hn({type:"info",title:"子会话已启动",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):d.type==="completed"?hn({type:"success",title:"子会话已完成",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):hn({type:"error",title:"子会话出错",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId})},onMessageSent:(d,k)=>{l(z=>{const U={};for(const[M,q]of Object.entries(z))U[M]=q.map(se=>se.id===d?{...se,title:k.slice(0,60)||se.title}:se);return U}),f(z=>z.map(U=>U.id===d?{...U,title:k.slice(0,60)||U.title}:U))},onRunComplete:async(d,k)=>{var q;const z=qe.current,U=ri(z,k);qe.current=U,U!==z&&((q=window.agentApi)==null||q.wakeConversation(!0));const M=d||T;M&&await Le(M,{refresh:!0,background:!0})}})})]}),Ht&&zt.createPortal(e.jsx("div",{onClick:()=>st(!1),style:{position:"fixed",inset:0,zIndex:10001,background:"rgba(17,24,39,0.18)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.2s var(--ease-out)",WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),style:{width:"min(920px, calc(100vw - 48px))",height:"min(760px, calc(100vh - 48px))",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:"var(--shadow-md)",overflow:"hidden",display:"flex",flexDirection:"column",animation:"fadeInUp 0.25s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border-subtle)",padding:"8px 10px",background:"var(--bg-deepest)"},children:[e.jsx("div",{style:{display:"flex",gap:6},children:Ln.map(d=>e.jsx("button",{onClick:()=>$(d.id),className:`settings-tab ${y===d.id?"settings-tab-active":""}`,children:d.label},d.id))}),e.jsx("button",{onClick:()=>st(!1),title:"关闭",className:"ui-icon-button ui-icon-button--close ui-icon-button--danger",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[y==="settings"&&e.jsx(Ai,{}),y==="mcp"&&e.jsx(zi,{}),y==="memory"&&e.jsx(Mi,{}),y==="skill"&&e.jsx(Wi,{}),y==="agent"&&e.jsx(Ni,{}),y==="lsp"&&e.jsx(Di,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),re&&Lt&&zt.createPortal(e.jsx("div",{onClick:()=>be(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(Lt.right-320,window.innerWidth-332)),top:Lt.bottom+8,width:320,maxHeight:`calc(100vh - ${Lt.bottom+20}px)`,overflowY:"auto",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"16px",display:"flex",flexDirection:"column",gap:16,animation:"fadeInUp 0.2s var(--ease-out)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"皮肤"}),e.jsx("div",{className:"appearance-choices",children:qs.map(d=>e.jsxs("button",{onClick:()=>ge(d.id),className:`appearance-choice ${ee===d.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${d.preview[0]} 55%, ${d.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:ee===d.id?600:400},children:d.label}),ee===d.id&&e.jsx("svg",{className:"appearance-choice-check",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m5 12 4 4L19 6"})})]},d.id))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"布局"}),e.jsx("div",{className:"appearance-segmented",children:Ks.map(d=>e.jsx("button",{onClick:()=>ot(d.id),title:d.description,className:`appearance-segment ${X===d.id?"appearance-segment-active":""}`,children:d.label},d.id))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,borderTop:"1px solid var(--border-subtle)",paddingTop:12},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em"},children:"语音"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["助手回复自动播报",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:pt,onChange:d=>Ye(d.target.checked)})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["隐藏后语音唤醒",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:te,onChange:d=>In(d.target.checked)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{flexShrink:0},children:"唤醒词"}),e.jsx("input",{value:Ce,onChange:d=>Vt(d.target.value||"小智"),style:{flex:1,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-primary)",fontSize:12}})]})]})]})}),document.body),e.jsx(Gi,{open:s,onCancel:()=>o(!1),onConfirm:async d=>{await xn(d),o(!1)}}),e.jsx(_i,{trigger:qt,heardText:Ae}),Nt.length>0&&zt.createPortal(e.jsx("div",{style:{position:"fixed",bottom:24,right:24,zIndex:2e4,display:"flex",flexDirection:"column",gap:10,alignItems:"flex-end",pointerEvents:"none"},children:Nt.map(d=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${d.type==="error"?"rgba(220,38,38,0.25)":d.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${d.type==="error"?"var(--danger)":d.type==="success"?"var(--success)":"var(--accent)"}`,borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"12px 14px",animation:"fadeInUp 0.22s var(--ease-out)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsxs("span",{style:{fontSize:12,fontWeight:600,color:d.type==="error"?"var(--danger)":d.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[d.type==="error"?"✕":d.type==="success"?"✓":"◎"," ",d.title]}),e.jsx("button",{onClick:()=>kt(d.id),title:"关闭",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:14,lineHeight:1,padding:"2px 4px",borderRadius:4,transition:"color 0.15s"},onMouseEnter:k=>k.currentTarget.style.color="var(--text-primary)",onMouseLeave:k=>k.currentTarget.style.color="var(--text-muted)",children:"×"})]}),e.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)",lineHeight:1.5,wordBreak:"break-all"},children:d.body}),d.sessionId&&e.jsx("button",{onClick:()=>{pe(d.sessionId),kt(d.id)},style:{marginTop:8,padding:"4px 10px",fontSize:11,fontWeight:500,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid var(--border-glow)",borderRadius:6,cursor:"pointer",transition:"background 0.15s",WebkitAppRegion:"no-drag"},onMouseEnter:k=>k.currentTarget.style.background="var(--accent-glow)",onMouseLeave:k=>k.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},d.id))}),document.body)]})}export{ea as default};