agentroam-runtime-darwin-arm64 0.2.0-preview.13 → 0.2.0-preview.14
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.
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/runtime/.next/BUILD_ID +1 -1
- package/runtime/.next/app-build-manifest.json +8 -8
- package/runtime/.next/app-path-routes-manifest.json +1 -1
- package/runtime/.next/build-manifest.json +6 -6
- package/runtime/.next/prerender-manifest.json +1 -1
- package/runtime/.next/react-loadable-manifest.json +1 -1
- package/runtime/.next/required-server-files.json +1 -1
- package/runtime/.next/routes-manifest.json +1 -1
- package/runtime/.next/server/app/_not-found/page.js +1 -1
- package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/runtime/.next/server/app/_not-found.html +1 -1
- package/runtime/.next/server/app/_not-found.rsc +1 -1
- package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
- package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
- package/runtime/.next/server/app/api/agent/model/route.js +1 -1
- package/runtime/.next/server/app/api/agent/models/route.js +1 -1
- package/runtime/.next/server/app/api/agent/run/route.js +1 -1
- package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
- package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
- package/runtime/.next/server/app/api/agent/stream/route.js +4 -4
- package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
- package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
- package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
- package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
- package/runtime/.next/server/app/api/mcp/disconnect/route.js +1 -1
- package/runtime/.next/server/app/api/mcp/servers/route.js +1 -1
- package/runtime/.next/server/app/api/memory/[key]/route.js +1 -1
- package/runtime/.next/server/app/api/memory/route.js +1 -1
- package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
- package/runtime/.next/server/app/api/projects/[id]/route.js +1 -1
- package/runtime/.next/server/app/api/projects/check/route.js +1 -1
- package/runtime/.next/server/app/api/projects/directories/route.js +1 -1
- package/runtime/.next/server/app/api/projects/roots/route.js +1 -1
- package/runtime/.next/server/app/api/projects/route.js +1 -1
- package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
- package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/goals/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/release/route.js +1 -0
- package/runtime/.next/server/app/api/sessions/[id]/release/route.js.nft.json +1 -0
- package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js +1 -0
- package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js.nft.json +1 -0
- package/runtime/.next/server/app/api/sessions/route.js +1 -1
- package/runtime/.next/server/app/api/skills/route.js +1 -1
- package/runtime/.next/server/app/api/tools/route.js +1 -1
- package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
- package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
- package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
- package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
- package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
- package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
- package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
- package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
- package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
- package/runtime/.next/server/app/web/page.js +11 -8
- package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
- package/runtime/.next/server/app/web.html +1 -1
- package/runtime/.next/server/app/web.rsc +2 -2
- package/runtime/.next/server/app-paths-manifest.json +27 -25
- package/runtime/.next/server/chunks/1322.js +37 -37
- package/runtime/.next/server/chunks/2083.js +12 -12
- package/runtime/.next/server/chunks/5303.js +1 -1
- package/runtime/.next/server/chunks/7186.js +3 -3
- package/runtime/.next/server/middleware-build-manifest.js +1 -1
- package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/runtime/.next/server/pages/404.html +1 -1
- package/runtime/.next/server/pages/500.html +1 -1
- package/runtime/.next/server/server-reference-manifest.json +1 -1
- package/runtime/.next/static/chunks/137.e70970795c25de4f.js +1 -0
- package/runtime/.next/static/chunks/919-e3163c9448664f1a.js +1 -0
- package/runtime/.next/static/chunks/app/web/page-f8e555341da23177.js +1 -0
- package/runtime/.next/static/chunks/main-app-07d67f2d4e96ecb8.js +1 -0
- package/runtime/.next/static/chunks/{webpack-d22db940097662ef.js → webpack-819dfd677dd52477.js} +1 -1
- package/runtime/lib/file-preview-service.mjs +29 -0
- package/runtime/lib/markdown-preview.mjs +65 -0
- package/runtime/node_modules/.package-lock.json +23 -11
- package/runtime/node_modules/@agent/core/dist/domain/agent/entities.d.ts +3 -0
- package/runtime/node_modules/@agent/core/dist/domain/agent/entities.d.ts.map +1 -1
- package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts +7 -0
- package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts.map +1 -1
- package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts +16 -0
- package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts.map +1 -1
- package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts +2 -2
- package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts.map +1 -1
- package/runtime/node_modules/@agent/core/dist/index.js +2 -1
- package/runtime/node_modules/@agent/core/dist/index.js.map +1 -1
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +39 -39
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +1 -1
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +18 -20
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -25
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/package.json +10 -10
- package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +41 -41
- package/runtime/node_modules/marked/LICENSE.md +44 -0
- package/runtime/node_modules/marked/README.md +106 -0
- package/runtime/node_modules/marked/bin/main.js +282 -0
- package/runtime/node_modules/marked/bin/marked.js +15 -0
- package/runtime/node_modules/marked/lib/marked.cjs +2211 -0
- package/runtime/node_modules/marked/lib/marked.d.cts +728 -0
- package/runtime/node_modules/marked/lib/marked.esm.js +2189 -0
- package/runtime/node_modules/marked/lib/marked.umd.js +2213 -0
- package/runtime/node_modules/marked/man/marked.1 +111 -0
- package/runtime/node_modules/marked/man/marked.1.md +92 -0
- package/runtime/node_modules/marked/marked.min.js +69 -0
- package/runtime/node_modules/marked/package.json +111 -0
- package/runtime/package-lock.json +48 -35
- package/runtime/package.json +1 -0
- package/runtime/webapp/dist/assets/App-u5-hbDMQ.js +285 -0
- package/runtime/webapp/dist/assets/index-3s0r60kD.css +1 -0
- package/runtime/webapp/dist/assets/{index-BAH3pT_c.js → index-jGt09xOx.js} +2 -2
- package/runtime/webapp/dist/index.html +2 -2
- package/runtime/ws-server.mjs +13 -0
- package/runtime/.next/static/chunks/108-bc4a0fe192dfff08.js +0 -1
- package/runtime/.next/static/chunks/137.261fab9d606d75d3.js +0 -1
- package/runtime/.next/static/chunks/app/web/page-8e4da33d77868123.js +0 -1
- package/runtime/.next/static/chunks/main-app-3596fd7d2841e9a3.js +0 -1
- package/runtime/webapp/dist/assets/App-CZspcejP.js +0 -275
- package/runtime/webapp/dist/assets/index-lt5J4xDf.css +0 -1
- /package/runtime/.next/static/{iaxCayE60RyqJY_Zj-OjS → 1LC7dx7c9RaWO6oZD2h4N}/_buildManifest.js +0 -0
- /package/runtime/.next/static/{iaxCayE60RyqJY_Zj-OjS → 1LC7dx7c9RaWO6oZD2h4N}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import{r as d,R as _l,j as e,c as pa,a as Jt,u as ut,i as $n,b as zl,S as Wl,L as Ll}from"./index-jGt09xOx.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 Pl=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),fa=(...t)=>t.filter((n,r,s)=>!!n&&n.trim()!==""&&s.indexOf(n)===r).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 Dl={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 Bl=d.forwardRef(({color:t="currentColor",size:n=24,strokeWidth:r=2,absoluteStrokeWidth:s,className:i="",children:a,iconNode:l,...u},h)=>d.createElement("svg",{ref:h,...Dl,width:n,height:n,stroke:t,strokeWidth:s?Number(r)*24/Number(n):r,className:fa("lucide",i),...u},[...l.map(([g,x])=>d.createElement(g,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 oe=(t,n)=>{const r=d.forwardRef(({className:s,...i},a)=>d.createElement(Bl,{ref:a,iconNode:n,className:fa(`lucide-${Pl(t)}`,s),...i}));return r.displayName=`${t}`,r};/**
|
|
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 $l=oe("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);/**
|
|
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 Fl=oe("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
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 Ol=oe("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"}]]);/**
|
|
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 Ao=oe("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"}]]);/**
|
|
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 Qr=oe("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
|
|
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 qn=oe("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
|
|
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 ga=oe("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"}]]);/**
|
|
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 Ul=oe("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"}]]);/**
|
|
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 Js=oe("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"}]]);/**
|
|
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 ql=oe("CornerUpRight",[["polyline",{points:"15 14 20 9 15 4",key:"1tbx3s"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]);/**
|
|
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 Hl=oe("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"}]]);/**
|
|
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 Vl=oe("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"}]]);/**
|
|
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 Ql=oe("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"}]]);/**
|
|
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 Kl=oe("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"}]]);/**
|
|
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 Gl=oe("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"}]]);/**
|
|
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 Zl=oe("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"}]]);/**
|
|
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 Jl=oe("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"}]]);/**
|
|
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 ks=oe("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"}]]);/**
|
|
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 Yl=oe("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"}]]);/**
|
|
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 Xl=oe("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"}]]);/**
|
|
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 ec=oe("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"}]]);/**
|
|
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 bi=oe("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"}]]);/**
|
|
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 tc=oe("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"}]]);/**
|
|
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 nc=oe("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"}]]);/**
|
|
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 rc=oe("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"}]]);/**
|
|
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 Rt=oe("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
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 sc=oe("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"}]]);/**
|
|
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 oc=oe("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"}]]);/**
|
|
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 ic=oe("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"}]]);/**
|
|
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 ha=oe("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"}]]);/**
|
|
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 yi=oe("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
|
|
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 ac=oe("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"}]]);/**
|
|
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 xa=oe("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"}]]);/**
|
|
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 ma=oe("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
|
|
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 lc=oe("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"}]]);/**
|
|
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 cc=oe("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"}]]);/**
|
|
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 dc=oe("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
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 Ys=oe("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"}]]);/**
|
|
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 bs=oe("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"}]]);/**
|
|
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 uc=oe("Unplug",[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]]);/**
|
|
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 pc=oe("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
|
|
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 fc=oe("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"}]]);/**
|
|
232
|
+
* @license lucide-react v0.468.0 - ISC
|
|
233
|
+
*
|
|
234
|
+
* This source code is licensed under the ISC license.
|
|
235
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
236
|
+
*/const gc=oe("Workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]);/**
|
|
237
|
+
* @license lucide-react v0.468.0 - ISC
|
|
238
|
+
*
|
|
239
|
+
* This source code is licensed under the ISC license.
|
|
240
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
+
*/const ba=oe("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"}]]);/**
|
|
242
|
+
* @license lucide-react v0.468.0 - ISC
|
|
243
|
+
*
|
|
244
|
+
* This source code is licensed under the ISC license.
|
|
245
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
+
*/const ya=oe("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function hc(t,n){if(Object.is(t,n))return!0;if(typeof t!="object"||t===null||typeof n!="object"||n===null)return!1;if(t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(const[s,i]of t)if(!Object.is(i,n.get(s)))return!1;return!0}if(t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(const s of t)if(!n.has(s))return!1;return!0}const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const s of r)if(!Object.prototype.hasOwnProperty.call(n,s)||!Object.is(t[s],n[s]))return!1;return!0}const{useRef:xc}=_l;function mc(t){const n=xc();return r=>{const s=t(r);return hc(n.current,s)?n.current:n.current=s}}const bc="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",yc="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 Ro({agentType:t,size:n=16,className:r}){return t==="customer-agent"?e.jsxs("svg",{className:r,"data-agent-icon":t,width:n,height:n,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:r,"data-agent-icon":t,width:n,height:n,viewBox:"29.487 29.964 121.035 119.954","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:yc})}):t==="claude-code"?e.jsx("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:bc})}):e.jsx("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M22 24H2V0h20zM17 4.8H7v14.4h10z",fillRule:"evenodd"})})}const va="webapp.nativeAgentRunPrefs.v1",vc=["codex","claude-code","opencode"];function wa(){try{const t=JSON.parse(localStorage.getItem(va)??"{}");return t&&typeof t=="object"?t:{}}catch{return{}}}function vs(t){return vc.includes(t)}function vi(t){return vs(t)?wa()[t]??{}:{}}function wc(t,n){if(!vs(t))return;const r=wa();r[t]=n;try{localStorage.setItem(va,JSON.stringify(r))}catch{}}function Xs(t){return t.providerID?`${t.providerID}/${t.id}`:t.id}function jc(t){const n=t.indexOf("/");return n>0?{providerID:t.slice(0,n),id:t.slice(n+1)}:{id:t}}function ws(t,n){const r=t??[],s=r.findIndex(a=>a.itemId===n.itemId&&a.sectionIndex===n.sectionIndex);return(s<0?[...r,{itemId:n.itemId,sectionIndex:n.sectionIndex,text:n.delta}]:r.map((a,l)=>l===s?{...a,text:a.text+n.delta}:a)).sort((a,l)=>a.sectionIndex-l.sectionIndex)}function wi(t){let n=[];for(const r of t)if(r.type==="runtime_progress"){const{type:s,...i}=r;n=ja(n,i)}else(r.type==="done"||r.type==="turn_aborted"||r.type==="error")&&(n=[]);return n}function ja(t,n){const r=t.findIndex(s=>s.progressId===n.progressId);return r<0?[...t,n]:t.map((s,i)=>i===r?n:s)}function ka(t,n){return[...t].reverse().find(r=>r.toolCallId===n)}function kc(t){return[...t].reverse().find(n=>!n.toolCallId)}function Sc(t,n){var s,i,a;const r=[];for(let l=0;l<t.length;l+=1){const u=t[l];r.push(u);const h=u.role==="user"?(i=(s=u.presentation)==null?void 0:s.executionTrace)==null?void 0:i.turnId:void 0;if(!h)continue;const g=t[l+1];((a=g==null?void 0:g.executionTrace)==null?void 0:a.turnId)===h?(r.push({...g,executionTrace:{...g.executionTrace,turnId:h,revision:n}}),l+=1):r.push({id:`codex-execution-trace:${h}`,role:"assistant",content:"",executionTrace:{turnId:h,revision:n},timestamp:u.timestamp})}return r}function Ic(t){var n,r,s;return t.role==="assistant"&&!!((n=t.toolCalls)!=null&&n.length||(s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length)}function Cc(t){return t.reduce((n,r)=>{var s,i,a;return n+(((s=r.toolCalls)==null?void 0:s.length)??0)+(((a=(i=r.presentation)==null?void 0:i.reasoning)==null?void 0:a.length)??0)},0)}function Sa(t,n,r,s){return t.map(i=>{var a;return(a=i.toolCalls)!=null&&a.some(l=>l.id===n)?{...i,toolCalls:i.toolCalls.map(l=>l.id===n?{...l,result:r,isError:s}:l)}:i})}function Ac(t,n,r){if(n.type==="reasoning_summary_delta"){const s=t.findIndex(i=>{var a,l;return(l=(a=i.presentation)==null?void 0:a.reasoning)==null?void 0:l.some(u=>u.itemId===n.itemId)});return s<0?[...t,{id:`codex-live-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:ws(void 0,n)},timestamp:r}]:t.map((i,a)=>{var l;return a===s?{...i,presentation:{...i.presentation,reasoning:ws((l=i.presentation)==null?void 0:l.reasoning,n)}}:i})}if(n.type==="tool_call"){const s=t.findIndex(i=>{var a;return(a=i.toolCalls)==null?void 0:a.some(l=>l.id===n.toolCall.id)});return s>=0?t.map((i,a)=>{var l;return a===s?{...i,toolCalls:(l=i.toolCalls)==null?void 0:l.map(u=>u.id===n.toolCall.id?{...u,name:n.toolCall.name,arguments:n.toolCall.arguments}:u)}:i}):[...t,{id:`codex-live-tool:${n.toolCall.id}`,role:"assistant",content:"",toolCalls:[{...n.toolCall}],timestamp:r}]}return t.some(s=>{var i;return(i=s.toolCalls)==null?void 0:i.some(a=>a.id===n.result.toolCallId)})?Sa(t,n.result.toolCallId,n.result.content,n.result.isError):[...t]}function wo(t,n,r,s=Date.now()){var g;const i=t.findIndex(x=>{var j;return((j=x.executionTrace)==null?void 0:j.turnId)===n}),a=i>=0?((g=t[i].executionTrace)==null?void 0:g.liveMessages)??[]:[],l=Ac(a,r,s);if(l.length===0&&a.length===0)return[...t];if(i>=0)return t.map((x,j)=>j===i?{...x,executionTrace:{...x.executionTrace,liveMessages:l}}:x);if(l===a)return[...t];const u=t.findLastIndex(x=>x.role==="user"&&!x.isQueued);if(u<0)return[...t];const h={id:`codex-execution-trace:${n}`,role:"assistant",content:"",executionTrace:{turnId:n,revision:`live:${n}`,liveMessages:l},timestamp:s};return[...t.slice(0,u+1),h,...t.slice(u+1)]}function Rc(t,n){const r=new Map(t.map(s=>[`${s.itemId}:${s.sectionIndex}`,s]));for(const s of n){const i=`${s.itemId}:${s.sectionIndex}`,a=r.get(i),l=a?s.text.startsWith(a.text)?s.text:a.text.startsWith(s.text)?a.text:s.text:s.text;r.set(i,{...s,text:l})}return[...r.values()]}function Tc(t,n){var s,i,a;const r=t.map(l=>{var u,h;return{...l,toolCalls:(u=l.toolCalls)==null?void 0:u.map(g=>({...g})),presentation:(h=l.presentation)!=null&&h.reasoning?{...l.presentation,reasoning:[...l.presentation.reasoning]}:l.presentation}});for(const l of n){const u=(s=l.presentation)==null?void 0:s.reasoning;if(u!=null&&u.length){const h=r.findIndex(g=>{var x,j;return(j=(x=g.presentation)==null?void 0:x.reasoning)==null?void 0:j.some(b=>u.some(w=>w.itemId===b.itemId))});if(h>=0){const g=r[h];r[h]={...g,presentation:{...g.presentation,reasoning:Rc(((i=g.presentation)==null?void 0:i.reasoning)??[],u)}}}else r.push(l)}for(const h of l.toolCalls??[]){const g=r.findIndex(x=>{var j;return(j=x.toolCalls)==null?void 0:j.some(b=>b.id===h.id)});if(g>=0){const x=r[g];r[g]={...x,toolCalls:(a=x.toolCalls)==null?void 0:a.map(j=>j.id===h.id?{...j,...h}:j)}}else r.push({...l,presentation:void 0,toolCalls:[h]})}}return r}function ji(t){for(let n=t.length-1;n>=0;n--)if(t[n].type==="context_usage"&&t[n].usage)return t[n].usage}function ki(t){var r;const n=new Map;for(const s of t)s.type==="native_subagent_update"&&((r=s.activity)!=null&&r.parentToolCallId)&&n.set(s.activity.parentToolCallId,s.activity);return[...n.values()]}function Si(t,n){var r,s;if(n.role==="assistant"&&((r=n.toolCalls)!=null&&r.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:n.toolCalls}]}return[...t,n]}function Ii(t,n){var s;if(!n)return t;const r=t[t.length-1];if(r&&r.role==="assistant"&&!((s=r.toolCalls)!=null&&s.length)&&!r.askUser&&!r.isCompactionSummary){const i=[...t];return i[i.length-1]={...r,content:r.content+n},i}return[...t,{id:crypto.randomUUID(),role:"assistant",content:n,timestamp:Date.now()}]}function Ci(t,n,r,s){return t.map(i=>{if(!i.toolCalls)return i;const a=i.toolCalls.map(l=>l.id===n?{...l,result:r,isError:s}:l);return{...i,toolCalls:a}})}function Ai(t,n,r,s){return t.map(i=>{if(!i.toolCalls)return i;const a=i.toolCalls.map(l=>l.name==="dispatch_agent"&&l.arguments.subSessionId===n?{...l,arguments:{...l.arguments,subAgentStatus:r,subAgentDetail:s}}:l);return{...i,toolCalls:a}})}function Ri(t,n,r){return t.map(s=>{if(!s.toolCalls)return s;const i=s.toolCalls.map(a=>a.name==="dispatch_agent"&&a.arguments.subSessionId===n?{...a,arguments:{...a.arguments,subAgentProgress:(a.arguments.subAgentProgress?a.arguments.subAgentProgress+`
|
|
247
|
+
`+r:r).split(`
|
|
248
|
+
`).slice(-30).join(`
|
|
249
|
+
`)}}:a);return{...s,toolCalls:i}})}function Ti(t,n,r){return t.map(s=>s.id===n?r(s):s)}function Mi(t,n){const r=t.findIndex(s=>{var i,a;return(a=(i=s.presentation)==null?void 0:i.reasoning)==null?void 0:a.some(l=>l.itemId===n.itemId)});return r<0?[...t,{id:`native-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:ws(void 0,n)},timestamp:Date.now()}]:t.map((s,i)=>{var a;return i===r?{...s,presentation:{...s.presentation,reasoning:ws((a=s.presentation)==null?void 0:a.reasoning,n)}}:s})}const xe=pa((t,n)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(r,s)=>t(i=>{const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:Si(i.messages,r),u=a?{...i.messagesBySession,[a]:Si(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),r)}:i.messagesBySession;return{messages:l,messagesBySession:u,currentText:a&&a!==i.sessionId?i.currentText:""}}),appendText:(r,s)=>t(i=>{if(!r)return i;const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:Ii(i.messages,r),u=a?{...i.messagesBySession,[a]:Ii(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),r)}:i.messagesBySession;return{messages:l,messagesBySession:u,currentText:a&&a!==i.sessionId?i.currentText:i.currentText+r}}),setRunningSession:r=>t({runningSessionId:r}),setSessionId:r=>t({sessionId:r}),updateToolResult:(r,s,i,a)=>t(l=>{const u=a??l.sessionId??void 0,h=u&&u!==l.sessionId?l.messages:Ci(l.messages,r,s,i),g=u?{...l.messagesBySession,[u]:Ci(l.messagesBySession[u]??(u===l.sessionId?l.messages:[]),r,s,i)}:l.messagesBySession;return{messages:h,messagesBySession:g}}),setMessages:(r,s)=>t(i=>{const a=s??i.sessionId??void 0,l=!a||a===i.sessionId;return{messages:l?r:i.messages,messagesBySession:a?{...i.messagesBySession,[a]:r}:i.messagesBySession,currentText:l?"":i.currentText}}),getMessagesForSession:r=>n().messagesBySession[r]??[],setContextUsage:(r,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{contextUsageBySession:{...i.contextUsageBySession,[a]:r}}:i}),getContextUsageForSession:r=>n().contextUsageBySession[r],applyRuntimeProgress:(r,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{runtimeProgressBySession:{...i.runtimeProgressBySession,[a]:ja(i.runtimeProgressBySession[a]??[],r)}}:i}),setRuntimeProgress:(r,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{runtimeProgressBySession:{...i.runtimeProgressBySession,[a]:r}}:i}),clearRuntimeProgress:r=>t(s=>{var u;const i=r??s.sessionId??void 0;if(!i||!((u=s.runtimeProgressBySession[i])!=null&&u.length))return s;const{[i]:a,...l}=s.runtimeProgressBySession;return{runtimeProgressBySession:l}}),applyNativeSubagentActivity:(r,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[a]:{...i.nativeSubagentsBySession[a]??{},[r.parentToolCallId]:r}}}:i}),setNativeSubagentActivities:(r,s)=>t(i=>{const a=s??i.sessionId??void 0;return a?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[a]:Object.fromEntries(r.map(l=>[l.parentToolCallId,l]))}}:i}),applyReasoningSummary:(r,s)=>t(i=>{const a=s??i.sessionId??void 0,l=a&&a!==i.sessionId?i.messages:Mi(i.messages,r),u=a?{...i.messagesBySession,[a]:Mi(i.messagesBySession[a]??(a===i.sessionId?i.messages:[]),r)}:i.messagesBySession;return{messages:l,messagesBySession:u}}),applyCodexExecutionEvent:(r,s,i)=>t(a=>{const l=i??a.sessionId??void 0,u=Date.now(),h=l&&l!==a.sessionId?a.messages:wo(a.messages,r,s,u),g=l?{...a.messagesBySession,[l]:wo(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),r,s,u)}:a.messagesBySession;return{messages:h,messagesBySession:g}}),updateMessage:(r,s,i)=>t(a=>{const l=i??a.sessionId??void 0,u=l&&l!==a.sessionId?a.messages:Ti(a.messages,r,s),h=l?{...a.messagesBySession,[l]:Ti(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),r,s)}:a.messagesBySession;return{messages:u,messagesBySession:h}}),updateSubAgentStatus:(r,s,i,a)=>t(l=>{const u=a??l.sessionId??void 0,h=u&&u!==l.sessionId?l.messages:Ai(l.messages,r,s,i),g=u?{...l.messagesBySession,[u]:Ai(l.messagesBySession[u]??(u===l.sessionId?l.messages:[]),r,s,i)}:l.messagesBySession;return{messages:h,messagesBySession:g}}),updateSubAgentProgress:(r,s,i)=>t(a=>{const l=i??a.sessionId??void 0,u=l&&l!==a.sessionId?a.messages:Ri(a.messages,r,s),h=l?{...a.messagesBySession,[l]:Ri(a.messagesBySession[l]??(l===a.sessionId?a.messages:[]),r,s)}:a.messagesBySession;return{messages:u,messagesBySession:h}}),clearMessages:r=>t(s=>{const i=r??s.sessionId??void 0;if(!i)return{messages:[],currentText:""};const{[i]:a,...l}=s.messagesBySession,{[i]:u,...h}=s.contextUsageBySession,{[i]:g,...x}=s.runtimeProgressBySession,{[i]:j,...b}=s.nativeSubagentsBySession;return{messages:i===s.sessionId?[]:s.messages,messagesBySession:l,contextUsageBySession:h,runtimeProgressBySession:x,nativeSubagentsBySession:b,currentText:i===s.sessionId?"":s.currentText}}),setTodos:r=>t({todos:r}),setCronTasks:r=>t({cronTasks:r})}));function To(){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 Mc(){return Ia()!==null||To()!==null}function Ec(t){var a,l;const n=Ia();if(n){let u=!1,h=()=>{},g=()=>{};const x=()=>{var j;u||(u=!0,h(),g(),(j=t.onEnd)==null||j.call(t))};return h=n.onDictation(({text:j,isFinal:b})=>{const w=j.trim();w&&(b?(t.onFinal(w),x()):t.onInterim(w))}),g=n.onDictationError(j=>{var b;(b=t.onError)==null||b.call(t,j),x()}),n.dictationStart().then(j=>{var b;j.ok||((b=t.onError)==null||b.call(t,j.reason||"无法启动语音识别"),x())}).catch(()=>{var j;(j=t.onError)==null||j.call(t,"无法启动语音识别"),x()}),{stop:()=>{n.dictationStop()}}}const r=To();if(!r)return(a=t.onError)==null||a.call(t,"当前环境不支持语音识别"),null;const s=new r;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let i="";s.onresult=u=>{let h="";for(let g=u.resultIndex;g<u.results.length;g++){const x=u.results[g];x.isFinal?i+=x[0].transcript:h+=x[0].transcript}h&&t.onInterim(i+h)},s.onerror=u=>{var h;u.error!=="no-speech"&&u.error!=="aborted"&&((h=t.onError)==null||h.call(t,`语音识别失败:${u.error??"未知错误"}`))},s.onend=()=>{var u;i&&t.onFinal(i.trim()),(u=t.onEnd)==null||u.call(t)};try{s.start()}catch{return(l=t.onEnd)==null||l.call(t),null}return{stop:()=>s.stop()}}function Nc(t){var l;const n=To();if(!n)return(l=t.onError)==null||l.call(t,"当前环境不支持语音唤醒"),null;let r=!1,s=null,i=null;const a=()=>{if(!r){s=new n,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=u=>{var x,j,b;const h=u.results[u.results.length-1],g=(j=(x=h==null?void 0:h[0])==null?void 0:x.transcript)==null?void 0:j.trim();g&&(h.isFinal&&((b=t.onHeard)==null||b.call(t,g)),g.includes(t.wakeWord)&&t.onWake(g))},s.onerror=u=>{var h;u.error==="not-allowed"&&((h=t.onError)==null||h.call(t,"麦克风权限被拒绝,语音唤醒已停用"),r=!0)},s.onend=()=>{r||(i=setTimeout(a,400))};try{s.start()}catch{i=setTimeout(a,800)}}};return a(),{stop:()=>{r=!0,i&&clearTimeout(i);try{s==null||s.abort()}catch{}}}}function qr(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function ps(t,n){return n(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const _c={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function zc(t){const n=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(n.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const r=new Float32Array(n.byteLength/2),s=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let i=0;i<r.length;i+=1)r[i]=s.getInt16(i*2,!0)/32768;return r}class Wc{constructor(n,r=_c){this.api=n,this.dependencies=r,this.context=null,this.node=null,this.ready=null,this.current=null}start(n){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const r={metadata:n,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=r,this.ensureReady().then(()=>{if(!(this.current!==r||!this.node)){this.node.port.postMessage({type:"start",generation:n.generation,sampleRate:n.sampleRate});for(const i of r.pending)this.postSamples(n.generation,i);r.pending=[],r.pendingSamples=0,r.finished&&this.node.port.postMessage({type:"finish",generation:n.generation})}}).catch(i=>this.fail(r,i))}enqueue(n,r){const s=this.current;if(!s||s.metadata.generation!==n||s.acknowledged)return;let i;try{i=zc(r)}catch(a){this.fail(s,a);return}if(this.node){this.postSamples(n,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(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||(r.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:n}))}flush(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:n}),r.pending=[],r.pendingSamples=0,this.acknowledge(r))}dispose(){var n,r;this.current&&this.flush(this.current.metadata.generation),(n=this.node)==null||n.disconnect(),this.node=null,(r=this.context)==null||r.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const n=this.dependencies.createContext();this.context=n,await n.audioWorklet.addModule(this.dependencies.workletUrl);const r=this.dependencies.createNode(n);r.port.onmessage=s=>this.onWorkletMessage(s.data),r.connect(n.destination),this.node=r,n.state!=="running"&&await n.resume()})(),this.ready)}postSamples(n,r){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:n,samples:r},[r.buffer])}onWorkletMessage(n){const r=this.current;if(!(!r||n.generation!==r.metadata.generation)){if(n.type==="drained"||n.type==="stopped"){this.acknowledge(r);return}n.type==="overflow"&&this.fail(r,new Error("TTS AudioWorklet buffer overflow"))}}fail(n,r){this.current!==n||n.acknowledged||(console.error("[tts] PCM playback failed",r),n.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(n.metadata.generation))}acknowledge(n){this.current!==n||n.acknowledged||(n.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(n.metadata.generation))}}async function mr(t,n,r,s,i,a,l){if(r!=="codex"){const h=l?await l():await t.getSession(n,s);a()&&i(h,"full");return}const u=l?await l():await t.getSession(n,{...s,view:"core"});a()&&i(u,"core")}function Ei(t,n,r,s){const i=r==="core"&&(s==null?void 0:s.delivery)!=="legacy-full"&&!!(s!=null&&s.revision),a=t.some(l=>!l.isQueued);return i&&a?Lc(t,n):Aa(t,n)}function Lc(t,n){var F,v;if(n.length===0)return t;if(t.length===0)return n;let r=t.filter(y=>!y.isQueued);const s=t.filter(y=>y.isQueued),i=n.findLastIndex(y=>y.role==="user"&&!y.isCompactionSummary);if(i<0)return t;const a=n[i];let l=r.findLastIndex(y=>y.role==="user"&&!y.isCompactionSummary&&jn(y)===jn(a));if(l<0)return[...r,...n.slice(i),...s];const u=Aa(r.slice(0,l),n.slice(0,i));r=[...u,...r.slice(l)],l=u.length;const h=r.findIndex((y,B)=>B>l&&y.role==="user"&&!y.isCompactionSummary),g=h<0?r.length:h,x=[];for(let y=l+1;y<g;y+=1)Ni(r[y])&&x.push(y);const j=n.slice(i+1).filter(Ni),b=(v=(F=n.find(y=>y.executionTrace))==null?void 0:F.executionTrace)==null?void 0:v.revision,w=r.map(y=>y.executionTrace&&b?{...y,executionTrace:{...y.executionTrace,revision:b}}:y),S=n.slice(i+1).find(y=>y.executionTrace),R=r.findIndex((y,B)=>{var $,A;return B>l&&B<g&&(($=y.executionTrace)==null?void 0:$.turnId)===((A=S==null?void 0:S.executionTrace)==null?void 0:A.turnId)});if(S&&R>=0){const y=r[R].executionTrace;w[R]={...S,id:r[R].id,timestamp:r[R].timestamp,executionTrace:{...S.executionTrace,...y!=null&&y.liveMessages?{liveMessages:y.liveMessages}:{}}}}const E=Math.min(x.length,j.length);for(let y=0;y<E;y+=1){const B=x[y],$=w[B],A=j[y];w[B]={...$,...A,id:A.id.startsWith("history-message.v1.")?A.id:$.id,timestamp:$.timestamp,images:A.images??$.images,presentation:A.presentation??$.presentation}}return j.length>E&&w.splice(g,0,...j.slice(E)),[...w,...s]}function Ni(t){var n,r,s;return t.role==="assistant"&&!t.executionTrace&&!((n=t.toolCalls)!=null&&n.length)&&!t.askUser&&!t.isCompactionSummary&&!((s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length)}function br(t){var i,a;const n=((i=t==null?void 0:t.history)==null?void 0:i.delivery)==="core",r=Ca(t,!n),s=(a=t==null?void 0:t.history)==null?void 0:a.revision;return!n||!s?r:Oc(Sc(r,s),(t==null?void 0:t.events)??[])}function Pc(t){return Ca(t).filter(Ic)}function Ca(t,n=!0){var j;const r=(t==null?void 0:t.messages)??[],s=(t==null?void 0:t.events)??[],i=new Set(s.filter(b=>b.type==="approval_resolved"&&b.questionId).map(b=>b.questionId)),a=new Map;for(const b of s)b.type==="tool_result"&&((j=b.result)!=null&&j.toolCallId)&&a.set(b.result.toolCallId,{content:b.result.content??"",isError:b.result.isError});const l=r.filter(b=>(b.role==="user"||b.role==="assistant"||b.role==="tool")&&b.name!=="__interrupt__").map(Fc),u=new Map;for(const b of l)b.role==="tool"&&b.toolCallId&&u.set(b.toolCallId,b);let h=l.filter(b=>b.role!=="tool").map(b=>{var w;return b.isCompactionSummary?b:b.role==="assistant"&&((w=b.toolCalls)!=null&&w.length)?{...b,toolCalls:b.toolCalls.map(S=>{const R=u.get(S.id);if(R)return{...S,...R.toolResultRef?{resultRef:R.toolResultRef,isError:R.toolResultRef.isError}:{result:R.content}};const E=a.get(S.id);return E?{...S,result:E.content,isError:E.isError}:S})}:b.role==="user"&&b.name&&b.name!=="__compaction_checkpoint__"&&!b.name.startsWith("__native_")?{...b,agentName:b.name}:b});const g=Uc(s,n);if(!h.some(b=>b.role==="assistant"&&!b.isCompactionSummary)&&g){const b=h.findLastIndex(w=>w.role==="user"&&!w.isCompactionSummary);h=b>=0?[...h.slice(0,b+1),g,...h.slice(b+1)]:[...h,g]}const x=new Set(h.flatMap(b=>{var w;return(w=b.askUser)!=null&&w.questionId?[b.askUser.questionId]:[]}));for(const b of s)b.type!=="ask_user"||!b.questionId||i.has(b.questionId)||x.has(b.questionId)||(x.add(b.questionId),h.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:b.questionId,question:b.question??"",options:b.options,fields:b.fields,multiSelect:b.multiSelect},timestamp:Date.now()}));return h}function Aa(t,n){if(n.length===0)return t;if(t.length===0)return n;const r=t.map(jo),s=n.map(jo),i=Math.max(0,t.length-n.length),a=Bc(t,n,i);let l={currentStart:i,length:0,distance:1/0};for(let b=0;b<r.length;b++)for(let w=0;w<s.length;w++){if(r[b]!==s[w])continue;const S=b-w;if(S<0)continue;let R=0;for(;b+R<r.length&&w+R<s.length&&r[b+R]===s[w+R];)R+=1;const E=Math.abs(S-i);(R>l.length||R===l.length&&E<l.distance)&&(l={currentStart:S,length:R,distance:E})}const u=a??(l.length>0?l.currentStart:i),h=n.map((b,w)=>{var F,v,y;const S=t[u+w];if(!S||!$c(S,b,s[w]))return b;const R=(v=(F=b.presentation)==null?void 0:F.attachments)==null?void 0:v.some(B=>B.dataUrl),E=(y=b.toolCalls)==null?void 0:y.map(B=>{var A;const $=(A=S.toolCalls)==null?void 0:A.find(C=>C.id===B.id);return($==null?void 0:$.result)===void 0?B:{...B,result:$.result,isError:$.isError}});return{...b,id:b.id.startsWith("history-message.v1.")?b.id:S.id,timestamp:S.timestamp,images:R?void 0:b.images??S.images,...E?{toolCalls:E}:{}}}),g=t.filter(b=>b.isQueued),x=t.slice(u).filter(b=>!b.isQueued),j=Dc(x,h);return[...t.slice(0,u).filter(b=>!b.isQueued),...j,...g]}function Dc(t,n){const r=n.findLastIndex(S=>S.role==="user"&&!S.isQueued);if(r<0)return n;const s=jn(n[r]);let i=-1,a=1/0;for(let S=0;S<t.length;S+=1){const R=t[S];if(R.role!=="user"||R.isQueued||jn(R)!==s)continue;const E=Math.abs(S-r);E<a&&(i=S,a=E)}if(i<0)return n;const l=t.findIndex((S,R)=>R>i&&S.role==="user"&&!S.isQueued),u=t.slice(i+1,l<0?t.length:l),h=n.slice(r+1),g=_i(u),x=_i(h);if(g.length<=x.length||!g.startsWith(x))return n;const j=g.slice(x.length),b=n.findLastIndex((S,R)=>{var E;return R>r&&S.role==="assistant"&&!((E=S.toolCalls)!=null&&E.length)&&!S.askUser&&!S.isCompactionSummary});if(b>=0)return n.map((S,R)=>R===b?{...S,content:S.content+j}:S);const w=u.findLast(S=>S.role==="assistant"&&!!S.content&&!S.isCompactionSummary);return[...n,{id:(w==null?void 0:w.id)??crypto.randomUUID(),role:"assistant",content:j,timestamp:(w==null?void 0:w.timestamp)??Date.now()}]}function _i(t){return t.filter(n=>n.role==="assistant"&&!n.isCompactionSummary).map(n=>n.content).join("")}function Bc(t,n,r){const s=n[0];if((s==null?void 0:s.role)!=="user")return null;const i=jn(s);let a=null;for(let l=0;l<t.length;l+=1){if(t[l].role!=="user"||t[l].isQueued||jn(t[l])!==i)continue;const u=Math.abs(l-r);(!a||u<a.distance)&&(a={start:l,distance:u})}return(a==null?void 0:a.start)??null}function $c(t,n,r){var s,i;return jo(t)===r||t.role==="assistant"&&n.role==="assistant"&&t.content===n.content&&JSON.stringify(((s=t.toolCalls)==null?void 0:s.map(a=>a.id))??[])===JSON.stringify(((i=n.toolCalls)==null?void 0:i.map(a=>a.id))??[])?!0:t.role==="user"&&n.role==="user"&&jn(t)===jn(n)}function jn(t){var n;return JSON.stringify({role:t.role,content:t.content,name:(n=t.name)!=null&&n.startsWith("__native_")?void 0:t.name,agentName:t.agentName,isCompactionSummary:t.isCompactionSummary})}function jo(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,toolResultRef:t.toolResultRef,name:t.name,agentName:t.agentName,presentation:t.role==="user"?void 0:t.presentation,isCompactionSummary:t.isCompactionSummary})}function Fc(t){var n;if(t.name==="__compaction_checkpoint__"){let r="";try{r=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:r,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:t.historyId??crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(n=t.toolCalls)!=null&&n.length?t.toolCalls:void 0,toolCallId:t.toolCallId,toolResultRef:t.toolResultRef,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function Oc(t,n){return n.reduce((r,s)=>{var a;if(!s.turnId)return r;let i=null;return s.type==="reasoning_summary_delta"&&s.itemId&&Number.isSafeInteger(s.sectionIndex)&&typeof s.delta=="string"?i={type:"reasoning_summary_delta",turnId:s.turnId,itemId:s.itemId,sectionIndex:s.sectionIndex,delta:s.delta}:s.type==="tool_call"&&s.toolCall?i={type:"tool_call",turnId:s.turnId,toolCall:s.toolCall}:s.type==="tool_result"&&((a=s.result)!=null&&a.toolCallId)&&(i={type:"tool_result",turnId:s.turnId,result:{toolCallId:s.result.toolCallId,content:s.result.content??"",isError:s.result.isError}}),i?wo(r,s.turnId,i):r},t)}function Uc(t,n=!0){var a;let r="";const s=[],i=new Map;for(const l of t){if(l.type==="text_chunk"&&l.text&&(r+=l.text),n&&l.type==="tool_call"&&l.toolCall){const u={id:l.toolCall.id,name:l.toolCall.name,arguments:l.toolCall.arguments};s.push(u),i.set(u.id,u)}if(n&&l.type==="tool_result"&&((a=l.result)!=null&&a.toolCallId)){const u=i.get(l.result.toolCallId);u&&(u.result=l.result.content??"",u.isError=l.result.isError)}}return!r.trim()&&s.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:s.length>0?s:void 0,timestamp:Date.now()}}class qc{constructor(){this.slot=null}prefetch(n,r,s){return this.getOrStart(n,r,s).promise}async consume(n,r,s){const i=this.getOrStart(n,r,s);try{return await i.promise}finally{this.slot===i&&(this.slot=null)}}invalidate(){this.slot=null}getOrStart(n,r,s){var l;if(((l=this.slot)==null?void 0:l.sessionId)===n&&this.slot.cursor===r)return this.slot;let i;try{i=s()}catch(u){i=Promise.reject(u)}const a={sessionId:n,cursor:r,promise:i};return this.slot=a,i.catch(()=>{this.slot===a&&(this.slot=null)}),a}}const Ra=60,Hc=32,Vc=240,Qc=6,Kc=10;function zi(t,n,r,s){if(s<=1||r<=0)return 0;const i=Math.max(0,Math.min(1,(t-n)/r));return Math.round(i*(s-1))}function Gc(t){const n=Math.min(Math.max(0,t),Ra);return n<=1?n===1?[0]:[]:Array.from({length:n},(r,s)=>Math.round(s/(n-1)*(t-1)))}function Wi(t,n=Qc){return Math.min(Vc,Math.max(Hc,Math.min(Math.max(0,t),Ra)*n))}function Zc(t,n,r){if(r<=0)return null;const s=Math.max(5,Math.round(r/10));return n==="ArrowUp"||n==="ArrowLeft"?Math.max(0,t-1):n==="ArrowDown"||n==="ArrowRight"?Math.min(r-1,t+1):n==="PageUp"?Math.max(0,t-s):n==="PageDown"?Math.min(r-1,t+s):n==="Home"?0:n==="End"?r-1:null}function Jc({entries:t,activeMessageId:n,loadingMessageId:r,onActivate:s}){const i=t.findIndex(E=>E.messageId===n),a=i>=0?i:Math.max(0,t.length-1),[l,u]=d.useState(a),[h,g]=d.useState(!1),x=d.useRef(!1),j=d.useMemo(()=>Gc(t.length),[t.length]);if(d.useEffect(()=>u(a),[a]),t.length<2)return null;const b=Math.min(l,t.length-1),w=t[b],S=r===w.messageId,R=(E,F)=>{const v=F.getBoundingClientRect();u(zi(E,v.top,v.height,t.length))};return e.jsxs("div",{className:`query-navigation-rail${h?" query-navigation-rail--open":""}`,style:{"--query-navigation-rail-height":`${Wi(t.length)}px`,"--query-navigation-rail-web-height":`${Wi(t.length,Kc)}px`},role:"slider",tabIndex:0,"aria-label":"用户消息导航","aria-orientation":"vertical","aria-valuemin":1,"aria-valuemax":t.length,"aria-valuenow":w.ordinal,"aria-valuetext":`第 ${w.ordinal} 条:${w.preview}`,"aria-busy":S||void 0,onPointerEnter:E=>{g(!0),R(E.clientY,E.currentTarget)},onPointerMove:E=>{E.pointerType==="touch"&&!x.current||R(E.clientY,E.currentTarget)},onPointerLeave:()=>{x.current||g(!1)},onPointerDown:E=>{x.current=!0,g(!0),E.currentTarget.setPointerCapture(E.pointerId),R(E.clientY,E.currentTarget)},onPointerUp:E=>{R(E.clientY,E.currentTarget);const F=zi(E.clientY,E.currentTarget.getBoundingClientRect().top,E.currentTarget.getBoundingClientRect().height,t.length);x.current=!1,E.currentTarget.releasePointerCapture(E.pointerId),s(t[F]),E.pointerType==="touch"&&g(!1)},onPointerCancel:()=>{x.current=!1,g(!1)},onFocus:()=>g(!0),onBlur:()=>g(!1),onKeyDown:E=>{if(E.key==="Enter"){E.preventDefault(),s(w);return}const F=Zc(b,E.key,t.length);F!==null&&(E.preventDefault(),u(F))},children:[e.jsxs("div",{className:"query-navigation-rail__track","aria-hidden":"true",children:[j.map(E=>e.jsx("span",{className:`query-navigation-rail__tick${E===b?" is-selected":""}${t[E].messageId===n?" is-active":""}`},E)),e.jsx("span",{className:"query-navigation-rail__marker",style:{top:`${b/Math.max(1,t.length-1)*100}%`}})]}),S&&e.jsx("span",{className:"query-navigation-rail__loading",role:"status","aria-label":"正在定位消息",children:e.jsx(Rt,{size:14,"aria-hidden":"true"})}),h&&e.jsxs("div",{className:"query-navigation-rail__preview",role:"status",children:[e.jsxs("span",{children:[w.ordinal," / ",t.length]}),e.jsx("p",{children:w.preview})]})]})}const Yc=/^(?:load failed|failed to fetch|network request failed|networkerror when attempting to fetch resource\.?|the network connection was lost\.?|fetch failed)$/i;function Ta(t){return t instanceof Error&&t.name!=="AbortError"&&Yc.test(t.message.trim())}function Xc(t){return Ta(t)?"网络连接中断,会话加载失败,请重新加载":t instanceof Error?t.message:"会话加载失败"}async function ed(t,n={}){const r=Math.max(1,Math.floor(n.maxAttempts??4)),s=Math.max(0,n.baseDelayMs??500),i=n.sleep??(a=>new Promise(l=>{setTimeout(l,a)}));for(let a=1;a<=r;a+=1)try{return await t()}catch(l){if(a===r||!Ta(l))throw l;await i(s*2**(a-1))}throw new Error("会话加载失败")}const td=2048,nd=2*1024*1024,rd=.85;function sd(t,n,r=td){const s=Math.max(t,n);if(s<=r)return{width:t,height:n};const i=r/s;return{width:Math.max(1,Math.round(t*i)),height:Math.max(1,Math.round(n*i))}}async function Li(t,n=od){if(t.type.toLowerCase()==="image/gif")return t;let r=null;try{r=await n.decode(t);const s=sd(r.width,r.height);if(!(s.width!==r.width||s.height!==r.height)&&t.size<=nd)return t;const a=t.type.toLowerCase()==="image/jpeg"?"image/jpeg":"image/webp",l=await n.encode(r,s.width,s.height,a,rd);return l&&l.size<t.size?l:t}catch{return t}finally{r==null||r.dispose()}}const od={decode(t){return new Promise((n,r)=>{const s=URL.createObjectURL(t),i=new Image;let a=!1;const l=()=>URL.revokeObjectURL(s);i.onload=()=>{a=!0,n({source:i,width:i.naturalWidth,height:i.naturalHeight,dispose:l})},i.onerror=()=>{a||l(),r(new Error("无法解码图片"))},i.src=s})},encode(t,n,r,s,i){const a=document.createElement("canvas");a.width=n,a.height=r;const l=a.getContext("2d");return l?(l.drawImage(t.source,0,0,n,r),new Promise(u=>a.toBlob(u,s,i))):Promise.resolve(null)}};function id(t){return t==="customer-agent"||t==="claude-code"}function ad(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),Object.assign(n.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(n);try{return n.focus(),n.select(),n.setSelectionRange(0,n.value.length),document.execCommand("copy")}catch{return!1}finally{n.remove()}}async function eo(t){const n=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(n==null?void 0:n.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await n.writeText(t),!0}catch{}return ad(t)}const ld="agentroam:draft:";function js(t){return`${ld}${t}`}function cd(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(js(t))??""}catch{return""}}function to(t,n){if(!(!t||typeof window>"u"))try{n?window.localStorage.setItem(js(t),n):window.localStorage.removeItem(js(t))}catch{}}function dd(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(js(t))}catch{}}const ud="agent-webapp:artifact-open:v1";let Pi=0;function Di(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function Ma(t,n){const r=t.trim();if(!r||/[\0\r\n]/.test(r))return null;if(Di(r))return r;if(!n||!Di(n))return null;const s=r.replaceAll("\\","/").split("/").filter(a=>a&&a!==".");if(s.length===0||s.some(a=>a===".."))return null;const i=/^[A-Za-z]:[\\/]/.test(n)||n.startsWith("\\\\")?"\\":"/";return`${n.replace(/[\\/]+$/,"")}${i}${s.join(i)}`}function Hn(t,n=window){return n.parent===n?!1:(Pi+=1,n.parent.postMessage({type:ud,requestId:Pi,path:t},n.location.origin),!0)}function pd(t){var n;return((n=[...t].reverse().find(r=>r.role==="user"&&!r.isQueued))==null?void 0:n.id)??null}function fd(t,n){const r=new Set(n.flatMap(s=>s.sourceMessageId?[s.sourceMessageId]:[]));return r.size===0?t:t.filter(s=>!r.has(s.id))}function no(t,n){var l,u,h;const r=t.filter(g=>!g.isQueued),s=new Map(t.filter(g=>g.isQueued&&g.queueItemId).map(g=>[g.queueItemId,g])),i=((l=n.active)==null?void 0:l.kind)==="message"?n.active:null;if(i){const g=s.get(i.id),x=i.sourceMessageId||(g==null?void 0:g.id)||i.id,j=r.findLastIndex(R=>R.role==="user"),b=r.findLastIndex((R,E)=>R.id===x||R.queueItemId===i.id||!g&&E===j&&R.role==="user"&&R.content===i.objective),w=b>=0?r[b]:g,S={...w??{},id:(w==null?void 0:w.id)||x,role:"user",content:i.objective,timestamp:(w==null?void 0:w.timestamp)??i.createdAt,agentName:(w==null?void 0:w.agentName)??((u=i.messagePayload)==null?void 0:u.agentName),images:(w==null?void 0:w.images)??((h=i.messagePayload)==null?void 0:h.images),isQueued:!1,queueItemId:void 0};b>=0?r[b]=S:r.push(S)}const a=n.queued.filter(g=>g.kind==="message").map(g=>{var j,b;const x=s.get(g.id);return{...x??{},id:g.sourceMessageId||(x==null?void 0:x.id)||g.id,role:"user",content:g.objective,timestamp:(x==null?void 0:x.timestamp)??g.createdAt,agentName:(j=g.messagePayload)==null?void 0:j.agentName,images:(b=g.messagePayload)==null?void 0:b.images,isQueued:!0,queueItemId:g.id}});return[...r,...a]}function Bi(t){var n;return{active:((n=t.active)==null?void 0:n.kind)==="message"?null:t.active,queued:t.queued.filter(r=>r.kind!=="message"),history:t.history.filter(r=>r.kind!=="message")}}function gd(t,n,r){if(n===r)return t;const s=t.filter(g=>g.isQueued),i=s.findIndex(g=>g.id===n),a=s.findIndex(g=>g.id===r);if(i<0||a<0)return t;const l=[...s],[u]=l.splice(i,1);l.splice(a,0,u);let h=0;return t.map(g=>g.isQueued?l[h++]:g)}function hd(t,n){return((t==null?void 0:t.agentType)??n)!=="customer-agent"}function Mo(t){return(t==null?void 0:t.agentType)!==void 0&&t.agentType!=="customer-agent"&&t.status==="running"}function xd(t){return Mo(t)&&(t==null?void 0:t.occupancy)==="owned-externally"}function Ea(t){return Mo(t)&&(t==null?void 0:t.occupancy)!=="owned-externally"}function md(t){return(t==null?void 0:t.agentType)==="customer-agent"&&t.status==="active"}function bd(t,n){return n||Ea(t)}function yd(t,n,r){return!!(n&&t&&t.agentType!=="customer-agent")}function fs(t,n){return t.find(r=>r.id===n)??null}const Ss=pa((t,n)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(r,s)=>t(i=>{const a={...i,[r]:s};return a.isConfigured=!!(a.apiKey&&a.modelId),a}),loadFromSystem:async()=>{if(window.agentApi)try{const r=await window.agentApi.getSettings(),s=r.profiles??[],i=r.activeProfileId??"",a=fs(s,i);t({modelProvider:(a==null?void 0:a.provider)??r.modelProvider??"anthropic",modelId:(a==null?void 0:a.modelId)??r.modelId??"claude-sonnet-4-6",apiKey:(a==null?void 0:a.apiKey)??r.apiKey??"",baseUrl:(a==null?void 0:a.baseUrl)??r.baseUrl??"",maxIterations:r.maxIterations??10,contextWindow:r.contextWindow??100,workingDirectory:r.workingDirectory??"/",isConfigured:!!(((a==null?void 0:a.apiKey)??r.apiKey)&&((a==null?void 0:a.modelId)??r.modelId)),profiles:s,activeProfileId:i,reasoningEffort:["off","low","medium","high"].includes(r.reasoningEffort??"")?r.reasoningEffort:"off"})}catch(r){console.error("Failed to load settings:",r)}},saveToSystem:async()=>{if(!window.agentApi)return;const r=n();await window.agentApi.saveSettings({modelProvider:r.modelProvider,modelId:r.modelId,apiKey:r.apiKey,baseUrl:r.baseUrl,maxIterations:r.maxIterations,contextWindow:r.contextWindow,workingDirectory:r.workingDirectory,isConfigured:r.isConfigured,profiles:r.profiles,activeProfileId:r.activeProfileId,reasoningEffort:r.reasoningEffort})},addProfile:r=>{const i={id:crypto.randomUUID(),...r};t(a=>({profiles:[...a.profiles,i]}))},updateProfile:(r,s)=>{t(a=>({profiles:a.profiles.map(l=>l.id===r?{...l,...s}:l)}));const i=n();if(i.activeProfileId===r){const a=fs(i.profiles,r);a&&t({modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})}},deleteProfile:r=>{t(s=>{var u;const i=s.profiles.filter(h=>h.id!==r),a=s.activeProfileId===r?((u=i[0])==null?void 0:u.id)??"":s.activeProfileId,l=fs(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:r=>{const s=n(),i=fs(s.profiles,r);i&&t({activeProfileId:r,modelProvider:i.provider,modelId:i.modelId,apiKey:i.apiKey,baseUrl:i.baseUrl,isConfigured:!!(i.apiKey&&i.modelId)})},switchActiveProfile:async r=>{n().setActiveProfileLocal(r),window.agentApi&&await window.agentApi.setActiveProfile(r)}}));function wr(t){return t.result!==void 0||t.resultRef!==void 0}function ro(t){return t.every(wr)}const Eo=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),Na=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),_a=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]),vd=new Set(["Read","read_file"]),wd=new Set(["Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]);function No(t){return Eo.has(t)?"command":Na.has(t)?"file":_a.has(t)?"search":"generic"}function _o(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 jd(t){var n;return((n=_o(t))==null?void 0:n.done)??null}function za(t){return Eo.has(t)?"终端":vd.has(t)?"查阅":wd.has(t)?"写入":_a.has(t)?"查阅":t==="Skill"?"技能":t==="Task"||t==="dispatch_agent"||t==="Agent"?"子任务":t==="TodoWrite"?"任务":t.startsWith("mcp__")||t.includes(":")?"工具":null}function $i(t){return t.replace(/\\/g,"/").split("/").pop()??t}function so(t,n=60){const r=(t??"").split(`
|
|
250
|
+
`)[0].trim();return r.length>n?r.slice(0,n)+"…":r}function kd(t,n){if(Eo.has(t))return so(String(n.command??""));if(t==="apply_patch"){const s=(Array.isArray(n.changes)?n.changes:[]).map(i=>$i(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 Na.has(t)?n.file_path?$i(String(n.file_path)):null:t==="Glob"||t==="glob_search"?String(n.pattern??"")||null:t==="Grep"||t==="grep_search"?String(n.pattern??n.query??"")||null:t==="Skill"?String(n.skill??"")||null:t==="Task"?so(String(n.description??n.task??""),80)||null:t==="WebSearch"?so(String(n.query??"")):t==="WebFetch"?String(n.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function Sd(t,n){return Math.max(0,Math.floor((n-t)/1e3))}function zo({startedAt:t}){const[n,r]=d.useState(()=>Date.now());return d.useEffect(()=>{r(Date.now());const s=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(s)},[t]),e.jsxs("span",{className:"activity-elapsed-time",children:[" · 持续了 ",Sd(t,n)," 秒"]})}function Wa({progress:t,compact:n=!1,startedAt:r}){const s=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),i=[t.label,s].filter(Boolean).join(","),a=!n&&t.phase==="thinking",l=!n&&t.phase==="status",u=a&&r!==void 0&&s===void 0;return e.jsxs("div",{className:`runtime-progress-row${n?" 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(Ao,{size:17,strokeWidth:1.8})}):l?e.jsx("span",{className:"runtime-progress-row__status-icon","aria-hidden":"true",children:e.jsx(Rt,{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}),u&&e.jsx(zo,{startedAt:r})]})}function jr({isDone:t,isError:n,color:r,size:s=11}){return t?n?e.jsx(Ul,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Qr,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Rt,{size:s,color:r,strokeWidth:2.5,style:{animation:"spin 1s linear infinite",flexShrink:0},"aria-hidden":"true"})}function Zr({name:t,color:n,size:r=14}){const s=No(t);return s==="command"?e.jsx(cc,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="search"?e.jsx(ma,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="file"?t==="Read"||t==="read_file"?e.jsx(ks,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(ha,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Skill"?e.jsx(lc,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="TodoWrite"?e.jsx(rc,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Task"||t==="dispatch_agent"||t==="Agent"?e.jsx(pc,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(ba,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"})}function Is({statusColor:t,isDone:n,expanded:r,onToggle:s,header:i,children:a,maxBodyHeight:l=600,primaryAction:u,primaryActionLabel:h,primaryActionTitle:g}){const x=e.jsxs("button",{type:"button",className:"tool-call-shell__header",...u?{onClick:u,"aria-label":h,title:g}:{onClick:s,"aria-expanded":r},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:j=>j.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:j=>j.currentTarget.style.background="var(--bg-deep)",children:[i,!u&&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:r?"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:n?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),x,u&&e.jsx("button",{type:"button",className:"tool-call-shell__disclosure",onClick:s,"aria-expanded":r,"aria-label":r?"收起工具详情":"展开工具详情",title:r?"收起工具详情":"展开工具详情",children:e.jsx(qn,{className:"tool-call-shell__chevron",size:12,strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:r?"rotate(90deg)":"rotate(0deg)"},"aria-hidden":"true"})})]}),r&&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 Gr({label:t,color:n="var(--text-muted)",bg:r="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:r,color:n,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function Yt(t){return t.replace(/\\/g,"/").split("/").pop()??t}function La(t){return t?t.split(`
|
|
251
|
+
`).length:0}function Cs(t,n,r=!1){const[s,i]=d.useState(r),[a,l]=d.useState(!1),[u,h]=d.useState(null),g=async()=>{if(!(!t.resultRef||t.result!==void 0||a||!n)){l(!0),h(null);try{await n(t.resultRef)}catch(j){h(j instanceof Error?j.message:"工具结果加载失败")}finally{l(!1)}}};return{expanded:s,setExpanded:i,toggle:()=>{const j=!s;i(j),j&&g()},loadingResult:a,resultError:u,loadResult:g}}function As({toolCall:t,loading:n,error:r,retry:s}){return!t.resultRef||t.result!==void 0?null:r?e.jsx("button",{type:"button",onClick:()=>void s(),className:"ui-text-button",children:"重新加载工具结果"}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,color:"var(--text-muted)",fontSize:11},children:[e.jsx(Rt,{size:11,strokeWidth:2.2,style:{animation:n?"spin 1s linear infinite":"none"},"aria-hidden":"true"}),n?"正在加载工具结果":`${t.resultRef.byteSize.toLocaleString()} 字节,展开后加载`]})}function Pa(t,n){const r=t.split(`
|
|
252
|
+
`),s=n.split(`
|
|
253
|
+
`);if(r.length*s.length>2e5)return s.map((w,S)=>({type:"added",text:w,lineNo:S+1}));const i=r.length,a=s.length,l=Array.from({length:i+1},()=>new Array(a+1).fill(0));for(let w=1;w<=i;w++)for(let S=1;S<=a;S++)l[w][S]=r[w-1]===s[S-1]?l[w-1][S-1]+1:Math.max(l[w-1][S],l[w][S-1]);const u=[];let h=i,g=a;for(;h>0&&g>0;)r[h-1]===s[g-1]?(u.unshift([h-1,g-1]),h--,g--):l[h-1][g]>=l[h][g-1]?h--:g--;const x=[];let j=0,b=0;for(const[w,S]of u){for(;j<w;)x.push({type:"removed",text:r[j],lineNo:j+1}),j++;for(;b<S;)x.push({type:"added",text:s[b],lineNo:b+1}),b++;x.push({type:"same",text:r[j],lineNo:j+1}),j++,b++}for(;j<i;)x.push({type:"removed",text:r[j],lineNo:j+1}),j++;for(;b<a;)x.push({type:"added",text:s[b],lineNo:b+1}),b++;return x}function Da({content:t,maxHeight:n=320}){const r=t.split(`
|
|
254
|
+
`);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:n,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:r.map((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 Ba({diff:t,maxHeight:n=360}){if(t.filter(u=>u.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const s=new Set(t.map((u,h)=>u.type!=="same"?h:-1).filter(u=>u>=0)),i=new Set;s.forEach(u=>{for(let h=Math.max(0,u-3);h<=Math.min(t.length-1,u+3);h++)i.add(h)});const a=[];let l=-1;return[...i].sort((u,h)=>u-h).forEach(u=>{l>=0&&u>l+1&&a.push("ellipsis"),a.push({diffLine:t[u],diffIdx:u}),l=u}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:n,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:a.map((u,h)=>{if(u==="ellipsis")return e.jsx("tr",{children:e.jsx("td",{colSpan:3,style:{padding:"2px 12px",color:"var(--text-muted)",fontSize:10,background:"var(--bg-deep)",textAlign:"center"},children:"⋯"})},`e${h}`);const{diffLine:g}=u,x=g.type==="added"?"rgba(5,150,105,0.08)":g.type==="removed"?"rgba(220,38,38,0.07)":"transparent",j=g.type==="added"?"+":g.type==="removed"?"−":" ",b=g.type==="added"?"var(--success)":g.type==="removed"?"var(--danger)":"transparent",w=g.type==="added"?"#059669":g.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:b,fontWeight:700,userSelect:"none"},children:j}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:g.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:w,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:g.text||" "})]},h)})})]})})}function Id({toolCall:t,beforeContent:n,previewPath:r,onLoadResult:s}){const i=Cs(t,s),{expanded:a}=i,[l,u]=d.useState("content"),h=t.arguments.file_path??"",g=t.arguments.content??"",x=La(g),j=t.isError,b=wr(t),w=b?j?"var(--danger)":"var(--success)":"var(--accent)",S=d.useMemo(()=>n&&g?Pa(n,g):null,[n,g]),R=d.useMemo(()=>S?{added:S.filter(v=>v.type==="added").length,removed:S.filter(v=>v.type==="removed").length}:null,[S]),E=j?"var(--danger)":b?"var(--text-muted)":"var(--accent)",F=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Zr,{name:t.name,color:E})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:h,children:Yt(h)}),e.jsx(Gr,{label:`${x} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),R&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[R.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",R.added]}),R.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",R.removed]})]}),(!b||j)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:w},children:[e.jsx(jr,{isDone:b,isError:j,color:w}),j&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Is,{statusColor:w,isDone:b,expanded:a,onToggle:i.toggle,header:F,primaryAction:r?()=>Hn(r):void 0,primaryActionLabel:r?`预览文件 ${Yt(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx(As,{toolCall:t,loading:i.loadingResult,error:i.resultError,retry:i.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:h}),S&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(v=>e.jsx("button",{onClick:()=>u(v),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:l===v?"var(--accent-dim)":"transparent",color:l===v?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:v==="content"?"文件内容":"变更行"},v))}),l==="diff"&&S?e.jsx(Ba,{diff:S}):e.jsx(Da,{content:g}),j&&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 Cd({toolCall:t,previewPath:n,onLoadResult:r}){const s=Cs(t,r),{expanded:i}=s,a=t.arguments.file_path??"",l=t.arguments.startLine,u=t.arguments.endLine,h=t.arguments.offset,g=t.arguments.limit,x=t.result??"",j=La(x),b=t.isError,w=wr(t),S=w?b?"var(--danger)":"var(--success)":"var(--accent)",R=l!==void 0?`L${l}–${u??"?"}`:h!==void 0?`第${h}行起${g?` ×${g}`:""}`:null,E=b?"var(--danger)":w?"var(--text-muted)":"var(--accent)",F=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Zr,{name:t.name,color:E})}),e.jsx("span",{className:"tool-call-shell__label",children:"查阅"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:Yt(a)}),R&&e.jsx(Gr,{label:R,color:"var(--accent)",bg:"var(--accent-dim)"}),w&&!b&&e.jsx(Gr,{label:`${j} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),(!w||b)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:S},children:[e.jsx(jr,{isDone:w,isError:b,color:S}),b&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Is,{statusColor:S,isDone:w,expanded:i,onToggle:s.toggle,header:F,maxBodyHeight:480,primaryAction:n?()=>Hn(n):void 0,primaryActionLabel:n?`预览文件 ${Yt(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(As,{toolCall:t,loading:s.loadingResult,error:s.resultError,retry:s.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),w&&!b?e.jsx(Da,{content:x}):w&&b&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:x})]})}function Ad({toolCall:t,previewPath:n,onLoadResult:r}){const s=Cs(t,r),{expanded:i}=s,a=t.arguments.file_path??"",l=t.arguments.old_string??"",u=t.arguments.new_string??"",h=t.isError,g=wr(t),x=g?h?"var(--danger)":"var(--success)":"var(--accent)",j=h?"var(--danger)":g?"var(--text-muted)":"var(--accent)",b=d.useMemo(()=>l&&u?Pa(l,u):null,[l,u]),w=d.useMemo(()=>b?{added:b.filter(R=>R.type==="added").length,removed:b.filter(R=>R.type==="removed").length}:null,[b]),S=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Zr,{name:t.name,color:j})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:Yt(a)}),w&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[w.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",w.added]}),w.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",w.removed]})]}),(!g||h)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:x},children:[e.jsx(jr,{isDone:g,isError:h,color:x}),h&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Is,{statusColor:x,isDone:g,expanded:i,onToggle:s.toggle,header:S,maxBodyHeight:480,primaryAction:n?()=>Hn(n):void 0,primaryActionLabel:n?`预览文件 ${Yt(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(As,{toolCall:t,loading:s.loadingResult,error:s.resultError,retry:s.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),b?e.jsx(Ba,{diff:b}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:l}),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:u})]}),h&&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 vr({label:t,content:n,error:r,maxPreviewLines:s=8,maxPreviewHeight:i=200,maxExpandedHeight:a=2e3}){const[l,u]=d.useState(!1),h=n.split(`
|
|
255
|
+
`),g=h.length>s,x=g&&!l?h.slice(0,s).join(`
|
|
256
|
+
`)+`
|
|
257
|
+
...`:n;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:r?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:r?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:r?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:r?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:l?a:i,overflow:"auto",margin:0,lineHeight:1.6},children:x}),g&&e.jsx("button",{onClick:()=>u(!l),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:l?"收起":`展开全部 (${h.length} 行)`})]})}function Rd({arguments:t}){var r;const n=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(Gr,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(Gr,{label:`sid: ${(r=t.subSessionId)==null?void 0:r.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),n&&e.jsx(vr,{label:"任务",content:n,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Td({raw:t}){const[n,r]=d.useState(!1);let s;try{const h=JSON.parse(t);delete h.subAgentProgress,delete h.subAgentStatus,delete h.subAgentDetail,s=JSON.stringify(h,null,2)}catch{s=t}const i=8,a=s.split(`
|
|
258
|
+
`),l=a.length>i,u=l&&!n?a.slice(0,i).join(`
|
|
259
|
+
`)+`
|
|
260
|
+
...`: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:n?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:u}),l&&e.jsx("button",{onClick:()=>r(!n),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:n?"收起":`展开全部 (${a.length} 行)`})]})}function Md({activity:t,workspacePath:n,enableFilePreview:r}){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(u=>{const h=s.get(u.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(Rs,{toolCall:{...u,...h?{result:h.content,isError:h.isError}:{}},workspacePath:n,enableFilePreview:r}),h&&e.jsx("pre",{className:`native-subagent-activity__tool-result${h.isError?" native-subagent-activity__tool-result--error":""}`,children:h.content})]},u.id)})),i.role==="tool"&&i.toolCallId&&!t.messages.some(u=>{var h;return(h=u.toolCalls)==null?void 0:h.some(g=>g.id===i.toolCallId)})&&e.jsx(vr,{label:"工具结果",content:i.content,error:i.name==="error",maxPreviewHeight:180})]},`${i.role}-${a}`)}),t.summary&&e.jsx(vr,{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(jr,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function Ed({toolCall:t,onSelectSession:n,nativeSubagent:r,previewPaths:s,workspacePath:i,enableFilePreview:a,onLoadResult:l}){const u=xe(X=>X.runningSessionId),h=Cs(t,l,!!r),{expanded:g,setExpanded:x}=h,j=t.name==="dispatch_agent",b=t.name==="Agent"&&!!r,w=t.arguments.subAgentStatus,S=t.arguments.subAgentDetail,R=t.arguments.subAgentProgress,E=wr(t);d.useEffect(()=>{j&&!w&&R&&x(!0),b&&(r.messages.length>0||r.summary)&&x(!0)},[j,b,r,w,R]);const F=j?w==="failed":b?r.status==="failed":t.isError,v=j?!!w||E&&!u:b?r.status!=="running":E,y=v?F?"var(--danger)":"var(--success)":"var(--accent)",B=F?"var(--danger)":v?"var(--text-muted)":"var(--accent)",$=j?null:_o(t.name),A=F?"错误":$?"":b?r.status==="stopped"?"已停止":v?"已完成":"运行中":j?w==="failed"?"失败":v?"已完成":"运行中":v?"完成":"执行中",C=b?r.description:j?(()=>{const se=(t.arguments.task??"").split(`
|
|
261
|
+
`)[0];return se.length>80?se.slice(0,80)+"…":se})():kd(t.name,t.arguments),W=b?`@${r.agentName??"agent"}`:j?`@${t.arguments.agentName??"agent"}`:za(t.name)??t.name,z=No(t.name),q=!v||!!F||!!A,le=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Zr,{name:t.name,color:B})}),e.jsx("span",{className:"tool-call-shell__label",title:$?t.name:void 0,style:{fontFamily:$?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:W}),C&&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:C}),!C&&e.jsx("span",{style:{flex:1}}),q&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:y},children:[e.jsx(jr,{isDone:v,isError:!!F,color:y}),A&&e.jsx("span",{children:A})]})]});return e.jsxs(Is,{statusColor:y,isDone:v,expanded:g,onToggle:h.toggle,header:le,maxBodyHeight:800,primaryAction:s.length===1?()=>Hn(s[0]):void 0,primaryActionLabel:s.length===1?`预览文件 ${Yt(s[0])}`:void 0,primaryActionTitle:s.length===1?`预览 ${s[0]}`:void 0,children:[e.jsx(As,{toolCall:t,loading:h.loadingResult,error:h.resultError,retry:h.loadResult}),s.length>1&&e.jsx("div",{className:"tool-call-file-list","aria-label":"改动文件",children:s.map(X=>e.jsxs("button",{type:"button",onClick:()=>Hn(X),"aria-label":`预览文件 ${Yt(X)}`,title:`预览 ${X}`,children:[e.jsx(ks,{size:12,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Yt(X)})]},X))}),b?e.jsx(Md,{activity:r,workspacePath:i,enableFilePreview:a}):j?e.jsx(Rd,{arguments:t.arguments}):z==="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(vr,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(Td,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!j&&!b&&e.jsx(vr,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),j&&w&&S&&e.jsx(vr,{label:w==="failed"?"错误信息":"执行摘要",content:S,error:w==="failed",maxPreviewHeight:180}),j&&!w&&R&&(!!u||!E)&&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:[R,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:""})]})]}),j&&!w&&!R&&!!u&&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(X=>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:`${X*.16}s`}},X)),"等待子 agent 响应..."]}),j&&t.arguments.subSessionId&&n&&e.jsxs("button",{onClick:()=>n(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:X=>{X.currentTarget.style.background="var(--accent)",X.currentTarget.style.color="white"},onMouseLeave:X=>{X.currentTarget.style.background="var(--accent-dim)",X.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 $a({items:t,onSelectSession:n,workspacePath:r,enableFilePreview:s,onLoadResult:i}){var S;const[a,l]=d.useState(!1),u=(S=t[0])==null?void 0:S.toolCall,h=u?_o(u.name):null;if(!u||!h||t.length<2)return null;const g=t.every(({toolCall:R})=>wr(R)),x=t.filter(({toolCall:R})=>R.isError).length,j=x>0?"var(--danger)":g?"var(--text-muted)":"var(--accent)",b=za(u.name)??h.done,w=`${b},${t.length} 项,${a?"收起":"展开"}`;return e.jsxs("div",{className:"tool-call-group",children:[e.jsxs("button",{type:"button",className:"tool-call-group__summary","aria-expanded":a,"aria-label":w,onClick:()=>l(R=>!R),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(Zr,{name:u.name,color:j})}),e.jsx("span",{className:"tool-call-group__label",children:b}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),x>0&&e.jsxs("span",{className:"tool-call-group__error",children:[x," 项失败"]}),!g&&e.jsx(jr,{isDone:!1,color:j,size:11}),e.jsx(qn,{className:"tool-call-group__chevron",size:13,strokeWidth:2.2,"aria-hidden":"true"})]}),a&&e.jsx("div",{className:"tool-call-group__items",children:t.map(({toolCall:R,beforeContent:E,progress:F,nativeSubagent:v})=>e.jsx(Rs,{toolCall:R,beforeContent:E,progress:F,nativeSubagent:v,onSelectSession:n,workspacePath:r,enableFilePreview:s,onLoadResult:i},R.id))})]})}function Nd(t,n){if(No(t.name)!=="file")return[];const r=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(r.filter(s=>typeof s=="string").map(s=>Ma(s,n)).filter(s=>!!s))]}function Rs({toolCall:t,onSelectSession:n,beforeContent:r,progress:s,nativeSubagent:i,workspacePath:a,enableFilePreview:l=!1,onLoadResult:u}){const h=l?Nd(t,a):[],g=t.name==="write_file"?e.jsx(Id,{toolCall:t,beforeContent:r,previewPath:h[0],onLoadResult:u}):t.name==="read_file"?e.jsx(Cd,{toolCall:t,previewPath:h[0],onLoadResult:u}):t.name==="str_replace"?e.jsx(Ad,{toolCall:t,previewPath:h[0],onLoadResult:u}):e.jsx(Ed,{toolCall:t,onSelectSession:n,nativeSubagent:i,previewPaths:h,workspacePath:a,enableFilePreview:l,onLoadResult:u});return e.jsxs("div",{className:"tool-call-with-progress",children:[g,s&&e.jsx(Wa,{progress:s,compact:!0})]})}function _d({question:t,options:n,fields:r,multiSelect:s,answered:i,answer:a,onAnswer:l}){const[u,h]=d.useState(new Set),[g,x]=d.useState(""),[j,b]=d.useState({}),w=!!(n!=null&&n.length),S=!!(r!=null&&r.length),R=y=>{i||h(B=>{const $=new Set(B);return s?$.has(y)?$.delete(y):$.add(y):($.clear(),$.add(y)),$})},E=()=>{if(u.size===0)return;const y=Array.from(u).map(B=>n[B].label);l(y.join(", "),Array.from(u))},F=()=>{const y=Array.from(u).map($=>n[$].label),B=Object.fromEntries((r??[]).map($=>{var A;return[$.name,((A=j[$.name])==null?void 0:A.trim())??""]}));!B.model&&y.length>0&&(B.model=y[0]),!(!Object.values(B).some(Boolean)&&y.length===0)&&l(JSON.stringify({fields:B,selectedOptions:y}),Array.from(u))},v=()=>{g.trim()&&l(g.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:"回答:"}),S?"配置已提交(敏感字段已隐藏)":a]}),w&&!i&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[n.map((y,B)=>{const $=u.has(B);return e.jsxs("button",{onClick:()=>R(B),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:$?"var(--accent)":"var(--border-subtle)",background:$?"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 ${$?"var(--accent)":"var(--border-subtle)"}`,background:$?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:$&&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:$?600:500,color:$?"var(--text-primary)":"var(--text-secondary)"},children:y.label}),y.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:y.description})]})]},B)}),!S&&e.jsx("button",{onClick:E,disabled:u.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:u.size>0?"var(--accent)":"var(--bg-surface)",color:u.size>0?"white":"var(--text-muted)",cursor:u.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),S&&!i&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[r.map(y=>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:y.label}),e.jsx("input",{type:y.type==="secret"?"password":"text",value:j[y.name]??"",onChange:B=>b($=>({...$,[y.name]:B.target.value})),placeholder:y.description,autoComplete:y.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"}}),y.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:y.description})]},y.name)),e.jsx("button",{onClick:F,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&&!S&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:w?"1px solid var(--border-subtle)":"none",marginTop:w?2:0},children:[e.jsx("input",{type:"text",value:g,onChange:y=>x(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),v())},placeholder:w?"或输入自定义回答…":"输入你的回答…",style:{flex:1,padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",transition:"border-color 0.15s ease"},onFocus:y=>{y.currentTarget.style.borderColor="var(--accent)"},onBlur:y=>{y.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:v,disabled:!g.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:g.trim()?"var(--accent)":"var(--bg-surface)",color:g.trim()?"white":"var(--text-muted)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})})}const oo={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"}},io={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},Fi=["system","messages","tools","images","overhead"];function zd(t,n){const r=(t==null?void 0:t.maxTokens)??Math.max(1,n*1e3),s=(t==null?void 0:t.totalTokens)??0,i=Object.fromEntries(Fi.map(l=>[l,0]));for(const l of(t==null?void 0:t.segments)??[]){const u=oo[l.category];u&&(i[u.group]+=l.tokens)}const a=Math.min(s/r,1);return{hasUsage:!!t,totalTokens:s,maxTokens:r,ratio:a,percent:Math.round(a*100),groups:Fi.map(l=>({key:l,label:io[l].label,color:io[l].color,tokens:i[l]})),details:((t==null?void 0:t.segments)??[]).filter(l=>l.tokens>0).map(l=>{var u,h;return{category:l.category,label:((u=oo[l.category])==null?void 0:u.label)??l.category,color:io[((h=oo[l.category])==null?void 0:h.group)??"overhead"].color,tokens:l.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function ko(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function Oi(t,n){return n?`${t.percent}%`:t.hasUsage?`${ko(t.totalTokens)} / ${ko(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Wd({usage:t,contextWindowK:n,compact:r=!1}){const[s,i]=d.useState(!1),[a,l]=d.useState(null),u=d.useRef(null),h=d.useMemo(()=>zd(t,n),[t,n]),g=h.ratio>=.85?"var(--danger)":h.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:u,type:"button",onClick:()=>{var b;const j=((b=u.current)==null?void 0:b.getBoundingClientRect())??null;l(j),i(w=>!w)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:r?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:h.hasUsage?g:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${h.ratio*62.832} 62.832`,transform:"rotate(-90 14 14)"})]}),e.jsx("span",{className:"context-usage-ribbon__summary context-usage-ribbon__summary--compact",children:Oi(h,!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:h.groups.map(j=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(j.tokens/h.maxTokens*100,100))}%`,background:j.color,opacity:j.key==="overhead"?.65:1,minWidth:j.tokens>0?1:0}},j.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:h.hasUsage?g:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:Oi(h,!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:r?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(r?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:h.hasUsage?g:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:h.hasUsage?`${h.percent}%`:"暂无"})]}),h.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:h.requestLabel}),h.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:h.details.map(j=>{const b=h.totalTokens>0?Math.round(j.tokens/h.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:j.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:j.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[ko(j.tokens)," · ",b,"%"]})]},j.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 Ld({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(Ao,{size:17,strokeWidth:1.8})}),e.jsxs("span",{children:["思考中",e.jsx(zo,{startedAt:t})]})]})}function Fa({sections:t,streaming:n=!1,startedAt:r,renderContent:s}){const i=d.useMemo(()=>[...t].sort((g,x)=>g.sectionIndex-x.sectionIndex).map(g=>g.text.trim()).filter(Boolean).join(`
|
|
262
|
+
|
|
263
|
+
`),[t]),a=d.useMemo(()=>(i.split(`
|
|
264
|
+
`).find(x=>x.trim())??"").replace(/^#{1,6}\s+/,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1"),[i]),[l,u]=d.useState(n);if(d.useEffect(()=>{u(n)},[n]),!i)return null;const h=n?"思考中":"思考";return e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":l,"aria-label":`${h},${l?"收起":"展开"}`,onClick:()=>u(g=>!g),children:[e.jsx("span",{className:"reasoning-summary__brain","aria-hidden":"true",children:e.jsx(Ao,{size:17,strokeWidth:1.8})}),e.jsxs("span",{className:"reasoning-summary__label",children:[h,n&&r!==void 0&&e.jsx(zo,{startedAt:r})]}),!l&&e.jsx("span",{className:"reasoning-summary__preview",children:a}),e.jsx("span",{className:"reasoning-summary__spacer"}),n&&e.jsx(Rt,{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 Oa(t){var n,r;return t.role==="assistant"&&!!((n=t.toolCalls)!=null&&n.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((r=t.images)!=null&&r.length)&&!t.presentation}function Pd(t){return Oa(t)&&t.content.trim().length===0}function Ua(t){const n=[];for(const r of t){const s=n[n.length-1];if(s&&Oa(s)&&Pd(r)){n[n.length-1]={...s,toolCalls:[...s.toolCalls,...r.toolCalls],timestamp:r.timestamp};continue}n.push(r)}return n}function qa(t){const n=[];for(const r of t){const s=jd(r.toolCall.name),i=n[n.length-1];s&&(i==null?void 0:i.action)===s?i.items.push(r):n.push({action:s,items:[r]})}return n}function Dd({trace:t,loadTrace:n,loadToolResult:r,renderContent:s,runtimeProgress:i,nativeSubagents:a,onSelectSession:l,workspacePath:u,enableFilePreview:h=!1}){const g=t.turnId,x=d.useRef(g),j=d.useRef(t.revision),b=d.useRef(null),[w,S]=d.useState(!1),[R,E]=d.useState(!1),[F,v]=d.useState(null),[y,B]=d.useState(null);d.useEffect(()=>{x.current=g,b.current=null,S(!1),E(!1),v(null),B(null)},[g]),d.useEffect(()=>{j.current=t.revision,b.current=null,E(!1),v(se=>(se==null?void 0:se.map(K=>{var Te;return{...K,toolCalls:(Te=K.toolCalls)==null?void 0:Te.map(Me=>Me.resultRef?{...Me,resultRef:{...Me.resultRef,revision:t.revision}}:Me)}}))??null)},[t.revision]);const $=t.liveMessages??[],A=d.useMemo(()=>Tc(F??[],$),[$,F]),C=F!==null||$.length>0,W=d.useCallback(async()=>{if(F)return F;if($.length>0)return $;if(b.current)return b.current;const se=g,K=t.revision;E(!0),B(null);const Te=n(t);b.current=Te;try{const Me=await Te;return x.current===se&&j.current===K&&v(Me),Me}catch(Me){throw x.current===se&&j.current===K&&B(Me instanceof Error?Me.message:"执行过程加载失败"),Me}finally{x.current===se&&j.current===K&&(b.current=null,E(!1))}},[$,n,F,g,t]),z=()=>{const se=!w;S(se),se&&!C&&W().catch(()=>{})},q=d.useCallback(async se=>{const K=await r(se);x.current===g&&v(Te=>Te&&Sa(Te,se.itemId,K.content,K.isError))},[r,g]),le=C?Cc(A):null,X=le!==null?`执行过程 · ${le} 项`:R?"执行过程加载中":"执行过程";return e.jsxs("div",{className:"codex-execution-trace","data-turn-id":t.turnId,children:[e.jsxs("button",{type:"button",className:"codex-execution-trace__summary","aria-expanded":w,"aria-label":`${X},${w?"收起":"展开"}`,onClick:z,children:[e.jsx("span",{className:"codex-execution-trace__icon","aria-hidden":"true",children:R?e.jsx(Rt,{size:14,strokeWidth:2}):y?e.jsx(ga,{size:14,strokeWidth:2}):e.jsx(gc,{size:14,strokeWidth:1.8})}),e.jsx("span",{className:"codex-execution-trace__label",children:X}),y&&e.jsx("span",{className:"codex-execution-trace__error",children:"加载失败"}),e.jsx("span",{className:"codex-execution-trace__spacer"}),e.jsx(qn,{className:"codex-execution-trace__chevron",size:13,strokeWidth:2.2,"aria-hidden":"true"})]}),w&&e.jsx("div",{className:"codex-execution-trace__body",children:y&&!C?e.jsx("button",{type:"button",className:"ui-text-button codex-execution-trace__retry",onClick:()=>void W().catch(()=>{}),children:"重新加载执行过程"}):C?e.jsx(Bd,{messages:A,renderContent:s,runtimeProgress:i,nativeSubagents:a,onSelectSession:l,workspacePath:u,enableFilePreview:h,onLoadResult:q}):R?e.jsx("div",{className:"codex-execution-trace__loading",role:"status",children:"正在加载这一轮的执行过程"}):null})]})}function Bd({messages:t,renderContent:n,runtimeProgress:r,nativeSubagents:s,onSelectSession:i,workspacePath:a,enableFilePreview:l,onLoadResult:u}){const h=d.useMemo(()=>{const g=new Map;return Ua(t).map(x=>{const j=(x.toolCalls??[]).map(b=>{const w=typeof b.arguments.file_path=="string"?b.arguments.file_path:void 0,S=b.name==="write_file"&&w?g.get(w):void 0;return b.name==="read_file"&&w&&b.result!==void 0&&!b.isError&&g.set(w,b.result),{toolCall:b,beforeContent:S,progress:ka(r,b.id),nativeSubagent:s[b.id]}});return{message:x,toolGroups:qa(j)}})},[t,s,r]);return h.length===0?e.jsx("div",{className:"codex-execution-trace__empty",children:"这一轮没有可显示的执行过程"}):e.jsx("div",{className:"codex-execution-trace__timeline",children:h.map(({message:g,toolGroups:x})=>{var j,b;return e.jsxs("div",{className:"codex-execution-trace__item",children:[(b=(j=g.presentation)==null?void 0:j.reasoning)!=null&&b.length?e.jsx(Fa,{sections:g.presentation.reasoning,renderContent:n}):null,x.map(w=>w.action&&w.items.length>1?e.jsx($a,{items:w.items,onSelectSession:i,workspacePath:a,enableFilePreview:l,onLoadResult:u},`group-${w.items[0].toolCall.id}`):w.items.map(({toolCall:S,beforeContent:R,progress:E,nativeSubagent:F})=>e.jsx(Rs,{toolCall:S,beforeContent:R,progress:E,nativeSubagent:F,onSelectSession:i,workspacePath:a,enableFilePreview:l,onLoadResult:u},S.id)))]},g.id)})})}function $d({appearanceOpen:t,settingsOpen:n,hideToBackgroundTitle:r="隐藏到后台",codexReleaseState:s="idle",onHideToBackground:i,onReleaseCodex:a,onToggleAppearance:l,onOpenSettings:u}){const h=s==="releasing"?"正在释放 Codex 会话":s==="released"?"已释放,可在 Codex 桌面端重试":"交接到 Codex 桌面端";return e.jsxs("div",{className:"chat-header-actions",children:[a&&e.jsx("button",{type:"button",onClick:a,title:h,"aria-label":h,disabled:s!=="idle",className:`ui-icon-button chat-header-action chat-header-action--codex-release is-${s}`,children:s==="releasing"?e.jsx(Rt,{size:15,className:"spin","aria-hidden":"true"}):s==="released"?e.jsx(Qr,{size:15,"aria-hidden":"true"}):e.jsx(uc,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:i,title:r,"aria-label":"隐藏后台",className:"ui-icon-button chat-header-action chat-header-action--background",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"m9 11 3 3 3-3M12 7v7M8 21h8"})]})}),e.jsx("button",{type:"button",onClick:g=>l(g.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:u,title:"设置","aria-label":"设置","aria-expanded":n,className:`ui-icon-button chat-header-action chat-header-action--settings ${n?"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 Fd=[{prompt:"带我熟悉这个项目",Icon:Ol},{prompt:"帮我排查一个问题",Icon:ba},{prompt:"一起实现一个新想法",Icon:nc}],Od={"customer-agent":"Customer Agent",codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function Ud({agentType:t,ready:n,onSelectPrompt:r}){const s=Od[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:n?`${s} · 已准备好`:`${s} · 等待配置`}),e.jsx("h2",{id:"empty-session-welcome-title",children:"嗨,我在。"}),e.jsx("p",{className:"empty-session-welcome__prompt",children:n?"今天想一起做点什么?":"配置好 API Key 后,我就能开始。"})]}),e.jsx("div",{className:"empty-session-welcome__starters","aria-label":"开始一个任务",children:Fd.map(({prompt:i,Icon:a})=>e.jsxs("button",{type:"button","data-prompt":i,disabled:!n,onClick:()=>r(i),children:[e.jsx(a,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:i})]},i))})]})}function qd({image:t,onClose:n}){return d.useEffect(()=>{if(!t)return;const r=document.body.style.overflow,s=i=>{i.key==="Escape"&&n()};return document.body.style.overflow="hidden",window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s),document.body.style.overflow=r}},[t,n]),t?Jt.createPortal(e.jsxs("div",{className:"message-image-lightbox",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:r=>{r.target===r.currentTarget&&n()},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:n,"aria-label":"关闭图片预览",title:"关闭",autoFocus:!0,children:e.jsx(ya,{size:22,"aria-hidden":"true"})})]}),document.body):null}const Hd={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function Vd(t){const{title:n="视频工作台",shots:r=[],status:s="generating",composedVideoUrl:i}=t,[a,l]=d.useState(!1),[u,h]=d.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:["🎬 ",n]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[r.filter(g=>g.status==="done").length,"/",r.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:Hr,children:"#"}),e.jsx("th",{style:{...Hr,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:Hr,children:"时长"}),e.jsx("th",{style:Hr,children:"状态"}),e.jsx("th",{style:Hr,children:"预览"})]})}),e.jsx("tbody",{children:r.map(g=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:Vr,children:g.index}),e.jsx("td",{style:{...Vr,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g.description,children:g.description}),e.jsxs("td",{style:Vr,children:[g.duration,"s"]}),e.jsxs("td",{style:Vr,children:[Hd[g.status]??"⏳",g.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:g.error,children:"!"})]}),e.jsx("td",{style:Vr,children:g.videoUrl?e.jsx("button",{onClick:()=>h(g.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:"▶ 播放"}):g.previewImageUrl?e.jsx("img",{src:g.previewImageUrl,alt:`shot-${g.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:"—"})})]},g.index))})]}),u&&e.jsx("video",{src:u,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 Hr={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)"},Qd={storyboard_workbench:Vd};function Kd(t,n,r){return!t||n!==t?!1:r===null||r===t}function Gd(t,n,r=Date.now()){return!t||t.sessionId!==n?t:{...t,until:r+9e4}}async function Zd(t){const{text:n,projectId:r,createSession:s,activateSession:i,showUserMessage:a,onSessionCreated:l,isCancelled:u}=t,h=!t.sessionId;let g=t.sessionId??null;if(!g){const x=await s(n.slice(0,60)||"语音任务",r||void 0);if(u!=null&&u())return null;g=x.id}return i(g),a(n,g),h&&l&&await l(g),g}async function Ui(t){var i,a;const n=((i=t.sessionId)==null?void 0:i.trim())||null,r=!n,s=n??(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),r&&await((a=t.onSessionCreated)==null?void 0:a.call(t,s)),s}const Jd=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|[ \t]*\/[^)\n]+)\)/gi,Yd=/`([^`\n]+)`/g,Xd=/:codex-file-citation\{([^}\n]*)\}/g,qi=/([A-Za-z][\w-]*)="([^"\n]*)"/g,eu=/\uE200visualize\uE202([^\uE201\n]+)\uE201/g;function Wo(t){if(!t.startsWith("/")||t.includes("?")||t.includes("#")||t.includes("\0"))return null;const n=t.match(/^(\/.*):([1-9]\d*)$/);return n?{path:n[1],line:Number(n[2])}:{path:t}}function tu(t){const n={};for(const i of t.matchAll(qi)){const a=i[1];if(a!=="path"&&a!=="purpose"||n[a]!==void 0)return null;n[a]=i[2]}if(t.replace(qi,"").trim())return null;const r=Wo(n.path??"");if(!r||r.line!==void 0)return null;const s=r.path.slice(r.path.lastIndexOf("/")+1)||r.path;return{path:r.path,label:s}}function nu(t){try{const n=JSON.parse(t);if(!n||typeof n!="object"||Array.isArray(n))return null;const{path:r,title:s,mode:i}=n;if(typeof r!="string"||s!==void 0&&typeof s!="string"||i!==void 0&&typeof i!="string")return null;const a=Wo(r);if(!a||a.line!==void 0)return null;const l=(s==null?void 0:s.trim())||a.path.slice(a.path.lastIndexOf("/")+1)||a.path;return{path:a.path,label:l}}catch{return null}}function ru(t,n){const r=[];let s=0;const i=[...[...t.matchAll(Jd)].map(a=>({kind:"markdown",match:a})),...[...t.matchAll(Xd)].map(a=>({kind:"citation",match:a})),...[...t.matchAll(eu)].map(a=>({kind:"visualize",match:a})),...[...t.matchAll(Yd)].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,u=l.index??0;if(u<s)continue;if(u>s&&r.push({type:"text",value:t.slice(s,u)}),a.kind==="code"){r.push({type:"code",value:l[1]}),s=u+l[0].length;continue}if(a.kind==="citation"){const g=tu(l[1]);r.push(g?{type:"artifact",label:g.label,path:g.path,raw:l[0]}:{type:"text",value:l[0]}),s=u+l[0].length;continue}if(a.kind==="visualize"){const g=nu(l[1]);r.push(g?{type:"artifact",label:g.label,path:g.path,raw:l[0]}:{type:"text",value:l[0]}),s=u+l[0].length;continue}const h=l[2];if(/^https?:\/\//i.test(h))r.push({type:"link",label:l[1],href:h});else{const g=Wo(h.replace(/^[ \t]+/,""));g?r.push({type:"artifact",label:l[1],path:g.path,...g.line?{line:g.line}:{},raw:l[0]}):r.push({type:"text",value:l[0]})}s=u+l[0].length}return s<t.length&&r.push({type:"text",value:t.slice(s)}),r.length>0?r:[{type:"text",value:t}]}function su(t){return ru(t)}function Ha(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0}function ou(t){const n=Ha(t);return n===void 0?void 0:`${Math.round(n/1e3)} 秒`}function iu(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function au(t){var n,r,s;return t.role==="assistant"&&!!(t.content.trim()||(n=t.toolCalls)!=null&&n.length||(s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length||t.askUser||t.widget)}function lu(t,n,r){var a;const s=t[n];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(a=s.toolCalls)!=null&&a.length||s.isCompactionSummary)return!1;let i=!r;for(let l=n+1;l<t.length;l++){const u=t[l];if(!u.isCompactionSummary){if(iu(u)){i=!0;break}if(au(u))return!1}}return i}function cu(t,n,r){const s=t[n];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=lu(t,n,r);return{showCopy:i,showSpeak:i,showCompletion:i,compact:s.role==="assistant"&&!i&&!s.isCompactionSummary}}const du=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function uu(t,n){const r=[],s=[],i=[];for(const l of t){const u=l.type.trim().toLowerCase();u.startsWith("image/")?du.has(u)?r.push(l):i.push(l):s.push(l)}const a=await Promise.all(r.map(async l=>{try{return{file:l,dataUrl:await n(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 gs(t,n){return n?t[n]:void 0}function pu(t,n){const r=Object.fromEntries(Object.entries(t).filter(([,s])=>s.token!==n.token&&s.sourceSessionId!==n.sourceSessionId));return r[n.sourceSessionId]=n,n.forkSessionId&&(r[n.forkSessionId]=n),r}function fu(t,n){const r=t[n];return r?Object.fromEntries(Object.entries(t).filter(([,s])=>s.token!==r.token)):t}function gu(t,n,r=crypto.randomUUID()){return{token:r,sourceSessionId:t,payload:{...n,images:n.images?[...n.images]:void 0,agentIds:n.agentIds?[...n.agentIds]:void 0},sendAttempted:!1}}function Hi(t,n){return t.forkSessionId===n&&t.sendAttempted?t:{...t,forkSessionId:n,sendAttempted:!0}}function hu(t,n){return!!(t&&n&&(t.sourceSessionId===n||t.forkSessionId===n))}async function xu(t){const n=await t.forkSession(t.sourceSessionId);return t.activateSession(n.id),await t.refreshAndSelect(n),n}const bn=50;function Vi(t){return t.trim().replace(/^\/goal\s+/i,"").replace(/^\$([\w-]+)/,"/$1").trim()}function ao(t){const r=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(r){const a=parseFloat(r[1]),l=r[2].toLowerCase(),u=l==="s"||l==="sec"||l==="秒"?a*1e3:l==="m"||l==="min"||l==="分"||l==="分钟"?a*6e4:a*36e5;return u>=36e5&&u%36e5===0?`每 ${u/36e5} 小时`:u>=6e4&&u%6e4===0?`每 ${u/6e4} 分钟`:`每 ${u/1e3} 秒`}const[s,i]=t.trim().split(/\s+/);return s==="0"&&i&&i!=="*"&&!i.includes("/")&&!i.includes(",")?`每天 ${i.padStart(2,"0")}:00`:`cron: ${t}`}function mu(t){const n=t.split(/(`[^`\n]+`)/g);return n.length<=1?t:e.jsx(e.Fragment,{children:n.map((r,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:r.slice(1,-1)},s):e.jsx("span",{children:r},s))})}function Va(t,n){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,i)=>{const a=`${n}-${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 Qi(t,n){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)},`${n}-${i}`):Va(s,`${n}-${i}`))}function So(t){return su(t).map((n,r)=>{if(n.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:n.value},r);if(n.type==="link")return e.jsx("a",{className:"chat-message-link",href:n.href,target:"_blank",rel:"noopener noreferrer",children:Qi(n.label,`${r}-label`)},r);if(n.type==="artifact"){if(!$n())return e.jsx("span",{children:n.raw},r);const s=n.line?`${n.path}:${n.line}`:n.path,i=n.label.replace(/^`([^`\n]+)`$/,"$1");return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:s,"aria-label":`打开交付物 ${i}`,onClick:()=>Hn(n.path),children:[e.jsx(ks,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Qi(n.label,`${r}-label`)})]},r)}return Va(n.value,`${r}`)})}function bu(t){if(t.length<2)return null;const n=a=>a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim()),r=n(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const i=t.slice(2).map(n);return{headers:r,rows:i}}function yu(t,n){const r=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:r(!0),children:So(s)},i))})}),e.jsx("tbody",{children:n.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:r(!1),children:So(a)},l))},i))})]})})}function vu(t,n){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:n})]})}function hs(t){const n=t.split(`
|
|
265
|
+
`),r=[];let s=0,i=0;const a=u=>u.trimStart().startsWith("```"),l=u=>n[u].trimStart().startsWith("|")&&u+1<n.length&&/^\|[\s\-:|]+\|$/.test(n[u+1].trim());for(;s<n.length;){if(a(n[s])){const u=n[s].trim().slice(3).trim();s++;const h=[];for(;s<n.length&&!a(n[s]);)h.push(n[s]),s++;s++,r.push(e.jsx("div",{children:vu(u,h.join(`
|
|
266
|
+
`))},`code-${i++}`));continue}if(l(s)){const u=[];for(;s<n.length&&n[s].trimStart().startsWith("|");)u.push(n[s].trim()),s++;const h=bu(u);h?r.push(e.jsx("div",{children:yu(h.headers,h.rows)},`tbl-${i++}`)):r.push(e.jsx("span",{children:u.map((g,x)=>e.jsxs("span",{children:[mu(g),x<u.length-1?`
|
|
267
|
+
`:null]},x))},`tbl-fb-${i++}`))}else{const u=[];for(;s<n.length&&!l(s)&&!a(n[s]);)u.push(n[s]),s++;u.length>0&&r.push(e.jsx("span",{children:u.map((h,g)=>e.jsxs("span",{children:[So(h),g<u.length-1?`
|
|
268
|
+
`:null]},g))},`txt-${i++}`))}}return e.jsx(e.Fragment,{children:r})}const Qa=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Ki=Object.fromEntries(Qa.map(t=>[t.value,t.label])),lo={low:"低",medium:"中",high:"高",xhigh:"超高",max:"最大"},Gi={codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function wu(t,n){return n==="codex"?t==="openai":n==="claude-code"?t==="anthropic":!1}const ys=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function Zi(t){return ys.some(n=>n.value===t)?t:"full-access"}function ju({activeAgentType:t="customer-agent",selectedProjectId:n=null,selectedSessionId:r=null,onSessionCreated:s,onMessageSent:i,onSubSessionCreated:a,onSelectSession:l,onSubAgentEvent:u,onRunComplete:h,sessionTitle:g,sessionSummary:x,workspacePath:j=null,onOpenSettings:b,settingsOpen:w=!1,onHideToBackground:S,onToggleAppearance:R,appearanceOpen:E=!1,hideToBackgroundTitle:F,voiceCommand:v=null}){var ii,ai,li,ci,di,ui,pi,fi,gi,hi,xi;const{messages:y,runningSessionId:B,appendText:$,addMessage:A,setRunningSession:C,setSessionId:W,updateToolResult:z,updateSubAgentStatus:q,updateSubAgentProgress:le,updateMessage:X,setMessages:se,getMessagesForSession:K,contextUsageBySession:Te,runtimeProgressBySession:Me,nativeSubagentsBySession:Vn,setContextUsage:Le,applyRuntimeProgress:Qn,setRuntimeProgress:Wt,clearRuntimeProgress:Lt,applyNativeSubagentActivity:kr,setNativeSubagentActivities:pt,applyReasoningSummary:T,applyCodexExecutionEvent:Q,clearMessages:me,sessionId:ce,todos:ke,setTodos:Ee,cronTasks:Ge,setCronTasks:be}=xe(),[we,Pt]=d.useState({active:null,queued:[],history:[]}),Ze=d.useMemo(()=>Ua(fd(y.filter(o=>!o.isQueued),we.queued)),[we.queued,y]),{isConfigured:Tt,profiles:tt,activeProfileId:ft,switchActiveProfile:Xt,loadFromSystem:Se,contextWindow:Sr,reasoningEffort:Pe,setField:en,saveToSystem:Dt}=Ss(),U=r||ce,[Ts,Ir]=d.useState({}),lt=d.useRef({}),gt=d.useCallback((o,c)=>{const p=o?pu(lt.current,o):c?fu(lt.current,c):lt.current;lt.current=p,Ir(p)},[]),De=gs(Ts,U),[tn,Bt]=d.useState(!1),[nn,ht]=d.useState("idle"),[Ms,Kn]=d.useState(null),[rn,Mt]=d.useState(null),fe=hd(x,t),pe=(x==null?void 0:x.agentType)??t,[Jr,Gn]=d.useState([]),Cr=d.useRef(null),[$t,Yr]=d.useState(()=>vi(pe)),[kn,ct]=d.useState(!1),Ar=d.useRef(null);d.useEffect(()=>{Yr(vi(pe)),ct(!1)},[pe]),d.useEffect(()=>{var o;!fe||!((o=window.agentApi)!=null&&o.listAgentModels)||Cr.current!==pe&&(Cr.current=pe,Gn([]),window.agentApi.listAgentModels(pe).then(c=>Gn(c.models??[])).catch(()=>{Gn([]),Cr.current=null}))},[fe,pe]),d.useEffect(()=>{if(!kn)return;const o=c=>{Ar.current&&!Ar.current.contains(c.target)&&ct(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[kn]);const Zn=d.useCallback(o=>{Yr(c=>{const p={...c,...o};return wc(pe,p),p})},[pe]),sn=d.useMemo(()=>fe?Jr.map(o=>({key:Xs(o),label:o.displayName||o.id,model:{id:o.id,...o.providerID?{providerID:o.providerID}:{}},reasoningEfforts:o.reasoningEfforts})):[],[fe,Jr]),on=d.useMemo(()=>fe?(tt??[]).filter(o=>{var c;return(c=o.modelId)==null?void 0:c.trim()}).filter(o=>pe==="opencode"||wu(o.provider,pe)).map(o=>({key:pe==="opencode"?Xs({id:o.modelId,providerID:o.provider}):o.modelId,label:o.name||o.modelId,model:{id:o.modelId,...pe==="opencode"?{providerID:o.provider}:{}}})):[],[fe,tt,pe]),Rr=(ii=$t.model)!=null&&ii.id?Xs($t.model):"",Tr=d.useMemo(()=>{var c;const o=sn.find(p=>p.key===Rr);if((c=o==null?void 0:o.reasoningEfforts)!=null&&c.length)return o.reasoningEfforts;if(pe==="claude-code")return["low","medium","high","xhigh"]},[sn,Rr,pe]),an=d.useMemo(()=>fe?pe==="codex"?Tr??[]:pe==="claude-code"?Tr??["low","medium","high","xhigh"]:[]:[],[fe,pe,Tr]),nt=$t.reasoningEffort&&an.includes($t.reasoningEffort)?$t.reasoningEffort:void 0,wt=sn.length>0||on.length>0,Jn=(x==null?void 0:x.messageQueueVersion)===1,Ft=id(x==null?void 0:x.agentType),Et=Ms===U?"direct":rn?"incompatible":(ai=x==null?void 0:x.compatibility)==null?void 0:ai.status,Sn=Et!==void 0&&Et!=="direct",In=Sn||(x==null?void 0:x.occupancy)==="owned-externally"&&x.agentType!=="codex",Yn=hu(De,U),Xr=Tt||fe,Cn=Xr&&!In&&!Yn&&nn!=="released",An=d.useRef(new Set),[Xn,xt]=d.useState("idle"),jt=d.useRef("idle"),er=d.useRef(null),[tr,Ot]=d.useState(()=>Date.now()),ln=!!(U&&(B===U||An.current.has(U))),rt=bd(x,ln),Ut=ln||xd(x),kt=U?Me[U]??[]:[],St=U?Vn[U]??{}:{},qt=kc(kt),Ht=Ze[Ze.length-1],Es=!!((Ht==null?void 0:Ht.role)==="assistant"&&Xn==="thinking"&&((ci=(li=Ht.presentation)==null?void 0:li.reasoning)!=null&&ci.some(o=>o.text.trim()))),Ns=Xn==="tools"&&Ze.some(o=>{var c;return((c=o.toolCalls)==null?void 0:c.length)&&!ro(o.toolCalls)}),_s=Ut&&!qt&&!Es&&!Ns;d.useEffect(()=>{Se()},[]),d.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(o=>be(o))},[]);const[qe,st]=d.useState(""),[ot,It]=d.useState(null),[Oe,Rn]=d.useState(""),[es,nr]=d.useState(null),[dt,Ct]=d.useState(null),Tn=d.useRef(null),[ts,rr]=d.useState(!1),[cn,sr]=d.useState(!1),[Mn,Vt]=d.useState(!1),[At,En]=d.useState("full-access"),[Nt,Ie]=d.useState(!1),[dn,He]=d.useState(null),[it,ns]=d.useState(!1),or=d.useRef(null),ir=d.useRef(null),Be=d.useCallback((o,c)=>{const p=Re.current||at.current;if(c===p&&Pt(Bi(o)),!c.startsWith("runtime:"))return;const m=K(c);se(no(m,o),c)},[K,se]);d.useEffect(()=>{if(!cn)return;const o=c=>{or.current&&!or.current.contains(c.target)&&sr(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[cn]),d.useEffect(()=>{if(!Mn)return;const o=c=>{ir.current&&!ir.current.contains(c.target)&&Vt(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[Mn]),d.useEffect(()=>{Vt(!1),En(Zi(x==null?void 0:x.permissionMode))},[fe,r,x==null?void 0:x.permissionMode]);const[Nn,te]=d.useState(null),[Je,Mr]=d.useState(null),[Er,zs]=d.useState(0),[rs,ar]=d.useState([]),[lr,Qt]=d.useState([]),[cr,dr]=d.useState(0),[Ws,un]=d.useState(null),mt=d.useRef(null),Nr=d.useRef(null),Kt=d.useRef(null),f=d.useRef(()=>{}),I=d.useRef(()=>{}),_=d.useRef(null),L=d.useRef(null),P=d.useRef(null);P.current||(P.current=new qc);const ne=d.useRef(null),J=d.useRef("latest"),ie=d.useRef(null),ze=d.useRef(!1),Ce=d.useRef(null),Ue=d.useRef(0),ae=d.useRef(0),re=d.useRef(null),Ye=d.useRef(!1),bt=d.useRef(!1),Xe=d.useRef(null),yt=d.useRef(!1),et=d.useRef(!1),Ae=d.useRef(null),We=d.useRef(new Map),de=d.useRef(new Set),$e=d.useRef(null),_r=d.useRef(!1),ss=d.useRef(!1),Ls=d.useRef(null),pn=d.useRef(null),[Po,Do]=d.useState(!1),[os,is]=d.useState(null),[Ps,Ds]=d.useState(null),[Bs,Xa]=d.useState("latest"),[el,ur]=d.useState(null),[tl,pr]=d.useState(null),[nl,fr]=d.useState(!1),[rl,Bo]=d.useState(!1),[$s,as]=d.useState(!1),[ls,cs]=d.useState(!1),[sl,zr]=d.useState(!1),$o=d.useRef(null),Wr=d.useRef(null),Fs=d.useRef(null),[fn,Fo]=d.useState(null),[ol,Oo]=d.useState([]),[il,Uo]=d.useState([]),[Lr,Os]=d.useState([]),[Pr,_n]=d.useState(null),[zn,Wn]=d.useState(null),Fe=d.useCallback(o=>Re.current===o?x==null?void 0:x.agentType:o.startsWith("runtime:codex:")?"codex":void 0,[x==null?void 0:x.agentType]),Ve=d.useCallback((o,c)=>{if(!c)return;const p=`${o}:${c}`;Ae.current!==p&&(Ae.current=p,We.current.clear())},[]),Us=d.useCallback(async o=>{const c=window.agentApi,p=Re.current;if(!c||!p)throw new Error("当前会话不可用");Ve(p,o.revision);const m=`${o.turnId}:${o.itemId}`;let M=We.current.get(m);M||(M=c.getSessionToolResult(p,o),We.current.set(m,M),M.catch(()=>{We.current.get(m)===M&&We.current.delete(m)}));const k=await M;return Re.current!==p||Ae.current!==`${p}:${o.revision}`,k},[Ve]),qo=d.useCallback(async o=>{const c=Re.current;if(!c)throw new Error("当前会话不可用");const p=await Us(o);Re.current===c&&z(o.itemId,p.content,p.isError,c)},[Us,z]),al=d.useCallback(async o=>{var M;const c=window.agentApi,p=Re.current;if(!c||!p)throw new Error("当前会话不可用");const m=await c.getSession(p,{view:"trace",revision:o.revision,turnId:o.turnId});if(Re.current!==p)throw new DOMException("Session selection changed","AbortError");if(((M=m==null?void 0:m.history)==null?void 0:M.revision)!==o.revision)throw new Error("会话内容已更新,请重新展开执行过程");return Ve(p,o.revision),Pc(m)},[Ve]);d.useEffect(()=>{Ae.current=null,We.current.clear()},[r]);const _t=d.useCallback((o,c)=>{const p=window.agentApi;!c||!p||P.current.prefetch(o,c,()=>p.getSession(o,{before:c,limit:bn,...Fe(o)==="codex"?{view:"core"}:{}})).catch(m=>{console.warn("[chat] failed to prefetch older history",{sessionId:o,error:m})})},[Fe]),Ln=d.useCallback(o=>{J.current=o,Xa(o)},[]);d.useEffect(()=>{if(!fe||!U){$e.current=null;return}if($e.current!==U){$e.current=U;const o=gs(lt.current,U);st((o==null?void 0:o.payload.content)??cd(U)),Qt((o==null?void 0:o.payload.images)??[]);return}if(_r.current&&qe===""){_r.current=!1;return}to(U,qe)},[qe,fe,U]);const ll=()=>{const o=mt.current;o&&(o.scrollTop<=240&&f.current(),J.current==="anchored"&&o.scrollHeight-o.scrollTop-o.clientHeight<=240&&I.current(),o.classList.add("is-scrolling"),Kt.current!==null&&window.clearTimeout(Kt.current),Kt.current=window.setTimeout(()=>{o.classList.remove("is-scrolling"),Kt.current=null},700))};d.useEffect(()=>()=>{Kt.current!==null&&window.clearTimeout(Kt.current)},[]),d.useLayoutEffect(()=>{const o=Ls.current,c=mt.current;!o||!c||(c.scrollTop=o.scrollTop+(c.scrollHeight-o.scrollHeight),Ls.current=null)},[y]),d.useLayoutEffect(()=>{const o=re.current,c=mt.current;if(!o||!c)return;const p=Array.from(c.querySelectorAll("[data-message-id]")).find(m=>m.dataset.messageId===o);p&&(co(c,p),re.current=null,ur(o))},[y]),d.useLayoutEffect(()=>{const o=mt.current;!Ye.current||!o||Bs!=="latest"||(Ye.current=!1,o.scrollTop=o.scrollHeight)},[Bs,y]);const[Ho,qs]=d.useState(!1),[Dr,Br]=d.useState(null),ds=d.useRef(null);d.useEffect(()=>{const o=window.agentApi;if(!(o!=null&&o.onTtsStart)||!o.onTtsPcm||!o.onTtsStreamEnd||!o.onTtsFlush)return;const c=new Wc(o),p=[o.onTtsStart(m=>c.start(m)),o.onTtsPcm(({generation:m,pcm:M})=>c.enqueue(m,M)),o.onTtsStreamEnd(({generation:m})=>c.finish(m)),o.onTtsFlush(({generation:m})=>c.flush(m)),o.onTtsEnd(()=>Br(null))];return()=>{for(const m of p)m();c.dispose()}},[]);const cl=()=>{var p;if(Ho){(p=ds.current)==null||p.stop(),ds.current=null,qs(!1);return}ps(window.agentApi,qr);const o=qe?`${qe.trimEnd()} `:"",c=Ec({onInterim:m=>st(o+m),onFinal:m=>{var M;st(o+m),(M=Wr.current)==null||M.focus()},onError:m=>te(m),onEnd:()=>{qs(!1),ds.current=null}});c&&(ds.current=c,qs(!0))},dl=async(o,c)=>{var p;if(Dr===o){await ps(window.agentApi,qr),Br(null);return}if(await ps(window.agentApi,qr),!((p=window.agentApi)!=null&&p.ttsSpeak)){te("TTS 模型服务不可用");return}Br(o);try{(await window.agentApi.ttsSpeak(c)).ok||(Br(null),te("TTS 模型播报失败"))}catch(m){Br(null),te(m instanceof Error?m.message:"TTS 模型播报失败")}},_e=d.useRef(null),Pn=d.useRef(!1),gr=d.useRef(new Set),$r=d.useRef(new Map),Vo=d.useRef(new Set),Fr=d.useRef(new Map),gn=d.useRef(null),Re=d.useRef(r??null),at=d.useRef(null),hr=d.useRef(0);d.useEffect(()=>{Re.current=r??null},[r]),d.useEffect(()=>{at.current=ce},[ce]),d.useEffect(()=>()=>{for(const o of $r.current.values())window.clearTimeout(o);$r.current.clear()},[]);const us=d.useCallback(async o=>{var p;const c=o||Re.current||at.current;if(!c||!((p=window.agentApi)!=null&&p.getSessionGoals)){Pt({active:null,queued:[],history:[]});return}try{const m=await window.agentApi.getSessionGoals(c);Be(m,c),m.active&&(_e.current=c,C(c))}catch(m){te(m instanceof Error?m.message:"目标状态加载失败")}},[Be,C]);d.useEffect(()=>{us(U)},[U,us]);const Qe=d.useCallback(o=>{const c=Re.current||at.current;o==="thinking"&&(jt.current!=="thinking"||er.current!==c)?(er.current=c,Ot(Date.now())):o!=="thinking"&&(er.current=null),jt.current=o,xt(o)},[]),ul=d.useCallback(o=>{er.current=o,jt.current="thinking",Ot(Date.now()),xt("thinking")},[]);d.useEffect(()=>{Bt(!1),ht("idle"),un(null)},[r]),d.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(o=>Oo(o)),window.agentApi.listSkills().then(o=>Uo(o.filter(c=>c.name))).catch(o=>console.error("[listSkills] mount error:",o)))},[]);const Qo=Pr===null?[]:ol.filter(o=>Pr===""||o.name.toLowerCase().includes(Pr.toLowerCase())),Hs=zn===null?[]:[...[{name:"goal",description:"目标模式:持续推进当前目标,后续目标自动排队"},{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(o=>zn===""||o.name.toLowerCase().includes(zn.toLowerCase())),...il.filter(o=>zn===""||o.name.toLowerCase().includes(zn.toLowerCase()))],pl=o=>{Os(c=>c.find(p=>p.id===o.id)?c:[...c,o]),st(c=>c.replace(/@[\w\u4e00-\u9fff]*$/,"")),_n(null),setTimeout(()=>{var c;return(c=Wr.current)==null?void 0:c.focus()},0)},fl=o=>{Os(c=>c.filter(p=>p.id!==o))},gl=o=>{st(c=>c.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${o.name} `)),Wn(null),setTimeout(()=>{var c;return(c=Wr.current)==null?void 0:c.focus()},0)},Ko=o=>{var m,M;st(o);const c=o.match(/@([\w\u4e00-\u9fff]*)$/);if(c){window.agentApi&&window.agentApi.listAgentDefs().then(k=>Oo(k)),Fo(((m=Fs.current)==null?void 0:m.getBoundingClientRect())??null),_n(c[1]),Wn(null);return}const p=o.match(/\/([-\w\u4e00-\u9fff]*)$/);if(p){window.agentApi&&window.agentApi.listSkills().then(k=>Uo(k.filter(H=>H.name))).catch(k=>console.error("[listSkills] slash error:",k)),Fo(((M=Fs.current)==null?void 0:M.getBoundingClientRect())??null),Wn(p[1]),_n(null);return}_n(null),Wn(null)},hl=o=>{Ko(o),_n(null),Wn(null),requestAnimationFrame(()=>{var c;return(c=Wr.current)==null?void 0:c.focus()})},xl=o=>{o.key==="Escape"&&(Pr!==null||zn!==null)?(o.preventDefault(),_n(null),Wn(null)):o.key==="Escape"&&ln?(o.preventDefault(),ti()):o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),oi())},ml=async o=>{const c=Array.from(o.target.files??[]);if(o.target.value="",c.length===0)return;const p=c.filter(m=>m.type.toLowerCase().startsWith("image/")).length;p>0&&dr(m=>m+1);try{const m=await uu(c,async k=>Go(await Li(k)));m.attachments.length>0&&ar(k=>[...k,...m.attachments]),m.images.length>0&&(Qt(k=>[...k,...m.images]),fe||vl());const M=[...m.unsupportedImages,...m.failedImages];M.length>0&&te(`无法添加图片:${M.map(k=>k.name).join("、")}。仅支持 JPG、PNG、GIF 和 WebP。`)}finally{p>0&&dr(m=>Math.max(0,m-1))}},bl=o=>{ar(c=>c.filter((p,m)=>m!==o))},yl=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Vs=o=>yl.test(o),vl=()=>{const o=tt.find(p=>p.id===ft);if(o&&Vs(o.modelId))return;const c=tt.find(p=>Vs(p.modelId));c&&Xt(c.id)},wl=o=>{Qt(c=>[...c,o])},jl=o=>{Qt(c=>c.filter((p,m)=>m!==o))},Go=o=>new Promise((c,p)=>{const m=new FileReader;m.onload=()=>c(m.result),m.onerror=p,m.readAsDataURL(o)});d.useEffect(()=>{const o=async c=>{if(!c.clipboardData)return;const p=Array.from(c.clipboardData.items).find(M=>M.type.startsWith("image/"));if(!p)return;c.preventDefault();const m=p.getAsFile();if(m){dr(M=>M+1);try{wl(await Go(await Li(m)))}catch{te("无法添加图片。仅支持 JPG、PNG、GIF 和 WebP。")}finally{dr(M=>Math.max(0,M-1))}}};return window.addEventListener("paste",o),()=>window.removeEventListener("paste",o)},[tt,ft]),d.useEffect(()=>{var c;const o=pn.current;pn.current=null,o!=="skip"&&((c=Nr.current)==null||c.scrollIntoView({behavior:o==="instant"?"auto":"smooth"}))},[y]),d.useEffect(()=>window.agentApi?window.agentApi.onEvent(c=>kl(c)):void 0,[ce]),d.useEffect(()=>{const o=++hr.current,c=r;let p=null;const m=()=>hr.current===o&&Re.current===c;return(async()=>{var N,V,O;const k=window.agentApi;if(!k||Kd(_e.current,at.current,c))return;if(!c){if(!m())return;(N=P.current)==null||N.invalidate(),me(),te(null),Mr(null),Kn(null),Mt(null),_.current=null,L.current=null,ie.current=null,Ue.current+=1,Ce.current=null,Ds(null),Ln("latest"),ur(null),pr(null),bt.current=!1,as(!1),fr(!1),is(null),cs(!1),zr(!1),ne.current=null,at.current=null,W(""),En("full-access");return}te(null),Mr(null),Kn(null),Mt(null),is(null),(V=P.current)==null||V.invalidate(),ae.current+=1,_.current=null,L.current=null,ie.current=null,Ln("latest"),fr(!1),ur(null),pr(null),bt.current=!1,as(!1),((O=Ce.current)==null?void 0:O.sessionId)!==c&&(Ue.current+=1,Ce.current=null,Ds(null)),cs(!0),zr(!1),ne.current=c,at.current=c,W(c);const H=K(c);se(H,c),p=window.setTimeout(()=>{m()&&zr(!0)},500);try{await ed(async()=>{if(!m())throw new DOMException("Session selection changed","AbortError");return await mr(k,c,Fe(c),{limit:bn},(D,G)=>{var Y,Ke,zt,ve;if(!m())return;const Z=D,ee=ji((D==null?void 0:D.events)??[]),he=wi((D==null?void 0:D.events)??[]),je=ki((D==null?void 0:D.events)??[]),ue=br(D);Ve(c,(Y=D==null?void 0:D.history)==null?void 0:Y.revision),x!=null&&x.compatibility&&Kn(c),En(Zi((Z==null?void 0:Z.permissionMode)??((Ke=Z==null?void 0:Z.metadata)==null?void 0:Ke.permissionMode)));const ye=((zt=D==null?void 0:D.history)==null?void 0:zt.nextCursor)??null;_.current=ye,L.current=ye,ie.current=null;const ge=K(c),Ne=Ei(ge,ue,G,D==null?void 0:D.history),xn=D!=null&&D.goalState&&c.startsWith("runtime:")?no(Ne,D.goalState):Ne;pn.current="instant",se(xn,c),_t(c,ye),Wt(he,c),pt(je,c),Ea(D)||md(D)?(_e.current=c,C(c)):_e.current===c&&(_e.current=null,C(null)),ee&&Le(ee,c);const mn=xn[xn.length-1];(mn==null?void 0:mn.role)==="assistant"&&((ve=mn.toolCalls)!=null&&ve.length)?Qe(ro(mn.toolCalls)?"thinking":"tools"):Qe((D==null?void 0:D.agentType)!=="customer-agent"&&(D==null?void 0:D.status)==="running"?"thinking":"idle"),p!==null&&window.clearTimeout(p),cs(!1),zr(!1)},m),!0})}catch(D){if(!m())return;console.error("[chat] failed to restore session",{sessionId:c,error:D});const G=Xc(D);Mr(G),x!=null&&x.compatibility&&Mt(G)}finally{p!==null&&window.clearTimeout(p),m()&&(cs(!1),zr(!1))}})(),()=>{p!==null&&window.clearTimeout(p),hr.current===o&&(hr.current+=1)}},[me,K,Fe,_t,r,Er,Le,Ln,se,W,Ve,Qe]);const hn=d.useCallback(async o=>{const c=window.agentApi;if(!(c!=null&&c.getSessionQueryIndex))return null;const p=++Ue.current;try{const m=await c.getSessionQueryIndex(o);return Ue.current!==p||Re.current!==o||m.sessionId!==o?null:(Ce.current=m,Ds(m),m)}catch(m){return Ue.current===p&&console.warn("[chat] failed to load query index",{sessionId:o,error:m}),null}},[]);d.useEffect(()=>{var k;const o=r;if(!o||ls||!((k=window.agentApi)!=null&&k.getSessionQueryIndex))return;let c=!1;const p=()=>{!c&&Re.current===o&&hn(o)},m=window,M=m.requestIdleCallback?m.requestIdleCallback(p,{timeout:1e3}):window.setTimeout(p,0);return()=>{c=!0,m.cancelIdleCallback&&m.requestIdleCallback?m.cancelIdleCallback(M):window.clearTimeout(M)}},[ls,hn,r,Er]);const Zo=d.useCallback(async o=>{if(!(!window.agentApi||document.visibilityState==="hidden")){if(J.current==="anchored"){fr(!0);return}if(Xe.current!==o&&(Xe.current=o,yt.current=!1,et.current=!1),yt.current){et.current=!0;return}yt.current=!0;try{do et.current=!1,await mr(window.agentApi,o,Fe(o),{limit:bn},(c,p)=>{var ee,he,je,ue,ye,ge;const m=br(c),M=K(o),k=Ei(M,m,p,c==null?void 0:c.history),H=c!=null&&c.goalState&&o.startsWith("runtime:")?no(k,c.goalState):k,N=mt.current,V=!N||N.scrollHeight-N.scrollTop-N.clientHeight<80;pn.current=V?null:"skip",se(H,o),Ve(o,(ee=c==null?void 0:c.history)==null?void 0:ee.revision),c!=null&&c.goalState&&Pt(Bi(c.goalState));const O=L.current,D=((he=c==null?void 0:c.history)==null?void 0:he.nextCursor)??null;if(_.current===O){const Ne=_.current!==D;_.current=D,Ne&&((je=P.current)==null||je.invalidate(),_t(o,D))}L.current=D,(ue=c==null?void 0:c.history)!=null&&ue.revision&&c.history.revision!==((ye=Ce.current)==null?void 0:ye.revision)&&hn(o);const G=ji((c==null?void 0:c.events)??[]);Wt(wi((c==null?void 0:c.events)??[]),o),pt(ki((c==null?void 0:c.events)??[]),o),G&&Le(G,o);const Z=H[H.length-1];(Z==null?void 0:Z.role)==="assistant"&&((ge=Z.toolCalls)!=null&&ge.length)?Qe(ro(Z.toolCalls)?"thinking":"tools"):Qe(Mo(c)?"thinking":"idle")},()=>Re.current===o&&ne.current===o);while(et.current)}catch(c){console.error("[chat] failed to refresh native session history",{sessionId:o,error:c})}finally{Xe.current===o&&(yt.current=!1)}}},[K,Fe,hn,_t,Le,se,Ve,Qe]);d.useEffect(()=>{const o=r,c=yd(x,o),p=(x==null?void 0:x.occupancy)==="owned-externally"||(x==null?void 0:x.status)==="running";if(!o||!c||!window.agentApi)return;let m=null,M=null,k=!1;const H=()=>{!k&&document.visibilityState!=="hidden"&&Zo(o)},N=()=>{m==null||m(),m=null,M!==null&&window.clearInterval(M),M=null},V=()=>{k||M!==null||document.visibilityState==="hidden"||(H(),M=window.setInterval(H,2e3))},O=()=>{if(!(k||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){p&&V();return}try{m=window.agentApi.observeSession(o,H,()=>{m=null,p&&V()})}catch{p&&V()}}},D=()=>{N(),document.visibilityState!=="hidden"&&(H(),O())};return O(),document.addEventListener("visibilitychange",D),()=>{k=!0,document.removeEventListener("visibilitychange",D),N(),Xe.current===o&&(Xe.current=null,et.current=!1)}},[Zo,r,B,x==null?void 0:x.agentType,x==null?void 0:x.occupancy,x==null?void 0:x.status]);const Qs=d.useCallback(async()=>{const o=ne.current,c=_.current,p=window.agentApi;if(!p||!o||!c||ss.current)return;ss.current=!0,is(null);const m=window.setTimeout(()=>{ne.current===o&&ss.current&&Do(!0)},500);try{const M=K(o);await mr(p,o,Fe(o),{before:c,limit:bn},(k,H)=>{var D,G;const N=br(k),V=mt.current;H!=="trace"&&V&&N.length>0&&(Ls.current={scrollHeight:V.scrollHeight,scrollTop:V.scrollTop},pn.current="skip");const O=((D=k==null?void 0:k.history)==null?void 0:D.nextCursor)??null;_.current=O,Ve(o,(G=k==null?void 0:k.history)==null?void 0:G.revision),N.length>0&&se([...N,...M],o),H!=="trace"&&_t(o,O)},()=>ne.current===o&&Re.current===o,()=>P.current.consume(o,c,()=>p.getSession(o,{before:c,limit:bn,...Fe(o)==="codex"?{view:"core"}:{}})))}catch(M){if(ne.current!==o)return;console.error("[chat] failed to load older history",{sessionId:o,error:M}),is(M instanceof Error?M.message:"历史消息加载失败")}finally{window.clearTimeout(m),ss.current=!1,ne.current===o&&Do(!1)}},[K,Fe,_t,se,Ve]);d.useEffect(()=>{f.current=()=>{Qs()}},[Qs]);const Jo=d.useCallback(async()=>{const o=ne.current,c=ie.current;if(!(!window.agentApi||!o||!c||J.current!=="anchored"||ze.current)){ze.current=!0,Bo(!0);try{const p=K(o),m=new Set(p.map(M=>M.id));await mr(window.agentApi,o,Fe(o),{after:c,limit:bn},M=>{var H,N;const k=br(M).filter(V=>!m.has(V.id));ie.current=((H=M==null?void 0:M.history)==null?void 0:H.newerCursor)??null,Ve(o,(N=M==null?void 0:M.history)==null?void 0:N.revision),k.length>0&&(pn.current="skip",se([...p,...k],o))},()=>Re.current===o&&ne.current===o&&J.current==="anchored")}catch(p){console.error("[chat] failed to load newer anchored history",{sessionId:o,error:p})}finally{ze.current=!1,Bo(!1)}}},[K,Fe,se,Ve]);d.useEffect(()=>{I.current=()=>{Jo()}},[Jo]);const Yo=d.useCallback(async()=>{const o=Re.current;if(!window.agentApi||!o||bt.current)return!1;const c=++ae.current;bt.current=!0,as(!0),pr(null);try{let p=!1;return await mr(window.agentApi,o,Fe(o),{limit:bn},(m,M)=>{var N,V,O,D,G,Z,ee;p=!0;const k=br(m),H=((N=m==null?void 0:m.history)==null?void 0:N.nextCursor)??null;M!=="trace"&&((V=P.current)==null||V.invalidate()),_.current=H,L.current=H,ie.current=null,Ve(o,(O=m==null?void 0:m.history)==null?void 0:O.revision),Ln("latest"),fr(!1),ur(((G=(D=Ce.current)==null?void 0:D.entries.at(-1))==null?void 0:G.messageId)??null),Ye.current=!0,pn.current="skip",se(k,o),M!=="trace"&&_t(o,H),((Z=m==null?void 0:m.history)==null?void 0:Z.revision)!==((ee=Ce.current)==null?void 0:ee.revision)&&hn(o)},()=>ae.current===c&&Re.current===o),p}catch(p){return te(p instanceof Error?p.message:"返回最新消息失败"),!1}finally{bt.current=!1,as(!1)}},[Fe,hn,_t,Ln,se,Ve]),Xo=d.useCallback(async(o,c=!0)=>{var H;const p=Re.current,m=mt.current;if(!window.agentApi||!p||!m)return;const M=++ae.current;ur(o.messageId);const k=Array.from(m.querySelectorAll("[data-message-id]")).find(N=>N.dataset.messageId===o.messageId);if(k){pr(null),co(m,k,"smooth");return}pr(o.messageId),(H=P.current)==null||H.invalidate();try{await mr(window.agentApi,p,Fe(p),{anchor:o.pageToken,limit:bn},(N,V)=>{var G,Z,ee,he,je,ue;if(((G=Ce.current)==null?void 0:G.revision)!==((Z=N==null?void 0:N.history)==null?void 0:Z.revision))return;const O=br(N),D=((ee=N==null?void 0:N.history)==null?void 0:ee.olderCursor)??((he=N==null?void 0:N.history)==null?void 0:he.nextCursor)??null;_.current=D,ie.current=((je=N==null?void 0:N.history)==null?void 0:je.newerCursor)??null,Ve(p,(ue=N==null?void 0:N.history)==null?void 0:ue.revision),Ln("anchored"),fr(!1),re.current=o.messageId,pn.current="skip",se(O,p),V!=="trace"&&(window.requestAnimationFrame(()=>{if(ae.current!==M||Re.current!==p)return;const ye=mt.current,ge=Array.from((ye==null?void 0:ye.querySelectorAll("[data-message-id]"))??[]).find(Ne=>Ne.dataset.messageId===o.messageId);!ye||!ge||(co(ye,ge),re.current=null,ur(o.messageId))}),_t(p,D))},()=>ae.current===M&&Re.current===p)}catch(N){if(N.code==="STALE_SESSION_ANCHOR"&&c){const O=await hn(p),D=O==null?void 0:O.entries.find(G=>G.ordinal===o.ordinal);D&&await Xo(D,!1);return}console.error("[chat] failed to open indexed query",{sessionId:p,error:N}),te(N instanceof Error?N.message:"无法打开这条消息")}finally{ae.current===M&&pr(null)}},[Fe,hn,_t,Ln,se,Ve]),ei=o=>{if(gr.current.has(o)||$r.current.has(o))return;const c=window.setTimeout(()=>{$r.current.delete(o),(async()=>{var p;if(!gr.current.has(o))try{const m=await((p=window.agentApi)==null?void 0:p.getSessionGoals(o)),M=Re.current||at.current;if(m&&o===M&&Be(m,o),m!=null&&m.active){_e.current=o,o===M&&(Pn.current=!1,te(null),C(o));return}if(Pn.current)return;const k=xe.getState().getMessagesForSession(o).find(H=>H.isQueued&&!H.queueItemId);if(!k){o===M&&(_e.current=null,C(null));return}X(k.id,H=>({...H,isQueued:!1}),o),xr(k,o)}catch(m){te(m instanceof Error?m.message:"排队消息自动发送失败")}})()},150);$r.current.set(o,c)},kl=o=>{var M,k,H;const c=Re.current||at.current,p=o._sid||c||void 0;if(o._nativeRunId&&Number.isSafeInteger(o._nativeSequence)){const N=`${o._nativeRunId}:${o._nativeSequence}`;if(de.current.has(N))return;de.current.add(N),de.current.size>2e3&&(de.current=new Set([...de.current].slice(-1e3)))}const m=!p||p===c;if(m&&J.current==="anchored"){fr(!0);return}switch(o.type){case"run_admitted":if(p){Fr.current.delete(p);const N=gs(lt.current,p);N&&(gn.current===N.token&&(gn.current=null),gt(void 0,p)),dd(p)}break;case"context_usage":o.usage&&Le(o.usage,p);break;case"text_chunk":o.text&&($(o.text,p),m&&Qe("thinking"));break;case"reasoning_summary_delta":if(typeof o.itemId=="string"&&Number.isSafeInteger(o.sectionIndex)&&typeof o.delta=="string"){const N={type:"reasoning_summary_delta",itemId:o.itemId,sectionIndex:o.sectionIndex,delta:o.delta,...o.turnId?{turnId:o.turnId}:{}};p&&o.turnId&&Fe(p)==="codex"?Q(o.turnId,N,p):T(N,p),m&&Qe("thinking")}break;case"runtime_progress":if(typeof o.progressId=="string"&&typeof o.label=="string"&&["thinking","tool","retry","status"].includes(o.phase??"")){const N={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}};Qn(N,p),m&&Qe(N.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(M=o.activity)!=null&&M.parentToolCallId&&(kr(o.activity,p),m&&o.activity.status==="running"&&Qe("tools"));break;case"tool_call":m&&Qe("tools"),o.toolCall&&o.toolCall.name!=="dispatch_agent"&&o.toolCall.name!=="ask_user"&&o.toolCall.name!=="show_widget"&&(p&&o.turnId&&Fe(p)==="codex"?Q(o.turnId,{type:"tool_call",toolCall:o.toolCall,turnId:o.turnId},p):A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:o.toolCall.id,name:o.toolCall.name,arguments:o.toolCall.arguments}],timestamp:Date.now()},p));break;case"tool_result":o.result&&(p&&o.turnId&&Fe(p)==="codex"?Q(o.turnId,{type:"tool_result",result:o.result,turnId:o.turnId},p):z(o.result.toolCallId,o.result.content,o.result.isError,p));break;case"todo_update":o.todos&&Ee(o.todos);break;case"cron_update":o.tasks&&be(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()},p),o.subSessionId){An.current.add(o.subSessionId);const N=_e.current||ce;N&&a&&a(N)}u==null||u({type:"started",agentName:o.agentName??"",task:o.task??"",subSessionId:o.subSessionId});break;case"agent_done":o.subSessionId&&(An.current.delete(o.subSessionId),q(o.subSessionId,o.status??"completed",o.status==="failed"?o.error:o.summary,p)),u==null||u({type:o.status==="failed"?"failed":"completed",agentName:o.agentName??"",task:o.task??"",subSessionId:o.subSessionId});break;case"agent_progress":o.subSessionId&&o.text&&le(o.subSessionId,o.text,p);break;case"compacted":A({id:crypto.randomUUID(),role:"assistant",content:o.summary??"",isCompactionSummary:!0,timestamp:Date.now()},p);break;case"show_widget":{const N=o.data??o.widgetData,V={widgetId:o.widgetId,widgetType:o.widgetType,data:N??{}},D=(p?xe.getState().getMessagesForSession(p):xe.getState().messages).find(G=>{var Z;return((Z=G.widget)==null?void 0:Z.widgetId)===V.widgetId});D?X(D.id,G=>({...G,widget:V}),p):A({id:crypto.randomUUID(),role:"assistant",content:"",widget:V,timestamp:Date.now()},p);break}case"ask_user":if(o.questionId&&(p?xe.getState().getMessagesForSession(p):xe.getState().messages).some(V=>{var O;return((O=V.askUser)==null?void 0:O.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()},p);break;case"approval_resolved":{if(!o.questionId)break;const V=(p?xe.getState().getMessagesForSession(p):xe.getState().messages).find(O=>{var D;return((D=O.askUser)==null?void 0:D.questionId)===o.questionId});V&&X(V.id,O=>({...O,askUser:O.askUser?{...O.askUser,answered:!0,answer:"已处理"}:O.askUser}),p);break}case"text_done":break;case"thinking":m&&Qe("thinking");break;case"done":if(p){const N=Ha(o.durationMs);if(N!==void 0){const V=[...K(p)].reverse().find(O=>{var D;return O.role==="assistant"&&!!O.content.trim()&&!((D=O.toolCalls)!=null&&D.length)&&!O.isCompactionSummary});V&&X(V.id,O=>({...O,presentation:{...O.presentation,completionDurationMs:N}}),p)}}if(Lt(p),m&&!xe.getState().messages.some(N=>N.isQueued)&&C(null),m&&(Qe("idle"),ut.getState().autoSpeak)){const V=[...xe.getState().messages].reverse().find(O=>O.role==="assistant"&&O.content&&!O.isCompactionSummary);V!=null&&V.content&&(k=window.agentApi)!=null&&k.ttsSpeak&&(qr(),window.agentApi.ttsSpeak(V.content.slice(0,600)).then(O=>{O.ok||te("TTS 模型播报失败")}).catch(O=>{te(O instanceof Error?O.message:"TTS 模型播报失败")}))}p&&(gr.current.has(p)?window.setTimeout(()=>{us(p)},150):ei(p));break;case"error":if(o._preserveActiveRun||Lt(p),p&&o.code==="SESSION_OCCUPIED"){const N=xe.getState().getMessagesForSession(p),V=Fr.current.get(p),O=gs(lt.current,p),D=V??(O==null?void 0:O.payload),G=D?[...N].reverse().find(ee=>ee.role==="user"&&!ee.isQueued&&ee.content===D.content):m?[...N].reverse().find(ee=>ee.role==="user"&&!ee.isQueued):void 0,Z=D??(G?{content:G.content,images:G.images,agentName:G.agentName}:void 0);G&&se(N.filter(ee=>ee.id!==G.id),p),Fr.current.delete(p),Z!=null&&Z.content&&(gt(O??gu(p,Z)),to(p,Z.content),m&&(st(Z.content),Qt(Z.images??[]))),m&&te(null)}if(m){if(o._preserveActiveRun&&p&&(Vo.current.add(p),_e.current=p,C(p),Qe("thinking")),o.code==="SESSION_ALREADY_RUNNING"){const N=p?xe.getState().getMessagesForSession(p):xe.getState().messages,V=pd(N);if(V){const O=N.find(D=>D.id===V);X(V,D=>({...D,isQueued:!0}),p),Jn&&(p!=null&&p.startsWith("runtime:"))&&O&&((H=window.agentApi)!=null&&H.enqueueSessionMessage)&&window.agentApi.enqueueSessionMessage(p,{sourceMessageId:O.id,content:O.content,images:O.images,agentName:O.agentName}).then(D=>Be(D,p)).catch(D=>{te(D instanceof Error?D.message:"排队消息保存失败")})}p&&Fr.current.delete(p),p&>(void 0,p),te(null)}else if(o.code!=="SESSION_OCCUPIED"){te(o.message??"Unknown error");const V=[...p?xe.getState().getMessagesForSession(p):xe.getState().messages].reverse().find(O=>O.role==="user"&&!O.isQueued);fe&&(V!=null&&V.content)&&(st(V.content),p&&to(p,V.content))}}if(!o._preserveActiveRun){const N=p??c;(!N||_e.current===N)&&(_e.current=null),(!N||xe.getState().runningSessionId===N)&&C(null),m&&Qe("idle")}p&&!o._preserveActiveRun&&(gr.current.has(p)?window.setTimeout(()=>{us(p)},150):ei(p));break;case"turn_aborted":Lt(p),m&&(C(null),Qe("idle"));break}},Sl=async o=>{var p;if(!U||!((p=window.agentApi)!=null&&p.setSessionPermissionMode)||it)return;const c=At;En(o),Vt(!1),ns(!0);try{await window.agentApi.setSessionPermissionMode(U,o)}catch(m){En(c),te(m instanceof Error?m.message:"权限模式更新失败")}finally{ns(!1)}},Il=async()=>{var o;if(!(!U||!((o=window.agentApi)!=null&&o.handoffSession)))try{await window.agentApi.handoffSession(U),te(null)}catch(c){te(c instanceof Error?c.message:"交接到 Desktop 失败")}},Cl=async()=>{var o;if(!(!U||(x==null?void 0:x.agentType)!=="codex"||!((o=window.agentApi)!=null&&o.releaseCodexSession)||nn!=="idle")&&!(Ut&&!window.confirm("停止当前执行并交接到 Codex 桌面端?"))){ht("releasing");try{await window.agentApi.releaseCodexSession(U),Pn.current=!0,hr.current+=1,_e.current=null,C(null),An.current.clear(),Pt(c=>({...c,active:null,queued:[]})),xt("idle"),te(null),ht("released")}catch(c){ht("idle"),te(c instanceof Error?c.message:"释放 Codex 会话失败")}}},Al=async()=>{var c;const o=De;if(!(!o||!U||tn)&&gn.current!==o.token){if(gn.current=o.token,o.forkSessionId){Bt(!0);const p=Hi(o,o.forkSessionId);gt(p),A({id:crypto.randomUUID(),role:"user",content:p.payload.content,timestamp:Date.now(),agentName:p.payload.agentName,images:p.payload.images},p.forkSessionId),xr(p.payload,p.forkSessionId,p.payload.agentIds).finally(()=>{gn.current=null,Bt(!1)});return}if(!((c=window.agentApi)!=null&&c.forkSession)){gn.current=null;return}Bt(!0);try{const p=await xu({sourceSessionId:o.sourceSessionId,forkSession:M=>window.agentApi.forkSession(M),activateSession:M=>{at.current=M,W(M)},refreshAndSelect:async M=>{s?await s(M.id,M):l==null||l(M.id)}}),m=Hi(o,p.id);gt(m),A({id:crypto.randomUUID(),role:"user",content:m.payload.content,timestamp:Date.now(),agentName:m.payload.agentName,images:m.payload.images},p.id),xr(m.payload,p.id,m.payload.agentIds).finally(()=>{gn.current=null,Bt(!1)}),te(null)}catch(p){gn.current=null,te(p instanceof Error?p.message:"创建会话副本失败"),Bt(!1)}}},ti=()=>{Pn.current=!0,hr.current+=1,window.agentApi&&window.agentApi.abort(U||void 0),_e.current=null,C(null),An.current.clear()},ni=async o=>{const c=r||ce;if(!c||!window.agentApi)return;const p=xe.getState().messages.find(m=>m.id===o);if(!(!p||!p.isQueued))try{p.queueItemId&&c.startsWith("runtime:")?Be(await window.agentApi.steerSessionMessage(c,p.queueItemId),c):(await window.agentApi.steer(p.content,c,p.agentName),X(o,m=>({...m,isQueued:!1,isSteered:!0}))),ot===o&&(It(null),Rn(""))}catch(m){te(m instanceof Error?m.message:"引导失败")}},Rl=o=>{const c=xe.getState().messages.find(p=>p.id===o&&p.isQueued);c&&(It(o),Rn(c.content))},Ks=()=>{It(null),Rn("")},ri=async o=>{const c=Oe.trim(),p=xe.getState().messages.find(m=>m.id===o&&m.isQueued);if(!(!p||!c))try{p.queueItemId&&(U!=null&&U.startsWith("runtime:"))?Be(await window.agentApi.updateSessionMessage(U,p.queueItemId,c),U):X(o,m=>m.isQueued?{...m,content:c}:m,U||void 0),Ks()}catch(m){te(m instanceof Error?m.message:"排队消息保存失败")}},Tl=async o=>{const c=xe.getState().messages.find(p=>p.id===o&&p.isQueued);if(c){if(!await eo(c.content)){te("复制排队消息失败");return}nr(o),window.setTimeout(()=>nr(p=>p===o?null:p),1200)}},Ml=async o=>{const c=xe.getState().messages,p=c.find(m=>m.id===o&&m.isQueued);if(p)try{p.queueItemId&&(U!=null&&U.startsWith("runtime:"))?Be(await window.agentApi.cancelSessionMessage(U,p.queueItemId),U):se(c.filter(m=>m.id!==o),U||void 0),ot===o&&Ks()}catch(m){te(m instanceof Error?m.message:"排队消息删除失败")}},Gs=async(o,c)=>{const p=xe.getState().messages,m=gd(p,o,c);if(m!==p){se(m,U||void 0);const M=m.filter(k=>k.isQueued&&k.queueItemId);if(U!=null&&U.startsWith("runtime:")&&M.length>0)try{Be(await window.agentApi.reorderSessionMessages(U,M.map(k=>k.queueItemId)),U)}catch(k){se(p,U),te(k instanceof Error?k.message:"排队消息排序保存失败")}}},El=(o,c)=>{const p=xe.getState().messages.filter(k=>k.isQueued),m=p.findIndex(k=>k.id===o),M=p[m+c];M&&Gs(o,M.id)},Nl=async o=>{const c=dn;if(He(null),!U||!c||c===o)return;const p=we.queued.map(N=>N.id),m=p.indexOf(c),M=p.indexOf(o);if(m<0||M<0)return;const k=[...p];k.splice(M,0,k.splice(m,1)[0]);const H=we;Pt({...we,queued:k.map((N,V)=>({...we.queued.find(O=>O.id===N),position:V}))});try{Be(await window.agentApi.reorderSessionGoals(U,k),U)}catch(N){Pt(H),te(N instanceof Error?N.message:"目标排序保存失败")}},si=async o=>{if(!U)return;const c=we.queued.find(p=>p.id===o);try{const p=await window.agentApi.cancelSessionGoal(U,o);if(Be(p,U),c!=null&&c.sourceMessageId){const m=xe.getState().getMessagesForSession(U);se(m.filter(M=>M.id!==c.sourceMessageId),U)}p.active||C(null)}catch(p){te(p instanceof Error?p.message:"目标删除失败")}};d.useEffect(()=>{ot&&(y.some(o=>o.id===ot&&o.isQueued)||(It(null),Rn("")))},[ot,y]);async function xr(o,c,p){var m,M;c.startsWith("runtime:")&&Fr.current.set(c,{content:o.content,images:o.images?[...o.images]:void 0,agentIds:p?[...p]:void 0,agentName:o.agentName}),Pn.current=!1,gr.current.add(c),ul(c),_e.current=c,C(c);try{if(window.agentApi){const k=fe&&vs(pe)?{...(m=$t.model)!=null&&m.id?{model:$t.model}:{},...nt?{reasoningEffort:nt}:{}}:void 0;await window.agentApi.run(o.content,c,p,o.agentName,o.images,k)}}catch(k){te(k instanceof Error?k.message:"Agent run failed")}finally{if(gr.current.delete(c),Vo.current.delete(c)){_e.current=c,C(c);return}const H=(M=window.agentApi)!=null&&M.getSessionGoals?await window.agentApi.getSessionGoals(c).catch(()=>{}):void 0;if(H&&c===(Re.current||at.current)&&Be(H,c),H!=null&&H.active){_e.current=c,C(c),h&&h(n,c);return}const N=Pn.current?void 0:xe.getState().getMessagesForSession(c).find(V=>V.isQueued&&!V.queueItemId);N?(X(N.id,V=>({...V,isQueued:!1}),c),h&&h(n,c),xr(N,c)):(_e.current=null,C(null),h&&h(n,c))}}const oi=async()=>{var V,O,D;if(!qe.trim()||!Cn||cr>0||J.current==="anchored"&&!await Yo())return;ps(window.agentApi,qr),te(null);const o=qe.trim();if(/^\/loop\b/i.test(o)){const G=o.slice(5).trim();if(st(""),A({id:crypto.randomUUID(),role:"user",content:o,timestamp:Date.now()}),/^stop$/i.test(G)){window.agentApi&&(await window.agentApi.cronDeleteAll(),be([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(G)||G===""){if(window.agentApi){const ue=await window.agentApi.cronList();be(ue);const ye=ue.length===0?"当前没有定时任务。":ue.map((ge,Ne)=>`**${Ne+1}.** \`${ge.id.slice(0,6)}\` · ${ao(ge.cron)} · ${ge.enabled?"▶ 启用":"⏸ 已暂停"}
|
|
269
|
+
${ge.prompt}`).join(`
|
|
270
|
+
|
|
271
|
+
`);A({id:crypto.randomUUID(),role:"assistant",content:ye,timestamp:Date.now()})}return}const Z=G.match(/^(?:pause|暂停)\s+(\S+)$/i);if(Z){if(window.agentApi){const ue=Ge.find(ge=>ge.id.startsWith(Z[1])),ye=await window.agentApi.cronPause((ue==null?void 0:ue.id)??Z[1]);if(ye){const ge=await window.agentApi.cronList();be(ge),A({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${ye.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${Z[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const ee=G.match(/^(?:resume|恢复)\s+(\S+)$/i);if(ee){if(window.agentApi){const ue=Ge.find(ge=>ge.id.startsWith(ee[1])),ye=await window.agentApi.cronResume((ue==null?void 0:ue.id)??ee[1]);if(ye){const ge=await window.agentApi.cronList();be(ge),A({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${ye.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${ee[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const he=G.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(he){if(window.agentApi){const ue=Ge.find(ge=>ge.id.startsWith(he[1]));if(await window.agentApi.cronDelete((ue==null?void 0:ue.id)??he[1])){const ge=await window.agentApi.cronList();be(ge),A({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${he[1]}\` 已删除。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${he[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const je=G.match(/^(\S+)\s+(.+)$/s);if(je){const ue=je[1],ye=je[2].trim();if(window.agentApi){let ge=r||ce;if(!ge){const Ne=await window.agentApi.createSession(ye.slice(0,60)||"定时任务",n||void 0);ge=Ne.id,W(Ne.id),s&&await s(Ne.id)}try{const Ne=await window.agentApi.cronCreate(ue,ye,{sessionId:ge}),xn=await window.agentApi.cronList();be(xn),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${Ne.id.slice(0,6)}\`),${ao(ue)}执行:${ye}`,timestamp:Date.now()})}catch(Ne){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${Ne instanceof Error?Ne.message:String(Ne)}`,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 c=o.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(c){const G=c[1]+c[2],Z=c[3].trim();if(Z&&window.agentApi){let ee=r||ce;if(!ee){const he=await window.agentApi.createSession(Z.slice(0,60)||"定时任务",n||void 0);ee=he.id,W(he.id),s&&await s(he.id)}try{const he=await window.agentApi.cronCreate(G,Z,{sessionId:ee}),je=await window.agentApi.cronList();be(je),st(""),A({id:crypto.randomUUID(),role:"user",content:o,timestamp:Date.now()}),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${he.id.slice(0,6)}\`),${ao(G)}执行:${Z}`,timestamp:Date.now()})}catch(he){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${he instanceof Error?he.message:String(he)}`,timestamp:Date.now()})}return}}const p=qe.trim(),m=p.match(/^\/goal(?:\s+([\s\S]+))?$/i),M=m?((V=m[1])==null?void 0:V.trim())??"":Nt?p:null;if(M!==null&&!M){te("请输入目标内容");return}const k=Lr.length>0?Lr.map(G=>G.name).join(", "):void 0,H=lr.length>0?[...lr]:void 0,N=Lr.map(G=>G.id);if(Os([]),fe&&(r||ce)&&(_r.current=!0),st(""),ar([]),Qt([]),M!==null){const G=crypto.randomUUID();let Z=null;Pn.current=!1;try{const ee=await Ui({text:M,projectId:n??null,sessionId:r||ce,createSession:async(je,ue)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(je,ue)},activateSession:je=>{at.current=je,W(je),_e.current=je,C(je)},showUserMessage:(je,ue)=>{Z=ue,A({id:G,role:"user",content:je,timestamp:Date.now(),agentName:k,images:H,isGoal:!0,goalId:G},ue)},onSessionCreated:s}),he=await window.agentApi.enqueueSessionGoal(ee,M,G);Be(he,ee),i&&i(ee,M)}catch(ee){if(Z){const he=xe.getState().getMessagesForSession(Z);se(he.filter(je=>je.id!==G),Z)}C(null),te(ee instanceof Error?ee.message:"目标创建失败")}return}if(rt){const G=crypto.randomUUID(),Z={id:G,role:"user",content:p,timestamp:Date.now(),agentName:k,images:H,isQueued:!0};if(fe&&Jn&&U&&((O=window.agentApi)!=null&&O.enqueueSessionMessage))try{const ee=await window.agentApi.enqueueSessionMessage(U,{sourceMessageId:G,content:p,images:H,agentIds:N,agentName:k});Be(ee,U),((D=ee.active)==null?void 0:D.sourceMessageId)===G&&A({...Z,isQueued:!1},U)}catch(ee){st(p),Qt(H??[]),te(ee instanceof Error?ee.message:"排队消息保存失败")}else A(Z);return}Ee([]);try{const G=await Ui({text:p,projectId:n??null,sessionId:r||ce,createSession:async(Z,ee)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(Z,ee)},activateSession:Z=>{at.current=Z,W(Z),_e.current=Z,C(Z)},showUserMessage:(Z,ee)=>A({id:crypto.randomUUID(),role:"user",content:Z,timestamp:Date.now(),agentName:k,images:H},ee),onSessionCreated:s});i&&i(G,p),await xr({content:p,agentName:k,images:H},G,N.length>0?N:void 0)}catch(G){te(G instanceof Error?G.message:"Agent run failed")}};return d.useEffect(()=>{if(!v||!window.agentApi)return;const{text:o,projectId:c,sessionId:p}=v;let m=!1;return(async()=>{try{Ee([]);const M=await Zd({text:o,projectId:c,sessionId:p,createSession:async(k,H)=>await window.agentApi.createSession(k,H),activateSession:k=>{at.current=k,W(k),_e.current=k,C(k)},showUserMessage:(k,H)=>A({id:crypto.randomUUID(),role:"user",content:k,timestamp:Date.now()},H),onSessionCreated:s,isCancelled:()=>m});if(!M)return;i&&i(M,o),await xr({content:o},M)}catch(M){te(M instanceof Error?M.message:"语音指令执行失败")}})(),()=>{m=!0}},[v==null?void 0:v.nonce]),e.jsxs("div",{className:"chat-view chat-view--codex-history",style:{display:"flex",flexDirection:"column",height:"100%",maxWidth:"var(--chat-max-width)",margin:"0 auto"},children:[e.jsxs("div",{className:"chat-top-bar",style:{display:"flex",alignItems:"center",padding:"var(--chat-header-padding)",height:"var(--chat-header-height)",flexShrink:0,borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"no-drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:g?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:g||"会话"}),b&&S&&R&&e.jsx($d,{appearanceOpen:E,settingsOpen:w,hideToBackgroundTitle:F,codexReleaseState:nn,onHideToBackground:S,onReleaseCodex:(x==null?void 0:x.agentType)==="codex"&&x.occupancy!=="owned-externally"?()=>{Cl()}:void 0,onToggleAppearance:R,onOpenSettings:b})]}),e.jsxs("div",{className:"chat-messages-frame",children:[e.jsxs("div",{ref:mt,className:"chat-messages",onScroll:ll,style:{overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[y.length>0&&(Po||os)&&e.jsx("div",{className:"chat-history-page-status",role:os?"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:os?"var(--danger)":"var(--text-muted)",fontSize:12},children:Po?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 Qs(),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:[os,",点击重试"]})}),y.length===0&&ls&&sl&&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:"正在加载历史消息"})]}),y.length===0&&!Ut&&!ls&&!Nn&&e.jsx(Ud,{agentType:(x==null?void 0:x.agentType)??t,ready:Cn,onSelectPrompt:hl},U??"initial-empty-session"),Ze.map((o,c)=>{var ee,he,je,ue,ye,ge,Ne,xn,mn;const p=o;if(p.isQueued)return null;if(p.executionTrace)return e.jsx(Dd,{trace:p.executionTrace,loadTrace:al,loadToolResult:Us,renderContent:hs,runtimeProgress:kt,nativeSubagents:St,onSelectSession:l,workspacePath:j,enableFilePreview:$n()},o.id);const m=o.role==="user",M=m&&(p.isGoal===!0||[we.active,...we.queued,...we.history].some(Y=>!!(Y&&Vi(Y.objective)===Vi(o.content)))),k=cu(Ze,c,Ut),H=ou((ee=p.presentation)==null?void 0:ee.completionDurationMs);if(p.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(p.widget){const Y=Qd[p.widget.widgetType];return Y?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(Y,{...p.widget.data,widgetId:p.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(p.widget.data,null,2)},o.id)}if(p.askUser)return e.jsx(_d,{questionId:p.askUser.questionId,question:p.askUser.question,options:p.askUser.options,fields:p.askUser.fields,multiSelect:p.askUser.multiSelect,answered:p.askUser.answered,answer:p.askUser.answer,onAnswer:(Y,Ke)=>{var zt;X(o.id,ve=>({...ve,askUser:{...ve.askUser,answered:!0,answer:Y}})),(zt=window.agentApi)==null||zt.answerQuestion(p.askUser.questionId,Y,Ke)}},o.id);const N=p.agentName?p.agentName.charAt(0).toUpperCase():"你",V=!m&&c===Ze.length-1,O=Ze[c+1],D=O&&O.role!==o.role&&!O.isCompactionSummary,G=(o.toolCalls??[]).map((Y,Ke)=>{let zt;if(Y.name==="write_file"&&Y.arguments.file_path){const ve=Y.arguments.file_path;e:for(let vt=c;vt>=0;vt--){const Gt=Ze[vt].toolCalls;if(!Gt)continue;const Or=vt===c?Ke-1:Gt.length-1;for(let Dn=Or;Dn>=0;Dn--){const Zt=Gt[Dn];if(Zt.name==="read_file"&&Zt.arguments.file_path===ve&&Zt.result&&!Zt.isError){zt=Zt.result;break e}}}}return{toolCall:Y,beforeContent:zt,progress:ka(kt,Y.id),nativeSubagent:St[Y.id]}}),Z=qa(G);return e.jsx("div",{"data-message-id":o.id,className:`chat-message-group${k.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:k.compact?0:D?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:e.jsxs("div",{className:`chat-message-row chat-message-row--${m?"user":"assistant"}`,style:{display:"flex",flexDirection:m?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[m?e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--accent)",color:"#fff",fontSize:12,fontWeight:700,letterSpacing:0,userSelect:"none"},children:N}):e.jsx("div",{className:"chat-message-avatar",style:{width:"var(--chat-avatar-size)",height:"var(--chat-avatar-size)",borderRadius:"50%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("path",{d:"M12 11V7"}),e.jsx("circle",{cx:"12",cy:"5",r:"2"}),e.jsx("circle",{cx:"8",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"16",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M8 20h8"})]})}),e.jsxs("div",{className:`chat-message-content chat-message-content--${m?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:m?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${m?"user":"assistant"} ${o.role==="assistant"&&o.content?"message-card":""}`,style:{padding:o.content||m&&((he=p.images)!=null&&he.length)?m?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:m?"14px 4px 14px 14px":"4px 14px 14px 14px",background:o.content||m&&((je=p.images)!=null&&je.length)?m?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:o.content||m&&((ue=p.images)!=null&&ue.length)?m?"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"&&((ye=o.presentation)==null?void 0:ye.reasoning)&&e.jsx(Fa,{sections:o.presentation.reasoning,streaming:Ut&&V&&Xn==="thinking",startedAt:tr,renderContent:hs}),m&&p.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"})]}),p.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:hs(o.content)}):o.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:m?o.content:hs(o.content)}),m&&p.images&&p.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:o.content?8:0},children:p.images.map((Y,Ke)=>e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":"放大查看图片",onClick:()=>un({src:Y,alt:`用户发送的图片 ${Ke+1}`}),children:e.jsx("img",{className:"chat-message-attachment-image",src:Y,alt:`用户发送的图片 ${Ke+1}`})},Ke))}),m&&!((ge=p.images)!=null&&ge.length)&&((Ne=p.presentation)==null?void 0:Ne.attachments)&&p.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:p.presentation.attachments.map((Y,Ke)=>Y.dataUrl?e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":`放大查看图片:${Y.name}`,onClick:()=>un({src:Y.dataUrl,alt:Y.name}),children:e.jsx("img",{className:"chat-message-attachment-image",src:Y.dataUrl,alt:Y.name,title:Y.name})},`${Y.name}-${Ke}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${Y.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:Y.name}),e.jsx("span",{children:"图片已失效"})]},`${Y.name}-${Ke}`))}),m&&((xn=p.presentation)==null?void 0:xn.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:p.presentation.rawContent})]}),Z.map(Y=>Y.action&&Y.items.length>1?e.jsx($a,{items:Y.items,onSelectSession:l,workspacePath:j,enableFilePreview:$n(),onLoadResult:qo},`group-${Y.items[0].toolCall.id}`):e.jsx(Rs,{toolCall:Y.items[0].toolCall,beforeContent:Y.items[0].beforeContent,progress:Y.items[0].progress,nativeSubagent:Y.items[0].nativeSubagent,onSelectSession:l,workspacePath:j,enableFilePreview:$n(),onLoadResult:qo},Y.items[0].toolCall.id)),(()=>{const Y=(o.toolCalls??[]).filter(ve=>ve.name==="write_file"&&ve.result&&!ve.isError);if(Y.length===0)return null;const Ke=new Map;for(const ve of Y){const vt=ve.arguments.file_path??"",Gt=ve.arguments.content??"",Or=Gt?Gt.split(`
|
|
272
|
+
`).length:0;let Dn=0;e:for(let Zt=c;Zt>=0;Zt--){const mi=Ze[Zt].toolCalls??[];for(let Zs=mi.length-1;Zs>=0;Zs--){const Ur=mi[Zs];if(Ur.name==="read_file"&&Ur.arguments.file_path===vt&&Ur.result&&!Ur.isError){Dn=Ur.result.split(`
|
|
273
|
+
`).length;break e}}}Ke.set(vt,{path:vt,lines:Or,added:Math.max(0,Or-Dn),removed:Math.max(0,Dn-Or)})}const zt=[...Ke.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:"变更汇总"}),zt.map(ve=>{const vt=Ma(ve.path,j),Gt=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:ve.path,children:ve.path.replace(/\\/g,"/").split("/").pop()}),ve.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",ve.added]}),ve.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",ve.removed]}),ve.added===0&&ve.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[ve.lines,"行"]})]});return $n()&&vt?e.jsx("button",{type:"button",className:"chat-file-change-link",onClick:()=>Hn(vt),title:`预览 ${vt}`,"aria-label":`预览改动文件 ${ve.path.replace(/\\/g,"/").split("/").pop()}`,children:Gt},ve.path):e.jsx("span",{className:"chat-file-change-link chat-file-change-link--static",children:Gt},ve.path)})]})})()]}),k.showCompletion&&e.jsxs("div",{className:"msg-completion-footer",children:[e.jsxs("span",{className:"msg-completion-status",children:[e.jsx(Qr,{size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"已完成"}),H&&e.jsxs("span",{children:[" · 总耗时 ",H]})]}),e.jsxs("span",{className:"msg-completion-actions",children:[!$n()&&k.showSpeak&&typeof((mn=window.agentApi)==null?void 0:mn.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>dl(o.id,o.content),title:Dr===o.id?"停止播报":"语音播报","aria-label":Dr===o.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${Dr===o.id?"is-active":""}`,children:Dr===o.id?e.jsx(dc,{size:12,fill:"currentColor","aria-hidden":"true"}):e.jsx(fc,{size:13,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{eo(o.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Js,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]})]}),!k.showCompletion&&(k.showCopy||M)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[M&&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(Ys,{size:13,strokeWidth:1.9,"aria-hidden":"true"})}),k.showCopy&&e.jsx("button",{type:"button",onClick:()=>{eo(o.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Js,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]}),m&&(p.isQueued||p.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[p.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"})]}),"排队中"]}),Ft&&e.jsxs("button",{onClick:()=>void ni(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:Y=>{Y.currentTarget.style.background="rgba(79,110,247,0.18)",Y.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:Y=>{Y.currentTarget.style.background="var(--accent-dim)",Y.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"})]}),"引导"]})]}),p.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)}),Ut&&qt&&e.jsx(Wa,{progress:qt,startedAt:tr}),_s&&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(Ld,{startedAt:tr})}),(Je||Nn)&&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:Je||Nn}),Je&&e.jsxs("button",{type:"button",onClick:()=>zs(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(xa,{size:14,"aria-hidden":"true"}),"重新加载"]})]}),e.jsx("div",{ref:Nr})]}),e.jsx(Jc,{entries:(Ps==null?void 0:Ps.entries)??[],activeMessageId:el,loadingMessageId:tl,onActivate:o=>{Xo(o)}}),Bs==="anchored"&&e.jsx("button",{type:"button",className:"chat-history-return-latest","data-has-updates":nl,"data-loading-newer":rl,"aria-busy":$s||void 0,"aria-label":"回到最新消息",title:"回到最新消息",disabled:$s,onClick:()=>{Yo()},children:$s?e.jsx(Rt,{className:"chat-history-return-latest__spinner",size:16,"aria-hidden":"true"}):e.jsx($l,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[Sn&&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:Et==="incompatible"?"var(--danger)":"var(--text-muted)",fontSize:12},children:e.jsx("span",{style:{flex:1},children:Et==="incompatible"?rn||((di=x==null?void 0:x.compatibility)==null?void 0:di.reason)||`Codex ${((ui=x==null?void 0:x.compatibility)==null?void 0:ui.producerVersion)??"未知版本"} 与当前 ${((pi=x==null?void 0:x.compatibility)==null?void 0:pi.readerVersion)??"运行时"} 不兼容`:`正在使用 Codex ${((fi=x==null?void 0:x.compatibility)==null?void 0:fi.readerVersion)??"当前版本"} 验证此会话`})}),Yn&&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:De!=null&&De.forkSessionId?"副本已创建,但消息尚未发送成功。":"此会话仍由原客户端持有,可创建副本继续。"}),Yn&&e.jsx("button",{type:"button",onClick:()=>void Al(),disabled:tn,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:tn?"wait":"pointer",opacity:tn?.65:1},children:tn?De!=null&&De.forkSessionId?"正在发送…":"正在创建…":De!=null&&De.forkSessionId?"重新发送":"以副本继续"})]}),ke.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(ke.filter(c=>c.status==="completed").map(c=>c.title.toLowerCase()));return ke.map(c=>{const p=c.status==="pending",m=c.status==="in-progress",M=c.status==="completed",k=p&&(c.dependsOn??[]).some(H=>!o.has(H.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:M?.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:M?"rgba(52,211,153,0.15)":m?"var(--accent-dim)":k?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:M?"1.5px solid rgba(52,211,153,0.6)":m?"1.5px solid var(--accent)":k?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[M&&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"})}),m&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),k&&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"})}),p&&!k&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:M?"var(--text-muted)":k?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:M?"line-through":"none",flex:1},children:c.title}),k&&e.jsx("span",{title:`等待: ${(c.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:"等待前置"}),c.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:["@",c.agentName]})]},c.id)})})()})]}),Ge.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(),be([]),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:"全部删除"})]}),Ge.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 c=await window.agentApi.cronList();be(c)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:c=>{c.currentTarget.style.borderColor="#d97706",c.currentTarget.style.color="#d97706"},onMouseLeave:c=>{c.currentTarget.style.borderColor="var(--border-default)",c.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(o.id);const c=await window.agentApi.cronList();be(c)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:c=>{c.currentTarget.style.borderColor="#22c55e",c.currentTarget.style.color="#22c55e"},onMouseLeave:c=>{c.currentTarget.style.borderColor="var(--border-default)",c.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(o.id);const c=await window.agentApi.cronList();be(c)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:c=>{c.currentTarget.style.borderColor="var(--danger)",c.currentTarget.style.color="var(--danger)"},onMouseLeave:c=>{c.currentTarget.style.borderColor="var(--border-default)",c.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},o.id))]}),rs.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:rs.map((o,c)=>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:()=>bl(c),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:"✕"})]},c))}),lr.length>0&&(()=>{const o=tt.find(p=>p.id===ft),c=!fe&&(!o||!Vs(o.modelId));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[c&&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:lr.map((p,m)=>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":`预览待发送图片 ${m+1}`,onClick:()=>un({src:p,alt:`待发送图片 ${m+1}`}),children:e.jsx("img",{src:p,alt:`待发送图片 ${m+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":`删除待发送图片 ${m+1}`,onClick:()=>jl(m),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:"✕"})]},m))})]})})(),(we.active||we.queued.length>0)&&e.jsxs("div",{className:"goal-queue","aria-label":"目标队列",children:[e.jsxs("div",{className:"goal-queue__header",children:[e.jsx(Ys,{size:14,strokeWidth:1.9,"aria-hidden":"true"}),e.jsx("span",{children:"目标"}),e.jsx("span",{className:"goal-queue__count",children:we.queued.length+(we.active?1:0)})]}),we.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:we.active.objective,children:we.active.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{si(we.active.id)},title:"停止当前目标","aria-label":"停止当前目标",children:e.jsx(bs,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]}),we.queued.map((o,c)=>e.jsxs("div",{className:`goal-queue__row is-queued${dn===o.id?" is-dragging":""}`,draggable:!0,onDragStart:()=>He(o.id),onDragEnd:()=>He(null),onDragOver:p=>p.preventDefault(),onDrop:()=>{Nl(o.id)},children:[e.jsx(bi,{className:"goal-queue__grip",size:14,strokeWidth:1.8,"aria-hidden":"true"}),e.jsxs("span",{className:"goal-queue__state",children:["#",c+1]}),e.jsx("span",{className:"goal-queue__objective",title:o.objective,children:o.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{si(o.id)},title:"移出目标队列","aria-label":"移出目标队列",children:e.jsx(bs,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]},o.id))]}),(()=>{const o=y.filter(c=>c.isQueued);return o.length===0?null:e.jsx("div",{className:"queued-message-list",children:o.map(c=>{const p=c,m=ot===c.id,M=p.content.length>80?p.content.slice(0,80)+"…":p.content;return e.jsxs("div",{className:`queued-message-row${dt===c.id?" is-dragging":""}`,"data-queued-message-id":c.id,onDragOver:k=>{!dt||dt===c.id||(k.preventDefault(),k.dataTransfer.dropEffect="move")},onDrop:k=>{k.preventDefault(),dt&&Gs(dt,c.id),Ct(null)},children:[e.jsx("button",{type:"button",className:"queued-message-grip",draggable:!m,"aria-label":"拖动调整排队顺序",title:"拖动调整顺序",onDragStart:k=>{Ct(c.id),k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",c.id)},onDragEnd:()=>Ct(null),onKeyDown:k=>{(k.key==="ArrowUp"||k.key==="ArrowDown")&&(k.preventDefault(),El(c.id,k.key==="ArrowUp"?-1:1))},onPointerDown:k=>{k.pointerType==="mouse"||m||(Tn.current={id:c.id,pointerId:k.pointerId},k.currentTarget.setPointerCapture(k.pointerId),Ct(c.id))},onPointerMove:k=>{var O;const H=Tn.current;if(!H||H.pointerId!==k.pointerId)return;k.preventDefault();const N=(O=document.elementFromPoint(k.clientX,k.clientY))==null?void 0:O.closest("[data-queued-message-id]"),V=N==null?void 0:N.dataset.queuedMessageId;V&&V!==H.id&&Gs(H.id,V)},onPointerUp:k=>{var H;((H=Tn.current)==null?void 0:H.pointerId)===k.pointerId&&(Tn.current=null,Ct(null))},onPointerCancel:()=>{Tn.current=null,Ct(null)},children:e.jsx(bi,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsxs("div",{className:"queued-message-content",children:[p.agentName&&e.jsxs("span",{className:"queued-message-agent",children:["@",p.agentName]}),m?e.jsx("input",{autoFocus:!0,className:"queued-message-edit-input",value:Oe,onChange:k=>Rn(k.target.value),onKeyDown:k=>{k.key==="Enter"&&!k.nativeEvent.isComposing?(k.preventDefault(),ri(c.id)):k.key==="Escape"&&(k.preventDefault(),Ks())},"aria-label":"编辑排队消息内容"}):e.jsx("span",{className:"queued-message-text",title:p.content,children:M})]}),e.jsxs("div",{className:"queued-message-actions",children:[Ft&&e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--accent",onClick:()=>void ni(c.id),title:"引导到当前对话","aria-label":"引导排队消息到当前对话",children:e.jsx(ql,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>void Tl(c.id),title:es===c.id?"已复制":"复制","aria-label":"复制排队消息",children:es===c.id?e.jsx(Qr,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Js,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>m?ri(c.id):Rl(c.id),disabled:m&&!Oe.trim(),title:m?"保存":"编辑","aria-label":m?"保存排队消息":"编辑排队消息",children:m?e.jsx(Qr,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(ha,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--danger",onClick:()=>Ml(c.id),title:"删除","aria-label":"删除排队消息",children:e.jsx(bs,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]})]},c.id)})})})(),e.jsx("div",{ref:Fs,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:$o,type:"file",multiple:!0,style:{display:"none"},onChange:ml}),Lr.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:Lr.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:()=>fl(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:Wr,rows:3,value:qe,onChange:o=>Ko(o.target.value),onBlur:()=>setTimeout(()=>{_n(null),Wn(null)},120),onKeyDown:xl,placeholder:Sn?Et==="incompatible"?"Codex 版本不兼容":"正在验证会话兼容性":In?"原客户端使用中,当前只读":Xr?Nt?"输入要持续推进的目标":rt?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!Cn}),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":ts,onClick:()=>rr(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"})})}),ts&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var o;rr(!1),(o=$o.current)==null||o.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{rr(!1),cl()},children:"语音输入"})]})]}),e.jsx("button",{type:"button",className:`web-native-runtime-status goal-mode-toggle${Nt?" is-active":""}`,"aria-pressed":Nt,"aria-label":Nt?"关闭目标模式":"开启目标模式",title:Nt?"目标模式已开启":"目标模式",onClick:()=>Ie(o=>!o),children:e.jsx(Ys,{size:18,strokeWidth:1.9,"aria-hidden":"true"})}),e.jsxs("div",{className:"web-native-permission-wrap",ref:ir,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${At}`,"aria-label":`会话权限:${(gi=ys.find(o=>o.value===At))==null?void 0:gi.label}`,"aria-haspopup":"menu","aria-expanded":Mn,title:`会话权限:${(hi=ys.find(o=>o.value===At))==null?void 0:hi.label}`,disabled:!U||it,onClick:()=>Vt(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"})]})}),Mn&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:ys.map(o=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":At===o.value,className:At===o.value?"is-active":"",onClick:()=>{Sl(o.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:At===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))})]}),fe&&(x==null?void 0:x.controller)==="web"&&typeof((xi=window.agentApi)==null?void 0:xi.handoffSession)=="function"&&e.jsx("button",{type:"button",className:"web-native-runtime-status",onClick:()=>{Il()},title:"交接到 Desktop",children:"交接到 Desktop"}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Wd,{usage:U?Te[U]:void 0,contextWindowK:Sr,compact:!0})}),e.jsx("label",{className:`web-native-model-control${fe?" web-native-model-control--native":""}`,title:"切换模型",children:fe&&vs(pe)?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"web-native-model-agent",title:`${Gi[pe]} 会话`,children:[e.jsx(Ro,{agentType:pe,size:14}),e.jsx("span",{className:"web-native-model-agent-name",children:Gi[pe]})]}),wt&&e.jsxs("select",{"aria-label":"当前模型",title:"切换模型",value:Rr,onChange:o=>{Zn({model:o.target.value?jc(o.target.value):void 0})},children:[e.jsx("option",{value:"",children:"默认模型"}),sn.map(o=>e.jsx("option",{value:o.key,children:o.label},o.key)),on.length>0&&e.jsx("optgroup",{label:"设置里的模型",children:on.map(o=>e.jsx("option",{value:o.key,children:o.label},o.key))})]})]}):e.jsx("select",{"aria-label":"当前模型",value:ft,disabled:tt.length===0,onChange:o=>{Xt(o.target.value)},children:tt.length===0?e.jsx("option",{value:"",children:"未配置模型"}):tt.map(o=>e.jsx("option",{value:o.id,children:o.name||o.modelId},o.id))})}),ln?e.jsx("button",{type:"button",onClick:ti,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"})})}):fe&&an.length>0?e.jsxs("div",{className:"web-native-effort-wrap",ref:Ar,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":kn,"aria-label":`推理强度:${nt?lo[nt]:"默认"}`,title:`推理强度:${nt?lo[nt]:"默认"}(点击切换)`,onClick:()=>ct(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"})]})}),kn&&e.jsxs("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:[e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":!nt,className:nt?void 0:"is-active",onClick:()=>{Zn({reasoningEffort:void 0}),ct(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:nt?"":"✓"}),"默认"]}),an.map(o=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":nt===o,className:nt===o?"is-active":void 0,onClick:()=>{Zn({reasoningEffort:o}),ct(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:nt===o?"✓":""}),lo[o]]},o))]})]}):fe?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:or,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":cn,"aria-label":`推理强度:${Ki[Pe]}`,title:`推理强度:${Ki[Pe]}(点击切换)`,onClick:()=>sr(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"})]})}),cn&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:Qa.map(o=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Pe===o.value,className:Pe===o.value?"is-active":void 0,onClick:()=>{en("reasoningEffort",o.value),Dt(),sr(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Pe===o.value?"✓":""}),o.label]},o.value))})]}),e.jsx("button",{type:"button",onClick:oi,disabled:!Cn||cr>0||!qe.trim(),className:"web-native-send-button","aria-label":rt?"排队发送":"发送",title:rt?"排队发送":"发送",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 发送",Nt?"目标":rt?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",Ho?" · 🎤 正在聆听…":""]})]}),e.jsx(qd,{image:Ws,onClose:()=>un(null)}),fn&&Pr!==null&&Qo.length>0&&Jt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-fn.top+8,left:fn.left,width:fn.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:"智能体"}),Qo.map(o=>e.jsxs("button",{onMouseDown:c=>{c.preventDefault(),pl(o)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:c=>{c.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:c=>{c.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),fn&&zn!==null&&Hs.length>0&&Jt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-fn.top+8,left:fn.left,width:fn.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:["技能 (",Hs.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:Hs.map(o=>e.jsxs("button",{onMouseDown:c=>{c.preventDefault(),gl(o)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:c=>{c.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:c=>{c.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 co(t,n,r="auto"){const s=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=t.scrollTop+i.top-s.top-Math.max(0,(t.clientHeight-i.height)/2);t.scrollTo({top:Math.max(0,a),behavior:r})}function uo({status:t,isRunning:n,needsInput:r}){return t==="failed"||t==="error"?"error":n?r?"needs-input":"running":"completed"}const po={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function Ka(t,n){return t.map((r,s)=>({session:r,index:s})).sort((r,s)=>n(r.session,s.session)||r.index-s.index).map(({session:r})=>r)}function Lo(t){return Ka(t,(n,r)=>r.created.localeCompare(n.created))}function ku(t,n){return Ka(Lo(t),(r,s)=>Number(n(s))-Number(n(r)))}const Ji={projectId:null,sessionId:null};function Io(t){return typeof t=="string"&&t.trim()?t.trim():null}function Yi(t){return{projectId:Io(t),sessionId:null}}function fo(t,n){return{projectId:Io(t),sessionId:Io(n)}}function Su(t){return t.agentType==="customer-agent"?`确定永久删除会话“${t.title}”吗?此操作不可恢复。`:t.agentType==="codex"?`确定归档 Codex 会话“${t.title}”并从 AgentRoam 中移除吗?可在 Codex 的已归档会话中恢复。`:`确定从 AgentRoam 中移除会话“${t.title}”吗?原生客户端中的历史记录会保留。`}function Iu(t,n){const r=new Set(n);return{...t,selectedSessionId:t.selectedSessionId&&r.has(t.selectedSessionId)?null:t.selectedSessionId,sessions:Object.fromEntries(Object.entries(t.sessions).map(([s,i])=>[s,{...i,data:i.data.filter(a=>!r.has(a.id))}]))}}function Cu(t,n){const r=new Set(n);let s=!1;const i=Object.fromEntries(Object.entries(t).map(([a,l])=>{const u=l.filter(h=>!r.has(h.id));return u.length!==l.length&&(s=!0),[a,u.length===l.length?l:u]}));return s?i:t}function Au(t,n,r,s){const i=[s,...(n[s]??[]).map(u=>u.id)],a=new Set(i),l=Object.fromEntries(Object.entries(n).flatMap(([u,h])=>{if(a.has(u))return[];const g=h.filter(x=>!a.has(x.id));return[[u,g.length===h.length?h:g]]}));return{sessionsByProject:Cu(t,i),childSessionsByParent:l,otherLocalSessions:r.filter(u=>!a.has(u.id)),removedIds:i}}const Ru=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Xi={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function ea(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function Tu(){const{maxIterations:t,contextWindow:n,isConfigured:r,profiles:s,activeProfileId:i,setField:a,loadFromSystem:l,saveToSystem:u,addProfile:h,updateProfile:g,deleteProfile:x,switchActiveProfile:j}=Ss(),[b,w]=d.useState(null),[S,R]=d.useState("success"),[E,F]=d.useState(null),[v,y]=d.useState(!1),[B,$]=d.useState(ea());d.useEffect(()=>{l()},[]);const A=()=>{y(!0),F(null),$(ea())},C=K=>{y(!1),F(K.id),$({name:K.name,provider:K.provider,modelId:K.modelId,apiKey:K.apiKey==="managed"?"":K.apiKey,baseUrl:K.baseUrl})},W=()=>{F(null),y(!1)},z=async()=>{if(!B.name.trim()||!B.apiKey.trim()||!B.modelId.trim()){w("名称、API Key 和模型 ID 为必填项"),R("error");return}v?h(B):E&&g(E,B),F(null),y(!1),w(null),setTimeout(()=>u(),0)},q=async K=>{x(K),setTimeout(()=>u(),0)},le=async K=>{await j(K),w("已切换模型"),R("success"),setTimeout(()=>w(null),1500)},X=async()=>{w(null);try{await u(),w("设置保存成功"),R("success")}catch(K){w(K instanceof Error?K.message:"保存失败"),R("error")}},se=v||E!==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:Eu,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(K=>{const Te=K.id===i,Me=K.id===E;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${Te?"var(--accent)":"var(--border-default)"}`,background:Te?"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:Te?"var(--accent)":"var(--bg-deep)",color:Te?"#fff":"var(--text-muted)",flexShrink:0},children:K.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:K.name||K.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[K.modelId," ",K.baseUrl?`· ${K.baseUrl}`:""]})]}),Te&&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:[!Te&&e.jsx("button",{onClick:()=>le(K.id),style:go,children:"切换"}),e.jsx("button",{onClick:()=>Me?W():C(K),style:go,children:Me?"收起":"编辑"}),e.jsx("button",{onClick:()=>q(K.id),style:{...go,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),Me&&e.jsx(ta,{draft:B,setDraft:$,onSave:z,onCancel:W})]},K.id)}),v&&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(ta,{draft:B,setDraft:$,onSave:z,onCancel:W})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},children:"常规"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Fn,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:K=>a("maxIterations",parseInt(K.target.value)||10),min:1,max:50,style:On})}),e.jsx(Fn,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:n??100,onChange:K=>a("contextWindow",parseInt(K.target.value)||100),min:8,max:2e3,style:On})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:X,style:Ga,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:r?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:r?"var(--success)":"var(--text-muted)",border:`1px solid ${r?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:r?"● 已连接":"○ 未配置"})]}),b&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:S==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:S==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:S==="success"?"var(--success)":"var(--danger)",fontSize:13},children:b})]})}function ta({draft:t,setDraft:n,onSave:r,onCancel:s}){const i=(a,l)=>n(u=>{const h={...u,[a]:l};return a==="provider"&&!u.modelId&&(h.modelId=Xi[l]??""),h});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(Fn,{label:"名称",children:e.jsx("input",{value:t.name,onChange:a=>i("name",a.target.value),placeholder:"我的 Claude",style:On})}),e.jsx(Fn,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:a=>{i("provider",a.target.value),i("modelId",Xi[a.target.value]??"")},style:On,children:Ru.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})})]}),e.jsx(Fn,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:a=>i("modelId",a.target.value),placeholder:"claude-sonnet-4-6",style:On})}),e.jsx(Fn,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:a=>i("apiKey",a.target.value),placeholder:"sk-...",style:On})}),e.jsx(Fn,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:a=>i("baseUrl",a.target.value),placeholder:"https://api.anthropic.com",style:On})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:r,style:Ga,children:"保存"}),e.jsx("button",{onClick:s,style:Mu,children:"取消"})]})]})}function Fn({label:t,children:n}){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}),n]})}const On={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"},Ga={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)"},Mu={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)"},Eu={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)"},go={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)"},ho={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function Nu(){const[t,n]=d.useState([]),[r,s]=d.useState("stdio"),[i,a]=d.useState(ho),[l,u]=d.useState(!1),[h,g]=d.useState({id:!1,command:!1,url:!1}),[x,j]=d.useState({}),[b,w]=d.useState({}),[S,R]=d.useState(new Set),[E,F]=d.useState(null),[v,y]=d.useState(""),[B,$]=d.useState(!1),A=async T=>{var me;if(!((me=window.agentApi)!=null&&me.mcpProbe))return;R(ce=>new Set([...ce,T.id])),w(ce=>{const ke={...ce};return delete ke[T.id],ke});const Q=new Promise((ce,ke)=>setTimeout(()=>ke(new Error("连接超时(15s)")),15e3));try{const ce=await Promise.race([window.agentApi.mcpProbe(T),Q]);j(ke=>({...ke,[T.id]:ce}))}catch(ce){const ke=ce instanceof Error?ce.message:String(ce);console.warn(`[MCP] probe failed for ${T.id}:`,ke),j(Ee=>{const Ge={...Ee};return delete Ge[T.id],Ge}),w(Ee=>({...Ee,[T.id]:ke})),(T.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(ke))&&(y(""),F({server:T}))}finally{R(ce=>{const ke=new Set(ce);return ke.delete(T.id),ke})}};d.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(T=>{n(T),T.filter(Q=>Q.enabled!==!1).forEach(Q=>A(Q))}).catch(console.error)},[]);const[C,W]=d.useState(""),[z,q]=d.useState(""),[le,X]=d.useState(!1),se=async()=>{q("");let T;try{T=JSON.parse(C.trim());const Q=T.mcpServers??T,me=Object.entries(Q);if(me.length===0){q("未找到任何服务器");return}X(!0);const ce=[];for(const[Ee,Ge]of me){const be=Ge,we=be.name||Ee,Ze=be.disabled!==!0;let Tt;if(be.url||be.type==="streamableHttp"||be.type==="sse"){const tt=be.type==="sse"?"sse":"streamableHttp";Tt={id:Ee,name:we,transport:tt,url:be.url,headers:be.headers??{},env:be.env??{},enabled:Ze}}else Tt={id:Ee,name:we,transport:"stdio",command:be.command,args:be.args??[],env:be.env??{},enabled:Ze};await window.agentApi.mcpSave(Tt),ce.push(Tt)}const ke=await window.agentApi.mcpList();n(ke),W(""),ce.filter(Ee=>Ee.enabled!==!1).forEach(Ee=>A(Ee))}catch(Q){q(Q instanceof Error?Q.message:"JSON 解析失败")}finally{X(!1)}},K=()=>i.id.trim()!==""&&i.command.trim()!=="",Te=()=>i.id.trim()!==""&&i.url.trim()!=="",Me=T=>{const Q={};for(const me of T.split(`
|
|
274
|
+
`)){const ce=me.indexOf(":");if(ce<1)continue;const ke=me.slice(0,ce).trim(),Ee=me.slice(ce+1).trim();ke&&(Q[ke]=Ee)}return Q},Vn=async()=>{if(g({id:!0,command:!0,url:!0}),!(r==="stdio"&&!K())&&!((r==="sse"||r==="streamableHttp")&&!Te())){u(!0);try{const T=r==="sse"||r==="streamableHttp"?Me(i.headersRaw):{},Q=r==="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:r,url:i.url,headers:T,enabled:!0};await window.agentApi.mcpSave(Q);const me=await window.agentApi.mcpList();n(me),a(ho),g({id:!1,command:!1,url:!1}),A(Q)}catch(T){console.error("Failed to save MCP server",T)}finally{u(!1)}}},Le=async T=>{await window.agentApi.mcpDelete(T),n(t.filter(Q=>Q.id!==T))},Qn=async(T,Q)=>{await window.agentApi.mcpSetEnabled(T,Q),n(t.map(me=>me.id===T?{...me,enabled:Q}:me))},Wt=async()=>{if(!(!E||!v.trim())){$(!0);try{const T=E.server.transport==="streamableHttp"?{...E.server,headers:{...E.server.headers??{},Authorization:`Bearer ${v.trim()}`}}:{...E.server,env:{...E.server.env??{},Authorization:`Bearer ${v.trim()}`}};await window.agentApi.mcpSave(T);const Q=await window.agentApi.mcpList();n(Q),F(null),y("");const me=Q.find(ce=>ce.id===T.id)??T;A(me)}finally{$(!1)}}},Lt=T=>T==="stdio"?"本地":T==="streamableHttp"?"HTTP":"SSE",kr=T=>T==="stdio"?"#68d391":T==="streamableHttp"?"#f6ad55":"#63b3ed",pt=T=>T==="stdio"?"rgba(154,230,180,0.15)":T==="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(T=>e.jsx("button",{onClick:()=>{s(T),g({id:!1,command:!1,url:!1}),a(Q=>({...ho,id:Q.id,name:Q.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:r===T?"var(--accent)":"transparent",color:r===T?"var(--text-inverse)":"var(--text-muted)"},children:T==="stdio"?"本地 stdio":T==="sse"?"远程 SSE":"HTTP"},T))})]}),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:T=>a(Q=>({...Q,id:T.target.value})),onBlur:()=>g(T=>({...T,id:!0})),placeholder:"服务器 ID *",style:{...yn,...h.id&&!i.id?xo:{}}}),h.id&&!i.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.name,onChange:T=>a(Q=>({...Q,name:T.target.value})),placeholder:"显示名称",style:{...yn,flex:1}})]}),r==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.command,onChange:T=>a(Q=>({...Q,command:T.target.value})),onBlur:()=>g(T=>({...T,command:!0})),placeholder:"命令(如 npx)*",style:{...yn,...h.command&&!i.command?xo:{}}}),h.command&&!i.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.args,onChange:T=>a(Q=>({...Q,args:T.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...yn,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:T=>a(Q=>({...Q,url:T.target.value})),onBlur:()=>g(T=>({...T,url:!0})),placeholder:r==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...yn,...h.url&&!i.url?xo:{}}}),h.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:T=>a(Q=>({...Q,headersRaw:T.target.value})),placeholder:`access_token: abc123
|
|
275
|
+
Authorization: Bearer sk-...`,rows:3,style:{...yn,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:Vn,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:T=>{W(T.target.value),q("")},placeholder:`{
|
|
276
|
+
"my-server": {
|
|
277
|
+
"command": "npx",
|
|
278
|
+
"args": ["-y", "some-mcp"]
|
|
279
|
+
}
|
|
280
|
+
}`,rows:5,style:{...yn,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),z&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:z}),e.jsx("button",{onClick:se,disabled:!C.trim()||le,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:C.trim()&&!le?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:C.trim()&&!le?1:.5},children:le?"导入中…":"导入"})]}),t.filter(T=>T.transport===r).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",r==="stdio"?"本地 stdio":r==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(T=>T.transport===r).map(T=>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:T.name||T.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:pt(T.transport),color:kr(T.transport),fontWeight:600},children:Lt(T.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[T.transport==="stdio"?`${T.command} ${(T.args??[]).join(" ")}`:T.url,T.transport!=="stdio"&&T.headers&&Object.keys(T.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(T.headers).length," 个请求头"]})]}),S.has(T.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"}}),"探测工具中…"]}):b[T.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:b[T.id]}),T.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(b[T.id])?e.jsx("button",{onClick:()=>{y(""),F({server:T})},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(T),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[T.id]&&x[T.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:x[T.id].map(Q=>e.jsx("span",{title:Q.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:Q.name},Q.name))}):x[T.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:T.enabled!==!1,onChange:Q=>Qn(T.id,Q.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Le(T.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:Q=>{Q.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:Q=>{Q.currentTarget.style.background="transparent"},children:"移除"})]})]},T.id))}),E&&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:T=>{T.target===T.currentTarget&&F(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:E.server.name||E.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:v,onChange:T=>y(T.target.value),onKeyDown:T=>{T.key==="Enter"&&Wt(),T.key==="Escape"&&F(null)},placeholder:"sk-… 或 Bearer token",style:{...yn,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>F(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:!v.trim()||B,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:v.trim()&&!B?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:v.trim()&&!B?1:.5},children:B?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const yn={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)"},xo={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function _u(){const[t,n]=d.useState([]),[r,s]=d.useState(""),[i,a]=d.useState(null),[l,u]=d.useState(!1),[h,g]=d.useState(""),[x,j]=d.useState(""),[b,w]=d.useState("user"),[S,R]=d.useState(""),[E,F]=d.useState(null),[v,y]=d.useState("success"),B=async()=>{if(window.agentApi){const W=await window.agentApi.listMemories();n(W)}};d.useEffect(()=>{B()},[]);const $=async()=>{if(!r.trim()){B();return}if(window.agentApi){const W=await window.agentApi.searchMemories(r);n(W.map(z=>z.entry))}},A=async()=>{if(!(!h.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:h.trim(),description:x,type:b,content:S,created:(i==null?void 0:i.created)??new Date().toISOString(),updated:new Date().toISOString()}),u(!1),a(null),g(""),j(""),R(""),w("user"),F("保存成功"),y("success"),await B()}catch(W){F(W instanceof Error?W.message:"保存失败"),y("error")}},C=W=>{a(W),g(W.name),j(W.description),w(W.type),R(W.content),u(!0)};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,letterSpacing:"-0.02em"},children:"记忆"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginTop:4},children:"跨会话的持久化知识库。"})]}),e.jsx("button",{onClick:()=>{u(!0),a(null),g(""),j(""),R(""),w("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:r,onChange:W=>s(W.target.value),onKeyDown:W=>W.key==="Enter"&&$(),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:$,style:na,children:"搜索"})]}),E&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:v==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:v==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:v==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:E}),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:h,onChange:W=>g(W.target.value),placeholder:"名称",style:{...xs,marginBottom:10},disabled:!!i}),e.jsx("input",{value:x,onChange:W=>j(W.target.value),placeholder:"描述",style:{...xs,marginBottom:10}}),e.jsxs("select",{value:b,onChange:W=>w(W.target.value),style:{...xs,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:S,onChange:W=>R(W.target.value),placeholder:"内容",rows:5,style:{...xs,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,style:{padding:"9px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--success)",color:"#000",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"保存"}),e.jsx("button",{onClick:()=>u(!1),style:na,children:"取消"})]})]}),t.map(W=>e.jsxs("div",{style:{padding:"14px 16px",marginBottom:8,background:"var(--bg-glass)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",transition:"border-color 0.2s"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{color:"var(--text-primary)",fontWeight:600,fontSize:14},children:W.name}),e.jsx("span",{style:{fontSize:10,padding:"2px 8px",borderRadius:10,background:"rgba(255,255,255,0.04)",color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:500},children:W.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>C(W),style:ra,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(W.name),F("删除成功"),y("success"),await B()}catch(z){F(z instanceof Error?z.message:"删除失败"),y("error")}},style:{...ra,color:"var(--danger)"},children:"删除"})]})]}),W.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:W.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[W.content.slice(0,180),W.content.length>180?"…":""]})]},W.name)),t.length===0&&!l&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const xs={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"},na={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)"},ra={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},zu=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function Wu(){const[t,n]=d.useState([]),[r,s]=d.useState(null),[i,a]=d.useState(!1),[l,u]=d.useState(null),[h,g]=d.useState("success"),[x,j]=d.useState(""),b=(C,W="success")=>{u(C),g(W),setTimeout(()=>u(null),3e3)},w=async()=>{if(!window.agentApi)return;const C=await window.agentApi.listSkills();n(C)};d.useEffect(()=>{w()},[]);const S=C=>{s({...C}),j((C.triggers??[]).join(", ")),a(!1)},R=()=>{s(zu()),j(""),a(!0)},E=()=>{s(null),a(!1)},F=async()=>{if(!r||!window.agentApi)return;if(!r.name.trim()){b("名称不能为空","error");return}const C=x.split(",").map(W=>W.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:r.name.trim(),description:r.description,triggers:C,prompt:r.prompt,filePath:r.filePath??""}),b(i?"技能已创建":"技能已保存"),s(null),await w()}catch(W){b(W instanceof Error?W.message:"保存失败","error")}},v=async C=>{if(window.agentApi)try{await window.agentApi.deleteSkill(C),b("已删除"),(r==null?void 0:r.name)===C&&s(null),await w()}catch(W){b(W instanceof Error?W.message:"删除失败","error")}},y=async C=>{if(!window.agentApi)return;const W=!C.enabled;await window.agentApi.setSkillEnabled(C.name,W),await w()},B=async()=>{if(window.agentApi)try{const C=await window.agentApi.importSkill();if(!C)return;b(`已导入技能「${C.name}」,本次会话立即生效`),await w()}catch(C){b(C instanceof Error?C.message:"导入失败","error")}},$={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:R,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:h==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:h==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:h==="success"?"var(--success)":"var(--danger)",fontSize:13},children:l}),r&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:i?"新建技能":`编辑:${r.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:$,value:r.name,disabled:!i,onChange:C=>s({...r,name:C.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"描述"}),e.jsx("input",{style:$,value:r.description,onChange:C=>s({...r,description:C.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"触发词(逗号分隔)"}),e.jsx("input",{style:$,value:x,onChange:C=>j(C.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"提示词"}),e.jsx("textarea",{style:{...$,minHeight:120,resize:"vertical"},value:r.prompt,onChange:C=>s({...r,prompt:C.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:F,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:E,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!r&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(C=>{var W;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:"14px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-glass)",opacity:C.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>y(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}),((W=C.triggers)==null?void 0:W.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:()=>S(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:()=>v(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 ms=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function Za(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function Lu(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:Za(),maxIterations:0,isDefault:!1}}const Co={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"},Kr={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},wn={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"},vn={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function Pu({ph:t,onChange:n,onDelete:r}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:wn,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>n({...t,key:s.target.value})}),e.jsx("input",{style:wn,placeholder:"说明",value:t.description,onChange:s=>n({...t,description:s.target.value})}),e.jsx("input",{style:wn,placeholder:"默认值",value:t.defaultValue,onChange:s=>n({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:r,style:{...Kr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function sa({initial:t,activeAgentId:n,onSave:r,onCancel:s}){const{profiles:i}=Ss(),[a,l]=d.useState([]),[u,h]=d.useState([]),[g,x]=d.useState({...Lu(),...t,capabilities:{...Za(),...t.capabilities??{}}}),[j,b]=d.useState(null),[w,S]=d.useState(!1);d.useEffect(()=>{var z,q;window.agentApi&&(window.agentApi.listSkills().then(le=>{l(le.filter(X=>X.name))}),(q=(z=window.agentApi).listMCPServers)==null||q.call(z).then(le=>{h(le??[])}).catch(()=>{}))},[]);const R=z=>x(q=>({...q,capabilities:{...q.capabilities,...z}})),E=z=>{const q=g.capabilities.enabledTools;if(q.length===0){const le=ms.map(X=>X.name).filter(X=>X!==z);R({enabledTools:le})}else if(q.includes(z)){const le=q.filter(X=>X!==z);R({enabledTools:le})}else{const le=[...q,z];le.length===ms.length?R({enabledTools:[]}):R({enabledTools:le})}},F=z=>{const q=g.capabilities.enabledSkills;R({enabledSkills:q.includes(z)?q.filter(le=>le!==z):[...q,z]})},v=z=>{const q=g.capabilities.enabledMCPServers;R({enabledMCPServers:q.includes(z)?q.filter(le=>le!==z):[...q,z]})},y=()=>x(z=>({...z,contextPlaceholders:[...z.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),B=(z,q)=>x(le=>{const X=[...le.contextPlaceholders];return X[z]=q,{...le,contextPlaceholders:X}}),$=z=>x(q=>({...q,contextPlaceholders:q.contextPlaceholders.filter((le,X)=>X!==z)})),A=async()=>{if(!g.name.trim()){b("名称为必填项");return}S(!0);try{await r(g)}catch(z){b(z instanceof Error?z.message:"保存失败")}finally{S(!1)}},C=z=>g.capabilities.enabledTools.length===0||g.capabilities.enabledTools.includes(z),W={fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:10,marginTop:22,paddingBottom:5,borderBottom:"1px solid var(--border-subtle)"};return e.jsxs("div",{style:{padding:"24px 28px",background:"transparent",borderTop:"1px solid var(--border-subtle)"},children:[j&&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:j}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:vn,children:"名称 *"}),e.jsx("input",{style:wn,value:g.name,onChange:z=>x(q=>({...q,name:z.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:vn,children:"描述"}),e.jsx("input",{style:wn,value:g.description,onChange:z=>x(q=>({...q,description:z.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:{...vn,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:g.systemPrompt,onChange:z=>x(q=>({...q,systemPrompt:z.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
|
|
281
|
+
|
|
282
|
+
当前项目:{{project_name}}`,rows:6,style:{...wn,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:W,children:"上下文占位符"}),g.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(z=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:z},z))}),g.contextPlaceholders.map((z,q)=>e.jsx(Pu,{ph:z,onChange:le=>B(q,le),onDelete:()=>$(q)},q))]}),e.jsx("button",{onClick:y,style:{...Kr,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:W,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:vn,children:"模型"}),e.jsxs("select",{value:g.capabilities.profileId,onChange:z=>R({profileId:z.target.value}),style:{...wn,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),i.map(z=>e.jsxs("option",{value:z.id,children:[z.name||z.modelId," (",z.provider,")"]},z.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:vn,children:["内置工具 ",g.capabilities.enabledTools.length===0?"(全部启用)":`(${g.capabilities.enabledTools.length}/${ms.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:ms.map(z=>{const q=C(z.name);return e.jsx("button",{onClick:()=>E(z.name),style:{padding:"4px 10px",borderRadius:20,border:q?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:q?"var(--accent-dim)":"transparent",color:q?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:z.label},z.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:vn,children:["技能 ",g.capabilities.enabledSkills.length===0?"(全部)":`(${g.capabilities.enabledSkills.length}/${a.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(z=>{const q=g.capabilities.enabledSkills.length===0||g.capabilities.enabledSkills.includes(z.name);return e.jsx("button",{onClick:()=>F(z.name),title:z.description,style:{padding:"4px 10px",borderRadius:20,border:q?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:q?"var(--accent-dim)":"transparent",color:q?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:z.name},z.name)})})]}),u.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:vn,children:["MCP 服务器 ",g.capabilities.enabledMCPServers.length===0?"(全部)":`(${g.capabilities.enabledMCPServers.length}/${u.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:u.map(z=>{const q=g.capabilities.enabledMCPServers.length===0||g.capabilities.enabledMCPServers.includes(z.id);return e.jsx("button",{onClick:()=>v(z.id),style:{padding:"4px 10px",borderRadius:20,border:q?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:q?"var(--accent-dim)":"transparent",color:q?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:z.name},z.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:vn,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:wn,value:g.maxIterations,min:0,max:100,onChange:z=>x(q=>({...q,maxIterations:Number(z.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:g.isDefault,onChange:z=>x(q=>({...q,isDefault:z.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:w,style:{...Co,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:w?.6:1},children:w?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:Co,children:"取消"})]})]})}function Du(){const[t,n]=d.useState([]),[r,s]=d.useState([]),[i,a]=d.useState(null),[l,u]=d.useState(!1),[h,g]=d.useState(null),[x,j]=d.useState("success"),b=(v,y="success")=>{g(v),j(y),setTimeout(()=>g(null),2e3)},w=async()=>{if(!window.agentApi)return;const v=await window.agentApi.listAgentDefs();n(v);const y=await window.agentApi.getSettings();s(y.activeAgentIds??[])};d.useEffect(()=>{w()},[]);const S=async v=>{await window.agentApi.createAgentDef(v),u(!1),b("智能体已创建"),await w()},R=async(v,y)=>{await window.agentApi.updateAgentDef(v,y),a(null),b("保存成功"),await w()},E=async v=>{await window.agentApi.deleteAgentDef(v),i===v&&a(null),b("已删除"),await w()},F=async v=>{const B=(await window.agentApi.setActiveAgentDef(v)).activeAgentIds??[];s(B),b(B.includes(v)?"已激活":"已取消激活")};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:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),h&&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:h}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{u(!0),a(null)},style:{...Co,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(sa,{initial:{},activeAgentId:r[0]??"",onSave:S,onCancel:()=>u(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!l&&e.jsx("div",{style:{padding:"28px 20px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无智能体配置,点击「新建智能体」开始创建"}),t.map(v=>{const y=r.includes(v.id),B=v.id===i;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${y?"var(--accent)":"var(--border-default)"}`,background:y?"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:y?"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:y?"#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:v.name}),y&&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:"激活"}),v.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),v.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[v.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:"自定义模型"}),v.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:[v.capabilities.enabledTools.length," 工具"]}),v.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:[v.capabilities.enabledSkills.length," 技能"]}),v.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:[v.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>F(v.id),style:{...Kr,color:y?"var(--accent)":"var(--text-muted)",borderColor:y?"var(--accent)":"var(--border-default)",background:y?"var(--accent-dim)":"transparent"},children:y?"取消激活":"激活"}),e.jsx("button",{onClick:()=>a(B?null:v.id),style:Kr,children:B?"收起":"编辑"}),e.jsx("button",{onClick:()=>E(v.id),style:{...Kr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),B&&e.jsx(sa,{initial:v,activeAgentId:r[0]??"",onSave:$=>R(v.id,$),onCancel:()=>a(null)})]},v.id)})]})]})}const Bu=[{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"}],mo={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function $u(){const[t,n]=d.useState([]),[r,s]=d.useState(mo),[i,a]=d.useState(!1),[l,u]=d.useState(null),[h,g]=d.useState(null),x=async()=>{var v;if((v=window.agentApi)!=null&&v.lspList)try{const y=await window.agentApi.lspList();n(y)}catch(y){console.error("[LSP] load error",y)}};d.useEffect(()=>{x()},[]);const j=v=>{s(y=>({...y,name:v.label,language:v.language,fileTypes:v.fileTypes,command:v.command,args:v.args}))},b=v=>{u(v.id),s({id:v.id,name:v.name,language:v.language,fileTypes:v.fileTypes.join(","),command:v.command,args:v.args.join(" "),envRaw:v.env?Object.entries(v.env).map(([y,B])=>`${y}=${B}`).join(`
|
|
283
|
+
`):""}),g(null)},w=()=>{u(null),s(mo)},S=async()=>{var A;if(!((A=window.agentApi)!=null&&A.lspSave))return;const v=r.name.trim(),y=r.command.trim();if(!v||!y)return;let B;if(r.envRaw.trim()){B={};for(const C of r.envRaw.split(`
|
|
284
|
+
`)){const W=C.indexOf("=");W>0&&(B[C.slice(0,W).trim()]=C.slice(W+1).trim())}}const $={id:l??crypto.randomUUID(),name:v,language:r.language.trim(),fileTypes:r.fileTypes.split(",").map(C=>C.trim()).filter(Boolean),command:y,args:r.args.trim()?r.args.trim().split(/\s+/):[],env:B,enabled:!0};a(!0);try{await window.agentApi.lspSave($),await x(),w()}finally{a(!1)}},R=async v=>{var y;(y=window.agentApi)!=null&&y.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(v),await x())},E=async v=>{var y;(y=window.agentApi)!=null&&y.lspSetEnabled&&(await window.agentApi.lspSetEnabled(v.id,!v.enabled),await x())},F=l!==null;return F&&l===null||!l&&r.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!F&&e.jsx("button",{onClick:()=>{u(""),s(mo)},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&&!F&&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:F?24:0},children:t.map(v=>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:()=>g(h===v.id?null:v.id),children:[e.jsx("div",{onClick:y=>{y.stopPropagation(),E(v)},style:{width:32,height:18,borderRadius:9,background:v.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:v.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:v.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[v.language,v.fileTypes.length>0?` · ${v.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[v.command,v.args.length?" "+v.args.join(" "):""]}),e.jsx("button",{onClick:y=>{y.stopPropagation(),b(v)},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:y=>{y.stopPropagation(),R(v.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:h===v.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),h===v.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:[v.command," ",v.args.join(" ")]})]}),v.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),v.fileTypes.join(", ")]}),v.env&&Object.keys(v.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(v.env).map(([y,B])=>`${y}=${B}`).join(", ")]})]})]},v.id))}),F&&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:Bn,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Bu.map(v=>e.jsx("button",{onClick:()=>j(v),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:v.label},v.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:Bn,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.name,onChange:v=>s(y=>({...y,name:v.target.value})),placeholder:"TypeScript Language Server",style:yr})]}),e.jsxs("div",{children:[e.jsx("label",{style:Bn,children:"语言"}),e.jsx("input",{value:r.language,onChange:v=>s(y=>({...y,language:v.target.value})),placeholder:"typescript",style:yr})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Bn,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:r.fileTypes,onChange:v=>s(y=>({...y,fileTypes:v.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:yr})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:Bn,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.command,onChange:v=>s(y=>({...y,command:v.target.value})),placeholder:"typescript-language-server",style:{...yr,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Bn,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:r.args,onChange:v=>s(y=>({...y,args:v.target.value})),placeholder:"--stdio",style:{...yr,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Bn,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:r.envRaw,onChange:v=>s(y=>({...y,envRaw:v.target.value})),placeholder:`NODE_ENV=production
|
|
285
|
+
TSPROTOCOL_LOG=verbose`,rows:3,style:{...yr,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),r.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void S(),disabled:i||!r.name.trim()||!r.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:i||!r.name.trim()||!r.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:i?"保存中…":"保存"}),e.jsx("button",{onClick:w,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"})]})]})]})}const yr={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"},Bn={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function Fu({trigger:t,heardText:n}){const[r,s]=d.useState(!1);return d.useEffect(()=>{if(t<=0)return;s(!0);const i=setTimeout(()=>s(!1),2400);return()=>clearTimeout(i)},[t]),r?Jt.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:"已唤醒 · 随时待命"}),n&&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:["“",n.slice(0,40),"”"]})]},t),document.body):null}const Ou=[{agentType:"customer-agent",label:"Customer Agent"},{agentType:"codex",label:"Codex"},{agentType:"claude-code",label:"Claude Code"},{agentType:"opencode",label:"OpenCode"}];function Uu({value:t,health:n,onChange:r}){return e.jsx("div",{className:"agent-workspace-switcher",role:"tablist","aria-label":"切换 Agent",children:Ou.map(s=>{const i=n.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:()=>r(s.agentType),children:[e.jsx(Ro,{agentType:s.agentType,size:22}),e.jsx("i",{className:a?"is-unavailable":"","aria-hidden":"true"})]},s.agentType)})})}const bo=264,oa=126;function qu(t){const n=typeof window>"u"?1024:window.innerWidth,r=typeof window>"u"?768:window.innerHeight,s=Math.max(8,Math.min(t.left+t.width-bo,n-bo-8)),i=t.top+t.height+7,a=i+oa<=r-8?i:Math.max(8,t.top-oa-7);return{left:s,top:a,width:bo}}function Hu({message:t,anchor:n,mobile:r,pending:s,onCancel:i,onConfirm:a}){const l=u=>u.stopPropagation();return e.jsx("div",{className:`sidebar-delete-confirmation-layer${r?" 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:r?void 0:qu(n),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 yo({session:t,deleteLabel:n="删除会话",onSelect:r,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:r,"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(Rt,{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(ga,{size:13,"aria-hidden":"true"})}),t.occupiedExternally&&e.jsx("span",{className:"sidebar-session-lock",title:"原客户端正在使用,只读","aria-label":"原客户端正在使用,只读",children:e.jsx(sc,{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 u=l.currentTarget.getBoundingClientRect();s({top:u.top,left:u.left,width:u.width,height:u.height})},title:n,"aria-label":`${n}:${t.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(bs,{size:14,"aria-hidden":"true"})})]})}const Vu=[["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"])]],Qu=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function Ku(t){var i;const n=t.toLocaleLowerCase(),r=Qu.get(n);if(r)return r;if(n.startsWith(".env")||n===".gitignore"||n===".npmrc")return"text";const s=n.includes(".")&&n.split(".").pop()||"";return((i=Vu.find(([,a])=>a.has(s)))==null?void 0:i[0])??"file"}const Gu={folder:{icon:ec,label:"文件夹"},code:{icon:Kl,label:"代码文件"},style:{icon:ic,label:"样式文件"},image:{icon:Gl,label:"图片文件"},video:{icon:Yl,label:"视频文件"},audio:{icon:Ql,label:"音频文件"},markdown:{icon:oc,label:"Markdown 文件"},text:{icon:ks,label:"文本文件"},json:{icon:Zl,label:"JSON 文件"},archive:{icon:Vl,label:"压缩文件"},spreadsheet:{icon:Jl,label:"表格文件"},presentation:{icon:ac,label:"演示文件"},database:{icon:Hl,label:"数据库文件"},file:{icon:Xl,label:"文件"}};function Zu(t,n){return n==="directory"?"folder":Ku(t)}const ia=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function Ju(t,n){const r=ia(t),s=ia(n),a=[{label:r==="/"?"/":r.split("/").filter(Boolean).pop()||r,path:r}];if(s===r)return a;const l=s.slice(r==="/"?1:r.length+1);let u=r;for(const h of l.split("/").filter(Boolean))u=u==="/"?`/${h}`:`${u}/${h}`,a.push({label:h,path:u});return a}function Yu({open:t,onCancel:n,onConfirm:r}){const[s,i]=d.useState([]),[a,l]=d.useState(""),[u,h]=d.useState(""),[g,x]=d.useState([]),[j,b]=d.useState(!1),[w,S]=d.useState(""),[R,E]=d.useState(!1),F=d.useMemo(()=>Ju(a||"/",u||a||"/"),[a,u]),v=async A=>{if(window.agentApi){b(!0),S("");try{const C=await window.agentApi.listProjectDirectories(A);x(C),h(A)}catch(C){S(C instanceof Error?C.message:"无法读取目录")}finally{b(!1)}}};if(d.useEffect(()=>{if(!t||!window.agentApi)return;let A=!1;return b(!0),S(""),window.agentApi.listProjectRoots().then(async C=>{if(A)return;i(C);const W=C[0]??"";l(W),W?await v(W):S("未配置可用的宿主机目录")}).catch(C=>{A||S(C instanceof Error?C.message:"无法读取宿主机目录")}).finally(()=>{A||b(!1)}),()=>{A=!0}},[t]),d.useEffect(()=>{if(!t)return;const A=C=>{C.key==="Escape"&&n()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,n]),!t)return null;const y=A=>{l(A),v(A)},B=()=>{F.length<=1||v(F[F.length-2].path)},$=async()=>{if(!(!u||R)){E(!0),S("");try{await r(u)}catch(A){S(A instanceof Error?A.message:"项目导入失败")}finally{E(!1)}}};return Jt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:A=>{A.target===A.currentTarget&&n()},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:n,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(ya,{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=>y(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:F.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(Fl,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:F.map((A,C)=>e.jsxs("span",{children:[C>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void v(A.path),children:A.label})]},A.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>u&&void v(u),disabled:!u||j,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(xa,{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":j,children:j?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):w?e.jsx("div",{className:"host-project-picker-state is-error",children:w}):g.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):g.map(A=>{const C=Zu(A.name,A.kind),{icon:W,label:z}=Gu[C],q=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${C}`,"aria-hidden":"true",children:e.jsx(W,{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:z,children:q},`${A.name}:${A.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void v(A.path),title:z,children:[q,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:u,children:u}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:n,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!u||j||R,onClick:()=>void $(),children:R?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const Ja="agentroam.agent-workspaces.v2",Xu=2,Ya=["customer-agent","codex","claude-code","opencode"];function aa(){return{version:2,activeAgent:"customer-agent",agents:{}}}function la(){return{workspaces:[],nextCursor:null,watermark:null,expandedWorkspaceIds:[],selectedWorkspaceId:null,selectedSessionId:null,sidebarScrollTop:0,sessions:{}}}function ep(t=localStorage){try{const n=JSON.parse(t.getItem(Ja)??"null");if(!Un(n)||n.version!==Xu)return aa();const r=op(n.activeAgent)?n.activeAgent:"customer-agent",s=Un(n.agents)?n.agents:{},i={};for(const a of Ya){const l=sp(s[a],a);l&&(i[a]=l)}return{version:2,activeAgent:r,agents:i}}catch{return aa()}}function ca(t,n=localStorage){try{n.setItem(Ja,JSON.stringify(t))}catch{}}function tp(t,n,r){const s=new Set(n.data.map(l=>l.workspaceId)),i=r?n.nextCursor?[...n.data,...t.filter(l=>!s.has(l.workspaceId))]:n.data:[...t,...n.data],a=new Set;return i.filter(l=>a.has(l.workspaceId)?!1:(a.add(l.workspaceId),!0))}function np(t,n,r){const s=new Set(n.data.map(l=>l.id)),i=r?n.nextCursor?[...n.data,...t.filter(l=>!s.has(l.id))]:n.data:[...t,...n.data],a=new Set;return i.filter(l=>a.has(l.id)?!1:(a.add(l.id),!0))}function rp(t,n){return!n||t.some(r=>r.id===n.id)?[...t]:[n,...t]}function sp(t,n){if(!Un(t))return null;const r=Array.isArray(t.workspaces)?t.workspaces.filter(i=>Un(i)&&i.agentType===n&&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(Un(t.sessions))for(const[i,a]of Object.entries(t.sessions))!Un(a)||!Array.isArray(a.data)||(s[i]={data:a.data.filter(l=>Un(l)&&l.agentType===n&&typeof l.id=="string"),nextCursor:typeof a.nextCursor=="string"?a.nextCursor:null,loaded:a.loaded===!0});return{workspaces:r,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 op(t){return typeof t=="string"&&Ya.includes(t)}function Un(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function da(t){var s;const n={},r={};for(const[i,a]of Object.entries(t)){const l=a.data;n[i]=Lo(l.filter(u=>!u.parentSessionId));for(const u of l.filter(h=>h.parentSessionId))(r[s=u.parentSessionId]??(r[s]=[])).push(u)}for(const i of Object.values(r))i.sort((a,l)=>a.created.localeCompare(l.created));return{roots:n,children:r,projectIds:new Set(Object.entries(t).filter(([,i])=>i.loaded).map(([i])=>i))}}function vo(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 ip(){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 ua(t,n){n&&t.detail>0&&t.currentTarget.blur()}function ap(){const t=document.activeElement;t instanceof HTMLElement&&(t.matches("input, textarea, select")||t.isContentEditable)&&t.blur()}function dp(){var un,mt,Nr,Kt;const[t]=d.useState(ep),n=t.activeAgent,r=t.agents[n]??la(),[s]=d.useState(()=>da(r.sessions)),i=d.useRef(t),[a,l]=d.useState(n),u=d.useRef(a);u.current=a;const[h,g]=d.useState(r.workspaces.map(vo)),[x,j]=d.useState(r.nextCursor),[b,w]=d.useState(r.watermark),[S,R]=d.useState(!1),[E,F]=d.useState(!1),[v,y]=d.useState(null),[B,$]=d.useState(!1),[A,C]=d.useState(s.roots),[W,z]=d.useState(""),[q,le]=d.useState(!1),[X,se]=d.useState(10),[K,Te]=d.useState(null),[Me,Vn]=d.useState(!1),[Le,Qn]=d.useState(null),Wt=d.useRef(!1),[Lt,kr]=d.useState([]),[pt,T]=d.useState(s.children),Q=d.useRef(A),me=d.useRef(pt);Q.current=A,me.current=pt;const[ce,ke]=d.useState(s.projectIds),[Ee,Ge]=d.useState(new Set),[be,we]=d.useState({}),[Pt,Ze]=d.useState(new Set),[Tt,tt]=d.useState(Object.fromEntries(Object.entries(r.sessions).map(([f,I])=>[f,I.nextCursor]))),ft=d.useRef(new Map),Xt=d.useRef(new Map),[Se,Sr]=d.useState(r.selectedWorkspaceId),[Pe,en]=d.useState(r.selectedSessionId),Dt=d.useRef(Se),U=d.useRef(Pe);Dt.current=Se,U.current=Pe;const[Ts,Ir]=d.useState(new Set),[lt,gt]=d.useState(new Set(r.expandedWorkspaceIds)),[De,tn]=d.useState(new Set),[Bt,nn]=d.useState(!1),[ht,Ms]=d.useState("settings"),Kn=xe(f=>f.setTodos),rn=ut(f=>f.skin),Mt=ut(f=>f.layout),fe=ut(f=>f.wakeEnabled),pe=ut(f=>f.wakeWord),Jr=ut(f=>f.setSkin),Gn=ut(f=>f.setLayout),Cr=ut(f=>f.setWakeEnabled),$t=ut(f=>f.setWakeWord),Yr=ut(f=>f.autoSpeak),kn=ut(f=>f.setAutoSpeak),ct=ut(f=>f.runningFirst),Ar=ut(f=>f.setRunningFirst),Zn=xe(f=>f.runningSessionId),sn=xe(mc(f=>Object.entries(f.messagesBySession).filter(([,I])=>I.some(_=>_.askUser&&!_.askUser.answered)).map(([I])=>I))),on=d.useCallback(f=>f.status==="running"||Zn===f.id,[Zn]),Rr=()=>{gt(new Set),Ir(new Set(Object.keys(pt)))},Tr=()=>{const f=h.filter(I=>!De.has(I.id)).map(I=>I.id);gt(new Set(f)),Ir(new Set);for(const I of f){if(St.current.has(I))continue;const _=kt.current.has(I);Je(I,{refresh:_,background:_})}},an=$n(),nt=zl(),wt=an&&nt,[Jn,Ft]=d.useState(!1),[Et,Sn]=d.useState(!1),[In,Yn]=d.useState(null),[Xr,Cn]=d.useState(0),[An,Xn]=d.useState(void 0),xt=d.useRef(null),jt=d.useRef(!1),[er,tr]=d.useState(null),Ot=d.useRef(null),ln=d.useRef(!1),rt=d.useRef(h);rt.current=h;const Ut=d.useRef(De);Ut.current=De;const kt=d.useRef(ce);kt.current=ce;const St=d.useRef(Ee);St.current=Ee;const qt=d.useRef(null);d.useEffect(()=>{document.documentElement.setAttribute("data-skin",rn)},[rn]),d.useEffect(()=>{document.body.classList.toggle("layout-compact",Mt==="compact")},[Mt]),d.useEffect(()=>{var L;const f=h.map((P,ne)=>({agentType:a,workspaceId:P.id,name:P.name,roots:P.description?[P.description]:[],order:ne,updatedAt:P.updated||void 0,source:P.source??(P.agentType==="claude-code"?"derived":"native"),canCreateSession:P.canCreateSession})),I=Object.fromEntries(h.map(P=>[P.id,{data:[...A[P.id]??[],...Object.values(pt).flat().filter(ne=>(A[P.id]??[]).some(J=>J.id===ne.parentSessionId))],nextCursor:Tt[P.id]??null,loaded:ce.has(P.id)}])),_={...i.current,version:2,activeAgent:a,agents:{...i.current.agents,[a]:{workspaces:f,nextCursor:x,watermark:b,expandedWorkspaceIds:[...lt],selectedWorkspaceId:Se,selectedSessionId:Pe,sidebarScrollTop:((L=qt.current)==null?void 0:L.scrollTop)??0,sessions:I}}};i.current=_,ca(_)},[a,pt,lt,ce,h,Se,Pe,Tt,A,x,b]);const Ht=d.useCallback(()=>{if(!window.agentApi||!fe||jt.current||xt.current)return;const f=()=>{Mc()&&!xt.current&&(xt.current=Nc({wakeWord:pe,onWake:I=>{var _;Xn(I),Cn(L=>L+1),(_=window.agentApi)==null||_.showWindow()},onError:I=>console.warn("[wake]",I)}))};typeof window.agentApi.wakeStart=="function"?(jt.current=!0,window.agentApi.wakeStart(pe).then(I=>{I.ok||(jt.current=!1,f())}).catch(()=>{jt.current=!1,f()})):f()},[fe,pe]);d.useEffect(()=>{var f;if((f=window.agentApi)!=null&&f.onWake)return window.agentApi.onWake(I=>{jt.current=!1,Xn(I),Cn(_=>_+1)})},[]),d.useEffect(()=>{var f;if((f=window.agentApi)!=null&&f.onWakeCommand)return window.agentApi.onWakeCommand(I=>{var ne;const _=((I==null?void 0:I.text)||"").trim();if(!_)return;const L=Ot.current&&Date.now()<Ot.current.until?Ot.current:null;if(L){L.until=Date.now()+9e4,en(L.sessionId),(ne=window.agentApi)==null||ne.wakeConversation(!0),tr({text:_,projectId:null,sessionId:L.sessionId,nonce:Date.now()}),Ie(`语音追问:${_.length>40?_.slice(0,40)+"…":_}`),He("success"),setTimeout(()=>Ie(null),4e3);return}const P=rt.current.find(J=>J.name&&_.includes(J.name)&&!Ut.current.has(J.id));P&&(Sr(P.id),gt(J=>{const ie=new Set(J);return ie.add(P.id),ie})),en(null),ln.current=!0,kn(!0),tr({text:_,projectId:(P==null?void 0:P.id)??null,nonce:Date.now()}),Ie(`语音指令:${_.length>40?_.slice(0,40)+"…":_}${P?`(项目:${P.name})`:""}`),He("success"),setTimeout(()=>Ie(null),4e3)})},[]);const Es=d.useCallback(async()=>{window.agentApi&&(Ht(),await window.agentApi.hideWindow())},[Ht]),Ns=d.useCallback(f=>{nn(!1),Yn({right:f.right,bottom:f.bottom}),Sn(I=>!I)},[]),_s=d.useCallback(()=>{Sn(!1),nn(f=>!f)},[]);d.useEffect(()=>{if(!Et)return;const f=()=>{const _=document.querySelector(".chat-header-action--appearance");if(!_)return;const L=_.getBoundingClientRect();Yn(P=>(P==null?void 0:P.right)===L.right&&P.bottom===L.bottom?P:{right:L.right,bottom:L.bottom})},I=window.requestAnimationFrame(f);return window.addEventListener("resize",f),()=>{window.cancelAnimationFrame(I),window.removeEventListener("resize",f)}},[Mt,Et]),d.useEffect(()=>{window.agentApi&&Ht()},[Ht]),d.useEffect(()=>{const f=()=>{var I;(I=xt.current)==null||I.stop(),xt.current=null};return window.addEventListener("focus",f),()=>window.removeEventListener("focus",f)},[]),d.useEffect(()=>{var f,I;fe||((f=xt.current)==null||f.stop(),xt.current=null,jt.current=!1,(I=window.agentApi)==null||I.wakeStop())},[fe]),d.useEffect(()=>{!fe||!window.agentApi||jt.current&&window.agentApi.wakeStart(pe)},[pe]),d.useEffect(()=>()=>{var f;(f=xt.current)==null||f.stop()},[]);const qe=[...Object.values(A).flat(),...Object.values(pt).flat()],st=qe,ot=W.trim().toLowerCase(),It=ot?qe.filter(f=>f.title.toLowerCase().includes(ot)||(f.cwd||"").toLowerCase().includes(ot)):null,Oe=Pe?st.find(f=>f.id===Pe):void 0,Rn=Oe==null?void 0:Oe.title,es=(Oe==null?void 0:Oe.cwd)||((un=h.find(f=>f.id===Se))==null?void 0:un.description)||null,nr=h.filter(f=>!De.has(f.id)).map(f=>f.id),dt=nr.length>0&&nr.every(f=>!lt.has(f)),[Ct,Tn]=d.useState(300),[ts,rr]=d.useState(!1),cn=d.useRef(!1),sr=d.useRef(0),Mn=d.useRef(0),Vt=d.useCallback(f=>{if(!cn.current)return;const I=Math.min(480,Math.max(160,Mn.current+f.clientX-sr.current));Tn(I)},[]),At=d.useCallback(()=>{cn.current=!1,rr(!1),document.removeEventListener("mousemove",Vt),document.removeEventListener("mouseup",At)},[Vt]),En=d.useCallback(f=>{cn.current=!0,rr(!0),sr.current=f.clientX,Mn.current=Ct,document.addEventListener("mousemove",Vt),document.addEventListener("mouseup",At)},[Ct,Vt,At]),[Nt,Ie]=d.useState(null),[dn,He]=d.useState("success"),it=f=>{Dt.current=f.projectId,U.current=f.sessionId,Sr(f.projectId),en(f.sessionId),f.sessionId||Kn([])},ns=f=>{var J;if(f===u.current)return;const I=u.current,_=i.current.agents[I];_&&(i.current={...i.current,agents:{...i.current.agents,[I]:{..._,sidebarScrollTop:((J=qt.current)==null?void 0:J.scrollTop)??_.sidebarScrollTop}}});const L=i.current.agents[f]??la(),P=da(L.sessions),ne=L.workspaces.map(vo);u.current=f,rt.current=ne,l(f),g(ne),j(L.nextCursor),w(L.watermark),R(!1),F(!1),y(null),Q.current=P.roots,me.current=P.children,C(P.roots),T(P.children),ke(P.projectIds),kt.current=P.projectIds,Ge(new Set),St.current=new Set,we({}),Ze(new Set),tt(Object.fromEntries(Object.entries(L.sessions).map(([ie,ze])=>[ie,ze.nextCursor]))),gt(new Set(L.expandedWorkspaceIds)),tn(new Set),it({projectId:L.selectedWorkspaceId,sessionId:L.selectedSessionId}),window.requestAnimationFrame(()=>{qt.current&&(qt.current.scrollTop=L.sidebarScrollTop)}),te(f,{refresh:L.workspaces.length>0,since:L.watermark})},[or,ir]=d.useState([]),Be=d.useCallback(f=>{ir(I=>I.filter(_=>_.id!==f))},[]),Nn=d.useCallback(f=>{const I=crypto.randomUUID();ir(_=>[..._,{...f,id:I}]),setTimeout(()=>Be(I),12e3)},[Be]);async function te(f=u.current,I={}){if(!window.agentApi)return;const _=(Xt.current.get(f)??0)+1;Xt.current.set(f,_),R(!0),y(null);try{const L=await window.agentApi.listAgentWorkspaces(f,{cursor:I.cursor,limit:50,refresh:I.refresh,since:I.refresh?I.since??b:null});if(u.current!==f||Xt.current.get(f)!==_)return;const P=rt.current.map((ae,re)=>({agentType:f,workspaceId:ae.id,name:ae.name,roots:ae.description?[ae.description]:[],order:re,updatedAt:ae.updated,source:ae.source??(f==="claude-code"?"derived":"native"),canCreateSession:ae.canCreateSession})),J=tp(P,L,!I.cursor).map(vo);rt.current=J,g(J),j(L.nextCursor),w(L.watermark),F(L.stale===!0);const ie=new Set(J.map(ae=>ae.id)),ze=Dt.current;ze&&!ie.has(ze)&&it(Ji);const Ce=new Set([...kt.current].filter(ae=>ie.has(ae)));ze&&ie.has(ze)&&Ce.add(ze),C(ae=>Object.fromEntries(Object.entries(ae).filter(([re])=>ie.has(re)))),ke(ae=>{const re=new Set([...ae].filter(Ye=>ie.has(Ye)));return kt.current=re,re}),Ge(ae=>{const re=new Set([...ae].filter(Ye=>ie.has(Ye)));return St.current=re,re}),we(ae=>Object.fromEntries(Object.entries(ae).filter(([re])=>ie.has(re))));const Ue=new Set;if(await Promise.all(J.map(async ae=>{ae.description&&!await window.agentApi.checkProjectPath(ae.description)&&Ue.add(ae.id)})),u.current!==f||Xt.current.get(f)!==_)return;if(tn(Ue),I.refreshLoadedSessions!==!1)for(const ae of Ce)Ue.has(ae)||St.current.has(ae)||Je(ae,{refresh:!0,background:!0})}catch(L){u.current===f&&(rt.current.length>0&&F(!0),y(L instanceof Error?L.message:"目录加载失败"))}finally{u.current===f&&Xt.current.get(f)===_&&R(!1)}}async function Je(f,I={}){var ne;if(!window.agentApi)return;const _=u.current,L=`${_}:${f}`,P=(ft.current.get(L)??0)+1;ft.current.set(L,P),Ge(J=>{const ie=new Set(J).add(f);return St.current=ie,ie}),we(J=>{if(!(f in J))return J;const ie={...J};return delete ie[f],ie});try{const J=await window.agentApi.listAgentWorkspaceSessions(_,f,{cursor:I.cursor,limit:20,refresh:I.refresh});if(u.current!==_||ft.current.get(L)!==P)return;const ie=Q.current[f]??[],ze=I.pendingSession?{...I.pendingSession,projectId:f}:void 0,Ce=ze?[ze,...ie.filter(de=>de.id!==ze.id)]:ie,Ue=new Set(Ce.map(de=>de.id)),ae=[...Ce,...[...Ue].flatMap(de=>me.current[de]??[])],re=np(ae,J,!I.cursor).map(de=>({...de,projectId:de.projectId??f})),Ye=Lo(re.filter(de=>!de.parentSessionId)),bt=Dt.current,Xe=U.current,yt=rp(Ye,ze);bt===f&&Xe&&!re.some(de=>de.id===Xe)&&!yt.some(de=>de.id===Xe)&&it(Ji);const et={};for(const de of re.filter($e=>$e.parentSessionId))(et[ne=de.parentSessionId]??(et[ne]=[])).push(de);for(const de of Object.values(et))de.sort(($e,_r)=>$e.created.localeCompare(_r.created));tt(de=>({...de,[f]:J.nextCursor})),Ze(de=>{const $e=new Set(de);return J.stale?$e.add(f):$e.delete(f),$e});const Ae={...Q.current,[f]:yt},We={...me.current};for(const de of Ue)delete We[de];for(const[de,$e]of Object.entries(et))We[de]=$e;Q.current=Ae,me.current=We,C(Ae),T(We),ke(de=>{const $e=new Set(de).add(f);return kt.current=$e,$e})}catch(J){if(ft.current.get(L)!==P)return;we(ie=>({...ie,[f]:J instanceof Error?J.message:"会话加载失败"}))}finally{ft.current.get(L)===P&&Ge(J=>{const ie=new Set(J);return ie.delete(f),St.current=ie,ie})}}const Mr=async f=>{if(!window.agentApi)return;const I=await window.agentApi.listChildSessions(f);T(_=>({..._,[f]:I.sort((L,P)=>L.created<P.created?-1:1)}))},Er=async(f,I)=>{if(!window.agentApi)return;const _=rt.current.find(L=>L.id===f);if(!_||_.canCreateSession===!1){Ie("请先选择目录"),He("info"),setTimeout(()=>Ie(null),3e3);return}if(!Wt.current){Wt.current=!0,Qn({projectId:f,agentType:I});try{const L=(_==null?void 0:_.source)==="imported"?void 0:f,P=await window.agentApi.createSession("新会话",L,I,_==null?void 0:_.description);if(u.current!==I)return;const ne=P.projectId===f?P:{...P,projectId:f},J={...Q.current,[f]:[ne,...(Q.current[f]??[]).filter(ie=>ie.id!==P.id)]};Q.current=J,C(J),it({projectId:f,sessionId:P.id}),wt&&Ft(!1),I==="customer-agent"&&Je(f,{refresh:!0,background:!0,pendingSession:ne})}catch(L){Ie(L instanceof Error?L.message:"新建会话失败"),He("error"),setTimeout(()=>Ie(null),3e3)}finally{Wt.current=!1,Qn(null)}}},zs=()=>{const f=rt.current.find(I=>I.id===Se);if(!Se||(f==null?void 0:f.canCreateSession)===!1){Ie("请先选择目录"),He("info"),setTimeout(()=>Ie(null),3e3);return}Er(Se,a)};d.useEffect(()=>{var f;window.agentApi&&(te(u.current,{refresh:(((f=i.current.agents[u.current])==null?void 0:f.workspaces.length)??0)>0}),Ss.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(kr).catch(()=>{}))},[]),d.useEffect(()=>{const f=window.setInterval(()=>{document.visibilityState!=="visible"||S||te(a,{refresh:!0,since:b,refreshLoadedSessions:!1})},15e3);return()=>window.clearInterval(f)},[a,S,b]),d.useEffect(()=>{if(!Se||!Pe||(Oe==null?void 0:Oe.agentType)==="customer-agent"||!window.agentApi)return;let f=!1;const I=async()=>{document.visibilityState==="visible"&&(f||await Je(Se,{refresh:!0,background:!0}))},_=window.setInterval(()=>void I(),1e4);return()=>{f=!0,window.clearInterval(_)}},[Se,Pe,Oe==null?void 0:Oe.agentType]),d.useEffect(()=>{if(!Se||!window.agentApi)return;const f=h.find(_=>_.id===Se),I=f==null?void 0:f.description;I&&window.agentApi.setProjectWorkingDir(I)},[Se,h]);const rs=f=>{it(Yi(f));const I=!lt.has(f);if(gt(_=>{const L=new Set(_);return I?L.add(f):L.delete(f),L}),I&&!St.current.has(f)){const _=kt.current.has(f);Je(f,{refresh:_,background:_})}},ar=async f=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const I=f.replace(/\\/g,"/"),_=I.split("/").filter(Boolean),L=_[_.length-1]||I||"导入的项目",P=await window.agentApi.importAgentWorkspace(u.current,I,L);await te(u.current,{refresh:!0,refreshLoadedSessions:!1}),it(Yi(P.workspace.workspaceId)),await Je(P.workspace.workspaceId,{refresh:!0}),gt(ne=>{const J=new Set(ne);return J.add(P.workspace.workspaceId),J}),Ie(P.existing?"该文件夹已在当前 Agent 的目录中":`已导入:${P.workspace.name}`),He(P.existing?"info":"success"),setTimeout(()=>Ie(null),3e3)},lr=async()=>{try{if(!window.agentApi){Ie("agentApi 未就绪,请重启应用"),He("error");return}if(an){$(!0);return}const f=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",f),!f)return;await ar(f)}catch(f){console.error("[import] error:",f),Ie(f instanceof Error?f.message:String(f)),He("error"),setTimeout(()=>Ie(null),5e3)}},Qt=async f=>{if(window.agentApi)try{await window.agentApi.deleteProject(f),Se===f&&(Sr(null),en(null),Kn([])),Ie("项目删除成功"),He("success"),setTimeout(()=>Ie(null),2500),await te()}catch(I){Ie(I instanceof Error?I.message:"项目删除失败"),He("error"),setTimeout(()=>Ie(null),4e3)}},cr=(f,I)=>{Te({session:f,anchor:I})},dr=async()=>{if(!window.agentApi||!K||Me)return;const{session:f}=K;Vn(!0);try{await window.agentApi.deleteSession(f.id);const I=f.projectId??Dt.current,_=f.agentType;if(I){const ne=`${_}:${I}`;ft.current.set(ne,(ft.current.get(ne)??0)+1)}const L=Au(Q.current,me.current,[],f.id);Q.current=L.sessionsByProject,me.current=L.childSessionsByParent,C(L.sessionsByProject),T(L.childSessionsByParent);const P=i.current.agents[_];if(P){const ne={...i.current,agents:{...i.current.agents,[_]:Iu(P,L.removedIds)}};i.current=ne,ca(ne)}U.current&&L.removedIds.includes(U.current)&&it({projectId:Dt.current,sessionId:null}),Ie("会话删除成功"),He("success"),setTimeout(()=>Ie(null),2500),Te(null),I&&Je(I,{refresh:!0,background:!0})}catch(I){Ie(I instanceof Error?I.message:"会话删除失败"),He("error"),setTimeout(()=>Ie(null),4e3)}finally{Vn(!1)}},Ws=[{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:an?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[wt&&Jn&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>Ft(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),wt&&!Jn&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>Ft(!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}}),Mt!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:Ct,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 0",position:"relative",zIndex:10,overflow:"hidden",...wt?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:Jn?"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(Ro,{agentType:"customer-agent",size:24})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsx(Uu,{value:a,health:Lt,onChange:ns}),e.jsxs("button",{type:"button",className:"sidebar-search-field",onClick:()=>{le(!0),se(10)},title:"搜索会话","aria-label":"搜索会话",children:[e.jsx(ma,{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":`${h.length} 个目录`,children:h.length})]}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:f=>{dt?Tr():Rr(),ua(f,dt)},title:dt?"展开全部会话":"折叠全部会话","aria-label":dt?"展开全部会话":"折叠全部会话","aria-pressed":dt,disabled:nr.length===0,className:`ui-icon-button sidebar-collapse-all${dt?" 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:dt?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:f=>{Ar(!ct),ua(f,ct)},title:ct?"按新建时间排序":"进行中会话优先","aria-label":ct?"按新建时间排序":"进行中会话优先","aria-pressed":ct,className:`ui-icon-button sidebar-session-sort${ct?" 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 lr(),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:qt,className:"app-sidebar-scroll",onPointerDownCapture:ap,onScroll:f=>{const I=f.currentTarget;I.scrollHeight-I.scrollTop-I.clientHeight<120&&x&&!S&&te(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:[h.map(f=>{var ae;const I=Se===f.id,_=lt.has(f.id),L=ce.has(f.id),P=Ee.has(f.id),ne=be[f.id],J=A[f.id]??[],ie=ct?ku(J,on):J,ze=ie.length>10,Ce=De.has(f.id),Ue=(Le==null?void 0:Le.agentType)===a&&Le.projectId===f.id;return e.jsxs("div",{className:"sidebar-project-block","aria-busy":P,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${I&&!Ce?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:Ce?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{Ce||rs(f.id)},disabled:Ce,"aria-expanded":_,"aria-pressed":I,title:Ce?`路径不存在:${f.description}`:f.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:Ce?"var(--text-muted)":I?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:I&&!Ce?600:400,cursor:Ce?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[Ce?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"})]}):f.canCreateSession===!1?e.jsx(tc,{size:13,"aria-hidden":"true",style:{flexShrink:0,opacity:I?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:I?1:.5},children:_?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:f.name})]}),a==="customer-agent"&&!an&&e.jsx("button",{onClick:re=>{re.stopPropagation(),Qt(f.id)},title:"删除目录","aria-label":`删除目录:${f.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(ip,{})}),f.canCreateSession!==!1&&e.jsx("button",{type:"button",onClick:re=>{re.stopPropagation(),Er(f.id,a)},title:Ue?"正在创建会话":`新建 ${a==="customer-agent"?"Customer Agent":a==="claude-code"?"Claude Code":a==="codex"?"Codex":"OpenCode"} 会话`,"aria-label":Ue?"正在创建会话":`在 ${f.name} 中新建会话`,"aria-busy":Ue,disabled:Le!==null||Ce||((ae=Lt.find(re=>re.agentType===a))==null?void 0:ae.available)===!1,className:"sidebar-runtime-create sidebar-project-add-action ui-icon-button ui-icon-button--small",children:Ue?e.jsx(Rt,{size:13,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):e.jsx(yi,{size:13,"aria-hidden":"true"})})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:_?ze?300:800:0,opacity:_?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:re=>{const Ye=re.currentTarget,bt=Ye.scrollHeight-Ye.scrollTop-Ye.clientHeight<80,Xe=Tt[f.id];bt&&Xe&&!P&&Je(f.id,{cursor:Xe})},style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...ze?{maxHeight:280,overflowY:"auto"}:{}},children:[ie.map(re=>{const Ye=Pe===re.id,bt=on(re),Xe=uo({status:re.status,isRunning:bt,needsInput:bt&&sn.includes(re.id)}),yt=pt[re.id]??[],et=!Ts.has(re.id);return e.jsxs("div",{children:[e.jsx(yo,{session:{id:re.id,title:re.title,visualState:Xe,statusLabel:po[Xe],occupiedExternally:re.agentType!=="codex"&&re.occupancy==="owned-externally",canDelete:re.canDelete,active:Ye,hasChildren:yt.length>0,expanded:et,compatibility:re.compatibility},onSelect:()=>{wt&&Ft(!1),it(fo(f.id,re.id)),yt.length>0&&Ir(Ae=>{const We=new Set(Ae);return We.has(re.id)?We.delete(re.id):We.add(re.id),We})},onDelete:Ae=>cr(re,Ae)}),e.jsx("div",{className:"sidebar-child-sessions",style:{maxHeight:et?yt.length*40:0,opacity:et?1:0},children:yt.map(Ae=>{const We=on(Ae),de=uo({status:Ae.status,isRunning:We,needsInput:We&&sn.includes(Ae.id)});return e.jsx(yo,{session:{id:Ae.id,title:Ae.title,visualState:de,statusLabel:po[de],occupiedExternally:Ae.agentType!=="codex"&&Ae.occupancy==="owned-externally",canDelete:Ae.canDelete,active:Pe===Ae.id,child:!0,compatibility:Ae.compatibility},deleteLabel:"删除子会话",onSelect:()=>{wt&&Ft(!1),it(fo(f.id,Ae.id))},onDelete:$e=>cr(Ae,$e)},Ae.id)})})]},re.id)}),P&&!L&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),ne&&e.jsxs("div",{title:ne,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 Je(f.id,{refresh:L,background:L}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),Pt.has(f.id)&&!ne&&e.jsx("div",{className:"sidebar-cache-state",children:"显示缓存,会话将在下次刷新时更新"}),ie.length===0&&L&&!P&&!ne&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},f.id)}),h.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:S?"正在加载目录...":"暂无目录"}),h.length>0&&S&&e.jsx("div",{className:"sidebar-cache-state",children:"正在同步目录..."}),E&&!v&&e.jsx("div",{className:"sidebar-cache-state",children:"当前显示缓存目录"}),v&&e.jsxs("div",{className:"sidebar-load-error",title:v,children:[e.jsx("span",{children:h.length>0?"目录刷新失败,当前显示缓存":"目录加载失败"}),e.jsx("button",{type:"button",onClick:()=>void te(a,{refresh:h.length>0}),children:"重试"})]})]})}),e.jsx("div",{className:"sidebar-bottom-action",children:e.jsx("button",{type:"button",className:"sidebar-new-session-primary",disabled:Le!==null||Se!==null&&De.has(Se)||((mt=Lt.find(f=>f.agentType===a))==null?void 0:mt.available)===!1,"aria-busy":Le!==null,"aria-disabled":Le!==null||!Se||((Nr=h.find(f=>f.id===Se))==null?void 0:Nr.canCreateSession)===!1,title:Le?"正在创建会话":Se&&((Kt=h.find(f=>f.id===Se))==null?void 0:Kt.canCreateSession)!==!1?"新建会话":"请先选择目录",onClick:zs,children:Le?e.jsxs(e.Fragment,{children:[e.jsx(Rt,{size:16,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}),e.jsx("span",{children:"正在创建..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(yi,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"新建会话"})]})})})]}),K&&e.jsx(Hu,{message:Su(K.session),anchor:K.anchor,mobile:wt,pending:Me,onCancel:()=>Te(null),onConfirm:()=>void dr()}),!wt&&e.jsx("div",{className:`app-sidebar-resizer${ts?" is-dragging":""}`,onMouseDown:En,style:{left:Ct}}),q&&e.jsx("div",{onClick:()=>le(!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:f=>f.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:W,onChange:f=>z(f.target.value),onKeyDown:f=>{f.key==="Escape"&&le(!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:[ot&&It&&It.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[It.length," 个结果"]}),ot&&It&&It.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!ot&&qe.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),(It??qe.slice(0,X)).map(f=>{const I=Pe===f.id,_=on(f),L=uo({status:f.status,isRunning:_,needsInput:_&&sn.includes(f.id)});return e.jsx(yo,{session:{id:f.id,title:f.title,visualState:L,statusLabel:po[L],occupiedExternally:f.agentType!=="codex"&&f.occupancy==="owned-externally",canDelete:f.canDelete,active:I,child:!!f.parentSessionId,compatibility:f.compatibility},onSelect:()=>{const P=f.projectId&&h.some(ne=>ne.id===f.projectId)?f.projectId:null;it(fo(P,f.id)),le(!1),wt&&Ft(!1)},onDelete:P=>cr(f,P)},f.id)}),!ot&&qe.length>X&&e.jsx("button",{type:"button",onClick:()=>se(f=>f+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:"更多…"})]})]})})]}),Nt&&Jt.createPortal(e.jsxs("div",{className:`app-action-notice is-${dn}`,role:dn==="error"?"alert":"status","aria-live":dn==="error"?"assertive":"polite",children:[e.jsx("span",{className:"app-action-notice-mark","aria-hidden":"true",children:dn==="success"?"✓":dn==="info"?"i":"!"}),e.jsx("span",{children:Nt})]}),document.body),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[Mt==="focus"&&e.jsx("button",{onClick:()=>Gn("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(ju,{activeAgentType:a,selectedProjectId:Se,selectedSessionId:Pe,sessionTitle:Rn,sessionSummary:Oe,workspacePath:es,voiceCommand:er,onOpenSettings:_s,settingsOpen:Bt,onHideToBackground:()=>void Es(),onToggleAppearance:Ns,appearanceOpen:Et,hideToBackgroundTitle:fe?`隐藏到后台(说“${pe}”唤醒)`:"隐藏到后台",onSessionCreated:async(f,I)=>{var L;const _=Dt.current;it({projectId:_,sessionId:f}),ln.current&&(ln.current=!1,Ot.current={sessionId:f,until:Date.now()+9e4},(L=window.agentApi)==null||L.wakeConversation(!0)),_&&await Je(_,{pendingSession:I})},onSubSessionCreated:async f=>{await Mr(f)},onSelectSession:f=>{en(f)},onSubAgentEvent:f=>{f.type==="started"?Nn({type:"info",title:"子会话已启动",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId}):f.type==="completed"?Nn({type:"success",title:"子会话已完成",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId}):Nn({type:"error",title:"子会话出错",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId})},onMessageSent:(f,I)=>{C(_=>{const L={};for(const[P,ne]of Object.entries(_))L[P]=ne.map(J=>J.id===f?{...J,title:I.slice(0,60)||J.title}:J);return L})},onRunComplete:async(f,I)=>{var ne;const _=Ot.current,L=Gd(_,I);Ot.current=L,L!==_&&((ne=window.agentApi)==null||ne.wakeConversation(!0));const P=f||Se;P&&await Je(P,{refresh:!0,background:!0})}})})]}),Bt&&Jt.createPortal(e.jsx("div",{onClick:()=>nn(!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:f=>f.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:Ws.map(f=>e.jsx("button",{onClick:()=>Ms(f.id),className:`settings-tab ${ht===f.id?"settings-tab-active":""}`,children:f.label},f.id))}),e.jsx("button",{onClick:()=>nn(!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:[ht==="settings"&&e.jsx(Tu,{}),ht==="mcp"&&e.jsx(Nu,{}),ht==="memory"&&e.jsx(_u,{}),ht==="skill"&&e.jsx(Wu,{}),ht==="agent"&&e.jsx(Du,{}),ht==="lsp"&&e.jsx($u,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),Et&&In&&Jt.createPortal(e.jsx("div",{onClick:()=>Sn(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:f=>f.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(In.right-320,window.innerWidth-332)),top:In.bottom+8,width:320,maxHeight:`calc(100vh - ${In.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:Wl.map(f=>e.jsxs("button",{onClick:()=>Jr(f.id),className:`appearance-choice ${rn===f.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${f.preview[0]} 55%, ${f.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:rn===f.id?600:400},children:f.label}),rn===f.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"})})]},f.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:Ll.map(f=>e.jsx("button",{onClick:()=>Gn(f.id),title:f.description,className:`appearance-segment ${Mt===f.id?"appearance-segment-active":""}`,children:f.label},f.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:Yr,onChange:f=>kn(f.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:fe,onChange:f=>Cr(f.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:pe,onChange:f=>$t(f.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(Yu,{open:B,onCancel:()=>$(!1),onConfirm:async f=>{await ar(f),$(!1)}}),e.jsx(Fu,{trigger:Xr,heardText:An}),or.length>0&&Jt.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:or.map(f=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${f.type==="error"?"rgba(220,38,38,0.25)":f.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${f.type==="error"?"var(--danger)":f.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:f.type==="error"?"var(--danger)":f.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[f.type==="error"?"✕":f.type==="success"?"✓":"◎"," ",f.title]}),e.jsx("button",{onClick:()=>Be(f.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:I=>I.currentTarget.style.color="var(--text-primary)",onMouseLeave:I=>I.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:f.body}),f.sessionId&&e.jsx("button",{onClick:()=>{en(f.sessionId),Be(f.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:I=>I.currentTarget.style.background="var(--accent-glow)",onMouseLeave:I=>I.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},f.id))}),document.body)]})}export{dp as default};
|