agentroam 0.2.0-preview.3 → 0.2.0-preview.4

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 (87) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/cloudflared/bundled-asset.test.js +1 -1
  3. package/dist/cloudflared/manifest.js +1 -1
  4. package/dist/tunnel/cloudflare-provider.js +17 -10
  5. package/dist/tunnel/cloudflare-provider.test.js +33 -0
  6. package/dist/tunnel/proxy-settings.js +141 -0
  7. package/dist/tunnel/proxy-settings.test.js +111 -0
  8. package/dist/tunnel/public-readiness.js +60 -36
  9. package/dist/tunnel/public-readiness.test.js +80 -0
  10. package/package.json +27 -9
  11. package/runtime/.next/BUILD_ID +1 -1
  12. package/runtime/.next/app-build-manifest.json +4 -4
  13. package/runtime/.next/app-path-routes-manifest.json +1 -1
  14. package/runtime/.next/build-manifest.json +7 -7
  15. package/runtime/.next/prerender-manifest.json +1 -1
  16. package/runtime/.next/react-loadable-manifest.json +1 -1
  17. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/runtime/.next/server/app/_not-found.html +1 -1
  19. package/runtime/.next/server/app/_not-found.rsc +1 -1
  20. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  21. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  22. package/runtime/.next/server/app/api/agent/model/route.js +1 -0
  23. package/runtime/.next/server/app/api/agent/model/route.js.nft.json +1 -0
  24. package/runtime/.next/server/app/api/agent/model.body +1 -0
  25. package/runtime/.next/server/app/api/agent/model.meta +1 -0
  26. package/runtime/.next/server/app/api/agent/run/route.js +1 -1
  27. package/runtime/.next/server/app/api/agent/steer/route.js +1 -0
  28. package/runtime/.next/server/app/api/agent/steer/route.js.nft.json +1 -0
  29. package/runtime/.next/server/app/api/agent/stream/route.js +3 -2
  30. package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
  31. package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
  32. package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
  33. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  34. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  35. package/runtime/.next/server/app/api/skills/route.js +1 -1
  36. package/runtime/.next/server/app/api/tools/route.js +1 -1
  37. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  38. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  39. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  40. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  41. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  42. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  43. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  44. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  45. package/runtime/.next/server/app/api/web-console/history/route.js.nft.json +1 -1
  46. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  47. package/runtime/.next/server/app/web/page.js +10 -10
  48. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  49. package/runtime/.next/server/app/web.html +1 -1
  50. package/runtime/.next/server/app/web.rsc +2 -2
  51. package/runtime/.next/server/app-paths-manifest.json +13 -11
  52. package/runtime/.next/server/chunks/322.js +28 -12
  53. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  54. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  55. package/runtime/.next/server/pages/404.html +1 -1
  56. package/runtime/.next/server/pages/500.html +1 -1
  57. package/runtime/.next/server/server-reference-manifest.json +1 -1
  58. package/runtime/.next/static/chunks/982.9e87a5cc0e6b13cf.js +1 -0
  59. package/runtime/.next/static/chunks/app/web/page-02e0df331bb14489.js +1 -0
  60. package/runtime/.next/static/chunks/{main-a7dd8c98b48af038.js → main-30618c50527ce4e9.js} +1 -1
  61. package/runtime/.next/static/chunks/{webpack-d91bc49de770fd58.js → webpack-0c872a6ee48cbbdf.js} +1 -1
  62. package/runtime/node_modules/.package-lock.json +3 -3
  63. package/runtime/node_modules/@agent/core/dist/domain/context/ContextLoader.d.ts +2 -0
  64. package/runtime/node_modules/@agent/core/dist/domain/context/ContextLoader.d.ts.map +1 -1
  65. package/runtime/node_modules/@agent/core/dist/index.js +114 -12
  66. package/runtime/node_modules/@agent/core/dist/index.js.map +7 -6
  67. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteAnonymousWebStore.d.ts +13 -0
  68. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteAnonymousWebStore.d.ts.map +1 -0
  69. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteAnonymousWebStore.test.d.ts +2 -0
  70. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteAnonymousWebStore.test.d.ts.map +1 -0
  71. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteDatabase.d.ts.map +1 -1
  72. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteSessionStore.d.ts.map +1 -1
  73. package/runtime/node_modules/@agent/core/dist/infrastructure/index.d.ts +1 -0
  74. package/runtime/node_modules/@agent/core/dist/infrastructure/index.d.ts.map +1 -1
  75. package/runtime/node_modules/node-abi/abi_registry.json +7 -0
  76. package/runtime/node_modules/node-abi/package.json +1 -1
  77. package/runtime/package-lock.json +3 -3
  78. package/runtime/webapp/dist/assets/App-lXIeMH5u.js +52 -0
  79. package/runtime/webapp/dist/assets/index-BAFMhDtY.js +42 -0
  80. package/runtime/webapp/dist/assets/index-Beg9M2xI.css +1 -0
  81. package/runtime/webapp/dist/index.html +17 -0
  82. package/runtime/webapp/dist/pcm-audio-worklet.js +126 -0
  83. package/runtime/ws-server.mjs +148 -18
  84. package/runtime/.next/static/chunks/982.bf2e6e7fe55cd5ca.js +0 -1
  85. package/runtime/.next/static/chunks/app/web/page-0ee508ac538f72d3.js +0 -1
  86. /package/runtime/.next/static/{OszWLAB2kMAnNfSwJzpyw → dclalTmecO-HMVQvSKG7g}/_buildManifest.js +0 -0
  87. /package/runtime/.next/static/{OszWLAB2kMAnNfSwJzpyw → dclalTmecO-HMVQvSKG7g}/_ssgManifest.js +0 -0
