agentroam-runtime-darwin-arm64 0.2.0-preview.11 → 0.2.0-preview.13

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 (122) hide show
  1. package/manifest.json +1 -1
  2. package/package.json +1 -1
  3. package/runtime/.next/BUILD_ID +1 -1
  4. package/runtime/.next/app-build-manifest.json +7 -7
  5. package/runtime/.next/app-path-routes-manifest.json +1 -1
  6. package/runtime/.next/build-manifest.json +8 -8
  7. package/runtime/.next/prerender-manifest.json +1 -1
  8. package/runtime/.next/react-loadable-manifest.json +3 -3
  9. package/runtime/.next/required-server-files.json +1 -1
  10. package/runtime/.next/routes-manifest.json +1 -1
  11. package/runtime/.next/server/app/_not-found/page.js +1 -1
  12. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/runtime/.next/server/app/_not-found.html +1 -1
  14. package/runtime/.next/server/app/_not-found.rsc +1 -1
  15. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  16. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  17. package/runtime/.next/server/app/api/agent/model/route.js +1 -1
  18. package/runtime/.next/server/app/api/agent/models/route.js +1 -0
  19. package/runtime/.next/server/app/api/agent/models/route.js.nft.json +1 -0
  20. package/runtime/.next/server/app/api/agent/run/route.js +1 -1
  21. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  22. package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
  23. package/runtime/.next/server/app/api/agent/stream/route.js +2 -2
  24. package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
  25. package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
  26. package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
  27. package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
  28. package/runtime/.next/server/app/api/mcp/disconnect/route.js +1 -1
  29. package/runtime/.next/server/app/api/mcp/servers/route.js +1 -1
  30. package/runtime/.next/server/app/api/memory/[key]/route.js +1 -1
  31. package/runtime/.next/server/app/api/memory/route.js +1 -1
  32. package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
  33. package/runtime/.next/server/app/api/projects/[id]/route.js +1 -1
  34. package/runtime/.next/server/app/api/projects/check/route.js +1 -1
  35. package/runtime/.next/server/app/api/projects/directories/route.js +1 -1
  36. package/runtime/.next/server/app/api/projects/roots/route.js +1 -1
  37. package/runtime/.next/server/app/api/projects/route.js +1 -1
  38. package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
  39. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
  40. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
  41. package/runtime/.next/server/app/api/sessions/[id]/goals/route.js +1 -1
  42. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
  43. package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js +1 -0
  44. package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js.nft.json +1 -0
  45. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  46. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  47. package/runtime/.next/server/app/api/skills/route.js +1 -1
  48. package/runtime/.next/server/app/api/tools/route.js +1 -1
  49. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  50. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  51. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  52. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  53. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  54. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  55. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  56. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  57. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  58. package/runtime/.next/server/app/web/page.js +10 -6
  59. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  60. package/runtime/.next/server/app/web.html +1 -1
  61. package/runtime/.next/server/app/web.rsc +2 -2
  62. package/runtime/.next/server/app-paths-manifest.json +20 -18
  63. package/runtime/.next/server/chunks/1322.js +40 -39
  64. package/runtime/.next/server/chunks/2083.js +7 -7
  65. package/runtime/.next/server/chunks/5303.js +2 -2
  66. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  67. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  68. package/runtime/.next/server/pages/404.html +1 -1
  69. package/runtime/.next/server/pages/500.html +1 -1
  70. package/runtime/.next/server/server-reference-manifest.json +1 -1
  71. package/runtime/.next/static/chunks/137.261fab9d606d75d3.js +1 -0
  72. package/runtime/.next/static/chunks/366.2332f424b0ce112a.js +1 -0
  73. package/runtime/.next/static/chunks/app/web/page-8e4da33d77868123.js +1 -0
  74. package/runtime/.next/static/chunks/{main-46a4068052b74acf.js → main-4b71c9eb0b4f4151.js} +1 -1
  75. package/runtime/.next/static/chunks/main-app-3596fd7d2841e9a3.js +1 -0
  76. package/runtime/.next/static/chunks/{webpack-5b0dd5760d684512.js → webpack-d22db940097662ef.js} +1 -1
  77. package/runtime/lib/file-preview-service.mjs +3 -1
  78. package/runtime/node_modules/.package-lock.json +11 -11
  79. package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts +2 -0
  80. package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts.map +1 -1
  81. package/runtime/node_modules/@agent/core/dist/domain/session/SessionHistory.d.ts.map +1 -1
  82. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndex.d.ts +16 -0
  83. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndex.d.ts.map +1 -0
  84. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndex.test.d.ts +2 -0
  85. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndex.test.d.ts.map +1 -0
  86. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndexCache.d.ts +11 -0
  87. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndexCache.d.ts.map +1 -0
  88. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndexCache.test.d.ts +2 -0
  89. package/runtime/node_modules/@agent/core/dist/domain/session/SessionQueryIndexCache.test.d.ts.map +1 -0
  90. package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts +18 -0
  91. package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts.map +1 -1
  92. package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts +3 -1
  93. package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts.map +1 -1
  94. package/runtime/node_modules/@agent/core/dist/domain/web-console/entities.d.ts +1 -0
  95. package/runtime/node_modules/@agent/core/dist/domain/web-console/entities.d.ts.map +1 -1
  96. package/runtime/node_modules/@agent/core/dist/index.js +224 -13
  97. package/runtime/node_modules/@agent/core/dist/index.js.map +8 -6
  98. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteDatabase.d.ts +2 -0
  99. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteDatabase.d.ts.map +1 -1
  100. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteWebConsoleStore.d.ts +1 -1
  101. package/runtime/node_modules/@agent/core/dist/infrastructure/SQLiteWebConsoleStore.d.ts.map +1 -1
  102. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +100 -79
  103. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +67 -59
  104. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +19 -21
  105. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -25
  106. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/package.json +10 -10
  107. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +98 -77
  108. package/runtime/package-lock.json +44 -44
  109. package/runtime/shell-integration.mjs +126 -0
  110. package/runtime/webapp/dist/assets/App-CZspcejP.js +275 -0
  111. package/runtime/webapp/dist/assets/{index-CMg2JqFN.js → index-BAH3pT_c.js} +12 -12
  112. package/runtime/webapp/dist/assets/index-lt5J4xDf.css +1 -0
  113. package/runtime/webapp/dist/index.html +2 -2
  114. package/runtime/ws-server.mjs +95 -35
  115. package/runtime/.next/static/chunks/366.9bfa310c7c3276cf.js +0 -1
  116. package/runtime/.next/static/chunks/793.e40ddf9167835123.js +0 -1
  117. package/runtime/.next/static/chunks/app/web/page-d0549ed261e10cd8.js +0 -1
  118. package/runtime/.next/static/chunks/main-app-1ca58b15d170cda2.js +0 -1
  119. package/runtime/webapp/dist/assets/App-B13GP2OF.js +0 -270
  120. package/runtime/webapp/dist/assets/index-8vuD14aR.css +0 -1
  121. /package/runtime/.next/static/{xTNCVAIsaS_jW3LOfeS7l → iaxCayE60RyqJY_Zj-OjS}/_buildManifest.js +0 -0
  122. /package/runtime/.next/static/{xTNCVAIsaS_jW3LOfeS7l → iaxCayE60RyqJY_Zj-OjS}/_ssgManifest.js +0 -0
