cli-link 0.0.5 → 0.0.7

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 (58) hide show
  1. package/bin/agentpilot.js +1 -0
  2. package/dist/client/assets/History-D2xDopni.js +4 -0
  3. package/dist/client/assets/ImageViewer-DuegU_fC.js +1 -0
  4. package/dist/client/assets/MarkdownRenderer-CsyizEL3.js +1 -0
  5. package/dist/client/assets/{PageTopBar-C8j-5s_3.js → PageTopBar-CQwjO6Af.js} +1 -1
  6. package/dist/client/assets/Session-B0s5zBGg.js +7 -0
  7. package/dist/client/assets/Settings-CfHFmJdV.js +1 -0
  8. package/dist/client/assets/Workspace-Cfl0mbNE.js +4 -0
  9. package/dist/client/assets/WorkspaceLinkedText-DCVYd9x-.js +2 -0
  10. package/dist/client/assets/c-BIGW1oBm.js +1 -0
  11. package/dist/client/assets/cpp-DIPi6g--.js +1 -0
  12. package/dist/client/assets/csharp-DSvCPggb.js +1 -0
  13. package/dist/client/assets/dart-bE4Kk8sk.js +1 -0
  14. package/dist/client/assets/dotenv-Da5cRb03.js +1 -0
  15. package/dist/client/assets/go-C27-OAKa.js +1 -0
  16. package/dist/client/assets/graphql-pNE0_Gx8.js +1 -0
  17. package/dist/client/assets/groovy-gcz8RCvz.js +1 -0
  18. package/dist/client/assets/index-BCg3ymV3.css +1 -0
  19. package/dist/client/assets/index-CrJqHlc8.js +2 -0
  20. package/dist/client/assets/java-VnEXKtx_.js +148 -0
  21. package/dist/client/assets/jsx-g9-lgVsj.js +1 -0
  22. package/dist/client/assets/kotlin-BdnUsdx6.js +1 -0
  23. package/dist/client/assets/less-B1dDrJ26.js +1 -0
  24. package/dist/client/assets/lua-BaeVxFsk.js +1 -0
  25. package/dist/client/assets/makefile-CHLpvVh8.js +1 -0
  26. package/dist/client/assets/php-BcCyJq-p.js +1 -0
  27. package/dist/client/assets/properties-DTPjHERo.js +1 -0
  28. package/dist/client/assets/ruby-BwImf3Ka.js +1 -0
  29. package/dist/client/assets/rust-B1yitclQ.js +1 -0
  30. package/dist/client/assets/scss-lMagJa-5.js +1 -0
  31. package/dist/client/assets/sql-CRqJ_cUM.js +1 -0
  32. package/dist/client/assets/svelte-B4a9v_or.js +1 -0
  33. package/dist/client/assets/swift-D82vCrfD.js +1 -0
  34. package/dist/client/assets/toml-vGWfd6FD.js +1 -0
  35. package/dist/client/assets/{vendor-icons-CNN4EKVi.js → vendor-icons-CMXJHDEv.js} +125 -65
  36. package/dist/client/assets/vendor-markdown--d-T3AbU.js +37 -0
  37. package/dist/client/assets/{vendor-motion-n6Lx6G4a.js → vendor-motion-D0ZmPdi9.js} +1 -1
  38. package/dist/client/assets/{vendor-react-DSV5aFEg.js → vendor-react-CcDXZHn_.js} +1 -1
  39. package/dist/client/assets/{vendor-virtual-CcftJrIC.js → vendor-virtual-DJI7OicV.js} +1 -1
  40. package/dist/client/assets/vue-DBXACu8K.js +1 -0
  41. package/dist/client/assets/workspace-return-FrQUv7g3.js +1 -0
  42. package/dist/client/index.html +18 -4
  43. package/dist/server/cli-manager.js +151 -26
  44. package/dist/server/codex-history.js +119 -17
  45. package/dist/server/index.js +1051 -65
  46. package/dist/server/store.js +369 -27
  47. package/dist/server/terminal-qr.js +17 -314
  48. package/package.json +5 -3
  49. package/dist/client/assets/History-BxJVDFpN.js +0 -3
  50. package/dist/client/assets/MarkdownRenderer-BO-KS_L1.js +0 -1
  51. package/dist/client/assets/Session-CQFXA2Sr.js +0 -11
  52. package/dist/client/assets/Settings-DYmjRmoN.js +0 -1
  53. package/dist/client/assets/Workspace-D8kv9euM.js +0 -8
  54. package/dist/client/assets/WorkspaceLinkedText-DQyPLk-X.js +0 -2
  55. package/dist/client/assets/code-highlight-CEcsuMpw.js +0 -1
  56. package/dist/client/assets/index-BXT2BylN.css +0 -1
  57. package/dist/client/assets/index-DOgH1Kf3.js +0 -2
  58. package/dist/client/assets/vendor-markdown-BDwu-Ux6.js +0 -35