@@ -0,0 +1,52 @@
1
+ import{r as g,g as Vr,R as Kr,j as e,a as ct}from"./index-BAFMhDtY.js";const qr={},ir=t=>{let i;const r=new Set,o=(v,m)=>{const S=typeof v=="function"?v(i):v;if(!Object.is(S,i)){const w=i;i=m??(typeof S!="object"||S===null)?S:Object.assign({},i,S),r.forEach(E=>E(i,w))}},s=()=>i,x={setState:o,getState:s,getInitialState:()=>p,subscribe:v=>(r.add(v),()=>r.delete(v)),destroy:()=>{(qr?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}},p=i=t(o,s,x);return x},Jr=t=>t?ir(t):ir;var kr={exports:{}},Ir={},Cr={exports:{}},zr={};/**
2
+ * @license React
3
+ * use-sync-external-store-shim.production.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var ut=g;function Qr(t,i){return t===i&&(t!==0||1/t===1/i)||t!==t&&i!==i}var Gr=typeof Object.is=="function"?Object.is:Qr,Yr=ut.useState,Xr=ut.useEffect,Zr=ut.useLayoutEffect,en=ut.useDebugValue;function tn(t,i){var r=i(),o=Yr({inst:{value:r,getSnapshot:i}}),s=o[0].inst,n=o[1];return Zr(function(){s.value=r,s.getSnapshot=i,_t(s)&&n({inst:s})},[t,r,i]),Xr(function(){return _t(s)&&n({inst:s}),t(function(){_t(s)&&n({inst:s})})},[t]),en(r),r}function _t(t){var i=t.getSnapshot;t=t.value;try{var r=i();return!Gr(t,r)}catch{return!0}}function rn(t,i){return i()}var nn=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?rn:tn;zr.useSyncExternalStore=ut.useSyncExternalStore!==void 0?ut.useSyncExternalStore:nn;Cr.exports=zr;var sn=Cr.exports;/**
10
+ * @license React
11
+ * use-sync-external-store-shim/with-selector.production.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var Mt=g,on=sn;function an(t,i){return t===i&&(t!==0||1/t===1/i)||t!==t&&i!==i}var ln=typeof Object.is=="function"?Object.is:an,dn=on.useSyncExternalStore,cn=Mt.useRef,un=Mt.useEffect,pn=Mt.useMemo,gn=Mt.useDebugValue;Ir.useSyncExternalStoreWithSelector=function(t,i,r,o,s){var n=cn(null);if(n.current===null){var l={hasValue:!1,value:null};n.current=l}else l=n.current;n=pn(function(){function x(w){if(!p){if(p=!0,v=w,w=o(w),s!==void 0&&l.hasValue){var E=l.value;if(s(E,w))return m=E}return m=w}if(E=m,ln(v,w))return E;var T=o(w);return s!==void 0&&s(E,T)?(v=w,E):(v=w,m=T)}var p=!1,v,m,S=r===void 0?null:r;return[function(){return x(i())},S===null?void 0:function(){return x(S())}]},[i,r,o,s]);var c=dn(t,n[0],n[1]);return un(function(){l.hasValue=!0,l.value=c},[c]),gn(c),c};kr.exports=Ir;var xn=kr.exports;const hn=Vr(xn),Ar={},{useDebugValue:fn}=Kr,{useSyncExternalStoreWithSelector:mn}=hn;let ar=!1;const bn=t=>t;function vn(t,i=bn,r){(Ar?"production":void 0)!=="production"&&r&&!ar&&(console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"),ar=!0);const o=mn(t.subscribe,t.getState,t.getServerState||t.getInitialState,i,r);return fn(o),o}const lr=t=>{(Ar?"production":void 0)!=="production"&&typeof t!="function"&&console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`.");const i=typeof t=="function"?Jr(t):t,r=(o,s)=>vn(i,o,s);return Object.assign(r,i),r},er=t=>t?lr(t):lr;function yn(t){for(let i=t.length-1;i>=0;i--)if(t[i].type==="context_usage"&&t[i].usage)return t[i].usage}function dr(t,i){var r,o;if(i.role==="assistant"&&((r=i.toolCalls)!=null&&r.length)){const s=t[t.length-1];if(s&&s.role==="assistant"&&!((o=s.toolCalls)!=null&&o.length))return[...t.slice(0,-1),{...s,content:s.content,toolCalls:i.toolCalls}]}return[...t,i]}function cr(t,i){var o;if(!i)return t;const r=t[t.length-1];if(r&&r.role==="assistant"&&!((o=r.toolCalls)!=null&&o.length)&&!r.askUser&&!r.isCompactionSummary){const s=[...t];return s[s.length-1]={...r,content:r.content+i},s}return[...t,{id:crypto.randomUUID(),role:"assistant",content:i,timestamp:Date.now()}]}function ur(t,i,r,o){return t.map(s=>{if(!s.toolCalls)return s;const n=s.toolCalls.map(l=>l.id===i?{...l,result:r,isError:o}:l);return{...s,toolCalls:n}})}function pr(t,i,r,o){return t.map(s=>{if(!s.toolCalls)return s;const n=s.toolCalls.map(l=>l.name==="dispatch_agent"&&l.arguments.subSessionId===i?{...l,arguments:{...l.arguments,subAgentStatus:r,subAgentDetail:o}}:l);return{...s,toolCalls:n}})}function gr(t,i,r){return t.map(o=>{if(!o.toolCalls)return o;const s=o.toolCalls.map(n=>n.name==="dispatch_agent"&&n.arguments.subSessionId===i?{...n,arguments:{...n.arguments,subAgentProgress:(n.arguments.subAgentProgress?n.arguments.subAgentProgress+`
18
+ `+r:r).split(`
19
+ `).slice(-30).join(`
20
+ `)}}:n);return{...o,toolCalls:s}})}function xr(t,i,r){return t.map(o=>o.id===i?r(o):o)}const Fe=er((t,i)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(r,o)=>t(s=>{const n=o??s.sessionId??void 0,l=n&&n!==s.sessionId?s.messages:dr(s.messages,r),c=n?{...s.messagesBySession,[n]:dr(s.messagesBySession[n]??(n===s.sessionId?s.messages:[]),r)}:s.messagesBySession;return{messages:l,messagesBySession:c,currentText:n&&n!==s.sessionId?s.currentText:""}}),appendText:(r,o)=>t(s=>{if(!r)return s;const n=o??s.sessionId??void 0,l=n&&n!==s.sessionId?s.messages:cr(s.messages,r),c=n?{...s.messagesBySession,[n]:cr(s.messagesBySession[n]??(n===s.sessionId?s.messages:[]),r)}:s.messagesBySession;return{messages:l,messagesBySession:c,currentText:n&&n!==s.sessionId?s.currentText:s.currentText+r}}),setRunningSession:r=>t({runningSessionId:r}),setSessionId:r=>t({sessionId:r}),updateToolResult:(r,o,s,n)=>t(l=>{const c=n??l.sessionId??void 0,x=c&&c!==l.sessionId?l.messages:ur(l.messages,r,o,s),p=c?{...l.messagesBySession,[c]:ur(l.messagesBySession[c]??(c===l.sessionId?l.messages:[]),r,o,s)}:l.messagesBySession;return{messages:x,messagesBySession:p}}),setMessages:(r,o)=>t(s=>{const n=o??s.sessionId??void 0;return{messages:r,messagesBySession:n?{...s.messagesBySession,[n]:r}:s.messagesBySession,currentText:""}}),getMessagesForSession:r=>i().messagesBySession[r]??[],setContextUsage:(r,o)=>t(s=>{const n=o??s.sessionId??void 0;return n?{contextUsageBySession:{...s.contextUsageBySession,[n]:r}}:s}),getContextUsageForSession:r=>i().contextUsageBySession[r],updateMessage:(r,o,s)=>t(n=>{const l=s??n.sessionId??void 0,c=l&&l!==n.sessionId?n.messages:xr(n.messages,r,o),x=l?{...n.messagesBySession,[l]:xr(n.messagesBySession[l]??(l===n.sessionId?n.messages:[]),r,o)}:n.messagesBySession;return{messages:c,messagesBySession:x}}),updateSubAgentStatus:(r,o,s,n)=>t(l=>{const c=n??l.sessionId??void 0,x=c&&c!==l.sessionId?l.messages:pr(l.messages,r,o,s),p=c?{...l.messagesBySession,[c]:pr(l.messagesBySession[c]??(c===l.sessionId?l.messages:[]),r,o,s)}:l.messagesBySession;return{messages:x,messagesBySession:p}}),updateSubAgentProgress:(r,o,s)=>t(n=>{const l=s??n.sessionId??void 0,c=l&&l!==n.sessionId?n.messages:gr(n.messages,r,o),x=l?{...n.messagesBySession,[l]:gr(n.messagesBySession[l]??(l===n.sessionId?n.messages:[]),r,o)}:n.messagesBySession;return{messages:c,messagesBySession:x}}),clearMessages:r=>t(o=>{const s=r??o.sessionId??void 0;if(!s)return{messages:[],currentText:""};const{[s]:n,...l}=o.messagesBySession,{[s]:c,...x}=o.contextUsageBySession;return{messages:s===o.sessionId?[]:o.messages,messagesBySession:l,contextUsageBySession:x,currentText:s===o.sessionId?"":o.currentText}}),setTodos:r=>t({todos:r}),setCronTasks:r=>t({cronTasks:r})})),wn={};function jn(t,i){let r;try{r=t()}catch{return}return{getItem:s=>{var n;const l=x=>x===null?null:JSON.parse(x,void 0),c=(n=r.getItem(s))!=null?n:null;return c instanceof Promise?c.then(l):l(c)},setItem:(s,n)=>r.setItem(s,JSON.stringify(n,void 0)),removeItem:s=>r.removeItem(s)}}const St=t=>i=>{try{const r=t(i);return r instanceof Promise?r:{then(o){return St(o)(r)},catch(o){return this}}}catch(r){return{then(o){return this},catch(o){return St(o)(r)}}}},Sn=(t,i)=>(r,o,s)=>{let n={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:k=>k,version:0,merge:(k,R)=>({...R,...k}),...i},l=!1;const c=new Set,x=new Set;let p;try{p=n.getStorage()}catch{}if(!p)return t((...k)=>{console.warn(`[zustand persist middleware] Unable to update item '${n.name}', the given storage is currently unavailable.`),r(...k)},o,s);const v=St(n.serialize),m=()=>{const k=n.partialize({...o()});let R;const u=v({state:k,version:n.version}).then(f=>p.setItem(n.name,f)).catch(f=>{R=f});if(R)throw R;return u},S=s.setState;s.setState=(k,R)=>{S(k,R),m()};const w=t((...k)=>{r(...k),m()},o,s);let E;const T=()=>{var k;if(!p)return;l=!1,c.forEach(u=>u(o()));const R=((k=n.onRehydrateStorage)==null?void 0:k.call(n,o()))||void 0;return St(p.getItem.bind(p))(n.name).then(u=>{if(u)return n.deserialize(u)}).then(u=>{if(u)if(typeof u.version=="number"&&u.version!==n.version){if(n.migrate)return n.migrate(u.state,u.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return u.state}).then(u=>{var f;return E=n.merge(u,(f=o())!=null?f:w),r(E,!0),m()}).then(()=>{R==null||R(E,void 0),l=!0,x.forEach(u=>u(E))}).catch(u=>{R==null||R(void 0,u)})};return s.persist={setOptions:k=>{n={...n,...k},k.getStorage&&(p=k.getStorage())},clearStorage:()=>{p==null||p.removeItem(n.name)},getOptions:()=>n,rehydrate:()=>T(),hasHydrated:()=>l,onHydrate:k=>(c.add(k),()=>{c.delete(k)}),onFinishHydration:k=>(x.add(k),()=>{x.delete(k)})},T(),E||w},kn=(t,i)=>(r,o,s)=>{let n={storage:jn(()=>localStorage),partialize:T=>T,version:0,merge:(T,k)=>({...k,...T}),...i},l=!1;const c=new Set,x=new Set;let p=n.storage;if(!p)return t((...T)=>{console.warn(`[zustand persist middleware] Unable to update item '${n.name}', the given storage is currently unavailable.`),r(...T)},o,s);const v=()=>{const T=n.partialize({...o()});return p.setItem(n.name,{state:T,version:n.version})},m=s.setState;s.setState=(T,k)=>{m(T,k),v()};const S=t((...T)=>{r(...T),v()},o,s);s.getInitialState=()=>S;let w;const E=()=>{var T,k;if(!p)return;l=!1,c.forEach(u=>{var f;return u((f=o())!=null?f:S)});const R=((k=n.onRehydrateStorage)==null?void 0:k.call(n,(T=o())!=null?T:S))||void 0;return St(p.getItem.bind(p))(n.name).then(u=>{if(u)if(typeof u.version=="number"&&u.version!==n.version){if(n.migrate)return[!0,n.migrate(u.state,u.version)];console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,u.state];return[!1,void 0]}).then(u=>{var f;const[B,P]=u;if(w=n.merge(P,(f=o())!=null?f:S),r(w,!0),B)return v()}).then(()=>{R==null||R(w,void 0),w=o(),l=!0,x.forEach(u=>u(w))}).catch(u=>{R==null||R(void 0,u)})};return s.persist={setOptions:T=>{n={...n,...T},T.storage&&(p=T.storage)},clearStorage:()=>{p==null||p.removeItem(n.name)},getOptions:()=>n,rehydrate:()=>E(),hasHydrated:()=>l,onHydrate:T=>(c.add(T),()=>{c.delete(T)}),onFinishHydration:T=>(x.add(T),()=>{x.delete(T)})},n.skipHydration||E(),w||S},In=(t,i)=>"getStorage"in i||"serialize"in i||"deserialize"in i?((wn?"production":void 0)!=="production"&&console.warn("[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."),Sn(t,i)):kn(t,i),Cn=In,zn=[{id:"pearl",label:"珍珠白",preview:["#f5f6fa","#4f6ef7"]},{id:"scifi",label:"科幻霓虹",preview:["#050a14","#22d3ee"]},{id:"noir",label:"暗夜黑",preview:["#0f1115","#a78bfa"]}],An=[{id:"standard",label:"标准",description:"侧边栏 + 对话区"},{id:"focus",label:"专注",description:"隐藏侧边栏,居中沉浸对话"},{id:"compact",label:"紧凑",description:"更小间距与字号,信息密度优先"}],Ee=er()(Cn(t=>({skin:"pearl",layout:"standard",autoSpeak:!1,wakeEnabled:!0,wakeWord:"小智",setSkin:i=>t({skin:i}),setLayout:i=>t({layout:i}),setAutoSpeak:i=>t({autoSpeak:i}),setWakeEnabled:i=>t({wakeEnabled:i}),setWakeWord:i=>t({wakeWord:i})}),{name:"agent-ui-prefs"}));function tr(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function Tr(){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 Rr(){return Tr()!==null||tr()!==null}function Tn(t){var n,l;const i=Tr();if(i){let c=!1,x=()=>{},p=()=>{};const v=()=>{var m;c||(c=!0,x(),p(),(m=t.onEnd)==null||m.call(t))};return x=i.onDictation(({text:m,isFinal:S})=>{const w=m.trim();w&&(S?(t.onFinal(w),v()):t.onInterim(w))}),p=i.onDictationError(m=>{var S;(S=t.onError)==null||S.call(t,m),v()}),i.dictationStart().then(m=>{var S;m.ok||((S=t.onError)==null||S.call(t,m.reason||"无法启动语音识别"),v())}).catch(()=>{var m;(m=t.onError)==null||m.call(t,"无法启动语音识别"),v()}),{stop:()=>{i.dictationStop()}}}const r=tr();if(!r)return(n=t.onError)==null||n.call(t,"当前环境不支持语音识别"),null;const o=new r;o.lang=t.lang??"zh-CN",o.continuous=!1,o.interimResults=!0;let s="";o.onresult=c=>{let x="";for(let p=c.resultIndex;p<c.results.length;p++){const v=c.results[p];v.isFinal?s+=v[0].transcript:x+=v[0].transcript}x&&t.onInterim(s+x)},o.onerror=c=>{var x;c.error!=="no-speech"&&c.error!=="aborted"&&((x=t.onError)==null||x.call(t,`语音识别失败:${c.error??"未知错误"}`))},o.onend=()=>{var c;s&&t.onFinal(s.trim()),(c=t.onEnd)==null||c.call(t)};try{o.start()}catch{return(l=t.onEnd)==null||l.call(t),null}return{stop:()=>o.stop()}}function Rn(t){var l;const i=tr();if(!i)return(l=t.onError)==null||l.call(t,"当前环境不支持语音唤醒"),null;let r=!1,o=null,s=null;const n=()=>{if(!r){o=new i,o.lang=t.lang??"zh-CN",o.continuous=!0,o.interimResults=!0,o.onresult=c=>{var v,m,S;const x=c.results[c.results.length-1],p=(m=(v=x==null?void 0:x[0])==null?void 0:v.transcript)==null?void 0:m.trim();p&&(x.isFinal&&((S=t.onHeard)==null||S.call(t,p)),p.includes(t.wakeWord)&&t.onWake(p))},o.onerror=c=>{var x;c.error==="not-allowed"&&((x=t.onError)==null||x.call(t,"麦克风权限被拒绝,语音唤醒已停用"),r=!0)},o.onend=()=>{r||(s=setTimeout(n,400))};try{o.start()}catch{s=setTimeout(n,800)}}};return n(),{stop:()=>{r=!0,s&&clearTimeout(s);try{o==null||o.abort()}catch{}}}}function vt(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function Wt(t,i){return i(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const Wn={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function Ln(t){const i=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(i.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const r=new Float32Array(i.byteLength/2),o=new DataView(i.buffer,i.byteOffset,i.byteLength);for(let s=0;s<r.length;s+=1)r[s]=o.getInt16(s*2,!0)/32768;return r}class En{constructor(i,r=Wn){this.api=i,this.dependencies=r,this.context=null,this.node=null,this.ready=null,this.current=null}start(i){var o;this.current&&!this.current.acknowledged&&((o=this.node)==null||o.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const r={metadata:i,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=r,this.ensureReady().then(()=>{if(!(this.current!==r||!this.node)){this.node.port.postMessage({type:"start",generation:i.generation,sampleRate:i.sampleRate});for(const s of r.pending)this.postSamples(i.generation,s);r.pending=[],r.pendingSamples=0,r.finished&&this.node.port.postMessage({type:"finish",generation:i.generation})}}).catch(s=>this.fail(r,s))}enqueue(i,r){const o=this.current;if(!o||o.metadata.generation!==i||o.acknowledged)return;let s;try{s=Ln(r)}catch(n){this.fail(o,n);return}if(this.node){this.postSamples(i,s);return}if(o.pendingSamples+s.length>o.metadata.sampleRate){this.fail(o,new Error("TTS PCM queue overflow"));return}o.pending.push(s),o.pendingSamples+=s.length}finish(i){var o;const r=this.current;!r||r.metadata.generation!==i||r.acknowledged||(r.finished=!0,(o=this.node)==null||o.port.postMessage({type:"finish",generation:i}))}flush(i){var o;const r=this.current;!r||r.metadata.generation!==i||r.acknowledged||((o=this.node)==null||o.port.postMessage({type:"flush",generation:i}),r.pending=[],r.pendingSamples=0,this.acknowledge(r))}dispose(){var i,r;this.current&&this.flush(this.current.metadata.generation),(i=this.node)==null||i.disconnect(),this.node=null,(r=this.context)==null||r.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const i=this.dependencies.createContext();this.context=i,await i.audioWorklet.addModule(this.dependencies.workletUrl);const r=this.dependencies.createNode(i);r.port.onmessage=o=>this.onWorkletMessage(o.data),r.connect(i.destination),this.node=r,i.state!=="running"&&await i.resume()})(),this.ready)}postSamples(i,r){var o;(o=this.node)==null||o.port.postMessage({type:"chunk",generation:i,samples:r},[r.buffer])}onWorkletMessage(i){const r=this.current;if(!(!r||i.generation!==r.metadata.generation)){if(i.type==="drained"||i.type==="stopped"){this.acknowledge(r);return}i.type==="overflow"&&this.fail(r,new Error("TTS AudioWorklet buffer overflow"))}}fail(i,r){this.current!==i||i.acknowledged||(console.error("[tts] PCM playback failed",r),i.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(i.metadata.generation))}acknowledge(i){this.current!==i||i.acknowledged||(i.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(i.metadata.generation))}}function Lt(t,i){return t.find(r=>r.id===i)??null}const Dt=er((t,i)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",setField:(r,o)=>t(s=>{const n={...s,[r]:o};return n.isConfigured=!!(n.apiKey&&n.modelId),n}),loadFromSystem:async()=>{if(window.agentApi)try{const r=await window.agentApi.getSettings(),o=r.profiles??[],s=r.activeProfileId??"",n=Lt(o,s);t({modelProvider:(n==null?void 0:n.provider)??r.modelProvider??"anthropic",modelId:(n==null?void 0:n.modelId)??r.modelId??"claude-sonnet-4-6",apiKey:(n==null?void 0:n.apiKey)??r.apiKey??"",baseUrl:(n==null?void 0:n.baseUrl)??r.baseUrl??"",maxIterations:r.maxIterations??10,contextWindow:r.contextWindow??100,workingDirectory:r.workingDirectory??"/",isConfigured:!!(((n==null?void 0:n.apiKey)??r.apiKey)&&((n==null?void 0:n.modelId)??r.modelId)),profiles:o,activeProfileId:s})}catch(r){console.error("Failed to load settings:",r)}},saveToSystem:async()=>{if(!window.agentApi)return;const r=i();await window.agentApi.saveSettings({modelProvider:r.modelProvider,modelId:r.modelId,apiKey:r.apiKey,baseUrl:r.baseUrl,maxIterations:r.maxIterations,contextWindow:r.contextWindow,workingDirectory:r.workingDirectory,isConfigured:r.isConfigured,profiles:r.profiles,activeProfileId:r.activeProfileId})},addProfile:r=>{const s={id:crypto.randomUUID(),...r};t(n=>({profiles:[...n.profiles,s]}))},updateProfile:(r,o)=>{t(n=>({profiles:n.profiles.map(l=>l.id===r?{...l,...o}:l)}));const s=i();if(s.activeProfileId===r){const n=Lt(s.profiles,r);n&&t({modelProvider:n.provider,modelId:n.modelId,apiKey:n.apiKey,baseUrl:n.baseUrl,isConfigured:!!(n.apiKey&&n.modelId)})}},deleteProfile:r=>{t(o=>{var c;const s=o.profiles.filter(x=>x.id!==r),n=o.activeProfileId===r?((c=s[0])==null?void 0:c.id)??"":o.activeProfileId,l=Lt(s,n);return{profiles:s,activeProfileId:n,...l?{modelProvider:l.provider,modelId:l.modelId,apiKey:l.apiKey,baseUrl:l.baseUrl,isConfigured:!!(l.apiKey&&l.modelId)}:{}}})},setActiveProfileLocal:r=>{const o=i(),s=Lt(o.profiles,r);s&&t({activeProfileId:r,modelProvider:s.provider,modelId:s.modelId,apiKey:s.apiKey,baseUrl:s.baseUrl,isConfigured:!!(s.apiKey&&s.modelId)})},switchActiveProfile:async r=>{i().setActiveProfileLocal(r),window.agentApi&&await window.agentApi.setActiveProfile(r)}}));function Pt({isDone:t,isError:i,color:r,size:o=11}){return t?i?e.jsxs("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:r,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:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsx("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:r,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 Ft({statusColor:t,isDone:i,expanded:r,onToggle:o,header:s,children:n,maxBodyHeight:l=600}){return e.jsxs("div",{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",{style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{style:{width:3,flexShrink:0,background:t,animation:i?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),e.jsxs("button",{onClick:o,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:c=>c.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:c=>c.currentTarget.style.background="var(--bg-deep)",children:[s,e.jsx("svg",{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:r?"rotate(180deg)":"rotate(0deg)",flexShrink:0},children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:r?l:0,opacity:r?1:0,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:n})})]})}function kt({label:t,color:i="var(--text-muted)",bg:r="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:r,color:i,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function rr(t){return t.replace(/\\/g,"/").split("/").pop()??t}function Wr(t){return t?t.split(`
21
+ `).length:0}function Lr(t,i){const r=t.split(`
22
+ `),o=i.split(`
23
+ `);if(r.length*o.length>2e5)return o.map((w,E)=>({type:"added",text:w,lineNo:E+1}));const s=r.length,n=o.length,l=Array.from({length:s+1},()=>new Array(n+1).fill(0));for(let w=1;w<=s;w++)for(let E=1;E<=n;E++)l[w][E]=r[w-1]===o[E-1]?l[w-1][E-1]+1:Math.max(l[w-1][E],l[w][E-1]);const c=[];let x=s,p=n;for(;x>0&&p>0;)r[x-1]===o[p-1]?(c.unshift([x-1,p-1]),x--,p--):l[x-1][p]>=l[x][p-1]?x--:p--;const v=[];let m=0,S=0;for(const[w,E]of c){for(;m<w;)v.push({type:"removed",text:r[m],lineNo:m+1}),m++;for(;S<E;)v.push({type:"added",text:o[S],lineNo:S+1}),S++;v.push({type:"same",text:r[m],lineNo:m+1}),m++,S++}for(;m<s;)v.push({type:"removed",text:r[m],lineNo:m+1}),m++;for(;S<n;)v.push({type:"added",text:o[S],lineNo:S+1}),S++;return v}function Er({content:t,maxHeight:i=320}){const r=t.split(`
24
+ `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:i,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:r.map((o,s)=>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:s+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:o||" "})]},s))})]})})}function Br({diff:t,maxHeight:i=360}){if(t.filter(c=>c.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const o=new Set(t.map((c,x)=>c.type!=="same"?x:-1).filter(c=>c>=0)),s=new Set;o.forEach(c=>{for(let x=Math.max(0,c-3);x<=Math.min(t.length-1,c+3);x++)s.add(x)});const n=[];let l=-1;return[...s].sort((c,x)=>c-x).forEach(c=>{l>=0&&c>l+1&&n.push("ellipsis"),n.push({diffLine:t[c],diffIdx:c}),l=c}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:i,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:n.map((c,x)=>{if(c==="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${x}`);const{diffLine:p}=c,v=p.type==="added"?"rgba(5,150,105,0.08)":p.type==="removed"?"rgba(220,38,38,0.07)":"transparent",m=p.type==="added"?"+":p.type==="removed"?"−":" ",S=p.type==="added"?"var(--success)":p.type==="removed"?"var(--danger)":"transparent",w=p.type==="added"?"#059669":p.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:v},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:S,fontWeight:700,userSelect:"none"},children:m}),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:w,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:p.text||" "})]},x)})})]})})}function Bn({toolCall:t,beforeContent:i}){const[r,o]=g.useState(!1),[s,n]=g.useState("content"),l=t.arguments.file_path??"",c=t.arguments.content??"",x=Wr(c),p=t.isError,v=!!t.result,m=v?p?"var(--danger)":"var(--success)":"var(--accent)",S=g.useMemo(()=>i&&c?Lr(i,c):null,[i,c]),w=g.useMemo(()=>S?{added:S.filter(k=>k.type==="added").length,removed:S.filter(k=>k.type==="removed").length}:null,[S]),E=v?p?"错误":"已写入":"写入中",T=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:v?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:m,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:rr(l)}),e.jsx(kt,{label:`${x} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),w&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[w.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",w.added]}),w.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",w.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:m,flexShrink:0},children:[e.jsx(Pt,{isDone:v,isError:p,color:m}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:E})]})]});return e.jsxs(Ft,{statusColor:m,isDone:v,expanded:r,onToggle:()=>o(!r),header:T,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:l}),S&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(k=>e.jsx("button",{onClick:()=>n(k),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:s===k?"var(--accent-dim)":"transparent",color:s===k?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:k==="content"?"文件内容":"变更行"},k))}),s==="diff"&&S?e.jsx(Br,{diff:S}):e.jsx(Er,{content:c}),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 Mn({toolCall:t}){const[i,r]=g.useState(!1),o=t.arguments.file_path??"",s=t.arguments.startLine,n=t.arguments.endLine,l=t.arguments.offset,c=t.arguments.limit,x=t.result??"",p=Wr(x),v=t.isError,m=!!t.result,S=m?v?"var(--danger)":"var(--success)":"var(--accent)",w=s!==void 0?`L${s}–${n??"?"}`:l!==void 0?`第${l}行起${c?` ×${c}`:""}`:null,E=m?v?"错误":"已读取":"读取中",T=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:m?v?"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:S,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:o,children:rr(o)}),w&&e.jsx(kt,{label:w,color:"var(--accent)",bg:"var(--accent-dim)"}),m&&!v&&e.jsx(kt,{label:`${p} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:S,flexShrink:0},children:[e.jsx(Pt,{isDone:m,isError:v,color:S}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:E})]})]});return e.jsxs(Ft,{statusColor:S,isDone:m,expanded:i,onToggle:()=>r(!i),header:T,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:o}),m&&!v?e.jsx(Er,{content:x}):m&&v&&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:x})]})}function Dn({toolCall:t}){const[i,r]=g.useState(!1),o=t.arguments.file_path??"",s=t.arguments.old_string??"",n=t.arguments.new_string??"",l=t.isError,c=!!t.result,x=c?l?"var(--danger)":"var(--success)":"var(--accent)",p=c?l?"错误":"已替换":"替换中",v=g.useMemo(()=>s&&n?Lr(s,n):null,[s,n]),m=g.useMemo(()=>v?{added:v.filter(w=>w.type==="added").length,removed:v.filter(w=>w.type==="removed").length}:null,[v]),S=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:c?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:x,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:o,children:rr(o)}),m&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[m.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",m.added]}),m.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",m.removed]})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:x,flexShrink:0},children:[e.jsx(Pt,{isDone:c,isError:l,color:x}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:p})]})]});return e.jsxs(Ft,{statusColor:x,isDone:c,expanded:i,onToggle:()=>r(!i),header:S,maxBodyHeight:480,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:o}),v?e.jsx(Br,{diff:v}):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:s}),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:n})]}),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 Gt({label:t,content:i,error:r,maxPreviewLines:o=8,maxPreviewHeight:s=200,maxExpandedHeight:n=2e3}){const[l,c]=g.useState(!1),x=i.split(`
25
+ `),p=x.length>o,v=p&&!l?x.slice(0,o).join(`
26
+ `)+`
27
+ ...`:i;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:r?"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:r?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:r?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:r?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:l?n:s,overflow:"auto",margin:0,lineHeight:1.6},children:v}),p&&e.jsx("button",{onClick:()=>c(!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?"收起":`展开全部 (${x.length} 行)`})]})}function Pn({arguments:t}){var r;const i=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(kt,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(kt,{label:`sid: ${(r=t.subSessionId)==null?void 0:r.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),i&&e.jsx(Gt,{label:"任务",content:i,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Fn({raw:t}){const[i,r]=g.useState(!1);let o;try{const x=JSON.parse(t);delete x.subAgentProgress,delete x.subAgentStatus,delete x.subAgentDetail,o=JSON.stringify(x,null,2)}catch{o=t}const s=8,n=o.split(`
28
+ `),l=n.length>s,c=l&&!i?n.slice(0,s).join(`
29
+ `)+`
30
+ ...`:o;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:i?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:c}),l&&e.jsx("button",{onClick:()=>r(!i),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:i?"收起":`展开全部 (${n.length} 行)`})]})}function $n({toolCall:t,onSelectSession:i}){const r=Fe(R=>R.runningSessionId),[o,s]=g.useState(!1),n=t.name==="dispatch_agent",l=t.arguments.subAgentStatus,c=t.arguments.subAgentDetail,x=t.arguments.subAgentProgress;g.useEffect(()=>{n&&!l&&x&&s(!0)},[n,l,x]);const p=n?l==="failed":t.isError,v=n?!!l||!!t.result&&!r:!!t.result,m=v?p?"var(--danger)":"var(--success)":"var(--accent)",S=n?l==="failed"?"失败":v?"已完成":"运行中":t.result?t.isError?"错误":"完成":"执行中",w=(()=>{if(t.name==="bash"){const u=(t.arguments.command??"").split(`
31
+ `)[0].trim();return u.length>50?u.slice(0,50)+"…":u}if(t.name==="grep_search"){const R=t.arguments.query??"";return R.length>45?R.slice(0,45)+"…":R}if(t.name==="glob_search")return t.arguments.pattern??"";if(n){const u=(t.arguments.task??"").split(`
32
+ `)[0];return u.length>80?u.slice(0,80)+"…":u}return null})(),E=n?`@${t.arguments.agentName??"agent"}`:t.name,T=n?e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:m,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"})]}):t.name==="bash"?e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:m,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.name==="grep_search"?e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:m,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.name==="glob_search"?e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:m,strokeWidth:"2",strokeLinecap:"round",children: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("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:m,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"})}),k=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:20,height:20,borderRadius:5,background:v?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:T}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:E}),w&&e.jsx("span",{style:{fontSize:11,color:"var(--text-muted)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w}),!w&&e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:m,flexShrink:0},children:[e.jsx(Pt,{isDone:v,isError:!!p,color:m}),e.jsx("span",{style:{fontSize:10,fontWeight:500},children:S})]})]});return e.jsxs(Ft,{statusColor:m,isDone:v,expanded:o,onToggle:()=>s(!o),header:k,maxBodyHeight:800,children:[n?e.jsx(Pn,{arguments:t.arguments}):e.jsx(Fn,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!n&&e.jsx(Gt,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),n&&l&&c&&e.jsx(Gt,{label:l==="failed"?"错误信息":"执行摘要",content:c,error:l==="failed",maxPreviewHeight:180}),n&&!l&&x&&(!!r||!t.result)&&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:[x,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:"​"})]})]}),n&&!l&&!x&&!!r&&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 响应..."]}),n&&t.arguments.subSessionId&&i&&e.jsxs("button",{onClick:()=>i(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 Nn({toolCall:t,onSelectSession:i,beforeContent:r}){return t.name==="write_file"?e.jsx(Bn,{toolCall:t,beforeContent:r}):t.name==="read_file"?e.jsx(Mn,{toolCall:t}):t.name==="str_replace"?e.jsx(Dn,{toolCall:t}):e.jsx($n,{toolCall:t,onSelectSession:i})}function Un({question:t,options:i,fields:r,multiSelect:o,answered:s,answer:n,onAnswer:l}){const[c,x]=g.useState(new Set),[p,v]=g.useState(""),[m,S]=g.useState({}),w=!!(i!=null&&i.length),E=!!(r!=null&&r.length),T=f=>{s||x(B=>{const P=new Set(B);return o?P.has(f)?P.delete(f):P.add(f):(P.clear(),P.add(f)),P})},k=()=>{if(c.size===0)return;const f=Array.from(c).map(B=>i[B].label);l(f.join(", "),Array.from(c))},R=()=>{const f=Array.from(c).map(P=>i[P].label),B=Object.fromEntries((r??[]).map(P=>{var X;return[P.name,((X=m[P.name])==null?void 0:X.trim())??""]}));!B.model&&f.length>0&&(B.model=f[0]),!(!Object.values(B).some(Boolean)&&f.length===0)&&l(JSON.stringify({fields:B,selectedOptions:f}),Array.from(c))},u=()=>{p.trim()&&l(p.trim())};return e.jsx("div",{style:{marginBottom:12},children:e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:s?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:s?"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:s?"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:s?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:s?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:s?"var(--text-muted)":"var(--accent)",flex:1},children:s?"已回答":"向你提问"}),o&&!s&&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},children:t}),s&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),E?"配置已提交(敏感字段已隐藏)":n]}),w&&!s&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[i.map((f,B)=>{const P=c.has(B);return e.jsxs("button",{onClick:()=>T(B),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:o?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:f.label}),f.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:f.description})]})]},B)}),!E&&e.jsx("button",{onClick:k,disabled:c.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:c.size>0?"var(--accent)":"var(--bg-surface)",color:c.size>0?"white":"var(--text-muted)",cursor:c.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),E&&!s&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[r.map(f=>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:f.label}),e.jsx("input",{type:f.type==="secret"?"password":"text",value:m[f.name]??"",onChange:B=>S(P=>({...P,[f.name]:B.target.value})),placeholder:f.description,autoComplete:f.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"}}),f.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:f.description})]},f.name)),e.jsx("button",{onClick:R,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:"确认配置"})]}),!s&&!E&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:w?"1px solid var(--border-subtle)":"none",marginTop:w?2:0},children:[e.jsx("input",{type:"text",value:p,onChange:f=>v(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),u())},placeholder:w?"或输入自定义回答…":"输入你的回答…",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:f=>{f.currentTarget.style.borderColor="var(--accent)"},onBlur:f=>{f.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:u,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 Ot={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"}},Ht={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 _n(t,i){const r=(t==null?void 0:t.maxTokens)??Math.max(1,i*1e3),o=(t==null?void 0:t.totalTokens)??0,s=Object.fromEntries(hr.map(l=>[l,0]));for(const l of(t==null?void 0:t.segments)??[]){const c=Ot[l.category];c&&(s[c.group]+=l.tokens)}const n=Math.min(o/r,1);return{hasUsage:!!t,totalTokens:o,maxTokens:r,ratio:n,percent:Math.round(n*100),groups:hr.map(l=>({key:l,label:Ht[l].label,color:Ht[l].color,tokens:s[l]})),details:((t==null?void 0:t.segments)??[]).filter(l=>l.tokens>0).map(l=>{var c,x;return{category:l.category,label:((c=Ot[l.category])==null?void 0:c.label)??l.category,color:Ht[((x=Ot[l.category])==null?void 0:x.group)??"overhead"].color,tokens:l.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function Yt(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function On(t,i){return i?`${t.percent}%`:t.hasUsage?`${Yt(t.totalTokens)} / ${Yt(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Hn({usage:t,contextWindowK:i,compact:r=!1}){const[o,s]=g.useState(!1),[n,l]=g.useState(null),c=g.useRef(null),x=g.useMemo(()=>_n(t,i),[t,i]),p=x.ratio>=.85?"var(--danger)":x.ratio>=.6?"#f59e0b":"var(--accent)",v=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.jsxs("button",{className:"context-usage-ribbon__button",ref:c,type:"button",onClick:()=>{var S;const m=((S=c.current)==null?void 0:S.getBoundingClientRect())??null;l(m),s(w=>!w)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},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:x.groups.map(m=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(m.tokens/x.maxTokens*100,100))}%`,background:m.color,opacity:m.key==="overhead"?.65:1,minWidth:m.tokens>0?1:0}},m.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:x.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:On(x,r)})]}),o&&n&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>s(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:Math.max(8,n.left),top:n.top-8,transform:"translateY(-100%)",width:Math.min(n.width,v-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:x.hasUsage?p:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:x.hasUsage?`${x.percent}%`:"暂无"})]}),x.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:x.requestLabel}),x.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:x.details.map(m=>{const S=x.totalTokens>0?Math.round(m.tokens/x.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:m.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:m.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[Yt(m.tokens)," · ",S,"%"]})]},m.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 fr({activity:t}){const i=t==="tools"?"工具执行中":"思考中";return e.jsxs("div",{className:"agent-activity-indicator",role:"status","aria-live":"polite",children:[e.jsx("span",{children:i}),e.jsx("span",{className:"agent-activity-dots","aria-hidden":"true",children:[0,1,2].map(r=>e.jsx("span",{style:{animationDelay:`${r*.16}s`}},r))})]})}function Vn({appearanceOpen:t,settingsOpen:i,hideToBackgroundTitle:r="隐藏到后台",onHideToBackground:o,onToggleAppearance:s,onOpenSettings:n}){return e.jsxs("div",{className:"chat-header-actions",children:[e.jsx("button",{type:"button",onClick:o,title:r,"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=>s(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:n,title:"设置","aria-label":"设置","aria-expanded":i,className:`ui-icon-button chat-header-action chat-header-action--settings ${i?"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 Kn={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function qn(t){const{title:i="视频工作台",shots:r=[],status:o="generating",composedVideoUrl:s}=t,[n,l]=g.useState(!1),[c,x]=g.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(!n),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:n?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",i]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[r.filter(p=>p.status==="done").length,"/",r.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:n?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!n&&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:yt,children:"#"}),e.jsx("th",{style:{...yt,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:yt,children:"时长"}),e.jsx("th",{style:yt,children:"状态"}),e.jsx("th",{style:yt,children:"预览"})]})}),e.jsx("tbody",{children:r.map(p=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:wt,children:p.index}),e.jsx("td",{style:{...wt,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.description,children:p.description}),e.jsxs("td",{style:wt,children:[p.duration,"s"]}),e.jsxs("td",{style:wt,children:[Kn[p.status]??"⏳",p.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:p.error,children:"!"})]}),e.jsx("td",{style:wt,children:p.videoUrl?e.jsx("button",{onClick:()=>x(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))})]}),c&&e.jsx("video",{src:c,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),s&&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:s,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:[o==="generating"&&e.jsx("span",{children:"🔄 生成中..."}),o==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),o==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),o==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const yt={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},wt={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},Jn={storyboard_workbench:qn};function Qn(t,i,r){return!t||i!==t?!1:r===null||r===t}function Gn(t,i,r=Date.now()){return!t||t.sessionId!==i?t:{...t,until:r+9e4}}async function Yn(t){const{text:i,projectId:r,createSession:o,activateSession:s,showUserMessage:n,onSessionCreated:l,isCancelled:c}=t,x=!t.sessionId;let p=t.sessionId??null;if(!p){const v=await o(i.slice(0,60)||"语音任务",r||void 0);if(c!=null&&c())return null;p=v.id}return s(p),n(i,p),x&&l&&await l(p),p}async function Xn(t){var s,n;const i=((s=t.sessionId)==null?void 0:s.trim())||null,r=!i,o=i??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!o)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(o),t.showUserMessage(t.text,o),r&&await((n=t.onSessionCreated)==null?void 0:n.call(t,o)),o}function Mr(){return typeof document<"u"&&document.body.dataset.webShell==="1"}function Zn(){return typeof navigator>"u"?!1:Mr()||!/Electron\//i.test(navigator.userAgent)}function es(t=900){const[i,r]=g.useState(()=>typeof window<"u"&&window.innerWidth<t);return g.useEffect(()=>{const o=window.matchMedia(`(max-width: ${t-1}px)`),s=n=>r(n.matches);return r(o.matches),o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[t]),i}function Vt(t){const r=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(r){const n=parseFloat(r[1]),l=r[2].toLowerCase(),c=l==="s"||l==="sec"||l==="秒"?n*1e3:l==="m"||l==="min"||l==="分"||l==="分钟"?n*6e4:n*36e5;return c>=36e5&&c%36e5===0?`每 ${c/36e5} 小时`:c>=6e4&&c%6e4===0?`每 ${c/6e4} 分钟`:`每 ${c/1e3} 秒`}const[o,s]=t.trim().split(/\s+/);return o==="0"&&s&&s!=="*"&&!s.includes("/")&&!s.includes(",")?`每天 ${s.padStart(2,"0")}:00`:`cron: ${t}`}function ts(t){const i=t.split(/(`[^`\n]+`)/g);return i.length<=1?t:e.jsx(e.Fragment,{children:i.map((r,o)=>r.startsWith("`")&&r.endsWith("`")&&r.length>2?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:r.slice(1,-1)},o):e.jsx("span",{children:r},o))})}function Xt(t){return t.split(/(`[^`\n]+`)/g).map((r,o)=>r.startsWith("`")&&r.endsWith("`")&&r.length>2?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:r.slice(1,-1)},o):r.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((n,l)=>n.startsWith("**")&&n.endsWith("**")&&n.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:n.slice(2,-2)},`${o}-${l}`):n.startsWith("*")&&n.endsWith("*")&&n.length>2?e.jsx("em",{children:n.slice(1,-1)},`${o}-${l}`):e.jsx("span",{children:n},`${o}-${l}`)))}function rs(t){if(t.length<2)return null;const i=n=>n.replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim()),r=i(t[0]),o=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(o))return null;const s=t.slice(2).map(i);return{headers:r,rows:s}}function ns(t,i){const r=o=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:o?600:400,color:o?"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((o,s)=>e.jsx("th",{style:r(!0),children:Xt(o)},s))})}),e.jsx("tbody",{children:i.map((o,s)=>e.jsx("tr",{style:{background:s%2===0?"transparent":"rgba(0,0,0,0.015)"},children:o.map((n,l)=>e.jsx("td",{style:r(!1),children:Xt(n)},l))},s))})]})})}function mr(t){const i=t.split(`
33
+ `),r=[];let o=0,s=0;for(;o<i.length;)if(i[o].trimStart().startsWith("|")&&o+1<i.length&&/^\|[\s\-:|]+\|$/.test(i[o+1].trim())){const n=[];for(;o<i.length&&i[o].trimStart().startsWith("|");)n.push(i[o].trim()),o++;const l=rs(n);l?r.push(e.jsx("div",{children:ns(l.headers,l.rows)},`tbl-${s++}`)):r.push(e.jsx("span",{children:n.map((c,x)=>e.jsxs("span",{children:[ts(c),x<n.length-1?`
34
+ `:null]},x))},`tbl-fb-${s++}`))}else{const n=[];for(;o<i.length&&!(i[o].trimStart().startsWith("|")&&o+1<i.length&&/^\|[\s\-:|]+\|$/.test(i[o+1].trim()));)n.push(i[o]),o++;n.length>0&&r.push(e.jsx("span",{children:n.map((l,c)=>e.jsxs("span",{children:[Xt(l),c<n.length-1?`
35
+ `:null]},c))},`txt-${s++}`))}return e.jsx(e.Fragment,{children:r})}function ss({selectedProjectId:t=null,selectedSessionId:i=null,onSessionCreated:r,onMessageSent:o,onSubSessionCreated:s,onSelectSession:n,onSubAgentEvent:l,onRunComplete:c,sessionTitle:x,onOpenSettings:p,settingsOpen:v=!1,onHideToBackground:m,onToggleAppearance:S,appearanceOpen:w=!1,hideToBackgroundTitle:E,voiceCommand:T=null}){const{messages:k,runningSessionId:R,appendText:u,addMessage:f,setRunningSession:B,setSessionId:P,updateToolResult:X,updateSubAgentStatus:A,updateSubAgentProgress:W,updateMessage:I,setMessages:M,getMessagesForSession:Y,contextUsageBySession:ce,setContextUsage:$e,clearMessages:q,sessionId:ue,todos:Re,setTodos:Ie,cronTasks:Ce,setCronTasks:ge}=Fe(),{isConfigured:ne,profiles:Be,activeProfileId:Me,switchActiveProfile:ot,loadFromSystem:b,contextWindow:F}=Dt(),oe=g.useRef(new Set),ee=i||ue,H=!!(ee&&(R===ee||oe.current.has(ee)));g.useEffect(()=>{b()},[]),g.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(a=>ge(a))},[]);const[J,be]=g.useState(""),xe=Zn(),[ze,He]=g.useState(!1),[Ve,ie]=g.useState(null),[Ne,pt]=g.useState([]),[Ue,gt]=g.useState([]),It=g.useRef(null),Qe=g.useRef(null),it=g.useRef(null),Ge=g.useRef(null),[We,xt]=g.useState(null),[at,lt]=g.useState([]),[Ct,ht]=g.useState([]),[ae,Ye]=g.useState([]),[ve,_e]=g.useState(null),[De,Le]=g.useState(null),[ft,zt]=g.useState(new Set),[Pe,Oe]=g.useState("idle"),[Xe,mt]=g.useState(!1),[Ze,et]=g.useState(null),tt=g.useRef(null);g.useEffect(()=>{const a=window.agentApi;if(!(a!=null&&a.onTtsStart)||!a.onTtsPcm||!a.onTtsStreamEnd||!a.onTtsFlush)return;const h=new En(a),j=[a.onTtsStart(y=>h.start(y)),a.onTtsPcm(({generation:y,pcm:N})=>h.enqueue(y,N)),a.onTtsStreamEnd(({generation:y})=>h.finish(y)),a.onTtsFlush(({generation:y})=>h.flush(y)),a.onTtsEnd(()=>et(null))];return()=>{for(const y of j)y();h.dispose()}},[]);const At=()=>{var j;if(Xe){(j=tt.current)==null||j.stop(),tt.current=null,mt(!1);return}Wt(window.agentApi,vt);const a=J?`${J.trimEnd()} `:"",h=Tn({onInterim:y=>be(a+y),onFinal:y=>{var N;be(a+y),(N=it.current)==null||N.focus()},onError:y=>ie(y),onEnd:()=>{mt(!1),tt.current=null}});h&&(tt.current=h,mt(!0))},Tt=async(a,h)=>{var j;if(Ze===a){await Wt(window.agentApi,vt),et(null);return}if(await Wt(window.agentApi,vt),!((j=window.agentApi)!=null&&j.ttsSpeak)){ie("TTS 模型服务不可用");return}et(a);try{(await window.agentApi.ttsSpeak(h)).ok||(et(null),ie("TTS 模型播报失败"))}catch(y){et(null),ie(y instanceof Error?y.message:"TTS 模型播报失败")}},d=g.useRef(null),C=g.useRef(!1),D=g.useRef(i??null),$=g.useRef(null),_=g.useRef(0);g.useEffect(()=>{D.current=i??null},[i]),g.useEffect(()=>{$.current=ue},[ue]),g.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(a=>lt(a)),window.agentApi.listSkills().then(a=>ht(a.filter(h=>h.name))).catch(a=>console.error("[listSkills] mount error:",a)))},[]);const V=ve===null?[]:at.filter(a=>ve===""||a.name.toLowerCase().includes(ve.toLowerCase())),pe=De===null?[]:[...[{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(a=>De===""||a.name.toLowerCase().includes(De.toLowerCase())),...Ct.filter(a=>De===""||a.name.toLowerCase().includes(De.toLowerCase()))],Se=a=>{Ye(h=>h.find(j=>j.id===a.id)?h:[...h,a]),be(h=>h.replace(/@[\w\u4e00-\u9fff]*$/,"")),_e(null),setTimeout(()=>{var h;return(h=it.current)==null?void 0:h.focus()},0)},we=a=>{Ye(h=>h.filter(j=>j.id!==a))},ye=a=>{be(h=>h.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${a.name} `)),Le(null),setTimeout(()=>{var h;return(h=it.current)==null?void 0:h.focus()},0)},Fr=a=>{const h=Array.from(a.target.files??[]);h.length>0&&pt(j=>[...j,...h]),a.target.value=""},$r=a=>{pt(h=>h.filter((j,y)=>y!==a))},Nr=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Ur=a=>Nr.test(a),nr=a=>{gt(h=>[...h,a])},_r=a=>{gt(h=>h.filter((j,y)=>y!==a))},sr=a=>new Promise((h,j)=>{const y=new FileReader;y.onload=()=>h(y.result),y.onerror=j,y.readAsDataURL(a)}),Or=async()=>{try{const a=await navigator.clipboard.read();for(const h of a){const j=h.types.find(y=>y.startsWith("image/"));if(j){const y=await h.getType(j);nr(await sr(y));break}}}catch{}};g.useEffect(()=>{const a=async h=>{if(!h.clipboardData)return;const j=Array.from(h.clipboardData.items).find(N=>N.type.startsWith("image/"));if(!j)return;h.preventDefault();const y=j.getAsFile();y&&nr(await sr(y))};return window.addEventListener("paste",a),()=>window.removeEventListener("paste",a)},[Be,Me]),g.useEffect(()=>{var a;(a=It.current)==null||a.scrollIntoView({behavior:"smooth"})},[k]),g.useEffect(()=>window.agentApi?window.agentApi.onEvent(h=>Hr(h)):void 0,[ue]),g.useEffect(()=>{const a=++_.current,h=i,j=()=>_.current===a&&D.current===h;return(async()=>{var N,O;if(window.agentApi&&!Qn(d.current,$.current,h)){if(!h){if(!j())return;q(),ie(null),$.current=null,P("");return}ie(null);try{const L=await window.agentApi.getSession(h),Q=(L==null?void 0:L.messages)??[],le=yn((L==null?void 0:L.events)??[]),Z=new Map;for(const z of(L==null?void 0:L.events)??[])z.type==="tool_result"&&((N=z.result)!=null&&N.toolCallId)&&Z.set(z.result.toolCallId,{content:z.result.content??"",isError:z.result.isError});const me=Q.filter(z=>(z.role==="user"||z.role==="assistant"||z.role==="tool")&&z.name!=="__interrupt__").map(z=>{if(z.name==="__compaction_checkpoint__"){let G="";try{G=JSON.parse(z.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:G,name:z.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:crypto.randomUUID(),role:z.role,content:z.content??"",toolCalls:z.toolCalls&&z.toolCalls.length>0?z.toolCalls:void 0,toolCallId:z.toolCallId,name:z.name,timestamp:Date.now()}}),se=(()=>{var Ae;let z="";const G=[];for(const te of(L==null?void 0:L.events)??[])if(te.type==="text_chunk"&&te.text&&(z+=te.text),te.type==="tool_call"&&te.toolCall&&G.push({id:te.toolCall.id,name:te.toolCall.name,arguments:te.toolCall.arguments}),te.type==="tool_result"&&((Ae=te.result)!=null&&Ae.toolCallId)){const Te=G.find(ke=>{var je;return ke.id===((je=te.result)==null?void 0:je.toolCallId)});Te&&(Te.result=te.result.content??"",Te.isError=te.result.isError)}return!z.trim()&&G.length===0?[]:[{id:crypto.randomUUID(),role:"assistant",content:z.trim(),toolCalls:G.length>0?G:void 0,timestamp:Date.now()}]})();let de=me.filter(z=>z.role!=="tool").map(z=>{var G;if(z.isCompactionSummary)return z;if(z.role==="assistant"&&((G=z.toolCalls)!=null&&G.length)){const Ae=z.toolCalls.map(te=>{const Te=me.find(je=>je.role==="tool"&&je.toolCallId===te.id);if(Te)return{...te,result:Te.content};const ke=Z.get(te.id);return ke?{...te,result:ke.content,isError:ke.isError}:te});return{...z,toolCalls:Ae}}return z.role==="user"&&z.name&&z.name!=="__compaction_checkpoint__"?{...z,agentName:z.name}:z});if(!de.some(z=>z.role==="assistant"&&!z.isCompactionSummary)&&se.length>0){const z=de.findLastIndex(G=>G.role==="user"&&!G.isCompactionSummary);de=z>=0?[...de.slice(0,z+1),...se,...de.slice(z+1)]:[...de,...se]}if(!j())return;const re=Y(h),he=re.length>0&&Fe.getState().runningSessionId===h?re:de;M(he,h),le&&$e(le,h),$.current=h,P(h);const fe=he[he.length-1];if((fe==null?void 0:fe.role)==="assistant"&&((O=fe.toolCalls)!=null&&O.length)){const z=fe.toolCalls.every(G=>G.result);Oe(z?"thinking":"tools")}else Oe("idle")}catch(L){if(!j())return;console.error("[chat] failed to restore session",{sessionId:h,error:L}),q(h),ie(L instanceof Error?L.message:"会话加载失败")}}})(),()=>{_.current===a&&(_.current+=1)}},[q,Y,R,i,$e,M,P]);const Hr=a=>{var N;const h=D.current||$.current,j=a._sid||h||void 0,y=!j||j===h;switch(a.type){case"context_usage":a.usage&&$e(a.usage,j);break;case"text_chunk":a.text&&(u(a.text,j),y&&Oe("thinking"));break;case"tool_call":y&&Oe("tools"),a.toolCall&&a.toolCall.name!=="dispatch_agent"&&a.toolCall.name!=="ask_user"&&a.toolCall.name!=="show_widget"&&f({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:a.toolCall.id,name:a.toolCall.name,arguments:a.toolCall.arguments}],timestamp:Date.now()},j);break;case"tool_result":a.result&&X(a.result.toolCallId,a.result.content,a.result.isError,j);break;case"todo_update":a.todos&&Ie(a.todos);break;case"cron_update":a.tasks&&ge(a.tasks);break;case"agent_dispatch":if(f({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:a.agentName,task:a.task??"",subSessionId:a.subSessionId}}],timestamp:Date.now()},j),a.subSessionId){oe.current.add(a.subSessionId);const O=d.current||ue;O&&s&&s(O)}l==null||l({type:"started",agentName:a.agentName??"",task:a.task??"",subSessionId:a.subSessionId});break;case"agent_done":a.subSessionId&&(oe.current.delete(a.subSessionId),A(a.subSessionId,a.status??"completed",a.status==="failed"?a.error:a.summary,j)),l==null||l({type:a.status==="failed"?"failed":"completed",agentName:a.agentName??"",task:a.task??"",subSessionId:a.subSessionId});break;case"agent_progress":a.subSessionId&&a.text&&W(a.subSessionId,a.text,j);break;case"compacted":f({id:crypto.randomUUID(),role:"assistant",content:a.summary??"",isCompactionSummary:!0,timestamp:Date.now()},j);break;case"show_widget":{const O=a.data??a.widgetData,L={widgetId:a.widgetId,widgetType:a.widgetType,data:O??{}},le=(j?Fe.getState().getMessagesForSession(j):Fe.getState().messages).find(Z=>{var me;return((me=Z.widget)==null?void 0:me.widgetId)===L.widgetId});le?I(le.id,Z=>({...Z,widget:L}),j):f({id:crypto.randomUUID(),role:"assistant",content:"",widget:L,timestamp:Date.now()},j);break}case"ask_user":f({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:a.questionId??"",question:a.question??"",options:a.options,fields:a.fields,multiSelect:a.multiSelect},timestamp:Date.now()},j);break;case"text_done":break;case"thinking":y&&Oe("thinking");break;case"done":if(y&&!Fe.getState().messages.some(O=>O.isQueued)&&B(null),y&&(Oe("idle"),Ee.getState().autoSpeak)){const L=[...Fe.getState().messages].reverse().find(Q=>Q.role==="assistant"&&Q.content&&!Q.isCompactionSummary);L!=null&&L.content&&(N=window.agentApi)!=null&&N.ttsSpeak&&(vt(),window.agentApi.ttsSpeak(L.content.slice(0,600)).then(Q=>{Q.ok||ie("TTS 模型播报失败")}).catch(Q=>{ie(Q instanceof Error?Q.message:"TTS 模型播报失败")}))}break;case"error":y&&(ie(a.message??"Unknown error"),B(null),Oe("idle"));break}},$t=()=>{C.current=!0,window.agentApi&&window.agentApi.abort(),d.current=null,B(null),oe.current.clear()},or=async a=>{const h=i||ue;if(!h||!window.agentApi)return;const j=Fe.getState().messages.find(y=>y.id===a);if(!(!j||!j.isQueued))try{await window.agentApi.steer(j.content,h,j.agentName),I(a,y=>({...y,isQueued:!1,isSteered:!0}))}catch(y){ie(y instanceof Error?y.message:"引导失败")}},Nt=async(a,h,j)=>{C.current=!1,d.current=h,B(h);try{window.agentApi&&await window.agentApi.run(a.content,h,j,a.agentName,a.images)}catch(y){ie(y instanceof Error?y.message:"Agent run failed")}finally{const y=C.current?void 0:Fe.getState().messages.find(N=>N.isQueued);y?(I(y.id,N=>({...N,isQueued:!1})),c&&c(t,h),Nt(y,h)):(d.current=null,B(null),c&&c(t,h))}},Rt=async()=>{if(!J.trim()||!ne)return;Wt(window.agentApi,vt),ie(null);const a=J.trim();if(/^\/loop\b/i.test(a)){const L=a.slice(5).trim();if(be(""),f({id:crypto.randomUUID(),role:"user",content:a,timestamp:Date.now()}),/^stop$/i.test(L)){window.agentApi&&(await window.agentApi.cronDeleteAll(),ge([]),f({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(L)||L===""){if(window.agentApi){const se=await window.agentApi.cronList();ge(se);const de=se.length===0?"当前没有定时任务。":se.map((re,K)=>`**${K+1}.** \`${re.id.slice(0,6)}\` · ${Vt(re.cron)} · ${re.enabled?"▶ 启用":"⏸ 已暂停"}
36
+ ${re.prompt}`).join(`
37
+
38
+ `);f({id:crypto.randomUUID(),role:"assistant",content:de,timestamp:Date.now()})}return}const Q=L.match(/^(?:pause|暂停)\s+(\S+)$/i);if(Q){if(window.agentApi){const se=Ce.find(re=>re.id.startsWith(Q[1])),de=await window.agentApi.cronPause((se==null?void 0:se.id)??Q[1]);if(de){const re=await window.agentApi.cronList();ge(re),f({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${de.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else f({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${Q[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const le=L.match(/^(?:resume|恢复)\s+(\S+)$/i);if(le){if(window.agentApi){const se=Ce.find(re=>re.id.startsWith(le[1])),de=await window.agentApi.cronResume((se==null?void 0:se.id)??le[1]);if(de){const re=await window.agentApi.cronList();ge(re),f({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${de.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else f({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${le[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const Z=L.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(Z){if(window.agentApi){const se=Ce.find(re=>re.id.startsWith(Z[1]));if(await window.agentApi.cronDelete((se==null?void 0:se.id)??Z[1])){const re=await window.agentApi.cronList();ge(re),f({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${Z[1]}\` 已删除。`,timestamp:Date.now()})}else f({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${Z[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const me=L.match(/^(\S+)\s+(.+)$/s);if(me){const se=me[1],de=me[2].trim();if(window.agentApi){let re=i||ue;if(!re){const K=await window.agentApi.createSession(de.slice(0,60)||"定时任务",t||void 0);re=K.id,P(K.id),r&&await r(K.id)}try{const K=await window.agentApi.cronCreate(se,de,{sessionId:re}),he=await window.agentApi.cronList();ge(he),f({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${K.id.slice(0,6)}\`),${Vt(se)}执行:${de}`,timestamp:Date.now()})}catch(K){f({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${K instanceof Error?K.message:String(K)}`,timestamp:Date.now()})}}return}f({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 h=a.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(h){const L=h[1]+h[2],Q=h[3].trim();if(Q&&window.agentApi){let le=i||ue;if(!le){const Z=await window.agentApi.createSession(Q.slice(0,60)||"定时任务",t||void 0);le=Z.id,P(Z.id),r&&await r(Z.id)}try{const Z=await window.agentApi.cronCreate(L,Q,{sessionId:le}),me=await window.agentApi.cronList();ge(me),be(""),f({id:crypto.randomUUID(),role:"user",content:a,timestamp:Date.now()}),f({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${Z.id.slice(0,6)}\`),${Vt(L)}执行:${Q}`,timestamp:Date.now()})}catch(Z){f({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${Z instanceof Error?Z.message:String(Z)}`,timestamp:Date.now()})}return}}const j=(()=>{const L=J.trim().match(/^\/([\w-]+)\s*(.*)$/);if(L){const Q=L[1],le=L[2].trim(),Z=Ct.find(me=>me.name===Q);if(Z)return le?`请使用「${Z.name}」技能协助完成:${le}(技能说明:${Z.description})`:`请使用「${Z.name}」技能协助:${Z.description}`}return J.trim()})(),y=ae.length>0?ae.map(L=>L.name).join(", "):void 0,N=Ue.length>0?[...Ue]:void 0,O=ae.map(L=>L.id);if(Ye([]),be(""),pt([]),gt([]),H){f({id:crypto.randomUUID(),role:"user",content:j,timestamp:Date.now(),agentName:y,images:N,isQueued:!0});return}Ie([]);try{const L=await Xn({text:j,projectId:t??null,sessionId:i||ue,createSession:async(Q,le)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(Q,le)},activateSession:Q=>{$.current=Q,P(Q),d.current=Q,B(Q)},showUserMessage:(Q,le)=>f({id:crypto.randomUUID(),role:"user",content:Q,timestamp:Date.now(),agentName:y,images:N},le),onSessionCreated:r});o&&o(L,j),await Nt({content:j,agentName:y,images:N},L,O.length>0?O:void 0)}catch(L){ie(L instanceof Error?L.message:"Agent run failed")}};return g.useEffect(()=>{if(!T||!window.agentApi)return;const{text:a,projectId:h,sessionId:j}=T;let y=!1;return(async()=>{try{Ie([]);const N=await Yn({text:a,projectId:h,sessionId:j,createSession:async(O,L)=>await window.agentApi.createSession(O,L),activateSession:O=>{$.current=O,P(O),d.current=O,B(O)},showUserMessage:(O,L)=>f({id:crypto.randomUUID(),role:"user",content:O,timestamp:Date.now()},L),onSessionCreated:r,isCancelled:()=>y});if(!N)return;o&&o(N,a),await Nt({content:a},N)}catch(N){ie(N instanceof Error?N.message:"语音指令执行失败")}})(),()=>{y=!0}},[T==null?void 0:T.nonce]),e.jsxs("div",{className:"chat-view",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:x?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:x||"会话"}),p&&m&&S&&e.jsx(Vn,{appearanceOpen:w,settingsOpen:v,hideToBackgroundTitle:E,onHideToBackground:m,onToggleAppearance:S,onOpenSettings:p})]}),e.jsxs("div",{className:"chat-messages",style:{flex:1,overflow:"auto",padding:"var(--chat-messages-padding)"},children:[k.length===0&&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:ne?"有什么我能帮你的?工具、记忆和技能随时待命。":"请先在设置中配置 API Key 以开始使用。"})]}),k.map((a,h)=>{var Z,me,se,de,re;const j=a;if(j.isQueued)return null;const y=a.role==="user";if(j.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)"}})]},a.id);if(j.widget){const K=Jn[j.widget.widgetType];return K?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(K,{...j.widget.data,widgetId:j.widget.widgetId})},a.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(j.widget.data,null,2)},a.id)}if(j.askUser)return e.jsx(Un,{questionId:j.askUser.questionId,question:j.askUser.question,options:j.askUser.options,fields:j.askUser.fields,multiSelect:j.askUser.multiSelect,answered:j.askUser.answered,answer:j.askUser.answer,onAnswer:(K,he)=>{var fe;I(a.id,z=>({...z,askUser:{...z.askUser,answered:!0,answer:K}})),(fe=window.agentApi)==null||fe.answerQuestion(j.askUser.questionId,K,he)}},a.id);const N=j.agentName?j.agentName.charAt(0).toUpperCase():"你",O=!y&&h===k.length-1,L=H&&O,Q=k[h+1],le=Q&&Q.role!==a.role&&!Q.isCompactionSummary;return e.jsxs("div",{className:"chat-message-group",style:{marginBottom:le?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:[L&&e.jsx("div",{style:{display:"flex",paddingLeft:"calc(var(--chat-avatar-size) + var(--chat-row-gap))",marginBottom:4},children:e.jsx(fr,{activity:Pe==="tools"?"tools":"thinking"})}),e.jsxs("div",{className:`chat-message-row chat-message-row--${y?"user":"assistant"}`,style:{display:"flex",flexDirection:y?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[y?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:N}):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--${y?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:y?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${y?"user":"assistant"} ${a.role==="assistant"&&a.content?"message-card":""}`,style:{padding:a.content||y&&((Z=j.images)!=null&&Z.length)?y?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:y?"14px 4px 14px 14px":"4px 14px 14px 14px",background:a.content||y&&((me=j.images)!=null&&me.length)?y?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:a.content||y&&((se=j.images)!=null&&se.length)?y?"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:[y&&j.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"})]}),j.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:a.content})]}):a.role==="assistant"&&a.content?(()=>{const he=a.content.length>500,fe=ft.has(a.id),z=he&&!fe?a.content.slice(0,500):a.content;return e.jsxs("div",{children:[e.jsxs("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",position:"relative"},children:[y?z:mr(z),he&&!fe&&e.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:40,background:y?"linear-gradient(transparent, rgba(232, 236, 254, 0.95))":"linear-gradient(transparent, var(--bg-surface))",pointerEvents:"none"}})]}),he&&e.jsxs("button",{onClick:()=>zt(G=>{const Ae=new Set(G);return fe?Ae.delete(a.id):Ae.add(a.id),Ae}),style:{display:"flex",alignItems:"center",gap:4,marginTop:6,padding:"3px 10px",borderRadius:20,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)"},onMouseEnter:G=>{G.currentTarget.style.background="var(--accent-dim)",G.currentTarget.style.color="var(--accent)",G.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},onMouseLeave:G=>{G.currentTarget.style.background="var(--bg-deep)",G.currentTarget.style.color="var(--text-muted)",G.currentTarget.style.borderColor="var(--border-default)"},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{transform:fe?"rotate(180deg)":"none",transition:"transform 0.2s"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})}),fe?"收起":`展开全文(还有 ${a.content.length-500} 字)`]})]})})():a.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:y?a.content:mr(a.content)}),y&&j.images&&j.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:a.content?8:0},children:j.images.map((K,he)=>e.jsx("img",{src:K,alt:`attachment-${he}`,style:{maxWidth:220,maxHeight:180,objectFit:"cover",borderRadius:6,border:"1px solid var(--border-subtle)",display:"block",cursor:"zoom-in"},onClick:()=>window.open(K,"_blank")},he))}),(de=a.toolCalls)==null?void 0:de.map((K,he)=>{let fe;if(K.name==="write_file"&&K.arguments.file_path){const z=K.arguments.file_path;e:for(let G=h;G>=0;G--){const te=k[G].toolCalls;if(!te)continue;const Te=G===h?he-1:te.length-1;for(let ke=Te;ke>=0;ke--){const je=te[ke];if(je.name==="read_file"&&je.arguments.file_path===z&&je.result&&!je.isError){fe=je.result;break e}}}}return e.jsx(Nn,{toolCall:K,beforeContent:fe,onSelectSession:n},K.id)}),(()=>{const K=(a.toolCalls??[]).filter(z=>z.name==="write_file"&&z.result&&!z.isError);if(K.length===0)return null;const he=new Map;for(const z of K){const G=z.arguments.file_path??"",Ae=z.arguments.content??"",te=Ae?Ae.split(`
39
+ `).length:0;let Te=0;e:for(let ke=h;ke>=0;ke--){const je=k[ke].toolCalls??[];for(let Ut=je.length-1;Ut>=0;Ut--){const bt=je[Ut];if(bt.name==="read_file"&&bt.arguments.file_path===G&&bt.result&&!bt.isError){Te=bt.result.split(`
40
+ `).length;break e}}}he.set(G,{path:G,lines:te,added:Math.max(0,te-Te),removed:Math.max(0,Te-te)})}const fe=[...he.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:"变更汇总"}),fe.map(z=>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:z.path,children:z.path.replace(/\\/g,"/").split("/").pop()}),z.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",z.added]}),z.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",z.removed]}),z.added===0&&z.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[z.lines,"行"]})]},z.path))]})})()]}),a.role==="assistant"&&a.content&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[typeof((re=window.agentApi)==null?void 0:re.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>Tt(a.id,a.content),title:Ze===a.id?"停止播报":"语音播报","aria-label":Ze===a.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${Ze===a.id?"is-active":""}`,children:Ze===a.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"})]})}),e.jsx("button",{type:"button",onClick:()=>{var K;(K=navigator.clipboard)==null||K.writeText(a.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"})]})})]}),y&&(j.isQueued||j.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[j.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"})]}),"排队中"]}),e.jsxs("button",{onClick:()=>void or(a.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:K=>{K.currentTarget.style.background="rgba(79,110,247,0.18)",K.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:K=>{K.currentTarget.style.background="var(--accent-dim)",K.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"})]}),"引导"]})]}),j.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"})}),"已引导"]})]})]})]})]},a.id)}),H&&k.length>0&&k[k.length-1].role==="user"&&!k[k.length-1].isQueued&&e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"4px 0 4px",animation:"fadeInUp 0.3s var(--ease-out)"},children:[e.jsx("div",{style:{width:30,height:30,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.jsx(fr,{activity:Pe==="tools"?"tools":"thinking"})]}),Ve&&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:Ve}),e.jsx("div",{ref:It})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-deepest)",borderTop:"1px solid var(--border-subtle)"},children:[Re.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 a=new Set(Re.filter(h=>h.status==="completed").map(h=>h.title.toLowerCase()));return Re.map(h=>{const j=h.status==="pending",y=h.status==="in-progress",N=h.status==="completed",O=j&&(h.dependsOn??[]).some(L=>!a.has(L.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:N?.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:N?"rgba(52,211,153,0.15)":y?"var(--accent-dim)":O?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:N?"1.5px solid rgba(52,211,153,0.6)":y?"1.5px solid var(--accent)":O?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[N&&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"})}),y&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),O&&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"})}),j&&!O&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:N?"var(--text-muted)":O?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:N?"line-through":"none",flex:1},children:h.title}),O&&e.jsx("span",{title:`等待: ${(h.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:"等待前置"}),h.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:["@",h.agentName]})]},h.id)})})()})]}),Ce.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(),ge([]),f({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:"全部删除"})]}),Ce.map(a=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:a.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:a.enabled?"#22c55e":"#9ca3af",boxShadow:a.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:a.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:a.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.label||a.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:a.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[a.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(a.id);const h=await window.agentApi.cronList();ge(h)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:h=>{h.currentTarget.style.borderColor="#d97706",h.currentTarget.style.color="#d97706"},onMouseLeave:h=>{h.currentTarget.style.borderColor="var(--border-default)",h.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(a.id);const h=await window.agentApi.cronList();ge(h)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:h=>{h.currentTarget.style.borderColor="#22c55e",h.currentTarget.style.color="#22c55e"},onMouseLeave:h=>{h.currentTarget.style.borderColor="var(--border-default)",h.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(a.id);const h=await window.agentApi.cronList();ge(h)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:h=>{h.currentTarget.style.borderColor="var(--danger)",h.currentTarget.style.color="var(--danger)"},onMouseLeave:h=>{h.currentTarget.style.borderColor="var(--border-default)",h.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},a.id))]}),Ne.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:Ne.map((a,h)=>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:a.name}),e.jsx("button",{onClick:()=>$r(h),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:"✕"})]},h))}),Ue.length>0&&(()=>{const a=Be.find(j=>j.id===Me),h=!a||!Ur(a.modelId);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[h&&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"})]}),"当前模型(",(a==null?void 0:a.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Ue.map((j,y)=>e.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[e.jsx("img",{src:j,alt:`image-${y}`,style:{width:72,height:72,objectFit:"cover",borderRadius:8,border:"1.5px solid var(--border-default)",display:"block"}}),e.jsx("button",{onClick:()=>_r(y),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:"✕"})]},y))})]})})(),(()=>{const a=k.filter(h=>h.isQueued);return a.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"})]}),"排队消息(",a.length,")"]}),a.map(h=>{const j=h,y=j.content.length>80?j.content.slice(0,80)+"…":j.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:[j.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:["@",j.agentName]}),y]}),e.jsxs("button",{onClick:()=>void or(h.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:N=>{N.currentTarget.style.background="rgba(79,110,247,0.18)",N.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:N=>{N.currentTarget.style.background="var(--accent-dim)",N.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"})]}),"引导"]})]},h.id)})]})})(),e.jsx("div",{ref:Ge,style:{position:"relative"},children:e.jsxs("div",{className:"composer-shell",style:{display:"flex",flexDirection:"column",gap:0,background:"var(--bg-surface)",borderRadius:14,overflow:"visible"},children:[e.jsx(Hn,{usage:ee?ce[ee]:void 0,contextWindowK:F,compact:xe}),Be.length>0&&(()=>{const a=[],h={};for(const y of Be)h[y.provider]||(a.push(y.provider),h[y.provider]=[]),h[y.provider].push(y);const j={anthropic:"Anthropic",openai:"OpenAI",deepseek:"DeepSeek"};return e.jsx("div",{style:{display:"flex",alignItems:"center",gap:0,padding:"5px 10px 4px",borderBottom:"1px solid var(--border-subtle)",overflowX:"auto",scrollbarWidth:"none"},children:a.map((y,N)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,paddingLeft:N>0?10:0,marginLeft:N>0?8:0,borderLeft:N>0?"1px solid var(--border-subtle)":"none",flexShrink:0},children:[e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",opacity:.6,flexShrink:0,letterSpacing:"0.03em",textTransform:"uppercase",fontWeight:500},children:j[y]??y}),h[y].map(O=>{const L=O.id===Me;return e.jsx("button",{onClick:()=>ot(O.id),title:`${O.provider} · ${O.modelId}`,style:{padding:"3px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,fontWeight:L?600:400,cursor:"pointer",whiteSpace:"nowrap",transition:"all 0.15s",flexShrink:0},children:O.name||O.modelId},O.id)})]},y))})})(),e.jsxs("div",{className:"composer-input-row",style:{display:"flex",alignItems:"center",gap:8,padding:"var(--composer-row-padding)"},children:[e.jsx("input",{ref:Qe,type:"file",multiple:!0,style:{display:"none"},onChange:Fr}),xe?e.jsxs("div",{className:"web-native-add-wrap",children:[e.jsx("button",{type:"button",className:"web-native-add-button","aria-label":"添加附件、图片或语音","aria-expanded":ze,onClick:()=>He(a=>!a),children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})}),ze&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var a;He(!1),(a=Qe.current)==null||a.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{He(!1),At()},children:"语音输入"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{var a;return(a=Qe.current)==null?void 0:a.click()},disabled:!ne||H,title:"添加附件",className:"ui-icon-button",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",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("button",{onClick:At,disabled:!ne,className:`ui-icon-button ${Xe?"mic-recording":""}`,title:Rr()?Xe?"停止录音":"语音输入":"当前环境不支持语音输入",style:Xe?{background:"rgba(244,63,94,0.12)",color:"var(--danger)"}:void 0,children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",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.jsxs("button",{onClick:()=>void Or(),disabled:!ne||H,title:"粘贴截图(需先 Cmd+Shift+4 截图至剪贴板)",className:`ui-icon-button ${Ue.length>0?"is-active":""}`,style:{position:"relative"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),e.jsx("circle",{cx:"9",cy:"9",r:"2"}),e.jsx("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]}),Ue.length>0&&e.jsx("span",{style:{position:"absolute",top:1,right:1,width:14,height:14,borderRadius:"50%",background:"var(--accent)",color:"#fff",fontSize:9,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:Ue.length})]})]}),ae.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:ae.map(a=>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"})]}),"@",a.name,e.jsx("button",{onClick:()=>we(a.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},a.id))}),e.jsx("input",{className:"composer-text-input",ref:it,value:J,onChange:a=>{var N,O;const h=a.target.value;be(h);const j=h.match(/@([\w\u4e00-\u9fff]*)$/);if(j){window.agentApi&&window.agentApi.listAgentDefs().then(L=>lt(L)),xt(((N=Ge.current)==null?void 0:N.getBoundingClientRect())??null),_e(j[1]),Le(null);return}const y=h.match(/\/([-\w\u4e00-\u9fff]*)$/);if(y){window.agentApi&&window.agentApi.listSkills().then(L=>ht(L.filter(Q=>Q.name))).catch(L=>console.error("[listSkills] slash error:",L)),xt(((O=Ge.current)==null?void 0:O.getBoundingClientRect())??null),Le(y[1]),_e(null);return}_e(null),Le(null)},onBlur:()=>setTimeout(()=>{_e(null),Le(null)},120),onKeyDown:a=>{a.key==="Escape"&&(ve!==null||De!==null)?(a.preventDefault(),_e(null),Le(null)):a.key==="Escape"&&H?(a.preventDefault(),$t()):a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),Rt())},placeholder:ne?H?"排队发送消息…":"发送消息… (@智能体 /技能)":"请先在设置中配置 API Key",disabled:!ne,style:{flex:1,padding:"7px 4px",border:"none",background:"transparent",color:"var(--text-primary)",fontSize:14,outline:0,boxShadow:"none",fontFamily:"var(--font-body)",letterSpacing:"0.01em"}}),xe?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Rt,disabled:!ne||!J.trim(),className:"web-native-send-button","aria-label":H?"排队发送":"发送",title:H?"排队发送":"发送",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"})})}),H&&e.jsx("button",{type:"button",onClick:$t,className:"web-native-stop-button","aria-label":"停止生成",title:"停止生成",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})})]}):H?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:Rt,disabled:!ne||!J.trim(),title:"排队发送(等当前对话结束后自动执行)",style:{height:34,padding:"0 14px",borderRadius:10,border:"none",background:ne&&J.trim()?"var(--accent)":"var(--bg-deep)",color:ne&&J.trim()?"var(--text-inverse)":"var(--text-muted)",fontSize:13,fontWeight:600,cursor:ne&&J.trim()?"pointer":"not-allowed",transition:"all 0.2s var(--ease-out)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",flexShrink:0,letterSpacing:"0.02em"},children:["排队",e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),e.jsx("button",{onClick:$t,title:"停止生成 (Esc)",style:{height:34,width:34,borderRadius:10,border:"none",background:"rgba(244,63,94,0.12)",color:"var(--danger)",cursor:"pointer",transition:"all 0.2s var(--ease-out)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.background="rgba(244,63,94,0.22)"},onMouseLeave:a=>{a.currentTarget.style.background="rgba(244,63,94,0.12)"},children:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})})]}):e.jsxs("button",{onClick:Rt,disabled:!ne||!J.trim(),style:{height:34,padding:"0 16px",borderRadius:10,border:"none",background:ne&&J.trim()?"var(--accent)":"var(--bg-deep)",color:ne&&J.trim()?"var(--text-inverse)":"var(--text-muted)",fontSize:13,fontWeight:600,cursor:ne&&J.trim()?"pointer":"not-allowed",transition:"all 0.2s var(--ease-out)",boxShadow:ne&&J.trim()?"0 2px 10px var(--accent-glow)":"none",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",flexShrink:0,letterSpacing:"0.02em"},children:["发送",e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",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 发送",H?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",Xe?" · 🎤 正在聆听…":""]})]}),We&&ve!==null&&V.length>0&&ct.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-We.top+8,left:We.left,width:We.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:"智能体"}),V.map(a=>e.jsxs("button",{onMouseDown:h=>{h.preventDefault(),Se(a)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:h=>{h.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:h=>{h.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",a.name]}),a.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:a.description})]},a.id))]}),document.body),We&&De!==null&&pe.length>0&&ct.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-We.top+8,left:We.left,width:We.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:["技能 (",pe.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:pe.map(a=>e.jsxs("button",{onMouseDown:h=>{h.preventDefault(),ye(a)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:h=>{h.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:h=>{h.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",a.name]}),a.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]},a.name))})]}),document.body)]})}const os=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],br={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function vr(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function is(){const{maxIterations:t,contextWindow:i,isConfigured:r,profiles:o,activeProfileId:s,setField:n,loadFromSystem:l,saveToSystem:c,addProfile:x,updateProfile:p,deleteProfile:v,switchActiveProfile:m}=Dt(),[S,w]=g.useState(null),[E,T]=g.useState("success"),[k,R]=g.useState(null),[u,f]=g.useState(!1),[B,P]=g.useState(vr());g.useEffect(()=>{l()},[]);const X=()=>{f(!0),R(null),P(vr())},A=q=>{f(!1),R(q.id),P({name:q.name,provider:q.provider,modelId:q.modelId,apiKey:q.apiKey,baseUrl:q.baseUrl})},W=()=>{R(null),f(!1)},I=async()=>{if(!B.name.trim()||!B.apiKey.trim()||!B.modelId.trim()){w("名称、API Key 和模型 ID 为必填项"),T("error");return}u?x(B):k&&p(k,B),R(null),f(!1),w(null),setTimeout(()=>c(),0)},M=async q=>{v(q),setTimeout(()=>c(),0)},Y=async q=>{await m(q),w("已切换模型"),T("success"),setTimeout(()=>w(null),1500)},ce=async()=>{w(null);try{await c(),w("设置保存成功"),T("success")}catch(q){w(q instanceof Error?q.message:"保存失败"),T("error")}},$e=u||k!==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",{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:X,style:ls,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[o.length===0&&!$e&&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:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),o.map(q=>{const ue=q.id===s,Re=q.id===k;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${ue?"var(--accent)":"var(--border-default)"}`,background:ue?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{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:ue?"var(--accent)":"var(--bg-deep)",color:ue?"#fff":"var(--text-muted)",flexShrink:0},children:q.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:q.name||q.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[q.modelId," ",q.baseUrl?`· ${q.baseUrl}`:""]})]}),ue&&e.jsx("span",{style:{fontSize:11,color:"var(--accent)",fontWeight:600,flexShrink:0},children:"● 使用中"}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[!ue&&e.jsx("button",{onClick:()=>Y(q.id),style:Kt,children:"切换"}),e.jsx("button",{onClick:()=>Re?W():A(q),style:Kt,children:Re?"收起":"编辑"}),e.jsx("button",{onClick:()=>M(q.id),style:{...Kt,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),Re&&e.jsx(yr,{draft:B,setDraft:P,onSave:I,onCancel:W})]},q.id)}),u&&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:B,setDraft:P,onSave:I,onCancel:W})]})]})]}),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(nt,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:q=>n("maxIterations",parseInt(q.target.value)||10),min:1,max:50,style:st})}),e.jsx(nt,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:i??100,onChange:q=>n("contextWindow",parseInt(q.target.value)||100),min:8,max:2e3,style:st})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:ce,style:Dr,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:r?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:r?"var(--success)":"var(--text-muted)",border:`1px solid ${r?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:r?"● 已连接":"○ 未配置"})]}),S&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:E==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:E==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:E==="success"?"var(--success)":"var(--danger)",fontSize:13},children:S})]})}function yr({draft:t,setDraft:i,onSave:r,onCancel:o}){const s=(n,l)=>i(c=>{const x={...c,[n]:l};return n==="provider"&&!c.modelId&&(x.modelId=br[l]??""),x});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(nt,{label:"名称",children:e.jsx("input",{value:t.name,onChange:n=>s("name",n.target.value),placeholder:"我的 Claude",style:st})}),e.jsx(nt,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:n=>{s("provider",n.target.value),s("modelId",br[n.target.value]??"")},style:st,children:os.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})})]}),e.jsx(nt,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:n=>s("modelId",n.target.value),placeholder:"claude-sonnet-4-6",style:st})}),e.jsx(nt,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:n=>s("apiKey",n.target.value),placeholder:"sk-...",style:st})}),e.jsx(nt,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:n=>s("baseUrl",n.target.value),placeholder:"https://api.anthropic.com",style:st})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:r,style:Dr,children:"保存"}),e.jsx("button",{onClick:o,style:as,children:"取消"})]})]})}function nt({label:t,children:i}){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}),i]})}const st={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"},Dr={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)"},as={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)"},ls={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)"},Kt={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)"},qt={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function ds(){const[t,i]=g.useState([]),[r,o]=g.useState("stdio"),[s,n]=g.useState(qt),[l,c]=g.useState(!1),[x,p]=g.useState({id:!1,command:!1,url:!1}),[v,m]=g.useState({}),[S,w]=g.useState({}),[E,T]=g.useState(new Set),[k,R]=g.useState(null),[u,f]=g.useState(""),[B,P]=g.useState(!1),X=async b=>{var oe;if(!((oe=window.agentApi)!=null&&oe.mcpProbe))return;T(ee=>new Set([...ee,b.id])),w(ee=>{const H={...ee};return delete H[b.id],H});const F=new Promise((ee,H)=>setTimeout(()=>H(new Error("连接超时(15s)")),15e3));try{const ee=await Promise.race([window.agentApi.mcpProbe(b),F]);m(H=>({...H,[b.id]:ee}))}catch(ee){const H=ee instanceof Error?ee.message:String(ee);console.warn(`[MCP] probe failed for ${b.id}:`,H),m(J=>{const be={...J};return delete be[b.id],be}),w(J=>({...J,[b.id]:H})),(b.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(H))&&(f(""),R({server:b}))}finally{T(ee=>{const H=new Set(ee);return H.delete(b.id),H})}};g.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(b=>{i(b),b.filter(F=>F.enabled!==!1).forEach(F=>X(F))}).catch(console.error)},[]);const[A,W]=g.useState(""),[I,M]=g.useState(""),[Y,ce]=g.useState(!1),$e=async()=>{M("");let b;try{b=JSON.parse(A.trim());const F=b.mcpServers??b,oe=Object.entries(F);if(oe.length===0){M("未找到任何服务器");return}ce(!0);const ee=[];for(const[J,be]of oe){const xe=be,ze=xe.name||J,Ve=xe.disabled!==!0;let ie;if(xe.url||xe.type==="streamableHttp"||xe.type==="sse"){const Ne=xe.type==="sse"?"sse":"streamableHttp";ie={id:J,name:ze,transport:Ne,url:xe.url,headers:xe.headers??{},env:xe.env??{},enabled:Ve}}else ie={id:J,name:ze,transport:"stdio",command:xe.command,args:xe.args??[],env:xe.env??{},enabled:Ve};await window.agentApi.mcpSave(ie),ee.push(ie)}const H=await window.agentApi.mcpList();i(H),W(""),ee.filter(J=>J.enabled!==!1).forEach(J=>X(J))}catch(F){M(F instanceof Error?F.message:"JSON 解析失败")}finally{ce(!1)}},q=()=>s.id.trim()!==""&&s.command.trim()!=="",ue=()=>s.id.trim()!==""&&s.url.trim()!=="",Re=b=>{const F={};for(const oe of b.split(`
41
+ `)){const ee=oe.indexOf(":");if(ee<1)continue;const H=oe.slice(0,ee).trim(),J=oe.slice(ee+1).trim();H&&(F[H]=J)}return F},Ie=async()=>{if(p({id:!0,command:!0,url:!0}),!(r==="stdio"&&!q())&&!((r==="sse"||r==="streamableHttp")&&!ue())){c(!0);try{const b=r==="sse"||r==="streamableHttp"?Re(s.headersRaw):{},F=r==="stdio"?{id:s.id,name:s.name||s.id,transport:"stdio",command:s.command,args:s.args.split(" ").filter(Boolean),enabled:!0}:{id:s.id,name:s.name||s.id,transport:r,url:s.url,headers:b,enabled:!0};await window.agentApi.mcpSave(F);const oe=await window.agentApi.mcpList();i(oe),n(qt),p({id:!1,command:!1,url:!1}),X(F)}catch(b){console.error("Failed to save MCP server",b)}finally{c(!1)}}},Ce=async b=>{await window.agentApi.mcpDelete(b),i(t.filter(F=>F.id!==b))},ge=async(b,F)=>{await window.agentApi.mcpSetEnabled(b,F),i(t.map(oe=>oe.id===b?{...oe,enabled:F}:oe))},ne=async()=>{if(!(!k||!u.trim())){P(!0);try{const b=k.server.transport==="streamableHttp"?{...k.server,headers:{...k.server.headers??{},Authorization:`Bearer ${u.trim()}`}}:{...k.server,env:{...k.server.env??{},Authorization:`Bearer ${u.trim()}`}};await window.agentApi.mcpSave(b);const F=await window.agentApi.mcpList();i(F),R(null),f("");const oe=F.find(ee=>ee.id===b.id)??b;X(oe)}finally{P(!1)}}},Be=b=>b==="stdio"?"本地":b==="streamableHttp"?"HTTP":"SSE",Me=b=>b==="stdio"?"#68d391":b==="streamableHttp"?"#f6ad55":"#63b3ed",ot=b=>b==="stdio"?"rgba(154,230,180,0.15)":b==="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(b=>e.jsx("button",{onClick:()=>{o(b),p({id:!1,command:!1,url:!1}),n(F=>({...qt,id:F.id,name:F.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:r===b?"var(--accent)":"transparent",color:r===b?"var(--text-inverse)":"var(--text-muted)"},children:b==="stdio"?"本地 stdio":b==="sse"?"远程 SSE":"HTTP"},b))})]}),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:s.id,onChange:b=>n(F=>({...F,id:b.target.value})),onBlur:()=>p(b=>({...b,id:!0})),placeholder:"服务器 ID *",style:{...Ke,...x.id&&!s.id?Jt:{}}}),x.id&&!s.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:s.name,onChange:b=>n(F=>({...F,name:b.target.value})),placeholder:"显示名称",style:{...Ke,flex:1}})]}),r==="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:s.command,onChange:b=>n(F=>({...F,command:b.target.value})),onBlur:()=>p(b=>({...b,command:!0})),placeholder:"命令(如 npx)*",style:{...Ke,...x.command&&!s.command?Jt:{}}}),x.command&&!s.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:s.args,onChange:b=>n(F=>({...F,args:b.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...Ke,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:s.url,onChange:b=>n(F=>({...F,url:b.target.value})),onBlur:()=>p(b=>({...b,url:!0})),placeholder:r==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...Ke,...x.url&&!s.url?Jt:{}}}),x.url&&!s.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:s.headersRaw,onChange:b=>n(F=>({...F,headersRaw:b.target.value})),placeholder:`access_token: abc123
42
+ Authorization: Bearer sk-...`,rows:3,style:{...Ke,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:Ie,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:A,onChange:b=>{W(b.target.value),M("")},placeholder:`{
43
+ "my-server": {
44
+ "command": "npx",
45
+ "args": ["-y", "some-mcp"]
46
+ }
47
+ }`,rows:5,style:{...Ke,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:$e,disabled:!A.trim()||Y,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:A.trim()&&!Y?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:A.trim()&&!Y?1:.5},children:Y?"导入中…":"导入"})]}),t.filter(b=>b.transport===r).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",r==="stdio"?"本地 stdio":r==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(b=>b.transport===r).map(b=>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:b.name||b.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:ot(b.transport),color:Me(b.transport),fontWeight:600},children:Be(b.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[b.transport==="stdio"?`${b.command} ${(b.args??[]).join(" ")}`:b.url,b.transport!=="stdio"&&b.headers&&Object.keys(b.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(b.headers).length," 个请求头"]})]}),E.has(b.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"}}),"探测工具中…"]}):S[b.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:S[b.id]}),b.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(S[b.id])?e.jsx("button",{onClick:()=>{f(""),R({server:b})},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:()=>X(b),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:"重试"})]}):v[b.id]&&v[b.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:v[b.id].map(F=>e.jsx("span",{title:F.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:F.name},F.name))}):v[b.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:b.enabled!==!1,onChange:F=>ge(b.id,F.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Ce(b.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:F=>{F.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:F=>{F.currentTarget.style.background="transparent"},children:"移除"})]})]},b.id))}),k&&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:b=>{b.target===b.currentTarget&&R(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:k.server.name||k.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:u,onChange:b=>f(b.target.value),onKeyDown:b=>{b.key==="Enter"&&ne(),b.key==="Escape"&&R(null)},placeholder:"sk-… 或 Bearer token",style:{...Ke,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>R(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:ne,disabled:!u.trim()||B,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:u.trim()&&!B?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:u.trim()&&!B?1:.5},children:B?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const Ke={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)"},Jt={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function cs(){const[t,i]=g.useState([]),[r,o]=g.useState(""),[s,n]=g.useState(null),[l,c]=g.useState(!1),[x,p]=g.useState(""),[v,m]=g.useState(""),[S,w]=g.useState("user"),[E,T]=g.useState(""),[k,R]=g.useState(null),[u,f]=g.useState("success"),B=async()=>{if(window.agentApi){const W=await window.agentApi.listMemories();i(W)}};g.useEffect(()=>{B()},[]);const P=async()=>{if(!r.trim()){B();return}if(window.agentApi){const W=await window.agentApi.searchMemories(r);i(W.map(I=>I.entry))}},X=async()=>{if(!(!x.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:x.trim(),description:v,type:S,content:E,created:(s==null?void 0:s.created)??new Date().toISOString(),updated:new Date().toISOString()}),c(!1),n(null),p(""),m(""),T(""),w("user"),R("保存成功"),f("success"),await B()}catch(W){R(W instanceof Error?W.message:"保存失败"),f("error")}},A=W=>{n(W),p(W.name),m(W.description),w(W.type),T(W.content),c(!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:()=>{c(!0),n(null),p(""),m(""),T(""),w("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:r,onChange:W=>o(W.target.value),onKeyDown:W=>W.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:wr,children:"搜索"})]}),k&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:u==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:u==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:u==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:k}),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:x,onChange:W=>p(W.target.value),placeholder:"名称",style:{...Et,marginBottom:10},disabled:!!s}),e.jsx("input",{value:v,onChange:W=>m(W.target.value),placeholder:"描述",style:{...Et,marginBottom:10}}),e.jsxs("select",{value:S,onChange:W=>w(W.target.value),style:{...Et,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:E,onChange:W=>T(W.target.value),placeholder:"内容",rows:5,style:{...Et,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:X,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:()=>c(!1),style:wr,children:"取消"})]})]}),t.map(W=>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:W.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:W.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>A(W),style:jr,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(W.name),R("删除成功"),f("success"),await B()}catch(I){R(I instanceof Error?I.message:"删除失败"),f("error")}},style:{...jr,color:"var(--danger)"},children:"删除"})]})]}),W.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:W.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[W.content.slice(0,180),W.content.length>180?"…":""]})]},W.name)),t.length===0&&!l&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Et={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"},wr={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)"},jr={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},us=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function ps(){const[t,i]=g.useState([]),[r,o]=g.useState(null),[s,n]=g.useState(!1),[l,c]=g.useState(null),[x,p]=g.useState("success"),[v,m]=g.useState(""),S=(A,W="success")=>{c(A),p(W),setTimeout(()=>c(null),3e3)},w=async()=>{if(!window.agentApi)return;const A=await window.agentApi.listSkills();i(A)};g.useEffect(()=>{w()},[]);const E=A=>{o({...A}),m((A.triggers??[]).join(", ")),n(!1)},T=()=>{o(us()),m(""),n(!0)},k=()=>{o(null),n(!1)},R=async()=>{if(!r||!window.agentApi)return;if(!r.name.trim()){S("名称不能为空","error");return}const A=v.split(",").map(W=>W.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:r.name.trim(),description:r.description,triggers:A,prompt:r.prompt,filePath:r.filePath??""}),S(s?"技能已创建":"技能已保存"),o(null),await w()}catch(W){S(W instanceof Error?W.message:"保存失败","error")}},u=async A=>{if(window.agentApi)try{await window.agentApi.deleteSkill(A),S("已删除"),(r==null?void 0:r.name)===A&&o(null),await w()}catch(W){S(W instanceof Error?W.message:"删除失败","error")}},f=async A=>{if(!window.agentApi)return;const W=!A.enabled;await window.agentApi.setSkillEnabled(A.name,W),await w()},B=async()=>{if(window.agentApi)try{const A=await window.agentApi.importSkill();if(!A)return;S(`已导入技能「${A.name}」,本次会话立即生效`),await w()}catch(A){S(A instanceof Error?A.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"},X={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:B,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:T,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:x==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:x==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:x==="success"?"var(--success)":"var(--danger)",fontSize:13},children:l}),r&&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:s?"新建技能":`编辑:${r.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:X,children:"名称"}),e.jsx("input",{style:P,value:r.name,disabled:!s,onChange:A=>o({...r,name:A.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:X,children:"描述"}),e.jsx("input",{style:P,value:r.description,onChange:A=>o({...r,description:A.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:X,children:"触发词(逗号分隔)"}),e.jsx("input",{style:P,value:v,onChange:A=>m(A.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:X,children:"提示词"}),e.jsx("textarea",{style:{...P,minHeight:120,resize:"vertical"},value:r.prompt,onChange:A=>o({...r,prompt:A.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:R,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:k,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&&!r&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(A=>{var W;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:A.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>f(A),title:A.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:A.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:A.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:A.name}),((W=A.triggers)==null?void 0:W.length)>0&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["触发词:",A.triggers.slice(0,3).join(" · "),A.triggers.length>3?" ...":""]})]}),A.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:A.description}),A.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:[A.prompt.slice(0,80),A.prompt.length>80?"...":""]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>E(A),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:()=>u(A.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:"删除"})]})]},A.name)})]})]})}const Bt=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function Pr(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function gs(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:Pr(),maxIterations:0,isDefault:!1}}const Zt={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"},jt={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},Je={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"},qe={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function xs({ph:t,onChange:i,onDelete:r}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:Je,placeholder:"变量名 (e.g. project)",value:t.key,onChange:o=>i({...t,key:o.target.value})}),e.jsx("input",{style:Je,placeholder:"说明",value:t.description,onChange:o=>i({...t,description:o.target.value})}),e.jsx("input",{style:Je,placeholder:"默认值",value:t.defaultValue,onChange:o=>i({...t,defaultValue:o.target.value})}),e.jsx("button",{onClick:r,style:{...jt,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function Sr({initial:t,activeAgentId:i,onSave:r,onCancel:o}){const{profiles:s}=Dt(),[n,l]=g.useState([]),[c,x]=g.useState([]),[p,v]=g.useState({...gs(),...t,capabilities:{...Pr(),...t.capabilities??{}}}),[m,S]=g.useState(null),[w,E]=g.useState(!1);g.useEffect(()=>{var I,M;window.agentApi&&(window.agentApi.listSkills().then(Y=>{l(Y.filter(ce=>ce.name))}),(M=(I=window.agentApi).listMCPServers)==null||M.call(I).then(Y=>{x(Y??[])}).catch(()=>{}))},[]);const T=I=>v(M=>({...M,capabilities:{...M.capabilities,...I}})),k=I=>{const M=p.capabilities.enabledTools;if(M.length===0){const Y=Bt.map(ce=>ce.name).filter(ce=>ce!==I);T({enabledTools:Y})}else if(M.includes(I)){const Y=M.filter(ce=>ce!==I);T({enabledTools:Y})}else{const Y=[...M,I];Y.length===Bt.length?T({enabledTools:[]}):T({enabledTools:Y})}},R=I=>{const M=p.capabilities.enabledSkills;T({enabledSkills:M.includes(I)?M.filter(Y=>Y!==I):[...M,I]})},u=I=>{const M=p.capabilities.enabledMCPServers;T({enabledMCPServers:M.includes(I)?M.filter(Y=>Y!==I):[...M,I]})},f=()=>v(I=>({...I,contextPlaceholders:[...I.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),B=(I,M)=>v(Y=>{const ce=[...Y.contextPlaceholders];return ce[I]=M,{...Y,contextPlaceholders:ce}}),P=I=>v(M=>({...M,contextPlaceholders:M.contextPlaceholders.filter((Y,ce)=>ce!==I)})),X=async()=>{if(!p.name.trim()){S("名称为必填项");return}E(!0);try{await r(p)}catch(I){S(I instanceof Error?I.message:"保存失败")}finally{E(!1)}},A=I=>p.capabilities.enabledTools.length===0||p.capabilities.enabledTools.includes(I),W={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:[m&&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:m}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:qe,children:"名称 *"}),e.jsx("input",{style:Je,value:p.name,onChange:I=>v(M=>({...M,name:I.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:qe,children:"描述"}),e.jsx("input",{style:Je,value:p.description,onChange:I=>v(M=>({...M,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:{...qe,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:p.systemPrompt,onChange:I=>v(M=>({...M,systemPrompt:I.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
48
+
49
+ 当前项目:{{project_name}}`,rows:6,style:{...Je,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:W,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,M)=>e.jsx(xs,{ph:I,onChange:Y=>B(M,Y),onDelete:()=>P(M)},M))]}),e.jsx("button",{onClick:f,style:{...jt,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:W,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:qe,children:"模型"}),e.jsxs("select",{value:p.capabilities.profileId,onChange:I=>T({profileId:I.target.value}),style:{...Je,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),s.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:qe,children:["内置工具 ",p.capabilities.enabledTools.length===0?"(全部启用)":`(${p.capabilities.enabledTools.length}/${Bt.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Bt.map(I=>{const M=A(I.name);return e.jsx("button",{onClick:()=>k(I.name),style:{padding:"4px 10px",borderRadius:20,border:M?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:M?"var(--accent-dim)":"transparent",color:M?"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:'点击切换;全选时恢复为"全部启用"'})]}),n.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:qe,children:["技能 ",p.capabilities.enabledSkills.length===0?"(全部)":`(${p.capabilities.enabledSkills.length}/${n.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:n.map(I=>{const M=p.capabilities.enabledSkills.length===0||p.capabilities.enabledSkills.includes(I.name);return e.jsx("button",{onClick:()=>R(I.name),title:I.description,style:{padding:"4px 10px",borderRadius:20,border:M?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:M?"var(--accent-dim)":"transparent",color:M?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:I.name},I.name)})})]}),c.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:qe,children:["MCP 服务器 ",p.capabilities.enabledMCPServers.length===0?"(全部)":`(${p.capabilities.enabledMCPServers.length}/${c.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:c.map(I=>{const M=p.capabilities.enabledMCPServers.length===0||p.capabilities.enabledMCPServers.includes(I.id);return e.jsx("button",{onClick:()=>u(I.id),style:{padding:"4px 10px",borderRadius:20,border:M?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:M?"var(--accent-dim)":"transparent",color:M?"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:qe,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:Je,value:p.maxIterations,min:0,max:100,onChange:I=>v(M=>({...M,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=>v(M=>({...M,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:X,disabled:w,style:{...Zt,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:w?.6:1},children:w?"保存中…":"保存"}),e.jsx("button",{onClick:o,style:Zt,children:"取消"})]})]})}function hs(){const[t,i]=g.useState([]),[r,o]=g.useState([]),[s,n]=g.useState(null),[l,c]=g.useState(!1),[x,p]=g.useState(null),[v,m]=g.useState("success"),S=(u,f="success")=>{p(u),m(f),setTimeout(()=>p(null),2e3)},w=async()=>{if(!window.agentApi)return;const u=await window.agentApi.listAgentDefs();i(u);const f=await window.agentApi.getSettings();o(f.activeAgentIds??[])};g.useEffect(()=>{w()},[]);const E=async u=>{await window.agentApi.createAgentDef(u),c(!1),S("智能体已创建"),await w()},T=async(u,f)=>{await window.agentApi.updateAgentDef(u,f),n(null),S("保存成功"),await w()},k=async u=>{await window.agentApi.deleteAgentDef(u),s===u&&n(null),S("已删除"),await w()},R=async u=>{const B=(await window.agentApi.setActiveAgentDef(u)).activeAgentIds??[];o(B),S(B.includes(u)?"已激活":"已取消激活")};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:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),x&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,border:v==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:v==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:v==="success"?"var(--success)":"var(--danger)",fontSize:13},children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{c(!0),n(null)},style:{...Zt,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(Sr,{initial:{},activeAgentId:r[0]??"",onSave:E,onCancel:()=>c(!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(u=>{const f=r.includes(u.id),B=u.id===s;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${f?"var(--accent)":"var(--border-default)"}`,background:f?"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:f?"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:f?"#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:u.name}),f&&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:"激活"}),u.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),u.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[u.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:"自定义模型"}),u.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:[u.capabilities.enabledTools.length," 工具"]}),u.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:[u.capabilities.enabledSkills.length," 技能"]}),u.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:[u.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>R(u.id),style:{...jt,color:f?"var(--accent)":"var(--text-muted)",borderColor:f?"var(--accent)":"var(--border-default)",background:f?"var(--accent-dim)":"transparent"},children:f?"取消激活":"激活"}),e.jsx("button",{onClick:()=>n(B?null:u.id),style:jt,children:B?"收起":"编辑"}),e.jsx("button",{onClick:()=>k(u.id),style:{...jt,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),B&&e.jsx(Sr,{initial:u,activeAgentId:r[0]??"",onSave:P=>T(u.id,P),onCancel:()=>n(null)})]},u.id)})]})]})}const fs=[{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"}],Qt={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function ms(){const[t,i]=g.useState([]),[r,o]=g.useState(Qt),[s,n]=g.useState(!1),[l,c]=g.useState(null),[x,p]=g.useState(null),v=async()=>{var u;if((u=window.agentApi)!=null&&u.lspList)try{const f=await window.agentApi.lspList();i(f)}catch(f){console.error("[LSP] load error",f)}};g.useEffect(()=>{v()},[]);const m=u=>{o(f=>({...f,name:u.label,language:u.language,fileTypes:u.fileTypes,command:u.command,args:u.args}))},S=u=>{c(u.id),o({id:u.id,name:u.name,language:u.language,fileTypes:u.fileTypes.join(","),command:u.command,args:u.args.join(" "),envRaw:u.env?Object.entries(u.env).map(([f,B])=>`${f}=${B}`).join(`
50
+ `):""}),p(null)},w=()=>{c(null),o(Qt)},E=async()=>{var X;if(!((X=window.agentApi)!=null&&X.lspSave))return;const u=r.name.trim(),f=r.command.trim();if(!u||!f)return;let B;if(r.envRaw.trim()){B={};for(const A of r.envRaw.split(`
51
+ `)){const W=A.indexOf("=");W>0&&(B[A.slice(0,W).trim()]=A.slice(W+1).trim())}}const P={id:l??crypto.randomUUID(),name:u,language:r.language.trim(),fileTypes:r.fileTypes.split(",").map(A=>A.trim()).filter(Boolean),command:f,args:r.args.trim()?r.args.trim().split(/\s+/):[],env:B,enabled:!0};n(!0);try{await window.agentApi.lspSave(P),await v(),w()}finally{n(!1)}},T=async u=>{var f;(f=window.agentApi)!=null&&f.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(u),await v())},k=async u=>{var f;(f=window.agentApi)!=null&&f.lspSetEnabled&&(await window.agentApi.lspSetEnabled(u.id,!u.enabled),await v())},R=l!==null;return R&&l===null||!l&&r.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"})," ","等工具进行代码分析。"]})]}),!R&&e.jsx("button",{onClick:()=>{c(""),o(Qt)},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&&!R&&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:R?24:0},children:t.map(u=>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(x===u.id?null:u.id),children:[e.jsx("div",{onClick:f=>{f.stopPropagation(),k(u)},style:{width:32,height:18,borderRadius:9,background:u.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:u.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:u.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[u.language,u.fileTypes.length>0?` · ${u.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[u.command,u.args.length?" "+u.args.join(" "):""]}),e.jsx("button",{onClick:f=>{f.stopPropagation(),S(u)},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:f=>{f.stopPropagation(),T(u.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:x===u.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),x===u.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:[u.command," ",u.args.join(" ")]})]}),u.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),u.fileTypes.join(", ")]}),u.env&&Object.keys(u.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(u.env).map(([f,B])=>`${f}=${B}`).join(", ")]})]})]},u.id))}),R&&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:rt,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:fs.map(u=>e.jsx("button",{onClick:()=>m(u),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:u.label},u.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:rt,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.name,onChange:u=>o(f=>({...f,name:u.target.value})),placeholder:"TypeScript Language Server",style:dt})]}),e.jsxs("div",{children:[e.jsx("label",{style:rt,children:"语言"}),e.jsx("input",{value:r.language,onChange:u=>o(f=>({...f,language:u.target.value})),placeholder:"typescript",style:dt})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rt,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:r.fileTypes,onChange:u=>o(f=>({...f,fileTypes:u.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:dt})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:rt,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.command,onChange:u=>o(f=>({...f,command:u.target.value})),placeholder:"typescript-language-server",style:{...dt,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rt,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:r.args,onChange:u=>o(f=>({...f,args:u.target.value})),placeholder:"--stdio",style:{...dt,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rt,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:r.envRaw,onChange:u=>o(f=>({...f,envRaw:u.target.value})),placeholder:`NODE_ENV=production
52
+ TSPROTOCOL_LOG=verbose`,rows:3,style:{...dt,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),r.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 E(),disabled:s||!r.name.trim()||!r.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:s||!r.name.trim()||!r.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:s?"保存中…":"保存"}),e.jsx("button",{onClick:w,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 dt={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"},rt={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function bs({trigger:t,heardText:i}){const[r,o]=g.useState(!1);return g.useEffect(()=>{if(t<=0)return;o(!0);const s=setTimeout(()=>o(!1),2400);return()=>clearTimeout(s)},[t]),r?ct.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(s=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${s}s var(--ease-out) infinite`}},s)),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:"已唤醒 · 随时待命"}),i&&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:["“",i.slice(0,40),"”"]})]},t),document.body):null}function ys(){var Tt;const[t,i]=g.useState([]),[r,o]=g.useState({}),[s,n]=g.useState({}),[l,c]=g.useState(null),[x,p]=g.useState(null),[v,m]=g.useState(new Set),[S,w]=g.useState(new Set),[E,T]=g.useState(new Set),[k,R]=g.useState(!1),[u,f]=g.useState("settings"),B=Fe(d=>d.setTodos),P=Ee(d=>d.skin),X=Ee(d=>d.layout),A=Ee(d=>d.wakeEnabled),W=Ee(d=>d.wakeWord),I=Ee(d=>d.setSkin),M=Ee(d=>d.setLayout),Y=Ee(d=>d.setWakeEnabled),ce=Ee(d=>d.setWakeWord),$e=Ee(d=>d.autoSpeak),q=Ee(d=>d.setAutoSpeak),ue=Mr(),Re=es(),Ie=ue&&Re,[Ce,ge]=g.useState(!1),[ne,Be]=g.useState(!1),[Me,ot]=g.useState(null),[b,F]=g.useState(0),[oe,ee]=g.useState(void 0),H=g.useRef(null),J=g.useRef(!1),[be,xe]=g.useState(null),ze=g.useRef(null),He=g.useRef(!1),Ve=g.useRef(t);Ve.current=t;const ie=g.useRef(E);ie.current=E,g.useEffect(()=>{document.documentElement.setAttribute("data-skin",P)},[P]),g.useEffect(()=>{document.body.classList.toggle("layout-compact",X==="compact")},[X]);const Ne=g.useCallback(()=>{if(!window.agentApi||!A||J.current||H.current)return;const d=()=>{Rr()&&!H.current&&(H.current=Rn({wakeWord:W,onWake:C=>{var D;ee(C),F($=>$+1),(D=window.agentApi)==null||D.showWindow()},onError:C=>console.warn("[wake]",C)}))};typeof window.agentApi.wakeStart=="function"?(J.current=!0,window.agentApi.wakeStart(W).then(C=>{C.ok||(J.current=!1,d())}).catch(()=>{J.current=!1,d()})):d()},[A,W]);g.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWake)return window.agentApi.onWake(C=>{J.current=!1,ee(C),F(D=>D+1)})},[]),g.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWakeCommand)return window.agentApi.onWakeCommand(C=>{var V;const D=((C==null?void 0:C.text)||"").trim();if(!D)return;const $=ze.current&&Date.now()<ze.current.until?ze.current:null;if($){$.until=Date.now()+9e4,p($.sessionId),(V=window.agentApi)==null||V.wakeConversation(!0),xe({text:D,projectId:null,sessionId:$.sessionId,nonce:Date.now()}),ae(`语音追问:${D.length>40?D.slice(0,40)+"…":D}`),ve("success"),setTimeout(()=>ae(null),4e3);return}const _=Ve.current.find(U=>U.name&&D.includes(U.name)&&!ie.current.has(U.id));_&&(c(_.id),w(U=>{const pe=new Set(U);return pe.add(_.id),pe})),p(null),He.current=!0,q(!0),xe({text:D,projectId:(_==null?void 0:_.id)??null,nonce:Date.now()}),ae(`语音指令:${D.length>40?D.slice(0,40)+"…":D}${_?`(项目:${_.name})`:""}`),ve("success"),setTimeout(()=>ae(null),4e3)})},[]);const pt=g.useCallback(async()=>{window.agentApi&&(Ne(),await window.agentApi.hideWindow())},[Ne]),Ue=g.useCallback(d=>{R(!1),ot({right:d.right,bottom:d.bottom}),Be(C=>!C)},[]),gt=g.useCallback(()=>{Be(!1),R(d=>!d)},[]);g.useEffect(()=>{if(!ne)return;const d=()=>{const D=document.querySelector(".chat-header-action--appearance");if(!D)return;const $=D.getBoundingClientRect();ot(_=>(_==null?void 0:_.right)===$.right&&_.bottom===$.bottom?_:{right:$.right,bottom:$.bottom})},C=window.requestAnimationFrame(d);return window.addEventListener("resize",d),()=>{window.cancelAnimationFrame(C),window.removeEventListener("resize",d)}},[X,ne]),g.useEffect(()=>{window.agentApi&&Ne()},[Ne]),g.useEffect(()=>{const d=()=>{var C;(C=H.current)==null||C.stop(),H.current=null};return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[]),g.useEffect(()=>{var d,C;A||((d=H.current)==null||d.stop(),H.current=null,J.current=!1,(C=window.agentApi)==null||C.wakeStop())},[A]),g.useEffect(()=>{!A||!window.agentApi||J.current&&window.agentApi.wakeStart(W)},[W]),g.useEffect(()=>()=>{var d;(d=H.current)==null||d.stop()},[]);const It=x?(Tt=Object.values(r).flat().find(d=>d.id===x))==null?void 0:Tt.title:void 0,[Qe,it]=g.useState(260),Ge=g.useRef(!1),We=g.useRef(0),xt=g.useRef(0),at=g.useCallback(d=>{if(!Ge.current)return;const C=Math.min(480,Math.max(160,xt.current+d.clientX-We.current));it(C)},[]),lt=g.useCallback(()=>{Ge.current=!1,document.removeEventListener("mousemove",at),document.removeEventListener("mouseup",lt)},[at]),Ct=g.useCallback(d=>{Ge.current=!0,We.current=d.clientX,xt.current=Qe,document.addEventListener("mousemove",at),document.addEventListener("mouseup",lt)},[Qe,at,lt]),[ht,ae]=g.useState(null),[Ye,ve]=g.useState("success"),[_e,De]=g.useState([]),Le=g.useCallback(d=>{De(C=>C.filter(D=>D.id!==d))},[]),ft=g.useCallback(d=>{const C=crypto.randomUUID();De(D=>[...D,{...d,id:C}]),setTimeout(()=>Le(C),12e3)},[Le]),zt=async()=>{if(!window.agentApi)return;const d=await window.agentApi.listProjects();i(d);const C=new Set;await Promise.all(d.map(async D=>{D.description&&!await window.agentApi.checkProjectPath(D.description)&&C.add(D.id)})),T(C),await Promise.all(d.map(D=>Pe(D.id)))},Pe=async d=>{if(!window.agentApi||!d)return;const C=await window.agentApi.listSessions(d),D=C.filter(_=>!_.parentSessionId);o(_=>({..._,[d]:D}));const $={};for(const _ of C.filter(V=>V.parentSessionId)){const V=_.parentSessionId;($[V]??($[V]=[])).push(_)}for(const _ of Object.values($))_.sort((V,U)=>V.created<U.created?-1:1);n(_=>{const V={..._};for(const U of D)$[U.id]?V[U.id]=$[U.id]:delete V[U.id];return V})},Oe=async d=>{if(!window.agentApi)return;const C=await window.agentApi.listChildSessions(d);n(D=>({...D,[d]:C.sort(($,_)=>$.created<_.created?-1:1)}))},Xe=async d=>{if(!window.agentApi)return;const C=await window.agentApi.createSession("新会话",d);await Pe(d),c(d),p(C.id),Ie&&ge(!1)};g.useEffect(()=>{(async()=>{if(!window.agentApi)return;await Dt.getState().loadFromSystem();const C=await window.agentApi.listProjects();i(C);const D={},$={};await Promise.all(C.map(async U=>{const pe=await window.agentApi.listSessions(U.id),Se=pe.filter(we=>!we.parentSessionId);D[U.id]=Se;for(const we of pe.filter(ye=>ye.parentSessionId)){const ye=we.parentSessionId;($[ye]??($[ye]=[])).push(we)}}));for(const U of Object.values($))U.sort((pe,Se)=>pe.created<Se.created?-1:1);o(D),n($);const V=Object.entries(D).flatMap(([U,pe])=>pe.map(Se=>({...Se,_pid:U}))).sort((U,pe)=>pe.updated>U.updated?1:-1)[0];V?(c(V._pid),p(V.id),w(new Set([V._pid]))):C.length>0&&(c(C[0].id),w(new Set([C[0].id])))})()},[]),g.useEffect(()=>{if(!l||!window.agentApi)return;const d=t.find(D=>D.id===l),C=d==null?void 0:d.description;C&&window.agentApi.setProjectWorkingDir(C)},[l,t]);const mt=async d=>{w(C=>{const D=new Set(C);return D.has(d)?D.delete(d):D.add(d),D}),l!==d&&(c(d),p(null),await Pe(d))},Ze=async()=>{try{if(!window.agentApi){ae("agentApi 未就绪,请重启应用"),ve("error");return}const d=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",d),!d)return;const C=d.replace(/\\/g,"/"),D=C.split("/").filter(Boolean),$=D[D.length-1]||"导入的项目",_=await window.agentApi.createProject($,C);await zt(),c(_.id),p(null),await Pe(_.id),w(V=>{const U=new Set(V);return U.add(_.id),U}),ae(`已导入:${$}`),ve("success"),setTimeout(()=>ae(null),3e3)}catch(d){console.error("[import] error:",d),ae(d instanceof Error?d.message:String(d)),ve("error"),setTimeout(()=>ae(null),5e3)}},et=async d=>{if(window.agentApi)try{await window.agentApi.deleteProject(d),l===d&&(c(null),p(null),B([])),ae("项目删除成功"),ve("success"),setTimeout(()=>ae(null),2500),await zt()}catch(C){ae(C instanceof Error?C.message:"项目删除失败"),ve("error"),setTimeout(()=>ae(null),4e3)}},tt=async d=>{if(window.agentApi)try{await window.agentApi.deleteSession(d),x===d&&(p(null),B([])),ae("会话删除成功"),ve("success"),setTimeout(()=>ae(null),2500),l&&await Pe(l)}catch(C){ae(C instanceof Error?C.message:"会话删除失败"),ve("error"),setTimeout(()=>ae(null),4e3)}},At=[{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:ue?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[Ie&&Ce&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>ge(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),Ie&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>ge(d=>!d),"aria-label":"会话列表","aria-expanded":Ce,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:Ce?e.jsx("path",{d:"M6 6l12 12M18 6 6 18"}):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:Qe,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 20px",position:"relative",zIndex:10,overflow:"hidden",...Ie?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:Ce?"translateX(0)":"translateX(-103%)",transition:"transform .24s ease",boxShadow:"12px 0 32px rgba(0,0,0,.5)",padding:"calc(env(safe-area-inset-top) + 56px) 0 20px"}:{}},children:[e.jsx("div",{className:"app-sidebar-brand",style:{padding:"0 20px 20px",borderBottom:"1px solid var(--border-subtle)",marginBottom:16},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx("div",{style:{width:28,height:28,borderRadius:8,background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]})}),e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",letterSpacing:"-0.01em"},children:"智能助手"})]})}),ht&&e.jsx("div",{style:{margin:"0 12px 10px",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:Ye==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:Ye==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:Ye==="success"?"var(--success)":"var(--danger)",fontSize:12},children:ht}),e.jsxs("div",{className:"app-sidebar-section",style:{padding:"0 20px 8px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.1em",fontWeight:600},children:"项目"}),e.jsx("button",{onClick:()=>void Ze(),title:"导入项目","aria-label":"导入项目",className:"ui-icon-button ui-icon-button--small",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:"M12 5v14M5 12h14"})})})]}),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:[t.map(d=>{const C=l===d.id&&!x,D=S.has(d.id),$=r[d.id]??[],_=$.length>10,V=E.has(d.id);return e.jsxs("div",{children:[e.jsxs("div",{className:`sidebar-row ${C&&!V?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:V?.45:1},children:[e.jsxs("button",{onClick:()=>{V||mt(d.id)},disabled:V,title:V?`路径不存在:${d.description}`:d.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:V?"var(--text-muted)":C?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:C&&!V?600:400,cursor:V?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},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:C&&!V?.8:.4,transform:D?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.2s ease"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})}),V?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:C?1:.5},children:D?e.jsxs(e.Fragment,{children:[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("line",{x1:"9",y1:"14",x2:"15",y2:"14"})]}):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}),$.length>0&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:C&&!V?"var(--accent)":"var(--text-muted)",background:C&&!V?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"15px",opacity:.8},children:$.length})]}),e.jsx("button",{onClick:U=>{U.stopPropagation(),et(d.id)},title:"删除项目",className:"sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{flexShrink:0,fontSize:14,lineHeight:1},children:"×"}),e.jsx("button",{onClick:U=>{U.stopPropagation(),Xe(d.id)},title:"新建会话",className:`sidebar-row-action sidebar-row-action--accent ui-icon-button ui-icon-button--small ${C&&!V?"is-active":""}`,style:{flexShrink:0,fontSize:16,lineHeight:1},children:"+"})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:D?_?300:800:0,opacity:D?1:0,transition:"max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,..._?{maxHeight:280,overflowY:"auto"}:{}},children:[$.map(U=>{const pe=x===U.id,Se=s[U.id]??[];return e.jsxs("div",{children:[e.jsxs("div",{className:`sidebar-row ${pe?"sidebar-row-active":""}`,style:{paddingRight:4},children:[e.jsxs("button",{onClick:()=>{Ie&&ge(!1),c(d.id),p(U.id),Se.length>0&&m(we=>{const ye=new Set(we);return ye.has(U.id)?ye.delete(U.id):ye.add(U.id),ye})},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"6px 10px",border:"none",background:"transparent",color:pe?"var(--accent)":"var(--text-secondary)",fontSize:12,cursor:"pointer",textAlign:"left",transition:"color 0.15s"},children:[e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",flexShrink:0,background:pe?"var(--accent)":U.status==="completed"?"var(--success)":"var(--border-default)",transition:"background 0.15s"}}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:U.title}),Se.length>0&&e.jsx("span",{className:"sidebar-count",style:{flexShrink:0,fontSize:9,fontWeight:600,color:pe?"var(--accent)":"var(--text-muted)",background:pe?"var(--accent-dim)":"var(--bg-deep)",borderRadius:8,padding:"0 5px",lineHeight:"16px",opacity:.8},children:Se.length})]}),e.jsx("button",{onClick:()=>void tt(U.id),title:"删除会话",className:"sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{fontSize:14,flexShrink:0,lineHeight:1},children:"×"})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:v.has(U.id)?0:Se.length*40,opacity:v.has(U.id)?0:1,transition:"max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease"},children:Se.map(we=>{const ye=x===we.id;return e.jsxs("div",{className:`sidebar-row ${ye?"sidebar-row-active":""}`,style:{paddingRight:4,marginLeft:14,borderLeft:"1px solid var(--border-subtle)"},children:[e.jsxs("button",{onClick:()=>{c(d.id),p(we.id)},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"5px 8px",border:"none",background:"transparent",color:ye?"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:we.title})]}),e.jsx("button",{onClick:()=>void tt(we.id),title:"删除子会话",className:"sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{fontSize:12,flexShrink:0,lineHeight:1},children:"×"})]},we.id)})})]},U.id)}),$.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},d.id)}),t.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:"暂无项目"})]})})]}),!Ie&&e.jsx("div",{onMouseDown:Ct,style:{width:4,flexShrink:0,cursor:"col-resize",zIndex:15,background:"transparent",transition:"background 0.15s"},onMouseEnter:d=>d.currentTarget.style.background="var(--accent)",onMouseLeave:d=>d.currentTarget.style.background="transparent"})]}),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-deepest)",position:"relative",zIndex:5},children:[X==="focus"&&e.jsx("button",{onClick:()=>M("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(ss,{selectedProjectId:l,selectedSessionId:x,sessionTitle:It,voiceCommand:be,onOpenSettings:gt,settingsOpen:k,onHideToBackground:()=>void pt(),onToggleAppearance:Ue,appearanceOpen:ne,hideToBackgroundTitle:A?`隐藏到后台(说“${W}”唤醒)`:"隐藏到后台",onSessionCreated:async d=>{var C;p(d),He.current&&(He.current=!1,ze.current={sessionId:d,until:Date.now()+9e4},(C=window.agentApi)==null||C.wakeConversation(!0)),await Pe(l||void 0)},onSubSessionCreated:async d=>{await Oe(d)},onSelectSession:d=>{p(d)},onSubAgentEvent:d=>{d.type==="started"?ft({type:"info",title:"子会话已启动",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):d.type==="completed"?ft({type:"success",title:"子会话已完成",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):ft({type:"error",title:"子会话出错",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId})},onMessageSent:(d,C)=>{o(D=>{const $={};for(const[_,V]of Object.entries(D))$[_]=V.map(U=>U.id===d?{...U,title:C.slice(0,60)||U.title}:U);return $})},onRunComplete:async(d,C)=>{var _;const D=ze.current,$=Gn(D,C);ze.current=$,$!==D&&((_=window.agentApi)==null||_.wakeConversation(!0)),(d||l)&&await Pe(d||l||"")}})})]}),k&&ct.createPortal(e.jsx("div",{onClick:()=>R(!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:At.map(d=>e.jsx("button",{onClick:()=>f(d.id),className:`settings-tab ${u===d.id?"settings-tab-active":""}`,children:d.label},d.id))}),e.jsx("button",{onClick:()=>R(!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:[u==="settings"&&e.jsx(is,{}),u==="mcp"&&e.jsx(ds,{}),u==="memory"&&e.jsx(cs,{}),u==="skill"&&e.jsx(ps,{}),u==="agent"&&e.jsx(hs,{}),u==="lsp"&&e.jsx(ms,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),ne&&Me&&ct.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(Me.right-320,window.innerWidth-332)),top:Me.bottom+8,width:320,maxHeight:`calc(100vh - ${Me.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:zn.map(d=>e.jsxs("button",{onClick:()=>I(d.id),className:`appearance-choice ${P===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:P===d.id?600:400},children:d.label}),P===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:An.map(d=>e.jsx("button",{onClick:()=>M(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:$e,onChange:d=>q(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:A,onChange:d=>Y(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:W,onChange:d=>ce(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(bs,{trigger:b,heardText:oe}),_e.length>0&&ct.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:_e.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:()=>Le(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:C=>C.currentTarget.style.color="var(--text-primary)",onMouseLeave:C=>C.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:()=>{p(d.sessionId),Le(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:C=>C.currentTarget.style.background="var(--accent-glow)",onMouseLeave:C=>C.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},d.id))}),document.body)]})}export{ys as default};