@@ -1,270 +0,0 @@
1
- import{r as u,R as Ya,c as Ji,j as e,a as Vt,u as nt,i as Hn,b as Xa,S as eo,L as to}from"./index-CMg2JqFN.js";/**
2
- * @license lucide-react v0.468.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const no=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Yi=(...t)=>t.filter((r,n,s)=>!!r&&r.trim()!==""&&s.indexOf(r)===n).join(" ").trim();/**
7
- * @license lucide-react v0.468.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */var ro={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
12
- * @license lucide-react v0.468.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const so=u.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:n=2,absoluteStrokeWidth:s,className:i="",children:a,iconNode:l,...c},f)=>u.createElement("svg",{ref:f,...ro,width:r,height:r,stroke:t,strokeWidth:s?Number(n)*24/Number(r):n,className:Yi("lucide",i),...c},[...l.map(([h,x])=>u.createElement(h,x)),...Array.isArray(a)?a:[a]]));/**
17
- * @license lucide-react v0.468.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const X=(t,r)=>{const n=u.forwardRef(({className:s,...i},a)=>u.createElement(so,{ref:a,iconNode:r,className:Yi(`lucide-${no(t)}`,s),...i}));return n.displayName=`${t}`,n};/**
22
- * @license lucide-react v0.468.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const io=X("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
27
- * @license lucide-react v0.468.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const ao=X("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);/**
32
- * @license lucide-react v0.468.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const Es=X("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);/**
37
- * @license lucide-react v0.468.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const Or=X("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
42
- * @license lucide-react v0.468.0 - ISC
43
- *
44
- * This source code is licensed under the ISC license.
45
- * See the LICENSE file in the root directory of this source tree.
46
- */const Qn=X("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
47
- * @license lucide-react v0.468.0 - ISC
48
- *
49
- * This source code is licensed under the ISC license.
50
- * See the LICENSE file in the root directory of this source tree.
51
- */const oo=X("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
52
- * @license lucide-react v0.468.0 - ISC
53
- *
54
- * This source code is licensed under the ISC license.
55
- * See the LICENSE file in the root directory of this source tree.
56
- */const lo=X("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
57
- * @license lucide-react v0.468.0 - ISC
58
- *
59
- * This source code is licensed under the ISC license.
60
- * See the LICENSE file in the root directory of this source tree.
61
- */const ss=X("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
62
- * @license lucide-react v0.468.0 - ISC
63
- *
64
- * This source code is licensed under the ISC license.
65
- * See the LICENSE file in the root directory of this source tree.
66
- */const co=X("CornerUpRight",[["polyline",{points:"15 14 20 9 15 4",key:"1tbx3s"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]);/**
67
- * @license lucide-react v0.468.0 - ISC
68
- *
69
- * This source code is licensed under the ISC license.
70
- * See the LICENSE file in the root directory of this source tree.
71
- */const uo=X("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
72
- * @license lucide-react v0.468.0 - ISC
73
- *
74
- * This source code is licensed under the ISC license.
75
- * See the LICENSE file in the root directory of this source tree.
76
- */const po=X("FileArchive",[["path",{d:"M10 12v-1",key:"v7bkov"}],["path",{d:"M10 18v-2",key:"1cjy8d"}],["path",{d:"M10 7V6",key:"dljcrl"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01",key:"gkbcor"}],["circle",{cx:"10",cy:"20",r:"2",key:"1xzdoj"}]]);/**
77
- * @license lucide-react v0.468.0 - ISC
78
- *
79
- * This source code is licensed under the ISC license.
80
- * See the LICENSE file in the root directory of this source tree.
81
- */const go=X("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);/**
82
- * @license lucide-react v0.468.0 - ISC
83
- *
84
- * This source code is licensed under the ISC license.
85
- * See the LICENSE file in the root directory of this source tree.
86
- */const fo=X("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
87
- * @license lucide-react v0.468.0 - ISC
88
- *
89
- * This source code is licensed under the ISC license.
90
- * See the LICENSE file in the root directory of this source tree.
91
- */const ho=X("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]);/**
92
- * @license lucide-react v0.468.0 - ISC
93
- *
94
- * This source code is licensed under the ISC license.
95
- * See the LICENSE file in the root directory of this source tree.
96
- */const xo=X("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
97
- * @license lucide-react v0.468.0 - ISC
98
- *
99
- * This source code is licensed under the ISC license.
100
- * See the LICENSE file in the root directory of this source tree.
101
- */const mo=X("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);/**
102
- * @license lucide-react v0.468.0 - ISC
103
- *
104
- * This source code is licensed under the ISC license.
105
- * See the LICENSE file in the root directory of this source tree.
106
- */const zs=X("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/**
107
- * @license lucide-react v0.468.0 - ISC
108
- *
109
- * This source code is licensed under the ISC license.
110
- * See the LICENSE file in the root directory of this source tree.
111
- */const bo=X("FileVideo2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["rect",{width:"8",height:"6",x:"2",y:"12",rx:"1",key:"1a6c1e"}],["path",{d:"m10 15.5 4 2.5v-6l-4 2.5",key:"t7cp39"}]]);/**
112
- * @license lucide-react v0.468.0 - ISC
113
- *
114
- * This source code is licensed under the ISC license.
115
- * See the LICENSE file in the root directory of this source tree.
116
- */const yo=X("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
117
- * @license lucide-react v0.468.0 - ISC
118
- *
119
- * This source code is licensed under the ISC license.
120
- * See the LICENSE file in the root directory of this source tree.
121
- */const vo=X("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
122
- * @license lucide-react v0.468.0 - ISC
123
- *
124
- * This source code is licensed under the ISC license.
125
- * See the LICENSE file in the root directory of this source tree.
126
- */const ci=X("GripVertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]);/**
127
- * @license lucide-react v0.468.0 - ISC
128
- *
129
- * This source code is licensed under the ISC license.
130
- * See the LICENSE file in the root directory of this source tree.
131
- */const wo=X("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);/**
132
- * @license lucide-react v0.468.0 - ISC
133
- *
134
- * This source code is licensed under the ISC license.
135
- * See the LICENSE file in the root directory of this source tree.
136
- */const jo=X("Lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]);/**
137
- * @license lucide-react v0.468.0 - ISC
138
- *
139
- * This source code is licensed under the ISC license.
140
- * See the LICENSE file in the root directory of this source tree.
141
- */const ko=X("ListTodo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);/**
142
- * @license lucide-react v0.468.0 - ISC
143
- *
144
- * This source code is licensed under the ISC license.
145
- * See the LICENSE file in the root directory of this source tree.
146
- */const Kn=X("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
147
- * @license lucide-react v0.468.0 - ISC
148
- *
149
- * This source code is licensed under the ISC license.
150
- * See the LICENSE file in the root directory of this source tree.
151
- */const So=X("LockKeyhole",[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]]);/**
152
- * @license lucide-react v0.468.0 - ISC
153
- *
154
- * This source code is licensed under the ISC license.
155
- * See the LICENSE file in the root directory of this source tree.
156
- */const Co=X("NotebookText",[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M9.5 8h5",key:"11mslq"}],["path",{d:"M9.5 12H16",key:"ktog6x"}],["path",{d:"M9.5 16H14",key:"p1seyn"}]]);/**
157
- * @license lucide-react v0.468.0 - ISC
158
- *
159
- * This source code is licensed under the ISC license.
160
- * See the LICENSE file in the root directory of this source tree.
161
- */const Io=X("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
162
- * @license lucide-react v0.468.0 - ISC
163
- *
164
- * This source code is licensed under the ISC license.
165
- * See the LICENSE file in the root directory of this source tree.
166
- */const Xi=X("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
167
- * @license lucide-react v0.468.0 - ISC
168
- *
169
- * This source code is licensed under the ISC license.
170
- * See the LICENSE file in the root directory of this source tree.
171
- */const ui=X("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
172
- * @license lucide-react v0.468.0 - ISC
173
- *
174
- * This source code is licensed under the ISC license.
175
- * See the LICENSE file in the root directory of this source tree.
176
- */const Ao=X("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]);/**
177
- * @license lucide-react v0.468.0 - ISC
178
- *
179
- * This source code is licensed under the ISC license.
180
- * See the LICENSE file in the root directory of this source tree.
181
- */const ea=X("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
182
- * @license lucide-react v0.468.0 - ISC
183
- *
184
- * This source code is licensed under the ISC license.
185
- * See the LICENSE file in the root directory of this source tree.
186
- */const ta=X("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
187
- * @license lucide-react v0.468.0 - ISC
188
- *
189
- * This source code is licensed under the ISC license.
190
- * See the LICENSE file in the root directory of this source tree.
191
- */const To=X("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);/**
192
- * @license lucide-react v0.468.0 - ISC
193
- *
194
- * This source code is licensed under the ISC license.
195
- * See the LICENSE file in the root directory of this source tree.
196
- */const Ro=X("SquareTerminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]]);/**
197
- * @license lucide-react v0.468.0 - ISC
198
- *
199
- * This source code is licensed under the ISC license.
200
- * See the LICENSE file in the root directory of this source tree.
201
- */const Mo=X("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
202
- * @license lucide-react v0.468.0 - ISC
203
- *
204
- * This source code is licensed under the ISC license.
205
- * See the LICENSE file in the root directory of this source tree.
206
- */const is=X("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
207
- * @license lucide-react v0.468.0 - ISC
208
- *
209
- * This source code is licensed under the ISC license.
210
- * See the LICENSE file in the root directory of this source tree.
211
- */const Ur=X("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
212
- * @license lucide-react v0.468.0 - ISC
213
- *
214
- * This source code is licensed under the ISC license.
215
- * See the LICENSE file in the root directory of this source tree.
216
- */const No=X("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
217
- * @license lucide-react v0.468.0 - ISC
218
- *
219
- * This source code is licensed under the ISC license.
220
- * See the LICENSE file in the root directory of this source tree.
221
- */const Eo=X("Volume2",[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]]);/**
222
- * @license lucide-react v0.468.0 - ISC
223
- *
224
- * This source code is licensed under the ISC license.
225
- * See the LICENSE file in the root directory of this source tree.
226
- */const na=X("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]);/**
227
- * @license lucide-react v0.468.0 - ISC
228
- *
229
- * This source code is licensed under the ISC license.
230
- * See the LICENSE file in the root directory of this source tree.
231
- */const ra=X("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function zo(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||t===null||typeof r!="object"||r===null)return!1;if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(const[s,i]of t)if(!Object.is(i,r.get(s)))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(const s of t)if(!r.has(s))return!1;return!0}const n=Object.keys(t);if(n.length!==Object.keys(r).length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(r,s)||!Object.is(t[s],r[s]))return!1;return!0}const{useRef:Wo}=Ya;function _o(t){const r=Wo();return n=>{const s=t(n);return zo(r.current,s)?r.current:r.current=s}}function pi(t,r){const n=t??[],s=n.findIndex(a=>a.itemId===r.itemId&&a.sectionIndex===r.sectionIndex);return(s<0?[...n,{itemId:r.itemId,sectionIndex:r.sectionIndex,text:r.delta}]:n.map((a,l)=>l===s?{...a,text:a.text+r.delta}:a)).sort((a,l)=>a.sectionIndex-l.sectionIndex)}function gi(t){let r=[];for(const n of t)if(n.type==="runtime_progress"){const{type:s,...i}=n;r=sa(r,i)}else(n.type==="done"||n.type==="turn_aborted"||n.type==="error")&&(r=[]);return r}function sa(t,r){const n=t.findIndex(s=>s.progressId===r.progressId);return n<0?[...t,r]:t.map((s,i)=>i===n?r:s)}function Lo(t,r){return[...t].reverse().find(n=>n.toolCallId===r)}function Po(t){return[...t].reverse().find(r=>!r.toolCallId)}function fi(t){for(let r=t.length-1;r>=0;r--)if(t[r].type==="context_usage"&&t[r].usage)return t[r].usage}function hi(t){var n;const r=new Map;for(const s of t)s.type==="native_subagent_update"&&((n=s.activity)!=null&&n.parentToolCallId)&&r.set(s.activity.parentToolCallId,s.activity);return[...r.values()]}function xi(t,r){var n,s;if(r.role==="assistant"&&((n=r.toolCalls)!=null&&n.length)){const i=t[t.length-1];if(i&&i.role==="assistant"&&!((s=i.toolCalls)!=null&&s.length))return[...t.slice(0,-1),{...i,content:i.content,toolCalls:r.toolCalls}]}return[...t,r]}function mi(t,r){var s;if(!r)return t;const n=t[t.length-1];if(n&&n.role==="assistant"&&!((s=n.toolCalls)!=null&&s.length)&&!n.askUser&&!n.isCompactionSummary){const i=[...t];return i[i.length-1]={...n,content:n.content+r},i}return[...t,{id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()}]}function bi(t,r,n,s){return t.map(i=>{if(!i.toolCalls)return i;const a=i.toolCalls.map(l=>l.id===r?{...l,result:n,isError:s}:l);return{...i,toolCalls:a}})}function yi(t,r,n,s){return t.map(i=>{if(!i.toolCalls)return i;const a=i.toolCalls.map(l=>l.name==="dispatch_agent"&&l.arguments.subSessionId===r?{...l,arguments:{...l.arguments,subAgentStatus:n,subAgentDetail:s}}:l);return{...i,toolCalls:a}})}function vi(t,r,n){return t.map(s=>{if(!s.toolCalls)return s;const i=s.toolCalls.map(a=>a.name==="dispatch_agent"&&a.arguments.subSessionId===r?{...a,arguments:{...a.arguments,subAgentProgress:(a.arguments.subAgentProgress?a.arguments.subAgentProgress+`
232
- `+n:n).split(`
233
- `).slice(-30).join(`
234
- `)}}:a);return{...s,toolCalls:i}})}function wi(t,r,n){return t.map(s=>s.id===r?n(s):s)}function ji(t,r){const n=t.findIndex(s=>{var i,a;return(a=(i=s.presentation)==null?void 0:i.reasoning)==null?void 0:a.some(l=>l.itemId===r.itemId)});return n<0?[...t,{id:`native-reasoning:${r.itemId}`,role:"assistant",content:"",presentation:{reasoning:pi(void 0,r)},timestamp:Date.now()}]:t.map((s,i)=>{var a;return i===n?{...s,presentation:{...s.presentation,reasoning:pi((a=s.presentation)==null?void 0:a.reasoning,r)}}:s})}const ge=Ji((t,r)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(n,s)=>t(i=>{const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:xi(i.messages,n),c=a?{...i.messagesBySession,[a]:xi(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),n)}:i.messagesBySession;return{messages:l,messagesBySession:c,currentText:a&&a!==i.sessionId?i.currentText:""}}),appendText:(n,s)=>t(i=>{if(!n)return i;const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:mi(i.messages,n),c=a?{...i.messagesBySession,[a]:mi(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),n)}:i.messagesBySession;return{messages:l,messagesBySession:c,currentText:a&&a!==i.sessionId?i.currentText:i.currentText+n}}),setRunningSession:n=>t({runningSessionId:n}),setSessionId:n=>t({sessionId:n}),updateToolResult:(n,s,i,a)=>t(l=>{const c=a??l.sessionId??void 0,f=c&&c!==l.sessionId?l.messages:bi(l.messages,n,s,i),h=c?{...l.messagesBySession,[c]:bi(l.messagesBySession[c]??(c===l.sessionId?l.messages:[]),n,s,i)}:l.messagesBySession;return{messages:f,messagesBySession:h}}),setMessages:(n,s)=>t(i=>{const a=s??i.sessionId??void 0,l=!a||a===i.sessionId;return{messages:l?n:i.messages,messagesBySession:a?{...i.messagesBySession,[a]:n}:i.messagesBySession,currentText:l?"":i.currentText}}),getMessagesForSession:n=>r().messagesBySession[n]??[],setContextUsage:(n,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{contextUsageBySession:{...i.contextUsageBySession,[a]:n}}:i}),getContextUsageForSession:n=>r().contextUsageBySession[n],applyRuntimeProgress:(n,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{runtimeProgressBySession:{...i.runtimeProgressBySession,[a]:sa(i.runtimeProgressBySession[a]??[],n)}}:i}),setRuntimeProgress:(n,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{runtimeProgressBySession:{...i.runtimeProgressBySession,[a]:n}}:i}),clearRuntimeProgress:n=>t(s=>{var c;const i=n??s.sessionId??void 0;if(!i||!((c=s.runtimeProgressBySession[i])!=null&&c.length))return s;const{[i]:a,...l}=s.runtimeProgressBySession;return{runtimeProgressBySession:l}}),applyNativeSubagentActivity:(n,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[a]:{...i.nativeSubagentsBySession[a]??{},[n.parentToolCallId]:n}}}:i}),setNativeSubagentActivities:(n,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[a]:Object.fromEntries(n.map(l=>[l.parentToolCallId,l]))}}:i}),applyReasoningSummary:(n,s)=>t(i=>{const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:ji(i.messages,n),c=a?{...i.messagesBySession,[a]:ji(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),n)}:i.messagesBySession;return{messages:l,messagesBySession:c}}),updateMessage:(n,s,i)=>t(a=>{const l=i??a.sessionId??void 0,c=l&&l!==a.sessionId?a.messages:wi(a.messages,n,s),f=l?{...a.messagesBySession,[l]:wi(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:c,messagesBySession:f}}),updateSubAgentStatus:(n,s,i,a)=>t(l=>{const c=a??l.sessionId??void 0,f=c&&c!==l.sessionId?l.messages:yi(l.messages,n,s,i),h=c?{...l.messagesBySession,[c]:yi(l.messagesBySession[c]??(c===l.sessionId?l.messages:[]),n,s,i)}:l.messagesBySession;return{messages:f,messagesBySession:h}}),updateSubAgentProgress:(n,s,i)=>t(a=>{const l=i??a.sessionId??void 0,c=l&&l!==a.sessionId?a.messages:vi(a.messages,n,s),f=l?{...a.messagesBySession,[l]:vi(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),n,s)}:a.messagesBySession;return{messages:c,messagesBySession:f}}),clearMessages:n=>t(s=>{const i=n??s.sessionId??void 0;if(!i)return{messages:[],currentText:""};const{[i]:a,...l}=s.messagesBySession,{[i]:c,...f}=s.contextUsageBySession,{[i]:h,...x}=s.runtimeProgressBySession,{[i]:m,...S}=s.nativeSubagentsBySession;return{messages:i===s.sessionId?[]:s.messages,messagesBySession:l,contextUsageBySession:f,runtimeProgressBySession:x,nativeSubagentsBySession:S,currentText:i===s.sessionId?"":s.currentText}}),setTodos:n=>t({todos:n}),setCronTasks:n=>t({cronTasks:n})}));function Ws(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function ia(){if(typeof window>"u")return null;const t=window.agentApi;return typeof(t==null?void 0:t.dictationStart)!="function"||typeof t.dictationStop!="function"||typeof t.onDictation!="function"||typeof t.onDictationError!="function"?null:t}function Bo(){return ia()!==null||Ws()!==null}function Do(t){var a,l;const r=ia();if(r){let c=!1,f=()=>{},h=()=>{};const x=()=>{var m;c||(c=!0,f(),h(),(m=t.onEnd)==null||m.call(t))};return f=r.onDictation(({text:m,isFinal:S})=>{const I=m.trim();I&&(S?(t.onFinal(I),x()):t.onInterim(I))}),h=r.onDictationError(m=>{var S;(S=t.onError)==null||S.call(t,m),x()}),r.dictationStart().then(m=>{var S;m.ok||((S=t.onError)==null||S.call(t,m.reason||"无法启动语音识别"),x())}).catch(()=>{var m;(m=t.onError)==null||m.call(t,"无法启动语音识别"),x()}),{stop:()=>{r.dictationStop()}}}const n=Ws();if(!n)return(a=t.onError)==null||a.call(t,"当前环境不支持语音识别"),null;const s=new n;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let i="";s.onresult=c=>{let f="";for(let h=c.resultIndex;h<c.results.length;h++){const x=c.results[h];x.isFinal?i+=x[0].transcript:f+=x[0].transcript}f&&t.onInterim(i+f)},s.onerror=c=>{var f;c.error!=="no-speech"&&c.error!=="aborted"&&((f=t.onError)==null||f.call(t,`语音识别失败:${c.error??"未知错误"}`))},s.onend=()=>{var c;i&&t.onFinal(i.trim()),(c=t.onEnd)==null||c.call(t)};try{s.start()}catch{return(l=t.onEnd)==null||l.call(t),null}return{stop:()=>s.stop()}}function Fo(t){var l;const r=Ws();if(!r)return(l=t.onError)==null||l.call(t,"当前环境不支持语音唤醒"),null;let n=!1,s=null,i=null;const a=()=>{if(!n){s=new r,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=c=>{var x,m,S;const f=c.results[c.results.length-1],h=(m=(x=f==null?void 0:f[0])==null?void 0:x.transcript)==null?void 0:m.trim();h&&(f.isFinal&&((S=t.onHeard)==null||S.call(t,h)),h.includes(t.wakeWord)&&t.onWake(h))},s.onerror=c=>{var f;c.error==="not-allowed"&&((f=t.onError)==null||f.call(t,"麦克风权限被拒绝,语音唤醒已停用"),n=!0)},s.onend=()=>{n||(i=setTimeout(a,400))};try{s.start()}catch{i=setTimeout(a,800)}}};return a(),{stop:()=>{n=!0,i&&clearTimeout(i);try{s==null||s.abort()}catch{}}}}function br(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function Pr(t,r){return r(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const $o={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function Oo(t){const r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(r.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const n=new Float32Array(r.byteLength/2),s=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let i=0;i<n.length;i+=1)n[i]=s.getInt16(i*2,!0)/32768;return n}class Uo{constructor(r,n=$o){this.api=r,this.dependencies=n,this.context=null,this.node=null,this.ready=null,this.current=null}start(r){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const n={metadata:r,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=n,this.ensureReady().then(()=>{if(!(this.current!==n||!this.node)){this.node.port.postMessage({type:"start",generation:r.generation,sampleRate:r.sampleRate});for(const i of n.pending)this.postSamples(r.generation,i);n.pending=[],n.pendingSamples=0,n.finished&&this.node.port.postMessage({type:"finish",generation:r.generation})}}).catch(i=>this.fail(n,i))}enqueue(r,n){const s=this.current;if(!s||s.metadata.generation!==r||s.acknowledged)return;let i;try{i=Oo(n)}catch(a){this.fail(s,a);return}if(this.node){this.postSamples(r,i);return}if(s.pendingSamples+i.length>s.metadata.sampleRate){this.fail(s,new Error("TTS PCM queue overflow"));return}s.pending.push(i),s.pendingSamples+=i.length}finish(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||(n.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:r}))}flush(r){var s;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:r}),n.pending=[],n.pendingSamples=0,this.acknowledge(n))}dispose(){var r,n;this.current&&this.flush(this.current.metadata.generation),(r=this.node)==null||r.disconnect(),this.node=null,(n=this.context)==null||n.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const r=this.dependencies.createContext();this.context=r,await r.audioWorklet.addModule(this.dependencies.workletUrl);const n=this.dependencies.createNode(r);n.port.onmessage=s=>this.onWorkletMessage(s.data),n.connect(r.destination),this.node=n,r.state!=="running"&&await r.resume()})(),this.ready)}postSamples(r,n){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:r,samples:n},[n.buffer])}onWorkletMessage(r){const n=this.current;if(!(!n||r.generation!==n.metadata.generation)){if(r.type==="drained"||r.type==="stopped"){this.acknowledge(n);return}r.type==="overflow"&&this.fail(n,new Error("TTS AudioWorklet buffer overflow"))}}fail(r,n){this.current!==r||r.acknowledged||(console.error("[tts] PCM playback failed",n),r.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(r.metadata.generation))}acknowledge(r){this.current!==r||r.acknowledged||(r.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(r.metadata.generation))}}function as(t){var x;const r=(t==null?void 0:t.messages)??[],n=(t==null?void 0:t.events)??[],s=new Set(n.filter(m=>m.type==="approval_resolved"&&m.questionId).map(m=>m.questionId)),i=new Map;for(const m of n)m.type==="tool_result"&&((x=m.result)!=null&&x.toolCallId)&&i.set(m.result.toolCallId,{content:m.result.content??"",isError:m.result.isError});const a=r.filter(m=>(m.role==="user"||m.role==="assistant"||m.role==="tool")&&m.name!=="__interrupt__").map(Qo),l=new Map;for(const m of a)m.role==="tool"&&m.toolCallId&&l.set(m.toolCallId,m);let c=a.filter(m=>m.role!=="tool").map(m=>{var S;return m.isCompactionSummary?m:m.role==="assistant"&&((S=m.toolCalls)!=null&&S.length)?{...m,toolCalls:m.toolCalls.map(I=>{const N=l.get(I.id);if(N)return{...I,result:N.content};const O=i.get(I.id);return O?{...I,result:O.content,isError:O.isError}:I})}:m.role==="user"&&m.name&&m.name!=="__compaction_checkpoint__"&&!m.name.startsWith("__native_")?{...m,agentName:m.name}:m});const f=Ko(n);if(!c.some(m=>m.role==="assistant"&&!m.isCompactionSummary)&&f){const m=c.findLastIndex(S=>S.role==="user"&&!S.isCompactionSummary);c=m>=0?[...c.slice(0,m+1),f,...c.slice(m+1)]:[...c,f]}const h=new Set(c.flatMap(m=>{var S;return(S=m.askUser)!=null&&S.questionId?[m.askUser.questionId]:[]}));for(const m of n)m.type!=="ask_user"||!m.questionId||s.has(m.questionId)||h.has(m.questionId)||(h.add(m.questionId),c.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:m.questionId,question:m.question??"",options:m.options,fields:m.fields,multiSelect:m.multiSelect},timestamp:Date.now()}));return c}function qo(t,r){if(r.length===0)return t;if(t.length===0)return r;const n=t.map(As),s=r.map(As),i=Math.max(0,t.length-r.length),a=Ho(t,r,i);let l={currentStart:i,length:0,distance:1/0};for(let x=0;x<n.length;x++)for(let m=0;m<s.length;m++){if(n[x]!==s[m])continue;const S=x-m;if(S<0)continue;let I=0;for(;x+I<n.length&&m+I<s.length&&n[x+I]===s[m+I];)I+=1;const N=Math.abs(S-i);(I>l.length||I===l.length&&N<l.distance)&&(l={currentStart:S,length:I,distance:N})}const c=a??(l.length>0?l.currentStart:i),f=r.map((x,m)=>{var N,O;const S=t[c+m];if(!S||!Vo(S,x,s[m]))return x;const I=(O=(N=x.presentation)==null?void 0:N.attachments)==null?void 0:O.some(K=>K.dataUrl);return{...x,id:S.id,timestamp:S.timestamp,images:I?void 0:x.images??S.images}}),h=t.filter(x=>x.isQueued);return[...t.slice(0,c).filter(x=>!x.isQueued),...f,...h]}function Ho(t,r,n){const s=r[0];if((s==null?void 0:s.role)!=="user")return null;const i=Hr(s);let a=null;for(let l=0;l<t.length;l+=1){if(t[l].role!=="user"||t[l].isQueued||Hr(t[l])!==i)continue;const c=Math.abs(l-n);(!a||c<a.distance)&&(a={start:l,distance:c})}return(a==null?void 0:a.start)??null}function Vo(t,r,n){return As(t)===n?!0:t.role==="user"&&r.role==="user"&&Hr(t)===Hr(r)}function Hr(t){var r;return JSON.stringify({role:t.role,content:t.content,name:(r=t.name)!=null&&r.startsWith("__native_")?void 0:t.name,agentName:t.agentName,isCompactionSummary:t.isCompactionSummary})}function As(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,name:t.name,agentName:t.agentName,presentation:t.role==="user"?void 0:t.presentation,isCompactionSummary:t.isCompactionSummary})}function Qo(t){var r;if(t.name==="__compaction_checkpoint__"){let n="";try{n=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:n,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(r=t.toolCalls)!=null&&r.length?t.toolCalls:void 0,toolCallId:t.toolCallId,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function Ko(t){var i;let r="";const n=[],s=new Map;for(const a of t){if(a.type==="text_chunk"&&a.text&&(r+=a.text),a.type==="tool_call"&&a.toolCall){const l={id:a.toolCall.id,name:a.toolCall.name,arguments:a.toolCall.arguments};n.push(l),s.set(l.id,l)}if(a.type==="tool_result"&&((i=a.result)!=null&&i.toolCallId)){const l=s.get(a.result.toolCallId);l&&(l.result=a.result.content??"",l.isError=a.result.isError)}}return!r.trim()&&n.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:n.length>0?n:void 0,timestamp:Date.now()}}class Go{constructor(){this.slot=null}prefetch(r,n,s){return this.getOrStart(r,n,s).promise}async consume(r,n,s){const i=this.getOrStart(r,n,s);try{return await i.promise}finally{this.slot===i&&(this.slot=null)}}invalidate(){this.slot=null}getOrStart(r,n,s){var l;if(((l=this.slot)==null?void 0:l.sessionId)===r&&this.slot.cursor===n)return this.slot;let i;try{i=s()}catch(c){i=Promise.reject(c)}const a={sessionId:r,cursor:n,promise:i};return this.slot=a,i.catch(()=>{this.slot===a&&(this.slot=null)}),a}}const Zo=/^(?:load failed|failed to fetch|network request failed|networkerror when attempting to fetch resource\.?|the network connection was lost\.?|fetch failed)$/i;function aa(t){return t instanceof Error&&t.name!=="AbortError"&&Zo.test(t.message.trim())}function Jo(t){return aa(t)?"网络连接中断,会话加载失败,请重新加载":t instanceof Error?t.message:"会话加载失败"}async function Yo(t,r={}){const n=Math.max(1,Math.floor(r.maxAttempts??4)),s=Math.max(0,r.baseDelayMs??500),i=r.sleep??(a=>new Promise(l=>{setTimeout(l,a)}));for(let a=1;a<=n;a+=1)try{return await t()}catch(l){if(a===n||!aa(l))throw l;await i(s*2**(a-1))}throw new Error("会话加载失败")}function Xo(t){return t==="customer-agent"||t==="claude-code"}function el(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),Object.assign(r.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(r);try{return r.focus(),r.select(),r.setSelectionRange(0,r.value.length),document.execCommand("copy")}catch{return!1}finally{r.remove()}}async function os(t){const r=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(r==null?void 0:r.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await r.writeText(t),!0}catch{}return el(t)}const tl="agentroam:draft:";function Vr(t){return`${tl}${t}`}function nl(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(Vr(t))??""}catch{return""}}function ls(t,r){if(!(!t||typeof window>"u"))try{r?window.localStorage.setItem(Vr(t),r):window.localStorage.removeItem(Vr(t))}catch{}}function rl(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(Vr(t))}catch{}}const sl="agent-webapp:artifact-open:v1";let ki=0;function Si(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function oa(t,r){const n=t.trim();if(!n||/[\0\r\n]/.test(n))return null;if(Si(n))return n;if(!r||!Si(r))return null;const s=n.replaceAll("\\","/").split("/").filter(a=>a&&a!==".");if(s.length===0||s.some(a=>a===".."))return null;const i=/^[A-Za-z]:[\\/]/.test(r)||r.startsWith("\\\\")?"\\":"/";return`${r.replace(/[\\/]+$/,"")}${i}${s.join(i)}`}function Tn(t,r=window){return r.parent===r?!1:(ki+=1,r.parent.postMessage({type:sl,requestId:ki,path:t},r.location.origin),!0)}function il(t){var r;return((r=[...t].reverse().find(n=>n.role==="user"&&!n.isQueued))==null?void 0:r.id)??null}function ds(t,r){const n=t.filter(a=>!a.isQueued),s=new Map(t.filter(a=>a.isQueued&&a.queueItemId).map(a=>[a.queueItemId,a])),i=r.filter(a=>a.kind==="message").map(a=>{var c,f;const l=s.get(a.id);return{...l??{},id:a.sourceMessageId||(l==null?void 0:l.id)||a.id,role:"user",content:a.objective,timestamp:(l==null?void 0:l.timestamp)??a.createdAt,agentName:(c=a.messagePayload)==null?void 0:c.agentName,images:(f=a.messagePayload)==null?void 0:f.images,isQueued:!0,queueItemId:a.id}});return[...n,...i]}function cs(t){return t.queued.filter(r=>r.kind==="message")}function Ci(t){var r;return{active:((r=t.active)==null?void 0:r.kind)==="message"?null:t.active,queued:t.queued.filter(n=>n.kind!=="message"),history:t.history.filter(n=>n.kind!=="message")}}function al(t,r,n){if(r===n)return t;const s=t.filter(h=>h.isQueued),i=s.findIndex(h=>h.id===r),a=s.findIndex(h=>h.id===n);if(i<0||a<0)return t;const l=[...s],[c]=l.splice(i,1);l.splice(a,0,c);let f=0;return t.map(h=>h.isQueued?l[f++]:h)}function ol(t,r){return((t==null?void 0:t.agentType)??r)!=="customer-agent"}function _s(t){return(t==null?void 0:t.agentType)!==void 0&&t.agentType!=="customer-agent"&&t.status==="running"}function ll(t){return _s(t)&&(t==null?void 0:t.occupancy)==="owned-externally"}function la(t){return _s(t)&&(t==null?void 0:t.occupancy)!=="owned-externally"}function dl(t,r){return r||la(t)}function cl(t,r,n){return!r||!t||t.agentType==="customer-agent"?!1:t.occupancy==="owned-externally"||n!==r}function Br(t,r){return t.find(n=>n.id===r)??null}const Qr=Ji((t,r)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(n,s)=>t(i=>{const a={...i,[n]:s};return a.isConfigured=!!(a.apiKey&&a.modelId),a}),loadFromSystem:async()=>{if(window.agentApi)try{const n=await window.agentApi.getSettings(),s=n.profiles??[],i=n.activeProfileId??"",a=Br(s,i);t({modelProvider:(a==null?void 0:a.provider)??n.modelProvider??"anthropic",modelId:(a==null?void 0:a.modelId)??n.modelId??"claude-sonnet-4-6",apiKey:(a==null?void 0:a.apiKey)??n.apiKey??"",baseUrl:(a==null?void 0:a.baseUrl)??n.baseUrl??"",maxIterations:n.maxIterations??10,contextWindow:n.contextWindow??100,workingDirectory:n.workingDirectory??"/",isConfigured:!!(((a==null?void 0:a.apiKey)??n.apiKey)&&((a==null?void 0:a.modelId)??n.modelId)),profiles:s,activeProfileId:i,reasoningEffort:["off","low","medium","high"].includes(n.reasoningEffort??"")?n.reasoningEffort:"off"})}catch(n){console.error("Failed to load settings:",n)}},saveToSystem:async()=>{if(!window.agentApi)return;const n=r();await window.agentApi.saveSettings({modelProvider:n.modelProvider,modelId:n.modelId,apiKey:n.apiKey,baseUrl:n.baseUrl,maxIterations:n.maxIterations,contextWindow:n.contextWindow,workingDirectory:n.workingDirectory,isConfigured:n.isConfigured,profiles:n.profiles,activeProfileId:n.activeProfileId,reasoningEffort:n.reasoningEffort})},addProfile:n=>{const i={id:crypto.randomUUID(),...n};t(a=>({profiles:[...a.profiles,i]}))},updateProfile:(n,s)=>{t(a=>({profiles:a.profiles.map(l=>l.id===n?{...l,...s}:l)}));const i=r();if(i.activeProfileId===n){const a=Br(i.profiles,n);a&&t({modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})}},deleteProfile:n=>{t(s=>{var c;const i=s.profiles.filter(f=>f.id!==n),a=s.activeProfileId===n?((c=i[0])==null?void 0:c.id)??"":s.activeProfileId,l=Br(i,a);return{profiles:i,activeProfileId:a,...l?{modelProvider:l.provider,modelId:l.modelId,apiKey:l.apiKey,baseUrl:l.baseUrl,isConfigured:!!(l.apiKey&&l.modelId)}:{},...l?{}:{modelProvider:"anthropic",modelId:"",apiKey:"",baseUrl:"",isConfigured:!1}}})},setActiveProfileLocal:n=>{const s=r(),i=Br(s.profiles,n);i&&t({activeProfileId:n,modelProvider:i.provider,modelId:i.modelId,apiKey:i.apiKey,baseUrl:i.baseUrl,isConfigured:!!(i.apiKey&&i.modelId)})},switchActiveProfile:async n=>{r().setActiveProfileLocal(n),window.agentApi&&await window.agentApi.setActiveProfile(n)}}));function Gn(t){return t.result!==void 0}function us(t){return t.every(Gn)}const Ls=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),da=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),ca=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]),ul=new Set(["Read","read_file"]),pl=new Set(["Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]);function Ps(t){return Ls.has(t)?"command":da.has(t)?"file":ca.has(t)?"search":"generic"}function Bs(t){switch(t){case"shell":case"bash":case"Bash":case"execute_command":case"run_command":return{done:"运行了命令",doing:"运行命令中"};case"BashOutput":case"KillShell":return{done:"查看了命令输出",doing:"查看输出中"};case"Read":case"read_file":return{done:"读取了文件",doing:"读取文件中"};case"Write":case"write_file":return{done:"写入了文件",doing:"写入文件中"};case"Edit":case"MultiEdit":case"str_replace":case"apply_patch":return{done:"修改了文件",doing:"修改文件中"};case"Glob":case"glob_search":return{done:"搜索了文件",doing:"搜索文件中"};case"Grep":case"grep_search":return{done:"搜索了内容",doing:"搜索内容中"};case"Skill":return{done:"调用了技能",doing:"调用技能中"};case"Task":return{done:"启动了子任务",doing:"启动子任务中"};case"WebSearch":return{done:"搜索了网络",doing:"搜索网络中"};case"WebFetch":return{done:"读取了网页",doing:"读取网页中"};case"TodoWrite":return{done:"更新了任务清单",doing:"更新任务清单中"};case"NotebookEdit":return{done:"编辑了 Notebook",doing:"编辑 Notebook 中"};default:return t.startsWith("mcp__")||t.includes(":")?{done:"调用了工具",doing:"调用工具中"}:null}}function gl(t){var r;return((r=Bs(t))==null?void 0:r.done)??null}function ua(t){return Ls.has(t)?"终端":ul.has(t)?"查阅":pl.has(t)?"写入":ca.has(t)?"查阅":t==="Skill"?"技能":t==="Task"||t==="dispatch_agent"||t==="Agent"?"子任务":t==="TodoWrite"?"任务":t.startsWith("mcp__")||t.includes(":")?"工具":null}function Ii(t){return t.replace(/\\/g,"/").split("/").pop()??t}function ps(t,r=60){const n=(t??"").split(`
235
- `)[0].trim();return n.length>r?n.slice(0,r)+"…":n}function fl(t,r){if(Ls.has(t))return ps(String(r.command??""));if(t==="apply_patch"){const s=(Array.isArray(r.changes)?r.changes:[]).map(i=>Ii(String((i==null?void 0:i.path)??""))).filter(Boolean);return s.length?s.length<=3?s.join("、"):`${s.slice(0,3).join("、")} 等 ${s.length} 个文件`:null}return da.has(t)?r.file_path?Ii(String(r.file_path)):null:t==="Glob"||t==="glob_search"?String(r.pattern??"")||null:t==="Grep"||t==="grep_search"?String(r.pattern??r.query??"")||null:t==="Skill"?String(r.skill??"")||null:t==="Task"?ps(String(r.description??r.task??""),80)||null:t==="WebSearch"?ps(String(r.query??"")):t==="WebFetch"?String(r.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function hl(t,r){return Math.max(0,Math.floor((r-t)/1e3))}function Ds({startedAt:t}){const[r,n]=u.useState(()=>Date.now());return u.useEffect(()=>{n(Date.now());const s=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(s)},[t]),e.jsxs("span",{className:"activity-elapsed-time",children:[" · 持续了 ",hl(t,r)," 秒"]})}function pa({progress:t,compact:r=!1,startedAt:n}){const s=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),i=[t.label,s].filter(Boolean).join(","),a=!r&&t.phase==="thinking",l=!r&&t.phase==="status",c=a&&n!==void 0&&s===void 0;return e.jsxs("div",{className:`runtime-progress-row${r?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":i,children:[a?e.jsx("span",{className:"runtime-progress-row__brain","aria-hidden":"true",children:e.jsx(Es,{size:17,strokeWidth:1.8})}):l?e.jsx("span",{className:"runtime-progress-row__status-icon","aria-hidden":"true",children:e.jsx(Kn,{size:17,strokeWidth:1.8})}):e.jsx("span",{className:"runtime-progress-row__spinner","aria-hidden":"true"}),e.jsx("span",{className:"runtime-progress-row__label",children:t.label}),s&&e.jsx("span",{className:"runtime-progress-row__detail",children:s}),c&&e.jsx(Ds,{startedAt:n})]})}function Zn({isDone:t,isError:r,color:n,size:s=11}){return t?r?e.jsx(lo,{size:s,color:n,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Or,{size:s,color:n,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Kn,{size:s,color:n,strokeWidth:2.5,style:{animation:"spin 1s linear infinite",flexShrink:0},"aria-hidden":"true"})}function kr({name:t,color:r,size:n=14}){const s=Ps(t);return s==="command"?e.jsx(Ro,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):s==="search"?e.jsx(ta,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):s==="file"?t==="Read"||t==="read_file"?e.jsx(zs,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Xi,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="Skill"?e.jsx(To,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="TodoWrite"?e.jsx(ko,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="Task"||t==="dispatch_agent"||t==="Agent"?e.jsx(No,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(na,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"})}function Kr({statusColor:t,isDone:r,expanded:n,onToggle:s,header:i,children:a,maxBodyHeight:l=600,primaryAction:c,primaryActionLabel:f,primaryActionTitle:h}){const x=e.jsxs("button",{type:"button",className:"tool-call-shell__header",...c?{onClick:c,"aria-label":f,title:h}:{onClick:s,"aria-expanded":n},style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:m=>m.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:m=>m.currentTarget.style.background="var(--bg-deep)",children:[i,!c&&e.jsx(Qn,{className:"tool-call-shell__chevron",size:12,color:"var(--text-muted)",strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(90deg)":"rotate(0deg)",flexShrink:0},"aria-hidden":"true"})]});return e.jsxs("div",{className:"tool-call-shell",style:{marginTop:4,borderRadius:9,border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-deepest)",fontSize:12,minWidth:0},children:[e.jsxs("div",{className:"tool-call-shell__row",style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{className:"tool-call-shell__status",style:{width:3,flexShrink:0,background:t,animation:r?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),x,c&&e.jsx("button",{type:"button",className:"tool-call-shell__disclosure",onClick:s,"aria-expanded":n,"aria-label":n?"收起工具详情":"展开工具详情",title:n?"收起工具详情":"展开工具详情",children:e.jsx(Qn,{className:"tool-call-shell__chevron",size:12,strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(90deg)":"rotate(0deg)"},"aria-hidden":"true"})})]}),n&&e.jsx("div",{className:"tool-call-shell__body",style:{overflow:"hidden",maxHeight:l,opacity:1,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{className:"tool-call-shell__body-content",style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:a})})]})}function jr({label:t,color:r="var(--text-muted)",bg:n="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:n,color:r,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function an(t){return t.replace(/\\/g,"/").split("/").pop()??t}function ga(t){return t?t.split(`
236
- `).length:0}function fa(t,r){const n=t.split(`
237
- `),s=r.split(`
238
- `);if(n.length*s.length>2e5)return s.map((I,N)=>({type:"added",text:I,lineNo:N+1}));const i=n.length,a=s.length,l=Array.from({length:i+1},()=>new Array(a+1).fill(0));for(let I=1;I<=i;I++)for(let N=1;N<=a;N++)l[I][N]=n[I-1]===s[N-1]?l[I-1][N-1]+1:Math.max(l[I-1][N],l[I][N-1]);const c=[];let f=i,h=a;for(;f>0&&h>0;)n[f-1]===s[h-1]?(c.unshift([f-1,h-1]),f--,h--):l[f-1][h]>=l[f][h-1]?f--:h--;const x=[];let m=0,S=0;for(const[I,N]of c){for(;m<I;)x.push({type:"removed",text:n[m],lineNo:m+1}),m++;for(;S<N;)x.push({type:"added",text:s[S],lineNo:S+1}),S++;x.push({type:"same",text:n[m],lineNo:m+1}),m++,S++}for(;m<i;)x.push({type:"removed",text:n[m],lineNo:m+1}),m++;for(;S<a;)x.push({type:"added",text:s[S],lineNo:S+1}),S++;return x}function ha({content:t,maxHeight:r=320}){const n=t.split(`
239
- `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:n.map((s,i)=>e.jsxs("tr",{children:[e.jsx("td",{style:{padding:"0 8px",color:"var(--text-muted)",textAlign:"right",userSelect:"none",borderRight:"1px solid var(--border-subtle)",background:"var(--bg-deep)",fontSize:10,minWidth:36},children:i+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:s||" "})]},i))})]})})}function xa({diff:t,maxHeight:r=360}){if(t.filter(c=>c.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const s=new Set(t.map((c,f)=>c.type!=="same"?f:-1).filter(c=>c>=0)),i=new Set;s.forEach(c=>{for(let f=Math.max(0,c-3);f<=Math.min(t.length-1,c+3);f++)i.add(f)});const a=[];let l=-1;return[...i].sort((c,f)=>c-f).forEach(c=>{l>=0&&c>l+1&&a.push("ellipsis"),a.push({diffLine:t[c],diffIdx:c}),l=c}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:a.map((c,f)=>{if(c==="ellipsis")return e.jsx("tr",{children:e.jsx("td",{colSpan:3,style:{padding:"2px 12px",color:"var(--text-muted)",fontSize:10,background:"var(--bg-deep)",textAlign:"center"},children:"⋯"})},`e${f}`);const{diffLine:h}=c,x=h.type==="added"?"rgba(5,150,105,0.08)":h.type==="removed"?"rgba(220,38,38,0.07)":"transparent",m=h.type==="added"?"+":h.type==="removed"?"−":" ",S=h.type==="added"?"var(--success)":h.type==="removed"?"var(--danger)":"transparent",I=h.type==="added"?"#059669":h.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:x},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:S,fontWeight:700,userSelect:"none"},children:m}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:h.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:I,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:h.text||" "})]},f)})})]})})}function xl({toolCall:t,beforeContent:r,previewPath:n}){const[s,i]=u.useState(!1),[a,l]=u.useState("content"),c=t.arguments.file_path??"",f=t.arguments.content??"",h=ga(f),x=t.isError,m=Gn(t),S=m?x?"var(--danger)":"var(--success)":"var(--accent)",I=u.useMemo(()=>r&&f?fa(r,f):null,[r,f]),N=u.useMemo(()=>I?{added:I.filter(U=>U.type==="added").length,removed:I.filter(U=>U.type==="removed").length}:null,[I]),O=x?"var(--danger)":m?"var(--text-muted)":"var(--accent)",K=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(kr,{name:t.name,color:O})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:c,children:an(c)}),e.jsx(jr,{label:`${h} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),N&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[N.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",N.added]}),N.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",N.removed]})]}),(!m||x)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:S},children:[e.jsx(Zn,{isDone:m,isError:x,color:S}),x&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Kr,{statusColor:S,isDone:m,expanded:s,onToggle:()=>i(!s),header:K,primaryAction:n?()=>Tn(n):void 0,primaryActionLabel:n?`预览文件 ${an(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:c}),I&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(U=>e.jsx("button",{onClick:()=>l(U),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:a===U?"var(--accent-dim)":"transparent",color:a===U?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:U==="content"?"文件内容":"变更行"},U))}),a==="diff"&&I?e.jsx(xa,{diff:I}):e.jsx(ha,{content:f}),x&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function ml({toolCall:t,previewPath:r}){const[n,s]=u.useState(!1),i=t.arguments.file_path??"",a=t.arguments.startLine,l=t.arguments.endLine,c=t.arguments.offset,f=t.arguments.limit,h=t.result??"",x=ga(h),m=t.isError,S=Gn(t),I=S?m?"var(--danger)":"var(--success)":"var(--accent)",N=a!==void 0?`L${a}–${l??"?"}`:c!==void 0?`第${c}行起${f?` ×${f}`:""}`:null,O=m?"var(--danger)":S?"var(--text-muted)":"var(--accent)",K=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(kr,{name:t.name,color:O})}),e.jsx("span",{className:"tool-call-shell__label",children:"查阅"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:i,children:an(i)}),N&&e.jsx(jr,{label:N,color:"var(--accent)",bg:"var(--accent-dim)"}),S&&!m&&e.jsx(jr,{label:`${x} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),(!S||m)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:I},children:[e.jsx(Zn,{isDone:S,isError:m,color:I}),m&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Kr,{statusColor:I,isDone:S,expanded:n,onToggle:()=>s(!n),header:K,maxBodyHeight:480,primaryAction:r?()=>Tn(r):void 0,primaryActionLabel:r?`预览文件 ${an(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:i}),S&&!m?e.jsx(ha,{content:h}):S&&m&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:h})]})}function bl({toolCall:t,previewPath:r}){const[n,s]=u.useState(!1),i=t.arguments.file_path??"",a=t.arguments.old_string??"",l=t.arguments.new_string??"",c=t.isError,f=Gn(t),h=f?c?"var(--danger)":"var(--success)":"var(--accent)",x=c?"var(--danger)":f?"var(--text-muted)":"var(--accent)",m=u.useMemo(()=>a&&l?fa(a,l):null,[a,l]),S=u.useMemo(()=>m?{added:m.filter(N=>N.type==="added").length,removed:m.filter(N=>N.type==="removed").length}:null,[m]),I=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(kr,{name:t.name,color:x})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:i,children:an(i)}),S&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[S.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",S.added]}),S.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",S.removed]})]}),(!f||c)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:h},children:[e.jsx(Zn,{isDone:f,isError:c,color:h}),c&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Kr,{statusColor:h,isDone:f,expanded:n,onToggle:()=>s(!n),header:I,maxBodyHeight:480,primaryAction:r?()=>Tn(r):void 0,primaryActionLabel:r?`预览文件 ${an(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:i}),m?e.jsx(xa,{diff:m}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a}),e.jsx("pre",{style:{fontSize:11,color:"var(--success)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(5,150,105,0.04)",border:"1px solid rgba(5,150,105,0.12)",borderLeft:"3px solid var(--success)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:l})]}),c&&t.result&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:t.result})]})}function Vn({label:t,content:r,error:n,maxPreviewLines:s=8,maxPreviewHeight:i=200,maxExpandedHeight:a=2e3}){const[l,c]=u.useState(!1),f=r.split(`
240
- `),h=f.length>s,x=h&&!l?f.slice(0,s).join(`
241
- `)+`
242
- ...`:r;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:n?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:n?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:n?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:n?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:l?a:i,overflow:"auto",margin:0,lineHeight:1.6},children:x}),h&&e.jsx("button",{onClick:()=>c(!l),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:l?"收起":`展开全部 (${f.length} 行)`})]})}function yl({arguments:t}){var n;const r=t.task??"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 0"},children:[e.jsxs("div",{style:{display:"flex",gap:8,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",flexWrap:"wrap"},children:[e.jsx(jr,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(jr,{label:`sid: ${(n=t.subSessionId)==null?void 0:n.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),r&&e.jsx(Vn,{label:"任务",content:r,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function vl({raw:t}){const[r,n]=u.useState(!1);let s;try{const f=JSON.parse(t);delete f.subAgentProgress,delete f.subAgentStatus,delete f.subAgentDetail,s=JSON.stringify(f,null,2)}catch{s=t}const i=8,a=s.split(`
243
- `),l=a.length>i,c=l&&!r?a.slice(0,i).join(`
244
- `)+`
245
- ...`:s;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"参数"}),e.jsx("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",maxHeight:r?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:c}),l&&e.jsx("button",{onClick:()=>n(!r),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:r?"收起":`展开全部 (${a.length} 行)`})]})}function wl({activity:t,workspacePath:r,enableFilePreview:n}){const s=new Map(t.messages.flatMap(i=>i.role==="tool"&&i.toolCallId?[[i.toolCallId,{content:i.content,isError:i.name==="error"}]]:[]));return e.jsxs("div",{className:"native-subagent-activity",children:[e.jsxs("div",{className:"native-subagent-activity__meta",children:[t.elapsedSeconds!==void 0&&e.jsxs("span",{children:[t.elapsedSeconds," 秒"]}),t.toolUses!==void 0&&e.jsxs("span",{children:[t.toolUses," 次工具调用"]}),t.lastToolName&&e.jsxs("span",{children:["正在使用 ",t.lastToolName]})]}),t.messages.map((i,a)=>{var l;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[i.role==="assistant"&&i.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:i.content}),i.role==="assistant"&&((l=i.toolCalls)==null?void 0:l.map(c=>{const f=s.get(c.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(Fs,{toolCall:{...c,...f?{result:f.content,isError:f.isError}:{}},workspacePath:r,enableFilePreview:n}),f&&e.jsx("pre",{className:`native-subagent-activity__tool-result${f.isError?" native-subagent-activity__tool-result--error":""}`,children:f.content})]},c.id)})),i.role==="tool"&&i.toolCallId&&!t.messages.some(c=>{var f;return(f=c.toolCalls)==null?void 0:f.some(h=>h.id===i.toolCallId)})&&e.jsx(Vn,{label:"工具结果",content:i.content,error:i.name==="error",maxPreviewHeight:180})]},`${i.role}-${a}`)}),t.summary&&e.jsx(Vn,{label:t.status==="failed"?"错误信息":"执行摘要",content:t.summary,error:t.status==="failed",maxPreviewHeight:180}),t.status==="running"&&t.messages.length===0&&!t.summary&&e.jsxs("div",{className:"native-subagent-activity__waiting",children:[e.jsx(Zn,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function jl({toolCall:t,onSelectSession:r,nativeSubagent:n,previewPaths:s,workspacePath:i,enableFilePreview:a}){const l=ge(_=>_.runningSessionId),[c,f]=u.useState(()=>!!n),h=t.name==="dispatch_agent",x=t.name==="Agent"&&!!n,m=t.arguments.subAgentStatus,S=t.arguments.subAgentDetail,I=t.arguments.subAgentProgress,N=Gn(t);u.useEffect(()=>{h&&!m&&I&&f(!0),x&&(n.messages.length>0||n.summary)&&f(!0)},[h,x,n,m,I]);const O=h?m==="failed":x?n.status==="failed":t.isError,K=h?!!m||N&&!l:x?n.status!=="running":N,U=K?O?"var(--danger)":"var(--success)":"var(--accent)",y=O?"var(--danger)":K?"var(--text-muted)":"var(--accent)",v=h?null:Bs(t.name),B=O?"错误":v?"":x?n.status==="stopped"?"已停止":K?"已完成":"运行中":h?m==="failed"?"失败":K?"已完成":"运行中":K?"完成":"执行中",H=x?n.description:h?(()=>{const ne=(t.arguments.task??"").split(`
246
- `)[0];return ne.length>80?ne.slice(0,80)+"…":ne})():fl(t.name,t.arguments),A=x?`@${n.agentName??"agent"}`:h?`@${t.arguments.agentName??"agent"}`:ua(t.name)??t.name,C=Ps(t.name),E=!K||!!O||!!B,M=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(kr,{name:t.name,color:y})}),e.jsx("span",{className:"tool-call-shell__label",title:v?t.name:void 0,style:{fontFamily:v?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:A}),H&&e.jsx("span",{className:"tool-call-shell__preview",style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:H}),!H&&e.jsx("span",{style:{flex:1}}),E&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:U},children:[e.jsx(Zn,{isDone:K,isError:!!O,color:U}),B&&e.jsx("span",{children:B})]})]});return e.jsxs(Kr,{statusColor:U,isDone:K,expanded:c,onToggle:()=>f(!c),header:M,maxBodyHeight:800,primaryAction:s.length===1?()=>Tn(s[0]):void 0,primaryActionLabel:s.length===1?`预览文件 ${an(s[0])}`:void 0,primaryActionTitle:s.length===1?`预览 ${s[0]}`:void 0,children:[x?e.jsx(wl,{activity:n,workspacePath:i,enableFilePreview:a}):h?e.jsx(yl,{arguments:t.arguments}):C==="command"&&typeof t.arguments.command=="string"?e.jsxs(e.Fragment,{children:[typeof t.arguments.cwd=="string"&&t.arguments.cwd&&e.jsxs("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:["工作目录 ",t.arguments.cwd]}),e.jsx(Vn,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(vl,{raw:JSON.stringify(t.arguments,null,2)}),s.length>1&&e.jsx("div",{className:"tool-call-file-list","aria-label":"改动文件",children:s.map(_=>e.jsx("button",{type:"button",onClick:()=>Tn(_),title:_,children:e.jsx("span",{children:an(_)})},_))}),t.result&&!h&&!x&&e.jsx(Vn,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),h&&m&&S&&e.jsx(Vn,{label:m==="failed"?"错误信息":"执行摘要",content:S,error:m==="failed",maxPreviewHeight:180}),h&&!m&&I&&(!!l||!N)&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"实时输出"}),e.jsxs("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderLeft:"3px solid var(--accent)",maxHeight:240,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:[I,e.jsx("span",{style:{display:"inline-block",width:"0.5em",height:"1em",background:"var(--accent)",verticalAlign:"text-bottom",animation:"blink 1s step-end infinite"},children:"​"})]})]}),h&&!m&&!I&&!!l&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 0",fontSize:11,color:"var(--text-muted)",fontStyle:"italic"},children:[[0,1,2].map(_=>e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--accent)",display:"inline-block",animation:"wave 1.1s ease-in-out infinite",animationDelay:`${_*.16}s`}},_)),"等待子 agent 响应..."]}),h&&t.arguments.subSessionId&&r&&e.jsxs("button",{onClick:()=>r(t.arguments.subSessionId),style:{alignSelf:"flex-start",padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--accent-dim)",color:"var(--accent)",fontSize:11,fontWeight:500,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s"},onMouseEnter:_=>{_.currentTarget.style.background="var(--accent)",_.currentTarget.style.color="white"},onMouseLeave:_=>{_.currentTarget.style.background="var(--accent-dim)",_.currentTarget.style.color="var(--accent)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 2a5 5 0 1 0 0 10A5 5 0 0 0 12 2z"}),e.jsx("path",{d:"M12 12c-5.33 0-8 2.67-8 4v2h16v-2c0-1.33-2.67-4-8-4z"})]}),"查看子会话"]})]})}function kl({items:t,onSelectSession:r,workspacePath:n,enableFilePreview:s}){var I;const[i,a]=u.useState(!1),l=(I=t[0])==null?void 0:I.toolCall,c=l?Bs(l.name):null;if(!l||!c||t.length<2)return null;const f=t.every(({toolCall:N})=>Gn(N)),h=t.filter(({toolCall:N})=>N.isError).length,x=h>0?"var(--danger)":f?"var(--text-muted)":"var(--accent)",m=ua(l.name)??c.done,S=`${m},${t.length} 项,${i?"收起":"展开"}`;return e.jsxs("div",{className:"tool-call-group",children:[e.jsxs("button",{type:"button",className:"tool-call-group__summary","aria-expanded":i,"aria-label":S,onClick:()=>a(N=>!N),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(kr,{name:l.name,color:x})}),e.jsx("span",{className:"tool-call-group__label",children:m}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),h>0&&e.jsxs("span",{className:"tool-call-group__error",children:[h," 项失败"]}),!f&&e.jsx(Zn,{isDone:!1,color:x,size:11}),e.jsx(Qn,{className:"tool-call-group__chevron",size:13,strokeWidth:2.2,"aria-hidden":"true"})]}),i&&e.jsx("div",{className:"tool-call-group__items",children:t.map(({toolCall:N,beforeContent:O,progress:K,nativeSubagent:U})=>e.jsx(Fs,{toolCall:N,beforeContent:O,progress:K,nativeSubagent:U,onSelectSession:r,workspacePath:n,enableFilePreview:s},N.id))})]})}function Sl(t,r){if(Ps(t.name)!=="file")return[];const n=t.name==="apply_patch"&&Array.isArray(t.arguments.changes)?t.arguments.changes.map(s=>s.path):[t.arguments.file_path??t.arguments.path??t.arguments.notebook_path];return[...new Set(n.filter(s=>typeof s=="string").map(s=>oa(s,r)).filter(s=>!!s))]}function Fs({toolCall:t,onSelectSession:r,beforeContent:n,progress:s,nativeSubagent:i,workspacePath:a,enableFilePreview:l=!1}){const c=l?Sl(t,a):[],f=t.name==="write_file"?e.jsx(xl,{toolCall:t,beforeContent:n,previewPath:c[0]}):t.name==="read_file"?e.jsx(ml,{toolCall:t,previewPath:c[0]}):t.name==="str_replace"?e.jsx(bl,{toolCall:t,previewPath:c[0]}):e.jsx(jl,{toolCall:t,onSelectSession:r,nativeSubagent:i,previewPaths:c,workspacePath:a,enableFilePreview:l});return e.jsxs("div",{className:"tool-call-with-progress",children:[f,s&&e.jsx(pa,{progress:s,compact:!0})]})}function Cl({question:t,options:r,fields:n,multiSelect:s,answered:i,answer:a,onAnswer:l}){const[c,f]=u.useState(new Set),[h,x]=u.useState(""),[m,S]=u.useState({}),I=!!(r!=null&&r.length),N=!!(n!=null&&n.length),O=v=>{i||f(B=>{const H=new Set(B);return s?H.has(v)?H.delete(v):H.add(v):(H.clear(),H.add(v)),H})},K=()=>{if(c.size===0)return;const v=Array.from(c).map(B=>r[B].label);l(v.join(", "),Array.from(c))},U=()=>{const v=Array.from(c).map(H=>r[H].label),B=Object.fromEntries((n??[]).map(H=>{var A;return[H.name,((A=m[H.name])==null?void 0:A.trim())??""]}));!B.model&&v.length>0&&(B.model=v[0]),!(!Object.values(B).some(Boolean)&&v.length===0)&&l(JSON.stringify({fields:B,selectedOptions:v}),Array.from(c))},y=()=>{h.trim()&&l(h.trim())};return e.jsx("div",{style:{marginBottom:12},children:e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:i?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:i?"var(--bg-deep)":"linear-gradient(135deg, rgba(79,110,247,0.04) 0%, var(--bg-deep) 100%)",overflow:"hidden",transition:"border-color 0.2s ease"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",borderBottom:i?"1px solid var(--border-subtle)":"1px solid rgba(79,110,247,0.15)"},children:[e.jsx("div",{style:{width:24,height:24,borderRadius:6,background:i?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:i?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),e.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:i?"var(--text-muted)":"var(--accent)",flex:1},children:i?"已回答":"向你提问"}),s&&!i&&e.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:10,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:500},children:"可多选"})]}),e.jsx("div",{style:{padding:"12px 14px 8px",fontSize:13,color:"var(--text-primary)",lineHeight:1.6,fontWeight:500,whiteSpace:"pre-wrap"},children:t}),i&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),N?"配置已提交(敏感字段已隐藏)":a]}),I&&!i&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[r.map((v,B)=>{const H=c.has(B);return e.jsxs("button",{onClick:()=>O(B),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:H?"var(--accent)":"var(--border-subtle)",background:H?"rgba(79,110,247,0.06)":"var(--bg-surface)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-body)",transition:"all 0.15s ease",width:"100%"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:s?4:8,border:`2px solid ${H?"var(--accent)":"var(--border-subtle)"}`,background:H?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:H&&e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:H?600:500,color:H?"var(--text-primary)":"var(--text-secondary)"},children:v.label}),v.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:v.description})]})]},B)}),!N&&e.jsx("button",{onClick:K,disabled:c.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:c.size>0?"var(--accent)":"var(--bg-surface)",color:c.size>0?"white":"var(--text-muted)",cursor:c.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),N&&!i&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[n.map(v=>e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:"var(--text-secondary)"},children:v.label}),e.jsx("input",{type:v.type==="secret"?"password":"text",value:m[v.name]??"",onChange:B=>S(H=>({...H,[v.name]:B.target.value})),placeholder:v.description,autoComplete:v.type==="secret"?"off":void 0,style:{padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none"}}),v.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:v.description})]},v.name)),e.jsx("button",{onClick:U,style:{padding:"8px 16px",borderRadius:8,border:"none",background:"var(--accent)",color:"white",cursor:"pointer",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end"},children:"确认配置"})]}),!i&&!N&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:I?"1px solid var(--border-subtle)":"none",marginTop:I?2:0},children:[e.jsx("input",{type:"text",value:h,onChange:v=>x(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),y())},placeholder:I?"或输入自定义回答…":"输入你的回答…",style:{flex:1,padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",transition:"border-color 0.15s ease"},onFocus:v=>{v.currentTarget.style.borderColor="var(--accent)"},onBlur:v=>{v.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:y,disabled:!h.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:h.trim()?"var(--accent)":"var(--bg-surface)",color:h.trim()?"white":"var(--text-muted)",cursor:h.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})})}const gs={systemBase:{label:"系统基础提示",group:"system"},environment:{label:"运行环境",group:"system"},projectContext:{label:"项目上下文",group:"system"},skills:{label:"技能指令",group:"system"},memory:{label:"Memory",group:"system"},embeddedTools:{label:"系统内嵌工具定义",group:"system"},conversationHistory:{label:"历史用户消息",group:"messages"},currentUserMessage:{label:"当前用户消息",group:"messages"},assistantMessages:{label:"AI 历史回复",group:"messages"},compactionSummary:{label:"上下文压缩摘要",group:"messages"},toolCalls:{label:"工具调用",group:"tools"},toolResults:{label:"工具结果",group:"tools"},nativeToolDefinitions:{label:"原生工具定义",group:"tools"},images:{label:"图片",group:"images"},messageOverhead:{label:"协议与消息开销",group:"overhead"}},fs={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},Ai=["system","messages","tools","images","overhead"];function Il(t,r){const n=(t==null?void 0:t.maxTokens)??Math.max(1,r*1e3),s=(t==null?void 0:t.totalTokens)??0,i=Object.fromEntries(Ai.map(l=>[l,0]));for(const l of(t==null?void 0:t.segments)??[]){const c=gs[l.category];c&&(i[c.group]+=l.tokens)}const a=Math.min(s/n,1);return{hasUsage:!!t,totalTokens:s,maxTokens:n,ratio:a,percent:Math.round(a*100),groups:Ai.map(l=>({key:l,label:fs[l].label,color:fs[l].color,tokens:i[l]})),details:((t==null?void 0:t.segments)??[]).filter(l=>l.tokens>0).map(l=>{var c,f;return{category:l.category,label:((c=gs[l.category])==null?void 0:c.label)??l.category,color:fs[((f=gs[l.category])==null?void 0:f.group)??"overhead"].color,tokens:l.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function Ts(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function Ti(t,r){return r?`${t.percent}%`:t.hasUsage?`${Ts(t.totalTokens)} / ${Ts(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Al({usage:t,contextWindowK:r,compact:n=!1}){const[s,i]=u.useState(!1),[a,l]=u.useState(null),c=u.useRef(null),f=u.useMemo(()=>Il(t,r),[t,r]),h=f.ratio>=.85?"var(--danger)":f.ratio>=.6?"#f59e0b":"var(--accent)",x=typeof window>"u"?1024:window.innerWidth;return e.jsxs("div",{className:"context-usage-ribbon",style:{position:"relative",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("button",{className:"context-usage-ribbon__button",ref:c,type:"button",onClick:()=>{var S;const m=((S=c.current)==null?void 0:S.getBoundingClientRect())??null;l(m),i(I=>!I)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:n?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"context-usage-ribbon__ring",width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:"currentColor",strokeWidth:"4",opacity:"0.14"}),e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:f.hasUsage?h:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${f.ratio*62.832} 62.832`,transform:"rotate(-90 14 14)"})]}),e.jsx("span",{className:"context-usage-ribbon__summary context-usage-ribbon__summary--compact",children:Ti(f,!0)})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"context-usage-ribbon__label",style:{fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap"},children:"上下文"}),e.jsx("div",{className:"context-usage-ribbon__meter",style:{flex:1,height:6,borderRadius:999,overflow:"hidden",background:"rgba(0,0,0,0.06)",display:"flex"},children:f.groups.map(m=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(m.tokens/f.maxTokens*100,100))}%`,background:m.color,opacity:m.key==="overhead"?.65:1,minWidth:m.tokens>0?1:0}},m.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:f.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:Ti(f,!1)})]})}),s&&a&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>i(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:n?Math.min(Math.max(8,a.left),Math.max(8,x-Math.min(340,x-16)-8)):Math.max(8,a.left),top:a.top-8,transform:"translateY(-100%)",width:Math.min(n?340:a.width,x-16),maxHeight:"min(520px, calc(100vh - 32px))",overflowY:"auto",zIndex:9999,padding:12,borderRadius:12,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-lg)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)"},children:"完整请求上下文估算"}),e.jsx("div",{style:{fontSize:11,color:f.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:f.hasUsage?`${f.percent}%`:"暂无"})]}),f.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:f.requestLabel}),f.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:f.details.map(m=>{const S=f.totalTokens>0?Math.round(m.tokens/f.totalTokens*100):0;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:m.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:m.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[Ts(m.tokens)," · ",S,"%"]})]},m.category)})}):e.jsx("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:"发送第一条消息后,将显示最新一次模型请求的完整上下文组成。"}),e.jsx("div",{style:{marginTop:10,fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:"基于最新一次实际发送前请求的完整组成估算,包含系统提示、环境、项目上下文、技能、memory、历史消息、工具定义/调用/结果、图片和压缩摘要。不同模型的 tokenizer 与协议存在差异,因此不是账单精确值。"})]})]})]})}function Tl({startedAt:t}){return e.jsxs("div",{className:"agent-activity-indicator",role:"status","aria-live":"polite",children:[e.jsx("span",{className:"agent-activity-icon","aria-hidden":"true",children:e.jsx(Es,{size:17,strokeWidth:1.8})}),e.jsxs("span",{children:["思考中",e.jsx(Ds,{startedAt:t})]})]})}function Rl({sections:t,streaming:r=!1,startedAt:n,renderContent:s}){const i=u.useMemo(()=>[...t].sort((h,x)=>h.sectionIndex-x.sectionIndex).map(h=>h.text.trim()).filter(Boolean).join(`
247
-
248
- `),[t]),a=u.useMemo(()=>(i.split(`
249
- `).find(x=>x.trim())??"").replace(/^#{1,6}\s+/,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1"),[i]),[l,c]=u.useState(r);if(u.useEffect(()=>{c(r)},[r]),!i)return null;const f=r?"思考中":"思考";return e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":l,"aria-label":`${f},${l?"收起":"展开"}`,onClick:()=>c(h=>!h),children:[e.jsx("span",{className:"reasoning-summary__brain","aria-hidden":"true",children:e.jsx(Es,{size:17,strokeWidth:1.8})}),e.jsxs("span",{className:"reasoning-summary__label",children:[f,r&&n!==void 0&&e.jsx(Ds,{startedAt:n})]}),!l&&e.jsx("span",{className:"reasoning-summary__preview",children:a}),e.jsx("span",{className:"reasoning-summary__spacer"}),r&&e.jsx(Kn,{className:"reasoning-summary__spinner",size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx(Qn,{className:"reasoning-summary__chevron",size:13,strokeWidth:2,"aria-hidden":"true"})]}),l&&e.jsx("div",{className:"reasoning-summary__content",children:s(i)})]})}function Ml({appearanceOpen:t,settingsOpen:r,hideToBackgroundTitle:n="隐藏到后台",onHideToBackground:s,onToggleAppearance:i,onOpenSettings:a}){return e.jsxs("div",{className:"chat-header-actions",children:[e.jsx("button",{type:"button",onClick:s,title:n,"aria-label":"隐藏后台",className:"ui-icon-button chat-header-action chat-header-action--background",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"m9 11 3 3 3-3M12 7v7M8 21h8"})]})}),e.jsx("button",{type:"button",onClick:l=>i(l.currentTarget.getBoundingClientRect()),title:"皮肤与布局","aria-label":"皮肤与布局","aria-expanded":t,className:`ui-icon-button chat-header-action chat-header-action--appearance ${t?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]})}),e.jsx("button",{type:"button",onClick:a,title:"设置","aria-label":"设置","aria-expanded":r,className:`ui-icon-button chat-header-action chat-header-action--settings ${r?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]})}const Nl=[{prompt:"带我熟悉这个项目",Icon:ao},{prompt:"帮我排查一个问题",Icon:na},{prompt:"一起实现一个新想法",Icon:jo}],El={"customer-agent":"Customer Agent",codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function zl({agentType:t,ready:r,onSelectPrompt:n}){const s=El[t];return e.jsxs("section",{className:"empty-session-welcome","aria-labelledby":"empty-session-welcome-title",children:[e.jsxs("div",{className:"empty-session-welcome__core","aria-hidden":"true",children:[e.jsx("span",{className:"empty-session-welcome__glow"}),e.jsxs("svg",{viewBox:"0 0 120 120",role:"presentation",children:[e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--outer",cx:"60",cy:"60",r:"44"}),e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--inner",cx:"60",cy:"60",r:"33"}),e.jsx("rect",{className:"empty-session-welcome__diamond",x:"43",y:"43",width:"34",height:"34",rx:"2"}),e.jsx("circle",{className:"empty-session-welcome__pulse",cx:"60",cy:"60",r:"3"})]})]}),e.jsxs("div",{className:"empty-session-welcome__copy",children:[e.jsx("p",{className:"empty-session-welcome__status",children:r?`${s} · 已准备好`:`${s} · 等待配置`}),e.jsx("h2",{id:"empty-session-welcome-title",children:"嗨,我在。"}),e.jsx("p",{className:"empty-session-welcome__prompt",children:r?"今天想一起做点什么?":"配置好 API Key 后,我就能开始。"})]}),e.jsx("div",{className:"empty-session-welcome__starters","aria-label":"开始一个任务",children:Nl.map(({prompt:i,Icon:a})=>e.jsxs("button",{type:"button","data-prompt":i,disabled:!r,onClick:()=>n(i),children:[e.jsx(a,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:i})]},i))})]})}function Wl({image:t,onClose:r}){return u.useEffect(()=>{if(!t)return;const n=document.body.style.overflow,s=i=>{i.key==="Escape"&&r()};return document.body.style.overflow="hidden",window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s),document.body.style.overflow=n}},[t,r]),t?Vt.createPortal(e.jsxs("div",{className:"message-image-lightbox",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:n=>{n.target===n.currentTarget&&r()},children:[e.jsx("img",{className:"message-image-lightbox__image",src:t.src,alt:t.alt}),e.jsx("button",{type:"button",className:"message-image-lightbox__close",onClick:r,"aria-label":"关闭图片预览",title:"关闭",autoFocus:!0,children:e.jsx(ra,{size:22,"aria-hidden":"true"})})]}),document.body):null}const _l={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function Ll(t){const{title:r="视频工作台",shots:n=[],status:s="generating",composedVideoUrl:i}=t,[a,l]=u.useState(!1),[c,f]=u.useState(null);return e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-surface)",overflow:"hidden",maxWidth:600},children:[e.jsxs("div",{onClick:()=>l(!a),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:a?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",r]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[n.filter(h=>h.status==="done").length,"/",n.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:a?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!a&&e.jsxs("div",{style:{padding:"12px 16px"},children:[e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13,marginBottom:12},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"var(--bg-deep)"},children:[e.jsx("th",{style:yr,children:"#"}),e.jsx("th",{style:{...yr,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:yr,children:"时长"}),e.jsx("th",{style:yr,children:"状态"}),e.jsx("th",{style:yr,children:"预览"})]})}),e.jsx("tbody",{children:n.map(h=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:vr,children:h.index}),e.jsx("td",{style:{...vr,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.description,children:h.description}),e.jsxs("td",{style:vr,children:[h.duration,"s"]}),e.jsxs("td",{style:vr,children:[_l[h.status]??"⏳",h.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:h.error,children:"!"})]}),e.jsx("td",{style:vr,children:h.videoUrl?e.jsx("button",{onClick:()=>f(h.videoUrl),style:{background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:6,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"▶ 播放"}):h.previewImageUrl?e.jsx("img",{src:h.previewImageUrl,alt:`shot-${h.index}`,style:{width:48,height:32,objectFit:"cover",borderRadius:4,border:"1px solid var(--border-subtle)"}}):e.jsx("span",{style:{color:"var(--text-muted)",fontSize:11},children:"—"})})]},h.index))})]}),c&&e.jsx("video",{src:c,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),i&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"完整视频"}),e.jsx("video",{src:i,controls:!0,style:{width:"100%",borderRadius:8,border:"1px solid var(--border-subtle)"}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[s==="generating"&&e.jsx("span",{children:"🔄 生成中..."}),s==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),s==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),s==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const yr={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},vr={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},Pl={storyboard_workbench:Ll};function Bl(t,r,n){return!t||r!==t?!1:n===null||n===t}function Dl(t,r,n=Date.now()){return!t||t.sessionId!==r?t:{...t,until:n+9e4}}async function Fl(t){const{text:r,projectId:n,createSession:s,activateSession:i,showUserMessage:a,onSessionCreated:l,isCancelled:c}=t,f=!t.sessionId;let h=t.sessionId??null;if(!h){const x=await s(r.slice(0,60)||"语音任务",n||void 0);if(c!=null&&c())return null;h=x.id}return i(h),a(r,h),f&&l&&await l(h),h}async function Ri(t){var i,a;const r=((i=t.sessionId)==null?void 0:i.trim())||null,n=!r,s=r??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!s)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(s),t.showUserMessage(t.text,s),n&&await((a=t.onSessionCreated)==null?void 0:a.call(t,s)),s}const $l=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|[ \t]*\/[^)\n]+)\)/gi,Ol=/`([^`\n]+)`/g,Ul=/:codex-file-citation\{([^}\n]*)\}/g,Mi=/([A-Za-z][\w-]*)="([^"\n]*)"/g;function ma(t){if(!t.startsWith("/")||t.includes("?")||t.includes("#")||t.includes("\0"))return null;const r=t.match(/^(\/.*):([1-9]\d*)$/);return r?{path:r[1],line:Number(r[2])}:{path:t}}function ql(t){const r={};for(const i of t.matchAll(Mi)){const a=i[1];if(a!=="path"&&a!=="purpose"||r[a]!==void 0)return null;r[a]=i[2]}if(t.replace(Mi,"").trim())return null;const n=ma(r.path??"");if(!n||n.line!==void 0)return null;const s=n.path.slice(n.path.lastIndexOf("/")+1)||n.path;return{path:n.path,label:s}}function Hl(t,r){const n=[];let s=0;const i=[...[...t.matchAll($l)].map(a=>({kind:"markdown",match:a})),...[...t.matchAll(Ul)].map(a=>({kind:"citation",match:a})),...[...t.matchAll(Ol)].map(a=>({kind:"code",match:a}))].sort((a,l)=>(a.match.index??0)-(l.match.index??0));for(const a of i){const{match:l}=a,c=l.index??0;if(c<s)continue;if(c>s&&n.push({type:"text",value:t.slice(s,c)}),a.kind==="code"){n.push({type:"code",value:l[1]}),s=c+l[0].length;continue}if(a.kind==="citation"){const h=ql(l[1]);n.push(h?{type:"artifact",label:h.label,path:h.path,raw:l[0]}:{type:"text",value:l[0]}),s=c+l[0].length;continue}const f=l[2];if(/^https?:\/\//i.test(f))n.push({type:"link",label:l[1],href:f});else{const h=ma(f.replace(/^[ \t]+/,""));h?n.push({type:"artifact",label:l[1],path:h.path,...h.line?{line:h.line}:{},raw:l[0]}):n.push({type:"text",value:l[0]})}s=c+l[0].length}return s<t.length&&n.push({type:"text",value:t.slice(s)}),n.length>0?n:[{type:"text",value:t}]}function Vl(t){return Hl(t)}function ba(t){var r,n;return t.role==="assistant"&&!!((r=t.toolCalls)!=null&&r.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((n=t.images)!=null&&n.length)&&!t.presentation}function Ql(t){return ba(t)&&t.content.trim().length===0}function Kl(t){const r=[];for(const n of t){const s=r[r.length-1];if(s&&ba(s)&&Ql(n)){r[r.length-1]={...s,toolCalls:[...s.toolCalls,...n.toolCalls],timestamp:n.timestamp};continue}r.push(n)}return r}function Gl(t){const r=[];for(const n of t){const s=gl(n.toolCall.name),i=r[r.length-1];s&&(i==null?void 0:i.action)===s?i.items.push(n):r.push({action:s,items:[n]})}return r}function ya(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0}function Zl(t){const r=ya(t);return r===void 0?void 0:`${Math.round(r/1e3)} 秒`}function Jl(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function Yl(t){var r,n,s;return t.role==="assistant"&&!!(t.content.trim()||(r=t.toolCalls)!=null&&r.length||(s=(n=t.presentation)==null?void 0:n.reasoning)!=null&&s.length||t.askUser||t.widget)}function Xl(t,r,n){var a;const s=t[r];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(a=s.toolCalls)!=null&&a.length||s.isCompactionSummary)return!1;let i=!n;for(let l=r+1;l<t.length;l++){const c=t[l];if(!c.isCompactionSummary){if(Jl(c)){i=!0;break}if(Yl(c))return!1}}return i}function ed(t,r,n){const s=t[r];if(!s)return{showCopy:!1,showSpeak:!1,showCompletion:!1,compact:!1};if(s.role==="user")return{showCopy:!!s.content,showSpeak:!1,showCompletion:!1,compact:!1};const i=Xl(t,r,n);return{showCopy:i,showSpeak:i,showCompletion:i,compact:s.role==="assistant"&&!i&&!s.isCompactionSummary}}const td=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function nd(t,r){const n=[],s=[],i=[];for(const l of t){const c=l.type.trim().toLowerCase();c.startsWith("image/")?td.has(c)?n.push(l):i.push(l):s.push(l)}const a=await Promise.all(n.map(async l=>{try{return{file:l,dataUrl:await r(l)}}catch{return{file:l,dataUrl:null}}}));return{images:a.flatMap(l=>l.dataUrl?[l.dataUrl]:[]),attachments:s,unsupportedImages:i,failedImages:a.flatMap(l=>l.dataUrl?[]:[l.file])}}function va(t,r){return!!(t&&(r==null?void 0:r.sessionId)===t&&r.code==="SESSION_OCCUPIED")}function Ni(t,r){return((t==null?void 0:t.agentType)==="codex"||(t==null?void 0:t.agentType)==="opencode")&&(t.occupancy==="owned-externally"||va(t.id,r))}async function rd(t){const r=await t.forkSession(t.sourceSessionId);return t.activateSession(r.id),await t.refreshAndSelect(r),r}const Dr=50;function Ei(t){return t.trim().replace(/^\/goal\s+/i,"").replace(/^\$([\w-]+)/,"/$1").trim()}function hs(t){const n=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(n){const a=parseFloat(n[1]),l=n[2].toLowerCase(),c=l==="s"||l==="sec"||l==="秒"?a*1e3:l==="m"||l==="min"||l==="分"||l==="分钟"?a*6e4:a*36e5;return c>=36e5&&c%36e5===0?`每 ${c/36e5} 小时`:c>=6e4&&c%6e4===0?`每 ${c/6e4} 分钟`:`每 ${c/1e3} 秒`}const[s,i]=t.trim().split(/\s+/);return s==="0"&&i&&i!=="*"&&!i.includes("/")&&!i.includes(",")?`每天 ${i.padStart(2,"0")}:00`:`cron: ${t}`}function sd(t){const r=t.split(/(`[^`\n]+`)/g);return r.length<=1?t:e.jsx(e.Fragment,{children:r.map((n,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.slice(1,-1)},s):e.jsx("span",{children:n},s))})}function wa(t,r){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,i)=>{const a=`${r}-${i}`;return s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:s.slice(2,-2)},a):s.startsWith("*")&&s.endsWith("*")&&s.length>2?e.jsx("em",{children:s.slice(1,-1)},a):e.jsx("span",{children:s},a)})}function zi(t,r){return t.split(/(`[^`\n]+`)/g).map((s,i)=>i%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:s.slice(1,-1)},`${r}-${i}`):wa(s,`${r}-${i}`))}function Rs(t){return Vl(t).map((r,n)=>{if(r.type==="code")return e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:r.value},n);if(r.type==="link")return e.jsx("a",{className:"chat-message-link",href:r.href,target:"_blank",rel:"noopener noreferrer",children:zi(r.label,`${n}-label`)},n);if(r.type==="artifact"){if(!Hn())return e.jsx("span",{children:r.raw},n);const s=r.line?`${r.path}:${r.line}`:r.path,i=r.label.replace(/^`([^`\n]+)`$/,"$1");return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:s,"aria-label":`打开交付物 ${i}`,onClick:()=>Tn(r.path),children:[e.jsx(zs,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:zi(r.label,`${n}-label`)})]},n)}return wa(r.value,`${n}`)})}function id(t){if(t.length<2)return null;const r=a=>a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim()),n=r(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const i=t.slice(2).map(r);return{headers:n,rows:i}}function ad(t,r){const n=s=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:s?600:400,color:s?"var(--text-primary)":"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"pre-wrap",wordBreak:"break-word"});return e.jsx("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"auto",background:"var(--bg-surface)"},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"var(--bg-deep)"},children:t.map((s,i)=>e.jsx("th",{style:n(!0),children:Rs(s)},i))})}),e.jsx("tbody",{children:r.map((s,i)=>e.jsx("tr",{style:{background:i%2===0?"transparent":"rgba(0,0,0,0.015)"},children:s.map((a,l)=>e.jsx("td",{style:n(!1),children:Rs(a)},l))},i))})]})})}function od(t,r){return e.jsxs("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"4px 10px",background:"var(--bg-deep)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em"},children:t||"code"}),e.jsx("pre",{style:{margin:0,padding:"10px 12px",fontSize:12,lineHeight:1.6,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto",maxHeight:420},children:r})]})}function xs(t){const r=t.split(`
250
- `),n=[];let s=0,i=0;const a=c=>c.trimStart().startsWith("```"),l=c=>r[c].trimStart().startsWith("|")&&c+1<r.length&&/^\|[\s\-:|]+\|$/.test(r[c+1].trim());for(;s<r.length;){if(a(r[s])){const c=r[s].trim().slice(3).trim();s++;const f=[];for(;s<r.length&&!a(r[s]);)f.push(r[s]),s++;s++,n.push(e.jsx("div",{children:od(c,f.join(`
251
- `))},`code-${i++}`));continue}if(l(s)){const c=[];for(;s<r.length&&r[s].trimStart().startsWith("|");)c.push(r[s].trim()),s++;const f=id(c);f?n.push(e.jsx("div",{children:ad(f.headers,f.rows)},`tbl-${i++}`)):n.push(e.jsx("span",{children:c.map((h,x)=>e.jsxs("span",{children:[sd(h),x<c.length-1?`
252
- `:null]},x))},`tbl-fb-${i++}`))}else{const c=[];for(;s<r.length&&!l(s)&&!a(r[s]);)c.push(r[s]),s++;c.length>0&&n.push(e.jsx("span",{children:c.map((f,h)=>e.jsxs("span",{children:[Rs(f),h<c.length-1?`
253
- `:null]},h))},`txt-${i++}`))}}return e.jsx(e.Fragment,{children:n})}const ja=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Wi=Object.fromEntries(ja.map(t=>[t.value,t.label])),qr=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function _i(t){return qr.some(r=>r.value===t)?t:"full-access"}function ld({activeAgentType:t="customer-agent",selectedProjectId:r=null,selectedSessionId:n=null,onSessionCreated:s,onMessageSent:i,onSubSessionCreated:a,onSelectSession:l,onSubAgentEvent:c,onRunComplete:f,sessionTitle:h,sessionSummary:x,workspacePath:m=null,onOpenSettings:S,settingsOpen:I=!1,onHideToBackground:N,onToggleAppearance:O,appearanceOpen:K=!1,hideToBackgroundTitle:U,voiceCommand:y=null}){var Xs,ei,ti,ni,ri,si,ii,ai,oi,li;const{messages:v,runningSessionId:B,appendText:H,addMessage:A,setRunningSession:C,setSessionId:E,updateToolResult:M,updateSubAgentStatus:_,updateSubAgentProgress:ne,updateMessage:ce,setMessages:Se,getMessagesForSession:G,contextUsageBySession:Ge,runtimeProgressBySession:vt,nativeSubagentsBySession:Rn,setContextUsage:Re,applyRuntimeProgress:Mn,setRuntimeProgress:Wt,clearRuntimeProgress:_t,applyNativeSubagentActivity:Jn,setNativeSubagentActivities:rt,applyReasoningSummary:k,clearMessages:D,sessionId:se,todos:de,setTodos:he,cronTasks:ye,setCronTasks:ve}=ge(),be=u.useMemo(()=>Kl(v.filter(o=>!o.isQueued)),[v]),{isConfigured:Lt,profiles:wt,activeProfileId:jt,switchActiveProfile:ct,loadFromSystem:Nn,contextWindow:Pt,reasoningEffort:ut,setField:xe,saveToSystem:Yn}=Qr(),[Fe,pt]=u.useState(),[kt,St]=u.useState(),[on,ln]=u.useState(!1),[dn,Ct]=u.useState(null),[Bt,En]=u.useState(null),$=n||se,Ce=ol(x,t),It=(x==null?void 0:x.messageQueueVersion)===1,Sr=Xo(x==null?void 0:x.agentType),Qt=dn===$?"direct":Bt?"incompatible":(Xs=x==null?void 0:x.compatibility)==null?void 0:Xs.status,Dt=Qt!==void 0&&Qt!=="direct",Ft=(x==null?void 0:x.occupancy)==="owned-externally"||Dt,At=va($,Fe),Tt=Lt||Ce,zn=Tt&&!Ft&&!At,cn=u.useRef(new Set),[Xn,Cr]=u.useState("idle"),er=u.useRef("idle"),un=u.useRef(null),[gt,Ir]=u.useState(()=>Date.now()),pn=!!($&&(B===$||cn.current.has($))),$t=dl(x,pn),Rt=pn||ll(x),Ar=$?vt[$]??[]:[],Gr=$?Rn[$]??{}:{},Kt=Po(Ar),Wn=be[be.length-1],ft=!!((Wn==null?void 0:Wn.role)==="assistant"&&Xn==="thinking"&&((ti=(ei=Wn.presentation)==null?void 0:ei.reasoning)!=null&&ti.some(o=>o.text.trim()))),tr=Xn==="tools"&&be.some(o=>{var p;return((p=o.toolCalls)==null?void 0:p.length)&&!us(o.toolCalls)}),Gt=Rt&&!Kt&&!ft&&!tr;u.useEffect(()=>{Nn()},[]),u.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(o=>ve(o))},[]);const[Ve,Ee]=u.useState(""),[ht,gn]=u.useState(null),[nr,Zt]=u.useState(""),[Tr,rr]=u.useState(null),[Ze,Je]=u.useState(null),fn=u.useRef(null),[sr,Mt]=u.useState(!1),[Jt,st]=u.useState(!1),[hn,it]=u.useState(!1),[$e,xt]=u.useState("full-access"),[at,Zr]=u.useState(!1),[Me,xn]=u.useState({active:null,queued:[],history:[]}),[Yt,ir]=u.useState(null),[Nt,Ot]=u.useState(!1),ze=u.useRef(null),ar=u.useRef(null),Qe=u.useCallback((o,p)=>{const g=zt.current||et.current;if(p===g&&xn(Ci(o)),!p.startsWith("runtime:"))return;const b=G(p);Se(ds(b,cs(o)),p)},[G,Se]);u.useEffect(()=>{if(!Jt)return;const o=p=>{ze.current&&!ze.current.contains(p.target)&&st(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[Jt]),u.useEffect(()=>{if(!hn)return;const o=p=>{ar.current&&!ar.current.contains(p.target)&&it(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[hn]),u.useEffect(()=>{it(!1),xt(_i(x==null?void 0:x.permissionMode))},[Ce,n,x==null?void 0:x.permissionMode]);const[mn,Y]=u.useState(null),[Xt,or]=u.useState(null),[Jr,Rr]=u.useState(0),[_n,Ln]=u.useState([]),[bn,Et]=u.useState([]),[Pn,Mr]=u.useState(0),[Nr,pe]=u.useState(null),mt=u.useRef(null),Ke=u.useRef(null),Ne=u.useRef(null),Er=u.useRef(()=>{}),bt=u.useRef(null),en=u.useRef(null),ot=u.useRef(null);ot.current||(ot.current=new Go);const lt=u.useRef(null),tt=u.useRef(null),Oe=u.useRef(!1),yn=u.useRef(!1),tn=u.useRef(new Set),lr=u.useRef(null),dr=u.useRef(!1),vn=u.useRef(!1),cr=u.useRef(null),wn=u.useRef(null),[Bn,zr]=u.useState(!1),[Dn,jn]=u.useState(null),[ur,Fn]=u.useState(!1),[Wr,d]=u.useState(!1),w=u.useRef(null),T=u.useRef(null),W=u.useRef(null),[z,ee]=u.useState(null),[J,ie]=u.useState([]),[We,Ie]=u.useState([]),[_e,ae]=u.useState([]),[Z,Ae]=u.useState(null),[Ye,Le]=u.useState(null),Xe=u.useCallback((o,p)=>{const g=window.agentApi;!p||!g||ot.current.prefetch(o,p,()=>g.getSession(o,{before:p,limit:Dr})).catch(b=>{console.warn("[chat] failed to prefetch older history",{sessionId:o,error:b})})},[]);u.useEffect(()=>{if(!Ce||!$){lr.current=null;return}if(lr.current!==$){lr.current=$,Ee(nl($));return}if(dr.current&&Ve===""){dr.current=!1;return}ls($,Ve)},[Ve,Ce,$]);const yt=()=>{const o=mt.current;o&&(o.scrollTop<=240&&Er.current(),o.classList.add("is-scrolling"),Ne.current!==null&&window.clearTimeout(Ne.current),Ne.current=window.setTimeout(()=>{o.classList.remove("is-scrolling"),Ne.current=null},700))};u.useEffect(()=>()=>{Ne.current!==null&&window.clearTimeout(Ne.current)},[]),u.useLayoutEffect(()=>{const o=cr.current,p=mt.current;!o||!p||(p.scrollTop=o.scrollTop+(p.scrollHeight-o.scrollHeight),cr.current=null)},[v]);const[je,Ue]=u.useState(!1),[re,ke]=u.useState(null),$n=u.useRef(null);u.useEffect(()=>{const o=window.agentApi;if(!(o!=null&&o.onTtsStart)||!o.onTtsPcm||!o.onTtsStreamEnd||!o.onTtsFlush)return;const p=new Uo(o),g=[o.onTtsStart(b=>p.start(b)),o.onTtsPcm(({generation:b,pcm:R})=>p.enqueue(b,R)),o.onTtsStreamEnd(({generation:b})=>p.finish(b)),o.onTtsFlush(({generation:b})=>p.flush(b)),o.onTtsEnd(()=>ke(null))];return()=>{for(const b of g)b();p.dispose()}},[]);const Ra=()=>{var g;if(je){(g=$n.current)==null||g.stop(),$n.current=null,Ue(!1);return}Pr(window.agentApi,br);const o=Ve?`${Ve.trimEnd()} `:"",p=Do({onInterim:b=>Ee(o+b),onFinal:b=>{var R;Ee(o+b),(R=T.current)==null||R.focus()},onError:b=>Y(b),onEnd:()=>{Ue(!1),$n.current=null}});p&&($n.current=p,Ue(!0))},Ma=async(o,p)=>{var g;if(re===o){await Pr(window.agentApi,br),ke(null);return}if(await Pr(window.agentApi,br),!((g=window.agentApi)!=null&&g.ttsSpeak)){Y("TTS 模型服务不可用");return}ke(o);try{(await window.agentApi.ttsSpeak(p)).ok||(ke(null),Y("TTS 模型播报失败"))}catch(b){ke(null),Y(b instanceof Error?b.message:"TTS 模型播报失败")}},Pe=u.useRef(null),On=u.useRef(!1),Un=u.useRef(new Set),pr=u.useRef(new Map),Os=u.useRef(new Set),zt=u.useRef(n??null),et=u.useRef(null),gr=u.useRef(0);u.useEffect(()=>{zt.current=n??null},[n]),u.useEffect(()=>{et.current=se},[se]),u.useEffect(()=>()=>{for(const o of pr.current.values())window.clearTimeout(o);pr.current.clear()},[]);const _r=u.useCallback(async o=>{var g;const p=o||zt.current||et.current;if(!p||!((g=window.agentApi)!=null&&g.getSessionGoals)){xn({active:null,queued:[],history:[]});return}try{const b=await window.agentApi.getSessionGoals(p);Qe(b,p),b.active&&(Pe.current=p,C(p))}catch(b){Y(b instanceof Error?b.message:"目标状态加载失败")}},[Qe,C]);u.useEffect(()=>{_r($)},[$,_r]);const qe=u.useCallback(o=>{const p=zt.current||et.current;o==="thinking"&&(er.current!=="thinking"||un.current!==p)?(un.current=p,Ir(Date.now())):o!=="thinking"&&(un.current=null),er.current=o,Cr(o)},[]),Na=u.useCallback(o=>{un.current=o,er.current="thinking",Ir(Date.now()),Cr("thinking")},[]);u.useEffect(()=>{pt(void 0),St(void 0),ln(!1),pe(null)},[n]),u.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(o=>ie(o)),window.agentApi.listSkills().then(o=>Ie(o.filter(p=>p.name))).catch(o=>console.error("[listSkills] mount error:",o)))},[]);const Us=Z===null?[]:J.filter(o=>Z===""||o.name.toLowerCase().includes(Z.toLowerCase())),Yr=Ye===null?[]:[...[{name:"goal",description:"目标模式:持续推进当前目标,后续目标自动排队"},{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(o=>Ye===""||o.name.toLowerCase().includes(Ye.toLowerCase())),...We.filter(o=>Ye===""||o.name.toLowerCase().includes(Ye.toLowerCase()))],Ea=o=>{ae(p=>p.find(g=>g.id===o.id)?p:[...p,o]),Ee(p=>p.replace(/@[\w\u4e00-\u9fff]*$/,"")),Ae(null),setTimeout(()=>{var p;return(p=T.current)==null?void 0:p.focus()},0)},za=o=>{ae(p=>p.filter(g=>g.id!==o))},Wa=o=>{Ee(p=>p.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${o.name} `)),Le(null),setTimeout(()=>{var p;return(p=T.current)==null?void 0:p.focus()},0)},qs=o=>{var b,R;Ee(o);const p=o.match(/@([\w\u4e00-\u9fff]*)$/);if(p){window.agentApi&&window.agentApi.listAgentDefs().then(j=>ie(j)),ee(((b=W.current)==null?void 0:b.getBoundingClientRect())??null),Ae(p[1]),Le(null);return}const g=o.match(/\/([-\w\u4e00-\u9fff]*)$/);if(g){window.agentApi&&window.agentApi.listSkills().then(j=>Ie(j.filter(Q=>Q.name))).catch(j=>console.error("[listSkills] slash error:",j)),ee(((R=W.current)==null?void 0:R.getBoundingClientRect())??null),Le(g[1]),Ae(null);return}Ae(null),Le(null)},_a=o=>{qs(o),Ae(null),Le(null),requestAnimationFrame(()=>{var p;return(p=T.current)==null?void 0:p.focus()})},La=o=>{o.key==="Escape"&&(Z!==null||Ye!==null)?(o.preventDefault(),Ae(null),Le(null)):o.key==="Escape"&&pn?(o.preventDefault(),Ks()):o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),Ys())},Pa=async o=>{const p=Array.from(o.target.files??[]);if(o.target.value="",p.length===0)return;const g=p.filter(b=>b.type.toLowerCase().startsWith("image/")).length;g>0&&Mr(b=>b+1);try{const b=await nd(p,Hs);b.attachments.length>0&&Ln(j=>[...j,...b.attachments]),b.images.length>0&&(Et(j=>[...j,...b.images]),Ce||Fa());const R=[...b.unsupportedImages,...b.failedImages];R.length>0&&Y(`无法添加图片:${R.map(j=>j.name).join("、")}。仅支持 JPG、PNG、GIF 和 WebP。`)}finally{g>0&&Mr(b=>Math.max(0,b-1))}},Ba=o=>{Ln(p=>p.filter((g,b)=>b!==o))},Da=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Xr=o=>Da.test(o),Fa=()=>{const o=wt.find(g=>g.id===jt);if(o&&Xr(o.modelId))return;const p=wt.find(g=>Xr(g.modelId));p&&ct(p.id)},$a=o=>{Et(p=>[...p,o])},Oa=o=>{Et(p=>p.filter((g,b)=>b!==o))},Hs=o=>new Promise((p,g)=>{const b=new FileReader;b.onload=()=>p(b.result),b.onerror=g,b.readAsDataURL(o)});u.useEffect(()=>{const o=async p=>{if(!p.clipboardData)return;const g=Array.from(p.clipboardData.items).find(R=>R.type.startsWith("image/"));if(!g)return;p.preventDefault();const b=g.getAsFile();b&&$a(await Hs(b))};return window.addEventListener("paste",o),()=>window.removeEventListener("paste",o)},[wt,jt]),u.useEffect(()=>{var p;const o=wn.current;wn.current=null,o!=="skip"&&((p=Ke.current)==null||p.scrollIntoView({behavior:o==="instant"?"auto":"smooth"}))},[v]),u.useEffect(()=>window.agentApi?window.agentApi.onEvent(p=>Ua(p)):void 0,[se]),u.useEffect(()=>{const o=++gr.current,p=n;let g=null;const b=()=>gr.current===o&&zt.current===p;return(async()=>{var q,F,P,ue,te;const j=window.agentApi;if(!j||Bl(Pe.current,et.current,p))return;if(!p){if(!b())return;(q=ot.current)==null||q.invalidate(),D(),Y(null),or(null),Ct(null),En(null),bt.current=null,en.current=null,jn(null),Fn(!1),d(!1),lt.current=null,et.current=null,E(""),xt("full-access");return}Y(null),or(null),Ct(null),En(null),jn(null),(F=ot.current)==null||F.invalidate(),bt.current=null,en.current=null,Fn(!0),d(!1),lt.current=p,et.current=p,E(p);const Q=G(p);Se(Q,p),g=window.setTimeout(()=>{b()&&d(!0)},500);try{const L=await Yo(async()=>{if(!b())throw new DOMException("Session selection changed","AbortError");return j.getSession(p,{limit:Dr})}),oe=L,le=fi((L==null?void 0:L.events)??[]),He=gi((L==null?void 0:L.events)??[]),we=hi((L==null?void 0:L.events)??[]),Be=as(L);if(!b())return;x!=null&&x.compatibility&&Ct(p),xt(_i((oe==null?void 0:oe.permissionMode)??((P=oe==null?void 0:oe.metadata)==null?void 0:P.permissionMode)));const fe=((ue=L==null?void 0:L.history)==null?void 0:ue.nextCursor)??null;bt.current=fe,en.current=fe;const De=G(p),hr=De.length>0&&ge.getState().runningSessionId===p?De:Be,V=L!=null&&L.goalState&&p.startsWith("runtime:")?ds(hr,cs(L.goalState)):hr;wn.current="instant",Se(V,p),Xe(p,fe),Wt(He,p),rt(we,p),la(L)?(Pe.current=p,C(p)):Pe.current===p&&(Pe.current=null,C(null)),le&&Re(le,p);const Te=V[V.length-1];if((Te==null?void 0:Te.role)==="assistant"&&((te=Te.toolCalls)!=null&&te.length)){const Ut=us(Te.toolCalls);qe(Ut?"thinking":"tools")}else qe((L==null?void 0:L.agentType)!=="customer-agent"&&(L==null?void 0:L.status)==="running"?"thinking":"idle")}catch(L){if(!b())return;console.error("[chat] failed to restore session",{sessionId:p,error:L});const oe=Jo(L);or(oe),x!=null&&x.compatibility&&En(oe)}finally{g!==null&&window.clearTimeout(g),b()&&(Fn(!1),d(!1))}})(),()=>{g!==null&&window.clearTimeout(g),gr.current===o&&(gr.current+=1)}},[D,G,Xe,n,Jr,Re,Se,E,qe]);const Vs=u.useCallback(async o=>{var p,g,b;if(!(!window.agentApi||document.visibilityState==="hidden")){if(tt.current!==o&&(tt.current=o,Oe.current=!1,yn.current=!1),Oe.current){yn.current=!0;return}Oe.current=!0;try{do{yn.current=!1;const R=await window.agentApi.getSession(o,{limit:Dr});if(zt.current!==o||lt.current!==o)return;const j=as(R),Q=G(o),q=qo(Q,j),F=R!=null&&R.goalState&&o.startsWith("runtime:")?ds(q,cs(R.goalState)):q,P=mt.current,ue=!P||P.scrollHeight-P.scrollTop-P.clientHeight<80;wn.current=ue?null:"skip",Se(F,o),R!=null&&R.goalState&&xn(Ci(R.goalState));const te=en.current,L=((p=R==null?void 0:R.history)==null?void 0:p.nextCursor)??null;if(bt.current===te){const He=bt.current!==L;bt.current=L,He&&((g=ot.current)==null||g.invalidate(),Xe(o,L))}en.current=L;const oe=fi((R==null?void 0:R.events)??[]);Wt(gi((R==null?void 0:R.events)??[]),o),rt(hi((R==null?void 0:R.events)??[]),o),oe&&Re(oe,o);const le=F[F.length-1];(le==null?void 0:le.role)==="assistant"&&((b=le.toolCalls)!=null&&b.length)?qe(us(le.toolCalls)?"thinking":"tools"):qe(_s(R)?"thinking":"idle")}while(yn.current)}catch(R){console.error("[chat] failed to refresh native session history",{sessionId:o,error:R})}finally{tt.current===o&&(Oe.current=!1)}}},[G,Xe,Re,Se,qe]);u.useEffect(()=>{const o=n,p=cl(x,o,B),g=(x==null?void 0:x.occupancy)==="owned-externally"||(x==null?void 0:x.status)==="running";if(!o||!p||!window.agentApi)return;let b=null,R=null,j=!1;const Q=()=>{!j&&document.visibilityState!=="hidden"&&Vs(o)},q=()=>{b==null||b(),b=null,R!==null&&window.clearInterval(R),R=null},F=()=>{j||R!==null||document.visibilityState==="hidden"||(Q(),R=window.setInterval(Q,2e3))},P=()=>{if(!(j||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){g&&F();return}try{b=window.agentApi.observeSession(o,Q,()=>{b=null,g&&F()})}catch{g&&F()}}},ue=()=>{q(),document.visibilityState!=="hidden"&&(Q(),P())};return P(),document.addEventListener("visibilitychange",ue),()=>{j=!0,document.removeEventListener("visibilitychange",ue),q(),tt.current===o&&(tt.current=null,yn.current=!1)}},[Vs,n,B,x==null?void 0:x.agentType,x==null?void 0:x.occupancy,x==null?void 0:x.status]);const es=u.useCallback(async()=>{var R;const o=lt.current,p=bt.current,g=window.agentApi;if(!g||!o||!p||vn.current)return;vn.current=!0,jn(null);const b=window.setTimeout(()=>{lt.current===o&&vn.current&&zr(!0)},500);try{const j=await ot.current.consume(o,p,()=>g.getSession(o,{before:p,limit:Dr}));if(lt.current!==o||zt.current!==o)return;const Q=as(j),q=G(o),F=mt.current;F&&Q.length>0&&(cr.current={scrollHeight:F.scrollHeight,scrollTop:F.scrollTop},wn.current="skip");const P=((R=j==null?void 0:j.history)==null?void 0:R.nextCursor)??null;bt.current=P,Q.length>0&&Se([...Q,...q],o),Xe(o,P)}catch(j){if(lt.current!==o)return;console.error("[chat] failed to load older history",{sessionId:o,error:j}),jn(j instanceof Error?j.message:"历史消息加载失败")}finally{window.clearTimeout(b),vn.current=!1,lt.current===o&&zr(!1)}},[G,Xe,Se]);u.useEffect(()=>{Er.current=()=>{es()}},[es]);const Qs=o=>{if(Un.current.has(o)||pr.current.has(o))return;const p=window.setTimeout(()=>{pr.current.delete(o),(async()=>{var g;if(!Un.current.has(o))try{const b=await((g=window.agentApi)==null?void 0:g.getSessionGoals(o)),R=zt.current||et.current;if(b&&o===R&&Qe(b,o),b!=null&&b.active){Pe.current=o,o===R&&(On.current=!1,Y(null),C(o));return}if(On.current)return;const j=ge.getState().getMessagesForSession(o).find(Q=>Q.isQueued&&!Q.queueItemId);if(!j){o===R&&(Pe.current=null,C(null));return}ce(j.id,Q=>({...Q,isQueued:!1}),o),Lr(j,o)}catch(b){Y(b instanceof Error?b.message:"排队消息自动发送失败")}})()},150);pr.current.set(o,p)},Ua=o=>{var R,j,Q;const p=zt.current||et.current,g=o._sid||p||void 0;if(o._nativeRunId&&Number.isSafeInteger(o._nativeSequence)){const q=`${o._nativeRunId}:${o._nativeSequence}`;if(tn.current.has(q))return;tn.current.add(q),tn.current.size>2e3&&(tn.current=new Set([...tn.current].slice(-1e3)))}const b=!g||g===p;switch(o.type){case"run_admitted":g&&g===p&&rl(g);break;case"context_usage":o.usage&&Re(o.usage,g);break;case"text_chunk":o.text&&(H(o.text,g),b&&qe("thinking"));break;case"reasoning_summary_delta":typeof o.itemId=="string"&&Number.isSafeInteger(o.sectionIndex)&&typeof o.delta=="string"&&(k({type:"reasoning_summary_delta",itemId:o.itemId,sectionIndex:o.sectionIndex,delta:o.delta},g),b&&qe("thinking"));break;case"runtime_progress":if(typeof o.progressId=="string"&&typeof o.label=="string"&&["thinking","tool","retry","status"].includes(o.phase??"")){const q={progressId:o.progressId,phase:o.phase,label:o.label,...o.detail===void 0?{}:{detail:o.detail},...o.toolCallId===void 0?{}:{toolCallId:o.toolCallId},...o.elapsedSeconds===void 0?{}:{elapsedSeconds:o.elapsedSeconds},...o.current===void 0?{}:{current:o.current},...o.total===void 0?{}:{total:o.total}};Mn(q,g),b&&qe(q.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(R=o.activity)!=null&&R.parentToolCallId&&(Jn(o.activity,g),b&&o.activity.status==="running"&&qe("tools"));break;case"tool_call":b&&qe("tools"),o.toolCall&&o.toolCall.name!=="dispatch_agent"&&o.toolCall.name!=="ask_user"&&o.toolCall.name!=="show_widget"&&A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:o.toolCall.id,name:o.toolCall.name,arguments:o.toolCall.arguments}],timestamp:Date.now()},g);break;case"tool_result":o.result&&M(o.result.toolCallId,o.result.content,o.result.isError,g);break;case"todo_update":o.todos&&he(o.todos);break;case"cron_update":o.tasks&&ve(o.tasks);break;case"agent_dispatch":if(A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:o.agentName,task:o.task??"",subSessionId:o.subSessionId}}],timestamp:Date.now()},g),o.subSessionId){cn.current.add(o.subSessionId);const q=Pe.current||se;q&&a&&a(q)}c==null||c({type:"started",agentName:o.agentName??"",task:o.task??"",subSessionId:o.subSessionId});break;case"agent_done":o.subSessionId&&(cn.current.delete(o.subSessionId),_(o.subSessionId,o.status??"completed",o.status==="failed"?o.error:o.summary,g)),c==null||c({type:o.status==="failed"?"failed":"completed",agentName:o.agentName??"",task:o.task??"",subSessionId:o.subSessionId});break;case"agent_progress":o.subSessionId&&o.text&&ne(o.subSessionId,o.text,g);break;case"compacted":A({id:crypto.randomUUID(),role:"assistant",content:o.summary??"",isCompactionSummary:!0,timestamp:Date.now()},g);break;case"show_widget":{const q=o.data??o.widgetData,F={widgetId:o.widgetId,widgetType:o.widgetType,data:q??{}},ue=(g?ge.getState().getMessagesForSession(g):ge.getState().messages).find(te=>{var L;return((L=te.widget)==null?void 0:L.widgetId)===F.widgetId});ue?ce(ue.id,te=>({...te,widget:F}),g):A({id:crypto.randomUUID(),role:"assistant",content:"",widget:F,timestamp:Date.now()},g);break}case"ask_user":if(o.questionId&&(g?ge.getState().getMessagesForSession(g):ge.getState().messages).some(F=>{var P;return((P=F.askUser)==null?void 0:P.questionId)===o.questionId}))break;A({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:o.questionId??"",question:o.question??"",options:o.options,fields:o.fields,multiSelect:o.multiSelect},timestamp:Date.now()},g);break;case"approval_resolved":{if(!o.questionId)break;const F=(g?ge.getState().getMessagesForSession(g):ge.getState().messages).find(P=>{var ue;return((ue=P.askUser)==null?void 0:ue.questionId)===o.questionId});F&&ce(F.id,P=>({...P,askUser:P.askUser?{...P.askUser,answered:!0,answer:"已处理"}:P.askUser}),g);break}case"text_done":break;case"thinking":b&&qe("thinking");break;case"done":if(g){const q=ya(o.durationMs);if(q!==void 0){const F=[...G(g)].reverse().find(P=>{var ue;return P.role==="assistant"&&!!P.content.trim()&&!((ue=P.toolCalls)!=null&&ue.length)&&!P.isCompactionSummary});F&&ce(F.id,P=>({...P,presentation:{...P.presentation,completionDurationMs:q}}),g)}}if(_t(g),b&&!ge.getState().messages.some(q=>q.isQueued)&&C(null),b&&(qe("idle"),nt.getState().autoSpeak)){const F=[...ge.getState().messages].reverse().find(P=>P.role==="assistant"&&P.content&&!P.isCompactionSummary);F!=null&&F.content&&(j=window.agentApi)!=null&&j.ttsSpeak&&(br(),window.agentApi.ttsSpeak(F.content.slice(0,600)).then(P=>{P.ok||Y("TTS 模型播报失败")}).catch(P=>{Y(P instanceof Error?P.message:"TTS 模型播报失败")}))}g&&(Un.current.has(g)?window.setTimeout(()=>{_r(g)},150):Qs(g));break;case"error":if(o._preserveActiveRun||_t(g),b){if(o._preserveActiveRun&&g&&(Os.current.add(g),Pe.current=g,C(g),qe("thinking")),o.code==="SESSION_ALREADY_RUNNING"){const q=g?ge.getState().getMessagesForSession(g):ge.getState().messages,F=il(q);if(F){const P=q.find(ue=>ue.id===F);ce(F,ue=>({...ue,isQueued:!0}),g),It&&(g!=null&&g.startsWith("runtime:"))&&P&&((Q=window.agentApi)!=null&&Q.enqueueSessionMessage)&&window.agentApi.enqueueSessionMessage(g,{sourceMessageId:P.id,content:P.content,images:P.images,agentName:P.agentName}).then(ue=>Qe(ue,g)).catch(ue=>{Y(ue instanceof Error?ue.message:"排队消息保存失败")})}St(void 0),pt(void 0),Y(null)}else if(o.code==="SESSION_OCCUPIED"){const F=[...g?ge.getState().getMessagesForSession(g):ge.getState().messages].reverse().find(P=>P.role==="user"&&!P.isQueued);St(F==null?void 0:F.content),F!=null&&F.content&&(Ee(F.content),g&&ls(g,F.content)),g&&pt({sessionId:g,code:o.code}),Y(null)}else{Y(o.message??"Unknown error");const F=[...g?ge.getState().getMessagesForSession(g):ge.getState().messages].reverse().find(P=>P.role==="user"&&!P.isQueued);Ce&&(F!=null&&F.content)&&(Ee(F.content),g&&ls(g,F.content))}o._preserveActiveRun||(C(null),qe("idle"))}g&&!o._preserveActiveRun&&(Un.current.has(g)?window.setTimeout(()=>{_r(g)},150):Qs(g));break;case"turn_aborted":_t(g),b&&(C(null),qe("idle"));break}},qa=async o=>{var g;if(!$||!((g=window.agentApi)!=null&&g.setSessionPermissionMode)||Nt)return;const p=$e;xt(o),it(!1),Ot(!0);try{await window.agentApi.setSessionPermissionMode($,o)}catch(b){xt(p),Y(b instanceof Error?b.message:"权限模式更新失败")}finally{Ot(!1)}},Ha=async()=>{var o;if(!(!$||!((o=window.agentApi)!=null&&o.handoffSession)))try{await window.agentApi.handoffSession($),Y(null)}catch(p){Y(p instanceof Error?p.message:"交接到 Desktop 失败")}},Va=async()=>{var o;if(!(!$||!((o=window.agentApi)!=null&&o.forkSession)||on)){ln(!0);try{await rd({sourceSessionId:$,forkSession:p=>window.agentApi.forkSession(p),activateSession:p=>{et.current=p,E(p)},refreshAndSelect:async p=>{s?await s(p.id,p):l==null||l(p.id)}}),kt&&Ee(kt),St(void 0),pt(void 0),Y(null)}catch(p){Y(p instanceof Error?p.message:"创建会话副本失败")}finally{ln(!1)}}},Ks=()=>{On.current=!0,gr.current+=1,window.agentApi&&window.agentApi.abort($||void 0),Pe.current=null,C(null),cn.current.clear()},Gs=async o=>{const p=n||se;if(!p||!window.agentApi)return;const g=ge.getState().messages.find(b=>b.id===o);if(!(!g||!g.isQueued))try{g.queueItemId&&p.startsWith("runtime:")?Qe(await window.agentApi.steerSessionMessage(p,g.queueItemId),p):(await window.agentApi.steer(g.content,p,g.agentName),ce(o,b=>({...b,isQueued:!1,isSteered:!0}))),ht===o&&(gn(null),Zt(""))}catch(b){Y(b instanceof Error?b.message:"引导失败")}},Qa=o=>{const p=ge.getState().messages.find(g=>g.id===o&&g.isQueued);p&&(gn(o),Zt(p.content))},ts=()=>{gn(null),Zt("")},Zs=async o=>{const p=nr.trim(),g=ge.getState().messages.find(b=>b.id===o&&b.isQueued);if(!(!g||!p))try{g.queueItemId&&($!=null&&$.startsWith("runtime:"))?Qe(await window.agentApi.updateSessionMessage($,g.queueItemId,p),$):ce(o,b=>b.isQueued?{...b,content:p}:b,$||void 0),ts()}catch(b){Y(b instanceof Error?b.message:"排队消息保存失败")}},Ka=async o=>{const p=ge.getState().messages.find(g=>g.id===o&&g.isQueued);if(p){if(!await os(p.content)){Y("复制排队消息失败");return}rr(o),window.setTimeout(()=>rr(g=>g===o?null:g),1200)}},Ga=async o=>{const p=ge.getState().messages,g=p.find(b=>b.id===o&&b.isQueued);if(g)try{g.queueItemId&&($!=null&&$.startsWith("runtime:"))?Qe(await window.agentApi.cancelSessionMessage($,g.queueItemId),$):Se(p.filter(b=>b.id!==o),$||void 0),ht===o&&ts()}catch(b){Y(b instanceof Error?b.message:"排队消息删除失败")}},ns=async(o,p)=>{const g=ge.getState().messages,b=al(g,o,p);if(b!==g){Se(b,$||void 0);const R=b.filter(j=>j.isQueued&&j.queueItemId);if($!=null&&$.startsWith("runtime:")&&R.length>0)try{Qe(await window.agentApi.reorderSessionMessages($,R.map(j=>j.queueItemId)),$)}catch(j){Se(g,$),Y(j instanceof Error?j.message:"排队消息排序保存失败")}}},Za=(o,p)=>{const g=ge.getState().messages.filter(j=>j.isQueued),b=g.findIndex(j=>j.id===o),R=g[b+p];R&&ns(o,R.id)},Ja=async o=>{const p=Yt;if(ir(null),!$||!p||p===o)return;const g=Me.queued.map(q=>q.id),b=g.indexOf(p),R=g.indexOf(o);if(b<0||R<0)return;const j=[...g];j.splice(R,0,j.splice(b,1)[0]);const Q=Me;xn({...Me,queued:j.map((q,F)=>({...Me.queued.find(P=>P.id===q),position:F}))});try{Qe(await window.agentApi.reorderSessionGoals($,j),$)}catch(q){xn(Q),Y(q instanceof Error?q.message:"目标排序保存失败")}},Js=async o=>{if($)try{const p=await window.agentApi.cancelSessionGoal($,o);Qe(p,$),p.active||C(null)}catch(p){Y(p instanceof Error?p.message:"目标删除失败")}};u.useEffect(()=>{ht&&(v.some(o=>o.id===ht&&o.isQueued)||(gn(null),Zt("")))},[ht,v]);async function Lr(o,p,g){var b;On.current=!1,Un.current.add(p),Na(p),Pe.current=p,C(p);try{window.agentApi&&await window.agentApi.run(o.content,p,g,o.agentName,o.images)}catch(R){Y(R instanceof Error?R.message:"Agent run failed")}finally{if(Un.current.delete(p),Os.current.delete(p)){Pe.current=p,C(p);return}const j=(b=window.agentApi)!=null&&b.getSessionGoals?await window.agentApi.getSessionGoals(p).catch(()=>{}):void 0;if(j&&p===(zt.current||et.current)&&Qe(j,p),j!=null&&j.active){Pe.current=p,C(p),f&&f(r,p);return}const Q=On.current?void 0:ge.getState().getMessagesForSession(p).find(q=>q.isQueued&&!q.queueItemId);Q?(ce(Q.id,q=>({...q,isQueued:!1}),p),f&&f(r,p),Lr(Q,p)):(Pe.current=null,C(null),f&&f(r,p))}}const Ys=async()=>{var F,P,ue;if(!Ve.trim()||!zn||Pn>0)return;Pr(window.agentApi,br),Y(null);const o=Ve.trim();if(/^\/loop\b/i.test(o)){const te=o.slice(5).trim();if(Ee(""),A({id:crypto.randomUUID(),role:"user",content:o,timestamp:Date.now()}),/^stop$/i.test(te)){window.agentApi&&(await window.agentApi.cronDeleteAll(),ve([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(te)||te===""){if(window.agentApi){const we=await window.agentApi.cronList();ve(we);const Be=we.length===0?"当前没有定时任务。":we.map((fe,De)=>`**${De+1}.** \`${fe.id.slice(0,6)}\` · ${hs(fe.cron)} · ${fe.enabled?"▶ 启用":"⏸ 已暂停"}
254
- ${fe.prompt}`).join(`
255
-
256
- `);A({id:crypto.randomUUID(),role:"assistant",content:Be,timestamp:Date.now()})}return}const L=te.match(/^(?:pause|暂停)\s+(\S+)$/i);if(L){if(window.agentApi){const we=ye.find(fe=>fe.id.startsWith(L[1])),Be=await window.agentApi.cronPause((we==null?void 0:we.id)??L[1]);if(Be){const fe=await window.agentApi.cronList();ve(fe),A({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${Be.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${L[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const oe=te.match(/^(?:resume|恢复)\s+(\S+)$/i);if(oe){if(window.agentApi){const we=ye.find(fe=>fe.id.startsWith(oe[1])),Be=await window.agentApi.cronResume((we==null?void 0:we.id)??oe[1]);if(Be){const fe=await window.agentApi.cronList();ve(fe),A({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${Be.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${oe[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const le=te.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(le){if(window.agentApi){const we=ye.find(fe=>fe.id.startsWith(le[1]));if(await window.agentApi.cronDelete((we==null?void 0:we.id)??le[1])){const fe=await window.agentApi.cronList();ve(fe),A({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${le[1]}\` 已删除。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${le[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const He=te.match(/^(\S+)\s+(.+)$/s);if(He){const we=He[1],Be=He[2].trim();if(window.agentApi){let fe=n||se;if(!fe){const De=await window.agentApi.createSession(Be.slice(0,60)||"定时任务",r||void 0);fe=De.id,E(De.id),s&&await s(De.id)}try{const De=await window.agentApi.cronCreate(we,Be,{sessionId:fe}),fr=await window.agentApi.cronList();ve(fr),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${De.id.slice(0,6)}\`),${hs(we)}执行:${Be}`,timestamp:Date.now()})}catch(De){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${De instanceof Error?De.message:String(De)}`,timestamp:Date.now()})}}return}A({id:crypto.randomUUID(),role:"assistant",content:"**定时任务用法:**\n- `/loop <间隔/cron> <任务>` — 创建,如 `/loop 5m 检查系统状态` 或 `/loop 0 9 * * * 早报`\n- `/loop list` — 查看所有定时任务\n- `/loop pause <id>` — 暂停\n- `/loop resume <id>` — 恢复\n- `/loop delete <id>` — 删除\n- `/loop stop` — 删除全部\n\n间隔支持:`30s`、`5m`、`2h`;也支持 5 字段 cron 表达式。",timestamp:Date.now()});return}const p=o.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(p){const te=p[1]+p[2],L=p[3].trim();if(L&&window.agentApi){let oe=n||se;if(!oe){const le=await window.agentApi.createSession(L.slice(0,60)||"定时任务",r||void 0);oe=le.id,E(le.id),s&&await s(le.id)}try{const le=await window.agentApi.cronCreate(te,L,{sessionId:oe}),He=await window.agentApi.cronList();ve(He),Ee(""),A({id:crypto.randomUUID(),role:"user",content:o,timestamp:Date.now()}),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${le.id.slice(0,6)}\`),${hs(te)}执行:${L}`,timestamp:Date.now()})}catch(le){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${le instanceof Error?le.message:String(le)}`,timestamp:Date.now()})}return}}const g=Ve.trim(),b=g.match(/^\/goal(?:\s+([\s\S]+))?$/i),R=b?((F=b[1])==null?void 0:F.trim())??"":at?g:null;if(R!==null&&!R){Y("请输入目标内容");return}const j=_e.length>0?_e.map(te=>te.name).join(", "):void 0,Q=bn.length>0?[...bn]:void 0,q=_e.map(te=>te.id);if(ae([]),Ce&&(n||se)&&(dr.current=!0),Ee(""),Ln([]),Et([]),R!==null){const te=crypto.randomUUID();On.current=!1;try{const L=await Ri({text:R,projectId:r??null,sessionId:n||se,createSession:async(le,He)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(le,He)},activateSession:le=>{et.current=le,E(le),Pe.current=le,C(le)},showUserMessage:(le,He)=>A({id:te,role:"user",content:le,timestamp:Date.now(),agentName:j,images:Q,isGoal:!0,goalId:te},He),onSessionCreated:s}),oe=await window.agentApi.enqueueSessionGoal(L,R,te);Qe(oe,L),i&&i(L,R)}catch(L){C(null),Y(L instanceof Error?L.message:"目标创建失败")}return}if($t){const te=crypto.randomUUID(),L={id:te,role:"user",content:g,timestamp:Date.now(),agentName:j,images:Q,isQueued:!0};if(Ce&&It&&$&&((P=window.agentApi)!=null&&P.enqueueSessionMessage))try{const oe=await window.agentApi.enqueueSessionMessage($,{sourceMessageId:te,content:g,images:Q,agentIds:q,agentName:j});Qe(oe,$),((ue=oe.active)==null?void 0:ue.sourceMessageId)===te&&A({...L,isQueued:!1},$)}catch(oe){Ee(g),Et(Q??[]),Y(oe instanceof Error?oe.message:"排队消息保存失败")}else A(L);return}he([]);try{const te=await Ri({text:g,projectId:r??null,sessionId:n||se,createSession:async(L,oe)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(L,oe)},activateSession:L=>{et.current=L,E(L),Pe.current=L,C(L)},showUserMessage:(L,oe)=>A({id:crypto.randomUUID(),role:"user",content:L,timestamp:Date.now(),agentName:j,images:Q},oe),onSessionCreated:s});i&&i(te,g),await Lr({content:g,agentName:j,images:Q},te,q.length>0?q:void 0)}catch(te){Y(te instanceof Error?te.message:"Agent run failed")}};return u.useEffect(()=>{if(!y||!window.agentApi)return;const{text:o,projectId:p,sessionId:g}=y;let b=!1;return(async()=>{try{he([]);const R=await Fl({text:o,projectId:p,sessionId:g,createSession:async(j,Q)=>await window.agentApi.createSession(j,Q),activateSession:j=>{et.current=j,E(j),Pe.current=j,C(j)},showUserMessage:(j,Q)=>A({id:crypto.randomUUID(),role:"user",content:j,timestamp:Date.now()},Q),onSessionCreated:s,isCancelled:()=>b});if(!R)return;i&&i(R,o),await Lr({content:o},R)}catch(R){Y(R instanceof Error?R.message:"语音指令执行失败")}})(),()=>{b=!0}},[y==null?void 0:y.nonce]),e.jsxs("div",{className:"chat-view chat-view--codex-history",style:{display:"flex",flexDirection:"column",height:"100%",maxWidth:"var(--chat-max-width)",margin:"0 auto"},children:[e.jsxs("div",{className:"chat-top-bar",style:{display:"flex",alignItems:"center",padding:"var(--chat-header-padding)",height:"var(--chat-header-height)",flexShrink:0,borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"no-drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:h?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:h||"会话"}),S&&N&&O&&e.jsx(Ml,{appearanceOpen:K,settingsOpen:I,hideToBackgroundTitle:U,onHideToBackground:N,onToggleAppearance:O,onOpenSettings:S})]}),e.jsxs("div",{ref:mt,className:"chat-messages",onScroll:yt,style:{flex:1,overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[v.length>0&&(Bn||Dn)&&e.jsx("div",{className:"chat-history-page-status",role:Dn?"alert":"status",style:{position:"absolute",top:8,left:"50%",transform:"translateX(-50%)",zIndex:2,minHeight:32,display:"flex",alignItems:"center",justifyContent:"center",gap:7,color:Dn?"var(--danger)":"var(--text-muted)",fontSize:12},children:Bn?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载更早消息"})]}):e.jsxs("button",{type:"button",onClick:()=>void es(),className:"chat-history-retry",style:{border:"1px solid color-mix(in srgb, var(--danger) 30%, transparent)",background:"color-mix(in srgb, var(--danger) 7%, transparent)",color:"var(--danger)",borderRadius:6,padding:"5px 10px",cursor:"pointer",fontSize:12},children:[Dn,",点击重试"]})}),v.length===0&&ur&&Wr&&e.jsxs("div",{className:"chat-history-initial-loading",role:"status",style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:9,color:"var(--text-muted)",fontSize:13},children:[e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}),e.jsx("span",{children:"正在加载历史消息"})]}),v.length===0&&!Rt&&!ur&&!mn&&e.jsx(zl,{agentType:(x==null?void 0:x.agentType)??t,ready:zn,onSelectPrompt:_a},$??"initial-empty-session"),be.map((o,p)=>{var oe,le,He,we,Be,fe,De,fr,hr;const g=o;if(g.isQueued)return null;const b=o.role==="user",R=b&&(g.isGoal===!0||[Me.active,...Me.queued,...Me.history].some(V=>!!(V&&Ei(V.objective)===Ei(o.content)))),j=ed(be,p,Rt),Q=Zl((oe=g.presentation)==null?void 0:oe.completionDurationMs);if(g.isCompactionSummary)return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,margin:"20px 0",color:"var(--text-muted)",fontSize:12},children:[e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",borderRadius:20,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:11,cursor:"default",userSelect:"none"},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"17 1 21 5 17 9"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("polyline",{points:"7 23 3 19 7 15"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),"上下文已压缩"]}),e.jsx("div",{style:{flex:1,height:1,background:"var(--border-subtle)"}})]},o.id);if(g.widget){const V=Pl[g.widget.widgetType];return V?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(V,{...g.widget.data,widgetId:g.widget.widgetId})},o.id):e.jsx("div",{style:{marginBottom:16,padding:12,borderRadius:8,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono, monospace)",fontSize:12,whiteSpace:"pre-wrap",maxHeight:300,overflow:"auto"},children:JSON.stringify(g.widget.data,null,2)},o.id)}if(g.askUser)return e.jsx(Cl,{questionId:g.askUser.questionId,question:g.askUser.question,options:g.askUser.options,fields:g.askUser.fields,multiSelect:g.askUser.multiSelect,answered:g.askUser.answered,answer:g.askUser.answer,onAnswer:(V,Te)=>{var Ut;ce(o.id,me=>({...me,askUser:{...me.askUser,answered:!0,answer:V}})),(Ut=window.agentApi)==null||Ut.answerQuestion(g.askUser.questionId,V,Te)}},o.id);const q=g.agentName?g.agentName.charAt(0).toUpperCase():"你",F=!b&&p===be.length-1,P=be[p+1],ue=P&&P.role!==o.role&&!P.isCompactionSummary,te=(o.toolCalls??[]).map((V,Te)=>{let Ut;if(V.name==="write_file"&&V.arguments.file_path){const me=V.arguments.file_path;e:for(let dt=p;dt>=0;dt--){const qt=be[dt].toolCalls;if(!qt)continue;const xr=dt===p?Te-1:qt.length-1;for(let kn=xr;kn>=0;kn--){const Ht=qt[kn];if(Ht.name==="read_file"&&Ht.arguments.file_path===me&&Ht.result&&!Ht.isError){Ut=Ht.result;break e}}}}return{toolCall:V,beforeContent:Ut,progress:Lo(Ar,V.id),nativeSubagent:Gr[V.id]}}),L=Gl(te);return e.jsx("div",{className:`chat-message-group${j.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:j.compact?0:ue?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:e.jsxs("div",{className:`chat-message-row chat-message-row--${b?"user":"assistant"}`,style:{display:"flex",flexDirection:b?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[b?e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--accent)",color:"#fff",fontSize:12,fontWeight:700,letterSpacing:0,userSelect:"none"},children:q}):e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("path",{d:"M12 11V7"}),e.jsx("circle",{cx:"12",cy:"5",r:"2"}),e.jsx("circle",{cx:"8",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"16",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M8 20h8"})]})}),e.jsxs("div",{className:`chat-message-content chat-message-content--${b?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:b?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${b?"user":"assistant"} ${o.role==="assistant"&&o.content?"message-card":""}`,style:{padding:o.content||b&&((le=g.images)!=null&&le.length)?b?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:b?"14px 4px 14px 14px":"4px 14px 14px 14px",background:o.content||b&&((He=g.images)!=null&&He.length)?b?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:o.content||b&&((we=g.images)!=null&&we.length)?b?"1px solid rgba(79, 110, 247, 0.18)":void 0:"none",fontSize:"var(--chat-bubble-font-size)",lineHeight:"var(--chat-bubble-line-height)",color:"var(--text-primary)",letterSpacing:"0.01em"},children:[o.role==="assistant"&&((Be=o.presentation)==null?void 0:Be.reasoning)&&e.jsx(Rl,{sections:o.presentation.reasoning,streaming:Rt&&F&&Xn==="thinking",startedAt:gt,renderContent:xs}),b&&g.agentName?e.jsxs("div",{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:10,fontWeight:700,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:10,padding:"1px 7px 1px 5px",letterSpacing:"0.04em",marginRight:7,verticalAlign:"middle"},children:[e.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),g.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:o.content})]}):o.role==="assistant"&&o.content?e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:xs(o.content)}):o.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:b?o.content:xs(o.content)}),b&&g.images&&g.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:o.content?8:0},children:g.images.map((V,Te)=>e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":"放大查看图片",onClick:()=>pe({src:V,alt:`用户发送的图片 ${Te+1}`}),children:e.jsx("img",{className:"chat-message-attachment-image",src:V,alt:`用户发送的图片 ${Te+1}`})},Te))}),b&&!((fe=g.images)!=null&&fe.length)&&((De=g.presentation)==null?void 0:De.attachments)&&g.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:g.presentation.attachments.map((V,Te)=>V.dataUrl?e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":`放大查看图片:${V.name}`,onClick:()=>pe({src:V.dataUrl,alt:V.name}),children:e.jsx("img",{className:"chat-message-attachment-image",src:V.dataUrl,alt:V.name,title:V.name})},`${V.name}-${Te}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${V.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:V.name}),e.jsx("span",{children:"图片已失效"})]},`${V.name}-${Te}`))}),b&&((fr=g.presentation)==null?void 0:fr.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:g.presentation.rawContent})]}),L.map(V=>V.action&&V.items.length>1?e.jsx(kl,{items:V.items,onSelectSession:l,workspacePath:m,enableFilePreview:Hn()},`group-${V.items[0].toolCall.id}`):e.jsx(Fs,{toolCall:V.items[0].toolCall,beforeContent:V.items[0].beforeContent,progress:V.items[0].progress,nativeSubagent:V.items[0].nativeSubagent,onSelectSession:l,workspacePath:m,enableFilePreview:Hn()},V.items[0].toolCall.id)),(()=>{const V=(o.toolCalls??[]).filter(me=>me.name==="write_file"&&me.result&&!me.isError);if(V.length===0)return null;const Te=new Map;for(const me of V){const dt=me.arguments.file_path??"",qt=me.arguments.content??"",xr=qt?qt.split(`
257
- `).length:0;let kn=0;e:for(let Ht=p;Ht>=0;Ht--){const di=be[Ht].toolCalls??[];for(let rs=di.length-1;rs>=0;rs--){const mr=di[rs];if(mr.name==="read_file"&&mr.arguments.file_path===dt&&mr.result&&!mr.isError){kn=mr.result.split(`
258
- `).length;break e}}}Te.set(dt,{path:dt,lines:xr,added:Math.max(0,xr-kn),removed:Math.max(0,kn-xr)})}const Ut=[...Te.values()];return e.jsxs("div",{style:{marginTop:10,padding:"8px 12px",borderRadius:8,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)",display:"flex",flexWrap:"wrap",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",flexShrink:0},children:"变更汇总"}),Ut.map(me=>{const dt=oa(me.path,m),qt=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:me.path,children:me.path.replace(/\\/g,"/").split("/").pop()}),me.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",me.added]}),me.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",me.removed]}),me.added===0&&me.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[me.lines,"行"]})]});return Hn()&&dt?e.jsx("button",{type:"button",className:"chat-file-change-link",onClick:()=>Tn(dt),title:`预览 ${dt}`,"aria-label":`预览改动文件 ${me.path.replace(/\\/g,"/").split("/").pop()}`,children:qt},me.path):e.jsx("span",{className:"chat-file-change-link chat-file-change-link--static",children:qt},me.path)})]})})()]}),j.showCompletion&&e.jsxs("div",{className:"msg-completion-footer",children:[e.jsxs("span",{className:"msg-completion-status",children:[e.jsx(Or,{size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"已完成"}),Q&&e.jsxs("span",{children:[" · 总耗时 ",Q]})]}),e.jsxs("span",{className:"msg-completion-actions",children:[!Hn()&&j.showSpeak&&typeof((hr=window.agentApi)==null?void 0:hr.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>Ma(o.id,o.content),title:re===o.id?"停止播报":"语音播报","aria-label":re===o.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${re===o.id?"is-active":""}`,children:re===o.id?e.jsx(Mo,{size:12,fill:"currentColor","aria-hidden":"true"}):e.jsx(Eo,{size:13,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{os(o.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(ss,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]})]}),!j.showCompletion&&(j.showCopy||R)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[R&&e.jsx("span",{className:"ui-icon-button ui-icon-button--small msg-action-button msg-goal-marker",title:"目标消息","aria-label":"目标消息",role:"img",children:e.jsx(is,{size:13,strokeWidth:1.9,"aria-hidden":"true"})}),j.showCopy&&e.jsx("button",{type:"button",onClick:()=>{os(o.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(ss,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]}),b&&(g.isQueued||g.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[g.isQueued&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--text-muted)",padding:"2px 8px",borderRadius:20,background:"var(--bg-deep)",border:"1px solid var(--border-subtle)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"排队中"]}),Sr&&e.jsxs("button",{onClick:()=>void Gs(o.id),title:"将此消息引导到当前对话",style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)",padding:"2px 10px",borderRadius:20,border:"1px solid rgba(79,110,247,0.3)",background:"var(--accent-dim)",cursor:"pointer",transition:"all 0.15s",fontFamily:"var(--font-body)"},onMouseEnter:V=>{V.currentTarget.style.background="rgba(79,110,247,0.18)",V.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:V=>{V.currentTarget.style.background="var(--accent-dim)",V.currentTarget.style.borderColor="rgba(79,110,247,0.3)"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"}),e.jsx("path",{d:"M12 3v18",opacity:"0.3"})]}),"引导"]})]}),g.isSteered&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--success)",padding:"2px 8px",borderRadius:20,background:"rgba(34,197,94,0.08)",border:"1px solid rgba(34,197,94,0.2)"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"已引导"]})]})]})]})},o.id)}),Rt&&Kt&&e.jsx(pa,{progress:Kt,startedAt:gt}),Gt&&e.jsx("div",{className:"chat-message-activity",style:{display:"flex",alignItems:"flex-start",padding:"4px 0 4px",animation:"fadeInUp 0.3s var(--ease-out)"},children:e.jsx(Tl,{startedAt:gt})}),(Xt||mn)&&e.jsxs("div",{style:{padding:12,margin:"8px 0",borderRadius:"var(--radius-sm)",background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",color:"var(--danger)",fontSize:13,animation:"fadeIn 0.2s var(--ease-out)",fontFamily:"var(--font-mono)",display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{flex:1,minWidth:0},children:Xt||mn}),Xt&&e.jsxs("button",{type:"button",onClick:()=>Rr(o=>o+1),"aria-label":"重新加载会话",title:"重新加载会话",style:{flexShrink:0,minHeight:30,display:"inline-flex",alignItems:"center",gap:5,padding:"5px 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:5,background:"var(--bg-workspace)",color:"var(--danger)",cursor:"pointer",fontSize:12},children:[e.jsx(ea,{size:14,"aria-hidden":"true"}),"重新加载"]})]}),e.jsx("div",{ref:Ke})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[Dt&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:9,padding:"8px 10px",border:"1px solid var(--border-default)",borderRadius:6,background:"var(--bg-surface)",color:Qt==="incompatible"?"var(--danger)":"var(--text-muted)",fontSize:12},children:e.jsx("span",{style:{flex:1},children:Qt==="incompatible"?Bt||((ni=x==null?void 0:x.compatibility)==null?void 0:ni.reason)||`Codex ${((ri=x==null?void 0:x.compatibility)==null?void 0:ri.producerVersion)??"未知版本"} 与当前 ${((si=x==null?void 0:x.compatibility)==null?void 0:si.readerVersion)??"运行时"} 不兼容`:`正在使用 Codex ${((ii=x==null?void 0:x.compatibility)==null?void 0:ii.readerVersion)??"当前版本"} 验证此会话`})}),((x==null?void 0:x.occupancy)==="owned-externally"||At)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:9,padding:"8px 10px",border:"1px solid var(--border-default)",borderRadius:6,background:"var(--bg-surface)",color:"var(--text-muted)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2"}),e.jsx("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]}),e.jsx("span",{style:{flex:1},children:Ni(x,Fe)?"此会话仍由原客户端持有,可创建副本继续。":`此会话正在被 ${(x==null?void 0:x.sourceLabel)||"原客户端"} 使用,当前只读;原客户端释放后会自动恢复输入。`}),Ni(x,Fe)&&e.jsx("button",{type:"button",onClick:()=>void Va(),disabled:on,style:{flexShrink:0,border:"1px solid var(--border-default)",borderRadius:5,padding:"5px 9px",background:"var(--bg-workspace)",color:"var(--text-primary)",fontSize:12,fontWeight:600,cursor:on?"wait":"pointer",opacity:on?.65:1},children:on?"正在创建…":"以副本继续"})]}),de.length>0&&e.jsxs("div",{style:{marginBottom:10,padding:"8px 12px",borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",boxShadow:"var(--shadow-sm)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,marginBottom:6,fontSize:10,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),"任务列表"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(()=>{const o=new Set(de.filter(p=>p.status==="completed").map(p=>p.title.toLowerCase()));return de.map(p=>{const g=p.status==="pending",b=p.status==="in-progress",R=p.status==="completed",j=g&&(p.dependsOn??[]).some(Q=>!o.has(Q.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:R?.65:1,transition:"opacity 0.3s"},children:[e.jsxs("div",{style:{width:16,height:16,borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:R?"rgba(52,211,153,0.15)":b?"var(--accent-dim)":j?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:R?"1.5px solid rgba(52,211,153,0.6)":b?"1.5px solid var(--accent)":j?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[R&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(52,211,153,0.9)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})}),b&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),j&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(239,68,68,0.8)",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})}),g&&!j&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:R?"var(--text-muted)":j?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:R?"line-through":"none",flex:1},children:p.title}),j&&e.jsx("span",{title:`等待: ${(p.dependsOn??[]).join(", ")}`,style:{fontSize:10,color:"rgba(239,68,68,0.9)",background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:"等待前置"}),p.agentName&&e.jsxs("span",{style:{fontSize:10,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.2)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:["@",p.agentName]})]},p.id)})})()})]}),ye.length>0&&e.jsxs("div",{style:{marginBottom:10,borderRadius:10,background:"var(--bg-surface)",border:"1px solid rgba(251,191,36,0.25)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderBottom:"1px solid rgba(251,191,36,0.15)",background:"rgba(251,191,36,0.06)"},children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#d97706",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",textTransform:"uppercase",letterSpacing:"0.07em",flex:1},children:"定时任务"}),e.jsx("button",{onClick:async()=>{window.agentApi&&(await window.agentApi.cronDeleteAll(),ve([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}))},title:"删除全部",style:{background:"none",border:"1px solid rgba(251,191,36,0.35)",borderRadius:6,color:"#d97706",cursor:"pointer",padding:"1px 7px",fontSize:10},children:"全部删除"})]}),ye.map(o=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:o.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:o.enabled?"#22c55e":"#9ca3af",boxShadow:o.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:o.enabled?"pulse 2s ease-in-out infinite":"none"}}),e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#d97706",background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.25)",borderRadius:6,padding:"1px 6px",flexShrink:0,fontFamily:"var(--font-mono)"},children:o.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.label||o.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:o.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[o.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(o.id);const p=await window.agentApi.cronList();ve(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="#d97706",p.currentTarget.style.color="#d97706"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(o.id);const p=await window.agentApi.cronList();ve(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="#22c55e",p.currentTarget.style.color="#22c55e"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(o.id);const p=await window.agentApi.cronList();ve(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="var(--danger)",p.currentTarget.style.color="var(--danger)"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},o.id))]}),_n.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:_n.map((o,p)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"3px 10px 3px 8px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.18)",fontSize:12,color:"var(--accent)",maxWidth:220},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.name}),e.jsx("button",{onClick:()=>Ba(p),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,marginLeft:2,fontSize:13,lineHeight:1,display:"flex"},children:"✕"})]},p))}),bn.length>0&&(()=>{const o=wt.find(g=>g.id===jt),p=!Ce&&(!o||!Xr(o.modelId));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[p&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:"rgba(234,179,8,0.1)",border:"1px solid rgba(234,179,8,0.4)",color:"rgba(202,138,4,1)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"当前模型(",(o==null?void 0:o.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:bn.map((g,b)=>e.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[e.jsx("button",{type:"button",className:"chat-message-image-button pending-image-preview-button","aria-label":`预览待发送图片 ${b+1}`,onClick:()=>pe({src:g,alt:`待发送图片 ${b+1}`}),children:e.jsx("img",{src:g,alt:`待发送图片 ${b+1}`,style:{width:72,height:72,objectFit:"cover",borderRadius:8,border:"1.5px solid var(--border-default)",display:"block"}})}),e.jsx("button",{type:"button","aria-label":`删除待发送图片 ${b+1}`,onClick:()=>Oa(b),style:{position:"absolute",top:-6,right:-6,width:18,height:18,borderRadius:"50%",background:"var(--danger, #e53e3e)",border:"none",color:"#fff",fontSize:11,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},children:"✕"})]},b))})]})})(),(Me.active||Me.queued.length>0)&&e.jsxs("div",{className:"goal-queue","aria-label":"目标队列",children:[e.jsxs("div",{className:"goal-queue__header",children:[e.jsx(is,{size:14,strokeWidth:1.9,"aria-hidden":"true"}),e.jsx("span",{children:"目标"}),e.jsx("span",{className:"goal-queue__count",children:Me.queued.length+(Me.active?1:0)})]}),Me.active&&e.jsxs("div",{className:"goal-queue__row is-active",children:[e.jsx("span",{className:"goal-queue__state",children:"进行中"}),e.jsx("span",{className:"goal-queue__objective",title:Me.active.objective,children:Me.active.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Js(Me.active.id)},title:"停止当前目标","aria-label":"停止当前目标",children:e.jsx(Ur,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]}),Me.queued.map((o,p)=>e.jsxs("div",{className:`goal-queue__row is-queued${Yt===o.id?" is-dragging":""}`,draggable:!0,onDragStart:()=>ir(o.id),onDragEnd:()=>ir(null),onDragOver:g=>g.preventDefault(),onDrop:()=>{Ja(o.id)},children:[e.jsx(ci,{className:"goal-queue__grip",size:14,strokeWidth:1.8,"aria-hidden":"true"}),e.jsxs("span",{className:"goal-queue__state",children:["#",p+1]}),e.jsx("span",{className:"goal-queue__objective",title:o.objective,children:o.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Js(o.id)},title:"移出目标队列","aria-label":"移出目标队列",children:e.jsx(Ur,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]},o.id))]}),(()=>{const o=v.filter(p=>p.isQueued);return o.length===0?null:e.jsx("div",{className:"queued-message-list",children:o.map(p=>{const g=p,b=ht===p.id,R=g.content.length>80?g.content.slice(0,80)+"…":g.content;return e.jsxs("div",{className:`queued-message-row${Ze===p.id?" is-dragging":""}`,"data-queued-message-id":p.id,onDragOver:j=>{!Ze||Ze===p.id||(j.preventDefault(),j.dataTransfer.dropEffect="move")},onDrop:j=>{j.preventDefault(),Ze&&ns(Ze,p.id),Je(null)},children:[e.jsx("button",{type:"button",className:"queued-message-grip",draggable:!b,"aria-label":"拖动调整排队顺序",title:"拖动调整顺序",onDragStart:j=>{Je(p.id),j.dataTransfer.effectAllowed="move",j.dataTransfer.setData("text/plain",p.id)},onDragEnd:()=>Je(null),onKeyDown:j=>{(j.key==="ArrowUp"||j.key==="ArrowDown")&&(j.preventDefault(),Za(p.id,j.key==="ArrowUp"?-1:1))},onPointerDown:j=>{j.pointerType==="mouse"||b||(fn.current={id:p.id,pointerId:j.pointerId},j.currentTarget.setPointerCapture(j.pointerId),Je(p.id))},onPointerMove:j=>{var P;const Q=fn.current;if(!Q||Q.pointerId!==j.pointerId)return;j.preventDefault();const q=(P=document.elementFromPoint(j.clientX,j.clientY))==null?void 0:P.closest("[data-queued-message-id]"),F=q==null?void 0:q.dataset.queuedMessageId;F&&F!==Q.id&&ns(Q.id,F)},onPointerUp:j=>{var Q;((Q=fn.current)==null?void 0:Q.pointerId)===j.pointerId&&(fn.current=null,Je(null))},onPointerCancel:()=>{fn.current=null,Je(null)},children:e.jsx(ci,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsxs("div",{className:"queued-message-content",children:[g.agentName&&e.jsxs("span",{className:"queued-message-agent",children:["@",g.agentName]}),b?e.jsx("input",{autoFocus:!0,className:"queued-message-edit-input",value:nr,onChange:j=>Zt(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.nativeEvent.isComposing?(j.preventDefault(),Zs(p.id)):j.key==="Escape"&&(j.preventDefault(),ts())},"aria-label":"编辑排队消息内容"}):e.jsx("span",{className:"queued-message-text",title:g.content,children:R})]}),e.jsxs("div",{className:"queued-message-actions",children:[Sr&&e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--accent",onClick:()=>void Gs(p.id),title:"引导到当前对话","aria-label":"引导排队消息到当前对话",children:e.jsx(co,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>void Ka(p.id),title:Tr===p.id?"已复制":"复制","aria-label":"复制排队消息",children:Tr===p.id?e.jsx(Or,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(ss,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>b?Zs(p.id):Qa(p.id),disabled:b&&!nr.trim(),title:b?"保存":"编辑","aria-label":b?"保存排队消息":"编辑排队消息",children:b?e.jsx(Or,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Xi,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--danger",onClick:()=>Ga(p.id),title:"删除","aria-label":"删除排队消息",children:e.jsx(Ur,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]})]},p.id)})})})(),e.jsx("div",{ref:W,className:"composer-anchor",style:{position:"relative"},children:e.jsx("div",{className:"composer-shell",style:{display:"flex",flexDirection:"column",gap:0,background:"var(--bg-surface)",borderRadius:14,overflow:"visible"},children:e.jsxs("div",{className:"composer-input-row",style:{display:"flex",alignItems:"center",gap:8,padding:"var(--composer-row-padding)"},children:[e.jsx("input",{ref:w,type:"file",multiple:!0,style:{display:"none"},onChange:Pa}),_e.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:_e.map(o=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"2px 7px 2px 6px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.25)",fontSize:12,color:"var(--accent)",flexShrink:0,whiteSpace:"nowrap"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]}),"@",o.name,e.jsx("button",{onClick:()=>za(o.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},o.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:T,rows:3,value:Ve,onChange:o=>qs(o.target.value),onBlur:()=>setTimeout(()=>{Ae(null),Le(null)},120),onKeyDown:La,placeholder:Dt?Qt==="incompatible"?"Codex 版本不兼容":"正在验证会话兼容性":Ft?"原客户端使用中,当前只读":Tt?at?"输入要持续推进的目标":$t?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!zn}),e.jsxs("div",{className:"web-native-composer-toolbar",children:[e.jsxs("div",{className:"web-native-add-wrap",children:[e.jsx("button",{type:"button",className:"web-native-add-button","aria-label":"添加附件、图片或语音","aria-expanded":sr,onClick:()=>Mt(o=>!o),children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})}),sr&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var o;Mt(!1),(o=w.current)==null||o.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{Mt(!1),Ra()},children:"语音输入"})]})]}),e.jsx("button",{type:"button",className:`web-native-runtime-status goal-mode-toggle${at?" is-active":""}`,"aria-pressed":at,"aria-label":at?"关闭目标模式":"开启目标模式",title:at?"目标模式已开启":"目标模式",onClick:()=>Zr(o=>!o),children:e.jsx(is,{size:18,strokeWidth:1.9,"aria-hidden":"true"})}),e.jsxs("div",{className:"web-native-permission-wrap",ref:ar,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${$e}`,"aria-label":`会话权限:${(ai=qr.find(o=>o.value===$e))==null?void 0:ai.label}`,"aria-haspopup":"menu","aria-expanded":hn,title:`会话权限:${(oi=qr.find(o=>o.value===$e))==null?void 0:oi.label}`,disabled:!$||Nt,onClick:()=>it(o=>!o),children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),hn&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:qr.map(o=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":$e===o.value,className:$e===o.value?"is-active":"",onClick:()=>{qa(o.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:$e===o.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:o.label}),e.jsx("small",{children:o.description})]})]},o.value))})]}),Ce&&(x==null?void 0:x.controller)==="web"&&typeof((li=window.agentApi)==null?void 0:li.handoffSession)=="function"&&e.jsx("button",{type:"button",className:"web-native-runtime-status",onClick:()=>{Ha()},title:"交接到 Desktop",children:"交接到 Desktop"}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Al,{usage:$?Ge[$]:void 0,contextWindowK:Pt,compact:!0})}),e.jsx("label",{className:"web-native-model-control",title:"切换模型",children:e.jsx("select",{"aria-label":"当前模型",value:Ce?"":jt,disabled:Ce||wt.length===0,onChange:o=>{ct(o.target.value)},children:Ce?e.jsx("option",{value:"",children:(x==null?void 0:x.agentType)??"本地 Agent"}):wt.length===0?e.jsx("option",{value:"",children:"未配置模型"}):wt.map(o=>e.jsx("option",{value:o.id,children:o.name||o.modelId},o.id))})}),pn?e.jsx("button",{type:"button",onClick:Ks,className:"web-native-stop-button","aria-label":"停止生成",title:"停止生成",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):Ce?e.jsxs("span",{className:"web-native-agent-status",role:"status","aria-label":"Agent 空闲",title:"Agent 空闲",children:[e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]}),e.jsx("span",{"aria-hidden":"true"})]}):e.jsxs("div",{className:"web-native-effort-wrap",ref:ze,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Jt,"aria-label":`推理强度:${Wi[ut]}`,title:`推理强度:${Wi[ut]}(点击切换)`,onClick:()=>st(o=>!o),children:e.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9.5 4.5A3.5 3.5 0 0 0 6 8v1a3 3 0 0 0-2 2.83V14a3 3 0 0 0 3 3h.25A3.75 3.75 0 0 0 11 20.75V3.25A3.75 3.75 0 0 0 9.5 4.5Z"}),e.jsx("path",{d:"M14.5 4.5A3.5 3.5 0 0 1 18 8v1a3 3 0 0 1 2 2.83V14a3 3 0 0 1-3 3h-.25A3.75 3.75 0 0 1 13 20.75V3.25a3.75 3.75 0 0 1 1.5 1.25Z"})]})}),Jt&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:ja.map(o=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":ut===o.value,className:ut===o.value?"is-active":void 0,onClick:()=>{xe("reasoningEffort",o.value),Yn(),st(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:ut===o.value?"✓":""}),o.label]},o.value))})]}),e.jsx("button",{type:"button",onClick:Ys,disabled:!zn||Pn>0||!Ve.trim(),className:"web-native-send-button","aria-label":$t?"排队发送":"发送",title:$t?"排队发送":"发送",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 19V5M5 12l7-7 7 7"})})})]})]})})}),e.jsxs("div",{className:"chat-composer-hint",style:{textAlign:"center",marginTop:7,fontSize:11,color:"var(--text-muted)",letterSpacing:"0.03em",opacity:.6},children:["Enter 发送",at?"目标":$t?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",je?" · 🎤 正在聆听…":""]})]}),e.jsx(Wl,{image:Nr,onClose:()=>pe(null)}),z&&Z!==null&&Us.length>0&&Vt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-z.top+8,left:z.left,width:z.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",overflow:"hidden",zIndex:99999},children:[e.jsx("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em"},children:"智能体"}),Us.map(o=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),Ea(o)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:p=>{p.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:p=>{p.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",o.name]}),o.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:o.description})]},o.id))]}),document.body),z&&Ye!==null&&Yr.length>0&&Vt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-z.top+8,left:z.left,width:z.width,background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:10,boxShadow:"var(--shadow-md)",zIndex:99999,display:"flex",flexDirection:"column",maxHeight:320},children:[e.jsxs("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",flexShrink:0},children:["技能 (",Yr.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:Yr.map(o=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),Wa(o)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:p=>{p.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:p=>{p.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",o.name]}),o.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.description})]},o.name))})]}),document.body)]})}function ms({status:t,isRunning:r,needsInput:n}){return t==="failed"||t==="error"?"error":r?n?"needs-input":"running":"completed"}const bs={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function ka(t,r){return t.map((n,s)=>({session:n,index:s})).sort((n,s)=>r(n.session,s.session)||n.index-s.index).map(({session:n})=>n)}function $s(t){return ka(t,(r,n)=>n.created.localeCompare(r.created))}function dd(t,r){return ka($s(t),(n,s)=>Number(r(s))-Number(r(n)))}const Li={projectId:null,sessionId:null};function Ms(t){return typeof t=="string"&&t.trim()?t.trim():null}function Pi(t){return{projectId:Ms(t),sessionId:null}}function ys(t,r){return{projectId:Ms(t),sessionId:Ms(r)}}function cd(t){return t.agentType==="customer-agent"?`确定永久删除会话“${t.title}”吗?此操作不可恢复。`:t.agentType==="codex"?`确定归档 Codex 会话“${t.title}”并从 AgentRoam 中移除吗?可在 Codex 的已归档会话中恢复。`:`确定从 AgentRoam 中移除会话“${t.title}”吗?原生客户端中的历史记录会保留。`}function ud(t,r){const n=new Set(r);return{...t,selectedSessionId:t.selectedSessionId&&n.has(t.selectedSessionId)?null:t.selectedSessionId,sessions:Object.fromEntries(Object.entries(t.sessions).map(([s,i])=>[s,{...i,data:i.data.filter(a=>!n.has(a.id))}]))}}function pd(t,r){const n=new Set(r);let s=!1;const i=Object.fromEntries(Object.entries(t).map(([a,l])=>{const c=l.filter(f=>!n.has(f.id));return c.length!==l.length&&(s=!0),[a,c.length===l.length?l:c]}));return s?i:t}function gd(t,r,n,s){const i=[s,...(r[s]??[]).map(c=>c.id)],a=new Set(i),l=Object.fromEntries(Object.entries(r).flatMap(([c,f])=>{if(a.has(c))return[];const h=f.filter(x=>!a.has(x.id));return[[c,h.length===f.length?f:h]]}));return{sessionsByProject:pd(t,i),childSessionsByParent:l,otherLocalSessions:n.filter(c=>!a.has(c.id)),removedIds:i}}const fd=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Bi={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function Di(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function hd(){const{maxIterations:t,contextWindow:r,isConfigured:n,profiles:s,activeProfileId:i,setField:a,loadFromSystem:l,saveToSystem:c,addProfile:f,updateProfile:h,deleteProfile:x,switchActiveProfile:m}=Qr(),[S,I]=u.useState(null),[N,O]=u.useState("success"),[K,U]=u.useState(null),[y,v]=u.useState(!1),[B,H]=u.useState(Di());u.useEffect(()=>{l()},[]);const A=()=>{v(!0),U(null),H(Di())},C=G=>{v(!1),U(G.id),H({name:G.name,provider:G.provider,modelId:G.modelId,apiKey:G.apiKey==="managed"?"":G.apiKey,baseUrl:G.baseUrl})},E=()=>{U(null),v(!1)},M=async()=>{if(!B.name.trim()||!B.apiKey.trim()||!B.modelId.trim()){I("名称、API Key 和模型 ID 为必填项"),O("error");return}y?f(B):K&&h(K,B),U(null),v(!1),I(null),setTimeout(()=>c(),0)},_=async G=>{x(G),setTimeout(()=>c(),0)},ne=async G=>{await m(G),I("已切换模型"),O("success"),setTimeout(()=>I(null),1500)},ce=async()=>{I(null);try{await c(),I("设置保存成功"),O("success")}catch(G){I(G instanceof Error?G.message:"保存失败"),O("error")}},Se=y||K!==null;return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:640,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"设置"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:36},children:"管理模型提供商和运行参数。工作目录在项目设置中配置。"}),e.jsxs("section",{style:{marginBottom:40},children:[e.jsxs("div",{className:"settings-head-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:14},children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",margin:0},children:"模型提供商"}),e.jsx("button",{onClick:A,style:md,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.length===0&&!Se&&e.jsx("div",{style:{padding:"20px 16px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),s.map(G=>{const Ge=G.id===i,vt=G.id===K;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${Ge?"var(--accent)":"var(--border-default)"}`,background:Ge?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{className:"profile-row",style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px"},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",padding:"2px 7px",borderRadius:4,background:Ge?"var(--accent)":"var(--bg-deep)",color:Ge?"#fff":"var(--text-muted)",flexShrink:0},children:G.provider}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G.name||G.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[G.modelId," ",G.baseUrl?`· ${G.baseUrl}`:""]})]}),Ge&&e.jsx("span",{style:{fontSize:11,color:"var(--accent)",fontWeight:600,flexShrink:0},children:"● 使用中"}),e.jsxs("div",{className:"profile-row-actions",style:{display:"flex",gap:6,flexShrink:0},children:[!Ge&&e.jsx("button",{onClick:()=>ne(G.id),style:vs,children:"切换"}),e.jsx("button",{onClick:()=>vt?E():C(G),style:vs,children:vt?"收起":"编辑"}),e.jsx("button",{onClick:()=>_(G.id),style:{...vs,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),vt&&e.jsx(Fi,{draft:B,setDraft:H,onSave:M,onCancel:E})]},G.id)}),y&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--accent)",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"10px 14px 0",fontSize:13,fontWeight:600,color:"var(--accent)"},children:"新建提供商"}),e.jsx(Fi,{draft:B,setDraft:H,onSave:M,onCancel:E})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},children:"常规"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Cn,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:G=>a("maxIterations",parseInt(G.target.value)||10),min:1,max:50,style:In})}),e.jsx(Cn,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:r??100,onChange:G=>a("contextWindow",parseInt(G.target.value)||100),min:8,max:2e3,style:In})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:ce,style:Sa,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:n?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:n?"var(--success)":"var(--text-muted)",border:`1px solid ${n?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:n?"● 已连接":"○ 未配置"})]}),S&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:N==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:N==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:N==="success"?"var(--success)":"var(--danger)",fontSize:13},children:S})]})}function Fi({draft:t,setDraft:r,onSave:n,onCancel:s}){const i=(a,l)=>r(c=>{const f={...c,[a]:l};return a==="provider"&&!c.modelId&&(f.modelId=Bi[l]??""),f});return e.jsxs("div",{style:{padding:"12px 14px 14px",display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(Cn,{label:"名称",children:e.jsx("input",{value:t.name,onChange:a=>i("name",a.target.value),placeholder:"我的 Claude",style:In})}),e.jsx(Cn,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:a=>{i("provider",a.target.value),i("modelId",Bi[a.target.value]??"")},style:In,children:fd.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})})]}),e.jsx(Cn,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:a=>i("modelId",a.target.value),placeholder:"claude-sonnet-4-6",style:In})}),e.jsx(Cn,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:a=>i("apiKey",a.target.value),placeholder:"sk-...",style:In})}),e.jsx(Cn,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:a=>i("baseUrl",a.target.value),placeholder:"https://api.anthropic.com",style:In})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:n,style:Sa,children:"保存"}),e.jsx("button",{onClick:s,style:xd,children:"取消"})]})]})}function Cn({label:t,children:r}){return e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:"var(--text-secondary)",marginBottom:6,fontWeight:500,textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),r]})}const In={width:"100%",padding:"9px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",boxSizing:"border-box"},Sa={padding:"11px 28px",borderRadius:"var(--radius-sm)",border:"1px solid transparent",background:"var(--accent)",color:"var(--text-inverse)",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)",boxShadow:"0 2px 16px var(--accent-glow)",transition:"transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out)"},xd={padding:"11px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:14,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",whiteSpace:"nowrap",transition:"all 0.15s var(--ease-out)"},md={padding:"6px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},vs={padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)"},ws={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function bd(){const[t,r]=u.useState([]),[n,s]=u.useState("stdio"),[i,a]=u.useState(ws),[l,c]=u.useState(!1),[f,h]=u.useState({id:!1,command:!1,url:!1}),[x,m]=u.useState({}),[S,I]=u.useState({}),[N,O]=u.useState(new Set),[K,U]=u.useState(null),[y,v]=u.useState(""),[B,H]=u.useState(!1),A=async k=>{var se;if(!((se=window.agentApi)!=null&&se.mcpProbe))return;O(de=>new Set([...de,k.id])),I(de=>{const he={...de};return delete he[k.id],he});const D=new Promise((de,he)=>setTimeout(()=>he(new Error("连接超时(15s)")),15e3));try{const de=await Promise.race([window.agentApi.mcpProbe(k),D]);m(he=>({...he,[k.id]:de}))}catch(de){const he=de instanceof Error?de.message:String(de);console.warn(`[MCP] probe failed for ${k.id}:`,he),m(ye=>{const ve={...ye};return delete ve[k.id],ve}),I(ye=>({...ye,[k.id]:he})),(k.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(he))&&(v(""),U({server:k}))}finally{O(de=>{const he=new Set(de);return he.delete(k.id),he})}};u.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(k=>{r(k),k.filter(D=>D.enabled!==!1).forEach(D=>A(D))}).catch(console.error)},[]);const[C,E]=u.useState(""),[M,_]=u.useState(""),[ne,ce]=u.useState(!1),Se=async()=>{_("");let k;try{k=JSON.parse(C.trim());const D=k.mcpServers??k,se=Object.entries(D);if(se.length===0){_("未找到任何服务器");return}ce(!0);const de=[];for(const[ye,ve]of se){const be=ve,Lt=be.name||ye,jt=be.disabled!==!0;let ct;if(be.url||be.type==="streamableHttp"||be.type==="sse"){const Nn=be.type==="sse"?"sse":"streamableHttp";ct={id:ye,name:Lt,transport:Nn,url:be.url,headers:be.headers??{},env:be.env??{},enabled:jt}}else ct={id:ye,name:Lt,transport:"stdio",command:be.command,args:be.args??[],env:be.env??{},enabled:jt};await window.agentApi.mcpSave(ct),de.push(ct)}const he=await window.agentApi.mcpList();r(he),E(""),de.filter(ye=>ye.enabled!==!1).forEach(ye=>A(ye))}catch(D){_(D instanceof Error?D.message:"JSON 解析失败")}finally{ce(!1)}},G=()=>i.id.trim()!==""&&i.command.trim()!=="",Ge=()=>i.id.trim()!==""&&i.url.trim()!=="",vt=k=>{const D={};for(const se of k.split(`
259
- `)){const de=se.indexOf(":");if(de<1)continue;const he=se.slice(0,de).trim(),ye=se.slice(de+1).trim();he&&(D[he]=ye)}return D},Rn=async()=>{if(h({id:!0,command:!0,url:!0}),!(n==="stdio"&&!G())&&!((n==="sse"||n==="streamableHttp")&&!Ge())){c(!0);try{const k=n==="sse"||n==="streamableHttp"?vt(i.headersRaw):{},D=n==="stdio"?{id:i.id,name:i.name||i.id,transport:"stdio",command:i.command,args:i.args.split(" ").filter(Boolean),enabled:!0}:{id:i.id,name:i.name||i.id,transport:n,url:i.url,headers:k,enabled:!0};await window.agentApi.mcpSave(D);const se=await window.agentApi.mcpList();r(se),a(ws),h({id:!1,command:!1,url:!1}),A(D)}catch(k){console.error("Failed to save MCP server",k)}finally{c(!1)}}},Re=async k=>{await window.agentApi.mcpDelete(k),r(t.filter(D=>D.id!==k))},Mn=async(k,D)=>{await window.agentApi.mcpSetEnabled(k,D),r(t.map(se=>se.id===k?{...se,enabled:D}:se))},Wt=async()=>{if(!(!K||!y.trim())){H(!0);try{const k=K.server.transport==="streamableHttp"?{...K.server,headers:{...K.server.headers??{},Authorization:`Bearer ${y.trim()}`}}:{...K.server,env:{...K.server.env??{},Authorization:`Bearer ${y.trim()}`}};await window.agentApi.mcpSave(k);const D=await window.agentApi.mcpList();r(D),U(null),v("");const se=D.find(de=>de.id===k.id)??k;A(se)}finally{H(!1)}}},_t=k=>k==="stdio"?"本地":k==="streamableHttp"?"HTTP":"SSE",Jn=k=>k==="stdio"?"#68d391":k==="streamableHttp"?"#f6ad55":"#63b3ed",rt=k=>k==="stdio"?"rgba(154,230,180,0.15)":k==="streamableHttp"?"rgba(246,173,85,0.15)":"rgba(99,179,237,0.15)";return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:660,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"MCP 服务器"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:32},children:"通过模型上下文协议连接外部工具。"}),e.jsxs("div",{style:{padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",marginBottom:28,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:0},children:"添加服务器"}),e.jsx("div",{style:{display:"flex",background:"var(--bg-surface)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden"},children:["stdio","sse","streamableHttp"].map(k=>e.jsx("button",{onClick:()=>{s(k),h({id:!1,command:!1,url:!1}),a(D=>({...ws,id:D.id,name:D.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:n===k?"var(--accent)":"transparent",color:n===k?"var(--text-inverse)":"var(--text-muted)"},children:k==="stdio"?"本地 stdio":k==="sse"?"远程 SSE":"HTTP"},k))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.id,onChange:k=>a(D=>({...D,id:k.target.value})),onBlur:()=>h(k=>({...k,id:!0})),placeholder:"服务器 ID *",style:{...nn,...f.id&&!i.id?js:{}}}),f.id&&!i.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.name,onChange:k=>a(D=>({...D,name:k.target.value})),placeholder:"显示名称",style:{...nn,flex:1}})]}),n==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.command,onChange:k=>a(D=>({...D,command:k.target.value})),onBlur:()=>h(k=>({...k,command:!0})),placeholder:"命令(如 npx)*",style:{...nn,...f.command&&!i.command?js:{}}}),f.command&&!i.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.args,onChange:k=>a(D=>({...D,args:k.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...nn,flex:2}})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.url,onChange:k=>a(D=>({...D,url:k.target.value})),onBlur:()=>h(k=>({...k,url:!0})),placeholder:n==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...nn,...f.url&&!i.url?js:{}}}),f.url&&!i.url&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("label",{style:{fontSize:12,color:"var(--text-muted)"},children:"请求头(每行 key: value)"}),e.jsx("textarea",{value:i.headersRaw,onChange:k=>a(D=>({...D,headersRaw:k.target.value})),placeholder:`access_token: abc123
260
- Authorization: Bearer sk-...`,rows:3,style:{...nn,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:Rn,disabled:l,style:{alignSelf:"flex-start",padding:"10px 22px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:l?"not-allowed":"pointer",fontFamily:"var(--font-body)"},children:l?"保存中…":"添加服务器"})]})]}),e.jsxs("div",{style:{marginBottom:28,padding:20,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",margin:"0 0 8px"},children:"导入 JSON 配置"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",margin:"0 0 10px"},children:"兼容 Claude Desktop / Cursor 格式,粘贴后点导入。"}),e.jsx("textarea",{value:C,onChange:k=>{E(k.target.value),_("")},placeholder:`{
261
- "my-server": {
262
- "command": "npx",
263
- "args": ["-y", "some-mcp"]
264
- }
265
- }`,rows:5,style:{...nn,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),M&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:M}),e.jsx("button",{onClick:Se,disabled:!C.trim()||ne,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:C.trim()&&!ne?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:C.trim()&&!ne?1:.5},children:ne?"导入中…":"导入"})]}),t.filter(k=>k.transport===n).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",n==="stdio"?"本地 stdio":n==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(k=>k.transport===n).map(k=>e.jsxs("div",{style:{padding:"14px 16px",background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",display:"flex",justifyContent:"space-between",alignItems:"center",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("div",{style:{fontSize:14,fontWeight:500,color:"var(--text-primary)"},children:k.name||k.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:rt(k.transport),color:Jn(k.transport),fontWeight:600},children:_t(k.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[k.transport==="stdio"?`${k.command} ${(k.args??[]).join(" ")}`:k.url,k.transport!=="stdio"&&k.headers&&Object.keys(k.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(k.headers).length," 个请求头"]})]}),N.has(k.id)?e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6,display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",border:"2px solid var(--accent)",borderTopColor:"transparent",animation:"spin 0.8s linear infinite"}}),"探测工具中…"]}):S[k.id]?e.jsxs("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:S[k.id]}),k.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(S[k.id])?e.jsx("button",{onClick:()=>{v(""),U({server:k})},style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid rgba(251,191,36,0.4)",background:"rgba(251,191,36,0.1)",color:"#fbbf24",cursor:"pointer",fontFamily:"var(--font-body)"},children:"输入 Token"}):null,e.jsx("button",{onClick:()=>A(k),style:{fontSize:11,padding:"2px 8px",borderRadius:4,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontFamily:"var(--font-body)"},children:"重试"})]}):x[k.id]&&x[k.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:x[k.id].map(D=>e.jsx("span",{title:D.description,style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"rgba(168,85,247,0.12)",color:"#c084fc",border:"1px solid rgba(168,85,247,0.2)",fontFamily:"var(--font-mono)",cursor:"default"},children:D.name},D.name))}):x[k.id]!==void 0?e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:6},children:"无可用工具"}):null]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("label",{style:{fontSize:12,color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",gap:4},children:[e.jsx("input",{type:"checkbox",checked:k.enabled!==!1,onChange:D=>Mn(k.id,D.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Re(k.id),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(248,113,113,0.2)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500,transition:"background 0.15s"},onMouseEnter:D=>{D.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:D=>{D.currentTarget.style.background="transparent"},children:"移除"})]})]},k.id))}),K&&e.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},onClick:k=>{k.target===k.currentTarget&&U(null)},children:e.jsxs("div",{style:{width:420,background:"var(--bg-surface)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-default)",padding:28,boxShadow:"0 24px 48px rgba(0,0,0,0.4)"},children:[e.jsx("h3",{style:{margin:"0 0 6px",fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:"需要认证"}),e.jsxs("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-muted)"},children:["服务器 ",e.jsx("strong",{style:{color:"var(--text-primary)"},children:K.server.name||K.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:y,onChange:k=>v(k.target.value),onKeyDown:k=>{k.key==="Enter"&&Wt(),k.key==="Escape"&&U(null)},placeholder:"sk-… 或 Bearer token",style:{...nn,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>U(null),style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:13,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"}),e.jsx("button",{onClick:Wt,disabled:!y.trim()||B,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:y.trim()&&!B?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:y.trim()&&!B?1:.5},children:B?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const nn={padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",fontFamily:"var(--font-body)"},js={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function yd(){const[t,r]=u.useState([]),[n,s]=u.useState(""),[i,a]=u.useState(null),[l,c]=u.useState(!1),[f,h]=u.useState(""),[x,m]=u.useState(""),[S,I]=u.useState("user"),[N,O]=u.useState(""),[K,U]=u.useState(null),[y,v]=u.useState("success"),B=async()=>{if(window.agentApi){const E=await window.agentApi.listMemories();r(E)}};u.useEffect(()=>{B()},[]);const H=async()=>{if(!n.trim()){B();return}if(window.agentApi){const E=await window.agentApi.searchMemories(n);r(E.map(M=>M.entry))}},A=async()=>{if(!(!f.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:f.trim(),description:x,type:S,content:N,created:(i==null?void 0:i.created)??new Date().toISOString(),updated:new Date().toISOString()}),c(!1),a(null),h(""),m(""),O(""),I("user"),U("保存成功"),v("success"),await B()}catch(E){U(E instanceof Error?E.message:"保存失败"),v("error")}},C=E=>{a(E),h(E.name),m(E.description),I(E.type),O(E.content),c(!0)};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"记忆"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginTop:4},children:"跨会话的持久化知识库。"})]}),e.jsx("button",{onClick:()=>{c(!0),a(null),h(""),m(""),O(""),I("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:n,onChange:E=>s(E.target.value),onKeyDown:E=>E.key==="Enter"&&H(),placeholder:"搜索记忆...",style:{flex:1,padding:"10px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)"}}),e.jsx("button",{onClick:H,style:$i,children:"搜索"})]}),K&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:y==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:y==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:y==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:K}),l&&e.jsxs("div",{style:{padding:20,marginBottom:24,background:"var(--bg-glass)",borderRadius:"var(--radius-md)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("input",{value:f,onChange:E=>h(E.target.value),placeholder:"名称",style:{...Fr,marginBottom:10},disabled:!!i}),e.jsx("input",{value:x,onChange:E=>m(E.target.value),placeholder:"描述",style:{...Fr,marginBottom:10}}),e.jsxs("select",{value:S,onChange:E=>I(E.target.value),style:{...Fr,marginBottom:10},children:[e.jsx("option",{value:"user",children:"用户"}),e.jsx("option",{value:"feedback",children:"反馈"}),e.jsx("option",{value:"project",children:"项目"}),e.jsx("option",{value:"reference",children:"参考"})]}),e.jsx("textarea",{value:N,onChange:E=>O(E.target.value),placeholder:"内容",rows:5,style:{...Fr,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,style:{padding:"9px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--success)",color:"#000",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"保存"}),e.jsx("button",{onClick:()=>c(!1),style:$i,children:"取消"})]})]}),t.map(E=>e.jsxs("div",{style:{padding:"14px 16px",marginBottom:8,background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{color:"var(--text-primary)",fontWeight:600,fontSize:14},children:E.name}),e.jsx("span",{style:{fontSize:10,padding:"2px 8px",borderRadius:10,background:"rgba(255,255,255,0.04)",color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:500},children:E.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>C(E),style:Oi,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(E.name),U("删除成功"),v("success"),await B()}catch(M){U(M instanceof Error?M.message:"删除失败"),v("error")}},style:{...Oi,color:"var(--danger)"},children:"删除"})]})]}),E.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:E.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[E.content.slice(0,180),E.content.length>180?"…":""]})]},E.name)),t.length===0&&!l&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Fr={width:"100%",padding:"11px 14px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"},$i={padding:"10px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-secondary)",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)"},Oi={padding:"4px 10px",borderRadius:6,fontSize:11,border:"none",background:"rgba(255,255,255,0.05)",color:"var(--text-secondary)",cursor:"pointer",fontFamily:"var(--font-body)",fontWeight:500},vd=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function wd(){const[t,r]=u.useState([]),[n,s]=u.useState(null),[i,a]=u.useState(!1),[l,c]=u.useState(null),[f,h]=u.useState("success"),[x,m]=u.useState(""),S=(C,E="success")=>{c(C),h(E),setTimeout(()=>c(null),3e3)},I=async()=>{if(!window.agentApi)return;const C=await window.agentApi.listSkills();r(C)};u.useEffect(()=>{I()},[]);const N=C=>{s({...C}),m((C.triggers??[]).join(", ")),a(!1)},O=()=>{s(vd()),m(""),a(!0)},K=()=>{s(null),a(!1)},U=async()=>{if(!n||!window.agentApi)return;if(!n.name.trim()){S("名称不能为空","error");return}const C=x.split(",").map(E=>E.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:n.name.trim(),description:n.description,triggers:C,prompt:n.prompt,filePath:n.filePath??""}),S(i?"技能已创建":"技能已保存"),s(null),await I()}catch(E){S(E instanceof Error?E.message:"保存失败","error")}},y=async C=>{if(window.agentApi)try{await window.agentApi.deleteSkill(C),S("已删除"),(n==null?void 0:n.name)===C&&s(null),await I()}catch(E){S(E instanceof Error?E.message:"删除失败","error")}},v=async C=>{if(!window.agentApi)return;const E=!C.enabled;await window.agentApi.setSkillEnabled(C.name,E),await I()},B=async()=>{if(window.agentApi)try{const C=await window.agentApi.importSkill();if(!C)return;S(`已导入技能「${C.name}」,本次会话立即生效`),await I()}catch(C){S(C instanceof Error?C.message:"导入失败","error")}},H={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},A={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"技能管理"}),e.jsx("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:"配置触发词和提示词,让 Agent 自动激活专属技能"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:B,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer"},children:"↓ 导入技能"}),e.jsx("button",{onClick:O,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"+ 新建技能"})]})]}),l&&e.jsx("div",{style:{marginBottom:16,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:f==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:f==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:f==="success"?"var(--success)":"var(--danger)",fontSize:13},children:l}),n&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:i?"新建技能":`编辑:${n.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:A,children:"名称"}),e.jsx("input",{style:H,value:n.name,disabled:!i,onChange:C=>s({...n,name:C.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"描述"}),e.jsx("input",{style:H,value:n.description,onChange:C=>s({...n,description:C.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"触发词(逗号分隔)"}),e.jsx("input",{style:H,value:x,onChange:C=>m(C.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"提示词"}),e.jsx("textarea",{style:{...H,minHeight:120,resize:"vertical"},value:n.prompt,onChange:C=>s({...n,prompt:C.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:U,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"保存"}),e.jsx("button",{onClick:K,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!n&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(C=>{var E;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:"14px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-glass)",opacity:C.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>v(C),title:C.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:C.enabled===!1?"var(--border-default)":"var(--accent)",cursor:"pointer",position:"relative",transition:"background 0.2s"},children:e.jsx("span",{style:{position:"absolute",top:2,left:C.enabled===!1?2:14,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:C.name}),((E=C.triggers)==null?void 0:E.length)>0&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["触发词:",C.triggers.slice(0,3).join(" · "),C.triggers.length>3?" ...":""]})]}),C.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:C.description}),C.prompt&&e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",opacity:.7},children:[C.prompt.slice(0,80),C.prompt.length>80?"...":""]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>N(C),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:12,cursor:"pointer"},children:"编辑"}),e.jsx("button",{onClick:()=>y(C.name),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(244,63,94,0.3)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer"},children:"删除"})]})]},C.name)})]})]})}const $r=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function Ca(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function jd(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:Ca(),maxIterations:0,isDefault:!1}}const Ns={padding:"5px 12px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-secondary)",fontSize:12,fontWeight:500,cursor:"pointer"},wr={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},sn={width:"100%",padding:"7px 10px",borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,outline:"none",boxSizing:"border-box"},rn={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function kd({ph:t,onChange:r,onDelete:n}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:sn,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>r({...t,key:s.target.value})}),e.jsx("input",{style:sn,placeholder:"说明",value:t.description,onChange:s=>r({...t,description:s.target.value})}),e.jsx("input",{style:sn,placeholder:"默认值",value:t.defaultValue,onChange:s=>r({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:n,style:{...wr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function Ui({initial:t,activeAgentId:r,onSave:n,onCancel:s}){const{profiles:i}=Qr(),[a,l]=u.useState([]),[c,f]=u.useState([]),[h,x]=u.useState({...jd(),...t,capabilities:{...Ca(),...t.capabilities??{}}}),[m,S]=u.useState(null),[I,N]=u.useState(!1);u.useEffect(()=>{var M,_;window.agentApi&&(window.agentApi.listSkills().then(ne=>{l(ne.filter(ce=>ce.name))}),(_=(M=window.agentApi).listMCPServers)==null||_.call(M).then(ne=>{f(ne??[])}).catch(()=>{}))},[]);const O=M=>x(_=>({..._,capabilities:{..._.capabilities,...M}})),K=M=>{const _=h.capabilities.enabledTools;if(_.length===0){const ne=$r.map(ce=>ce.name).filter(ce=>ce!==M);O({enabledTools:ne})}else if(_.includes(M)){const ne=_.filter(ce=>ce!==M);O({enabledTools:ne})}else{const ne=[..._,M];ne.length===$r.length?O({enabledTools:[]}):O({enabledTools:ne})}},U=M=>{const _=h.capabilities.enabledSkills;O({enabledSkills:_.includes(M)?_.filter(ne=>ne!==M):[..._,M]})},y=M=>{const _=h.capabilities.enabledMCPServers;O({enabledMCPServers:_.includes(M)?_.filter(ne=>ne!==M):[..._,M]})},v=()=>x(M=>({...M,contextPlaceholders:[...M.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),B=(M,_)=>x(ne=>{const ce=[...ne.contextPlaceholders];return ce[M]=_,{...ne,contextPlaceholders:ce}}),H=M=>x(_=>({..._,contextPlaceholders:_.contextPlaceholders.filter((ne,ce)=>ce!==M)})),A=async()=>{if(!h.name.trim()){S("名称为必填项");return}N(!0);try{await n(h)}catch(M){S(M instanceof Error?M.message:"保存失败")}finally{N(!1)}},C=M=>h.capabilities.enabledTools.length===0||h.capabilities.enabledTools.includes(M),E={fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:10,marginTop:22,paddingBottom:5,borderBottom:"1px solid var(--border-subtle)"};return e.jsxs("div",{style:{padding:"24px 28px",background:"transparent",borderTop:"1px solid var(--border-subtle)"},children:[m&&e.jsx("div",{style:{marginBottom:12,padding:"8px 12px",borderRadius:7,background:"rgba(244,63,94,0.08)",border:"1px solid rgba(244,63,94,0.25)",color:"var(--danger)",fontSize:12},children:m}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:rn,children:"名称 *"}),e.jsx("input",{style:sn,value:h.name,onChange:M=>x(_=>({..._,name:M.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:rn,children:"描述"}),e.jsx("input",{style:sn,value:h.description,onChange:M=>x(_=>({..._,description:M.target.value})),placeholder:"一句话描述"})]})]}),e.jsxs("div",{style:{marginTop:14},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:5},children:[e.jsx("label",{style:{...rn,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:h.systemPrompt,onChange:M=>x(_=>({..._,systemPrompt:M.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
266
-
267
- 当前项目:{{project_name}}`,rows:6,style:{...sn,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:E,children:"上下文占位符"}),h.contextPlaceholders.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6},children:["变量名","说明","默认值",""].map(M=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:M},M))}),h.contextPlaceholders.map((M,_)=>e.jsx(kd,{ph:M,onChange:ne=>B(_,ne),onDelete:()=>H(_)},_))]}),e.jsx("button",{onClick:v,style:{...wr,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:E,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:rn,children:"模型"}),e.jsxs("select",{value:h.capabilities.profileId,onChange:M=>O({profileId:M.target.value}),style:{...sn,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),i.map(M=>e.jsxs("option",{value:M.id,children:[M.name||M.modelId," (",M.provider,")"]},M.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:rn,children:["内置工具 ",h.capabilities.enabledTools.length===0?"(全部启用)":`(${h.capabilities.enabledTools.length}/${$r.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:$r.map(M=>{const _=C(M.name);return e.jsx("button",{onClick:()=>K(M.name),style:{padding:"4px 10px",borderRadius:20,border:_?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:_?"var(--accent-dim)":"transparent",color:_?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:M.label},M.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),a.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:rn,children:["技能 ",h.capabilities.enabledSkills.length===0?"(全部)":`(${h.capabilities.enabledSkills.length}/${a.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(M=>{const _=h.capabilities.enabledSkills.length===0||h.capabilities.enabledSkills.includes(M.name);return e.jsx("button",{onClick:()=>U(M.name),title:M.description,style:{padding:"4px 10px",borderRadius:20,border:_?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:_?"var(--accent-dim)":"transparent",color:_?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:M.name},M.name)})})]}),c.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:rn,children:["MCP 服务器 ",h.capabilities.enabledMCPServers.length===0?"(全部)":`(${h.capabilities.enabledMCPServers.length}/${c.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:c.map(M=>{const _=h.capabilities.enabledMCPServers.length===0||h.capabilities.enabledMCPServers.includes(M.id);return e.jsx("button",{onClick:()=>y(M.id),style:{padding:"4px 10px",borderRadius:20,border:_?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:_?"var(--accent-dim)":"transparent",color:_?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:M.name},M.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:rn,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:sn,value:h.maxIterations,min:0,max:100,onChange:M=>x(_=>({..._,maxIterations:Number(M.target.value)}))})]}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",paddingBottom:2},children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:"var(--text-secondary)"},children:[e.jsx("input",{type:"checkbox",checked:h.isDefault,onChange:M=>x(_=>({..._,isDefault:M.target.checked})),style:{width:14,height:14,accentColor:"var(--accent)",cursor:"pointer"}}),"新会话默认使用此智能体"]})})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,disabled:I,style:{...Ns,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:I?.6:1},children:I?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:Ns,children:"取消"})]})]})}function Sd(){const[t,r]=u.useState([]),[n,s]=u.useState([]),[i,a]=u.useState(null),[l,c]=u.useState(!1),[f,h]=u.useState(null),[x,m]=u.useState("success"),S=(y,v="success")=>{h(y),m(v),setTimeout(()=>h(null),2e3)},I=async()=>{if(!window.agentApi)return;const y=await window.agentApi.listAgentDefs();r(y);const v=await window.agentApi.getSettings();s(v.activeAgentIds??[])};u.useEffect(()=>{I()},[]);const N=async y=>{await window.agentApi.createAgentDef(y),c(!1),S("智能体已创建"),await I()},O=async(y,v)=>{await window.agentApi.updateAgentDef(y,v),a(null),S("保存成功"),await I()},K=async y=>{await window.agentApi.deleteAgentDef(y),i===y&&a(null),S("已删除"),await I()},U=async y=>{const B=(await window.agentApi.setActiveAgentDef(y)).activeAgentIds??[];s(B),S(B.includes(y)?"已激活":"已取消激活")};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"智能体"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:28},children:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),f&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,border:x==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:x==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:x==="success"?"var(--success)":"var(--danger)",fontSize:13},children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{c(!0),a(null)},style:{...Ns,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600},children:"+ 新建智能体"})}),l&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",overflow:"hidden",marginBottom:16},children:[e.jsx("div",{style:{padding:"10px 16px",background:"var(--bg-surface)",display:"flex",alignItems:"center",gap:8},children:e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)"},children:"新建智能体"})}),e.jsx(Ui,{initial:{},activeAgentId:n[0]??"",onSave:N,onCancel:()=>c(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!l&&e.jsx("div",{style:{padding:"28px 20px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无智能体配置,点击「新建智能体」开始创建"}),t.map(y=>{const v=n.includes(y.id),B=y.id===i;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${v?"var(--accent)":"var(--border-default)"}`,background:v?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s, background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 16px"},children:[e.jsx("div",{style:{width:34,height:34,borderRadius:8,flexShrink:0,background:v?"var(--accent)":"var(--bg-deep)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:v?"#fff":"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:y.name}),v&&e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"rgba(79,110,247,0.12)",padding:"1px 6px",borderRadius:4,letterSpacing:"0.05em"},children:"激活"}),y.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),y.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[y.capabilities.profileId&&e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"rgba(79,110,247,0.08)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.15)"},children:"自定义模型"}),y.capabilities.enabledTools.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.capabilities.enabledTools.length," 工具"]}),y.capabilities.enabledSkills.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.capabilities.enabledSkills.length," 技能"]}),y.contextPlaceholders.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>U(y.id),style:{...wr,color:v?"var(--accent)":"var(--text-muted)",borderColor:v?"var(--accent)":"var(--border-default)",background:v?"var(--accent-dim)":"transparent"},children:v?"取消激活":"激活"}),e.jsx("button",{onClick:()=>a(B?null:y.id),style:wr,children:B?"收起":"编辑"}),e.jsx("button",{onClick:()=>K(y.id),style:{...wr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),B&&e.jsx(Ui,{initial:y,activeAgentId:n[0]??"",onSave:H=>O(y.id,H),onCancel:()=>a(null)})]},y.id)})]})]})}const Cd=[{label:"TypeScript / JavaScript",language:"typescript",fileTypes:".ts,.tsx,.js,.jsx",command:"typescript-language-server",args:"--stdio"},{label:"Python (pylsp)",language:"python",fileTypes:".py",command:"pylsp",args:""},{label:"Python (pyright)",language:"python",fileTypes:".py",command:"pyright-langserver",args:"--stdio"},{label:"Rust (rust-analyzer)",language:"rust",fileTypes:".rs",command:"rust-analyzer",args:""},{label:"Go (gopls)",language:"go",fileTypes:".go",command:"gopls",args:""},{label:"C/C++ (clangd)",language:"cpp",fileTypes:".c,.cpp,.cc,.h,.hpp",command:"clangd",args:""},{label:"Java (jdtls via brew)",language:"java",fileTypes:".java",command:"jdtls",args:"--data /tmp/jdtls-workspace"}],ks={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function Id(){const[t,r]=u.useState([]),[n,s]=u.useState(ks),[i,a]=u.useState(!1),[l,c]=u.useState(null),[f,h]=u.useState(null),x=async()=>{var y;if((y=window.agentApi)!=null&&y.lspList)try{const v=await window.agentApi.lspList();r(v)}catch(v){console.error("[LSP] load error",v)}};u.useEffect(()=>{x()},[]);const m=y=>{s(v=>({...v,name:y.label,language:y.language,fileTypes:y.fileTypes,command:y.command,args:y.args}))},S=y=>{c(y.id),s({id:y.id,name:y.name,language:y.language,fileTypes:y.fileTypes.join(","),command:y.command,args:y.args.join(" "),envRaw:y.env?Object.entries(y.env).map(([v,B])=>`${v}=${B}`).join(`
268
- `):""}),h(null)},I=()=>{c(null),s(ks)},N=async()=>{var A;if(!((A=window.agentApi)!=null&&A.lspSave))return;const y=n.name.trim(),v=n.command.trim();if(!y||!v)return;let B;if(n.envRaw.trim()){B={};for(const C of n.envRaw.split(`
269
- `)){const E=C.indexOf("=");E>0&&(B[C.slice(0,E).trim()]=C.slice(E+1).trim())}}const H={id:l??crypto.randomUUID(),name:y,language:n.language.trim(),fileTypes:n.fileTypes.split(",").map(C=>C.trim()).filter(Boolean),command:v,args:n.args.trim()?n.args.trim().split(/\s+/):[],env:B,enabled:!0};a(!0);try{await window.agentApi.lspSave(H),await x(),I()}finally{a(!1)}},O=async y=>{var v;(v=window.agentApi)!=null&&v.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(y),await x())},K=async y=>{var v;(v=window.agentApi)!=null&&v.lspSetEnabled&&(await window.agentApi.lspSetEnabled(y.id,!y.enabled),await x())},U=l!==null;return U&&l===null||!l&&n.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!U&&e.jsx("button",{onClick:()=>{c(""),s(ks)},style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",flexShrink:0},children:"+ 添加服务器"})]}),t.length===0&&!U&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:"尚未配置任何 LSP 服务器"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:U?24:0},children:t.map(y=>e.jsxs("div",{style:{background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",cursor:"pointer"},onClick:()=>h(f===y.id?null:y.id),children:[e.jsx("div",{onClick:v=>{v.stopPropagation(),K(y)},style:{width:32,height:18,borderRadius:9,background:y.enabled?"var(--success, #34d399)":"var(--border-default)",position:"relative",cursor:"pointer",flexShrink:0,transition:"background 0.2s"},children:e.jsx("div",{style:{position:"absolute",top:2,left:y.enabled?16:2,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:500,fontSize:13,color:"var(--text-primary)"},children:y.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[y.language,y.fileTypes.length>0?` · ${y.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[y.command,y.args.length?" "+y.args.join(" "):""]}),e.jsx("button",{onClick:v=>{v.stopPropagation(),S(y)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"编辑"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),O(y.id)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--danger, #f43f5e)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"删除"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{flexShrink:0,transition:"transform 0.2s",transform:f===y.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),f===y.id&&e.jsxs("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-muted)",borderTop:"1px solid var(--border-subtle)",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"命令:"}),e.jsxs("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:[y.command," ",y.args.join(" ")]})]}),y.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),y.fileTypes.join(", ")]}),y.env&&Object.keys(y.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(y.env).map(([v,B])=>`${v}=${B}`).join(", ")]})]})]},y.id))}),U&&e.jsxs("div",{style:{padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:l?"编辑 LSP 服务器":"添加 LSP 服务器"}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:Sn,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Cd.map(y=>e.jsx("button",{onClick:()=>m(y),style:{background:"var(--bg-deep)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:"pointer",color:"var(--text-secondary)",fontFamily:"var(--font-body)"},children:y.label},y.label))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:Sn,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.name,onChange:y=>s(v=>({...v,name:y.target.value})),placeholder:"TypeScript Language Server",style:qn})]}),e.jsxs("div",{children:[e.jsx("label",{style:Sn,children:"语言"}),e.jsx("input",{value:n.language,onChange:y=>s(v=>({...v,language:y.target.value})),placeholder:"typescript",style:qn})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Sn,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:n.fileTypes,onChange:y=>s(v=>({...v,fileTypes:y.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:qn})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:Sn,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.command,onChange:y=>s(v=>({...v,command:y.target.value})),placeholder:"typescript-language-server",style:{...qn,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Sn,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:n.args,onChange:y=>s(v=>({...v,args:y.target.value})),placeholder:"--stdio",style:{...qn,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Sn,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:n.envRaw,onChange:y=>s(v=>({...v,envRaw:y.target.value})),placeholder:`NODE_ENV=production
270
- TSPROTOCOL_LOG=verbose`,rows:3,style:{...qn,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),n.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void N(),disabled:i||!n.name.trim()||!n.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:i||!n.name.trim()||!n.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:i?"保存中…":"保存"}),e.jsx("button",{onClick:I,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"})]})]})]})}const qn={width:"100%",padding:"8px 10px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",boxSizing:"border-box"},Sn={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function Ad({trigger:t,heardText:r}){const[n,s]=u.useState(!1);return u.useEffect(()=>{if(t<=0)return;s(!0);const i=setTimeout(()=>s(!1),2400);return()=>clearTimeout(i)},[t]),n?Vt.createPortal(e.jsxs("div",{style:{position:"fixed",inset:0,zIndex:3e4,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:22,background:"radial-gradient(circle at 50% 50%, var(--accent-glow), transparent 60%)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",animation:"fadeIn 0.3s var(--ease-out)",pointerEvents:"none",WebkitAppRegion:"no-drag"},children:[e.jsxs("div",{style:{position:"relative",width:120,height:120},children:[[0,.45,.9].map(i=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${i}s var(--ease-out) infinite`}},i)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),r&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",r.slice(0,40),"”"]})]},t),document.body):null}const Td="m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z",Rd="M75.91 73.628V62.232c0-.96.36-1.68 1.199-2.16l22.912-13.194c3.119-1.8 6.838-2.639 10.676-2.639 14.394 0 23.511 11.157 23.511 23.032 0 .839 0 1.799-.12 2.758l-23.752-13.914c-1.439-.84-2.879-.84-4.318 0L75.91 73.627Zm53.499 44.383v-27.23c0-1.68-.72-2.88-2.159-3.719L97.142 69.55l9.836-5.638c.839-.48 1.559-.48 2.399 0l22.912 13.195c6.598 3.839 11.035 11.995 11.035 19.912 0 9.116-5.397 17.513-13.915 20.992v.001Zm-60.577-23.99-9.836-5.758c-.84-.48-1.2-1.2-1.2-2.16v-26.39c0-12.834 9.837-22.55 23.152-22.55 5.039 0 9.716 1.679 13.676 4.678L70.993 55.516c-1.44.84-2.16 2.039-2.16 3.719v34.787-.002Zm21.173 12.234L75.91 98.339V81.546l14.095-7.917 14.094 7.917v16.793l-14.094 7.916Zm9.056 36.467c-5.038 0-9.716-1.68-13.675-4.678l23.631-13.676c1.439-.839 2.159-2.038 2.159-3.718V85.863l9.956 5.757c.84.48 1.2 1.2 1.2 2.16v26.389c0 12.835-9.957 22.552-23.27 22.552v.001Zm-28.43-26.75L47.72 102.778c-6.599-3.84-11.036-11.996-11.036-19.913 0-9.236 5.518-17.513 14.034-20.992v27.35c0 1.68.72 2.879 2.16 3.718l29.989 17.393-9.837 5.638c-.84.48-1.56.48-2.399 0Zm-1.318 19.673c-13.555 0-23.512-10.196-23.512-22.792 0-.959.12-1.919.24-2.879l23.63 13.675c1.44.84 2.88.84 4.32 0l30.108-17.392v11.395c0 .96-.361 1.68-1.2 2.16l-22.912 13.194c-3.119 1.8-6.837 2.639-10.675 2.639Zm29.748 14.274c14.515 0 26.63-10.316 29.39-23.991 13.434-3.479 22.071-16.074 22.071-28.91 0-8.396-3.598-16.553-10.076-22.43.6-2.52.96-5.039.96-7.557 0-17.153-13.915-29.99-29.989-29.99-3.239 0-6.358.48-9.477 1.56-5.398-5.278-12.835-8.637-20.992-8.637-14.515 0-26.63 10.316-29.39 23.991-13.434 3.48-22.07 16.074-22.07 28.91 0 8.396 3.598 16.553 10.075 22.431-.6 2.519-.96 5.038-.96 7.556 0 17.154 13.915 29.989 29.99 29.989 3.238 0 6.357-.479 9.476-1.559 5.397 5.278 12.835 8.637 20.992 8.637Z";function Ia({agentType:t,size:r=16,className:n}){return t==="customer-agent"?e.jsxs("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 1024 1024",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M248 430 512 294l264 136-264 136-264-136Z",stroke:"currentColor",strokeWidth:"64",strokeLinejoin:"round"}),e.jsx("path",{d:"m248 594 264 136 264-136",stroke:"currentColor",strokeWidth:"64",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M512 350c10 38 30 58 68 68-38 10-58 30-68 68-10-38-30-58-68-68 38-10 58-30 68-68Z",fill:"currentColor"})]}):t==="codex"?e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"29.487 29.964 121.035 119.954","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:Rd})}):t==="claude-code"?e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:Td})}):e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M22 24H2V0h20zM17 4.8H7v14.4h10z",fillRule:"evenodd"})})}const Md=[{agentType:"customer-agent",label:"Customer Agent"},{agentType:"codex",label:"Codex"},{agentType:"claude-code",label:"Claude Code"},{agentType:"opencode",label:"OpenCode"}];function Nd({value:t,health:r,onChange:n}){return e.jsx("div",{className:"agent-workspace-switcher",role:"tablist","aria-label":"切换 Agent",children:Md.map(s=>{const i=r.find(l=>l.agentType===s.agentType),a=(i==null?void 0:i.available)===!1;return e.jsxs("button",{type:"button",role:"tab","aria-selected":t===s.agentType,"aria-label":s.label,title:a?`${s.label} 不可用:${(i==null?void 0:i.error)??"未检测到运行时"}`:s.label,className:t===s.agentType?"is-active":"",onClick:()=>n(s.agentType),children:[e.jsx(Ia,{agentType:s.agentType,size:22}),e.jsx("i",{className:a?"is-unavailable":"","aria-hidden":"true"})]},s.agentType)})})}const Ss=264,qi=126;function Ed(t){const r=typeof window>"u"?1024:window.innerWidth,n=typeof window>"u"?768:window.innerHeight,s=Math.max(8,Math.min(t.left+t.width-Ss,r-Ss-8)),i=t.top+t.height+7,a=i+qi<=n-8?i:Math.max(8,t.top-qi-7);return{left:s,top:a,width:Ss}}function zd({message:t,anchor:r,mobile:n,pending:s,onCancel:i,onConfirm:a}){const l=c=>c.stopPropagation();return e.jsx("div",{className:`sidebar-delete-confirmation-layer${n?" is-mobile":""}`,onClick:s?void 0:i,children:e.jsxs("div",{className:"sidebar-delete-confirmation",role:"alertdialog","aria-modal":"true","aria-labelledby":"sidebar-delete-confirmation-title","aria-describedby":"sidebar-delete-confirmation-message",style:n?void 0:Ed(r),onClick:l,children:[e.jsx("strong",{id:"sidebar-delete-confirmation-title",children:"删除会话"}),e.jsx("p",{id:"sidebar-delete-confirmation-message",children:t}),e.jsxs("div",{className:"sidebar-delete-confirmation-actions",children:[e.jsx("button",{type:"button",onClick:i,disabled:s,children:"取消"}),e.jsx("button",{type:"button",className:"is-danger",onClick:a,disabled:s,children:s?"正在删除...":"删除"})]})]})})}function Cs({session:t,deleteLabel:r="删除会话",onSelect:n,onDelete:s}){var i,a;return e.jsxs("div",{className:`sidebar-row sidebar-session-row${t.child?" sidebar-session-row--child":""}${t.active?" sidebar-row-active":""}`,children:[e.jsxs("button",{type:"button",className:"sidebar-session-button",onClick:n,"aria-pressed":t.active,"aria-expanded":t.hasChildren?!!t.expanded:void 0,title:t.title,children:[e.jsx("span",{className:`sidebar-status-dot is-${t.visualState}`,title:t.statusLabel,"aria-label":t.statusLabel}),e.jsx("span",{className:"sidebar-session-title",children:t.title}),((i=t.compatibility)==null?void 0:i.status)==="checking"&&e.jsx("span",{className:"sidebar-session-compatibility",title:`正在验证 Codex ${t.compatibility.producerVersion??"未知版本"} 会话兼容性`,"aria-label":"正在验证会话兼容性",children:e.jsx(Kn,{size:13,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"})}),((a=t.compatibility)==null?void 0:a.status)==="incompatible"&&e.jsx("span",{className:"sidebar-session-compatibility",title:t.compatibility.reason??"Codex 版本不兼容","aria-label":"Codex 版本不兼容",children:e.jsx(oo,{size:13,"aria-hidden":"true"})}),t.occupiedExternally&&e.jsx("span",{className:"sidebar-session-lock",title:"原客户端正在使用,只读","aria-label":"原客户端正在使用,只读",children:e.jsx(So,{size:13,"aria-hidden":"true"})}),t.hasChildren&&e.jsx(Qn,{size:13,className:`sidebar-session-disclosure${t.expanded?" is-expanded":""}`,"aria-hidden":"true"})]}),t.canDelete&&s&&e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation();const c=l.currentTarget.getBoundingClientRect();s({top:c.top,left:c.left,width:c.width,height:c.height})},title:r,"aria-label":`${r}:${t.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(Ur,{size:14,"aria-hidden":"true"})})]})}const Wd=[["style",new Set(["css","scss","sass","less","styl"])],["image",new Set(["png","jpg","jpeg","gif","webp","avif","bmp","ico","svg","tif","tiff"])],["video",new Set(["mp4","mov","m4v","webm","mkv","avi","wmv","flv","mpeg","mpg"])],["audio",new Set(["mp3","wav","m4a","aac","ogg","flac","opus"])],["markdown",new Set(["md","mdx","markdown"])],["json",new Set(["json","jsonc","geojson"])],["archive",new Set(["zip","tar","gz","tgz","bz2","xz","7z","rar"])],["spreadsheet",new Set(["csv","tsv","xls","xlsx","ods"])],["presentation",new Set(["ppt","pptx","key","odp"])],["database",new Set(["db","sqlite","sqlite3"])],["text",new Set(["txt","log","rtf","ini","cfg","conf","env","yaml","yml","toml","xml","pdf","doc","docx","odt"])],["code",new Set(["js","jsx","mjs","cjs","ts","tsx","vue","svelte","java","kt","kts","py","rb","go","rs","php","c","cc","cpp","h","hpp","cs","swift","scala","sh","bash","zsh","fish","sql","html"])]],_d=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function Ld(t){var i;const r=t.toLocaleLowerCase(),n=_d.get(r);if(n)return n;if(r.startsWith(".env")||r===".gitignore"||r===".npmrc")return"text";const s=r.includes(".")&&r.split(".").pop()||"";return((i=Wd.find(([,a])=>a.has(s)))==null?void 0:i[0])??"file"}const Pd={folder:{icon:vo,label:"文件夹"},code:{icon:fo,label:"代码文件"},style:{icon:Io,label:"样式文件"},image:{icon:ho,label:"图片文件"},video:{icon:bo,label:"视频文件"},audio:{icon:go,label:"音频文件"},markdown:{icon:Co,label:"Markdown 文件"},text:{icon:zs,label:"文本文件"},json:{icon:xo,label:"JSON 文件"},archive:{icon:po,label:"压缩文件"},spreadsheet:{icon:mo,label:"表格文件"},presentation:{icon:Ao,label:"演示文件"},database:{icon:uo,label:"数据库文件"},file:{icon:yo,label:"文件"}};function Bd(t,r){return r==="directory"?"folder":Ld(t)}const Hi=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function Dd(t,r){const n=Hi(t),s=Hi(r),a=[{label:n==="/"?"/":n.split("/").filter(Boolean).pop()||n,path:n}];if(s===n)return a;const l=s.slice(n==="/"?1:n.length+1);let c=n;for(const f of l.split("/").filter(Boolean))c=c==="/"?`/${f}`:`${c}/${f}`,a.push({label:f,path:c});return a}function Fd({open:t,onCancel:r,onConfirm:n}){const[s,i]=u.useState([]),[a,l]=u.useState(""),[c,f]=u.useState(""),[h,x]=u.useState([]),[m,S]=u.useState(!1),[I,N]=u.useState(""),[O,K]=u.useState(!1),U=u.useMemo(()=>Dd(a||"/",c||a||"/"),[a,c]),y=async A=>{if(window.agentApi){S(!0),N("");try{const C=await window.agentApi.listProjectDirectories(A);x(C),f(A)}catch(C){N(C instanceof Error?C.message:"无法读取目录")}finally{S(!1)}}};if(u.useEffect(()=>{if(!t||!window.agentApi)return;let A=!1;return S(!0),N(""),window.agentApi.listProjectRoots().then(async C=>{if(A)return;i(C);const E=C[0]??"";l(E),E?await y(E):N("未配置可用的宿主机目录")}).catch(C=>{A||N(C instanceof Error?C.message:"无法读取宿主机目录")}).finally(()=>{A||S(!1)}),()=>{A=!0}},[t]),u.useEffect(()=>{if(!t)return;const A=C=>{C.key==="Escape"&&r()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,r]),!t)return null;const v=A=>{l(A),y(A)},B=()=>{U.length<=1||y(U[U.length-2].path)},H=async()=>{if(!(!c||O)){K(!0),N("");try{await n(c)}catch(A){N(A instanceof Error?A.message:"项目导入失败")}finally{K(!1)}}};return Vt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:A=>{A.target===A.currentTarget&&r()},children:e.jsxs("section",{className:"host-project-picker",role:"dialog","aria-modal":"true","aria-labelledby":"host-project-picker-title",children:[e.jsxs("header",{className:"host-project-picker-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"host-project-picker-title",children:"选择宿主机项目"}),e.jsx("p",{children:"文件将直接在运行 AgentRoam 的机器上读写"})]}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(ra,{size:16,"aria-hidden":"true"})})]}),s.length>1&&e.jsxs("label",{className:"host-project-picker-root",children:[e.jsx("span",{children:"根目录"}),e.jsx("select",{value:a,onChange:A=>v(A.target.value),children:s.map(A=>e.jsx("option",{value:A,children:A},A))})]}),e.jsxs("nav",{className:"host-project-picker-nav","aria-label":"当前目录",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:B,disabled:U.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(io,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:U.map((A,C)=>e.jsxs("span",{children:[C>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void y(A.path),children:A.label})]},A.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>c&&void y(c),disabled:!c||m,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(ea,{size:15,"aria-hidden":"true"})})]}),a==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":m,children:m?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):I?e.jsx("div",{className:"host-project-picker-state is-error",children:I}):h.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):h.map(A=>{const C=Bd(A.name,A.kind),{icon:E,label:M}=Pd[C],_=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${C}`,"aria-hidden":"true",children:e.jsx(E,{size:18,strokeWidth:1.8})}),e.jsx("span",{className:"host-project-picker-name",children:A.name})]});return A.kind==="file"?e.jsx("div",{className:"host-project-picker-row is-file",title:M,children:_},`${A.name}:${A.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void y(A.path),title:M,children:[_,A.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(Qn,{size:16})})]},`${A.name}:${A.path}`)})}),e.jsxs("footer",{className:"host-project-picker-footer",children:[e.jsx("code",{title:c,children:c}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:r,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!c||m||O,onClick:()=>void H(),children:O?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const Aa="agentroam.agent-workspaces.v2",$d=2,Ta=["customer-agent","codex","claude-code","opencode"];function Vi(){return{version:2,activeAgent:"customer-agent",agents:{}}}function Qi(){return{workspaces:[],nextCursor:null,watermark:null,expandedWorkspaceIds:[],selectedWorkspaceId:null,selectedSessionId:null,sidebarScrollTop:0,sessions:{}}}function Od(t=localStorage){try{const r=JSON.parse(t.getItem(Aa)??"null");if(!An(r)||r.version!==$d)return Vi();const n=Qd(r.activeAgent)?r.activeAgent:"customer-agent",s=An(r.agents)?r.agents:{},i={};for(const a of Ta){const l=Vd(s[a],a);l&&(i[a]=l)}return{version:2,activeAgent:n,agents:i}}catch{return Vi()}}function Ki(t,r=localStorage){try{r.setItem(Aa,JSON.stringify(t))}catch{}}function Ud(t,r,n){const s=new Set(r.data.map(l=>l.workspaceId)),i=n?r.nextCursor?[...r.data,...t.filter(l=>!s.has(l.workspaceId))]:r.data:[...t,...r.data],a=new Set;return i.filter(l=>a.has(l.workspaceId)?!1:(a.add(l.workspaceId),!0))}function qd(t,r,n){const s=new Set(r.data.map(l=>l.id)),i=n?r.nextCursor?[...r.data,...t.filter(l=>!s.has(l.id))]:r.data:[...t,...r.data],a=new Set;return i.filter(l=>a.has(l.id)?!1:(a.add(l.id),!0))}function Hd(t,r){return!r||t.some(n=>n.id===r.id)?[...t]:[r,...t]}function Vd(t,r){if(!An(t))return null;const n=Array.isArray(t.workspaces)?t.workspaces.filter(i=>An(i)&&i.agentType===r&&typeof i.workspaceId=="string"&&typeof i.name=="string"&&Array.isArray(i.roots)&&i.roots.every(a=>typeof a=="string")&&typeof i.order=="number"&&(i.canCreateSession===void 0||typeof i.canCreateSession=="boolean")):[],s={};if(An(t.sessions))for(const[i,a]of Object.entries(t.sessions))!An(a)||!Array.isArray(a.data)||(s[i]={data:a.data.filter(l=>An(l)&&l.agentType===r&&typeof l.id=="string"),nextCursor:typeof a.nextCursor=="string"?a.nextCursor:null,loaded:a.loaded===!0});return{workspaces:n,nextCursor:typeof t.nextCursor=="string"?t.nextCursor:null,watermark:typeof t.watermark=="string"?t.watermark:null,expandedWorkspaceIds:Array.isArray(t.expandedWorkspaceIds)?t.expandedWorkspaceIds.filter(i=>typeof i=="string"):[],selectedWorkspaceId:typeof t.selectedWorkspaceId=="string"?t.selectedWorkspaceId:null,selectedSessionId:typeof t.selectedSessionId=="string"?t.selectedSessionId:null,sidebarScrollTop:typeof t.sidebarScrollTop=="number"&&t.sidebarScrollTop>=0?t.sidebarScrollTop:0,sessions:s}}function Qd(t){return typeof t=="string"&&Ta.includes(t)}function An(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Gi(t){var s;const r={},n={};for(const[i,a]of Object.entries(t)){const l=a.data;r[i]=$s(l.filter(c=>!c.parentSessionId));for(const c of l.filter(f=>f.parentSessionId))(n[s=c.parentSessionId]??(n[s]=[])).push(c)}for(const i of Object.values(n))i.sort((a,l)=>a.created.localeCompare(l.created));return{roots:r,children:n,projectIds:new Set(Object.entries(t).filter(([,i])=>i.loaded).map(([i])=>i))}}function Is(t){return{id:t.workspaceId,name:t.name,description:t.roots[0]??"",created:t.updatedAt??"",updated:t.updatedAt??"",agentType:t.agentType,source:t.source,canCreateSession:t.canCreateSession}}function Kd(){return e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M8 6V4h8v2"}),e.jsx("path",{d:"M19 6l-1 14H6L5 6"}),e.jsx("path",{d:"M10 11v5M14 11v5"})]})}function Zi(t,r){r&&t.detail>0&&t.currentTarget.blur()}function Gd(){const t=document.activeElement;t instanceof HTMLElement&&(t.matches("input, textarea, select")||t.isContentEditable)&&t.blur()}function Yd(){var jn,ur,Fn,Wr;const[t]=u.useState(Od),r=t.activeAgent,n=t.agents[r]??Qi(),[s]=u.useState(()=>Gi(n.sessions)),i=u.useRef(t),[a,l]=u.useState(r),c=u.useRef(a);c.current=a;const[f,h]=u.useState(n.workspaces.map(Is)),[x,m]=u.useState(n.nextCursor),[S,I]=u.useState(n.watermark),[N,O]=u.useState(!1),[K,U]=u.useState(!1),[y,v]=u.useState(null),[B,H]=u.useState(!1),[A,C]=u.useState(s.roots),[E,M]=u.useState(""),[_,ne]=u.useState(!1),[ce,Se]=u.useState(10),[G,Ge]=u.useState(null),[vt,Rn]=u.useState(!1),[Re,Mn]=u.useState(null),Wt=u.useRef(!1),[_t,Jn]=u.useState([]),[rt,k]=u.useState(s.children),D=u.useRef(A),se=u.useRef(rt);D.current=A,se.current=rt;const[de,he]=u.useState(s.projectIds),[ye,ve]=u.useState(new Set),[be,Lt]=u.useState({}),[wt,jt]=u.useState(new Set),[ct,Nn]=u.useState(Object.fromEntries(Object.entries(n.sessions).map(([d,w])=>[d,w.nextCursor]))),Pt=u.useRef(new Map),ut=u.useRef(new Map),[xe,Yn]=u.useState(n.selectedWorkspaceId),[Fe,pt]=u.useState(n.selectedSessionId),kt=u.useRef(xe),St=u.useRef(Fe);kt.current=xe,St.current=Fe;const[on,ln]=u.useState(new Set),[dn,Ct]=u.useState(new Set(n.expandedWorkspaceIds)),[Bt,En]=u.useState(new Set),[$,Ce]=u.useState(!1),[It,Sr]=u.useState("settings"),Qt=ge(d=>d.setTodos),Dt=nt(d=>d.skin),Ft=nt(d=>d.layout),At=nt(d=>d.wakeEnabled),Tt=nt(d=>d.wakeWord),zn=nt(d=>d.setSkin),cn=nt(d=>d.setLayout),Xn=nt(d=>d.setWakeEnabled),Cr=nt(d=>d.setWakeWord),er=nt(d=>d.autoSpeak),un=nt(d=>d.setAutoSpeak),gt=nt(d=>d.runningFirst),Ir=nt(d=>d.setRunningFirst),pn=ge(d=>d.runningSessionId),$t=ge(_o(d=>Object.entries(d.messagesBySession).filter(([,w])=>w.some(T=>T.askUser&&!T.askUser.answered)).map(([w])=>w))),Rt=u.useCallback(d=>d.status==="running"||pn===d.id,[pn]),Ar=()=>{Ct(new Set),ln(new Set(Object.keys(rt)))},Gr=()=>{const d=f.filter(w=>!Bt.has(w.id)).map(w=>w.id);Ct(new Set(d)),ln(new Set);for(const w of d){if($e.current.has(w))continue;const T=it.current.has(w);Oe(w,{refresh:T,background:T})}},Kt=Hn(),Wn=Xa(),ft=Kt&&Wn,[tr,Gt]=u.useState(!1),[Ve,Ee]=u.useState(!1),[ht,gn]=u.useState(null),[nr,Zt]=u.useState(0),[Tr,rr]=u.useState(void 0),Ze=u.useRef(null),Je=u.useRef(!1),[fn,sr]=u.useState(null),Mt=u.useRef(null),Jt=u.useRef(!1),st=u.useRef(f);st.current=f;const hn=u.useRef(Bt);hn.current=Bt;const it=u.useRef(de);it.current=de;const $e=u.useRef(ye);$e.current=ye;const xt=u.useRef(null);u.useEffect(()=>{document.documentElement.setAttribute("data-skin",Dt)},[Dt]),u.useEffect(()=>{document.body.classList.toggle("layout-compact",Ft==="compact")},[Ft]),u.useEffect(()=>{var W;const d=f.map((z,ee)=>({agentType:a,workspaceId:z.id,name:z.name,roots:z.description?[z.description]:[],order:ee,updatedAt:z.updated||void 0,source:z.source??(z.agentType==="claude-code"?"derived":"native"),canCreateSession:z.canCreateSession})),w=Object.fromEntries(f.map(z=>[z.id,{data:[...A[z.id]??[],...Object.values(rt).flat().filter(ee=>(A[z.id]??[]).some(J=>J.id===ee.parentSessionId))],nextCursor:ct[z.id]??null,loaded:de.has(z.id)}])),T={...i.current,version:2,activeAgent:a,agents:{...i.current.agents,[a]:{workspaces:d,nextCursor:x,watermark:S,expandedWorkspaceIds:[...dn],selectedWorkspaceId:xe,selectedSessionId:Fe,sidebarScrollTop:((W=xt.current)==null?void 0:W.scrollTop)??0,sessions:w}}};i.current=T,Ki(T)},[a,rt,dn,de,f,xe,Fe,ct,A,x,S]);const at=u.useCallback(()=>{if(!window.agentApi||!At||Je.current||Ze.current)return;const d=()=>{Bo()&&!Ze.current&&(Ze.current=Fo({wakeWord:Tt,onWake:w=>{var T;rr(w),Zt(W=>W+1),(T=window.agentApi)==null||T.showWindow()},onError:w=>console.warn("[wake]",w)}))};typeof window.agentApi.wakeStart=="function"?(Je.current=!0,window.agentApi.wakeStart(Tt).then(w=>{w.ok||(Je.current=!1,d())}).catch(()=>{Je.current=!1,d()})):d()},[At,Tt]);u.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWake)return window.agentApi.onWake(w=>{Je.current=!1,rr(w),Zt(T=>T+1)})},[]),u.useEffect(()=>{var d;if((d=window.agentApi)!=null&&d.onWakeCommand)return window.agentApi.onWakeCommand(w=>{var ee;const T=((w==null?void 0:w.text)||"").trim();if(!T)return;const W=Mt.current&&Date.now()<Mt.current.until?Mt.current:null;if(W){W.until=Date.now()+9e4,pt(W.sessionId),(ee=window.agentApi)==null||ee.wakeConversation(!0),sr({text:T,projectId:null,sessionId:W.sessionId,nonce:Date.now()}),pe(`语音追问:${T.length>40?T.slice(0,40)+"…":T}`),Ke("success"),setTimeout(()=>pe(null),4e3);return}const z=st.current.find(J=>J.name&&T.includes(J.name)&&!hn.current.has(J.id));z&&(Yn(z.id),Ct(J=>{const ie=new Set(J);return ie.add(z.id),ie})),pt(null),Jt.current=!0,un(!0),sr({text:T,projectId:(z==null?void 0:z.id)??null,nonce:Date.now()}),pe(`语音指令:${T.length>40?T.slice(0,40)+"…":T}${z?`(项目:${z.name})`:""}`),Ke("success"),setTimeout(()=>pe(null),4e3)})},[]);const Zr=u.useCallback(async()=>{window.agentApi&&(at(),await window.agentApi.hideWindow())},[at]),Me=u.useCallback(d=>{Ce(!1),gn({right:d.right,bottom:d.bottom}),Ee(w=>!w)},[]),xn=u.useCallback(()=>{Ee(!1),Ce(d=>!d)},[]);u.useEffect(()=>{if(!Ve)return;const d=()=>{const T=document.querySelector(".chat-header-action--appearance");if(!T)return;const W=T.getBoundingClientRect();gn(z=>(z==null?void 0:z.right)===W.right&&z.bottom===W.bottom?z:{right:W.right,bottom:W.bottom})},w=window.requestAnimationFrame(d);return window.addEventListener("resize",d),()=>{window.cancelAnimationFrame(w),window.removeEventListener("resize",d)}},[Ft,Ve]),u.useEffect(()=>{window.agentApi&&at()},[at]),u.useEffect(()=>{const d=()=>{var w;(w=Ze.current)==null||w.stop(),Ze.current=null};return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[]),u.useEffect(()=>{var d,w;At||((d=Ze.current)==null||d.stop(),Ze.current=null,Je.current=!1,(w=window.agentApi)==null||w.wakeStop())},[At]),u.useEffect(()=>{!At||!window.agentApi||Je.current&&window.agentApi.wakeStart(Tt)},[Tt]),u.useEffect(()=>()=>{var d;(d=Ze.current)==null||d.stop()},[]);const Yt=[...Object.values(A).flat(),...Object.values(rt).flat()],ir=Yt,Nt=E.trim().toLowerCase(),Ot=Nt?Yt.filter(d=>d.title.toLowerCase().includes(Nt)||(d.cwd||"").toLowerCase().includes(Nt)):null,ze=Fe?ir.find(d=>d.id===Fe):void 0,ar=ze==null?void 0:ze.title,Qe=(ze==null?void 0:ze.cwd)||((jn=f.find(d=>d.id===xe))==null?void 0:jn.description)||null,mn=f.filter(d=>!Bt.has(d.id)).map(d=>d.id),Y=mn.length>0&&mn.every(d=>!dn.has(d)),[Xt,or]=u.useState(300),[Jr,Rr]=u.useState(!1),_n=u.useRef(!1),Ln=u.useRef(0),bn=u.useRef(0),Et=u.useCallback(d=>{if(!_n.current)return;const w=Math.min(480,Math.max(160,bn.current+d.clientX-Ln.current));or(w)},[]),Pn=u.useCallback(()=>{_n.current=!1,Rr(!1),document.removeEventListener("mousemove",Et),document.removeEventListener("mouseup",Pn)},[Et]),Mr=u.useCallback(d=>{_n.current=!0,Rr(!0),Ln.current=d.clientX,bn.current=Xt,document.addEventListener("mousemove",Et),document.addEventListener("mouseup",Pn)},[Xt,Et,Pn]),[Nr,pe]=u.useState(null),[mt,Ke]=u.useState("success"),Ne=d=>{kt.current=d.projectId,St.current=d.sessionId,Yn(d.projectId),pt(d.sessionId),d.sessionId||Qt([])},Er=d=>{var J;if(d===c.current)return;const w=c.current,T=i.current.agents[w];T&&(i.current={...i.current,agents:{...i.current.agents,[w]:{...T,sidebarScrollTop:((J=xt.current)==null?void 0:J.scrollTop)??T.sidebarScrollTop}}});const W=i.current.agents[d]??Qi(),z=Gi(W.sessions),ee=W.workspaces.map(Is);c.current=d,st.current=ee,l(d),h(ee),m(W.nextCursor),I(W.watermark),O(!1),U(!1),v(null),D.current=z.roots,se.current=z.children,C(z.roots),k(z.children),he(z.projectIds),it.current=z.projectIds,ve(new Set),$e.current=new Set,Lt({}),jt(new Set),Nn(Object.fromEntries(Object.entries(W.sessions).map(([ie,We])=>[ie,We.nextCursor]))),Ct(new Set(W.expandedWorkspaceIds)),En(new Set),Ne({projectId:W.selectedWorkspaceId,sessionId:W.selectedSessionId}),window.requestAnimationFrame(()=>{xt.current&&(xt.current.scrollTop=W.sidebarScrollTop)}),tt(d,{refresh:W.workspaces.length>0,since:W.watermark})},[bt,en]=u.useState([]),ot=u.useCallback(d=>{en(w=>w.filter(T=>T.id!==d))},[]),lt=u.useCallback(d=>{const w=crypto.randomUUID();en(T=>[...T,{...d,id:w}]),setTimeout(()=>ot(w),12e3)},[ot]);async function tt(d=c.current,w={}){if(!window.agentApi)return;const T=(ut.current.get(d)??0)+1;ut.current.set(d,T),O(!0),v(null);try{const W=await window.agentApi.listAgentWorkspaces(d,{cursor:w.cursor,limit:50,refresh:w.refresh,since:w.refresh?w.since??S:null});if(c.current!==d||ut.current.get(d)!==T)return;const z=st.current.map((ae,Z)=>({agentType:d,workspaceId:ae.id,name:ae.name,roots:ae.description?[ae.description]:[],order:Z,updatedAt:ae.updated,source:ae.source??(d==="claude-code"?"derived":"native"),canCreateSession:ae.canCreateSession})),J=Ud(z,W,!w.cursor).map(Is);st.current=J,h(J),m(W.nextCursor),I(W.watermark),U(W.stale===!0);const ie=new Set(J.map(ae=>ae.id)),We=kt.current;We&&!ie.has(We)&&Ne(Li);const Ie=new Set([...it.current].filter(ae=>ie.has(ae)));We&&ie.has(We)&&Ie.add(We),C(ae=>Object.fromEntries(Object.entries(ae).filter(([Z])=>ie.has(Z)))),he(ae=>{const Z=new Set([...ae].filter(Ae=>ie.has(Ae)));return it.current=Z,Z}),ve(ae=>{const Z=new Set([...ae].filter(Ae=>ie.has(Ae)));return $e.current=Z,Z}),Lt(ae=>Object.fromEntries(Object.entries(ae).filter(([Z])=>ie.has(Z))));const _e=new Set;if(await Promise.all(J.map(async ae=>{ae.description&&!await window.agentApi.checkProjectPath(ae.description)&&_e.add(ae.id)})),c.current!==d||ut.current.get(d)!==T)return;if(En(_e),w.refreshLoadedSessions!==!1)for(const ae of Ie)_e.has(ae)||$e.current.has(ae)||Oe(ae,{refresh:!0,background:!0})}catch(W){c.current===d&&(st.current.length>0&&U(!0),v(W instanceof Error?W.message:"目录加载失败"))}finally{c.current===d&&ut.current.get(d)===T&&O(!1)}}async function Oe(d,w={}){var ee;if(!window.agentApi)return;const T=c.current,W=`${T}:${d}`,z=(Pt.current.get(W)??0)+1;Pt.current.set(W,z),ve(J=>{const ie=new Set(J).add(d);return $e.current=ie,ie}),Lt(J=>{if(!(d in J))return J;const ie={...J};return delete ie[d],ie});try{const J=await window.agentApi.listAgentWorkspaceSessions(T,d,{cursor:w.cursor,limit:20,refresh:w.refresh});if(c.current!==T||Pt.current.get(W)!==z)return;const ie=D.current[d]??[],We=w.pendingSession?{...w.pendingSession,projectId:d}:void 0,Ie=We?[We,...ie.filter(re=>re.id!==We.id)]:ie,_e=new Set(Ie.map(re=>re.id)),ae=[...Ie,...[..._e].flatMap(re=>se.current[re]??[])],Z=qd(ae,J,!w.cursor).map(re=>({...re,projectId:re.projectId??d})),Ae=$s(Z.filter(re=>!re.parentSessionId)),Ye=kt.current,Le=St.current,Xe=Hd(Ae,We);Ye===d&&Le&&!Z.some(re=>re.id===Le)&&!Xe.some(re=>re.id===Le)&&Ne(Li);const yt={};for(const re of Z.filter(ke=>ke.parentSessionId))(yt[ee=re.parentSessionId]??(yt[ee]=[])).push(re);for(const re of Object.values(yt))re.sort((ke,$n)=>ke.created.localeCompare($n.created));Nn(re=>({...re,[d]:J.nextCursor})),jt(re=>{const ke=new Set(re);return J.stale?ke.add(d):ke.delete(d),ke});const je={...D.current,[d]:Xe},Ue={...se.current};for(const re of _e)delete Ue[re];for(const[re,ke]of Object.entries(yt))Ue[re]=ke;D.current=je,se.current=Ue,C(je),k(Ue),he(re=>{const ke=new Set(re).add(d);return it.current=ke,ke})}catch(J){if(Pt.current.get(W)!==z)return;Lt(ie=>({...ie,[d]:J instanceof Error?J.message:"会话加载失败"}))}finally{Pt.current.get(W)===z&&ve(J=>{const ie=new Set(J);return ie.delete(d),$e.current=ie,ie})}}const yn=async d=>{if(!window.agentApi)return;const w=await window.agentApi.listChildSessions(d);k(T=>({...T,[d]:w.sort((W,z)=>W.created<z.created?-1:1)}))},tn=async(d,w)=>{if(!window.agentApi)return;const T=st.current.find(W=>W.id===d);if(!T||T.canCreateSession===!1){pe("请先选择目录"),Ke("info"),setTimeout(()=>pe(null),3e3);return}if(!Wt.current){Wt.current=!0,Mn({projectId:d,agentType:w});try{const W=(T==null?void 0:T.source)==="imported"?void 0:d,z=await window.agentApi.createSession("新会话",W,w,T==null?void 0:T.description);if(c.current!==w)return;const ee=z.projectId===d?z:{...z,projectId:d},J={...D.current,[d]:[ee,...(D.current[d]??[]).filter(ie=>ie.id!==z.id)]};D.current=J,C(J),Ne({projectId:d,sessionId:z.id}),ft&&Gt(!1),w==="customer-agent"&&Oe(d,{refresh:!0,background:!0,pendingSession:ee})}catch(W){pe(W instanceof Error?W.message:"新建会话失败"),Ke("error"),setTimeout(()=>pe(null),3e3)}finally{Wt.current=!1,Mn(null)}}},lr=()=>{const d=st.current.find(w=>w.id===xe);if(!xe||(d==null?void 0:d.canCreateSession)===!1){pe("请先选择目录"),Ke("info"),setTimeout(()=>pe(null),3e3);return}tn(xe,a)};u.useEffect(()=>{var d;window.agentApi&&(tt(c.current,{refresh:(((d=i.current.agents[c.current])==null?void 0:d.workspaces.length)??0)>0}),Qr.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(Jn).catch(()=>{}))},[]),u.useEffect(()=>{const d=window.setInterval(()=>{document.visibilityState!=="visible"||N||tt(a,{refresh:!0,since:S,refreshLoadedSessions:!1})},15e3);return()=>window.clearInterval(d)},[a,N,S]),u.useEffect(()=>{if(!xe||!Fe||(ze==null?void 0:ze.agentType)==="customer-agent"||!window.agentApi)return;let d=!1;const w=async()=>{document.visibilityState==="visible"&&(d||await Oe(xe,{refresh:!0,background:!0}))},T=window.setInterval(()=>void w(),1e4);return()=>{d=!0,window.clearInterval(T)}},[xe,Fe,ze==null?void 0:ze.agentType]),u.useEffect(()=>{if(!xe||!window.agentApi)return;const d=f.find(T=>T.id===xe),w=d==null?void 0:d.description;w&&window.agentApi.setProjectWorkingDir(w)},[xe,f]);const dr=d=>{Ne(Pi(d));const w=!dn.has(d);if(Ct(T=>{const W=new Set(T);return w?W.add(d):W.delete(d),W}),w&&!$e.current.has(d)){const T=it.current.has(d);Oe(d,{refresh:T,background:T})}},vn=async d=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const w=d.replace(/\\/g,"/"),T=w.split("/").filter(Boolean),W=T[T.length-1]||w||"导入的项目",z=await window.agentApi.importAgentWorkspace(c.current,w,W);await tt(c.current,{refresh:!0,refreshLoadedSessions:!1}),Ne(Pi(z.workspace.workspaceId)),await Oe(z.workspace.workspaceId,{refresh:!0}),Ct(ee=>{const J=new Set(ee);return J.add(z.workspace.workspaceId),J}),pe(z.existing?"该文件夹已在当前 Agent 的目录中":`已导入:${z.workspace.name}`),Ke(z.existing?"info":"success"),setTimeout(()=>pe(null),3e3)},cr=async()=>{try{if(!window.agentApi){pe("agentApi 未就绪,请重启应用"),Ke("error");return}if(Kt){H(!0);return}const d=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",d),!d)return;await vn(d)}catch(d){console.error("[import] error:",d),pe(d instanceof Error?d.message:String(d)),Ke("error"),setTimeout(()=>pe(null),5e3)}},wn=async d=>{if(window.agentApi)try{await window.agentApi.deleteProject(d),xe===d&&(Yn(null),pt(null),Qt([])),pe("项目删除成功"),Ke("success"),setTimeout(()=>pe(null),2500),await tt()}catch(w){pe(w instanceof Error?w.message:"项目删除失败"),Ke("error"),setTimeout(()=>pe(null),4e3)}},Bn=(d,w)=>{Ge({session:d,anchor:w})},zr=async()=>{if(!window.agentApi||!G||vt)return;const{session:d}=G;Rn(!0);try{await window.agentApi.deleteSession(d.id);const w=d.projectId??kt.current,T=d.agentType;if(w){const ee=`${T}:${w}`;Pt.current.set(ee,(Pt.current.get(ee)??0)+1)}const W=gd(D.current,se.current,[],d.id);D.current=W.sessionsByProject,se.current=W.childSessionsByParent,C(W.sessionsByProject),k(W.childSessionsByParent);const z=i.current.agents[T];if(z){const ee={...i.current,agents:{...i.current.agents,[T]:ud(z,W.removedIds)}};i.current=ee,Ki(ee)}St.current&&W.removedIds.includes(St.current)&&Ne({projectId:kt.current,sessionId:null}),pe("会话删除成功"),Ke("success"),setTimeout(()=>pe(null),2500),Ge(null),w&&Oe(w,{refresh:!0,background:!0})}catch(w){pe(w instanceof Error?w.message:"会话删除失败"),Ke("error"),setTimeout(()=>pe(null),4e3)}finally{Rn(!1)}},Dn=[{id:"settings",label:"设置"},{id:"mcp",label:"MCP"},{id:"memory",label:"记忆"},{id:"skill",label:"技能"},{id:"agent",label:"智能体"},{id:"lsp",label:"LSP"}];return e.jsxs("div",{className:"app-shell",style:{display:"flex",height:Kt?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[ft&&tr&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>Gt(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),ft&&!tr&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>Gt(!0),"aria-label":"会话列表","aria-expanded":!1,style:{position:"fixed",top:"calc(env(safe-area-inset-top) + 8px)",left:10,zIndex:1250,width:34,height:34,borderRadius:9,border:"1px solid var(--border-default)",background:"var(--bg-glass, rgba(18,20,28,.82))",color:"var(--text-secondary)",display:"grid",placeItems:"center",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag",cursor:"pointer"},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})})}),e.jsx("div",{className:"app-drag-region",style:{position:"fixed",top:0,left:0,right:0,height:52,zIndex:9999,WebkitAppRegion:"drag",pointerEvents:"none"}}),e.jsx("div",{className:"app-accent-glow",style:{position:"absolute",top:"-120px",left:"-80px",width:320,height:320,borderRadius:"50%",background:"radial-gradient(circle, var(--accent-glow) 0%, transparent 70%)",pointerEvents:"none",zIndex:0}}),Ft!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:Xt,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 0",position:"relative",zIndex:10,overflow:"hidden",...ft?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:tr?"translateX(0)":"translateX(-103%)",transition:"transform .24s ease",boxShadow:"12px 0 32px rgba(0,0,0,.5)",padding:"calc(env(safe-area-inset-top) + 12px) 0 0"}:{}},children:[e.jsx("div",{className:"app-sidebar-brand",style:{padding:"0 20px 10px"},children:e.jsxs("div",{className:"sidebar-brand-row",children:[e.jsx("div",{className:"sidebar-brand-mark","aria-hidden":"true",children:e.jsx(Ia,{agentType:"customer-agent",size:24})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsx(Nd,{value:a,health:_t,onChange:Er}),e.jsxs("button",{type:"button",className:"sidebar-search-field",onClick:()=>{ne(!0),Se(10)},title:"搜索会话","aria-label":"搜索会话",children:[e.jsx(ta,{size:15,"aria-hidden":"true"}),e.jsx("span",{children:"搜索会话"}),e.jsx("kbd",{children:"⌘ K"})]}),e.jsxs("div",{className:"sidebar-project-toolbar",children:[e.jsxs("div",{className:"sidebar-project-heading",children:[e.jsx("span",{className:"sidebar-project-title",children:"目录"}),e.jsx("span",{className:"sidebar-project-count","aria-label":`${f.length} 个目录`,children:f.length})]}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:d=>{Y?Gr():Ar(),Zi(d,Y)},title:Y?"展开全部会话":"折叠全部会话","aria-label":Y?"展开全部会话":"折叠全部会话","aria-pressed":Y,disabled:mn.length===0,className:`ui-icon-button sidebar-collapse-all${Y?" is-active":""}`,children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Y?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m7 6 5 5 5-5"}),e.jsx("path",{d:"m7 13 5 5 5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m17 11-5-5-5 5"}),e.jsx("path",{d:"m17 18-5-5-5 5"})]})})}),e.jsx("button",{type:"button",onClick:d=>{Ir(!gt),Zi(d,gt)},title:gt?"按新建时间排序":"进行中会话优先","aria-label":gt?"按新建时间排序":"进行中会话优先","aria-pressed":gt,className:`ui-icon-button sidebar-session-sort${gt?" is-active":""}`,children:e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h10M3 12h7M3 18h4"}),e.jsx("path",{d:"m15 9 3-3 3 3M18 6v12"})]})}),e.jsx("button",{type:"button",onClick:()=>void cr(),title:"导入目录","aria-label":"导入目录",className:"ui-icon-button",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]})]}),e.jsx("div",{ref:xt,className:"app-sidebar-scroll",onPointerDownCapture:Gd,onScroll:d=>{const w=d.currentTarget;w.scrollHeight-w.scrollTop-w.clientHeight<120&&x&&!N&&tt(a,{cursor:x})},style:{flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[f.map(d=>{var ae;const w=xe===d.id,T=dn.has(d.id),W=de.has(d.id),z=ye.has(d.id),ee=be[d.id],J=A[d.id]??[],ie=gt?dd(J,Rt):J,We=ie.length>10,Ie=Bt.has(d.id),_e=(Re==null?void 0:Re.agentType)===a&&Re.projectId===d.id;return e.jsxs("div",{className:"sidebar-project-block","aria-busy":z,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${w&&!Ie?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:Ie?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{Ie||dr(d.id)},disabled:Ie,"aria-expanded":T,"aria-pressed":w,title:Ie?`路径不存在:${d.description}`:d.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:Ie?"var(--text-muted)":w?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:w&&!Ie?600:400,cursor:Ie?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[Ie?e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):d.canCreateSession===!1?e.jsx(wo,{size:13,"aria-hidden":"true",style:{flexShrink:0,opacity:w?1:.5}}):e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:w?1:.5},children:T?e.jsx("path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6A2 2 0 0 1 18.46 20H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}):e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name})]}),a==="customer-agent"&&!Kt&&e.jsx("button",{onClick:Z=>{Z.stopPropagation(),wn(d.id)},title:"删除目录","aria-label":`删除目录:${d.name}`,className:"sidebar-project-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{flexShrink:0},children:e.jsx(Kd,{})}),d.canCreateSession!==!1&&e.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),tn(d.id,a)},title:_e?"正在创建会话":`新建 ${a==="customer-agent"?"Customer Agent":a==="claude-code"?"Claude Code":a==="codex"?"Codex":"OpenCode"} 会话`,"aria-label":_e?"正在创建会话":`在 ${d.name} 中新建会话`,"aria-busy":_e,disabled:Re!==null||Ie||((ae=_t.find(Z=>Z.agentType===a))==null?void 0:ae.available)===!1,className:"sidebar-runtime-create sidebar-project-add-action ui-icon-button ui-icon-button--small",children:_e?e.jsx(Kn,{size:13,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):e.jsx(ui,{size:13,"aria-hidden":"true"})})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:T?We?300:800:0,opacity:T?1:0,transition:"max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease"},children:e.jsxs("div",{className:"sidebar-project-sessions",onScroll:Z=>{const Ae=Z.currentTarget,Ye=Ae.scrollHeight-Ae.scrollTop-Ae.clientHeight<80,Le=ct[d.id];Ye&&Le&&!z&&Oe(d.id,{cursor:Le})},style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...We?{maxHeight:280,overflowY:"auto"}:{}},children:[ie.map(Z=>{const Ae=Fe===Z.id,Ye=Rt(Z),Le=ms({status:Z.status,isRunning:Ye,needsInput:Ye&&$t.includes(Z.id)}),Xe=rt[Z.id]??[],yt=!on.has(Z.id);return e.jsxs("div",{children:[e.jsx(Cs,{session:{id:Z.id,title:Z.title,visualState:Le,statusLabel:bs[Le],occupiedExternally:Z.occupancy==="owned-externally",canDelete:Z.canDelete,active:Ae,hasChildren:Xe.length>0,expanded:yt,compatibility:Z.compatibility},onSelect:()=>{ft&&Gt(!1),Ne(ys(d.id,Z.id)),Xe.length>0&&ln(je=>{const Ue=new Set(je);return Ue.has(Z.id)?Ue.delete(Z.id):Ue.add(Z.id),Ue})},onDelete:je=>Bn(Z,je)}),e.jsx("div",{className:"sidebar-child-sessions",style:{maxHeight:yt?Xe.length*40:0,opacity:yt?1:0},children:Xe.map(je=>{const Ue=Rt(je),re=ms({status:je.status,isRunning:Ue,needsInput:Ue&&$t.includes(je.id)});return e.jsx(Cs,{session:{id:je.id,title:je.title,visualState:re,statusLabel:bs[re],occupiedExternally:je.occupancy==="owned-externally",canDelete:je.canDelete,active:Fe===je.id,child:!0,compatibility:je.compatibility},deleteLabel:"删除子会话",onSelect:()=>{ft&&Gt(!1),Ne(ys(d.id,je.id))},onDelete:ke=>Bn(je,ke)},je.id)})})]},Z.id)}),z&&!W&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),ee&&e.jsxs("div",{title:ee,style:{display:"flex",alignItems:"center",gap:8,color:"var(--danger)",fontSize:11,padding:"4px 10px"},children:[e.jsx("span",{style:{flex:1},children:"会话加载失败"}),e.jsx("button",{type:"button",onClick:()=>void Oe(d.id,{refresh:W,background:W}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),wt.has(d.id)&&!ee&&e.jsx("div",{className:"sidebar-cache-state",children:"显示缓存,会话将在下次刷新时更新"}),ie.length===0&&W&&!z&&!ee&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},d.id)}),f.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:N?"正在加载目录...":"暂无目录"}),f.length>0&&N&&e.jsx("div",{className:"sidebar-cache-state",children:"正在同步目录..."}),K&&!y&&e.jsx("div",{className:"sidebar-cache-state",children:"当前显示缓存目录"}),y&&e.jsxs("div",{className:"sidebar-load-error",title:y,children:[e.jsx("span",{children:f.length>0?"目录刷新失败,当前显示缓存":"目录加载失败"}),e.jsx("button",{type:"button",onClick:()=>void tt(a,{refresh:f.length>0}),children:"重试"})]})]})}),e.jsx("div",{className:"sidebar-bottom-action",children:e.jsx("button",{type:"button",className:"sidebar-new-session-primary",disabled:Re!==null||xe!==null&&Bt.has(xe)||((ur=_t.find(d=>d.agentType===a))==null?void 0:ur.available)===!1,"aria-busy":Re!==null,"aria-disabled":Re!==null||!xe||((Fn=f.find(d=>d.id===xe))==null?void 0:Fn.canCreateSession)===!1,title:Re?"正在创建会话":xe&&((Wr=f.find(d=>d.id===xe))==null?void 0:Wr.canCreateSession)!==!1?"新建会话":"请先选择目录",onClick:lr,children:Re?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{size:16,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}),e.jsx("span",{children:"正在创建..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(ui,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"新建会话"})]})})})]}),G&&e.jsx(zd,{message:cd(G.session),anchor:G.anchor,mobile:ft,pending:vt,onCancel:()=>Ge(null),onConfirm:()=>void zr()}),!ft&&e.jsx("div",{className:`app-sidebar-resizer${Jr?" is-dragging":""}`,onMouseDown:Mr,style:{left:Xt}}),_&&e.jsx("div",{onClick:()=>ne(!1),style:{position:"fixed",inset:0,zIndex:1300,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"12vh 16px 16px"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),style:{width:"min(560px, 100%)",maxHeight:"64vh",display:"flex",flexDirection:"column",borderRadius:12,border:"1px solid var(--border-default)",background:"var(--bg-surface)",boxShadow:"0 18px 48px rgba(17,24,39,0.28)",overflow:"hidden"},children:[e.jsx("div",{style:{padding:10,borderBottom:"1px solid var(--border-subtle)"},children:e.jsx("input",{autoFocus:!0,value:E,onChange:d=>M(d.target.value),onKeyDown:d=>{d.key==="Escape"&&ne(!1)},placeholder:"搜索所有会话(标题或目录)…","aria-label":"搜索所有会话",style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-primary)",fontSize:14,outline:"none",fontFamily:"var(--font-body)",boxSizing:"border-box"}})}),e.jsxs("div",{style:{overflowY:"auto",padding:8},children:[Nt&&Ot&&Ot.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[Ot.length," 个结果"]}),Nt&&Ot&&Ot.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!Nt&&Yt.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),(Ot??Yt.slice(0,ce)).map(d=>{const w=Fe===d.id,T=Rt(d),W=ms({status:d.status,isRunning:T,needsInput:T&&$t.includes(d.id)});return e.jsx(Cs,{session:{id:d.id,title:d.title,visualState:W,statusLabel:bs[W],occupiedExternally:d.occupancy==="owned-externally",canDelete:d.canDelete,active:w,child:!!d.parentSessionId,compatibility:d.compatibility},onSelect:()=>{const z=d.projectId&&f.some(ee=>ee.id===d.projectId)?d.projectId:null;Ne(ys(z,d.id)),ne(!1),ft&&Gt(!1)},onDelete:z=>Bn(d,z)},d.id)}),!Nt&&Yt.length>ce&&e.jsx("button",{type:"button",onClick:()=>Se(d=>d+10),style:{width:"100%",padding:"8px 10px",border:0,borderTop:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",textAlign:"center"},children:"更多…"})]})]})})]}),Nr&&Vt.createPortal(e.jsxs("div",{className:`app-action-notice is-${mt}`,role:mt==="error"?"alert":"status","aria-live":mt==="error"?"assertive":"polite",children:[e.jsx("span",{className:"app-action-notice-mark","aria-hidden":"true",children:mt==="success"?"✓":mt==="info"?"i":"!"}),e.jsx("span",{children:Nr})]}),document.body),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[Ft==="focus"&&e.jsx("button",{onClick:()=>cn("standard"),title:"返回标准布局",style:{position:"absolute",top:12,left:12,zIndex:100,padding:"5px 10px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-glass)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",backdropFilter:"blur(8px)",WebkitAppRegion:"no-drag"},children:"← 侧边栏"}),e.jsx("div",{style:{height:"100%",paddingTop:0},children:e.jsx(ld,{activeAgentType:a,selectedProjectId:xe,selectedSessionId:Fe,sessionTitle:ar,sessionSummary:ze,workspacePath:Qe,voiceCommand:fn,onOpenSettings:xn,settingsOpen:$,onHideToBackground:()=>void Zr(),onToggleAppearance:Me,appearanceOpen:Ve,hideToBackgroundTitle:At?`隐藏到后台(说“${Tt}”唤醒)`:"隐藏到后台",onSessionCreated:async(d,w)=>{var W;const T=kt.current;Ne({projectId:T,sessionId:d}),Jt.current&&(Jt.current=!1,Mt.current={sessionId:d,until:Date.now()+9e4},(W=window.agentApi)==null||W.wakeConversation(!0)),T&&await Oe(T,{pendingSession:w})},onSubSessionCreated:async d=>{await yn(d)},onSelectSession:d=>{pt(d)},onSubAgentEvent:d=>{d.type==="started"?lt({type:"info",title:"子会话已启动",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):d.type==="completed"?lt({type:"success",title:"子会话已完成",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId}):lt({type:"error",title:"子会话出错",body:`${d.agentName}:${d.task.slice(0,60)}`,sessionId:d.subSessionId})},onMessageSent:(d,w)=>{C(T=>{const W={};for(const[z,ee]of Object.entries(T))W[z]=ee.map(J=>J.id===d?{...J,title:w.slice(0,60)||J.title}:J);return W})},onRunComplete:async(d,w)=>{var ee;const T=Mt.current,W=Dl(T,w);Mt.current=W,W!==T&&((ee=window.agentApi)==null||ee.wakeConversation(!0));const z=d||xe;z&&await Oe(z,{refresh:!0,background:!0})}})})]}),$&&Vt.createPortal(e.jsx("div",{onClick:()=>Ce(!1),style:{position:"fixed",inset:0,zIndex:10001,background:"rgba(17,24,39,0.18)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.2s var(--ease-out)",WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),style:{width:"min(920px, calc(100vw - 48px))",height:"min(760px, calc(100vh - 48px))",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:"var(--shadow-md)",overflow:"hidden",display:"flex",flexDirection:"column",animation:"fadeInUp 0.25s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border-subtle)",padding:"8px 10px",background:"var(--bg-deepest)"},children:[e.jsx("div",{style:{display:"flex",gap:6},children:Dn.map(d=>e.jsx("button",{onClick:()=>Sr(d.id),className:`settings-tab ${It===d.id?"settings-tab-active":""}`,children:d.label},d.id))}),e.jsx("button",{onClick:()=>Ce(!1),title:"关闭",className:"ui-icon-button ui-icon-button--close ui-icon-button--danger",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[It==="settings"&&e.jsx(hd,{}),It==="mcp"&&e.jsx(bd,{}),It==="memory"&&e.jsx(yd,{}),It==="skill"&&e.jsx(wd,{}),It==="agent"&&e.jsx(Sd,{}),It==="lsp"&&e.jsx(Id,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),Ve&&ht&&Vt.createPortal(e.jsx("div",{onClick:()=>Ee(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:d=>d.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(ht.right-320,window.innerWidth-332)),top:ht.bottom+8,width:320,maxHeight:`calc(100vh - ${ht.bottom+20}px)`,overflowY:"auto",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"16px",display:"flex",flexDirection:"column",gap:16,animation:"fadeInUp 0.2s var(--ease-out)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"皮肤"}),e.jsx("div",{className:"appearance-choices",children:eo.map(d=>e.jsxs("button",{onClick:()=>zn(d.id),className:`appearance-choice ${Dt===d.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${d.preview[0]} 55%, ${d.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:Dt===d.id?600:400},children:d.label}),Dt===d.id&&e.jsx("svg",{className:"appearance-choice-check",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m5 12 4 4L19 6"})})]},d.id))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"布局"}),e.jsx("div",{className:"appearance-segmented",children:to.map(d=>e.jsx("button",{onClick:()=>cn(d.id),title:d.description,className:`appearance-segment ${Ft===d.id?"appearance-segment-active":""}`,children:d.label},d.id))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,borderTop:"1px solid var(--border-subtle)",paddingTop:12},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em"},children:"语音"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["助手回复自动播报",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:er,onChange:d=>un(d.target.checked)})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["隐藏后语音唤醒",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:At,onChange:d=>Xn(d.target.checked)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{flexShrink:0},children:"唤醒词"}),e.jsx("input",{value:Tt,onChange:d=>Cr(d.target.value||"小智"),style:{flex:1,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-primary)",fontSize:12}})]})]})]})}),document.body),e.jsx(Fd,{open:B,onCancel:()=>H(!1),onConfirm:async d=>{await vn(d),H(!1)}}),e.jsx(Ad,{trigger:nr,heardText:Tr}),bt.length>0&&Vt.createPortal(e.jsx("div",{style:{position:"fixed",bottom:24,right:24,zIndex:2e4,display:"flex",flexDirection:"column",gap:10,alignItems:"flex-end",pointerEvents:"none"},children:bt.map(d=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${d.type==="error"?"rgba(220,38,38,0.25)":d.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${d.type==="error"?"var(--danger)":d.type==="success"?"var(--success)":"var(--accent)"}`,borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"12px 14px",animation:"fadeInUp 0.22s var(--ease-out)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsxs("span",{style:{fontSize:12,fontWeight:600,color:d.type==="error"?"var(--danger)":d.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[d.type==="error"?"✕":d.type==="success"?"✓":"◎"," ",d.title]}),e.jsx("button",{onClick:()=>ot(d.id),title:"关闭",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:14,lineHeight:1,padding:"2px 4px",borderRadius:4,transition:"color 0.15s"},onMouseEnter:w=>w.currentTarget.style.color="var(--text-primary)",onMouseLeave:w=>w.currentTarget.style.color="var(--text-muted)",children:"×"})]}),e.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)",lineHeight:1.5,wordBreak:"break-all"},children:d.body}),d.sessionId&&e.jsx("button",{onClick:()=>{pt(d.sessionId),ot(d.id)},style:{marginTop:8,padding:"4px 10px",fontSize:11,fontWeight:500,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid var(--border-glow)",borderRadius:6,cursor:"pointer",transition:"background 0.15s",WebkitAppRegion:"no-drag"},onMouseEnter:w=>w.currentTarget.style.background="var(--accent-glow)",onMouseLeave:w=>w.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},d.id))}),document.body)]})}export{Yd as default};