package/bin/agentpilot.js CHANGED
@@ -241,6 +241,7 @@ async function main() {
241
241
  process.env.PORT = port;
242
242
  process.env.HOST = host;
243
243
  process.env.AGENTPILOT_NPX = '1';
244
+ process.env.AGENTPILOT_PACKAGE_VERSION = pkg.version;
244
245
  if (options.noToken && options.token) {
245
246
  throw new Error('--token cannot be used with --no-token');
246
247
  }
@@ -0,0 +1,4 @@
1
+ import{u as Ie,d as Pe,r as m,j as e}from"./vendor-react-CcDXZHn_.js";import{u as Be,s as $,h as Ue,c as g}from"./index-CrJqHlc8.js";import{g as ze,a as Oe,M as F}from"./WorkspaceLinkedText-DCVYd9x-.js";import{P as Ae}from"./PageTopBar-CQwjO6Af.js";import{o as xe,X as me,p as Ge,q as V,j as X,r as D,s as W,t as Ke,L as ue,a as We,n as he,e as q,u as fe,B as be,h as I,C as w,S as _,Z as qe,F as _e,l as Je,m as Qe}from"./vendor-icons-CMXJHDEv.js";import{A as ge,m as O}from"./vendor-motion-D0ZmPdi9.js";import"./workspace-return-FrQUv7g3.js";function Ve(t){return t==="active"||t==="running"?"active":t==="attention"||t==="failed"||t==="confirm"?"attention":"all"}function pe(t){if(/^```/.test(t.trim()))return t;try{const s=JSON.parse(t);return"```json\n"+JSON.stringify(s,null,2)+"\n```"}catch{}return t.split(`
2
+ `).map(s=>{const d=s.trim();if(!d)return s;try{const i=JSON.parse(d);return"```json\n"+JSON.stringify(i,null,2)+"\n```"}catch{return s}}).join(`
3
+ `)}function ke(t){const n=Date.now()-t,s=Math.floor(n/6e4);if(s<1)return"刚刚";if(s<60)return`${s}分钟前`;const d=Math.floor(s/60);if(d<24)return`${d}小时前`;const i=Math.floor(d/24);return i===1?"昨天":i<7?`${i}天前`:new Date(t).toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}function A(t){return t.split(/[\\/]/).filter(Boolean).pop()||t}function je(t){var s,d;const r=(s=t.title)==null?void 0:s.trim();if(r&&r!=="会话记录")return r;const n=(d=t.preview)==null?void 0:d.replace(/^(你|AI|问题|确认|错误|工具|系统|思考):/,"").trim();return n?n.length>36?`${n.slice(0,36).trimEnd()}...`:n:"未命名会话"}function Xe(t){var n;const r=(n=t.preview)==null?void 0:n.trim();return r||(t.title&&t.title!=="会话记录"?t.title:"暂无消息摘要")}function Ye(t){const r=new Date(t||Date.now()),n=new Date,s=new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime(),d=new Date(r.getFullYear(),r.getMonth(),r.getDate()).getTime(),i=Math.floor((s-d)/864e5);return i<=0?"今天":i===1?"昨天":i<7?"近 7 天":r.toLocaleDateString("zh-CN",{month:"long",day:"numeric"})}function Ze(t){return t.reduce((r,n)=>{const s=Ye(n.endTime||n.startTime),d=r.find(i=>i.label===s);return d?d.tasks.push(n):r.push({label:s,tasks:[n]}),r},[])}function et(t){const r=[`扫描 ${t.scanned}`];return t.imported>0&&r.push(`导入 ${t.imported}`),t.updated>0&&r.push(`更新 ${t.updated}`),t.messagesImported>0&&r.push(`${t.messagesImported} 条消息`),t.skipped>0&&r.push(`跳过 ${t.skipped}`),t.failed>0&&r.push(`失败 ${t.failed}`),`Codex 同步完成:${r.join(" · ")}`}const Lt=()=>{var ce;const t=Ie(),{cliConfig:r}=Be(),[n,s]=Pe(),d=Ve(n.get("filter")),i=n.get("detail"),[c,p]=m.useState([]),[x,l]=m.useState(!0),[y,f]=m.useState(""),[b,H]=m.useState(""),[N,v]=m.useState(null),[C,k]=m.useState(""),[S,E]=m.useState(!1),[T,re]=m.useState(null),[P,ae]=m.useState(""),[we,B]=m.useState(!1),[ve,se]=m.useState(null),[ne,U]=m.useState(""),z=m.useRef(null),L=m.useCallback(async()=>{try{const a=await $.fetchHistory();p(u=>a.map(h=>{const j=u.find(Fe=>Fe.id===h.id);return j!=null&&j.messagesLoaded?{...h,messagesLoaded:!0,messages:j.messages}:h}))}catch(a){console.error("[History] Failed to fetch:",a)}finally{l(!1)}},[]);m.useEffect(()=>{n.has("scope")&&s(a=>(a.delete("scope"),a),{replace:!0})},[n,s]),m.useEffect(()=>{L()},[L]),m.useEffect(()=>{H(""),k(""),v(null),U(""),z.current=null},[i]),m.useEffect(()=>{const u=Ue().onMessage(h=>{h.type==="history_changed"&&L()});return()=>{u()}},[L]);const ie=y.trim().toLowerCase(),le=c.filter(a=>d==="all"?!0:d==="active"?a.status==="running":a.status==="confirm"||a.status==="failed").filter(a=>ie?[a.title,a.preview,a.workDir,a.workDir?A(a.workDir):"",a.status].filter(Boolean).join(" ").toLowerCase().includes(ie):!0),Ce=Ze(le),o=c.find(a=>a.id===i),de=o!=null&&o.messagesLoaded?ze(o.messages):[],M=(r==null?void 0:r.workDir)||"",Se=M||"当前项目历史",Te=M?A(M):"未选择工作目录",J=o!=null&&o.workDir?A(o.workDir):"",$e=!!(o!=null&&o.workDir)&&!!M&&o.workDir!==M;m.useEffect(()=>{if(!i||!o||o.messagesLoaded||z.current===i)return;let a=!1;return z.current=i,se(i),U(""),$.fetchHistoryTask(i).then(u=>{if(!a){if(!u){U("会话记录不存在或已被删除");return}p(h=>h.map(j=>j.id===u.id?u:j))}}).catch(u=>{a||(console.error("[History] Failed to fetch detail:",u),U(u instanceof Error?u.message:"加载会话记录失败"))}).finally(()=>{a||(se(null),z.current=null)}),()=>{a=!0}},[i,o==null?void 0:o.id,o==null?void 0:o.messagesLoaded]);const De=a=>{s(u=>(u.set("filter",a),u.delete("detail"),u))},He=a=>{t(`/session?history=${encodeURIComponent(a)}`)},R=()=>{s(a=>(a.delete("detail"),a))},Ee=async(a,u)=>{u.stopPropagation();try{await $.deleteHistoryTask(a),p(h=>h.filter(j=>j.id!==a)),i===a&&R()}catch(h){console.error("[History] Failed to delete:",h)}},Le=async()=>{try{await $.clearHistory(),p([]),B(!1),R()}catch(a){console.error("[History] Failed to clear:",a)}},Me=async()=>{if(!S){E(!0),re(null),ae("");try{const a=await $.syncCodexHistory();re(a),await L()}catch(a){ae(a instanceof Error?a.message:"同步 Codex 记录失败")}finally{E(!1)}}},oe=async()=>{if(!o||N)return;const a=b.trim();if(a){if(!o.canResume){k("该会话记录缺少可恢复的 CLI 会话 ID,无法继续追问");return}v(o.id),k("");try{await $.resumeHistoryTask(o.id,a),H(""),t("/session")}catch(u){k(u instanceof Error?u.message:"恢复会话记录失败")}finally{v(null)}}},Re=[{id:"all",label:"全部",count:c.length},{id:"active",label:"进行中",count:c.filter(a=>a.status==="running").length},{id:"attention",label:"需要处理",count:c.filter(a=>a.status==="confirm"||a.status==="failed").length}];return e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950 relative",children:[e.jsx(Ae,{title:"历史会话",meta:e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[160px] flex-shrink-0",title:Se,children:[e.jsx(X,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:Te})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Me,disabled:S,title:"同步 Codex 本地记录",className:"p-2 rounded-full text-gray-500 hover:text-primary-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-primary-400 dark:hover:bg-gray-800 disabled:opacity-60 transition-colors",children:e.jsx(Ge,{className:g("w-4 h-4",S&&"animate-spin")})}),c.length>0&&e.jsx("button",{type:"button",onClick:()=>B(!0),title:"清空当前项目历史",className:"p-2 rounded-full text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-950/40 transition-colors flex-shrink-0",children:e.jsx(V,{className:"w-4 h-4"})})]}),bottom:e.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xe,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500"}),e.jsx("input",{value:y,onChange:a=>f(a.target.value),placeholder:"搜索标题、摘要或项目",className:"h-10 w-full rounded-xl border border-gray-200 bg-gray-50 pl-9 pr-9 text-sm text-gray-900 outline-none transition-colors placeholder:text-gray-400 focus:border-primary-300 focus:bg-white focus:ring-[3px] focus:ring-primary-100 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-100 dark:placeholder:text-gray-600 dark:focus:border-primary-700 dark:focus:bg-gray-950 dark:focus:ring-primary-950"}),y&&e.jsx("button",{type:"button",onClick:()=>f(""),className:"absolute right-2 top-1/2 rounded-full p-1 -translate-y-1/2 text-gray-400 hover:bg-gray-200 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:"清除搜索",children:e.jsx(me,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto hide-scrollbar",children:Re.map(a=>e.jsxs("button",{onClick:()=>De(a.id),className:g("inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium whitespace-nowrap transition-colors",d===a.id?"border-primary-200 bg-primary-50 text-primary-700 dark:border-primary-900 dark:bg-primary-950/60 dark:text-primary-300":"border-gray-200 bg-white text-gray-500 hover:text-gray-700 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-400 dark:hover:text-gray-300"),children:[a.label,e.jsx("span",{className:g("rounded-full px-1.5 py-0.5 text-[10px]",d===a.id?"bg-primary-100 text-primary-700 dark:bg-primary-900 dark:text-primary-200":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:a.count})]},a.id))})]})}),(T||P)&&e.jsx("div",{className:"px-4 pt-3 flex-shrink-0",children:e.jsxs("div",{className:g("flex items-start gap-2 rounded-lg border px-3 py-2 text-xs",P?"border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300":"border-green-200 bg-green-50 text-green-700 dark:border-green-900 dark:bg-green-950/40 dark:text-green-300"),title:((ce=T==null?void 0:T.errors)==null?void 0:ce.join(`
4
+ `))||void 0,children:[P?e.jsx(D,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0"}):e.jsx(W,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:P||(T?et(T):"")})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-3 pb-4 pt-3",children:x?e.jsx(jt,{}):le.length>0?e.jsx("div",{className:"space-y-5",children:Ce.map(a=>e.jsxs("section",{className:"space-y-2",children:[e.jsx("div",{className:"px-1 text-[11px] font-medium text-gray-400 dark:text-gray-600",children:a.label}),e.jsx("div",{className:"space-y-2",children:a.tasks.map(u=>e.jsx(wt,{task:u,onClick:()=>He(u.id),onDelete:h=>Ee(u.id,h)},u.id))})]},a.label))}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-400 dark:text-gray-600 gap-3",children:[y?e.jsx(xe,{className:"w-12 h-12 opacity-20"}):e.jsx(Ke,{className:"w-12 h-12 opacity-20"}),e.jsx("p",{className:"text-sm",children:y?"没有匹配的会话":"暂无相关会话"})]})}),e.jsx(ge,{children:we&&e.jsxs(e.Fragment,{children:[e.jsx(O.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>B(!1),className:"absolute inset-0 bg-black/40 z-40"}),e.jsxs(O.div,{initial:{y:24,opacity:0},animate:{y:0,opacity:1},exit:{y:24,opacity:0},transition:{duration:.18},className:"absolute bottom-4 left-4 right-4 z-50 rounded-2xl border border-gray-200 bg-white p-4 shadow-xl dark:border-gray-800 dark:bg-gray-900",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded-full bg-red-50 p-2 text-red-600 dark:bg-red-950/50 dark:text-red-400",children:e.jsx(V,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"清空历史会话"}),e.jsxs("div",{className:"mt-1 text-xs leading-relaxed text-gray-500 dark:text-gray-400",children:["将删除当前项目下的 ",c.length," 条历史会话,当前正在进行的对话不会被清空。"]})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>B(!1),className:"h-10 flex-1 rounded-xl border border-gray-200 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-gray-800 dark:text-gray-200 dark:hover:bg-gray-800",children:"取消"}),e.jsx("button",{type:"button",onClick:Le,className:"h-10 flex-1 rounded-xl bg-red-600 text-sm font-medium text-white transition-colors hover:bg-red-700",children:"清空"})]})]})]})}),e.jsx(ge,{children:i&&o&&e.jsxs(e.Fragment,{children:[e.jsx(O.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:R,className:"absolute inset-0 bg-black/40 z-40"}),e.jsxs(O.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",damping:25,stiffness:200},className:"absolute bottom-0 left-0 right-0 h-[85%] bg-white dark:bg-gray-900 rounded-t-2xl z-50 flex flex-col shadow-xl",children:[e.jsx("div",{className:"flex justify-center pt-3 pb-2 flex-shrink-0",onClick:R,children:e.jsx("div",{className:"w-12 h-1.5 bg-gray-300 dark:bg-gray-600 rounded-full"})}),e.jsxs("div",{className:"px-5 pb-4 border-b border-gray-100 dark:border-gray-800 flex-shrink-0",children:[e.jsxs("div",{className:"flex justify-between items-start gap-4 mb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-base font-medium text-gray-900 dark:text-gray-100 leading-snug",children:je(o)}),o.preview&&e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-relaxed text-gray-500 dark:text-gray-400",children:o.preview})]}),e.jsx("button",{onClick:R,className:"p-1 text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full flex-shrink-0",children:e.jsx(me,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx(vt,{status:o.status}),J&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1 text-xs text-gray-500 dark:text-gray-400",title:o.workDir,children:[e.jsx(X,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]}),o.duration&&e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["耗时 ",o.duration]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:ke(o.startTime)})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-5 bg-gray-50 dark:bg-gray-950",children:[e.jsx("div",{className:"text-center text-xs text-gray-400 dark:text-gray-600 mb-4",children:"完整消息流"}),ve===o.id?e.jsxs("div",{className:"flex flex-col items-center justify-center mt-10 gap-2 text-gray-400 dark:text-gray-600",children:[e.jsx(ue,{className:"w-5 h-5 animate-spin"}),e.jsx("div",{className:"text-sm",children:"正在加载会话详情"})]}):ne?e.jsx("div",{className:"text-center text-sm text-red-500 dark:text-red-400 mt-8",children:ne}):de.length>0?e.jsx("div",{className:"space-y-4",children:de.map(a=>e.jsx(tt,{message:a},a.id))}):o.messagesLoaded?e.jsx("div",{className:"text-center text-sm text-gray-400 dark:text-gray-600 mt-8",children:"无消息记录"}):e.jsx("div",{className:"text-center text-sm text-gray-400 dark:text-gray-600 mt-8",children:"点击后加载消息记录"})]}),e.jsx("div",{className:"border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900 p-3 pb-safe flex-shrink-0",children:o.canResume?e.jsxs(e.Fragment,{children:[$e&&e.jsxs("div",{className:"mb-2 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300",children:["继续后会切换到 ",J]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("textarea",{value:b,onChange:a=>{H(a.target.value),k(""),a.currentTarget.style.height="auto",a.currentTarget.style.height=`${Math.min(a.currentTarget.scrollHeight,96)}px`},onKeyDown:a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&(a.preventDefault(),oe())},placeholder:"基于这段会话继续追问…",rows:1,disabled:N===o.id,className:"flex-1 min-h-[42px] max-h-24 resize-none rounded-2xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 px-4 py-2.5 text-sm text-gray-800 dark:text-gray-200 placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none focus:border-primary-400 focus:bg-white dark:focus:bg-gray-800 focus:ring-[3px] focus:ring-primary-100 dark:focus:ring-primary-900 hide-scrollbar"}),e.jsx("button",{type:"button",onClick:oe,disabled:!b.trim()||N===o.id,className:g("p-2.5 rounded-full flex-shrink-0 transition-all duration-200 shadow-sm active:scale-95",b.trim()&&N!==o.id?"bg-primary-600 text-white hover:bg-primary-700":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500 shadow-none"),title:"继续追问",children:N===o.id?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):e.jsx(We,{className:"w-4 h-4"})})]}),C&&e.jsx("div",{className:"mt-2 text-xs text-red-500 dark:text-red-400 px-1",children:C})]}):e.jsx("div",{className:"rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-950 px-3 py-2 text-xs text-gray-500 dark:text-gray-400",children:"该会话记录缺少底层 CLI 会话 ID,无法继续追问。"})})]})]})})]})},tt=({message:t})=>{switch(t.type){case"ai_response":return e.jsx(ye,{message:t.message,resultMessage:t.resultMessage});case"process_group":return e.jsx(yt,{group:t});case"system_group":return e.jsx(bt,{group:t});case"tool_group":return e.jsx(ft,{group:t});case"user":return e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"bg-primary-600 text-white rounded-2xl rounded-tr-sm px-4 py-2.5 max-w-[85%] shadow-sm",children:e.jsx("p",{className:"text-[15px] leading-relaxed whitespace-pre-wrap",children:e.jsx(Oe,{linkClassName:"text-white decoration-white/70",children:t.content})})})});case"ai":return e.jsx(ye,{message:t});case"tool":return e.jsx(ht,{message:t});case"confirm":return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:g("border rounded-xl px-4 py-2.5 max-w-[85%] shadow-sm",t.status==="approved"?"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800":"bg-red-50 dark:bg-red-950 border-red-200 dark:border-red-800"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.status==="approved"?e.jsx(W,{className:"w-3.5 h-3.5 text-green-600"}):e.jsx(D,{className:"w-3.5 h-3.5 text-red-600"}),e.jsx("span",{className:g("text-xs font-medium",t.status==="approved"?"text-green-700 dark:text-green-400":"text-red-700 dark:text-red-400"),children:t.status==="approved"?"已批准":"已拒绝"})]}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:t.content})]})});case"system":{const r=t.details;if(r&&Object.keys(r).length>0){const n=r.subtype==="result",s=[];if(r.model&&s.push({label:"模型",value:r.model}),r.costUsd!=null&&s.push({label:"费用",value:`$${Number(r.costUsd).toFixed(4)}`}),r.durationMs!=null){const d=Math.round(Number(r.durationMs)/1e3);s.push({label:"耗时",value:d>=60?`${Math.floor(d/60)}m${d%60}s`:`${d}s`})}return r.numTurns!=null&&s.push({label:"轮次",value:String(r.numTurns)}),e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:`px-3 py-2 rounded-xl border max-w-[85%] ${n?"bg-green-50/80 dark:bg-green-950/40 border-green-200/60 dark:border-green-800/40":"bg-gray-50 dark:bg-gray-800/80 border-gray-200 dark:border-gray-700"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx("span",{className:`text-xs font-medium ${n?"text-green-700 dark:text-green-300":"text-gray-500 dark:text-gray-400"}`,children:t.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:t.time})]}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((d,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300",children:[e.jsx("span",{className:"opacity-60",children:d.label}),e.jsx("span",{className:"font-semibold",children:d.value})]},i))})]})})}return e.jsx("div",{className:"flex justify-start",children:e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded-full",children:t.content})})}case"thinking":return e.jsx(kt,{message:t});case"error":return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-800 text-red-800 dark:text-red-300 rounded-xl px-4 py-2.5 max-w-[85%] shadow-sm flex items-start gap-2",children:[e.jsx(D,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm leading-relaxed",children:t.content})]})});default:return null}};function Q(t){return Number(t||0).toLocaleString()}function rt(t){const r=Math.round(t/1e3);return r>=60?`${Math.floor(r/60)}m${r%60}s`:`${r}s`}function at(t){if(!t)return"";const r=[],n=Number(t.inputTokens||0),s=Number(t.outputTokens||0),d=Number(t.reasoningOutputTokens||0);return(n>0||s>0)&&(r.push(`${Q(n)} 输入`),r.push(`${Q(s)} 输出`)),d>0&&r.push(`${Q(d)} 推理`),t.costUsd!=null&&r.push(`$${Number(t.costUsd).toFixed(4)}`),t.durationMs!=null&&r.push(rt(Number(t.durationMs))),r.length>0?`Token ${r.join(" · ")}`:""}const ye=({message:t,resultMessage:r})=>e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[88%] min-w-0",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 text-gray-800 dark:text-gray-200 rounded-2xl rounded-tl-md px-3.5 py-3 shadow-sm markdown-body overflow-hidden min-w-0",children:e.jsx(F,{children:t.content})}),(r==null?void 0:r.details)&&e.jsx(st,{message:r})]})}),st=({message:t})=>{const[r,n]=m.useState(!1),s=Z(t),d=at(t.details);return!d&&s.length===0?null:e.jsxs("div",{className:"mt-1 ml-1 min-w-0 text-[10px] text-gray-400 dark:text-gray-500",children:[e.jsxs("button",{type:"button",onClick:()=>s.length>0&&n(i=>!i),className:g("inline-flex max-w-full items-center gap-1 rounded-md px-1 py-0.5 text-left transition-colors",s.length>0&&"hover:bg-gray-100 dark:hover:bg-gray-900"),title:r?"收起用量详情":"展开用量详情",children:[e.jsx("span",{className:"truncate",children:d||"完成元信息"}),s.length>0&&(r?e.jsx(I,{className:"h-3 w-3 flex-shrink-0"}):e.jsx(w,{className:"h-3 w-3 flex-shrink-0"}))]}),r&&s.length>0&&e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:s.map((i,c)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300",children:[e.jsx("span",{className:"opacity-60",children:i.label}),e.jsx("span",{className:"font-semibold",children:i.value})]},`${i.label}-${c}`))})]})};function nt(t){const r=(t.toolName||t.content||"").toLowerCase();return["readfile","writefile","read","write","edit","multiedit"].includes(r)}function G(t){return t.toolName&&t.toolName!=="result"?t.toolName:t.content||"tool"}function it(t){return Ne(t).join("、")||"工具调用"}function Ne(t){return Array.from(new Set(t.map(G).filter(Boolean)))}function lt(t){if(t.some(r=>r.status==="failed"))return"failed";if(t.some(r=>r.status==="running"))return"running";if(t.some(r=>r.status==="success"))return"success"}function dt(t){const r=t.filter(i=>i.status==="running").length,n=t.filter(i=>i.status==="failed").length,s=t.filter(i=>i.status==="success").length,d=[`${t.length} 个`];return r&&d.push(`${r} 运行中`),n&&d.push(`${n} 失败`),s&&!r&&!n&&d.push("已完成"),d.join(" · ")}function ee(t,r="w-4 h-4 text-primary-600 dark:text-primary-400"){return nt(t)?e.jsx(Je,{className:r}):e.jsx(_,{className:r})}function te({status:t,className:r="w-3.5 h-3.5"}){return t==="running"?e.jsx(Qe,{className:g(r,"text-primary-500 animate-pulse")}):t==="success"?e.jsx(W,{className:g(r,"text-green-600")}):t==="failed"?e.jsx(D,{className:g(r,"text-red-600")}):null}function Y({status:t}){return e.jsx("span",{className:g("w-1.5 h-1.5 rounded-full flex-shrink-0",t==="running"?"bg-primary-500 animate-pulse":t==="failed"?"bg-red-500":t==="success"?"bg-green-500":"bg-gray-300 dark:bg-gray-600")})}function ot(t){return t==="running"?"运行中":t==="success"?"已完成":t==="failed"?"失败":"待执行"}const K=({message:t,compact:r=!1,section:n="both"})=>{const s="max-h-32";return e.jsxs(e.Fragment,{children:[n!=="output"&&t.toolDetails&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-0.5",children:"输入"}),e.jsx("div",{className:g("text-xs text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 p-2 rounded-lg border border-primary-50 dark:border-gray-700 overflow-y-auto",s),children:e.jsx(F,{children:pe(t.toolDetails)})})]}),n!=="input"&&t.toolResult&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-0.5",children:"输出"}),e.jsx("div",{className:g("text-xs p-2 rounded-lg overflow-y-auto",s,t.status==="failed"?"text-red-700 dark:text-red-300 bg-red-50/50 dark:bg-red-950/50 border border-red-100 dark:border-red-900":"text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 border border-primary-50 dark:border-gray-700"),children:e.jsx(F,{children:pe(t.toolResult)})})]})]})};function ct(t){if(t.some(r=>r.status==="failed"))return"failed";if(t.some(r=>r.status==="running"))return"running";if(t.some(r=>r.status==="success"))return"success"}function xt(t){const r=t.filter(c=>c.type==="thinking"||c.type==="ai").length,n=t.filter(c=>c.type==="tool").length,s=t.filter(c=>c.type==="tool"&&!!c.toolResult).length,d=t.filter(c=>c.type==="system").length,i=[`${t.length} 步`];return r&&i.push(`${r} 思考`),n&&i.push(`${n} 执行`),s&&i.push(`${s} 观察`),d&&i.push(`${d} 元信息`),i.join(" · ")}function mt(t){return t==="failed"?"失败":t==="running"?"运行中":t==="success"?"已完成":"待执行"}function ut(t,r){return`${mt(r)} · ${t.length} 步`}function gt(t){return t.type==="thinking"?"思考":t.type==="system"?"元信息":t.type==="ai"?"思考":"过程"}function pt(t){return t.type==="thinking"?e.jsx(be,{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400"}):t.type==="system"?e.jsx(_,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500"}):e.jsx(he,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500"})}const yt=({group:t})=>{const[r,n]=m.useState(!1),[s,d]=m.useState({}),i=ct(t.messages),c=xt(t.messages),p=ut(t.messages,i),x=m.useCallback(l=>{d(y=>({...y,[l]:!y[l]}))},[]);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[85%] min-w-0 rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50/90 dark:bg-gray-900/80 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>n(!r),className:"w-full max-w-full px-3 py-2 flex items-center gap-2 text-left min-w-0 overflow-hidden hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",children:[r?e.jsx(w,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(q,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx(qe,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-gray-600 dark:text-gray-300 flex-shrink-0",children:"执行过程"}),e.jsxs("span",{className:g("inline-flex min-w-0 max-w-[48%] shrink items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full",i==="failed"?"bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300":i==="running"?"bg-primary-100 text-primary-700 dark:bg-primary-950 dark:text-primary-300":"bg-gray-200/70 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),title:c,children:[e.jsx(Y,{status:i}),e.jsx("span",{className:"min-w-0 truncate",children:p})]}),e.jsx("span",{className:"hidden sm:inline text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate min-w-0 flex-1",title:t.content,children:t.content})]}),r&&e.jsx("div",{className:"border-t border-gray-200/80 dark:border-gray-800 divide-y divide-gray-200/70 dark:divide-gray-800",children:t.messages.map(l=>{if(l.type==="tool"){const b=G(l),H=l.content&&l.content!==b,N=`${l.id}:input`,v=`${l.id}:output`,C=!!s[N],k=!!s[v],S=!!l.toolDetails,E=!!l.toolResult;return e.jsxs("div",{className:"px-3 py-2 min-w-0 bg-white/40 dark:bg-gray-900/30",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx("span",{className:"mt-0.5 flex-shrink-0",children:ee(l,"w-3.5 h-3.5 text-primary-600 dark:text-primary-400")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary-50 px-1.5 py-0.5 text-[10px] font-semibold leading-none text-primary-700 dark:bg-primary-950/60 dark:text-primary-300 flex-shrink-0",children:"执行"}),e.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 font-mono text-[11px] leading-none text-gray-700 dark:bg-gray-800 dark:text-gray-200 truncate",title:b,children:b}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:l.time}),e.jsx(te,{status:l.status,className:"w-3 h-3"})]}),H&&e.jsx("span",{className:"mt-1 block text-xs text-gray-500 dark:text-gray-400 truncate",title:l.content,children:l.content})]}),S&&e.jsx("button",{type:"button",onClick:()=>x(N),className:"mt-0.5 rounded p-0.5 text-primary-500 hover:bg-primary-50 dark:hover:bg-primary-950 flex-shrink-0",title:C?"收起执行输入":"展开执行输入",children:C?e.jsx(I,{className:"w-3 h-3"}):e.jsx(w,{className:"w-3 h-3"})})]}),S&&C&&e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{message:l,compact:!0,section:"input"})}),E&&e.jsxs("div",{className:g("mt-2 rounded-lg border px-2 py-1.5 flex items-start gap-2 min-w-0",l.status==="failed"?"border-red-100 bg-red-50/60 dark:border-red-900/60 dark:bg-red-950/20":"border-green-100 bg-green-50/40 dark:border-green-900/50 dark:bg-green-950/15"),children:[e.jsx(_e,{className:g("mt-0.5 w-3.5 h-3.5 flex-shrink-0",l.status==="failed"?"text-red-500 dark:text-red-400":"text-green-600 dark:text-green-400")}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:g("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-semibold leading-none flex-shrink-0",l.status==="failed"?"bg-red-100 text-red-700 dark:bg-red-950/70 dark:text-red-300":"bg-green-100 text-green-700 dark:bg-green-950/70 dark:text-green-300"),children:"观察"}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:l.status==="failed"?"执行失败输出":"执行结果"}),e.jsxs("span",{className:g("inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] leading-none flex-shrink-0",l.status==="failed"?"bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300":"bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300"),children:[e.jsx(Y,{status:l.status}),ot(l.status)]})]})}),e.jsx("button",{type:"button",onClick:()=>x(v),className:"mt-0.5 rounded p-0.5 text-primary-500 hover:bg-primary-50 dark:hover:bg-primary-950 flex-shrink-0",title:k?"收起观察结果":"展开观察结果",children:k?e.jsx(I,{className:"w-3 h-3"}):e.jsx(w,{className:"w-3 h-3"})})]}),E&&k&&e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{message:l,compact:!0,section:"output"})})]},l.id)}const y=gt(l),f=l.type==="thinking"||l.type==="ai";return e.jsx("div",{className:g("px-3 py-2 min-w-0",f&&"bg-indigo-50/60 dark:bg-indigo-950/20"),children:e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx("span",{className:"mt-0.5 flex-shrink-0",children:pt(l)}),e.jsxs("div",{className:g("min-w-0 flex-1",f&&"border-l-2 border-indigo-200 pl-2 dark:border-indigo-800/80"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:g("truncate font-semibold",f?"inline-flex items-center rounded-full bg-indigo-100 px-1.5 py-0.5 text-[10px] leading-none text-indigo-700 dark:bg-indigo-950/70 dark:text-indigo-300":"text-xs text-gray-600 dark:text-gray-300"),title:y,children:y}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:l.time})]}),(l.type==="ai"||l.type==="thinking")&&e.jsx("div",{className:"mt-1.5 text-xs leading-relaxed text-gray-700 dark:text-indigo-100 markdown-body-sm",children:e.jsx(F,{children:l.content})}),l.type==="system"&&e.jsx("span",{className:"mt-1 block text-xs text-gray-500 dark:text-gray-400 truncate",title:l.content,children:l.content})]})]})},l.id)})})]})})},ht=({message:t})=>e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-primary-50 dark:bg-primary-950 border border-primary-100 dark:border-primary-900 rounded-xl px-3 py-2 max-w-[85%] flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[ee(t),e.jsx("span",{className:"text-sm text-primary-800 dark:text-primary-300 break-words min-w-0",children:t.content}),e.jsx("span",{className:"ml-auto flex-shrink-0",children:e.jsx(te,{status:t.status})})]}),e.jsx(K,{message:t})]})}),ft=({group:t})=>{const[r,n]=m.useState(!1),[s,d]=m.useState({}),i=lt(t.messages),c=it(t.messages),p=m.useCallback(x=>{d(l=>({...l,[x]:!l[x]}))},[]);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[85%] rounded-xl border border-primary-100 dark:border-gray-700 bg-primary-50/90 dark:bg-gray-800 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>n(!r),className:"w-full px-3 py-2 flex items-center gap-2 text-left min-w-0 hover:bg-primary-100/60 dark:hover:bg-gray-700 transition-colors",children:[r?e.jsx(w,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}):e.jsx(q,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}),e.jsx(_,{className:"w-3.5 h-3.5 text-primary-600 dark:text-primary-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-primary-800 dark:text-primary-300 flex-shrink-0",children:"工具调用"}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",i==="failed"?"bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300":i==="running"?"bg-primary-100 text-primary-700 dark:bg-primary-950 dark:text-primary-300":"bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300"),children:dt(t.messages)}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"min-w-0 truncate text-xs text-gray-600 dark:text-gray-400",title:c,children:c})]}),!r&&e.jsx("div",{className:"px-3 pb-2 flex flex-wrap gap-1.5",children:Ne(t.messages).map(x=>{const l=t.messages.find(y=>G(y)===x);return e.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-600 dark:text-gray-300 border border-primary-100/60 dark:border-gray-700",title:x,children:[e.jsx(Y,{status:l==null?void 0:l.status}),e.jsx("span",{className:"truncate text-left",children:x})]},x)})}),r&&e.jsx("div",{className:"border-t border-primary-100/80 dark:border-gray-700 divide-y divide-primary-100/70 dark:divide-gray-700",children:t.messages.map(x=>{const l=G(x),y=x.content&&x.content!==l,f=!!(x.toolDetails||x.toolResult),b=!!s[x.id];return e.jsxs("div",{className:"px-3 py-2 flex flex-col gap-1.5 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>f&&p(x.id),className:g("w-full flex flex-col gap-1 min-w-0 text-left",f&&"cursor-pointer hover:text-primary-900 dark:hover:text-primary-200"),children:[e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0",children:[ee(x,"w-3.5 h-3.5 text-primary-600 dark:text-primary-400 flex-shrink-0 mt-0.5"),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold text-primary-800 dark:text-primary-300",title:l,children:l}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:x.time}),f&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-500 dark:text-gray-400 border border-primary-100/60 dark:border-gray-700",children:x.toolDetails&&x.toolResult?"输入/输出":x.toolDetails?"输入":"输出"}),e.jsx(te,{status:x.status,className:"w-3 h-3"}),f&&(b?e.jsx(I,{className:"w-3 h-3 text-primary-500"}):e.jsx(w,{className:"w-3 h-3 text-primary-500"}))]})]}),y&&e.jsx("span",{className:"w-full pl-5 pr-1 text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:x.content})]}),f&&b&&e.jsx(K,{message:x,compact:!0})]},x.id)})})]})})};function Z(t){const r=t.details;if(!r)return[];const n=[];if(r.model&&n.push({label:"模型",value:r.model}),r.costUsd!=null&&n.push({label:"费用",value:`$${Number(r.costUsd).toFixed(4)}`}),r.durationMs!=null){const s=Math.round(Number(r.durationMs)/1e3);n.push({label:"耗时",value:s>=60?`${Math.floor(s/60)}m${s%60}s`:`${s}s`})}if(r.numTurns!=null&&n.push({label:"轮次",value:String(r.numTurns)}),r.inputTokens!=null||r.outputTokens!=null){const s=r.inputTokens?Number(r.inputTokens).toLocaleString():"0",d=r.outputTokens?Number(r.outputTokens).toLocaleString():"0";n.push({label:"Token",value:`${s} → ${d}`})}return r.reasoningOutputTokens!=null&&n.push({label:"推理",value:Number(r.reasoningOutputTokens).toLocaleString()}),n}const bt=({group:t})=>{const[r,n]=m.useState(!1),s=t.messages.length>1,d=t.messages[t.messages.length-1],i=Z(d);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[85%] rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50/90 dark:bg-gray-900/80 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>s&&n(!r),className:g("w-full px-3 py-2 flex items-center gap-2 text-left min-w-0",s&&"hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"),children:[s?r?e.jsx(w,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(q,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(_,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-gray-600 dark:text-gray-300 flex-shrink-0",children:"系统消息"}),s&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-gray-200/70 dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex-shrink-0",children:[t.messages.length," 条"]}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:t.content})]}),!r&&i.length>0&&e.jsx("div",{className:"px-3 pb-2 flex flex-wrap gap-1.5",children:i.map((c,p)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 max-w-full",children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:c.label}),e.jsx("span",{className:"font-semibold truncate",children:c.value})]},`${c.label}-${p}`))}),r&&s&&e.jsx("div",{className:"border-t border-gray-200/80 dark:border-gray-800 divide-y divide-gray-200/70 dark:divide-gray-800",children:t.messages.map(c=>{const p=Z(c);return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate min-w-0",children:c.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:c.time})]}),p.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:p.map((x,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 max-w-full",children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:x.label}),e.jsx("span",{className:"font-semibold truncate",children:x.value})]},`${x.label}-${l}`))})]},c.id)})})]})})},kt=({message:t})=>{const[r,n]=m.useState(!1);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-indigo-50/80 dark:bg-indigo-950/40 border border-indigo-200/60 dark:border-indigo-800/40 rounded-xl px-3 py-2 max-w-[85%] cursor-pointer hover:bg-indigo-100/60 dark:hover:bg-indigo-950/60 transition-colors",onClick:()=>n(!r),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(be,{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-indigo-600 dark:text-indigo-400",children:"思考过程"}),e.jsxs("span",{className:"text-[10px] text-indigo-400 dark:text-indigo-500",children:["(",t.content.length," 字)"]}),r?e.jsx(I,{className:"w-3 h-3 text-indigo-400"}):e.jsx(w,{className:"w-3 h-3 text-indigo-400"})]}),r&&e.jsx("div",{className:"mt-2 text-sm text-indigo-800/80 dark:text-indigo-200/80 markdown-body-sm prose-sm",children:e.jsx(F,{children:t.content})})]})})},jt=()=>e.jsx("div",{className:"space-y-3",children:[0,1,2,3].map(t=>e.jsx("div",{className:"rounded-xl border border-gray-100 bg-white p-3.5 shadow-sm dark:border-gray-800 dark:bg-gray-900",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-9 w-9 animate-pulse rounded-full bg-gray-100 dark:bg-gray-800"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-gray-100 dark:bg-gray-800"}),e.jsx("div",{className:"h-3 w-full animate-pulse rounded bg-gray-100 dark:bg-gray-800"}),e.jsx("div",{className:"h-3 w-1/2 animate-pulse rounded bg-gray-100 dark:bg-gray-800"})]})]})},t))}),Nt=({status:t})=>{switch(t){case"running":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary-50 px-2 py-0.5 text-[10px] font-medium text-primary-700 dark:bg-primary-950/60 dark:text-primary-300",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary-500 animate-pulse"}),"进行中"]});case"confirm":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-orange-50 px-2 py-0.5 text-[10px] font-medium text-orange-700 dark:bg-orange-950/50 dark:text-orange-300",children:[e.jsx(fe,{className:"h-3 w-3"}),"待确认"]});case"failed":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-[10px] font-medium text-red-700 dark:bg-red-950/50 dark:text-red-300",children:[e.jsx(D,{className:"h-3 w-3"}),"失败"]});case"completed":return null}},wt=({task:t,onClick:r,onDelete:n})=>{const s=je(t),d=Xe(t),i=t.workDir?A(t.workDir):"",c=[t.messageCount?`${t.messageCount} 条消息`:"",t.confirmCount>0?`${t.confirmCount} 次确认`:"",t.toolCount>0?`${t.toolCount} 个工具`:"",t.duration||""].filter(Boolean);return e.jsx("div",{onClick:r,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),r())},role:"button",tabIndex:0,className:"group cursor-pointer rounded-xl border border-gray-100 bg-white p-3.5 shadow-sm transition-colors active:scale-[0.99] hover:border-gray-200 hover:bg-gray-50/70 dark:border-gray-800 dark:bg-gray-900 dark:hover:border-gray-700 dark:hover:bg-gray-900/80",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400",children:e.jsx(he,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("h3",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-gray-100",title:s,children:s}),e.jsx("span",{className:"flex-shrink-0 text-[11px] text-gray-400 dark:text-gray-500",children:ke(t.endTime||t.startTime)})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-relaxed text-gray-500 dark:text-gray-400",title:d,children:d}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[i&&e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1 rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-500 dark:bg-gray-800 dark:text-gray-400",title:t.workDir,children:[e.jsx(X,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:i})]}),e.jsx(Nt,{status:t.status}),t.canResume&&e.jsx("span",{className:"inline-flex items-center rounded-full bg-green-50 px-2 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-950/50 dark:text-green-300",children:"可继续"}),c.map(p=>e.jsx("span",{className:"rounded-full bg-gray-50 px-2 py-0.5 text-[10px] text-gray-400 dark:bg-gray-950 dark:text-gray-500",children:p},p))]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1 pt-5",children:[e.jsx("button",{onClick:n,className:"rounded-full p-1.5 text-gray-300 transition-colors hover:bg-red-50 hover:text-red-500 dark:text-gray-600 dark:hover:bg-red-950/40 dark:hover:text-red-400",title:"删除会话",children:e.jsx(V,{className:"h-3.5 w-3.5"})}),e.jsx(q,{className:"h-4 w-4 text-gray-300 dark:text-gray-600"})]})]})})},vt=({status:t})=>{switch(t){case"running":return e.jsxs("div",{className:"flex items-center gap-1.5 text-primary-600 dark:text-primary-400",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary-600 dark:bg-primary-400 animate-pulse"}),e.jsx("span",{className:"text-xs font-medium",children:"进行中"})]});case"confirm":return e.jsxs("div",{className:"flex items-center gap-1.5 text-orange-600 dark:text-orange-400",children:[e.jsx(fe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"等待确认"})]});case"completed":return e.jsxs("div",{className:"flex items-center gap-1.5 text-green-600",children:[e.jsx(W,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"已完成"})]});case"failed":return e.jsxs("div",{className:"flex items-center gap-1.5 text-red-600",children:[e.jsx(D,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"失败"})]})}};export{Lt as History};
@@ -0,0 +1 @@
1
+ import{R as lt,r,j as i}from"./vendor-react-CcDXZHn_.js";import{c as H}from"./index-CrJqHlc8.js";import{E as ut,a4 as ht,z as ft,R as xt}from"./vendor-icons-CMXJHDEv.js";const c=1,dt=16;function D(p,u,Y){return Math.min(Y,Math.max(u,p))}function G(p,u){return Math.hypot(p.x-u.x,p.y-u.y)}function K(p,u){return{x:(p.x+u.x)/2,y:(p.y+u.y)/2}}const yt=lt.memo(function({src:u,alt:Y="",resetKey:U,className:q,canvasClassName:J,imageClassName:Q,padding:M=dt}){const O=r.useRef(null),x=r.useRef(new Map),R=r.useRef(null),h=r.useRef(c),C=r.useRef({x:0,y:0}),A=r.useRef(null),y=r.useRef({width:0,height:0}),[v,L]=r.useState(c),[V,B]=r.useState({x:0,y:0}),[k,F]=r.useState(null),[f,tt]=r.useState({width:0,height:0});r.useEffect(()=>{A.current=k},[k]),r.useEffect(()=>{y.current=f},[f]);const T=r.useMemo(()=>{if(!k||f.width<=0||f.height<=0)return 1;const t=Math.max(1,f.width-M*2),e=Math.max(1,f.height-M*2);return Math.min(t/k.naturalWidth,e/k.naturalHeight,1)},[k,M,f.height,f.width]),P=r.useMemo(()=>Math.max(c,1/T),[T]),d=r.useMemo(()=>Math.min(16,Math.max(4,P*3)),[P]),et=Math.max(1,Math.round(v*T*100)),Z=r.useCallback((t,e)=>{const n=A.current,s=y.current;if(!n||s.width<=0||s.height<=0)return{x:0,y:0};const l=Math.max(1,s.width-M*2),m=Math.max(1,s.height-M*2),w=Math.min(l/n.naturalWidth,m/n.naturalHeight,1),j=n.naturalWidth*w*e,S=n.naturalHeight*w*e,N=Math.max(0,(j-l)/2),g=Math.max(0,(S-m)/2);return{x:N>0?D(t.x,-N,N):0,y:g>0?D(t.y,-g,g):0}},[M]),a=r.useCallback((t,e)=>{const n=D(t,c,d),s=n<=c?{x:0,y:0}:Z(e,n);h.current=n,C.current=s,L(n),B(s)},[Z,d]),o=r.useCallback((t,e)=>{var s;const n=(s=O.current)==null?void 0:s.getBoundingClientRect();return n?{x:t-n.left,y:e-n.top}:{x:y.current.width/2,y:y.current.height/2}},[]),b=r.useCallback((t,e)=>{const n=h.current,s=C.current,l=D(t,c,d);if(!e||n<=0){a(l,s);return}const m=y.current,w={x:m.width/2,y:m.height/2},j={x:(e.x-w.x-s.x)/n,y:(e.y-w.y-s.y)/n},S={x:e.x-w.x-j.x*l,y:e.y-w.y-j.y*l};a(l,S)},[a,d]),X=r.useCallback(()=>{a(c,{x:0,y:0})},[a]),rt=r.useCallback(()=>{a(h.current,{x:0,y:0})},[a]),W=r.useCallback(()=>{const t=y.current;b(P,{x:t.width/2,y:t.height/2})},[P,b]),z=r.useCallback(t=>{const e=y.current;b(h.current*t,{x:e.width/2,y:e.height/2})},[b]);r.useEffect(()=>{var t;F(null),x.current.clear(),R.current=null,h.current=c,C.current={x:0,y:0},L(c),B({x:0,y:0}),(t=O.current)==null||t.focus({preventScroll:!0})},[U,u]),r.useEffect(()=>{const t=O.current;if(!t)return;const e=()=>{const s=t.getBoundingClientRect();tt({width:s.width,height:s.height})};e();const n=typeof ResizeObserver<"u"?new ResizeObserver(e):null;return n==null||n.observe(t),window.addEventListener("resize",e),()=>{n==null||n.disconnect(),window.removeEventListener("resize",e)}},[]),r.useEffect(()=>{a(h.current,C.current)},[a,k,f.height,f.width]);const E=r.useCallback(()=>Array.from(x.current.values()).map(t=>o(t.clientX,t.clientY)),[o]),I=r.useCallback(()=>{const[t,e]=E();!t||!e||(R.current={mode:"pinch",startDistance:Math.max(1,G(t,e)),startMidpoint:K(t,e),startScale:h.current,startOffset:C.current})},[E]),nt=r.useCallback(t=>{if(!(t.pointerType==="mouse"&&t.button!==0)){if(t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId),x.current.set(t.pointerId,{clientX:t.clientX,clientY:t.clientY}),x.current.size>=2){I();return}R.current={mode:"pan",startPoint:o(t.clientX,t.clientY),startOffset:C.current}}},[o,I]),st=r.useCallback(t=>{if(!x.current.has(t.pointerId))return;x.current.set(t.pointerId,{clientX:t.clientX,clientY:t.clientY});const e=R.current;if(!e)return;if(e.mode==="pinch"){const[l,m]=E();if(!l||!m)return;const w=Math.max(1,G(l,m)),j=K(l,m),S=D(e.startScale*(w/e.startDistance),c,d),N=y.current,g={x:N.width/2,y:N.height/2},$={x:(e.startMidpoint.x-g.x-e.startOffset.x)/e.startScale,y:(e.startMidpoint.y-g.y-e.startOffset.y)/e.startScale},ot={x:j.x-g.x-$.x*S,y:j.y-g.y-$.y*S};a(S,ot);return}const n=o(t.clientX,t.clientY),s={x:e.startOffset.x+n.x-e.startPoint.x,y:e.startOffset.y+n.y-e.startPoint.y};a(h.current,s)},[a,E,d,o]),_=r.useCallback(t=>{if(t.currentTarget.hasPointerCapture(t.pointerId)&&t.currentTarget.releasePointerCapture(t.pointerId),x.current.delete(t.pointerId),x.current.size>=2){I();return}const e=Array.from(x.current.values())[0];if(e){R.current={mode:"pan",startPoint:o(e.clientX,e.clientY),startOffset:C.current};return}R.current=null},[o,I]),it=r.useCallback(t=>{t.preventDefault();const e=o(t.clientX,t.clientY),n=Math.exp(-t.deltaY*.0015);b(h.current*n,e)},[o,b]),ct=r.useCallback(t=>{const e=o(t.clientX,t.clientY),n=Math.min(d,Math.max(P,2));b(h.current<=c+.02?n:c,e)},[P,d,o,b]),at=r.useCallback(t=>{if(t.key==="+"||t.key==="="){t.preventDefault(),z(1.25);return}if(t.key==="-"||t.key==="_"){t.preventDefault(),z(.8);return}if(t.key==="0"){t.preventDefault(),X();return}t.key==="1"&&(t.preventDefault(),W())},[X,z,W]);return i.jsxs("div",{className:H("relative h-full min-h-0 overflow-hidden",q),children:[i.jsx("div",{ref:O,className:H("relative h-full w-full overflow-hidden touch-none select-none outline-none",v>c?"cursor-grab active:cursor-grabbing":"cursor-zoom-in",J),tabIndex:0,onDoubleClick:ct,onKeyDown:at,onPointerCancel:_,onPointerDown:nt,onPointerMove:st,onPointerUp:_,onWheel:it,children:i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",style:{padding:M},children:i.jsx("img",{src:u,alt:Y,className:H("max-h-full max-w-full object-contain shadow-sm will-change-transform",Q),draggable:!1,onLoad:t=>{F({naturalWidth:t.currentTarget.naturalWidth||1,naturalHeight:t.currentTarget.naturalHeight||1})},style:{transform:`translate3d(${V.x}px, ${V.y}px, 0) scale(${v})`,transformOrigin:"center center"}})})}),i.jsx("div",{className:"pointer-events-none absolute bottom-3 left-0 right-0 z-10 flex justify-center px-3",children:i.jsxs("div",{className:"pointer-events-auto flex max-w-full items-center gap-1 rounded-full border border-white/10 bg-black/70 px-1.5 py-1.5 text-white shadow-lg backdrop-blur",children:[i.jsx("button",{type:"button",onClick:()=>z(.8),className:"flex h-8 w-8 items-center justify-center rounded-full text-white/85 transition-colors hover:bg-white/10 hover:text-white disabled:opacity-40",disabled:v<=c,title:"缩小","aria-label":"缩小",children:i.jsx(ut,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:X,className:"flex h-8 w-8 items-center justify-center rounded-full text-white/85 transition-colors hover:bg-white/10 hover:text-white",title:"适屏","aria-label":"适屏",children:i.jsx(ht,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:W,className:"flex h-8 min-w-8 items-center justify-center rounded-full px-2 text-[11px] font-semibold text-white/85 transition-colors hover:bg-white/10 hover:text-white",title:"原始大小","aria-label":"原始大小",children:"1:1"}),i.jsxs("div",{className:"min-w-12 px-1 text-center text-[11px] font-medium tabular-nums text-white/75",children:[et,"%"]}),i.jsx("button",{type:"button",onClick:()=>z(1.25),className:"flex h-8 w-8 items-center justify-center rounded-full text-white/85 transition-colors hover:bg-white/10 hover:text-white disabled:opacity-40",disabled:v>=d,title:"放大","aria-label":"放大",children:i.jsx(ft,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:rt,className:"flex h-8 w-8 items-center justify-center rounded-full text-white/85 transition-colors hover:bg-white/10 hover:text-white",title:"居中图片","aria-label":"居中图片",children:i.jsx(xt,{className:"h-4 w-4"})})]})})]})});export{yt as Z};
@@ -0,0 +1 @@
1
+ import{r as d,j as o,R as x}from"./vendor-react-CcDXZHn_.js";import{u as W}from"./index-CrJqHlc8.js";import{b as R,c as S}from"./java-VnEXKtx_.js";import{u as L,p as T,f as E,s as A}from"./WorkspaceLinkedText-DCVYd9x-.js";import{M as H,r as _}from"./vendor-markdown--d-T3AbU.js";import{a5 as P,g as M,a6 as F}from"./vendor-icons-CMXJHDEv.js";import"./workspace-return-FrQUv7g3.js";const G=[_],b="agentpilot.markdownCodeWrap",y="agentpilot:markdown-code-wrap-change",I=8e4;function V(e){return function(){return function(a){N(a,e)}}}function D(e){return(e==null?void 0:e.type)==="element"&&["a","pre"].includes(e.tagName)}function N(e,t){if(!(e!=null&&e.children)||D(e))return;const r=[];let a=!1;for(const n of e.children){if((n==null?void 0:n.type)==="text"&&typeof n.value=="string"){const i=A(n.value,t);if(i.length===1&&i[0].type==="text"){r.push(n);continue}a=!0;for(const f of i)f.type==="text"?r.push({type:"text",value:f.text}):r.push({type:"element",tagName:"a",properties:{href:f.target.href,title:E(f.target)},children:[{type:"text",value:f.text}]});continue}N(n,t),r.push(n)}a&&(e.children=r)}function O(e){return e.startsWith("/workspace?")}function h(...e){return e.filter(Boolean).join(" ")}function C(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(C).join(""):x.isValidElement(e)?C(e.props.children):""}function z(e){var a;const t=x.Children.toArray(e).find(x.isValidElement);return x.isValidElement(t)&&((a=String(t.props.className||"").match(/language-([^\s]+)/))==null?void 0:a[1])||""}function B(e){if(typeof document>"u")return!1;const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="-9999px",document.body.appendChild(t),t.select();try{return document.execCommand("copy")}finally{document.body.removeChild(t)}}async function K(e){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(e),!0}catch{}return B(e)}function X(e){return!!e&&/^https?:\/\//i.test(e)}function Y(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(b)==="true"}catch{return!1}}function $(e){if(!(typeof window>"u")){try{window.localStorage.setItem(b,e?"true":"false")}catch{}window.dispatchEvent(new CustomEvent(y,{detail:e}))}}function q(){const[e,t]=d.useState(Y);d.useEffect(()=>{function a(i){i.key===b&&t(i.newValue==="true")}function n(i){i instanceof CustomEvent&&typeof i.detail=="boolean"&&t(i.detail)}return window.addEventListener("storage",a),window.addEventListener(y,n),()=>{window.removeEventListener("storage",a),window.removeEventListener(y,n)}},[]);const r=d.useCallback(a=>{t(a),$(a)},[]);return[e,r]}function J({children:e,...t}){const[r,a]=d.useState(!1),[n,i]=q(),[f,s]=d.useState(!1),m=d.useRef(null),w=z(e),c=C(e).replace(/\n$/,""),u=R(w,c),k=!!u&&c.length<=I;return d.useEffect(()=>{if(!r)return;const l=window.setTimeout(()=>a(!1),1200);return()=>window.clearTimeout(l)},[r]),d.useEffect(()=>{const l=m.current;if(!l||n){s(!1);return}const g=()=>{s(l.scrollWidth>l.clientWidth+1)};g();const p=typeof ResizeObserver<"u"?new ResizeObserver(g):null;return p==null||p.observe(l),window.addEventListener("resize",g),()=>{p==null||p.disconnect(),window.removeEventListener("resize",g)}},[c,n]),o.jsxs("div",{className:h("markdown-code-frame",n&&"is-wrapped",f&&"is-scrollable"),children:[o.jsxs("div",{className:"markdown-code-toolbar",children:[o.jsx("span",{className:"markdown-code-language",children:u||"code"}),o.jsx("button",{type:"button",className:h("markdown-code-action",n&&"is-active"),onClick:()=>i(!n),title:n?"关闭代码换行":"开启代码换行","aria-label":n?"关闭代码换行":"开启代码换行",children:o.jsx(P,{className:"h-3.5 w-3.5"})}),o.jsx("button",{type:"button",className:h("markdown-code-action",r&&"is-active"),onClick:async()=>{await K(c)&&a(!0)},title:r?"已复制":"复制代码","aria-label":r?"已复制":"复制代码",children:r?o.jsx(M,{className:"h-3.5 w-3.5"}):o.jsx(F,{className:"h-3.5 w-3.5"})})]}),o.jsx("pre",{...t,ref:m,className:h("markdown-code-pre",t.className),children:o.jsx(S,{content:c,language:u,className:"markdown-code-shiki-code",highlight:k})})]})}function ae({children:e,enableWorkspaceLinks:t=!0}){const{cliConfig:r}=W(),a=L(),n=r==null?void 0:r.workDir,i=d.useMemo(()=>{const s=[];return t&&s.push(V(n)),s},[t,n]),f=d.useMemo(()=>({a({href:s,children:m,node:w,...c}){const u=typeof s=="string"?T(s,n):null,k=typeof s=="string"&&O(s),l=(u==null?void 0:u.href)||(k?s:""),g=l||s,p=X(g),j=!!u||k;return o.jsx("a",{...c,href:g,className:h("markdown-link",j&&"markdown-file-link",c.className),title:u?E(u):c.title,target:p?"_blank":c.target,rel:p?"noreferrer":c.rel,onClick:v=>{l&&a(v,l)},children:m})},pre({children:s,node:m,...w}){return o.jsx(J,{...w,children:s})},table({children:s,node:m,...w}){return o.jsx("div",{className:"markdown-table-wrap",role:"region","aria-label":"横向滚动表格",tabIndex:0,children:o.jsx("table",{...w,children:s})})},img({src:s,alt:m,node:w,...c}){return o.jsx("span",{className:"markdown-image-wrap",children:o.jsx("img",{...c,src:s,alt:m||"",loading:"lazy"})})}}),[a,n]);return o.jsx(H,{remarkPlugins:G,rehypePlugins:i,components:f,children:e})}export{ae as default};
@@ -1 +1 @@
1
- import{j as e}from"./vendor-react-DSV5aFEg.js";import{c}from"./index-DOgH1Kf3.js";const x=({title:a,meta:s,leading:i,actions:r,bottom:t,className:l})=>e.jsxs("div",{className:c("bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800 flex-shrink-0 pt-safe z-10",l),children:[e.jsxs("div",{className:"min-h-14 px-4 py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i,e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:a}),s&&e.jsx("div",{className:"mt-0.5 flex items-center gap-2 min-w-0",children:s})]})]}),r&&e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:r})]}),t]});export{x as P};
1
+ import{j as e}from"./vendor-react-CcDXZHn_.js";import{c}from"./index-CrJqHlc8.js";const x=({title:a,meta:s,leading:i,actions:r,bottom:t,className:l})=>e.jsxs("div",{className:c("bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800 flex-shrink-0 pt-safe z-10",l),children:[e.jsxs("div",{className:"min-h-14 px-4 py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i,e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:a}),s&&e.jsx("div",{className:"mt-0.5 flex items-center gap-2 min-w-0",children:s})]})]}),r&&e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:r})]}),t]});export{x as P};
@@ -0,0 +1,7 @@
1
+ import{u as Ms,b as Ps,d as Ds,r as l,j as e,R as D}from"./vendor-react-CcDXZHn_.js";import{u as $s}from"./vendor-virtual-DJI7OicV.js";import{u as Ls,a as Fs,s as mt,b as ht,c as g,M as Us,g as zr,d as Hs,e as Os,f as _s}from"./index-CrJqHlc8.js";import{g as Ws,W as qs,i as Jt,M as Ce,a as Ks}from"./WorkspaceLinkedText-DCVYd9x-.js";import{P as Bs}from"./PageTopBar-CQwjO6Af.js";import{Z as zs}from"./ImageViewer-DuegU_fC.js";import{r as Vs,c as Hr}from"./workspace-return-FrQUv7g3.js";import{X as Q,M as ft,H as Oe,S as ee,C as O,a as Or,b as Qs,T as Zt,A as Gs,c as Js,d as me,R as _r,e as te,L as pt,I as Zs,f as Ys,g as Yt,B as Xt,F as wt,h as We,i as Xs,j as ea,D as ta,k as ra,P as sa,Z as aa,l as na,m as la,n as ia}from"./vendor-icons-CMXJHDEv.js";const oa=48,da=2,ca=12e3,ua=1e3;function xa(r,t=oa){return r.scrollHeight-r.scrollTop-r.clientHeight<=t}function gt(r){return!Number.isFinite(r)||r<=0?"":r<1024*1024?`${Math.max(1,Math.round(r/1024))} KB`:`${(r/1024/1024).toFixed(r>=10*1024*1024?0:1)} MB`}function Vr(r){const t=gt(r.size);return`${r.name}${t?` · ${t}`:""}`}function ma(r){return r.map(t=>({id:t.id,name:t.name,size:t.size,url:ht.getAttachmentPreviewUrl(t.path)}))}function ga(r){return r.map(t=>({id:t.id,name:t.name,size:t.size,url:t.previewUrl}))}function Wr(r){if(/^```/.test(r.trim()))return r;try{const o=JSON.parse(r);return"```json\n"+JSON.stringify(o,null,2)+"\n```"}catch{}return r.split(`
2
+ `).map(o=>{const n=o.trim();if(!n)return o;try{const c=JSON.parse(n);return"```json\n"+JSON.stringify(c,null,2)+"\n```"}catch{return o}}).join(`
3
+ `)}function qr(r,t){const i=Math.min(Math.max(t,0),r.length),n=r.slice(0,i).match(/(^|\s)([^\s]*)$/),c=(n==null?void 0:n[2])||"";if(!c)return null;const u=i-c.length,f=i;if(c.startsWith("@"))return{mode:"file",prefix:"@",start:u,end:f,query:c.slice(1)};if(c.startsWith("/")){const w=r.lastIndexOf(`
4
+ `,Math.max(0,u-1))+1,j=r.slice(w,u);if(/^\s*$/.test(j))return{mode:"command",prefix:"/",start:u,end:f,query:c.slice(1)}}return null}function ha(r){var n;const t=(r==null?void 0:r.cliCommand)||"",i=((n=t.split(/[\\/]/).pop())==null?void 0:n.toLowerCase())||t.toLowerCase();return((r==null?void 0:r.cliType)||(i.includes("codex")?"codex":"claude"))==="codex"?"Codex CLI":"Claude Code"}function Kr(r){var o,n;const t=(o=r==null?void 0:r.title)==null?void 0:o.trim();if(t&&t!=="会话记录")return t;const i=(n=r==null?void 0:r.preview)==null?void 0:n.trim();return i?i.length>36?`${i.slice(0,36).trimEnd()}...`:i:"历史会话"}function fa(r){return r?r.split(/[\\/]/).filter(Boolean).pop()||r:""}function pa(r){return r.reduce((t,i)=>{var o;return i.type!=="system"||((o=i.details)==null?void 0:o.subtype)!=="result"?t:{inputTokens:t.inputTokens+Number(i.details.inputTokens||0),outputTokens:t.outputTokens+Number(i.details.outputTokens||0),cacheReadTokens:t.cacheReadTokens+Number(i.details.cacheReadTokens||0),cacheCreationTokens:t.cacheCreationTokens+Number(i.details.cacheCreationTokens||0),costUsd:t.costUsd+Number(i.details.costUsd||0)}},{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0})}function ya(r){return r?`history:${r}`:"live"}function _e(r){var t,i,o;return r?[r.id,r.type,r.status||"",r.content.length,((t=r.toolResult)==null?void 0:t.length)||0,((i=r.toolDetails)==null?void 0:i.length)||0,((o=r.details)==null?void 0:o.subtype)||""].join(":"):""}function ba(r){if(!r)return"";if(r.type==="ai_response")return["ai_response",r.id,_e(r.message),_e(r.resultMessage)].join(":");if(Jt(r)){const t=r.messages[r.messages.length-1];return[r.type,r.id,r.messages.length,r.content,_e(t)].join(":")}return _e(r)}function ka(r){const t=Math.max(0,Math.floor(r/1e3));if(t<60)return`${t}s`;const i=Math.floor(t/60),o=t%60;return`${i}m ${o.toString().padStart(2,"0")}s`}function ja(r){const t=r.map(i=>i.type).lastIndexOf("user");return t===-1?r:r.slice(t+1)}function wa(r){const t=r[r.length-1];return _e(t)}function Na(r,t){var o;const i=r[r.length-1];if(!i)return{label:`正在等待 ${t} 返回`,tone:"waiting"};if(i.type==="thinking")return{label:"正在整理思考",tone:"thinking"};if(i.type==="tool"){const n=Nt(i);return i.status==="running"?{label:`正在执行 ${n}`,tone:"tool"}:i.status==="failed"?{label:`${n} 未完成,等待下一步`,tone:"waiting"}:{label:`${n} 已完成,等待下一步`,tone:"tool"}}return i.type==="ai"?{label:"正在生成回复",tone:"active"}:i.type==="system"?{label:((o=i.details)==null?void 0:o.subtype)==="init"?"会话已初始化":"正在处理系统事件",tone:"active"}:i.type==="confirm"?{label:"等待确认",tone:"waiting"}:i.type==="question"?{label:"等待回答",tone:"waiting"}:i.type==="error"?{label:"收到错误,等待 CLI 收尾",tone:"waiting"}:{label:"正在处理",tone:"active"}}function va(r,t,i,o){const n=Na(r,t),c=ka(i);return o>=ca?{label:"仍在处理,暂无新输出",detail:`${n.label} · 已运行 ${c}`,tone:"waiting"}:{...n,detail:`已运行 ${c}`}}const on=()=>{var Lr,Fr;const{status:r,messages:t,promptQueue:i,promptQueuePaused:o,connectionStatus:n,sendMessage:c,queuePrompt:u,removeQueuedPrompt:f,clearPromptQueue:w,resumePromptQueue:j,confirmResponse:v,questionResponse:p,interrupt:m,newSession:I,editUserMessage:A,cliConfig:h,tokenUsage:y,hasMoreMessagesBefore:R,isLoadingOlderMessages:M,loadOlderMessages:F}=Ls(),E=Ms(),_=Ps(),[re]=Ds(),G=re.get("history"),k=!!G,vt=ha(h),K=i,Re=o,{inputValue:T,setInputValue:tr,attachments:se,attachmentError:Ct,attachmentUploading:ge,attachmentFailed:qe,readyAttachments:Ke,uploadImageFiles:Tt,removeAttachment:Yr,retryAttachmentUpload:Xr,clearDraft:rr}=Fs(),[es,Se]=l.useState(!1),[ts,Be]=l.useState(null),[Rt,St]=l.useState(!1),[rs,ze]=l.useState(!1),[x,he]=l.useState(null),[Ie,z]=l.useState(0),[sr,It]=l.useState([]),[ae,ar]=l.useState(!1),[nr,At]=l.useState(!1),[lr,Ve]=l.useState([]),[ne,ir]=l.useState(!1),[or,Qe]=l.useState(!1),[Et,Mt]=l.useState(""),[fe,ss]=l.useState(""),[dr,as]=l.useState([]),[cr,ns]=l.useState([]),[ur,ls]=l.useState([]),[Ge,is]=l.useState(""),[xr,os]=l.useState(!1),[pe,mr]=l.useState(!1),[J,Je]=l.useState(null),[Ae,Ee]=l.useState(""),[Pt,Ze]=l.useState(!1),[ds,le]=l.useState(null),[C,Dt]=l.useState(null),[gr,$t]=l.useState(!1),[Ye,Xe]=l.useState(""),[Me,Lt]=l.useState(""),[ye,Ft]=l.useState(!1),[hr,be]=l.useState(""),[ke,et]=l.useState({}),[cs,us]=l.useState(!0),[xs,tt]=l.useState(!1),[fr,pr]=l.useState(null),[yr,Ut]=l.useState(null),[rt,Ht]=l.useState(Date.now()),ie=l.useRef(null),st=l.useRef(null),Ot=l.useRef(null),oe=l.useRef(Vs()),W=l.useRef(null),Pe=l.useRef(!0),De=l.useRef(),at=l.useRef(new Set),je=l.useRef(!1),de=l.useRef(0),$e=l.useRef(null),nt=l.useRef(""),we=`${_.pathname}${_.search}${_.hash}`,Z=ya(G),_t=l.useMemo(()=>{if(k||r!=="running"||t.length===0)return null;const s=t.map(d=>d.type).lastIndexOf("user");return s===-1||t.slice(s+1).some(d=>["thinking","ai","tool","confirm","question","error"].includes(d.type))?null:{id:"active-thinking-placeholder",type:"thinking",status:"running",content:"正在等待 CLI 返回可展示的思考摘要。",time:""}},[k,t,r]),S=l.useMemo(()=>{const s=k?(C==null?void 0:C.messages)||[]:t;return Ws(_t?[...s,_t]:s,{finalizeCurrentTurn:k||r==="idle"})},[_t,C==null?void 0:C.messages,k,t,r]),lt=l.useMemo(()=>{const s={};if(k)return s;const a=S.map(d=>d.type).lastIndexOf("user");if(r==="running"&&a!==-1)for(let d=S.length-1;d>a;d-=1){const b=S[d];if(b.type==="process_group"){s[b.id]=!0;break}}return s},[S,k,r]),Le=l.useCallback(s=>ke[s]??lt[s]??!1,[lt,ke]),Wt=l.useMemo(()=>k?pa((C==null?void 0:C.messages)||[]):y,[C==null?void 0:C.messages,k,y]),br=l.useCallback(s=>{const a=W.current;if(!a)return null;const d=s.closest("[data-message-id]"),b=a.getBoundingClientRect(),N=d?d.getBoundingClientRect().top-b.top:void 0;return{sourceKey:Z,messageId:(d==null?void 0:d.dataset.messageId)||void 0,scrollTop:a.scrollTop,messageTop:N,expandedIds:Object.entries(ke).filter(([,L])=>L).map(([L])=>L)}},[Z,ke]),ms=l.useMemo(()=>({createReturnAnchor:br}),[br]),ce=l.useMemo(()=>ba(S[S.length-1]),[S]),it=l.useMemo(()=>k?[]:ja(t),[k,t]),gs=l.useMemo(()=>wa(it),[it]),qt=l.useMemo(()=>{if(k||r!=="running")return null;const s=fr??rt,a=yr??s;return va(it,vt,rt-s,rt-a)},[vt,k,yr,it,fr,rt,r]),P=l.useCallback((s,a=s)=>{Pe.current=s,us(d=>d===s?d:s),s&&a&&tt(!1)},[]),ue=l.useCallback(()=>{const s=W.current;if(!s)return;const a=s.getBoundingClientRect(),d=a.top+4,N=Array.from(s.querySelectorAll("[data-message-id]")).find(L=>L.getBoundingClientRect().bottom>d);N!=null&&N.dataset.messageId&&($e.current={messageId:N.dataset.messageId,messageTop:N.getBoundingClientRect().top-a.top})},[]);l.useEffect(()=>{if(k||r!=="running"){pr(null),Ut(null);return}const s=Date.now();pr(a=>a??s),Ut(a=>a??s),Ht(s)},[k,r]),l.useEffect(()=>{k||r!=="running"||Ut(Date.now())},[k,gs,r]),l.useEffect(()=>{if(k||r!=="running")return;Ht(Date.now());const s=window.setInterval(()=>{Ht(Date.now())},ua);return()=>window.clearInterval(s)},[k,r]);const H=$s({count:S.length,getScrollElement:()=>W.current,getItemKey:s=>{var a;return((a=S[s])==null?void 0:a.id)??s},estimateSize:s=>{const a=S[s];return a?a.type==="ai_response"?a.resultMessage?112:80:a.type==="process_group"?Le(a.id)?72+a.messages.length*52:36:a.type==="system_group"?Le(a.id)?48+a.messages.length*42:32:a.type==="tool_group"?Le(a.id)?72+a.messages.length*40:34:a.type==="system"&&!a.details&&a.content==="系统消息"?0:a.type==="system"&&!a.details?28:a.type==="thinking"?Le(a.id)?96:34:a.type==="tool"?34:a.type==="confirm"?80:a.type==="question"?100:a.type==="error"?60:80:80},overscan:5});H.shouldAdjustScrollPositionOnItemSizeChange=s=>{const a=W.current;return a?Pe.current?s.start<a.scrollTop:s.end<=a.scrollTop:!0},l.useEffect(()=>{const s=W.current;if(!s)return;de.current=s.scrollTop;const a=()=>{const d=de.current,b=s.scrollTop;de.current=b,b<d-da?(P(!1,!1),ue()):xa(s)?(P(!0),$e.current=null):(P(!1,!1),ue()),!k&&s.scrollTop<80&&R&&!M&&F()};return s.addEventListener("scroll",a,{passive:!0}),()=>s.removeEventListener("scroll",a)},[ue,R,k,M,F,P]),l.useEffect(()=>{var d,b;if(((d=oe.current)==null?void 0:d.sourceRoute)===we&&((b=oe.current)==null?void 0:b.sourceKey)===Z||(je.current=!1,at.current.clear(),$e.current=null,nt.current="",P(!0),et({})),tt(!1),Lt(""),be(""),Ft(!1),!G){Dt(null),$t(!1),Xe("");return}let a=!1;return Dt(null),$t(!0),Xe(""),mt.fetchHistoryTask(G).then(N=>{if(!a){if(!N){Xe("会话记录不存在或已被删除");return}Dt(N)}}).catch(N=>{a||Xe(N instanceof Error?N.message:"加载会话记录失败")}).finally(()=>{a||$t(!1)}),()=>{a=!0}},[Z,we,G,P]),l.useEffect(()=>{var s,a;if(t.length===0){if(((s=oe.current)==null?void 0:s.sourceRoute)===we&&((a=oe.current)==null?void 0:a.sourceKey)===Z)return;je.current=!1,at.current.clear(),$e.current=null,nt.current="",P(!0),tt(!1),et({})}},[Z,we,t.length,P]),l.useLayoutEffect(()=>{var xe;const s=oe.current;if(!s)return;if(s.sourceRoute!==we||s.sourceKey!==Z){oe.current=null,Hr();return}if((xe=s.expandedIds)!=null&&xe.some(B=>ke[B]!==!0)){je.current=!0,P(!1,!1),et(B=>{var Ur;const ve={...B};return(Ur=s.expandedIds)==null||Ur.forEach(Es=>{ve[Es]=!0}),ve});return}if(S.length===0)return;const a=W.current;if(!a)return;const d=s.messageId?S.findIndex(B=>B.id===s.messageId):-1;je.current=!0,P(!1,!1);let b=0,N=0;const L=()=>{if(d>=0&&s.messageId&&s.messageTop!==void 0){const B=Array.from(a.querySelectorAll("[data-message-id]")).find(ve=>ve.dataset.messageId===s.messageId);if(B){const ve=B.getBoundingClientRect().top-a.getBoundingClientRect().top;a.scrollTop+=ve-s.messageTop}else s.scrollTop!==void 0&&(a.scrollTop=s.scrollTop)}else s.scrollTop!==void 0&&(a.scrollTop=s.scrollTop);oe.current=null,Hr()};return b=requestAnimationFrame(()=>{d>=0?H.scrollToIndex(d,{align:"start"}):s.scrollTop!==void 0&&(a.scrollTop=s.scrollTop),N=requestAnimationFrame(L)}),()=>{b&&cancelAnimationFrame(b),N&&cancelAnimationFrame(N)}},[Z,we,S,ke,P,H]),l.useLayoutEffect(()=>{if(k||Pe.current||!ce)return;const s=()=>{const d=$e.current,b=W.current;if(!d||!b){ue();return}const N=Array.from(b.querySelectorAll("[data-message-id]")).find(B=>B.dataset.messageId===d.messageId);if(!N){ue();return}const xe=N.getBoundingClientRect().top-b.getBoundingClientRect().top-d.messageTop;Math.abs(xe)>1&&(b.scrollTop+=xe,de.current=b.scrollTop),ue()};s();const a=requestAnimationFrame(s);return()=>cancelAnimationFrame(a)},[ue,ce,k]),l.useEffect(()=>{S.length>0&&!je.current&&(je.current=!0,requestAnimationFrame(()=>{H.scrollToIndex(S.length-1,{align:"end"});const s=W.current;s&&(de.current=s.scrollTop),P(!0)}))},[S.length,P,H]),l.useEffect(()=>{const s=nt.current;nt.current=ce,!(!ce||!s||s===ce)&&!k&&!Pe.current&&tt(!0)},[ce,k]),l.useEffect(()=>(S.length>0&&Pe.current&&(De.current&&cancelAnimationFrame(De.current),De.current=requestAnimationFrame(()=>{H.scrollToIndex(S.length-1,{align:"end"});const s=W.current;s&&(de.current=s.scrollTop),P(!0)})),()=>{De.current&&cancelAnimationFrame(De.current)}),[S.length,ce,P,H]);const hs=l.useCallback(()=>{S.length!==0&&(P(!0),requestAnimationFrame(()=>{H.scrollToIndex(S.length-1,{align:"end"});const s=W.current;s&&(de.current=s.scrollTop)}))},[S.length,P,H]),fs=l.useCallback(s=>{et(a=>{const d=a[s]??lt[s]??!1;return{...a,[s]:!d}})},[lt]),ot=l.useCallback(()=>{const s=Ot.current,a=ie.current;if(!s||!a)return;Ot.current=null;const d=Math.min(s.start,a.value.length),b=Math.min(s.end,a.value.length);a.focus(),a.setSelectionRange(d,b)},[]),U=l.useCallback((s,a=s.length)=>{Ot.current={start:a,end:a},tr(s),requestAnimationFrame(ot)},[ot]);l.useLayoutEffect(()=>{const s=ie.current;s&&(s.style.height="auto",s.style.height=T?`${Math.min(s.scrollHeight,120)}px`:"auto")},[T]),l.useLayoutEffect(()=>{ot()},[T,ot]);const kr=l.useCallback(async()=>{if(!ae){ar(!0);try{const s=await ht.getSkills();It(s.skills||[]),At(!0)}catch{It([]),At(!0)}finally{ar(!1)}}},[ae]),dt=l.useCallback(async()=>{if(!ne){ir(!0),Mt("");try{const s=await mt.fetchPromptHistory({scope:"current",limit:50});Ve(s),Qe(!0)}catch(s){Ve([]),Mt(s instanceof Error&&s.message?s.message:"加载历史提问失败"),Qe(!0)}finally{ir(!1)}}},[ne]);l.useEffect(()=>{It([]),At(!1)},[h==null?void 0:h.workDir,h==null?void 0:h.cliCommand]),l.useEffect(()=>{Ve([]),Qe(!1),Mt("")},[h==null?void 0:h.workDir]),l.useEffect(()=>{(x==null?void 0:x.mode)==="command"&&!nr&&!ae&&kr()},[x==null?void 0:x.mode,nr,ae,kr]),l.useEffect(()=>{(x==null?void 0:x.mode)==="history"&&!or&&!ne&&dt()},[x==null?void 0:x.mode,dt,or,ne]);const V=n==="disconnected",Y=n==="reconnecting",$=l.useCallback(()=>{he(null),z(0)},[]),Ne=l.useCallback(async s=>{mr(!0);try{const a=await ht.listFiles(s);ss(a.dir),as(a.dirs),ns(a.files||[]),ls(a.quickAccess||[]),is(a.parent),os(a.isRoot)}catch{}mr(!1)},[]),ct=l.useCallback(()=>{const s=ie.current;return s?{start:s.selectionStart??T.length,end:s.selectionEnd??s.selectionStart??T.length}:{start:T.length,end:T.length}},[T.length]),Fe=l.useCallback((s,a,d,b=d.length)=>{const N=T.slice(0,s)+d+T.slice(a);return U(N,s+b),N},[T,U]),Kt=l.useCallback((s,a)=>{const d=qr(s,a);if(!d){$();return}he({mode:d.mode,trigger:d}),z(0),d.mode==="file"&&((x==null?void 0:x.mode)!=="file"||!fe)&&!pe&&Ne((h==null?void 0:h.workDir)||"~")},[x==null?void 0:x.mode,h==null?void 0:h.workDir,$,fe,pe,Ne]),Ue=l.useCallback(()=>{rr(),Se(!1),$(),ie.current&&(ie.current.style.height="auto"),st.current&&(st.current.value="")},[rr,$]),jr=l.useCallback(()=>{const s={content:T,attachments:Ke};if(!(!(T.trim()||Ke.length>0)||V||Y||ge||qe)){if(r!=="idle"||Re||K.length>0){u(s),St(!0),Ue();return}r==="idle"&&(c(s),Ue())}},[qe,ge,Ue,T,V,Y,Re,u,K.length,Ke,c,r]),ps=l.useCallback(()=>{m()},[m]),wr=l.useCallback(()=>{Ue(),w(),I()},[Ue,w,I]);l.useEffect(()=>{K.length>0||St(!1)},[K.length]);const ys=s=>{const a=s.target.value;tr(a);const d=s.target;d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,120)}px`,Kt(a,d.selectionStart??a.length)},bs=l.useCallback(()=>{if((x==null?void 0:x.mode)==="history")return;const s=ie.current;s&&Kt(s.value,s.selectionStart??s.value.length)},[x==null?void 0:x.mode,Kt]),Nr=l.useCallback(s=>{const a=T,d=a.trimStart(),b=s+" ",N=b.length;if(d===""){U(b,N);return}if(d.startsWith("/ ")||d.startsWith("! ")||d.startsWith("@ ")||d.startsWith("# ")){const L=d.slice(2);U(b+L,N);return}if(d.startsWith("/")||d.startsWith("!")||d.startsWith("@")||d.startsWith("#")){const L=d.indexOf(" "),xe=L>=0?d.slice(L+1):"";U(b+xe,N);return}U(b+a,N)},[T,U]),vr=l.useCallback(()=>{const s=ct(),a=qr(T,s.start),d=(a==null?void 0:a.mode)==="file"?a.start:s.start,b=(a==null?void 0:a.mode)==="file"?a.end:s.end,N=T.slice(0,d)+"@"+T.slice(b);U(N,d+1),he({mode:"file",trigger:{mode:"file",prefix:"@",start:d,end:d+1,query:""}}),z(0),pe||Ne((h==null?void 0:h.workDir)||"~")},[h==null?void 0:h.workDir,pe,ct,T,Ne,U]),Cr=l.useCallback(()=>{const s=T,a=s.trimStart();let d="/";if(!a)d="/";else if(a.startsWith("/"))d=a;else if(a.startsWith("!")||a.startsWith("@")||a.startsWith("#")){const N=a.indexOf(" "),L=N>=0?a.slice(N+1):"";d=L?`/ ${L}`:"/"}else d=`/ ${s}`;const b=d.startsWith("/ ")?2:Math.max(1,d.search(/\s/)===-1?d.length:d.search(/\s/)+1);U(d,1),he({mode:"command",trigger:{mode:"command",prefix:"/",start:0,end:b,query:""}}),z(0)},[T,U]),ut=l.useCallback(s=>{if(s==="/"){Cr();return}if(s==="@"){vr();return}Nr(s),$()},[$,Cr,vr,Nr]),Tr=l.useCallback(s=>{const a=`${s} `,d=x==null?void 0:x.trigger;if((d==null?void 0:d.mode)==="command"){const b=T[d.end]===" "?d.end+1:d.end;Fe(d.start,b,a)}else U(a,a.length);$()},[x==null?void 0:x.trigger,$,T,Fe,U]),Bt=l.useCallback(s=>{const a=((h==null?void 0:h.workDir)||fe).split("/").slice(0,3).join("/");return a?s.replace(a,"~"):s},[h==null?void 0:h.workDir,fe]),Rr=l.useCallback(s=>{const d=`@${Bt(s)} `,b=x==null?void 0:x.trigger;if((b==null?void 0:b.mode)==="file"){const N=T[b.end]===" "?b.end+1:b.end;Fe(b.start,N,d)}else{const N=ct();Fe(N.start,N.end,d)}$()},[x==null?void 0:x.trigger,$,Bt,ct,T,Fe]),Sr=l.useCallback(s=>{Ne(s),he(a=>(a==null?void 0:a.mode)==="file"&&a.trigger?{...a,trigger:{...a.trigger,query:""}}:a),z(0)},[Ne]),Ir=l.useCallback(s=>{U(s),$()},[$,U]),ks=l.useCallback(async s=>{Ve(a=>a.filter(d=>d.id!==s));try{await mt.deletePromptHistory(s,{scope:"current"})}catch{Qe(!1)}},[]),js=s=>{v(s)},ws=l.useCallback(s=>{r!=="idle"||n!=="connected"||(Je(s.id),Ee(s.content),le(null),$())},[$,n,r]),Ns=l.useCallback(()=>{Je(null),Ee(""),Ze(!1),le(null)},[]),vs=l.useCallback(async()=>{if(!J||Pt)return;const s=t.find(a=>a.id===J);if(!Ae.trim()){le("消息不能为空");return}if(s&&Ae.trim()===s.content.trim()){le("内容没有变化");return}Ze(!0),le(null);try{await A(J,Ae),Je(null),Ee("")}catch(a){le(a instanceof Error?a.message:"编辑消息失败")}finally{Ze(!1)}},[A,J,Pt,Ae,t]),Ar=l.useCallback(async()=>{if(!C||ye)return;const s=Me.trim();if(s){if(!C.canResume){be("该会话记录缺少可恢复的 CLI 会话 ID,无法继续追问");return}if(n!=="connected"){be("连接恢复后才能继续该会话");return}Ft(!0),be("");try{await mt.resumeHistoryTask(C.id,s),Lt(""),E("/session")}catch(a){be(a instanceof Error?a.message:"恢复会话记录失败")}finally{Ft(!1)}}},[n,Me,ye,C,E]);l.useEffect(()=>{J&&!t.some(s=>s.id===J)&&(Je(null),Ee(""),le(null),Ze(!1))},[J,t]);const Cs=!k&&r==="idle"&&n==="connected",zt=r!=="idle"||Re||K.length>0,Er=(!!T.trim()||Ke.length>0)&&!V&&!Y&&!ge&&!qe,Ts=V||Y?"连接已断开":ge?"图片处理中...":qe?"请先重试或移除失败图片":zt?"继续追问,会加入队列...":"输入指令...",Rs=l.useCallback(s=>{Be({items:ga(se),index:s})},[se]),Ss=l.useCallback((s,a)=>{Be({items:ma(s),index:a})},[]),Is=H.getVirtualItems(),xt=(x==null?void 0:x.mode)==="command"?(((Lr=x.trigger)==null?void 0:Lr.query)||"").toLowerCase():"",X=(x==null?void 0:x.mode)==="file"?(((Fr=x.trigger)==null?void 0:Fr.query)||"").toLowerCase():"",Vt=!k&&xs&&!cs&&S.length>0,As=qt?Vt?112:72:16,Qt=l.useMemo(()=>sr.filter(s=>!xt||s.command.toLowerCase().includes(xt)||s.description.toLowerCase().includes(xt)),[xt,sr]),Mr=l.useMemo(()=>dr.filter(s=>!X||s.name.toLowerCase().includes(X)),[X,dr]),Pr=l.useMemo(()=>cr.filter(s=>!X||s.name.toLowerCase().includes(X)),[X,cr]),q=l.useMemo(()=>{if(!x)return[];if(x.mode==="command")return Qt.map(s=>({kind:"command",key:`${s.source}:${s.name}`,command:s.command,description:s.description,source:s.source}));if(x.mode==="file"){const s=[];return X||s.push(...ur.map(a=>({kind:"file-quick",key:`quick:${a.path}`,name:a.name,path:a.path}))),!xr&&Ge&&s.push({kind:"file-parent",key:`parent:${Ge}`,path:Ge}),s.push(...Mr.map(a=>({kind:"file-dir",key:`dir:${a.path}`,name:a.name,path:a.path}))),s.push(...Pr.map(a=>({kind:"file-file",key:`file:${a.path}`,name:a.name,path:a.path,ext:a.ext}))),s}return lr.map(s=>({kind:"history",key:`prompt-history:${s.id}`,id:s.id,text:s.text,useCount:s.useCount,lastUsedAt:s.lastUsedAt}))},[X,x,xr,Ge,ur,Mr,Pr,Qt,lr]),Dr=T.trimStart().charAt(0);l.useEffect(()=>{Ie>Math.max(0,q.length-1)&&z(0)},[Ie,q.length]);const $r=l.useCallback(s=>{switch(s.kind){case"command":Tr(s.command);break;case"file-quick":case"file-parent":case"file-dir":Sr(s.path);break;case"file-file":Rr(s.path);break;case"history":Ir(s.text);break}},[Sr,Tr,Rr,Ir]);return e.jsx(qs,{value:ms,children:e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950",children:[e.jsx(Bs,{leading:k?e.jsx("div",{className:"flex h-4 w-4 flex-shrink-0 items-center justify-center text-gray-500 dark:text-gray-400",children:e.jsx(Oe,{className:"h-4 w-4"})}):e.jsx("div",{className:"relative flex items-center justify-center w-4 h-4 flex-shrink-0",children:V?e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500"}):n==="connecting"?e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-500 animate-pulse"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500 z-10"}),r==="running"&&e.jsx("div",{className:"absolute w-4 h-4 rounded-full bg-green-500 opacity-30 animate-ping"})]})}),title:k?Kr(C):vt,meta:k?e.jsxs(e.Fragment,{children:[(C==null?void 0:C.workDir)&&e.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[120px] flex-shrink-0",children:fa(C.workDir)}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full font-medium",C!=null&&C.canResume?"bg-primary-50 dark:bg-primary-950 text-primary-600 dark:text-primary-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"),children:C!=null&&C.canResume?"可继续":"只读"})]}):e.jsxs(e.Fragment,{children:[(h==null?void 0:h.workDir)&&e.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[120px] flex-shrink-0",children:h.workDir.split("/").pop()}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full font-medium",V?"bg-red-50 dark:bg-red-950 text-red-600 dark:text-red-400":Y||n==="connecting"?"bg-yellow-50 dark:bg-yellow-950 text-yellow-600 dark:text-yellow-400":r==="idle"?"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400":r==="running"?"bg-primary-50 dark:bg-primary-950 text-primary-600 dark:text-primary-400":r==="confirm"?"bg-orange-50 dark:bg-orange-950 text-orange-600 dark:text-orange-400":r==="question"?"bg-blue-50 dark:bg-blue-950 text-blue-600 dark:text-blue-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"),children:V?"已断开":Y?"重连中...":n==="connecting"?"连接中...":r==="idle"?"空闲":r==="running"?"进行中":r==="confirm"?"等待确认":r==="question"?"等待回答":"空闲"})]}),actions:e.jsxs(e.Fragment,{children:[Wt.inputTokens>0&&e.jsxs("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[120px] flex-shrink-0",children:[(Wt.inputTokens+Wt.outputTokens).toLocaleString()," tok"]}),k?e.jsx("button",{onClick:()=>E("/session"),className:"p-2 text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:bg-primary-50 dark:hover:bg-primary-950 rounded-full transition-colors",title:"返回当前会话",children:e.jsx(Q,{className:"w-5 h-5"})}):e.jsx("button",{onClick:()=>{t.length>0||K.length>0?ze(!0):wr()},className:"p-2 text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:bg-primary-50 dark:hover:bg-primary-950 rounded-full transition-colors",title:"新开会话",children:e.jsx(ft,{className:"w-5 h-5"})})]})}),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{ref:W,className:"h-full overflow-y-auto overflow-x-hidden",children:k&&gr?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-400 dark:text-gray-600 gap-3",children:[e.jsx("div",{className:"w-6 h-6 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm",children:"正在加载历史会话"})]}):k&&Ye?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-red-400 dark:text-red-500 gap-3 px-6 text-center",children:[e.jsx(Q,{className:"w-10 h-10 opacity-50"}),e.jsx("p",{className:"text-sm",children:Ye})]}):S.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-400 dark:text-gray-600 gap-3",children:[k?e.jsx(Oe,{className:"w-12 h-12 opacity-20"}):e.jsx(ee,{className:"w-12 h-12 opacity-20"}),e.jsx("p",{className:"text-sm font-medium",children:k?"无消息记录":"AgentPilot"}),e.jsx("p",{className:"text-xs text-gray-300 dark:text-gray-600",children:k?"这条历史会话没有可展示的消息":"AI Agent 遥控器,随时随地掌控"})]}):e.jsxs(e.Fragment,{children:[!k&&R&&e.jsx("div",{className:"px-4 pt-3 pb-1 flex justify-center",children:e.jsx("button",{type:"button",onClick:F,disabled:M,className:"text-xs px-3 py-1.5 rounded-full bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:border-primary-200 dark:hover:border-primary-800 disabled:opacity-60 transition-colors",children:M?"加载中...":"加载更早消息"})}),e.jsx("div",{style:{height:H.getTotalSize()+As,width:"100%",position:"relative"},children:Is.map(s=>{const a=S[s.index],d=!at.current.has(a.id);return at.current.add(a.id),e.jsx("div",{"data-index":s.index,"data-message-id":a.id,ref:H.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${s.start}px)`},children:e.jsx("div",{className:g("px-4 py-2"),children:e.jsx(Ia,{message:a,isStreaming:!k&&r==="running"&&s.index===S.length-1&&a.type==="ai",animate:d,expanded:Le(a.id),onToggleExpand:fs,canEditUserMessage:Cs,editingMessageId:J,editingValue:Ae,editingSubmitting:Pt,editError:ds,onStartEdit:ws,onEditingValueChange:Ee,onCancelEdit:Ns,onSubmitEdit:vs,onPreviewAttachments:Ss})})},a.id)})})]})}),qt&&e.jsx(Ca,{activity:qt,elevated:Vt}),Vt&&e.jsxs("button",{type:"button",onClick:hs,className:"absolute bottom-3 left-1/2 z-20 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-primary-200 bg-white px-3 py-1.5 text-xs font-medium text-primary-600 shadow-lg shadow-primary-100/60 transition-colors hover:bg-primary-50 dark:border-primary-800 dark:bg-gray-900 dark:text-primary-300 dark:shadow-black/30 dark:hover:bg-primary-950",title:"回到底部",children:[e.jsx(O,{className:"h-3.5 w-3.5"}),"有新内容,回到底部"]})]}),e.jsx("div",{className:"bg-white dark:bg-gray-900 border-t border-gray-100 dark:border-gray-800 flex-shrink-0 relative shadow-[0_-1px_8px_rgba(0,0,0,0.04)] dark:shadow-[0_-1px_8px_rgba(0,0,0,0.2)]",children:k?e.jsxs("div",{className:"px-3 pt-3 pb-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-gray-700 dark:text-gray-300",children:[e.jsx(Oe,{className:"h-3.5 w-3.5 text-gray-400 dark:text-gray-500"}),e.jsx("span",{className:"truncate",children:"历史会话"})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-gray-400 dark:text-gray-500",children:C?Kr(C):"正在加载..."})]}),e.jsx("button",{type:"button",onClick:()=>E("/session"),className:"flex-shrink-0 rounded-full border border-gray-200 px-2.5 py-1 text-xs text-gray-500 transition-colors hover:border-primary-200 hover:text-primary-600 dark:border-gray-800 dark:text-gray-400 dark:hover:border-primary-800 dark:hover:text-primary-400",children:"当前会话"})]}),gr?e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-xl border border-gray-100 bg-gray-50 px-3 py-3 text-xs text-gray-400 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-500",children:[e.jsx("div",{className:"h-4 w-4 rounded-full border-2 border-primary-500 border-t-transparent animate-spin"}),"正在加载历史会话"]}):Ye?e.jsx("div",{className:"rounded-xl border border-red-100 bg-red-50 px-3 py-2 text-xs text-red-600 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300",children:Ye}):C!=null&&C.canResume?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-end gap-2.5",children:[e.jsx("textarea",{value:Me,onChange:s=>{Lt(s.target.value),be(""),s.currentTarget.style.height="auto",s.currentTarget.style.height=`${Math.min(s.currentTarget.scrollHeight,120)}px`},onKeyDown:s=>{s.key==="Enter"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),Ar())},placeholder:n==="connected"?"继续这段会话...":"连接恢复后可继续",disabled:ye||n!=="connected",rows:1,className:"min-h-[44px] max-h-[120px] flex-1 resize-none rounded-2xl border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-800 outline-none transition-all placeholder:text-gray-400 focus:border-primary-400 focus:bg-white focus:ring-[3px] focus:ring-primary-100 disabled:opacity-70 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-200 dark:placeholder:text-gray-600 dark:focus:bg-gray-800 dark:focus:ring-primary-900 hide-scrollbar"}),e.jsx("button",{type:"button",onClick:Ar,disabled:!Me.trim()||ye||n!=="connected",className:g("p-2.5 rounded-full flex-shrink-0 transition-all duration-200 shadow-sm active:scale-95",Me.trim()&&!ye&&n==="connected"?"bg-primary-600 text-white hover:bg-primary-700 shadow-primary-200 dark:shadow-primary-900":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500 shadow-none"),title:"继续此会话",children:ye?e.jsx("div",{className:"h-4 w-4 rounded-full border-2 border-current border-t-transparent animate-spin"}):e.jsx(Or,{className:"w-4 h-4"})})]}),hr&&e.jsx("div",{className:"mt-2 px-1 text-xs text-red-500 dark:text-red-400",children:hr})]}):e.jsx("div",{className:"rounded-xl border border-gray-200 bg-gray-50 px-3 py-2 text-xs leading-relaxed text-gray-500 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-400",children:"这条历史记录为只读模式,缺少可恢复的 CLI 会话 ID,无法继续追问。"})]}):r==="confirm"?e.jsx(Ga,{pendingMessage:t.filter(s=>s.type==="confirm"&&s.status==="pending").slice(-1)[0],onConfirm:js}):r==="question"?e.jsx(Za,{pendingMessage:t.filter(s=>s.type==="question"&&s.status==="pending").slice(-1)[0],onAnswer:p}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex min-h-[40px] items-center gap-1 overflow-x-auto px-3 py-1.5 hide-scrollbar",children:[e.jsx(He,{prefix:"/",icon:e.jsx(Qs,{className:"w-3 h-3"}),label:"命令",color:"bg-blue-50/50 dark:bg-blue-950/50 text-blue-500/70 dark:text-blue-400/70 border-blue-200/40 dark:border-blue-800/40",active:(x==null?void 0:x.mode)==="command",onClick:()=>ut("/")}),e.jsx(He,{prefix:"!",icon:e.jsx(Zt,{className:"w-3 h-3"}),label:"Bash",color:"bg-amber-50/50 dark:bg-amber-950/50 text-amber-500/70 dark:text-amber-400/70 border-amber-200/40 dark:border-amber-800/40",active:Dr==="!",onClick:()=>ut("!")}),e.jsx(He,{prefix:"@",icon:e.jsx(Gs,{className:"w-3 h-3"}),label:"文件",color:"bg-green-50/50 dark:bg-green-950/50 text-green-500/70 dark:text-green-400/70 border-green-200/40 dark:border-green-800/40",active:(x==null?void 0:x.mode)==="file",onClick:()=>ut("@")}),e.jsx(He,{prefix:"#",icon:e.jsx(Js,{className:"w-3 h-3"}),label:"记忆",color:"bg-purple-50/50 dark:bg-purple-950/50 text-purple-500/70 dark:text-purple-400/70 border-purple-200/40 dark:border-purple-800/40",active:Dr==="#",onClick:()=>ut("#")}),e.jsx(He,{prefix:"",icon:e.jsx(Oe,{className:"w-3 h-3"}),label:"历史",color:"bg-gray-50/50 dark:bg-gray-950/50 text-gray-500/70 dark:text-gray-400/70 border-gray-200/40 dark:border-gray-800/40",active:(x==null?void 0:x.mode)==="history",onClick:()=>{(x==null?void 0:x.mode)==="history"?$():(he({mode:"history"}),z(0),dt())}})]}),x&&e.jsx("div",{className:"overflow-hidden border-t border-gray-100 dark:border-gray-800",onMouseDown:s=>s.preventDefault(),children:e.jsxs("div",{className:"max-h-52 overflow-y-auto overscroll-contain py-1",children:[x.mode==="command"&&(Qt.length>0||ae)&&e.jsx("div",{className:"px-4 py-1 text-[10px] font-medium uppercase tracking-wider text-gray-400 dark:text-gray-500",children:"CLI Skills"}),x.mode==="file"&&fe&&e.jsx("div",{className:"px-4 py-1 text-[10px] font-medium text-gray-400 dark:text-gray-500 truncate",children:Bt(fe)}),q.map((s,a)=>e.jsx(Ya,{item:s,selected:a===Ie,onSelect:()=>$r(s),onDeleteHistory:s.kind==="history"?()=>ks(s.id):void 0},s.key)),x.mode==="command"&&ae&&e.jsx("div",{className:"px-4 py-3 text-xs text-gray-400 text-center",children:"正在加载 CLI Skills..."}),x.mode==="file"&&pe&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx("div",{className:"w-5 h-5 border-2 border-green-500 border-t-transparent rounded-full animate-spin"})}),x.mode==="history"&&ne&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-xs text-gray-400 dark:text-gray-500",children:[e.jsx("div",{className:"h-4 w-4 rounded-full border-2 border-gray-300 border-t-transparent animate-spin dark:border-gray-600"}),"正在加载历史提问"]}),x.mode==="history"&&!ne&&Et&&e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 text-xs text-red-500 dark:text-red-400",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(me,{className:"h-3.5 w-3.5 flex-shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:Et})]}),e.jsxs("button",{type:"button",onClick:()=>void dt(),className:"inline-flex flex-shrink-0 items-center gap-1 rounded-full border border-red-200 px-2 py-1 text-[11px] font-medium text-red-600 transition-colors hover:bg-red-50 dark:border-red-900 dark:text-red-300 dark:hover:bg-red-950/40",title:"重新加载历史提问",children:[e.jsx(_r,{className:"h-3 w-3"}),"重试"]})]}),!ae&&!pe&&!ne&&!Et&&q.length===0&&e.jsx("div",{className:"px-4 py-3 text-xs text-gray-400 text-center",children:x.mode==="command"?"命令会原样发送给 CLI":x.mode==="file"?"没有匹配的文件":"暂无历史提问"})]})}),K.length>0&&e.jsxs("div",{className:"border-t border-gray-100 px-3 py-2 dark:border-gray-800",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>St(s=>!s),className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg px-1 py-1 text-left transition-colors hover:bg-gray-50 dark:hover:bg-gray-800",title:Rt?"收起追问队列":"展开追问队列",children:[Rt?e.jsx(O,{className:"h-3.5 w-3.5 flex-shrink-0 text-gray-400"}):e.jsx(te,{className:"h-3.5 w-3.5 flex-shrink-0 text-gray-400"}),e.jsx("span",{className:"truncate text-xs font-medium text-gray-600 dark:text-gray-300",children:Re?"追问队列已暂停":r==="running"?"等待当前回答结束":"等待发送"}),e.jsxs("span",{className:"flex-shrink-0 rounded-full bg-primary-50 px-1.5 py-0.5 text-[10px] font-medium text-primary-600 dark:bg-primary-950 dark:text-primary-300",children:[K.length," 条"]})]}),Re&&e.jsx("button",{type:"button",onClick:j,className:"flex-shrink-0 rounded-full border border-primary-200 px-2 py-1 text-xs font-medium text-primary-600 transition-colors hover:bg-primary-50 dark:border-primary-800 dark:text-primary-300 dark:hover:bg-primary-950",children:"继续"}),e.jsx("button",{type:"button",onClick:w,className:"flex-shrink-0 rounded-full border border-gray-200 px-2 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-50 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-800",children:"清空"})]}),Rt&&e.jsx("div",{className:"mt-2 max-h-36 overflow-y-auto rounded-xl border border-gray-100 bg-gray-50 dark:border-gray-800 dark:bg-gray-950",children:K.map((s,a)=>{var d;return e.jsxs("div",{className:"flex items-start gap-2 border-b border-gray-100 px-3 py-2 last:border-b-0 dark:border-gray-800",children:[e.jsx("span",{className:"mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full bg-white text-[10px] font-medium text-gray-400 dark:bg-gray-900 dark:text-gray-500",children:a+1}),e.jsxs("div",{className:"min-w-0 flex-1 text-xs leading-relaxed text-gray-600 dark:text-gray-300",children:[s.content&&e.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.content}),!!((d=s.attachments)!=null&&d.length)&&e.jsxs("div",{className:g("font-medium text-primary-600 dark:text-primary-300",s.content?"mt-1":""),children:["图片附件 ",s.attachments.length," 张"]})]}),e.jsx("button",{type:"button",onClick:()=>f(s.id),className:"mt-0.5 flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-gray-100 hover:text-red-500 dark:hover:bg-gray-800 dark:hover:text-red-400",title:"移除追问",children:e.jsx(Q,{className:"h-3.5 w-3.5"})})]},s.id)})})]}),e.jsxs("div",{className:"px-3 pt-3 pb-2",children:[e.jsx("input",{ref:st,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:s=>{const a=s.currentTarget;a.files&&Tt(a.files).finally(()=>{a.value=""})}}),e.jsxs("div",{className:g("rounded-2xl border bg-gray-50/90 shadow-sm transition-all dark:bg-gray-900/90",es?"border-primary-400 ring-[3px] ring-primary-100 dark:border-primary-500 dark:ring-primary-900/60":"border-gray-200 focus-within:border-primary-400 focus-within:bg-white focus-within:ring-[3px] focus-within:ring-primary-100 dark:border-gray-700 dark:focus-within:bg-gray-900 dark:focus-within:ring-primary-900"),onDragEnter:s=>{Array.from(s.dataTransfer.items||[]).some(d=>d.type.startsWith("image/"))&&(s.preventDefault(),Se(!0))},onDragOver:s=>{Array.from(s.dataTransfer.items||[]).some(d=>d.type.startsWith("image/"))&&(s.preventDefault(),Se(!0))},onDragLeave:()=>Se(!1),onDrop:s=>{const a=Array.from(s.dataTransfer.files||[]).filter(d=>d.type.startsWith("image/"));Se(!1),a.length!==0&&(s.preventDefault(),Tt(a))},children:[(se.length>0||Ct)&&e.jsxs("div",{className:"border-b border-gray-200/70 px-2.5 pb-2 pt-2.5 dark:border-gray-700/80",children:[se.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-0.5",children:se.map((s,a)=>e.jsxs("div",{className:g("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-lg border bg-white shadow-sm dark:bg-gray-800",s.status==="failed"?"border-red-300 dark:border-red-800":"border-gray-200 dark:border-gray-700"),title:s.error||Vr(s),children:[e.jsxs("button",{type:"button",onClick:()=>Rs(a),className:"block h-full w-full",title:"预览图片",children:[e.jsx("img",{src:s.previewUrl,alt:s.name,className:g("h-full w-full object-cover transition-opacity",s.status!=="ready"&&"opacity-75"),loading:"lazy"}),s.status==="uploading"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/35 text-white",children:e.jsx(pt,{className:"h-4 w-4 animate-spin"})}),s.status==="failed"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-red-950/45 text-white",children:e.jsx(me,{className:"h-4 w-4"})})]}),s.status==="failed"&&e.jsx("button",{type:"button",onClick:()=>Xr(s.id),className:"absolute bottom-1 right-1 flex h-5 w-5 items-center justify-center rounded-full bg-white text-red-600 shadow-sm transition-colors hover:bg-red-50 dark:bg-gray-900 dark:text-red-300 dark:hover:bg-red-950",title:"重试上传",children:e.jsx(_r,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",onClick:()=>Yr(s.id),className:"absolute right-1 top-1 flex h-5 w-5 items-center justify-center rounded-full bg-black/60 text-white transition-colors hover:bg-black/75",title:"移除图片",children:e.jsx(Q,{className:"h-3 w-3"})})]},s.id))}),Ct&&e.jsx("div",{className:g("text-xs text-red-500 dark:text-red-400",se.length>0?"mt-1.5":""),children:Ct})]}),e.jsxs("div",{className:"flex items-end gap-2 px-2 py-2",children:[e.jsx("button",{type:"button",onClick:()=>{var s;return(s=st.current)==null?void 0:s.click()},disabled:V||Y||ge||se.length>=Us,className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full text-gray-500 transition-all hover:bg-white hover:text-primary-600 active:scale-95 disabled:cursor-not-allowed disabled:opacity-45 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-primary-300",title:"添加图片",children:ge?e.jsx(pt,{className:"h-4 w-4 animate-spin"}):e.jsx(Zs,{className:"h-4 w-4"})}),e.jsx("div",{className:"relative min-w-0 flex-1",children:e.jsx("textarea",{ref:ie,value:T,onChange:ys,placeholder:Ts,disabled:V||Y,className:"block w-full min-h-[40px] max-h-[120px] resize-none bg-transparent px-1 py-2 text-sm leading-6 text-gray-800 outline-none placeholder:text-gray-400 disabled:opacity-60 dark:text-gray-200 dark:placeholder:text-gray-600 hide-scrollbar",rows:1,onSelect:bs,onPaste:s=>{const a=Array.from(s.clipboardData.files||[]).filter(d=>d.type.startsWith("image/"));a.length!==0&&(s.preventDefault(),Tt(a))},onKeyDown:s=>{if(s.key==="Enter"&&(s.metaKey||s.ctrlKey)){s.preventDefault(),jr();return}if(x&&s.key==="Escape"){s.preventDefault(),$();return}if(x&&q.length>0&&s.key==="ArrowDown"){s.preventDefault(),z(a=>(a+1)%q.length);return}if(x&&q.length>0&&s.key==="ArrowUp"){s.preventDefault(),z(a=>(a-1+q.length)%q.length);return}x&&q[Ie]&&(s.key==="Enter"||s.key==="Tab")&&(s.preventDefault(),$r(q[Ie]))}})}),e.jsx("button",{onClick:jr,disabled:!Er,className:g("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full transition-all active:scale-95",Er?"bg-primary-600 text-white shadow-sm shadow-primary-200 hover:bg-primary-700 dark:shadow-primary-950":"bg-gray-200 text-gray-400 shadow-none dark:bg-gray-800 dark:text-gray-500"),title:zt?"加入追问队列":"发送",children:e.jsx(Or,{className:"h-4 w-4"})},zt?"queue":"send"),r==="running"&&e.jsx("button",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-red-500 text-white shadow-sm transition-all hover:bg-red-600 active:scale-95",onClick:ps,title:"停止当前回答",children:e.jsx(Ys,{className:"h-4 w-4 fill-current"})},"interrupt")]})]})]})]})}),e.jsx(Ta,{viewer:ts,onClose:()=>Be(null),onIndexChange:s=>Be(a=>a&&{...a,index:s})}),rs&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>ze(!1),className:"absolute inset-0 bg-black/40 z-40"}),e.jsxs("div",{className:"absolute inset-x-4 top-1/2 -translate-y-1/2 bg-white dark:bg-gray-900 rounded-2xl z-50 p-5 shadow-xl",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary-50 dark:bg-primary-950 flex items-center justify-center flex-shrink-0",children:e.jsx(ft,{className:"w-5 h-5 text-primary-600 dark:text-primary-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"新开会话"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-0.5",children:K.length>0?"当前会话将保存到会话记录,追问队列会被清空":"当前会话将保存到会话记录"})]})]}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{onClick:()=>ze(!1),className:"flex-1 py-2.5 border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 rounded-xl font-medium hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors text-sm",children:"取消"}),e.jsx("button",{onClick:()=>{ze(!1),wr()},className:"flex-1 py-2.5 bg-primary-600 text-white rounded-xl font-medium hover:bg-primary-700 transition-colors text-sm shadow-sm",children:"确认"})]})]})]})]})})},Ca=D.memo(function({activity:t,elevated:i}){const o=t.tone==="tool"?"border-amber-200 bg-amber-50/95 text-amber-800 shadow-amber-100/50 dark:border-amber-800/45 dark:bg-gray-900/95 dark:text-gray-200 dark:shadow-black/20":t.tone==="thinking"?"border-indigo-200 bg-indigo-50/95 text-indigo-800 shadow-indigo-100/50 dark:border-indigo-800/45 dark:bg-gray-900/95 dark:text-gray-200 dark:shadow-black/20":t.tone==="waiting"?"border-gray-200 bg-white/95 text-gray-700 shadow-gray-100/60 dark:border-gray-800 dark:bg-gray-900/95 dark:text-gray-200 dark:shadow-black/20":"border-primary-200 bg-primary-50/95 text-primary-800 shadow-primary-100/50 dark:border-primary-800/45 dark:bg-gray-900/95 dark:text-gray-200 dark:shadow-black/20",n=t.tone==="tool"?"text-amber-700 dark:bg-amber-950/35 dark:text-amber-300":t.tone==="thinking"?"text-indigo-700 dark:bg-indigo-950/35 dark:text-indigo-300":t.tone==="waiting"?"text-gray-600 dark:bg-gray-800/80 dark:text-gray-300":"text-primary-700 dark:bg-primary-950/35 dark:text-primary-300";return e.jsx("div",{className:g("pointer-events-none absolute left-3 right-3 z-20 flex justify-center",i?"bottom-14":"bottom-3"),children:e.jsxs("div",{className:g("pointer-events-auto flex max-w-full items-center gap-2 rounded-lg border px-3 py-2 text-left shadow-md backdrop-blur",o),children:[e.jsx("span",{className:g("flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full bg-white/70 dark:bg-gray-800/80",n),children:t.tone==="thinking"?e.jsx(Xt,{className:"h-3.5 w-3.5 animate-pulse"}):t.tone==="tool"?e.jsx(ee,{className:"h-3.5 w-3.5 animate-pulse"}):e.jsx(pt,{className:"h-3.5 w-3.5 animate-spin"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-medium leading-4",children:t.label}),e.jsx("div",{className:"truncate text-[10px] leading-3 opacity-70 dark:text-gray-400 dark:opacity-100",children:t.detail})]})]})})}),Ta=D.memo(function({viewer:t,onClose:i,onIndexChange:o}){const n=(t==null?void 0:t.items.length)||0,c=t?Math.min(Math.max(t.index,0),n-1):0,u=t==null?void 0:t.items[c],f=l.useCallback(w=>{if(!(t!=null&&t.items.length))return;const j=(w+t.items.length)%t.items.length;o(j)},[o,t]);return l.useEffect(()=>{if(!t)return;const w=j=>{j.key==="Escape"&&i(),j.key==="ArrowLeft"&&f(c-1),j.key==="ArrowRight"&&f(c+1)};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[f,i,c,t]),!t||!u?null:e.jsxs("div",{className:"fixed inset-0 z-[70] flex flex-col bg-black/95 text-white",role:"dialog","aria-modal":"true",children:[e.jsxs("div",{className:"flex h-14 flex-shrink-0 items-center gap-2 px-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:u.name||"图片预览"}),e.jsxs("div",{className:"mt-0.5 text-xs text-white/55",children:[n>1?`${c+1}/${n}`:gt(u.size),n>1&&gt(u.size)?` · ${gt(u.size)}`:""]})]}),e.jsx("a",{href:u.url,download:u.name||"image",className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-white/80 transition-colors hover:bg-white/10 hover:text-white",title:"下载图片",children:e.jsx(ta,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:i,className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-white/80 transition-colors hover:bg-white/10 hover:text-white",title:"关闭预览",children:e.jsx(Q,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 px-3 pb-4",children:[e.jsx(zs,{src:u.url,alt:u.name,resetKey:u.id,className:"h-full",imageClassName:"rounded-lg shadow-2xl",padding:12}),n>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>f(c-1),className:"absolute left-3 top-1/2 flex h-10 w-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/40 text-white transition-colors hover:bg-black/65",title:"上一张",children:e.jsx(ra,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:()=>f(c+1),className:"absolute right-3 top-1/2 flex h-10 w-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/40 text-white transition-colors hover:bg-black/65",title:"下一张",children:e.jsx(te,{className:"h-5 w-5"})})]})]}),n>1&&e.jsx("div",{className:"flex h-20 flex-shrink-0 items-center gap-2 overflow-x-auto border-t border-white/10 px-3",children:t.items.map((w,j)=>e.jsx("button",{type:"button",onClick:()=>o(j),className:g("h-14 w-14 flex-shrink-0 overflow-hidden rounded-lg border transition-all",j===c?"border-white opacity-100":"border-white/20 opacity-60 hover:opacity-90"),title:w.name,children:e.jsx("img",{src:w.url,alt:w.name,className:"h-full w-full object-cover"})},w.id))})]})}),Te=D.memo(function({attachments:t,inverted:i=!1,onPreview:o}){if(!(t!=null&&t.length))return null;const n=t.slice(0,4),c=Math.max(0,t.length-n.length);return e.jsx("div",{className:g("grid gap-2",t.length===1?"grid-cols-1":"grid-cols-2"),children:n.map((u,f)=>e.jsxs("button",{type:"button",onClick:()=>o(t,f),className:g("group relative block overflow-hidden rounded-lg border text-left outline-none transition-transform active:scale-[0.99]",i?"border-white/25 bg-white/10":"border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-800"),title:Vr(u),children:[e.jsx("img",{src:ht.getAttachmentPreviewUrl(u.path),alt:u.name,className:g("w-full transition-transform group-hover:scale-[1.01]",t.length===1?"max-h-80 min-h-36 object-contain":"h-28 object-cover sm:h-32"),loading:"lazy"}),f===n.length-1&&c>0&&e.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-lg font-semibold text-white",children:["+",c]})]},u.id))})}),Ra=D.memo(function({message:t,animClass:i,canEdit:o,isEditing:n,editingValue:c,editingSubmitting:u,editError:f,onStartEdit:w,onEditingValueChange:j,onCancelEdit:v,onSubmitEdit:p,onPreviewAttachments:m}){var h;const I=l.useRef(null),A=l.useCallback(y=>{y&&(y.style.height="auto",y.style.height=`${Math.min(y.scrollHeight,240)}px`)},[]);return l.useEffect(()=>{n&&requestAnimationFrame(()=>{const y=I.current;y&&(A(y),y.focus(),y.setSelectionRange(y.value.length,y.value.length))})},[n,A]),n?e.jsx("div",{className:g("flex justify-end",i),children:e.jsxs("div",{className:"w-[95%] max-w-2xl bg-primary-600 text-white rounded-2xl rounded-tr-sm px-3 py-3 shadow-sm",children:[e.jsx("textarea",{ref:I,value:c,disabled:u,onChange:y=>{j(y.target.value),A(y.currentTarget)},onKeyDown:y=>{y.key==="Escape"&&(y.preventDefault(),v()),y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),p())},className:"w-full min-h-[88px] max-h-60 resize-none overflow-y-auto rounded-xl border border-white/25 bg-white/10 px-3 py-2 text-[15px] leading-relaxed text-white placeholder:text-primary-100 outline-none focus:border-white/60 focus:ring-2 focus:ring-white/20 disabled:opacity-70"}),f&&e.jsx("div",{className:"mt-2 text-xs text-red-100 bg-red-500/25 border border-red-200/30 rounded-lg px-2 py-1",children:f}),e.jsxs("div",{className:"mt-2 flex justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:v,disabled:u,className:"p-1.5 rounded-full text-primary-100 hover:text-white hover:bg-white/15 active:scale-95 transition-all disabled:opacity-50",title:"取消编辑",children:e.jsx(Q,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:p,disabled:u||!c.trim(),className:"p-1.5 rounded-full bg-white text-primary-700 hover:bg-primary-50 active:scale-95 transition-all disabled:opacity-50 disabled:cursor-not-allowed",title:"提交编辑",children:e.jsx(Yt,{className:"w-4 h-4"})})]})]})}):e.jsx("div",{className:g("flex justify-end",i),children:e.jsxs("div",{className:"relative group max-w-[95%]",children:[o&&e.jsx("button",{type:"button",onClick:()=>w(t),className:"absolute -left-8 top-1/2 -translate-y-1/2 p-1.5 rounded-full bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 shadow-sm opacity-70 sm:opacity-0 sm:group-hover:opacity-100 focus:opacity-100 transition-all",title:"编辑消息",children:e.jsx(sa,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"bg-primary-600 text-white rounded-2xl rounded-tr-sm px-4 py-2.5 shadow-sm relative overflow-hidden",children:[e.jsx(Te,{attachments:t.attachments,inverted:!0,onPreview:m}),t.content.trim()&&e.jsx("p",{className:g("text-[15px] leading-relaxed whitespace-pre-wrap break-words",(h=t.attachments)!=null&&h.length?"mt-2":""),children:e.jsx(Ks,{linkClassName:"text-white decoration-white/70",children:t.content})})]}),e.jsx("div",{className:"mt-1 pr-1 text-right text-[10px] leading-none text-gray-400 dark:text-gray-500",children:t.time})]})})}),Sa=D.memo(function({message:t,animate:i}){const o=zr(t.details);if(!o)return null;const n=o.isFinalAttempt,c=Hs(o),u=i?"message-animate-in":"";return e.jsx("div",{className:g("flex justify-start",u),children:e.jsx("div",{className:g("max-w-[95%] rounded-xl border px-4 py-3 shadow-sm overflow-hidden",n?"border-red-100 bg-red-50 text-red-800 dark:border-red-800 dark:bg-red-950/70 dark:text-red-200":"border-amber-100 bg-amber-50 text-amber-800 dark:border-amber-800/70 dark:bg-amber-950/40 dark:text-amber-200"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[n?e.jsx(me,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}):e.jsx(pt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 animate-spin"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-semibold",children:Os(o)}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed break-words",children:_s(o)}),c&&e.jsxs("details",{className:"mt-2 text-xs",children:[e.jsx("summary",{className:g("cursor-pointer select-none",n?"text-red-600 dark:text-red-300":"text-amber-700 dark:text-amber-300"),children:"诊断信息"}),e.jsx("div",{className:g("mt-1 rounded-md border px-2 py-1.5 font-mono leading-relaxed break-words",n?"border-red-100 bg-white/55 text-red-700 dark:border-red-800/80 dark:bg-red-950/45 dark:text-red-200":"border-amber-100 bg-white/55 text-amber-700 dark:border-amber-800/70 dark:bg-amber-950/45 dark:text-amber-200"),children:c})]})]})]})})})}),Ia=D.memo(function({message:t,isStreaming:i,animate:o,expanded:n,onToggleExpand:c,canEditUserMessage:u,editingMessageId:f,editingValue:w,editingSubmitting:j,editError:v,onStartEdit:p,onEditingValueChange:m,onCancelEdit:I,onSubmitEdit:A,onPreviewAttachments:h}){var R;const y=o?"message-animate-in":"";switch(t.type){case"ai_response":return e.jsx(Br,{message:t.message,resultMessage:t.resultMessage,animate:o,onPreviewAttachments:h});case"process_group":return e.jsx(Wa,{group:t,animate:o,expanded:n??!1,onToggleExpand:c});case"system_group":return e.jsx(za,{group:t,animate:o,expanded:n??!1,onToggleExpand:c,onPreviewAttachments:h});case"tool_group":return e.jsx(Ka,{group:t,animate:o,expanded:n??!1,onToggleExpand:c});case"user":return e.jsx(Ra,{message:t,animClass:y,canEdit:u,isEditing:f===t.id,editingValue:w,editingSubmitting:j,editError:v,onStartEdit:p,onEditingValueChange:m,onCancelEdit:I,onSubmitEdit:A,onPreviewAttachments:h});case"ai":return e.jsx(Br,{message:t,isStreaming:i,animate:o,onPreviewAttachments:h});case"tool":return e.jsx(qa,{message:t,animate:o,expanded:n??!1,onToggleExpand:c});case"confirm":return e.jsx("div",{className:g("flex justify-start",y),children:e.jsxs("div",{className:g("border rounded-xl px-4 py-3 max-w-[95%] shadow-sm relative overflow-hidden",t.status==="pending"?"bg-orange-50 dark:bg-orange-950 border-orange-200 dark:border-orange-800":t.status==="approved"?"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800":"bg-red-50 dark:bg-red-950 border-red-200 dark:border-red-800"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.status==="pending"?e.jsx(me,{className:"w-4 h-4 text-orange-500"}):t.status==="approved"?e.jsx(Yt,{className:"w-4 h-4 text-green-600"}):e.jsx(Q,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{className:g("text-sm font-semibold",t.status==="pending"?"text-orange-800 dark:text-orange-300":t.status==="approved"?"text-green-800 dark:text-green-300":"text-red-800 dark:text-red-300"),children:t.status==="pending"?"等待确认":t.status==="approved"?"已批准":"已拒绝"}),t.permission&&e.jsx(Zr,{permission:t.permission})]}),e.jsx("p",{className:g("text-sm",t.status==="pending"?"text-orange-900 dark:text-orange-200":t.status==="approved"?"text-green-900 dark:text-green-200":"text-red-900 dark:text-red-200"),children:t.content}),((R=t.permission)==null?void 0:R.filePath)&&e.jsx("div",{className:"mt-1.5 text-xs font-mono text-gray-500 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1 rounded break-all",children:t.permission.filePath})]})});case"system":return e.jsx(Va,{message:t,animate:o,onPreviewAttachments:h});case"question":return e.jsx(Ja,{message:t,animate:o});case"thinking":return e.jsx(Qa,{message:t,animate:o,expanded:n??!1,onToggleExpand:c});case"error":return zr(t.details)?e.jsx(Sa,{message:t,animate:o}):e.jsx("div",{className:g("flex justify-start",y),children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-800 text-red-800 dark:text-red-300 rounded-xl px-4 py-3 max-w-[95%] shadow-sm flex items-start gap-2 overflow-hidden",children:[e.jsx(Q,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm leading-relaxed break-words min-w-0",children:t.content})]})});default:return null}},(r,t)=>{var n,c,u,f,w,j;const i=Jt(r.message),o=Jt(t.message);if(i||o){if(!i||!o||r.message.type!==t.message.type||r.message.id!==t.message.id||r.message.content!==t.message.content||r.message.time!==t.message.time||r.message.messages.length!==t.message.messages.length)return!1;for(let v=0;v<r.message.messages.length;v+=1){const p=r.message.messages[v],m=t.message.messages[v];if(p.id!==m.id||p.content!==m.content||p.status!==m.status||p.toolDetails!==m.toolDetails||p.toolResult!==m.toolResult||p.details!==m.details||p.attachments!==m.attachments)return!1}return!(r.animate!==t.animate||r.expanded!==t.expanded)}if(r.message.type==="ai_response"||t.message.type==="ai_response"){if(r.message.type!=="ai_response"||t.message.type!=="ai_response")return!1;const v=r.message,p=t.message;return!(v.id!==p.id||v.content!==p.content||v.time!==p.time||v.message.content!==p.message.content||v.message.time!==p.message.time||v.message.attachments!==p.message.attachments||((n=v.resultMessage)==null?void 0:n.id)!==((c=p.resultMessage)==null?void 0:c.id)||((u=v.resultMessage)==null?void 0:u.details)!==((f=p.resultMessage)==null?void 0:f.details)||((w=v.resultMessage)==null?void 0:w.attachments)!==((j=p.resultMessage)==null?void 0:j.attachments)||r.animate!==t.animate)}return!(r.message.id!==t.message.id||r.message.content!==t.message.content||r.message.status!==t.message.status||r.isStreaming!==t.isStreaming||r.animate!==t.animate||r.expanded!==t.expanded||(r.message.type==="user"||t.message.type==="user")&&(r.canEditUserMessage!==t.canEditUserMessage||r.editingMessageId!==t.editingMessageId||(r.editingMessageId===r.message.id||t.editingMessageId===t.message.id)&&(r.editingValue!==t.editingValue||r.editingSubmitting!==t.editingSubmitting||r.editError!==t.editError))||r.message.toolDetails!==t.message.toolDetails||r.message.toolResult!==t.message.toolResult||r.message.permission!==t.message.permission||r.message.question!==t.message.question||r.message.attachments!==t.message.attachments)}),Br=D.memo(function({message:t,resultMessage:i,isStreaming:o,animate:n,onPreviewAttachments:c}){const u=n?"message-animate-in":"",f=[...t.attachments||[],...(i==null?void 0:i.attachments)||[]].filter((w,j,v)=>v.findIndex(p=>p.id===w.id)===j);return e.jsx("div",{className:g("flex justify-start",u),children:e.jsxs("article",{className:"max-w-[95%] sm:max-w-[88%] min-w-0",children:[e.jsxs("div",{className:"mb-1 ml-1 flex items-center gap-1.5 text-[10px] leading-none text-gray-400 dark:text-gray-500",children:[e.jsx("span",{className:g("h-1.5 w-1.5 rounded-full",o?"bg-primary-500 animate-pulse":"bg-gray-300 dark:bg-gray-600")}),e.jsx("span",{children:o?"正在回复":"AI 回复"}),e.jsx("span",{children:t.time})]}),e.jsxs("div",{className:"assistant-message-body markdown-body min-w-0 overflow-hidden rounded-2xl rounded-tl-md border border-gray-100 bg-white px-3.5 py-3 text-gray-800 shadow-sm dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100",children:[e.jsx(Ce,{isStreaming:o,children:t.content}),o&&e.jsx("span",{className:"inline-block w-1.5 h-4 bg-primary-500 animate-pulse ml-0.5 align-text-bottom rounded-sm"}),f.length>0&&e.jsx("div",{className:g(t.content.trim()?"mt-3":""),children:e.jsx(Te,{attachments:f,onPreview:c})})]}),(i==null?void 0:i.details)&&e.jsx(Aa,{message:i})]})})}),Aa=D.memo(function({message:t}){const[i,o]=l.useState(!1),n=kt(t.details),c=Ba(t.details);return!c&&n.length===0?null:e.jsxs("div",{className:"mt-1 ml-1 min-w-0 text-[10px] text-gray-400 dark:text-gray-500",children:[e.jsxs("button",{type:"button",onClick:()=>n.length>0&&o(u=>!u),className:g("inline-flex max-w-full items-center gap-1 rounded-md px-1 py-0.5 text-left transition-colors",n.length>0&&"hover:bg-gray-100 dark:hover:bg-gray-900"),title:i?"收起用量详情":"展开用量详情",children:[e.jsx("span",{className:"truncate",children:c||"完成元信息"}),n.length>0&&(i?e.jsx(We,{className:"h-3 w-3 flex-shrink-0"}):e.jsx(O,{className:"h-3 w-3 flex-shrink-0"}))]}),i&&n.length>0&&e.jsx("div",{className:"mt-1",children:jt(n)})]})});function Ea(r){const t=(r.toolName||r.content||"").toLowerCase();return["readfile","writefile","read","write","edit","multiedit"].includes(t)}function Nt(r){return r.toolName&&r.toolName!=="result"?r.toolName:r.content||"tool"}function Ma(r){return Pa(r).join("、")||"工具调用"}function Pa(r){return Array.from(new Set(r.map(Nt).filter(Boolean)))}function Da(r){if(r.some(t=>t.status==="running"))return"running";if(r.some(t=>t.status==="failed"))return"partial";if(r.some(t=>t.status==="success"))return"success"}function $a(r){const t=r.filter(c=>c.status==="running").length,i=r.filter(c=>c.status==="failed").length,o=r.filter(c=>c.status==="success").length,n=[`${r.length} 个`];return t&&n.push(`${t} 运行中`),i&&n.push(`${i} 受限`),o&&(t||i)&&n.push(`${o} 完成`),o&&!t&&!i&&n.push("已完成"),n.join(" · ")}function er(r,t="w-4 h-4"){return Ea(r)?e.jsx(na,{className:t}):e.jsx(ee,{className:t})}function Qr({status:r,className:t="w-3.5 h-3.5"}){return r==="running"?e.jsx(la,{className:g(t,"text-primary-500 animate-pulse")}):r==="success"?e.jsx(Yt,{className:g(t,"text-green-600")}):r==="failed"||r==="partial"?e.jsx(me,{className:g(t,"text-amber-500")}):null}function yt({status:r}){return e.jsx("span",{className:g("w-1.5 h-1.5 rounded-full flex-shrink-0",r==="running"?"bg-primary-500 animate-pulse":r==="failed"||r==="partial"?"bg-amber-500":r==="success"?"bg-green-500":"bg-gray-300 dark:bg-gray-600")})}function La(r){if(r.some(t=>t.status==="running"))return"running";if(r.some(t=>t.status==="failed"))return"partial";if(r.some(t=>t.status==="success"))return"success"}function Fa(r){const t=r.filter(f=>f.type==="thinking"||f.type==="ai").length,i=r.filter(f=>f.type==="tool").length,o=r.filter(f=>f.type==="tool"&&!!f.toolResult).length,n=r.filter(f=>f.type==="system").length,c=r.filter(f=>f.status==="failed").length,u=[`${r.length} 步`];return t&&u.push(`${t} 思考`),i&&u.push(`${i} 执行`),o&&u.push(`${o} 观察`),n&&u.push(`${n} 元信息`),c&&u.push(`${c} 受限`),u.join(" · ")}function Ua(r){return r==="partial"?"有受限步骤":r==="failed"?"未完成":r==="running"?"运行中":r==="success"?"已完成":"待执行"}function Ha(r,t){return`${Ua(t)} · ${r.length} 步`}function Oa(r){return r.type==="thinking"?r.status==="running"?"思考中":"思考":r.type==="system"?"元信息":r.type==="ai"?"过程说明":"过程"}function _a(r){return r.type==="thinking"?e.jsx(Xt,{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400"}):r.type==="system"?e.jsx(ee,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500"}):e.jsx(ia,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500"})}const Wa=D.memo(function({group:t,animate:i,expanded:o,onToggleExpand:n}){const c=i?"message-animate-in":"",u=La(t.messages),f=Fa(t.messages),w=Ha(t.messages,u),[j,v]=l.useState({}),p=l.useCallback(m=>{v(I=>({...I,[m]:!I[m]}))},[]);return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:"w-full max-w-full min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:"w-full max-w-full rounded-lg px-2.5 py-1.5 flex items-center gap-1.5 text-left min-w-0 overflow-hidden text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-900 transition-colors",children:[o?e.jsx(O,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx(aa,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300 flex-shrink-0",children:"执行过程"}),e.jsxs("span",{className:g("inline-flex min-w-0 max-w-[48%] shrink items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full",u==="partial"?"bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300":u==="running"?"bg-primary-50 text-primary-600 dark:bg-primary-950/50 dark:text-primary-300":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),title:f,children:[e.jsx(yt,{status:u}),e.jsx("span",{className:"min-w-0 truncate",children:w})]}),e.jsx("span",{className:"hidden sm:inline text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",title:t.content,children:t.content})]}),o&&e.jsx("div",{className:"mt-1 ml-4 overflow-hidden rounded-lg border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 divide-y divide-gray-100 dark:divide-gray-800",children:t.messages.map(m=>{if(m.type==="tool"){const R=Nt(m),M=m.content&&m.content!==R,F=`${m.id}:input`,E=`${m.id}:output`,_=!!j[F],re=!!j[E],G=!!m.toolDetails,k=!!m.toolResult;return e.jsxs("div",{className:"px-3 py-2 min-w-0 bg-white/40 dark:bg-gray-900/30",children:[e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0 text-left",children:[e.jsx("span",{className:"mt-0.5 flex-shrink-0",children:er(m,"w-3.5 h-3.5 text-primary-500 dark:text-primary-400")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary-50 px-1.5 py-0.5 text-[10px] font-semibold leading-none text-primary-700 dark:bg-primary-950/60 dark:text-primary-300 flex-shrink-0",children:"执行"}),e.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 font-mono text-[11px] leading-none text-gray-700 dark:bg-gray-800 dark:text-gray-200 truncate",title:R,children:R}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:m.time}),e.jsx(Qr,{status:m.status,className:"w-3 h-3"})]}),M&&e.jsx("span",{className:"mt-1 block text-xs text-gray-500 dark:text-gray-400 truncate",title:m.content,children:m.content})]}),G&&e.jsx("button",{type:"button",onClick:()=>p(F),className:"mt-0.5 rounded p-0.5 text-primary-500 hover:bg-primary-50 dark:hover:bg-primary-950 flex-shrink-0",title:_?"收起执行输入":"展开执行输入",children:_?e.jsx(We,{className:"w-3 h-3"}):e.jsx(O,{className:"w-3 h-3"})})]}),G&&_&&e.jsx(bt,{message:m,compact:!0,section:"input"}),k&&e.jsxs("div",{className:g("mt-2 w-full rounded-lg border px-2 py-1.5 flex items-start gap-2 min-w-0 text-left",m.status==="failed"?"border-amber-100 bg-amber-50/60 dark:border-amber-900/60 dark:bg-amber-950/20":"border-green-100 bg-green-50/40 dark:border-green-900/50 dark:bg-green-950/15"),children:[e.jsx(wt,{className:g("mt-0.5 w-3.5 h-3.5 flex-shrink-0",m.status==="failed"?"text-amber-500 dark:text-amber-400":"text-green-600 dark:text-green-400")}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:g("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-semibold leading-none flex-shrink-0",m.status==="failed"?"bg-amber-100 text-amber-700 dark:bg-amber-950/70 dark:text-amber-300":"bg-green-100 text-green-700 dark:bg-green-950/70 dark:text-green-300"),children:"观察"}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:m.status==="failed"?"未完成输出":"执行结果"}),e.jsxs("span",{className:g("inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] leading-none flex-shrink-0",m.status==="failed"?"bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300":"bg-green-50 text-green-600 dark:bg-green-950/50 dark:text-green-300"),children:[e.jsx(yt,{status:m.status}),Gr(m.status)]})]})}),e.jsx("button",{type:"button",onClick:()=>p(E),className:"mt-0.5 rounded p-0.5 text-primary-500 hover:bg-primary-50 dark:hover:bg-primary-950 flex-shrink-0",title:re?"收起观察结果":"展开观察结果",children:re?e.jsx(We,{className:"w-3 h-3"}):e.jsx(O,{className:"w-3 h-3"})})]}),k&&re&&e.jsx(bt,{message:m,compact:!0,section:"output"})]},m.id)}const I=Oa(m),A=m.type==="thinking",h=m.type==="ai",y=A||h;return e.jsx("div",{className:g("px-3 py-2 min-w-0",y&&"bg-indigo-50/60 dark:bg-indigo-950/20"),children:e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0 text-left",children:[e.jsx("span",{className:"mt-0.5 flex-shrink-0",children:_a(m)}),e.jsxs("div",{className:g("min-w-0 flex-1",y&&"border-l-2 border-indigo-200 pl-2 dark:border-indigo-800/80"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:g("truncate font-semibold",y?"inline-flex items-center rounded-full bg-indigo-100 px-1.5 py-0.5 text-[10px] leading-none text-indigo-700 dark:bg-indigo-950/70 dark:text-indigo-300":"text-xs text-gray-600 dark:text-gray-300"),title:I,children:I}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:m.time})]}),m.type==="ai"&&e.jsx("div",{className:"mt-1.5 text-xs leading-relaxed text-gray-700 dark:text-indigo-100 markdown-body-sm",children:e.jsx(Ce,{children:m.content})}),m.type==="thinking"&&e.jsx("div",{className:"mt-1.5 text-xs leading-relaxed text-gray-700 dark:text-indigo-100 markdown-body-sm",children:e.jsx(Ce,{children:m.content})}),m.type==="system"&&e.jsx("span",{className:"mt-1 block text-xs text-gray-500 dark:text-gray-400 truncate",title:m.content,children:m.content})]})]})},m.id)})})]})})});function Gr(r){return r==="running"?"运行中":r==="success"?"已完成":r==="failed"?"未完成":"待执行"}const bt=D.memo(function({message:t,compact:i=!1,section:o="both"}){const n=i?"max-h-40":"max-h-72";return e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",onClick:c=>c.stopPropagation(),children:[o!=="output"&&t.toolDetails&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-1",children:"输入"}),e.jsx("div",{className:g("text-xs text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 p-2.5 rounded-lg border border-primary-50 dark:border-gray-700 overflow-y-auto markdown-body-sm",n),children:e.jsx(Ce,{children:Wr(t.toolDetails)})})]}),o!=="input"&&t.toolResult&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-1",children:"输出"}),e.jsx("div",{className:g("text-xs p-2.5 rounded-lg overflow-y-auto markdown-body-sm",n,t.status==="failed"?"text-amber-700 dark:text-amber-300 bg-amber-50/50 dark:bg-amber-950/50 border border-amber-100 dark:border-amber-900":"text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 border border-primary-50 dark:border-gray-700"),children:e.jsx(Ce,{children:Wr(t.toolResult)})})]})]})}),qa=D.memo(function({message:t,animate:i,expanded:o,onToggleExpand:n}){const c=i?"message-animate-in":"",u=!!(t.toolDetails||t.toolResult),f=Gr(t.status);return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:g("w-full max-w-full rounded-lg px-2.5 py-1.5 text-left text-xs text-gray-500 dark:text-gray-400",u&&"cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-900 transition-colors"),onClick:()=>u&&n(t.id),children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[u?o?e.jsx(O,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx("span",{className:"w-3.5 flex-shrink-0"}),er(t,"w-3.5 h-3.5 flex-shrink-0 text-gray-400 dark:text-gray-500"),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300 flex-shrink-0",children:"工具"}),e.jsxs("span",{className:g("inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] leading-none flex-shrink-0",t.status==="failed"?"bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300":t.status==="running"?"bg-primary-50 text-primary-600 dark:bg-primary-950/50 dark:text-primary-300":t.status==="success"?"bg-green-50 text-green-600 dark:bg-green-950/50 dark:text-green-300":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:[e.jsx(yt,{status:t.status}),f]}),e.jsx("span",{className:"truncate min-w-0",title:t.content,children:t.content})]}),o&&u&&e.jsx("div",{className:"mt-2 rounded-lg border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 p-2",children:e.jsx(bt,{message:t})})]})})}),Ka=D.memo(function({group:t,animate:i,expanded:o,onToggleExpand:n}){const c=i?"message-animate-in":"",u=Da(t.messages),f=Ma(t.messages),[w,j]=l.useState({}),v=l.useCallback(p=>{j(m=>({...m,[p]:!m[p]}))},[]);return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:"w-full max-w-full",children:[e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:"w-full max-w-full rounded-lg px-2.5 py-1.5 flex items-center gap-1.5 text-left min-w-0 text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-900 transition-colors",children:[o?e.jsx(O,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx(ee,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300 flex-shrink-0",children:"工具调用"}),e.jsxs("span",{className:g("inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",u==="partial"?"bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300":u==="running"?"bg-primary-50 text-primary-600 dark:bg-primary-950/50 dark:text-primary-300":"bg-green-50 text-green-600 dark:bg-green-950/50 dark:text-green-300"),children:[e.jsx(yt,{status:u}),$a(t.messages)]}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"min-w-0 truncate text-xs",title:f,children:f})]}),o&&e.jsx("div",{className:"mt-1 ml-4 overflow-hidden rounded-lg border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 divide-y divide-gray-100 dark:divide-gray-800",children:t.messages.map(p=>{const m=Nt(p),I=p.content&&p.content!==m,A=!!(p.toolDetails||p.toolResult),h=!!w[p.id];return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>A&&v(p.id),className:g("w-full flex flex-col gap-1 text-gray-600 dark:text-gray-300 min-w-0 text-left",A&&"cursor-pointer hover:text-gray-900 dark:hover:text-gray-100"),children:[e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0",children:[er(p,"w-3.5 h-3.5 flex-shrink-0 mt-0.5 text-gray-400 dark:text-gray-500"),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold",title:m,children:m}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:p.time}),A&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 border border-gray-100 dark:border-gray-700",children:p.toolDetails&&p.toolResult?"输入/输出":p.toolDetails?"输入":"输出"}),e.jsx(Qr,{status:p.status,className:"w-3 h-3"}),A&&(h?e.jsx(We,{className:"w-3 h-3 text-primary-500"}):e.jsx(O,{className:"w-3 h-3 text-primary-500"}))]})]}),I&&e.jsx("span",{className:"w-full pl-5 pr-1 text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:p.content})]}),A&&h&&e.jsx(bt,{message:p,compact:!0})]},p.id)})})]})})});function Gt(r){return Number(r||0).toLocaleString()}function Jr(r){const t=Math.round(r/1e3);return t>=60?`${Math.floor(t/60)}m${t%60}s`:`${t}s`}function Ba(r){if(!r)return"";const t=[],i=Number(r.inputTokens||0),o=Number(r.outputTokens||0),n=Number(r.reasoningOutputTokens||0);return(i>0||o>0)&&(t.push(`${Gt(i)} 输入`),t.push(`${Gt(o)} 输出`)),n>0&&t.push(`${Gt(n)} 推理`),r.costUsd!=null&&t.push(`$${Number(r.costUsd).toFixed(4)}`),r.durationMs!=null&&t.push(Jr(Number(r.durationMs))),t.length>0?`Token ${t.join(" · ")}`:""}function kt(r){if(!r)return[];const t=[];if(r.model&&t.push({label:"模型",value:r.model,color:"bg-purple-50 text-purple-700 dark:bg-purple-950 dark:text-purple-300"}),r.costUsd!=null&&t.push({label:"费用",value:`$${Number(r.costUsd).toFixed(4)}`,color:"bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300"}),r.durationMs!=null&&t.push({label:"耗时",value:Jr(Number(r.durationMs)),color:"bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300"}),r.numTurns!=null&&t.push({label:"轮次",value:String(r.numTurns),color:"bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-300"}),r.inputTokens!=null||r.outputTokens!=null){const i=r.inputTokens?Number(r.inputTokens).toLocaleString():"0",o=r.outputTokens?Number(r.outputTokens).toLocaleString():"0";let n=`${i} → ${o}`;if(r.cacheReadTokens||r.cacheCreationTokens){const c=[];r.cacheCreationTokens&&c.push(`缓存写 ${Number(r.cacheCreationTokens).toLocaleString()}`),r.cacheReadTokens&&c.push(`缓存读 ${Number(r.cacheReadTokens).toLocaleString()}`),n+=` (${c.join(", ")})`}t.push({label:"Token",value:n,color:"bg-cyan-50 text-cyan-700 dark:bg-cyan-950 dark:text-cyan-300"})}return r.reasoningOutputTokens!=null&&t.push({label:"推理",value:Number(r.reasoningOutputTokens).toLocaleString(),color:"bg-violet-50 text-violet-700 dark:bg-violet-950 dark:text-violet-300"}),r.toolsCount!=null&&t.push({label:"工具",value:String(r.toolsCount),color:"bg-indigo-50 text-indigo-700 dark:bg-indigo-950 dark:text-indigo-300"}),t}function jt(r){return r.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map((t,i)=>e.jsxs("span",{className:g("inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium max-w-full",t.color),children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:t.label}),e.jsx("span",{className:"font-semibold truncate",children:t.value})]},`${t.label}-${i}`))})}const za=D.memo(function({group:t,animate:i,expanded:o,onToggleExpand:n,onPreviewAttachments:c}){var p;const u=i?"message-animate-in":"",f=t.messages[t.messages.length-1],w=kt(f==null?void 0:f.details),j=t.messages.length>1,v=t.messages.filter(m=>{var I;return((I=m.details)==null?void 0:I.subtype)==="result"}).length;return e.jsx("div",{className:g("flex justify-start",u),children:e.jsxs("div",{className:"w-full max-w-full",children:[e.jsxs("button",{type:"button",onClick:()=>j&&n(t.id),className:g("w-full max-w-full rounded-lg px-2.5 py-1.5 flex items-center gap-1.5 text-left min-w-0 text-xs text-gray-500 dark:text-gray-400",j&&"hover:bg-gray-100 dark:hover:bg-gray-900 transition-colors cursor-pointer"),children:[j?o?e.jsx(O,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(ee,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300 flex-shrink-0",children:"系统"}),j&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex-shrink-0",children:[t.messages.length," 条",v>0?` · ${v} 次完成`:""]}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"truncate min-w-0",children:t.content})]}),o&&e.jsx("div",{className:"mt-1 ml-4 overflow-hidden rounded-lg border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 divide-y divide-gray-100 dark:divide-gray-800",children:t.messages.map(m=>{var A;const I=kt(m.details);return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate min-w-0",children:m.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:m.time})]}),I.length>0&&e.jsx("div",{className:"mt-1.5",children:jt(I)}),!!((A=m.attachments)!=null&&A.length)&&e.jsx("div",{className:"mt-2",children:e.jsx(Te,{attachments:m.attachments,onPreview:c})})]},m.id)})}),!o&&!j&&w.length>0&&e.jsx("div",{className:"ml-4 mt-1",children:jt(w.slice(0,2))}),!o&&!j&&!!((p=f==null?void 0:f.attachments)!=null&&p.length)&&e.jsx("div",{className:"ml-4 mt-2 max-w-lg",children:e.jsx(Te,{attachments:f.attachments,onPreview:c})})]})})}),Va=D.memo(function({message:t,animate:i,onPreviewAttachments:o}){var p;const n=t.details,c=i?"message-animate-in":"",u=t.content==="系统消息",f=!!((p=t.attachments)!=null&&p.length);if((!n||Object.keys(n).length===0)&&u&&!f)return null;if(!n||Object.keys(n).length===0)return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:"max-w-[95%]",children:[!u&&e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400",children:[e.jsx(ee,{className:"w-3.5 h-3.5 flex-shrink-0 text-gray-400 dark:text-gray-500"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300",children:"系统"}),e.jsx("span",{className:"truncate",children:t.content})]}),f&&e.jsx("div",{className:g(u?"":"mt-2","max-w-lg"),children:e.jsx(Te,{attachments:t.attachments,onPreview:o})})]})});const w=n.subtype==="result",j=n.subtype==="init",v=kt(n);return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:"w-full max-w-full rounded-lg px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(ee,{className:"w-3.5 h-3.5 flex-shrink-0 text-gray-400 dark:text-gray-500"}),e.jsx("span",{className:g("font-medium flex-shrink-0",w?"text-green-700 dark:text-green-300":j?"text-blue-700 dark:text-blue-300":"text-gray-600 dark:text-gray-300"),children:"系统"}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:t.time}),e.jsx("span",{className:"truncate min-w-0",children:t.content})]}),v.length>0&&e.jsx("div",{className:"mt-1 ml-5",children:jt(v.slice(0,2))}),f&&e.jsx("div",{className:"mt-2 ml-5 max-w-lg",children:e.jsx(Te,{attachments:t.attachments,onPreview:o})})]})})}),Qa=D.memo(function({message:t,animate:i,expanded:o,onToggleExpand:n}){const c=i?"message-animate-in":"",u=t.status==="running";return e.jsx("div",{className:g("flex justify-start",c),children:e.jsxs("div",{className:"w-full max-w-full rounded-lg px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-900 transition-colors",onClick:()=>n(t.id),children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[o?e.jsx(O,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx(Xt,{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-300 flex-shrink-0",children:u?"思考中...":"思考过程"}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:u?"运行中":`${t.content.length} 字`})]}),o&&e.jsx("div",{className:"mt-2 rounded-lg border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 p-2 text-sm text-gray-600 dark:text-gray-300 markdown-body-sm",children:e.jsx(Ce,{children:t.content})})]})})}),Zr=({permission:r})=>{const t={file:{icon:wt,label:"文件操作",color:"bg-primary-100 text-primary-700 dark:bg-primary-900 dark:text-primary-300"},command:{icon:Zt,label:"命令执行",color:"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300"},other:{icon:me,label:"权限请求",color:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"}}[r.category],i=t.icon;return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${t.color}`,children:[e.jsx(i,{className:"w-3 h-3"}),t.label]})},Ga=({pendingMessage:r,onConfirm:t})=>{const[i,o]=l.useState(!1),n=r==null?void 0:r.permission;return e.jsxs("div",{className:"p-4 pb-safe",children:[e.jsxs("div",{className:"flex items-center gap-2 text-orange-600 dark:text-orange-400 mb-3",children:[e.jsx(me,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:"需要确认"}),n&&e.jsx(Zr,{permission:n})]}),e.jsx("div",{className:"mb-3",children:e.jsx("p",{className:"text-sm text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-100 dark:border-gray-700",children:(r==null?void 0:r.content)||"CLI 请求确认"})}),(n==null?void 0:n.category)==="file"&&n.filePath&&e.jsxs("div",{className:"mb-3 bg-primary-50 dark:bg-primary-950 border border-primary-100 dark:border-primary-900 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-800 dark:text-primary-300 mb-1",children:[e.jsx(wt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:n.toolName})]}),e.jsx("div",{className:"text-xs font-mono text-primary-600 dark:text-primary-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1 rounded",children:n.filePath})]}),(n==null?void 0:n.category)==="command"&&n.command&&e.jsxs("div",{className:"mb-3 bg-amber-50 dark:bg-amber-950 border border-amber-100 dark:border-amber-900 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-800 dark:text-amber-300 mb-1",children:[e.jsx(Zt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:"命令执行"})]}),e.jsx("div",{className:"text-xs font-mono text-amber-700 dark:text-amber-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1.5 rounded whitespace-pre-wrap break-all",children:n.command})]}),(n==null?void 0:n.diffContent)&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("button",{onClick:()=>o(!i),className:"flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 mb-1.5",children:[i?e.jsx(We,{className:"w-3.5 h-3.5"}):e.jsx(O,{className:"w-3.5 h-3.5"}),i?"收起内容":"查看变更内容"]}),i&&e.jsx("div",{className:"overflow-hidden",children:e.jsx("div",{className:"text-xs font-mono bg-slate-800 text-slate-200 p-3 rounded-lg max-h-48 overflow-y-auto whitespace-pre-wrap break-all",children:n.diffContent})})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>t(!1),className:"flex-1 py-2.5 border border-red-200 dark:border-red-800 text-red-600 dark:text-red-400 rounded-lg font-medium hover:bg-red-50 dark:hover:bg-red-950 transition-colors",children:"拒绝"}),e.jsx("button",{onClick:()=>t(!0),className:"flex-1 py-2.5 bg-primary-600 text-white rounded-lg font-medium hover:bg-primary-700 transition-colors shadow-sm",children:"批准"})]})]})},Ja=D.memo(function({message:t,animate:i}){var u;const o=i?"message-animate-in":"",n=t.question,c=t.status==="answered";return e.jsx("div",{className:g("flex justify-start",o),children:e.jsxs("div",{className:g("border rounded-xl px-4 py-3 max-w-[95%] shadow-sm relative overflow-hidden","bg-blue-50 dark:bg-blue-950 border-blue-200 dark:border-blue-800"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ft,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-blue-800 dark:text-blue-300",children:c?"已回答":"Agent 提问"})]}),(u=n==null?void 0:n.questions)==null?void 0:u.map((f,w)=>e.jsxs("div",{className:"mb-2 last:mb-0",children:[f.header&&e.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400 uppercase tracking-wider",children:f.header}),e.jsx("p",{className:"text-sm text-blue-900 dark:text-blue-200",children:f.question}),f.options&&f.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:f.options.map((j,v)=>e.jsx("span",{className:"text-xs px-2 py-1 rounded-full bg-blue-100/60 dark:bg-blue-900/60 text-blue-700 dark:text-blue-300 border border-blue-200/50 dark:border-blue-800/50",children:j.label},v))})]},w))]})})}),Za=({pendingMessage:r,onAnswer:t})=>{const[i,o]=l.useState({}),[n,c]=l.useState({}),u=r==null?void 0:r.question,f=(u==null?void 0:u.questions)||[],w=f.length<=1;l.useEffect(()=>{o({}),c({})},[r==null?void 0:r.id]);const j=h=>{var R;const y=(R=i[h])==null?void 0:R.trim();return y||(n[h]||[]).join(", ")},v=(h,y)=>w?y||j(0):f.map((R,M)=>{const F=M===h&&y?y:j(M);return`${R.header?`[${R.header}] ${R.question}`:R.question}
5
+ 回答:${F}`}).join(`
6
+
7
+ `),p=f.length>0&&f.every((h,y)=>!!j(y)),m=(h,y,R)=>{if(w&&!R){t(v(h,y),u==null?void 0:u.toolUseId);return}o(M=>({...M,[h]:""})),c(M=>{const F=M[h]||[],E=R?F.includes(y)?F.filter(_=>_!==y):[...F,y]:[y];return{...M,[h]:E}})},I=(h,y)=>{o(R=>({...R,[h]:y})),y.trim()&&c(R=>({...R,[h]:[]}))},A=()=>{p&&(t(v(),u==null?void 0:u.toolUseId),o({}),c({}))};return e.jsxs("div",{className:"p-4 pb-safe",children:[e.jsxs("div",{className:"flex items-center gap-2 text-blue-600 dark:text-blue-400 mb-3",children:[e.jsx(ft,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:"Agent 提问"})]}),f.map((h,y)=>{var F;const R=n[y]||[],M=i[y]||"";return e.jsxs("div",{className:"mb-3",children:[h.header&&e.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400 uppercase tracking-wider",children:h.header}),e.jsx("p",{className:"text-sm text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-100 dark:border-gray-700",children:h.question}),h.options&&h.options.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:h.options.map((E,_)=>{const re=R.includes(E.label);return e.jsxs("button",{onClick:()=>m(y,E.label,h.multiSelect),className:g("w-full text-left px-4 py-3 border rounded-lg transition-colors",re?"bg-blue-100 dark:bg-blue-900 border-blue-400 dark:border-blue-600":"bg-blue-50 dark:bg-blue-950 border-blue-200 dark:border-blue-800 hover:bg-blue-100 dark:hover:bg-blue-900"),children:[e.jsx("span",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:E.label}),E.description&&e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:E.description})]},_)})}),e.jsx("input",{type:"text",value:M,onChange:E=>I(y,E.target.value),onKeyDown:E=>{E.key==="Enter"&&w&&M.trim()?(t(M.trim(),u==null?void 0:u.toolUseId),o({})):E.key==="Enter"&&p&&A()},placeholder:(F=h.options)!=null&&F.length?"或输入自定义回答...":"输入回答...",className:"mt-2 w-full bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 focus:border-blue-400 focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900 rounded-lg px-3 py-2 text-sm text-gray-800 dark:text-gray-200 placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none transition-all"})]},y)}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:A,disabled:!p,className:g("px-4 py-2 rounded-lg font-medium text-sm transition-colors",p?"bg-blue-600 text-white hover:bg-blue-700 shadow-sm":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500"),children:"发送"})})]})},He=({prefix:r,icon:t,label:i,color:o,active:n,onClick:c})=>e.jsxs("button",{type:"button",onClick:c,"aria-label":r?`${i} ${r}`:i,title:r?`${i} ${r}`:i,className:g("box-border inline-flex h-7 min-w-7 flex-shrink-0 items-center justify-center gap-1 rounded-full border px-2 text-[11px] font-normal leading-none whitespace-nowrap transition-all active:scale-95",n?"opacity-100 ring-1 ring-current ring-opacity-20 shadow-sm":"opacity-70 hover:opacity-100",o),children:[t,e.jsx("span",{className:"hidden sm:inline",children:i})]}),Ya=D.memo(function({item:t,selected:i,onSelect:o,onDeleteHistory:n}){const c=g("w-full flex items-center gap-3 px-4 py-2.5 transition-colors text-left",i?"bg-primary-50 dark:bg-primary-950/50":"hover:bg-gray-50 dark:hover:bg-gray-800 active:bg-gray-100 dark:active:bg-gray-700");return t.kind==="command"?e.jsxs("button",{type:"button",onClick:o,className:c,title:`${t.command} ${t.description}`,children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-purple-600 dark:text-purple-400 whitespace-nowrap",children:t.command}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 truncate flex-1",children:t.description}),e.jsx("span",{className:"text-[10px] text-gray-300 dark:text-gray-600 flex-shrink-0",children:t.source})]}):t.kind==="history"?e.jsxs("div",{className:g(c,"pr-2"),title:t.text,children:[e.jsxs("button",{type:"button",onClick:o,className:"flex min-w-0 flex-1 items-center gap-3 text-left",children:[e.jsx(Oe,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-gray-700 dark:text-gray-300",children:t.text}),t.useCount>1&&e.jsx("span",{className:"flex-shrink-0 rounded-full bg-gray-100 px-1.5 py-0.5 text-[10px] text-gray-400 dark:bg-gray-800 dark:text-gray-500",children:t.useCount})]}),n&&e.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),n()},className:"flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full text-gray-300 transition-colors hover:bg-red-50 hover:text-red-500 dark:text-gray-600 dark:hover:bg-red-950/50 dark:hover:text-red-400",title:"删除历史提问",children:e.jsx(Q,{className:"h-3.5 w-3.5"})})]}):t.kind==="file-parent"?e.jsxs("button",{type:"button",onClick:o,className:c,title:t.path,children:[e.jsx(Xs,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:"返回上级"})]}):t.kind==="file-file"?e.jsxs("button",{type:"button",onClick:o,className:c,title:t.path,children:[e.jsx(wt,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate flex-1",children:t.name}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.ext||"?"})]}):e.jsxs("button",{type:"button",onClick:o,className:c,title:t.path,children:[e.jsx(ea,{className:g("w-4 h-4 flex-shrink-0",t.kind==="file-quick"?"text-primary-500":"text-amber-500")}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:t.name}),e.jsx(te,{className:"w-3.5 h-3.5 text-gray-300 dark:text-gray-600 ml-auto flex-shrink-0"})]})});export{on as Session};
@@ -0,0 +1 @@
1
+ import{r as l,j as e,u as he}from"./vendor-react-CcDXZHn_.js";import{i as ne,j as pe,p as fe,b as le,u as be,k as ke,c as y}from"./index-CrJqHlc8.js";import{A as je,m as ie}from"./vendor-motion-D0ZmPdi9.js";import{X as de,o as we,a7 as Ne,j as te,a8 as ce,a9 as K,i as ve,g as $,e as Ce,D as ye,F as Se,aa as Le,ab as Ie,ac as Ae,x as oe,a6 as z,d as Pe,M as Te,ad as De,p as Re,T as Ee,ae as Me,af as _e,ag as We,s as Fe,ah as Oe}from"./vendor-icons-CMXJHDEv.js";import{P as Be}from"./PageTopBar-CQwjO6Af.js";function qe(){const[r,a]=l.useState(()=>ne());l.useEffect(()=>pe(()=>{a(ne())}),[]);const s=l.useCallback(async()=>fe(),[]);return{...r,promptInstall:s}}const ue="agentpilot_favorite_workdirs",Ue=30,$e={home:e.jsx(Ie,{className:"w-4 h-4"}),desktop:e.jsx(Le,{className:"w-4 h-4"}),documents:e.jsx(Se,{className:"w-4 h-4"}),downloads:e.jsx(ye,{className:"w-4 h-4"})},Ge={favorite:"常用",recent:"最近",quick:"快捷",current:"当前目录"},X={favorite:4,recent:3,quick:2,current:1};function xe(){if(typeof window>"u")return[];try{const r=JSON.parse(window.localStorage.getItem(ue)||"[]");return Array.isArray(r)?r.filter(a=>typeof a=="string"):[]}catch{return[]}}function Qe(r){typeof window>"u"||window.localStorage.setItem(ue,JSON.stringify(r))}function me(r){const a=r.split(/[\\/]/).filter(Boolean);return a[a.length-1]||r||"工作目录"}function re(r){return r.replace(/^\/Users\/[^/]+/,"~").replace(/\/+/g,"/")}function ae(r){return r.toLowerCase().replace(/\\/g,"/").trim()}function He(r){return r.split(/[\\/._\-\s]+/).filter(Boolean).map(a=>a[0]).join("").toLowerCase()}function Je(r){const a=r.trim();return a==="~"||a.startsWith("~/")||a.startsWith("/")||a.startsWith("./")||a.startsWith("../")||a.includes("/")||a.includes("\\")}function Ke(r,a){const s=ae(a);if(!s)return 1;const c=ae(r.name),g=ae(r.path),E=He(r.path);return s.split(/\s+/).filter(Boolean).every(L=>c.includes(L)||g.includes(L)||E.includes(L))?c===s?120:g===s?115:c.startsWith(s)?100:g.endsWith(`/${s}`)?95:c.includes(s)?80:g.includes(s)?60:E.startsWith(s)?45:30:0}function ze(r){const a=new Map;for(const s of r){const c=a.get(s.path);(!c||X[s.source]>X[c.source])&&a.set(s.path,s)}return Array.from(a.values())}const Xe=({open:r,currentDir:a,onSelect:s,onClose:c})=>{const[g,E]=l.useState(a),[m,L]=l.useState([]),[M,V]=l.useState(""),[G,N]=l.useState(!1),[I,Y]=l.useState([]),[_,v]=l.useState([]),[h,C]=l.useState(()=>xe()),[p,f]=l.useState(""),[A,u]=l.useState(!1),[O,Q]=l.useState(!1),[P,o]=l.useState(""),T=l.useCallback(async t=>{u(!0),o("");try{const i=await le.listDir(t);return E(i.dir),L(i.dirs),V(i.parent),N(i.isRoot),Y(i.quickAccess),!0}catch(i){return o(i.message||"加载失败"),!1}finally{u(!1)}},[]),x=l.useCallback(async()=>{Q(!0);try{const t=await le.fetchWorkdirs();v(t.workdirs)}catch{v([])}finally{Q(!1)}},[]);l.useEffect(()=>{r&&(f(""),C(xe()),T(a),x())},[r,a,T,x]);const b=l.useMemo(()=>{const t=new Map(_.map(i=>[i.path,i]));return h.map(i=>{const n=t.get(i);return{name:(n==null?void 0:n.name)||me(i),path:i,source:"favorite"}})},[h,_]),D=l.useMemo(()=>_.map(t=>({name:t.name,path:t.path,source:h.includes(t.path)?"favorite":"recent"})),[h,_]),R=l.useMemo(()=>{const t=p.trim();return t?ze([...b,...D,...I.map(n=>({name:n.name,path:n.path,source:"quick"})),...m.map(n=>({name:n.name,path:n.path,source:"current"}))]).map(n=>({...n,score:Ke(n,t)+X[n.source]*5})).filter(n=>n.score>X[n.source]*5).sort((n,w)=>(w.score||0)-(n.score||0)||n.name.localeCompare(w.name)).slice(0,24):[]},[m,b,D,p,I]),B=l.useMemo(()=>D.filter(t=>t.path!==g&&t.source==="recent").slice(0,8),[g,D]),k=p.trim(),q=k.length>0&&Je(k),W=async t=>{await T(t)&&f("")},H=()=>{s(g),c()},J=async()=>{if(!q)return;await T(k)&&f("")},Z=async()=>{if(k){if(q){await J();return}R[0]&&await W(R[0].path)}},ee=t=>{C(i=>{const n=i.includes(t)?i.filter(w=>w!==t):[t,...i].slice(0,Ue);return Qe(n),n})},j=(t,i)=>{const n=h.includes(t);return e.jsx("button",{type:"button",onClick:()=>ee(t),className:`p-2 rounded-lg transition-colors flex-shrink-0 ${n?"text-amber-500 hover:bg-amber-50 dark:text-amber-400 dark:hover:bg-amber-950":"text-gray-300 hover:text-amber-500 hover:bg-gray-50 dark:text-gray-600 dark:hover:text-amber-400 dark:hover:bg-gray-800"}`,"aria-label":n?`取消收藏 ${i}`:`收藏 ${i}`,title:n?"取消收藏":"收藏",children:e.jsx(K,{className:"w-4 h-4",fill:n?"currentColor":"none"})})},F=(t,i={})=>e.jsxs("div",{className:"w-full flex items-center rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",children:[e.jsxs("button",{type:"button",onClick:()=>W(t.path),className:"min-w-0 flex-1 flex items-center gap-3 px-3 py-3 text-left",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400 flex-shrink-0",children:i.icon||e.jsx(te,{className:"w-5 h-5 text-amber-500 dark:text-amber-400"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm text-gray-700 dark:text-gray-300 truncate",children:t.name}),e.jsx("span",{className:"block text-[11px] text-gray-400 dark:text-gray-500 font-mono truncate",children:i.showSource?`${Ge[t.source]} · ${re(t.path)}`:re(t.path)})]}),e.jsx(Ce,{className:"w-4 h-4 text-gray-300 dark:text-gray-600 flex-shrink-0"})]}),j(t.path,t.name)]},`${t.source}-${t.path}`);return e.jsx(je,{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(ie.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/50 z-40",onClick:c}),e.jsxs(ie.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-gray-900 rounded-t-2xl z-50 flex flex-col",style:{maxHeight:"84vh"},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-gray-800",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"选择工作目录"}),e.jsx("button",{onClick:c,className:"p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(de,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"px-4 py-3 border-b border-gray-100 dark:border-gray-800 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(we,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",value:p,onChange:t=>f(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),Z())},placeholder:"搜索目录或粘贴路径",className:"w-full rounded-lg border border-gray-200 bg-gray-50 py-2 pl-9 pr-9 text-sm text-gray-900 outline-none transition-colors focus:border-primary-500 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"}),p&&e.jsx("button",{type:"button",onClick:()=>f(""),className:"absolute right-2 top-1/2 -translate-y-1/2 rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300","aria-label":"清空搜索",children:e.jsx(de,{className:"h-4 w-4"})})]}),q&&e.jsxs("button",{type:"button",onClick:J,className:"w-full flex items-center gap-2 rounded-lg border border-dashed border-primary-200 bg-primary-50 px-3 py-2 text-left text-sm text-primary-700 transition-colors hover:bg-primary-100 dark:border-primary-800 dark:bg-primary-950 dark:text-primary-300 dark:hover:bg-primary-900",children:[e.jsx(Ne,{className:"w-4 h-4 flex-shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["跳转到 ",k]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm font-mono text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-950 rounded-lg px-3 py-2",children:[e.jsx(te,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 overflow-x-auto whitespace-nowrap",children:re(g)}),j(g,me(g))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:p.trim()?e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1",children:"匹配结果"}),R.length===0?e.jsx("div",{className:"px-3 py-4 text-center text-sm text-gray-400",children:"没有匹配目录"}):e.jsx("div",{className:"space-y-0.5",children:R.map(t=>F(t,{showSource:!0,icon:t.source==="recent"?e.jsx(ce,{className:"w-5 h-5 text-blue-500 dark:text-blue-400"}):t.source==="favorite"?e.jsx(K,{className:"w-5 h-5 text-amber-500 dark:text-amber-400",fill:"currentColor"}):void 0}))})]}):e.jsxs(e.Fragment,{children:[b.length>0&&e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1",children:"常用目录"}),e.jsx("div",{className:"space-y-0.5",children:b.slice(0,8).map(t=>F(t,{icon:e.jsx(K,{className:"w-5 h-5 text-amber-500 dark:text-amber-400",fill:"currentColor"})}))})]}),(B.length>0||O)&&e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1",children:"最近使用"}),O?e.jsx("div",{className:"px-3 py-3 text-sm text-gray-400",children:"加载最近目录..."}):e.jsx("div",{className:"space-y-0.5",children:B.map(t=>F(t,{icon:t.source==="favorite"?e.jsx(K,{className:"w-5 h-5 text-amber-500 dark:text-amber-400",fill:"currentColor"}):e.jsx(ce,{className:"w-5 h-5 text-blue-500 dark:text-blue-400"})}))})]}),I.length>0&&e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1",children:"快捷访问"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:I.map(t=>e.jsxs("button",{onClick:()=>W(t.path),className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors text-left",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:$e[t.icon]||e.jsx(te,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:t.name})]},t.path))})]}),e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1",children:"目录列表"}),!G&&e.jsxs("button",{onClick:()=>W(M),className:"w-full flex items-center gap-3 px-3 py-3 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors text-left",children:[e.jsx(ve,{className:"w-5 h-5 text-gray-400"}),e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"返回上级目录"})]}),A&&e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 border-2 border-primary-600 border-t-transparent rounded-full animate-spin"})}),P&&e.jsx("div",{className:"px-3 py-4 text-center text-sm text-red-500",children:P}),!A&&!P&&m.length===0&&e.jsx("div",{className:"px-3 py-4 text-center text-sm text-gray-400",children:"此目录下没有子目录"}),!A&&!P&&m.map(t=>F({...t,source:"current"}))]})]})}),e.jsx("div",{className:"px-4 py-3 border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900 pb-safe",children:e.jsxs("button",{onClick:H,className:"w-full py-3 flex items-center justify-center gap-2 text-sm font-medium text-white bg-primary-600 rounded-xl hover:bg-primary-700 transition-colors active:scale-[0.98]",children:[e.jsx($,{className:"w-4 h-4"}),"使用此目录"]})})]})]})})},Ve=["--dangerously-bypass-approvals-and-sandbox","-m","gpt-5.5","-c",'model_reasoning_effort="xhigh"',"-c",'service_tier="priority"'],U={claude:{label:"Claude Code",command:"claude",cliArgs:["--dangerously-skip-permissions"],dangerArg:"--dangerously-skip-permissions"},codex:{label:"Codex CLI",command:"codex",cliArgs:Ve,dangerArg:"--dangerously-bypass-approvals-and-sandbox",modelLabel:"GPT-5.5",intelligenceLabel:"xhigh",speedLabel:"priority"}};function ge(r){var c;const a=r||"";return a.trim()?(((c=a.split(/[\\/]/).pop())==null?void 0:c.toLowerCase())||a.toLowerCase()).includes("codex")?"codex":"claude":"codex"}function Ye(r){const a=document.createElement("textarea");a.value=r,a.setAttribute("readonly",""),a.style.position="fixed",a.style.top="-9999px",document.body.appendChild(a),a.select();try{return document.execCommand("copy")}finally{document.body.removeChild(a)}}async function Ze(r){var a;try{if((a=navigator.clipboard)!=null&&a.writeText)return await navigator.clipboard.writeText(r),!0}catch{}return Ye(r)}function et(r){return r==="connected"?"已连接":r==="connecting"?"连接中":r==="reconnecting"?"重连中":"已断开"}function tt(r){return r==="idle"?"空闲":r==="running"?"进行中":r==="confirm"?"等待确认":r==="question"?"等待回答":"未连接"}const it=()=>{const r=he(),{connectionStatus:a,cliConfig:s,startCLI:c,restartCLI:g,setConfirmMode:E,status:m,newSession:L}=be(),{theme:M,toggleTheme:V}=ke(),{canPromptInstall:G,isInstalled:N,isInstalling:I,isIos:Y,promptInstall:_}=qe(),[v,h]=l.useState("codex"),[C,p]=l.useState("key"),[f,A]=l.useState("codex"),[u,O]=l.useState("~"),[Q,P]=l.useState(!1),[o,T]=l.useState(null),x=a==="connected",b=m==="running"||m==="confirm"||m==="question",D=window.location.origin,R=window.location.hostname||"localhost",B=window.location.port||(window.location.protocol==="https:"?"443":"80");l.useEffect(()=>{if(s){const d=s.cliType||ge(s.cliCommand);h(d),p(s.confirmMode),A(s.cliCommand),O(s.workDir)}},[s]),l.useEffect(()=>{if(!o)return;const d=window.setTimeout(()=>T(null),1200);return()=>window.clearTimeout(d)},[o]);const k=(d=u,S=v,se=f)=>({cliType:S,cliCommand:se,workDir:d,confirmMode:C,cliArgs:U[S].cliArgs}),q=()=>{c(k())},W=()=>{g(),r("/session")},H=d=>{p(d),x&&E(d)},J=d=>{const S=U[d].command;d===v&&S===f||(h(d),A(S),x&&!b&&c(k(u,d,S)))},Z=d=>{O(d),x&&c(k(d))},ee=d=>{A(d),h(ge(d))},j=U[v],F=et(a),t=tt(m),i=C==="auto"?"自动通过":"手动确认",n=(s==null?void 0:s.workDir)===u&&(s!=null&&s.isGitRepo)?s.gitBranch||"HEAD":"",w=async(d,S)=>{await Ze(S)&&T(d)};return e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950 overflow-y-auto",children:[e.jsx(Be,{title:"设置",className:"sticky top-0"}),e.jsxs("div",{className:"w-full max-w-3xl mx-auto p-4 space-y-5 pb-8",children:[e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2 px-1",children:"当前状态"}),e.jsx("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 shadow-sm overflow-hidden",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:y("w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0",x?"bg-green-50 dark:bg-green-950 text-green-600 dark:text-green-400":"bg-red-50 dark:bg-red-950 text-red-600 dark:text-red-400"),children:e.jsx(Ae,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:x?"AgentPilot 可用":"AgentPilot 未连接"}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 truncate",children:[j.label," · ",t]})]})]}),e.jsxs("span",{className:y("inline-flex w-fit items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium",x?"bg-green-50 dark:bg-green-950 text-green-700 dark:text-green-400":"bg-red-50 dark:bg-red-950 text-red-700 dark:text-red-400"),children:[e.jsx("span",{className:y("h-2 w-2 rounded-full",x?"bg-green-500":"bg-red-500")}),F]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs("span",{className:y("rounded-full px-2.5 py-1 text-xs font-medium",m==="running"?"bg-primary-50 dark:bg-primary-950 text-primary-700 dark:text-primary-300":m==="confirm"?"bg-orange-50 dark:bg-orange-950 text-orange-700 dark:text-orange-400":m==="question"?"bg-blue-50 dark:bg-blue-950 text-blue-700 dark:text-blue-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"),children:["CLI ",t]}),e.jsx("span",{className:"rounded-full bg-gray-100 dark:bg-gray-800 px-2.5 py-1 text-xs font-medium text-gray-700 dark:text-gray-300",children:j.label}),e.jsx("span",{className:"rounded-full bg-amber-50 dark:bg-amber-950 px-2.5 py-1 text-xs font-medium text-amber-700 dark:text-amber-400",children:"权限已跳过"}),e.jsx("span",{className:"rounded-full bg-gray-100 dark:bg-gray-800 px-2.5 py-1 text-xs font-medium text-gray-700 dark:text-gray-300",children:i}),n&&e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1 rounded-full bg-gray-100 dark:bg-gray-800 px-2.5 py-1 text-xs font-medium text-gray-700 dark:text-gray-300",children:[e.jsx(oe,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n})]})]}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"访问地址"}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:justify-end",children:[e.jsx("span",{className:"truncate text-sm font-mono text-gray-900 dark:text-gray-100",children:D}),e.jsx("button",{type:"button",onClick:()=>w("serverUrl",D),className:"flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:o==="serverUrl"?"已复制":"复制访问地址","aria-label":o==="serverUrl"?"已复制访问地址":"复制访问地址",children:o==="serverUrl"?e.jsx($,{className:"w-3.5 h-3.5"}):e.jsx(z,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"主机"}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-mono text-gray-900 dark:text-gray-100",children:R}),e.jsx("button",{type:"button",onClick:()=>w("host",R),className:"flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:o==="host"?"已复制":"复制主机","aria-label":o==="host"?"已复制主机":"复制主机",children:o==="host"?e.jsx($,{className:"w-3.5 h-3.5"}):e.jsx(z,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"端口"}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-mono text-gray-900 dark:text-gray-100",children:B}),e.jsx("button",{type:"button",onClick:()=>w("port",B),className:"flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:o==="port"?"已复制":"复制端口","aria-label":o==="port"?"已复制端口":"复制端口",children:o==="port"?e.jsx($,{className:"w-3.5 h-3.5"}):e.jsx(z,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"工作目录"}),e.jsxs("div",{className:"flex min-w-0 items-start gap-2 sm:max-w-[75%] sm:justify-end",children:[e.jsx("span",{className:"min-w-0 break-all text-sm font-mono leading-relaxed text-gray-900 dark:text-gray-100",children:u}),e.jsx("button",{type:"button",onClick:()=>w("workDir",u),className:"flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:o==="workDir"?"已复制":"复制工作目录","aria-label":o==="workDir"?"已复制工作目录":"复制工作目录",children:o==="workDir"?e.jsx($,{className:"w-3.5 h-3.5"}):e.jsx(z,{className:"w-3.5 h-3.5"})})]})]}),n&&e.jsxs("div",{className:"flex flex-col gap-1.5 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Git 分支"}),e.jsxs("span",{className:"inline-flex w-fit max-w-full min-w-0 items-center gap-1.5 rounded-full bg-gray-100 px-2.5 py-1 text-sm font-medium text-gray-700 dark:bg-gray-800 dark:text-gray-300",children:[e.jsx(oe,{className:"h-3.5 w-3.5 flex-shrink-0"}),e.jsx("span",{className:"min-w-0 break-all",children:n})]})]})]}),e.jsx("div",{className:"mt-4 rounded-lg border border-amber-200 bg-amber-50 p-3 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Pe,{className:"w-4 h-4 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-amber-800 dark:text-amber-300",children:"危险模式已启用"}),e.jsxs("div",{className:"mt-1 text-xs leading-relaxed text-amber-700 dark:text-amber-400",children:["使用 ",e.jsx("span",{className:"font-mono break-all",children:j.dangerArg})," 运行,CLI 可以直接读写文件并执行命令。仅在可信环境中使用。"]})]})]})}),e.jsxs("div",{className:"mt-4 grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsxs("button",{type:"button",onClick:()=>{x?(L(),r("/session")):q()},className:"w-full py-2.5 flex items-center justify-center gap-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 transition-colors",children:[x?e.jsx(Te,{className:"w-4 h-4"}):e.jsx(De,{className:"w-4 h-4"}),x?"新开会话":"启动 CLI"]}),x&&e.jsxs("button",{type:"button",onClick:W,className:"w-full py-2.5 px-4 flex items-center justify-center gap-2 text-sm font-medium text-red-600 dark:text-red-400 bg-white dark:bg-gray-900 border border-red-100 dark:border-red-800 rounded-lg hover:bg-red-50 dark:hover:bg-red-950 transition-colors sm:w-auto",children:[e.jsx(Re,{className:"w-4 h-4"}),"重启 CLI"]})]})]})})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2 px-1",children:"Agent CLI"}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-50 dark:border-gray-800 flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary-50 dark:bg-primary-950 text-primary-600 dark:text-primary-400 flex items-center justify-center",children:e.jsx(Ee,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:"Agent 配置"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"选择 CLI、启动命令和工作目录"})]})]}),e.jsxs("div",{className:"divide-y divide-gray-50 dark:divide-gray-800",children:[e.jsxs("div",{className:"w-full p-4 space-y-2",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"当前 Agent"}),e.jsx("div",{className:"grid grid-cols-2 gap-2 rounded-lg bg-gray-50 dark:bg-gray-800 p-1 border border-gray-200 dark:border-gray-700",children:Object.keys(U).map(d=>e.jsx("button",{type:"button",onClick:()=>J(d),disabled:b,className:y("py-2 px-3 rounded-md text-sm font-medium transition-colors",v===d?"bg-white dark:bg-gray-900 text-primary-700 dark:text-primary-300 shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",b&&"opacity-60 cursor-not-allowed"),children:U[d].label},d))}),b&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"CLI 正在处理任务时暂不可切换 Agent。"})]}),e.jsxs("div",{className:"w-full p-4 space-y-2",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"启动命令"}),e.jsx("input",{type:"text",value:f,onChange:d=>ee(d.target.value),className:"w-full text-sm text-gray-900 dark:text-gray-100 font-mono bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 focus:outline-none focus:border-primary-500 disabled:cursor-not-allowed disabled:opacity-70",disabled:x&&m!=="disconnected"}),x&&m!=="disconnected"&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"已连接时命令会被锁定,重启 CLI 后按当前配置生效。"})]}),e.jsxs("div",{className:"w-full p-4 space-y-2",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"工作目录"}),e.jsxs("button",{type:"button",onClick:()=>P(!0),className:"w-full flex items-start gap-2 text-sm text-gray-900 dark:text-gray-100 font-mono bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-left hover:border-primary-500 transition-colors",children:[e.jsx(Me,{className:"w-4 h-4 text-amber-500 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"min-w-0 flex-1 break-all leading-relaxed",children:u})]}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"选择后会作为新会话的默认工作目录。"})]}),e.jsxs("div",{className:"w-full p-4 space-y-2",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"确认模式"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 rounded-lg bg-gray-50 dark:bg-gray-800 p-1 border border-gray-200 dark:border-gray-700",children:[e.jsx("button",{type:"button",onClick:()=>H("key"),className:y("py-2 px-3 rounded-md text-sm font-medium transition-colors",C==="key"?"bg-white dark:bg-gray-900 text-primary-700 dark:text-primary-300 shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"),children:"手动确认"}),e.jsx("button",{type:"button",onClick:()=>H("auto"),className:y("py-2 px-3 rounded-md text-sm font-medium transition-colors",C==="auto"?"bg-white dark:bg-gray-900 text-amber-700 dark:text-amber-300 shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"),children:"自动通过"})]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:["CLI 仍发出权限请求时,",C==="auto"?"系统会自动通过。":"需要你在对话页确认。"]})]}),v==="codex"&&e.jsxs("div",{className:"w-full p-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"模型档位"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 sm:justify-end",children:[e.jsx("span",{className:"text-xs px-2 py-1 rounded-full bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300",children:j.modelLabel}),e.jsxs("span",{className:"text-xs px-2 py-1 rounded-full bg-green-50 dark:bg-green-950 text-green-700 dark:text-green-400",children:["推理强度 ",j.intelligenceLabel]}),e.jsxs("span",{className:"text-xs px-2 py-1 rounded-full bg-blue-50 dark:bg-blue-950 text-blue-700 dark:text-blue-400",children:["服务层级 ",j.speedLabel]})]})]})]})]})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2 px-1",children:"应用设置"}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 shadow-sm overflow-hidden divide-y divide-gray-50 dark:divide-gray-800",children:[e.jsxs("div",{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[M==="dark"?e.jsx("div",{className:"w-10 h-10 rounded-full bg-gray-800 text-gray-300 flex items-center justify-center",children:e.jsx(_e,{className:"w-5 h-5"})}):e.jsx("div",{className:"w-10 h-10 rounded-full bg-yellow-50 text-yellow-600 flex items-center justify-center",children:e.jsx(We,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:M==="dark"?"深色模式":"浅色模式"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"切换界面主题"})]})]}),e.jsx("button",{onClick:V,className:y("relative inline-flex h-7 w-12 items-center rounded-full transition-colors",M==="dark"?"bg-primary-600":"bg-gray-300"),"aria-label":"切换界面主题",children:e.jsx("span",{className:y("inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-sm",M==="dark"?"translate-x-6":"translate-x-1")})})]}),e.jsxs("div",{className:"p-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:y("w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0",N?"bg-green-50 dark:bg-green-950 text-green-600 dark:text-green-400":"bg-primary-50 dark:bg-primary-950 text-primary-600 dark:text-primary-400"),children:N?e.jsx(Fe,{className:"w-5 h-5"}):e.jsx(Oe,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:N?"已安装为独立 App":"添加到主屏幕"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 leading-relaxed",children:N?"当前正在独立窗口中运行":G?"从桌面或主屏幕直接启动 AgentPilot":Y?"打开分享菜单后选择“添加到主屏幕”":"使用浏览器菜单安装 AgentPilot"})]})]}),G?e.jsxs("button",{type:"button",onClick:_,disabled:I,className:"flex items-center justify-center gap-1.5 rounded-lg bg-primary-600 px-3 py-2 text-sm font-medium text-white hover:bg-primary-700 disabled:cursor-not-allowed disabled:opacity-60 transition-colors flex-shrink-0",children:[e.jsx(ye,{className:"w-4 h-4"}),I?"安装中":"安装"]}):e.jsx("span",{className:y("text-xs px-2 py-1 rounded-full font-medium flex-shrink-0",N?"bg-green-50 dark:bg-green-950 text-green-700 dark:text-green-400":"bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400"),children:N?"已完成":"浏览器菜单"})]})]})]}),e.jsxs("div",{className:"text-center pt-4 pb-8",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-400 dark:text-gray-600",children:"AgentPilot"}),e.jsx("div",{className:"text-xs text-gray-300 dark:text-gray-600 mt-1",children:"AI Agent 遥控器"}),e.jsx("div",{className:"text-[10px] text-gray-300 dark:text-gray-700 mt-2",children:"v0.1.0"})]})]}),e.jsx(Xe,{open:Q,currentDir:u,onSelect:Z,onClose:()=>P(!1)})]})};export{it as Settings};