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.
Files changed (124) hide show
  1. package/manifest.json +1 -1
  2. package/package.json +1 -1
  3. package/runtime/.next/BUILD_ID +1 -1
  4. package/runtime/.next/app-build-manifest.json +8 -8
  5. package/runtime/.next/app-path-routes-manifest.json +1 -1
  6. package/runtime/.next/build-manifest.json +6 -6
  7. package/runtime/.next/prerender-manifest.json +1 -1
  8. package/runtime/.next/react-loadable-manifest.json +1 -1
  9. package/runtime/.next/required-server-files.json +1 -1
  10. package/runtime/.next/routes-manifest.json +1 -1
  11. package/runtime/.next/server/app/_not-found/page.js +1 -1
  12. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/runtime/.next/server/app/_not-found.html +1 -1
  14. package/runtime/.next/server/app/_not-found.rsc +1 -1
  15. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  16. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  17. package/runtime/.next/server/app/api/agent/model/route.js +1 -1
  18. package/runtime/.next/server/app/api/agent/models/route.js +1 -1
  19. package/runtime/.next/server/app/api/agent/run/route.js +1 -1
  20. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  21. package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
  22. package/runtime/.next/server/app/api/agent/stream/route.js +4 -4
  23. package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
  24. package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
  25. package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
  26. package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
  27. package/runtime/.next/server/app/api/mcp/disconnect/route.js +1 -1
  28. package/runtime/.next/server/app/api/mcp/servers/route.js +1 -1
  29. package/runtime/.next/server/app/api/memory/[key]/route.js +1 -1
  30. package/runtime/.next/server/app/api/memory/route.js +1 -1
  31. package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
  32. package/runtime/.next/server/app/api/projects/[id]/route.js +1 -1
  33. package/runtime/.next/server/app/api/projects/check/route.js +1 -1
  34. package/runtime/.next/server/app/api/projects/directories/route.js +1 -1
  35. package/runtime/.next/server/app/api/projects/roots/route.js +1 -1
  36. package/runtime/.next/server/app/api/projects/route.js +1 -1
  37. package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
  38. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
  39. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
  40. package/runtime/.next/server/app/api/sessions/[id]/goals/route.js +1 -1
  41. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
  42. package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js +1 -1
  43. package/runtime/.next/server/app/api/sessions/[id]/release/route.js +1 -0
  44. package/runtime/.next/server/app/api/sessions/[id]/release/route.js.nft.json +1 -0
  45. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  46. package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js +1 -0
  47. package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js.nft.json +1 -0
  48. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  49. package/runtime/.next/server/app/api/skills/route.js +1 -1
  50. package/runtime/.next/server/app/api/tools/route.js +1 -1
  51. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  52. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  53. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  54. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  55. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  56. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  57. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  58. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  59. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  60. package/runtime/.next/server/app/web/page.js +11 -8
  61. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  62. package/runtime/.next/server/app/web.html +1 -1
  63. package/runtime/.next/server/app/web.rsc +2 -2
  64. package/runtime/.next/server/app-paths-manifest.json +27 -25
  65. package/runtime/.next/server/chunks/1322.js +37 -37
  66. package/runtime/.next/server/chunks/2083.js +12 -12
  67. package/runtime/.next/server/chunks/5303.js +1 -1
  68. package/runtime/.next/server/chunks/7186.js +3 -3
  69. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  70. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  71. package/runtime/.next/server/pages/404.html +1 -1
  72. package/runtime/.next/server/pages/500.html +1 -1
  73. package/runtime/.next/server/server-reference-manifest.json +1 -1
  74. package/runtime/.next/static/chunks/137.e70970795c25de4f.js +1 -0
  75. package/runtime/.next/static/chunks/919-e3163c9448664f1a.js +1 -0
  76. package/runtime/.next/static/chunks/app/web/page-f8e555341da23177.js +1 -0
  77. package/runtime/.next/static/chunks/main-app-07d67f2d4e96ecb8.js +1 -0
  78. package/runtime/.next/static/chunks/{webpack-d22db940097662ef.js → webpack-819dfd677dd52477.js} +1 -1
  79. package/runtime/lib/file-preview-service.mjs +29 -0
  80. package/runtime/lib/markdown-preview.mjs +65 -0
  81. package/runtime/node_modules/.package-lock.json +23 -11
  82. package/runtime/node_modules/@agent/core/dist/domain/agent/entities.d.ts +3 -0
  83. package/runtime/node_modules/@agent/core/dist/domain/agent/entities.d.ts.map +1 -1
  84. package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts +7 -0
  85. package/runtime/node_modules/@agent/core/dist/domain/model/entities.d.ts.map +1 -1
  86. package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts +16 -0
  87. package/runtime/node_modules/@agent/core/dist/domain/session/entities.d.ts.map +1 -1
  88. package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts +2 -2
  89. package/runtime/node_modules/@agent/core/dist/domain/session/index.d.ts.map +1 -1
  90. package/runtime/node_modules/@agent/core/dist/index.js +2 -1
  91. package/runtime/node_modules/@agent/core/dist/index.js.map +1 -1
  92. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +39 -39
  93. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +1 -1
  94. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +18 -20
  95. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -25
  96. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/package.json +10 -10
  97. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +41 -41
  98. package/runtime/node_modules/marked/LICENSE.md +44 -0
  99. package/runtime/node_modules/marked/README.md +106 -0
  100. package/runtime/node_modules/marked/bin/main.js +282 -0
  101. package/runtime/node_modules/marked/bin/marked.js +15 -0
  102. package/runtime/node_modules/marked/lib/marked.cjs +2211 -0
  103. package/runtime/node_modules/marked/lib/marked.d.cts +728 -0
  104. package/runtime/node_modules/marked/lib/marked.esm.js +2189 -0
  105. package/runtime/node_modules/marked/lib/marked.umd.js +2213 -0
  106. package/runtime/node_modules/marked/man/marked.1 +111 -0
  107. package/runtime/node_modules/marked/man/marked.1.md +92 -0
  108. package/runtime/node_modules/marked/marked.min.js +69 -0
  109. package/runtime/node_modules/marked/package.json +111 -0
  110. package/runtime/package-lock.json +48 -35
  111. package/runtime/package.json +1 -0
  112. package/runtime/webapp/dist/assets/App-u5-hbDMQ.js +285 -0
  113. package/runtime/webapp/dist/assets/index-3s0r60kD.css +1 -0
  114. package/runtime/webapp/dist/assets/{index-BAH3pT_c.js → index-jGt09xOx.js} +2 -2
  115. package/runtime/webapp/dist/index.html +2 -2
  116. package/runtime/ws-server.mjs +13 -0
  117. package/runtime/.next/static/chunks/108-bc4a0fe192dfff08.js +0 -1
  118. package/runtime/.next/static/chunks/137.261fab9d606d75d3.js +0 -1
  119. package/runtime/.next/static/chunks/app/web/page-8e4da33d77868123.js +0 -1
  120. package/runtime/.next/static/chunks/main-app-3596fd7d2841e9a3.js +0 -1
  121. package/runtime/webapp/dist/assets/App-CZspcejP.js +0 -275
  122. package/runtime/webapp/dist/assets/index-lt5J4xDf.css +0 -1
  123. /package/runtime/.next/static/{iaxCayE60RyqJY_Zj-OjS → 1LC7dx7c9RaWO6oZD2h4N}/_buildManifest.js +0 -0
  124. /package/runtime/.next/static/{iaxCayE60RyqJY_Zj-OjS → 1LC7dx7c9RaWO6oZD2h4N}/_ssgManifest.js +0 -0
@@ -1,275 +0,0 @@
1
- import{r as d,R as nl,j as e,c as Ha,a as Kt,u as ot,i as or,b as rl,S as sl,L as il}from"./index-BAH3pT_c.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 al=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Va=(...t)=>t.filter((r,n,i)=>!!r&&r.trim()!==""&&i.indexOf(r)===n).join(" ").trim();/**
7
- * @license lucide-react v0.468.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */var ol={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 ll=d.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:n=2,absoluteStrokeWidth:i,className:a="",children:o,iconNode:l,...p},g)=>d.createElement("svg",{ref:g,...ol,width:r,height:r,stroke:t,strokeWidth:i?Number(n)*24/Number(r):n,className:Va("lucide",a),...p},[...l.map(([h,m])=>d.createElement(h,m)),...Array.isArray(o)?o:[o]]));/**
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 ne=(t,r)=>{const n=d.forwardRef(({className:i,...a},o)=>d.createElement(ll,{ref:o,iconNode:r,className:Va(`lucide-${al(t)}`,i),...a}));return n.displayName=`${t}`,n};/**
22
- * @license lucide-react v0.468.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const dl=ne("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 cl=ne("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 ul=ne("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 ui=ne("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 cs=ne("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 dr=ne("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 pl=ne("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 fl=ne("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 Ws=ne("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 gl=ne("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=ne("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 xl=ne("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 ml=ne("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 bl=ne("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 yl=ne("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 vl=ne("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 wl=ne("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 xs=ne("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 jl=ne("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 kl=ne("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 Sl=ne("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 ea=ne("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 Il=ne("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 Cl=ne("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 Al=ne("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 dn=ne("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 Rl=ne("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 Tl=ne("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 Ml=ne("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 Qa=ne("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 ta=ne("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 El=ne("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 Ka=ne("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 Ga=ne("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 Nl=ne("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 zl=ne("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 _l=ne("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 Ls=ne("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 us=ne("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 Wl=ne("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
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 Ll=ne("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"}]]);/**
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 Za=ne("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"}]]);/**
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 Ya=ne("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function Pl(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||t===null||typeof r!="object"||r===null)return!1;if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(const[i,a]of t)if(!Object.is(a,r.get(i)))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(const i of t)if(!r.has(i))return!1;return!0}const n=Object.keys(t);if(n.length!==Object.keys(r).length)return!1;for(const i of n)if(!Object.prototype.hasOwnProperty.call(r,i)||!Object.is(t[i],r[i]))return!1;return!0}const{useRef:Dl}=nl;function Bl(t){const r=Dl();return n=>{const i=t(n);return Pl(r.current,i)?r.current:r.current=i}}const Fl="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",$l="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 pi({agentType:t,size:r=16,className:n}){return t==="customer-agent"?e.jsxs("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 1024 1024",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M248 430 512 294l264 136-264 136-264-136Z",stroke:"currentColor",strokeWidth:"64",strokeLinejoin:"round"}),e.jsx("path",{d:"m248 594 264 136 264-136",stroke:"currentColor",strokeWidth:"64",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M512 350c10 38 30 58 68 68-38 10-58 30-68 68-10-38-30-58-68-68 38-10 58-30 68-68Z",fill:"currentColor"})]}):t==="codex"?e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"29.487 29.964 121.035 119.954","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:$l})}):t==="claude-code"?e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:Fl})}):e.jsx("svg",{className:n,"data-agent-icon":t,width:r,height:r,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M22 24H2V0h20zM17 4.8H7v14.4h10z",fillRule:"evenodd"})})}const Ja="webapp.nativeAgentRunPrefs.v1",Ol=["codex","claude-code","opencode"];function Xa(){try{const t=JSON.parse(localStorage.getItem(Ja)??"{}");return t&&typeof t=="object"?t:{}}catch{return{}}}function fs(t){return Ol.includes(t)}function na(t){return fs(t)?Xa()[t]??{}:{}}function Ul(t,r){if(!fs(t))return;const n=Xa();n[t]=r;try{localStorage.setItem(Ja,JSON.stringify(n))}catch{}}function Ps(t){return t.providerID?`${t.providerID}/${t.id}`:t.id}function ql(t){const r=t.indexOf("/");return r>0?{providerID:t.slice(0,r),id:t.slice(r+1)}:{id:t}}function ra(t,r){const n=t??[],i=n.findIndex(o=>o.itemId===r.itemId&&o.sectionIndex===r.sectionIndex);return(i<0?[...n,{itemId:r.itemId,sectionIndex:r.sectionIndex,text:r.delta}]:n.map((o,l)=>l===i?{...o,text:o.text+r.delta}:o)).sort((o,l)=>o.sectionIndex-l.sectionIndex)}function sa(t){let r=[];for(const n of t)if(n.type==="runtime_progress"){const{type:i,...a}=n;r=eo(r,a)}else(n.type==="done"||n.type==="turn_aborted"||n.type==="error")&&(r=[]);return r}function eo(t,r){const n=t.findIndex(i=>i.progressId===r.progressId);return n<0?[...t,r]:t.map((i,a)=>a===n?r:i)}function Hl(t,r){return[...t].reverse().find(n=>n.toolCallId===r)}function Vl(t){return[...t].reverse().find(r=>!r.toolCallId)}function ia(t){for(let r=t.length-1;r>=0;r--)if(t[r].type==="context_usage"&&t[r].usage)return t[r].usage}function aa(t){var n;const r=new Map;for(const i of t)i.type==="native_subagent_update"&&((n=i.activity)!=null&&n.parentToolCallId)&&r.set(i.activity.parentToolCallId,i.activity);return[...r.values()]}function oa(t,r){var n,i;if(r.role==="assistant"&&((n=r.toolCalls)!=null&&n.length)){const a=t[t.length-1];if(a&&a.role==="assistant"&&!((i=a.toolCalls)!=null&&i.length))return[...t.slice(0,-1),{...a,content:a.content,toolCalls:r.toolCalls}]}return[...t,r]}function la(t,r){var i;if(!r)return t;const n=t[t.length-1];if(n&&n.role==="assistant"&&!((i=n.toolCalls)!=null&&i.length)&&!n.askUser&&!n.isCompactionSummary){const a=[...t];return a[a.length-1]={...n,content:n.content+r},a}return[...t,{id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()}]}function da(t,r,n,i){return t.map(a=>{if(!a.toolCalls)return a;const o=a.toolCalls.map(l=>l.id===r?{...l,result:n,isError:i}:l);return{...a,toolCalls:o}})}function ca(t,r,n,i){return t.map(a=>{if(!a.toolCalls)return a;const o=a.toolCalls.map(l=>l.name==="dispatch_agent"&&l.arguments.subSessionId===r?{...l,arguments:{...l.arguments,subAgentStatus:n,subAgentDetail:i}}:l);return{...a,toolCalls:o}})}function ua(t,r,n){return t.map(i=>{if(!i.toolCalls)return i;const a=i.toolCalls.map(o=>o.name==="dispatch_agent"&&o.arguments.subSessionId===r?{...o,arguments:{...o.arguments,subAgentProgress:(o.arguments.subAgentProgress?o.arguments.subAgentProgress+`
237
- `+n:n).split(`
238
- `).slice(-30).join(`
239
- `)}}:o);return{...i,toolCalls:a}})}function pa(t,r,n){return t.map(i=>i.id===r?n(i):i)}function fa(t,r){const n=t.findIndex(i=>{var a,o;return(o=(a=i.presentation)==null?void 0:a.reasoning)==null?void 0:o.some(l=>l.itemId===r.itemId)});return n<0?[...t,{id:`native-reasoning:${r.itemId}`,role:"assistant",content:"",presentation:{reasoning:ra(void 0,r)},timestamp:Date.now()}]:t.map((i,a)=>{var o;return a===n?{...i,presentation:{...i.presentation,reasoning:ra((o=i.presentation)==null?void 0:o.reasoning,r)}}:i})}const ge=Ha((t,r)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(n,i)=>t(a=>{const o=i??a.sessionId??void 0,l=o&&o!==a.sessionId?a.messages:oa(a.messages,n),p=o?{...a.messagesBySession,[o]:oa(a.messagesBySession[o]??(o===a.sessionId?a.messages:[]),n)}:a.messagesBySession;return{messages:l,messagesBySession:p,currentText:o&&o!==a.sessionId?a.currentText:""}}),appendText:(n,i)=>t(a=>{if(!n)return a;const o=i??a.sessionId??void 0,l=o&&o!==a.sessionId?a.messages:la(a.messages,n),p=o?{...a.messagesBySession,[o]:la(a.messagesBySession[o]??(o===a.sessionId?a.messages:[]),n)}:a.messagesBySession;return{messages:l,messagesBySession:p,currentText:o&&o!==a.sessionId?a.currentText:a.currentText+n}}),setRunningSession:n=>t({runningSessionId:n}),setSessionId:n=>t({sessionId:n}),updateToolResult:(n,i,a,o)=>t(l=>{const p=o??l.sessionId??void 0,g=p&&p!==l.sessionId?l.messages:da(l.messages,n,i,a),h=p?{...l.messagesBySession,[p]:da(l.messagesBySession[p]??(p===l.sessionId?l.messages:[]),n,i,a)}:l.messagesBySession;return{messages:g,messagesBySession:h}}),setMessages:(n,i)=>t(a=>{const o=i??a.sessionId??void 0,l=!o||o===a.sessionId;return{messages:l?n:a.messages,messagesBySession:o?{...a.messagesBySession,[o]:n}:a.messagesBySession,currentText:l?"":a.currentText}}),getMessagesForSession:n=>r().messagesBySession[n]??[],setContextUsage:(n,i)=>t(a=>{const o=i??a.sessionId??void 0;return o?{contextUsageBySession:{...a.contextUsageBySession,[o]:n}}:a}),getContextUsageForSession:n=>r().contextUsageBySession[n],applyRuntimeProgress:(n,i)=>t(a=>{const o=i??a.sessionId??void 0;return o?{runtimeProgressBySession:{...a.runtimeProgressBySession,[o]:eo(a.runtimeProgressBySession[o]??[],n)}}:a}),setRuntimeProgress:(n,i)=>t(a=>{const o=i??a.sessionId??void 0;return o?{runtimeProgressBySession:{...a.runtimeProgressBySession,[o]:n}}:a}),clearRuntimeProgress:n=>t(i=>{var p;const a=n??i.sessionId??void 0;if(!a||!((p=i.runtimeProgressBySession[a])!=null&&p.length))return i;const{[a]:o,...l}=i.runtimeProgressBySession;return{runtimeProgressBySession:l}}),applyNativeSubagentActivity:(n,i)=>t(a=>{const o=i??a.sessionId??void 0;return o?{nativeSubagentsBySession:{...a.nativeSubagentsBySession,[o]:{...a.nativeSubagentsBySession[o]??{},[n.parentToolCallId]:n}}}:a}),setNativeSubagentActivities:(n,i)=>t(a=>{const o=i??a.sessionId??void 0;return o?{nativeSubagentsBySession:{...a.nativeSubagentsBySession,[o]:Object.fromEntries(n.map(l=>[l.parentToolCallId,l]))}}:a}),applyReasoningSummary:(n,i)=>t(a=>{const o=i??a.sessionId??void 0,l=o&&o!==a.sessionId?a.messages:fa(a.messages,n),p=o?{...a.messagesBySession,[o]:fa(a.messagesBySession[o]??(o===a.sessionId?a.messages:[]),n)}:a.messagesBySession;return{messages:l,messagesBySession:p}}),updateMessage:(n,i,a)=>t(o=>{const l=a??o.sessionId??void 0,p=l&&l!==o.sessionId?o.messages:pa(o.messages,n,i),g=l?{...o.messagesBySession,[l]:pa(o.messagesBySession[l]??(l===o.sessionId?o.messages:[]),n,i)}:o.messagesBySession;return{messages:p,messagesBySession:g}}),updateSubAgentStatus:(n,i,a,o)=>t(l=>{const p=o??l.sessionId??void 0,g=p&&p!==l.sessionId?l.messages:ca(l.messages,n,i,a),h=p?{...l.messagesBySession,[p]:ca(l.messagesBySession[p]??(p===l.sessionId?l.messages:[]),n,i,a)}:l.messagesBySession;return{messages:g,messagesBySession:h}}),updateSubAgentProgress:(n,i,a)=>t(o=>{const l=a??o.sessionId??void 0,p=l&&l!==o.sessionId?o.messages:ua(o.messages,n,i),g=l?{...o.messagesBySession,[l]:ua(o.messagesBySession[l]??(l===o.sessionId?o.messages:[]),n,i)}:o.messagesBySession;return{messages:p,messagesBySession:g}}),clearMessages:n=>t(i=>{const a=n??i.sessionId??void 0;if(!a)return{messages:[],currentText:""};const{[a]:o,...l}=i.messagesBySession,{[a]:p,...g}=i.contextUsageBySession,{[a]:h,...m}=i.runtimeProgressBySession,{[a]:b,...k}=i.nativeSubagentsBySession;return{messages:a===i.sessionId?[]:i.messages,messagesBySession:l,contextUsageBySession:g,runtimeProgressBySession:m,nativeSubagentsBySession:k,currentText:a===i.sessionId?"":i.currentText}}),setTodos:n=>t({todos:n}),setCronTasks:n=>t({cronTasks:n})}));function fi(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function to(){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 Ql(){return to()!==null||fi()!==null}function Kl(t){var o,l;const r=to();if(r){let p=!1,g=()=>{},h=()=>{};const m=()=>{var b;p||(p=!0,g(),h(),(b=t.onEnd)==null||b.call(t))};return g=r.onDictation(({text:b,isFinal:k})=>{const I=b.trim();I&&(k?(t.onFinal(I),m()):t.onInterim(I))}),h=r.onDictationError(b=>{var k;(k=t.onError)==null||k.call(t,b),m()}),r.dictationStart().then(b=>{var k;b.ok||((k=t.onError)==null||k.call(t,b.reason||"无法启动语音识别"),m())}).catch(()=>{var b;(b=t.onError)==null||b.call(t,"无法启动语音识别"),m()}),{stop:()=>{r.dictationStop()}}}const n=fi();if(!n)return(o=t.onError)==null||o.call(t,"当前环境不支持语音识别"),null;const i=new n;i.lang=t.lang??"zh-CN",i.continuous=!1,i.interimResults=!0;let a="";i.onresult=p=>{let g="";for(let h=p.resultIndex;h<p.results.length;h++){const m=p.results[h];m.isFinal?a+=m[0].transcript:g+=m[0].transcript}g&&t.onInterim(a+g)},i.onerror=p=>{var g;p.error!=="no-speech"&&p.error!=="aborted"&&((g=t.onError)==null||g.call(t,`语音识别失败:${p.error??"未知错误"}`))},i.onend=()=>{var p;a&&t.onFinal(a.trim()),(p=t.onEnd)==null||p.call(t)};try{i.start()}catch{return(l=t.onEnd)==null||l.call(t),null}return{stop:()=>i.stop()}}function Gl(t){var l;const r=fi();if(!r)return(l=t.onError)==null||l.call(t,"当前环境不支持语音唤醒"),null;let n=!1,i=null,a=null;const o=()=>{if(!n){i=new r,i.lang=t.lang??"zh-CN",i.continuous=!0,i.interimResults=!0,i.onresult=p=>{var m,b,k;const g=p.results[p.results.length-1],h=(b=(m=g==null?void 0:g[0])==null?void 0:m.transcript)==null?void 0:b.trim();h&&(g.isFinal&&((k=t.onHeard)==null||k.call(t,h)),h.includes(t.wakeWord)&&t.onWake(h))},i.onerror=p=>{var g;p.error==="not-allowed"&&((g=t.onError)==null||g.call(t,"麦克风权限被拒绝,语音唤醒已停用"),n=!0)},i.onend=()=>{n||(a=setTimeout(o,400))};try{i.start()}catch{a=setTimeout(o,800)}}};return o(),{stop:()=>{n=!0,a&&clearTimeout(a);try{i==null||i.abort()}catch{}}}}function Wr(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function as(t,r){return r(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const Zl={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function Yl(t){const r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(r.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const n=new Float32Array(r.byteLength/2),i=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let a=0;a<n.length;a+=1)n[a]=i.getInt16(a*2,!0)/32768;return n}class Jl{constructor(r,n=Zl){this.api=r,this.dependencies=n,this.context=null,this.node=null,this.ready=null,this.current=null}start(r){var i;this.current&&!this.current.acknowledged&&((i=this.node)==null||i.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const n={metadata:r,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=n,this.ensureReady().then(()=>{if(!(this.current!==n||!this.node)){this.node.port.postMessage({type:"start",generation:r.generation,sampleRate:r.sampleRate});for(const a of n.pending)this.postSamples(r.generation,a);n.pending=[],n.pendingSamples=0,n.finished&&this.node.port.postMessage({type:"finish",generation:r.generation})}}).catch(a=>this.fail(n,a))}enqueue(r,n){const i=this.current;if(!i||i.metadata.generation!==r||i.acknowledged)return;let a;try{a=Yl(n)}catch(o){this.fail(i,o);return}if(this.node){this.postSamples(r,a);return}if(i.pendingSamples+a.length>i.metadata.sampleRate){this.fail(i,new Error("TTS PCM queue overflow"));return}i.pending.push(a),i.pendingSamples+=a.length}finish(r){var i;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||(n.finished=!0,(i=this.node)==null||i.port.postMessage({type:"finish",generation:r}))}flush(r){var i;const n=this.current;!n||n.metadata.generation!==r||n.acknowledged||((i=this.node)==null||i.port.postMessage({type:"flush",generation:r}),n.pending=[],n.pendingSamples=0,this.acknowledge(n))}dispose(){var r,n;this.current&&this.flush(this.current.metadata.generation),(r=this.node)==null||r.disconnect(),this.node=null,(n=this.context)==null||n.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const r=this.dependencies.createContext();this.context=r,await r.audioWorklet.addModule(this.dependencies.workletUrl);const n=this.dependencies.createNode(r);n.port.onmessage=i=>this.onWorkletMessage(i.data),n.connect(r.destination),this.node=n,r.state!=="running"&&await r.resume()})(),this.ready)}postSamples(r,n){var i;(i=this.node)==null||i.port.postMessage({type:"chunk",generation:r,samples:n},[n.buffer])}onWorkletMessage(r){const n=this.current;if(!(!n||r.generation!==n.metadata.generation)){if(r.type==="drained"||r.type==="stopped"){this.acknowledge(n);return}r.type==="overflow"&&this.fail(n,new Error("TTS AudioWorklet buffer overflow"))}}fail(r,n){this.current!==r||r.acknowledged||(console.error("[tts] PCM playback failed",n),r.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(r.metadata.generation))}acknowledge(r){this.current!==r||r.acknowledged||(r.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(r.metadata.generation))}}function ir(t){var m;const r=(t==null?void 0:t.messages)??[],n=(t==null?void 0:t.events)??[],i=new Set(n.filter(b=>b.type==="approval_resolved"&&b.questionId).map(b=>b.questionId)),a=new Map;for(const b of n)b.type==="tool_result"&&((m=b.result)!=null&&m.toolCallId)&&a.set(b.result.toolCallId,{content:b.result.content??"",isError:b.result.isError});const o=r.filter(b=>(b.role==="user"||b.role==="assistant"||b.role==="tool")&&b.name!=="__interrupt__").map(nd),l=new Map;for(const b of o)b.role==="tool"&&b.toolCallId&&l.set(b.toolCallId,b);let p=o.filter(b=>b.role!=="tool").map(b=>{var k;return b.isCompactionSummary?b:b.role==="assistant"&&((k=b.toolCalls)!=null&&k.length)?{...b,toolCalls:b.toolCalls.map(I=>{const M=l.get(I.id);if(M)return{...I,result:M.content};const O=a.get(I.id);return O?{...I,result:O.content,isError:O.isError}:I})}:b.role==="user"&&b.name&&b.name!=="__compaction_checkpoint__"&&!b.name.startsWith("__native_")?{...b,agentName:b.name}:b});const g=rd(n);if(!p.some(b=>b.role==="assistant"&&!b.isCompactionSummary)&&g){const b=p.findLastIndex(k=>k.role==="user"&&!k.isCompactionSummary);p=b>=0?[...p.slice(0,b+1),g,...p.slice(b+1)]:[...p,g]}const h=new Set(p.flatMap(b=>{var k;return(k=b.askUser)!=null&&k.questionId?[b.askUser.questionId]:[]}));for(const b of n)b.type!=="ask_user"||!b.questionId||i.has(b.questionId)||h.has(b.questionId)||(h.add(b.questionId),p.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 p}function Xl(t,r){if(r.length===0)return t;if(t.length===0)return r;const n=t.map(ai),i=r.map(ai),a=Math.max(0,t.length-r.length),o=ed(t,r,a);let l={currentStart:a,length:0,distance:1/0};for(let m=0;m<n.length;m++)for(let b=0;b<i.length;b++){if(n[m]!==i[b])continue;const k=m-b;if(k<0)continue;let I=0;for(;m+I<n.length&&b+I<i.length&&n[m+I]===i[b+I];)I+=1;const M=Math.abs(k-a);(I>l.length||I===l.length&&M<l.distance)&&(l={currentStart:k,length:I,distance:M})}const p=o??(l.length>0?l.currentStart:a),g=r.map((m,b)=>{var M,O;const k=t[p+b];if(!k||!td(k,m,i[b]))return m;const I=(O=(M=m.presentation)==null?void 0:M.attachments)==null?void 0:O.some(_=>_.dataUrl);return{...m,id:m.id.startsWith("history-message.v1.")?m.id:k.id,timestamp:k.timestamp,images:I?void 0:m.images??k.images}}),h=t.filter(m=>m.isQueued);return[...t.slice(0,p).filter(m=>!m.isQueued),...g,...h]}function ed(t,r,n){const i=r[0];if((i==null?void 0:i.role)!=="user")return null;const a=gs(i);let o=null;for(let l=0;l<t.length;l+=1){if(t[l].role!=="user"||t[l].isQueued||gs(t[l])!==a)continue;const p=Math.abs(l-n);(!o||p<o.distance)&&(o={start:l,distance:p})}return(o==null?void 0:o.start)??null}function td(t,r,n){return ai(t)===n?!0:t.role==="user"&&r.role==="user"&&gs(t)===gs(r)}function gs(t){var r;return JSON.stringify({role:t.role,content:t.content,name:(r=t.name)!=null&&r.startsWith("__native_")?void 0:t.name,agentName:t.agentName,isCompactionSummary:t.isCompactionSummary})}function ai(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,name:t.name,agentName:t.agentName,presentation:t.role==="user"?void 0:t.presentation,isCompactionSummary:t.isCompactionSummary})}function nd(t){var r;if(t.name==="__compaction_checkpoint__"){let n="";try{n=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:n,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:t.historyId??crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(r=t.toolCalls)!=null&&r.length?t.toolCalls:void 0,toolCallId:t.toolCallId,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function rd(t){var a;let r="";const n=[],i=new Map;for(const o of t){if(o.type==="text_chunk"&&o.text&&(r+=o.text),o.type==="tool_call"&&o.toolCall){const l={id:o.toolCall.id,name:o.toolCall.name,arguments:o.toolCall.arguments};n.push(l),i.set(l.id,l)}if(o.type==="tool_result"&&((a=o.result)!=null&&a.toolCallId)){const l=i.get(o.result.toolCallId);l&&(l.result=o.result.content??"",l.isError=o.result.isError)}}return!r.trim()&&n.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:n.length>0?n:void 0,timestamp:Date.now()}}class sd{constructor(){this.slot=null}prefetch(r,n,i){return this.getOrStart(r,n,i).promise}async consume(r,n,i){const a=this.getOrStart(r,n,i);try{return await a.promise}finally{this.slot===a&&(this.slot=null)}}invalidate(){this.slot=null}getOrStart(r,n,i){var l;if(((l=this.slot)==null?void 0:l.sessionId)===r&&this.slot.cursor===n)return this.slot;let a;try{a=i()}catch(p){a=Promise.reject(p)}const o={sessionId:r,cursor:n,promise:a};return this.slot=o,a.catch(()=>{this.slot===o&&(this.slot=null)}),o}}const id=60;function ga(t,r,n,i){if(i<=1||n<=0)return 0;const a=Math.max(0,Math.min(1,(t-r)/n));return Math.round(a*(i-1))}function ad(t){const r=Math.min(Math.max(0,t),id);return r<=1?r===1?[0]:[]:Array.from({length:r},(n,i)=>Math.round(i/(r-1)*(t-1)))}function od(t,r,n){if(n<=0)return null;const i=Math.max(5,Math.round(n/10));return r==="ArrowUp"||r==="ArrowLeft"?Math.max(0,t-1):r==="ArrowDown"||r==="ArrowRight"?Math.min(n-1,t+1):r==="PageUp"?Math.max(0,t-i):r==="PageDown"?Math.min(n-1,t+i):r==="Home"?0:r==="End"?n-1:null}function ld({entries:t,activeMessageId:r,loadingMessageId:n,onActivate:i}){const a=t.findIndex(_=>_.messageId===r),o=a>=0?a:Math.max(0,t.length-1),[l,p]=d.useState(o),[g,h]=d.useState(!1),m=d.useRef(!1),b=d.useMemo(()=>ad(t.length),[t.length]);if(d.useEffect(()=>p(o),[o]),t.length<2)return null;const k=Math.min(l,t.length-1),I=t[k],M=n===I.messageId,O=(_,F)=>{const y=F.getBoundingClientRect();p(ga(_,y.top,y.height,t.length))};return e.jsxs("div",{className:`query-navigation-rail${g?" query-navigation-rail--open":""}`,role:"slider",tabIndex:0,"aria-label":"用户消息导航","aria-orientation":"vertical","aria-valuemin":1,"aria-valuemax":t.length,"aria-valuenow":I.ordinal,"aria-valuetext":`第 ${I.ordinal} 条:${I.preview}`,"aria-busy":M||void 0,onPointerEnter:_=>{h(!0),O(_.clientY,_.currentTarget)},onPointerMove:_=>{_.pointerType==="touch"&&!m.current||O(_.clientY,_.currentTarget)},onPointerLeave:()=>{m.current||h(!1)},onPointerDown:_=>{m.current=!0,h(!0),_.currentTarget.setPointerCapture(_.pointerId),O(_.clientY,_.currentTarget)},onPointerUp:_=>{O(_.clientY,_.currentTarget);const F=ga(_.clientY,_.currentTarget.getBoundingClientRect().top,_.currentTarget.getBoundingClientRect().height,t.length);m.current=!1,_.currentTarget.releasePointerCapture(_.pointerId),i(t[F]),_.pointerType==="touch"&&h(!1)},onPointerCancel:()=>{m.current=!1,h(!1)},onFocus:()=>h(!0),onBlur:()=>h(!1),onKeyDown:_=>{if(_.key==="Enter"){_.preventDefault(),i(I);return}const F=od(k,_.key,t.length);F!==null&&(_.preventDefault(),p(F))},children:[e.jsxs("div",{className:"query-navigation-rail__track","aria-hidden":"true",children:[b.map(_=>e.jsx("span",{className:`query-navigation-rail__tick${_===k?" is-selected":""}${t[_].messageId===r?" is-active":""}`},_)),e.jsx("span",{className:"query-navigation-rail__marker",style:{top:`${k/Math.max(1,t.length-1)*100}%`}})]}),M&&e.jsx("span",{className:"query-navigation-rail__loading",role:"status","aria-label":"正在定位消息",children:e.jsx(dn,{size:14,"aria-hidden":"true"})}),g&&e.jsxs("div",{className:"query-navigation-rail__preview",role:"status",children:[e.jsxs("span",{children:[I.ordinal," / ",t.length]}),e.jsx("p",{children:I.preview})]})]})}const dd=/^(?:load failed|failed to fetch|network request failed|networkerror when attempting to fetch resource\.?|the network connection was lost\.?|fetch failed)$/i;function no(t){return t instanceof Error&&t.name!=="AbortError"&&dd.test(t.message.trim())}function cd(t){return no(t)?"网络连接中断,会话加载失败,请重新加载":t instanceof Error?t.message:"会话加载失败"}async function ud(t,r={}){const n=Math.max(1,Math.floor(r.maxAttempts??4)),i=Math.max(0,r.baseDelayMs??500),a=r.sleep??(o=>new Promise(l=>{setTimeout(l,o)}));for(let o=1;o<=n;o+=1)try{return await t()}catch(l){if(o===n||!no(l))throw l;await a(i*2**(o-1))}throw new Error("会话加载失败")}const pd=2048,fd=2*1024*1024,gd=.85;function hd(t,r,n=pd){const i=Math.max(t,r);if(i<=n)return{width:t,height:r};const a=n/i;return{width:Math.max(1,Math.round(t*a)),height:Math.max(1,Math.round(r*a))}}async function ha(t,r=xd){if(t.type.toLowerCase()==="image/gif")return t;let n=null;try{n=await r.decode(t);const i=hd(n.width,n.height);if(!(i.width!==n.width||i.height!==n.height)&&t.size<=fd)return t;const o=t.type.toLowerCase()==="image/jpeg"?"image/jpeg":"image/webp",l=await r.encode(n,i.width,i.height,o,gd);return l&&l.size<t.size?l:t}catch{return t}finally{n==null||n.dispose()}}const xd={decode(t){return new Promise((r,n)=>{const i=URL.createObjectURL(t),a=new Image;let o=!1;const l=()=>URL.revokeObjectURL(i);a.onload=()=>{o=!0,r({source:a,width:a.naturalWidth,height:a.naturalHeight,dispose:l})},a.onerror=()=>{o||l(),n(new Error("无法解码图片"))},a.src=i})},encode(t,r,n,i,a){const o=document.createElement("canvas");o.width=r,o.height=n;const l=o.getContext("2d");return l?(l.drawImage(t.source,0,0,r,n),new Promise(p=>o.toBlob(p,i,a))):Promise.resolve(null)}};function md(t){return t==="customer-agent"||t==="claude-code"}function bd(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),Object.assign(r.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(r);try{return r.focus(),r.select(),r.setSelectionRange(0,r.value.length),document.execCommand("copy")}catch{return!1}finally{r.remove()}}async function Ds(t){const r=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(r==null?void 0:r.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await r.writeText(t),!0}catch{}return bd(t)}const yd="agentroam:draft:";function hs(t){return`${yd}${t}`}function vd(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(hs(t))??""}catch{return""}}function Bs(t,r){if(!(!t||typeof window>"u"))try{r?window.localStorage.setItem(hs(t),r):window.localStorage.removeItem(hs(t))}catch{}}function wd(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(hs(t))}catch{}}const jd="agent-webapp:artifact-open:v1";let xa=0;function ma(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function ro(t,r){const n=t.trim();if(!n||/[\0\r\n]/.test(n))return null;if(ma(n))return n;if(!r||!ma(r))return null;const i=n.replaceAll("\\","/").split("/").filter(o=>o&&o!==".");if(i.length===0||i.some(o=>o===".."))return null;const a=/^[A-Za-z]:[\\/]/.test(r)||r.startsWith("\\\\")?"\\":"/";return`${r.replace(/[\\/]+$/,"")}${a}${i.join(a)}`}function Wn(t,r=window){return r.parent===r?!1:(xa+=1,r.parent.postMessage({type:jd,requestId:xa,path:t},r.location.origin),!0)}function kd(t){var r;return((r=[...t].reverse().find(n=>n.role==="user"&&!n.isQueued))==null?void 0:r.id)??null}function Fs(t,r){const n=t.filter(o=>!o.isQueued),i=new Map(t.filter(o=>o.isQueued&&o.queueItemId).map(o=>[o.queueItemId,o])),a=r.filter(o=>o.kind==="message").map(o=>{var p,g;const l=i.get(o.id);return{...l??{},id:o.sourceMessageId||(l==null?void 0:l.id)||o.id,role:"user",content:o.objective,timestamp:(l==null?void 0:l.timestamp)??o.createdAt,agentName:(p=o.messagePayload)==null?void 0:p.agentName,images:(g=o.messagePayload)==null?void 0:g.images,isQueued:!0,queueItemId:o.id}});return[...n,...a]}function $s(t){return t.queued.filter(r=>r.kind==="message")}function ba(t){var r;return{active:((r=t.active)==null?void 0:r.kind)==="message"?null:t.active,queued:t.queued.filter(n=>n.kind!=="message"),history:t.history.filter(n=>n.kind!=="message")}}function Sd(t,r,n){if(r===n)return t;const i=t.filter(h=>h.isQueued),a=i.findIndex(h=>h.id===r),o=i.findIndex(h=>h.id===n);if(a<0||o<0)return t;const l=[...i],[p]=l.splice(a,1);l.splice(o,0,p);let g=0;return t.map(h=>h.isQueued?l[g++]:h)}function Id(t,r){return((t==null?void 0:t.agentType)??r)!=="customer-agent"}function gi(t){return(t==null?void 0:t.agentType)!==void 0&&t.agentType!=="customer-agent"&&t.status==="running"}function Cd(t){return gi(t)&&(t==null?void 0:t.occupancy)==="owned-externally"}function so(t){return gi(t)&&(t==null?void 0:t.occupancy)!=="owned-externally"}function Ad(t,r){return r||so(t)}function Rd(t,r,n){return!!(r&&t&&t.agentType!=="customer-agent")}function os(t,r){return t.find(n=>n.id===r)??null}const ms=Ha((t,r)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(n,i)=>t(a=>{const o={...a,[n]:i};return o.isConfigured=!!(o.apiKey&&o.modelId),o}),loadFromSystem:async()=>{if(window.agentApi)try{const n=await window.agentApi.getSettings(),i=n.profiles??[],a=n.activeProfileId??"",o=os(i,a);t({modelProvider:(o==null?void 0:o.provider)??n.modelProvider??"anthropic",modelId:(o==null?void 0:o.modelId)??n.modelId??"claude-sonnet-4-6",apiKey:(o==null?void 0:o.apiKey)??n.apiKey??"",baseUrl:(o==null?void 0:o.baseUrl)??n.baseUrl??"",maxIterations:n.maxIterations??10,contextWindow:n.contextWindow??100,workingDirectory:n.workingDirectory??"/",isConfigured:!!(((o==null?void 0:o.apiKey)??n.apiKey)&&((o==null?void 0:o.modelId)??n.modelId)),profiles:i,activeProfileId:a,reasoningEffort:["off","low","medium","high"].includes(n.reasoningEffort??"")?n.reasoningEffort:"off"})}catch(n){console.error("Failed to load settings:",n)}},saveToSystem:async()=>{if(!window.agentApi)return;const n=r();await window.agentApi.saveSettings({modelProvider:n.modelProvider,modelId:n.modelId,apiKey:n.apiKey,baseUrl:n.baseUrl,maxIterations:n.maxIterations,contextWindow:n.contextWindow,workingDirectory:n.workingDirectory,isConfigured:n.isConfigured,profiles:n.profiles,activeProfileId:n.activeProfileId,reasoningEffort:n.reasoningEffort})},addProfile:n=>{const a={id:crypto.randomUUID(),...n};t(o=>({profiles:[...o.profiles,a]}))},updateProfile:(n,i)=>{t(o=>({profiles:o.profiles.map(l=>l.id===n?{...l,...i}:l)}));const a=r();if(a.activeProfileId===n){const o=os(a.profiles,n);o&&t({modelProvider:o.provider,modelId:o.modelId,apiKey:o.apiKey,baseUrl:o.baseUrl,isConfigured:!!(o.apiKey&&o.modelId)})}},deleteProfile:n=>{t(i=>{var p;const a=i.profiles.filter(g=>g.id!==n),o=i.activeProfileId===n?((p=a[0])==null?void 0:p.id)??"":i.activeProfileId,l=os(a,o);return{profiles:a,activeProfileId:o,...l?{modelProvider:l.provider,modelId:l.modelId,apiKey:l.apiKey,baseUrl:l.baseUrl,isConfigured:!!(l.apiKey&&l.modelId)}:{},...l?{}:{modelProvider:"anthropic",modelId:"",apiKey:"",baseUrl:"",isConfigured:!1}}})},setActiveProfileLocal:n=>{const i=r(),a=os(i.profiles,n);a&&t({activeProfileId:n,modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})},switchActiveProfile:async n=>{r().setActiveProfileLocal(n),window.agentApi&&await window.agentApi.setActiveProfile(n)}}));function cr(t){return t.result!==void 0}function Os(t){return t.every(cr)}const hi=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),io=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),ao=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]),Td=new Set(["Read","read_file"]),Md=new Set(["Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]);function xi(t){return hi.has(t)?"command":io.has(t)?"file":ao.has(t)?"search":"generic"}function mi(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 Ed(t){var r;return((r=mi(t))==null?void 0:r.done)??null}function oo(t){return hi.has(t)?"终端":Td.has(t)?"查阅":Md.has(t)?"写入":ao.has(t)?"查阅":t==="Skill"?"技能":t==="Task"||t==="dispatch_agent"||t==="Agent"?"子任务":t==="TodoWrite"?"任务":t.startsWith("mcp__")||t.includes(":")?"工具":null}function ya(t){return t.replace(/\\/g,"/").split("/").pop()??t}function Us(t,r=60){const n=(t??"").split(`
240
- `)[0].trim();return n.length>r?n.slice(0,r)+"…":n}function Nd(t,r){if(hi.has(t))return Us(String(r.command??""));if(t==="apply_patch"){const i=(Array.isArray(r.changes)?r.changes:[]).map(a=>ya(String((a==null?void 0:a.path)??""))).filter(Boolean);return i.length?i.length<=3?i.join("、"):`${i.slice(0,3).join("、")} 等 ${i.length} 个文件`:null}return io.has(t)?r.file_path?ya(String(r.file_path)):null:t==="Glob"||t==="glob_search"?String(r.pattern??"")||null:t==="Grep"||t==="grep_search"?String(r.pattern??r.query??"")||null:t==="Skill"?String(r.skill??"")||null:t==="Task"?Us(String(r.description??r.task??""),80)||null:t==="WebSearch"?Us(String(r.query??"")):t==="WebFetch"?String(r.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function zd(t,r){return Math.max(0,Math.floor((r-t)/1e3))}function bi({startedAt:t}){const[r,n]=d.useState(()=>Date.now());return d.useEffect(()=>{n(Date.now());const i=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(i)},[t]),e.jsxs("span",{className:"activity-elapsed-time",children:[" · 持续了 ",zd(t,r)," 秒"]})}function lo({progress:t,compact:r=!1,startedAt:n}){const i=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),a=[t.label,i].filter(Boolean).join(","),o=!r&&t.phase==="thinking",l=!r&&t.phase==="status",p=o&&n!==void 0&&i===void 0;return e.jsxs("div",{className:`runtime-progress-row${r?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":a,children:[o?e.jsx("span",{className:"runtime-progress-row__brain","aria-hidden":"true",children:e.jsx(ui,{size:17,strokeWidth:1.8})}):l?e.jsx("span",{className:"runtime-progress-row__status-icon","aria-hidden":"true",children:e.jsx(dn,{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}),i&&e.jsx("span",{className:"runtime-progress-row__detail",children:i}),p&&e.jsx(bi,{startedAt:n})]})}function ur({isDone:t,isError:r,color:n,size:i=11}){return t?r?e.jsx(fl,{size:i,color:n,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(cs,{size:i,color:n,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(dn,{size:i,color:n,strokeWidth:2.5,style:{animation:"spin 1s linear infinite",flexShrink:0},"aria-hidden":"true"})}function Fr({name:t,color:r,size:n=14}){const i=xi(t);return i==="command"?e.jsx(zl,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):i==="search"?e.jsx(Ga,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):i==="file"?t==="Read"||t==="read_file"?e.jsx(xs,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Qa,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="Skill"?e.jsx(Nl,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="TodoWrite"?e.jsx(Al,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):t==="Task"||t==="dispatch_agent"||t==="Agent"?e.jsx(Wl,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Za,{size:n,color:r,strokeWidth:1.8,"aria-hidden":"true"})}function bs({statusColor:t,isDone:r,expanded:n,onToggle:i,header:a,children:o,maxBodyHeight:l=600,primaryAction:p,primaryActionLabel:g,primaryActionTitle:h}){const m=e.jsxs("button",{type:"button",className:"tool-call-shell__header",...p?{onClick:p,"aria-label":g,title:h}:{onClick:i,"aria-expanded":n},style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:b=>b.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:b=>b.currentTarget.style.background="var(--bg-deep)",children:[a,!p&&e.jsx(dr,{className:"tool-call-shell__chevron",size:12,color:"var(--text-muted)",strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(90deg)":"rotate(0deg)",flexShrink:0},"aria-hidden":"true"})]});return e.jsxs("div",{className:"tool-call-shell",style:{marginTop:4,borderRadius:9,border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-deepest)",fontSize:12,minWidth:0},children:[e.jsxs("div",{className:"tool-call-shell__row",style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{className:"tool-call-shell__status",style:{width:3,flexShrink:0,background:t,animation:r?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),m,p&&e.jsx("button",{type:"button",className:"tool-call-shell__disclosure",onClick:i,"aria-expanded":n,"aria-label":n?"收起工具详情":"展开工具详情",title:n?"收起工具详情":"展开工具详情",children:e.jsx(dr,{className:"tool-call-shell__chevron",size:12,strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:n?"rotate(90deg)":"rotate(0deg)"},"aria-hidden":"true"})})]}),n&&e.jsx("div",{className:"tool-call-shell__body",style:{overflow:"hidden",maxHeight:l,opacity:1,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{className:"tool-call-shell__body-content",style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:o})})]})}function Br({label:t,color:r="var(--text-muted)",bg:n="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:n,color:r,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function Gt(t){return t.replace(/\\/g,"/").split("/").pop()??t}function co(t){return t?t.split(`
241
- `).length:0}function uo(t,r){const n=t.split(`
242
- `),i=r.split(`
243
- `);if(n.length*i.length>2e5)return i.map((I,M)=>({type:"added",text:I,lineNo:M+1}));const a=n.length,o=i.length,l=Array.from({length:a+1},()=>new Array(o+1).fill(0));for(let I=1;I<=a;I++)for(let M=1;M<=o;M++)l[I][M]=n[I-1]===i[M-1]?l[I-1][M-1]+1:Math.max(l[I-1][M],l[I][M-1]);const p=[];let g=a,h=o;for(;g>0&&h>0;)n[g-1]===i[h-1]?(p.unshift([g-1,h-1]),g--,h--):l[g-1][h]>=l[g][h-1]?g--:h--;const m=[];let b=0,k=0;for(const[I,M]of p){for(;b<I;)m.push({type:"removed",text:n[b],lineNo:b+1}),b++;for(;k<M;)m.push({type:"added",text:i[k],lineNo:k+1}),k++;m.push({type:"same",text:n[b],lineNo:b+1}),b++,k++}for(;b<a;)m.push({type:"removed",text:n[b],lineNo:b+1}),b++;for(;k<o;)m.push({type:"added",text:i[k],lineNo:k+1}),k++;return m}function po({content:t,maxHeight:r=320}){const n=t.split(`
244
- `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:n.map((i,a)=>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:a+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:i||" "})]},a))})]})})}function fo({diff:t,maxHeight:r=360}){if(t.filter(p=>p.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const i=new Set(t.map((p,g)=>p.type!=="same"?g:-1).filter(p=>p>=0)),a=new Set;i.forEach(p=>{for(let g=Math.max(0,p-3);g<=Math.min(t.length-1,p+3);g++)a.add(g)});const o=[];let l=-1;return[...a].sort((p,g)=>p-g).forEach(p=>{l>=0&&p>l+1&&o.push("ellipsis"),o.push({diffLine:t[p],diffIdx:p}),l=p}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:r,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:o.map((p,g)=>{if(p==="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${g}`);const{diffLine:h}=p,m=h.type==="added"?"rgba(5,150,105,0.08)":h.type==="removed"?"rgba(220,38,38,0.07)":"transparent",b=h.type==="added"?"+":h.type==="removed"?"−":" ",k=h.type==="added"?"var(--success)":h.type==="removed"?"var(--danger)":"transparent",I=h.type==="added"?"#059669":h.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:m},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:k,fontWeight:700,userSelect:"none"},children:b}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:h.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:I,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:h.text||" "})]},g)})})]})})}function _d({toolCall:t,beforeContent:r,previewPath:n}){const[i,a]=d.useState(!1),[o,l]=d.useState("content"),p=t.arguments.file_path??"",g=t.arguments.content??"",h=co(g),m=t.isError,b=cr(t),k=b?m?"var(--danger)":"var(--success)":"var(--accent)",I=d.useMemo(()=>r&&g?uo(r,g):null,[r,g]),M=d.useMemo(()=>I?{added:I.filter(F=>F.type==="added").length,removed:I.filter(F=>F.type==="removed").length}:null,[I]),O=m?"var(--danger)":b?"var(--text-muted)":"var(--accent)",_=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Fr,{name:t.name,color:O})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:p,children:Gt(p)}),e.jsx(Br,{label:`${h} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),M&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[M.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",M.added]}),M.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",M.removed]})]}),(!b||m)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:k},children:[e.jsx(ur,{isDone:b,isError:m,color:k}),m&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(bs,{statusColor:k,isDone:b,expanded:i,onToggle:()=>a(!i),header:_,primaryAction:n?()=>Wn(n):void 0,primaryActionLabel:n?`预览文件 ${Gt(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:p}),I&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(F=>e.jsx("button",{onClick:()=>l(F),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:o===F?"var(--accent-dim)":"transparent",color:o===F?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:F==="content"?"文件内容":"变更行"},F))}),o==="diff"&&I?e.jsx(fo,{diff:I}):e.jsx(po,{content:g}),m&&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 Wd({toolCall:t,previewPath:r}){const[n,i]=d.useState(!1),a=t.arguments.file_path??"",o=t.arguments.startLine,l=t.arguments.endLine,p=t.arguments.offset,g=t.arguments.limit,h=t.result??"",m=co(h),b=t.isError,k=cr(t),I=k?b?"var(--danger)":"var(--success)":"var(--accent)",M=o!==void 0?`L${o}–${l??"?"}`:p!==void 0?`第${p}行起${g?` ×${g}`:""}`:null,O=b?"var(--danger)":k?"var(--text-muted)":"var(--accent)",_=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Fr,{name:t.name,color:O})}),e.jsx("span",{className:"tool-call-shell__label",children:"查阅"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:Gt(a)}),M&&e.jsx(Br,{label:M,color:"var(--accent)",bg:"var(--accent-dim)"}),k&&!b&&e.jsx(Br,{label:`${m} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),(!k||b)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:I},children:[e.jsx(ur,{isDone:k,isError:b,color:I}),b&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(bs,{statusColor:I,isDone:k,expanded:n,onToggle:()=>i(!n),header:_,maxBodyHeight:480,primaryAction:r?()=>Wn(r):void 0,primaryActionLabel:r?`预览文件 ${Gt(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),k&&!b?e.jsx(po,{content:h}):k&&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:h})]})}function Ld({toolCall:t,previewPath:r}){const[n,i]=d.useState(!1),a=t.arguments.file_path??"",o=t.arguments.old_string??"",l=t.arguments.new_string??"",p=t.isError,g=cr(t),h=g?p?"var(--danger)":"var(--success)":"var(--accent)",m=p?"var(--danger)":g?"var(--text-muted)":"var(--accent)",b=d.useMemo(()=>o&&l?uo(o,l):null,[o,l]),k=d.useMemo(()=>b?{added:b.filter(M=>M.type==="added").length,removed:b.filter(M=>M.type==="removed").length}:null,[b]),I=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Fr,{name:t.name,color:m})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:Gt(a)}),k&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[k.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",k.added]}),k.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",k.removed]})]}),(!g||p)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:h},children:[e.jsx(ur,{isDone:g,isError:p,color:h}),p&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(bs,{statusColor:h,isDone:g,expanded:n,onToggle:()=>i(!n),header:I,maxBodyHeight:480,primaryAction:r?()=>Wn(r):void 0,primaryActionLabel:r?`预览文件 ${Gt(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),b?e.jsx(fo,{diff:b}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:o}),e.jsx("pre",{style:{fontSize:11,color:"var(--success)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(5,150,105,0.04)",border:"1px solid rgba(5,150,105,0.12)",borderLeft:"3px solid var(--success)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:l})]}),p&&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 lr({label:t,content:r,error:n,maxPreviewLines:i=8,maxPreviewHeight:a=200,maxExpandedHeight:o=2e3}){const[l,p]=d.useState(!1),g=r.split(`
245
- `),h=g.length>i,m=h&&!l?g.slice(0,i).join(`
246
- `)+`
247
- ...`:r;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:n?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:n?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:n?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:n?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:l?o:a,overflow:"auto",margin:0,lineHeight:1.6},children:m}),h&&e.jsx("button",{onClick:()=>p(!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?"收起":`展开全部 (${g.length} 行)`})]})}function Pd({arguments:t}){var n;const r=t.task??"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 0"},children:[e.jsxs("div",{style:{display:"flex",gap:8,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",flexWrap:"wrap"},children:[e.jsx(Br,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(Br,{label:`sid: ${(n=t.subSessionId)==null?void 0:n.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),r&&e.jsx(lr,{label:"任务",content:r,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Dd({raw:t}){const[r,n]=d.useState(!1);let i;try{const g=JSON.parse(t);delete g.subAgentProgress,delete g.subAgentStatus,delete g.subAgentDetail,i=JSON.stringify(g,null,2)}catch{i=t}const a=8,o=i.split(`
248
- `),l=o.length>a,p=l&&!r?o.slice(0,a).join(`
249
- `)+`
250
- ...`:i;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"参数"}),e.jsx("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",maxHeight:r?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:p}),l&&e.jsx("button",{onClick:()=>n(!r),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:r?"收起":`展开全部 (${o.length} 行)`})]})}function Bd({activity:t,workspacePath:r,enableFilePreview:n}){const i=new Map(t.messages.flatMap(a=>a.role==="tool"&&a.toolCallId?[[a.toolCallId,{content:a.content,isError:a.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((a,o)=>{var l;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[a.role==="assistant"&&a.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:a.content}),a.role==="assistant"&&((l=a.toolCalls)==null?void 0:l.map(p=>{const g=i.get(p.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(yi,{toolCall:{...p,...g?{result:g.content,isError:g.isError}:{}},workspacePath:r,enableFilePreview:n}),g&&e.jsx("pre",{className:`native-subagent-activity__tool-result${g.isError?" native-subagent-activity__tool-result--error":""}`,children:g.content})]},p.id)})),a.role==="tool"&&a.toolCallId&&!t.messages.some(p=>{var g;return(g=p.toolCalls)==null?void 0:g.some(h=>h.id===a.toolCallId)})&&e.jsx(lr,{label:"工具结果",content:a.content,error:a.name==="error",maxPreviewHeight:180})]},`${a.role}-${o}`)}),t.summary&&e.jsx(lr,{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(ur,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function Fd({toolCall:t,onSelectSession:r,nativeSubagent:n,previewPaths:i,workspacePath:a,enableFilePreview:o}){const l=ge(L=>L.runningSessionId),[p,g]=d.useState(()=>!!n),h=t.name==="dispatch_agent",m=t.name==="Agent"&&!!n,b=t.arguments.subAgentStatus,k=t.arguments.subAgentDetail,I=t.arguments.subAgentProgress,M=cr(t);d.useEffect(()=>{h&&!b&&I&&g(!0),m&&(n.messages.length>0||n.summary)&&g(!0)},[h,m,n,b,I]);const O=h?b==="failed":m?n.status==="failed":t.isError,_=h?!!b||M&&!l:m?n.status!=="running":M,F=_?O?"var(--danger)":"var(--success)":"var(--accent)",y=O?"var(--danger)":_?"var(--text-muted)":"var(--accent)",j=h?null:mi(t.name),q=O?"错误":j?"":m?n.status==="stopped"?"已停止":_?"已完成":"运行中":h?b==="failed"?"失败":_?"已完成":"运行中":_?"完成":"执行中",K=m?n.description:h?(()=>{const ae=(t.arguments.task??"").split(`
251
- `)[0];return ae.length>80?ae.slice(0,80)+"…":ae})():Nd(t.name,t.arguments),A=m?`@${n.agentName??"agent"}`:h?`@${t.arguments.agentName??"agent"}`:oo(t.name)??t.name,C=xi(t.name),W=!_||!!O||!!q,E=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(Fr,{name:t.name,color:y})}),e.jsx("span",{className:"tool-call-shell__label",title:j?t.name:void 0,style:{fontFamily:j?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:A}),K&&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:K}),!K&&e.jsx("span",{style:{flex:1}}),W&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:F},children:[e.jsx(ur,{isDone:_,isError:!!O,color:F}),q&&e.jsx("span",{children:q})]})]});return e.jsxs(bs,{statusColor:F,isDone:_,expanded:p,onToggle:()=>g(!p),header:E,maxBodyHeight:800,primaryAction:i.length===1?()=>Wn(i[0]):void 0,primaryActionLabel:i.length===1?`预览文件 ${Gt(i[0])}`:void 0,primaryActionTitle:i.length===1?`预览 ${i[0]}`:void 0,children:[i.length>1&&e.jsx("div",{className:"tool-call-file-list","aria-label":"改动文件",children:i.map(L=>e.jsxs("button",{type:"button",onClick:()=>Wn(L),"aria-label":`预览文件 ${Gt(L)}`,title:`预览 ${L}`,children:[e.jsx(xs,{size:12,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Gt(L)})]},L))}),m?e.jsx(Bd,{activity:n,workspacePath:a,enableFilePreview:o}):h?e.jsx(Pd,{arguments:t.arguments}):C==="command"&&typeof t.arguments.command=="string"?e.jsxs(e.Fragment,{children:[typeof t.arguments.cwd=="string"&&t.arguments.cwd&&e.jsxs("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:["工作目录 ",t.arguments.cwd]}),e.jsx(lr,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(Dd,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!h&&!m&&e.jsx(lr,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),h&&b&&k&&e.jsx(lr,{label:b==="failed"?"错误信息":"执行摘要",content:k,error:b==="failed",maxPreviewHeight:180}),h&&!b&&I&&(!!l||!M)&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"实时输出"}),e.jsxs("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderLeft:"3px solid var(--accent)",maxHeight:240,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:[I,e.jsx("span",{style:{display:"inline-block",width:"0.5em",height:"1em",background:"var(--accent)",verticalAlign:"text-bottom",animation:"blink 1s step-end infinite"},children:"​"})]})]}),h&&!b&&!I&&!!l&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 0",fontSize:11,color:"var(--text-muted)",fontStyle:"italic"},children:[[0,1,2].map(L=>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:`${L*.16}s`}},L)),"等待子 agent 响应..."]}),h&&t.arguments.subSessionId&&r&&e.jsxs("button",{onClick:()=>r(t.arguments.subSessionId),style:{alignSelf:"flex-start",padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--accent-dim)",color:"var(--accent)",fontSize:11,fontWeight:500,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s"},onMouseEnter:L=>{L.currentTarget.style.background="var(--accent)",L.currentTarget.style.color="white"},onMouseLeave:L=>{L.currentTarget.style.background="var(--accent-dim)",L.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 $d({items:t,onSelectSession:r,workspacePath:n,enableFilePreview:i}){var I;const[a,o]=d.useState(!1),l=(I=t[0])==null?void 0:I.toolCall,p=l?mi(l.name):null;if(!l||!p||t.length<2)return null;const g=t.every(({toolCall:M})=>cr(M)),h=t.filter(({toolCall:M})=>M.isError).length,m=h>0?"var(--danger)":g?"var(--text-muted)":"var(--accent)",b=oo(l.name)??p.done,k=`${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":k,onClick:()=>o(M=>!M),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(Fr,{name:l.name,color:m})}),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"}),h>0&&e.jsxs("span",{className:"tool-call-group__error",children:[h," 项失败"]}),!g&&e.jsx(ur,{isDone:!1,color:m,size:11}),e.jsx(dr,{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:M,beforeContent:O,progress:_,nativeSubagent:F})=>e.jsx(yi,{toolCall:M,beforeContent:O,progress:_,nativeSubagent:F,onSelectSession:r,workspacePath:n,enableFilePreview:i},M.id))})]})}function Od(t,r){if(xi(t.name)!=="file")return[];const n=t.name==="apply_patch"&&Array.isArray(t.arguments.changes)?t.arguments.changes.map(i=>i.path):[t.arguments.file_path??t.arguments.path??t.arguments.notebook_path];return[...new Set(n.filter(i=>typeof i=="string").map(i=>ro(i,r)).filter(i=>!!i))]}function yi({toolCall:t,onSelectSession:r,beforeContent:n,progress:i,nativeSubagent:a,workspacePath:o,enableFilePreview:l=!1}){const p=l?Od(t,o):[],g=t.name==="write_file"?e.jsx(_d,{toolCall:t,beforeContent:n,previewPath:p[0]}):t.name==="read_file"?e.jsx(Wd,{toolCall:t,previewPath:p[0]}):t.name==="str_replace"?e.jsx(Ld,{toolCall:t,previewPath:p[0]}):e.jsx(Fd,{toolCall:t,onSelectSession:r,nativeSubagent:a,previewPaths:p,workspacePath:o,enableFilePreview:l});return e.jsxs("div",{className:"tool-call-with-progress",children:[g,i&&e.jsx(lo,{progress:i,compact:!0})]})}function Ud({question:t,options:r,fields:n,multiSelect:i,answered:a,answer:o,onAnswer:l}){const[p,g]=d.useState(new Set),[h,m]=d.useState(""),[b,k]=d.useState({}),I=!!(r!=null&&r.length),M=!!(n!=null&&n.length),O=j=>{a||g(q=>{const K=new Set(q);return i?K.has(j)?K.delete(j):K.add(j):(K.clear(),K.add(j)),K})},_=()=>{if(p.size===0)return;const j=Array.from(p).map(q=>r[q].label);l(j.join(", "),Array.from(p))},F=()=>{const j=Array.from(p).map(K=>r[K].label),q=Object.fromEntries((n??[]).map(K=>{var A;return[K.name,((A=b[K.name])==null?void 0:A.trim())??""]}));!q.model&&j.length>0&&(q.model=j[0]),!(!Object.values(q).some(Boolean)&&j.length===0)&&l(JSON.stringify({fields:q,selectedOptions:j}),Array.from(p))},y=()=>{h.trim()&&l(h.trim())};return e.jsx("div",{style:{marginBottom:12},children:e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:a?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:a?"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:a?"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:a?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:a?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:a?"var(--text-muted)":"var(--accent)",flex:1},children:a?"已回答":"向你提问"}),i&&!a&&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}),a&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),M?"配置已提交(敏感字段已隐藏)":o]}),I&&!a&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[r.map((j,q)=>{const K=p.has(q);return e.jsxs("button",{onClick:()=>O(q),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:K?"var(--accent)":"var(--border-subtle)",background:K?"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:i?4:8,border:`2px solid ${K?"var(--accent)":"var(--border-subtle)"}`,background:K?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:K&&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:K?600:500,color:K?"var(--text-primary)":"var(--text-secondary)"},children:j.label}),j.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:j.description})]})]},q)}),!M&&e.jsx("button",{onClick:_,disabled:p.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:p.size>0?"var(--accent)":"var(--bg-surface)",color:p.size>0?"white":"var(--text-muted)",cursor:p.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),M&&!a&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[n.map(j=>e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:"var(--text-secondary)"},children:j.label}),e.jsx("input",{type:j.type==="secret"?"password":"text",value:b[j.name]??"",onChange:q=>k(K=>({...K,[j.name]:q.target.value})),placeholder:j.description,autoComplete:j.type==="secret"?"off":void 0,style:{padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none"}}),j.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:j.description})]},j.name)),e.jsx("button",{onClick: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:"确认配置"})]}),!a&&!M&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:I?"1px solid var(--border-subtle)":"none",marginTop:I?2:0},children:[e.jsx("input",{type:"text",value:h,onChange:j=>m(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),y())},placeholder:I?"或输入自定义回答…":"输入你的回答…",style:{flex:1,padding:"8px 12px",borderRadius:8,border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)",fontSize:13,fontFamily:"var(--font-body)",outline:"none",transition:"border-color 0.15s ease"},onFocus:j=>{j.currentTarget.style.borderColor="var(--accent)"},onBlur:j=>{j.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:y,disabled:!h.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:h.trim()?"var(--accent)":"var(--bg-surface)",color:h.trim()?"white":"var(--text-muted)",cursor:h.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})})}const qs={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"}},Hs={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},va=["system","messages","tools","images","overhead"];function qd(t,r){const n=(t==null?void 0:t.maxTokens)??Math.max(1,r*1e3),i=(t==null?void 0:t.totalTokens)??0,a=Object.fromEntries(va.map(l=>[l,0]));for(const l of(t==null?void 0:t.segments)??[]){const p=qs[l.category];p&&(a[p.group]+=l.tokens)}const o=Math.min(i/n,1);return{hasUsage:!!t,totalTokens:i,maxTokens:n,ratio:o,percent:Math.round(o*100),groups:va.map(l=>({key:l,label:Hs[l].label,color:Hs[l].color,tokens:a[l]})),details:((t==null?void 0:t.segments)??[]).filter(l=>l.tokens>0).map(l=>{var p,g;return{category:l.category,label:((p=qs[l.category])==null?void 0:p.label)??l.category,color:Hs[((g=qs[l.category])==null?void 0:g.group)??"overhead"].color,tokens:l.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function oi(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function wa(t,r){return r?`${t.percent}%`:t.hasUsage?`${oi(t.totalTokens)} / ${oi(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Hd({usage:t,contextWindowK:r,compact:n=!1}){const[i,a]=d.useState(!1),[o,l]=d.useState(null),p=d.useRef(null),g=d.useMemo(()=>qd(t,r),[t,r]),h=g.ratio>=.85?"var(--danger)":g.ratio>=.6?"#f59e0b":"var(--accent)",m=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:p,type:"button",onClick:()=>{var k;const b=((k=p.current)==null?void 0:k.getBoundingClientRect())??null;l(b),a(I=>!I)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:n?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"context-usage-ribbon__ring",width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:"currentColor",strokeWidth:"4",opacity:"0.14"}),e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:g.hasUsage?h:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${g.ratio*62.832} 62.832`,transform:"rotate(-90 14 14)"})]}),e.jsx("span",{className:"context-usage-ribbon__summary context-usage-ribbon__summary--compact",children:wa(g,!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:g.groups.map(b=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(b.tokens/g.maxTokens*100,100))}%`,background:b.color,opacity:b.key==="overhead"?.65:1,minWidth:b.tokens>0?1:0}},b.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:g.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:wa(g,!1)})]})}),i&&o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>a(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:n?Math.min(Math.max(8,o.left),Math.max(8,m-Math.min(340,m-16)-8)):Math.max(8,o.left),top:o.top-8,transform:"translateY(-100%)",width:Math.min(n?340:o.width,m-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:g.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:g.hasUsage?`${g.percent}%`:"暂无"})]}),g.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:g.requestLabel}),g.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:g.details.map(b=>{const k=g.totalTokens>0?Math.round(b.tokens/g.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:b.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:b.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[oi(b.tokens)," · ",k,"%"]})]},b.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 Vd({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(ui,{size:17,strokeWidth:1.8})}),e.jsxs("span",{children:["思考中",e.jsx(bi,{startedAt:t})]})]})}function Qd({sections:t,streaming:r=!1,startedAt:n,renderContent:i}){const a=d.useMemo(()=>[...t].sort((h,m)=>h.sectionIndex-m.sectionIndex).map(h=>h.text.trim()).filter(Boolean).join(`
252
-
253
- `),[t]),o=d.useMemo(()=>(a.split(`
254
- `).find(m=>m.trim())??"").replace(/^#{1,6}\s+/,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1"),[a]),[l,p]=d.useState(r);if(d.useEffect(()=>{p(r)},[r]),!a)return null;const g=r?"思考中":"思考";return e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":l,"aria-label":`${g},${l?"收起":"展开"}`,onClick:()=>p(h=>!h),children:[e.jsx("span",{className:"reasoning-summary__brain","aria-hidden":"true",children:e.jsx(ui,{size:17,strokeWidth:1.8})}),e.jsxs("span",{className:"reasoning-summary__label",children:[g,r&&n!==void 0&&e.jsx(bi,{startedAt:n})]}),!l&&e.jsx("span",{className:"reasoning-summary__preview",children:o}),e.jsx("span",{className:"reasoning-summary__spacer"}),r&&e.jsx(dn,{className:"reasoning-summary__spinner",size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx(dr,{className:"reasoning-summary__chevron",size:13,strokeWidth:2,"aria-hidden":"true"})]}),l&&e.jsx("div",{className:"reasoning-summary__content",children:i(a)})]})}function Kd({appearanceOpen:t,settingsOpen:r,hideToBackgroundTitle:n="隐藏到后台",onHideToBackground:i,onToggleAppearance:a,onOpenSettings:o}){return e.jsxs("div",{className:"chat-header-actions",children:[e.jsx("button",{type:"button",onClick:i,title:n,"aria-label":"隐藏后台",className:"ui-icon-button chat-header-action chat-header-action--background",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"m9 11 3 3 3-3M12 7v7M8 21h8"})]})}),e.jsx("button",{type:"button",onClick:l=>a(l.currentTarget.getBoundingClientRect()),title:"皮肤与布局","aria-label":"皮肤与布局","aria-expanded":t,className:`ui-icon-button chat-header-action chat-header-action--appearance ${t?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]})}),e.jsx("button",{type:"button",onClick:o,title:"设置","aria-label":"设置","aria-expanded":r,className:`ui-icon-button chat-header-action chat-header-action--settings ${r?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]})}const Gd=[{prompt:"带我熟悉这个项目",Icon:ul},{prompt:"帮我排查一个问题",Icon:Za},{prompt:"一起实现一个新想法",Icon:Cl}],Zd={"customer-agent":"Customer Agent",codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function Yd({agentType:t,ready:r,onSelectPrompt:n}){const i=Zd[t];return e.jsxs("section",{className:"empty-session-welcome","aria-labelledby":"empty-session-welcome-title",children:[e.jsxs("div",{className:"empty-session-welcome__core","aria-hidden":"true",children:[e.jsx("span",{className:"empty-session-welcome__glow"}),e.jsxs("svg",{viewBox:"0 0 120 120",role:"presentation",children:[e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--outer",cx:"60",cy:"60",r:"44"}),e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--inner",cx:"60",cy:"60",r:"33"}),e.jsx("rect",{className:"empty-session-welcome__diamond",x:"43",y:"43",width:"34",height:"34",rx:"2"}),e.jsx("circle",{className:"empty-session-welcome__pulse",cx:"60",cy:"60",r:"3"})]})]}),e.jsxs("div",{className:"empty-session-welcome__copy",children:[e.jsx("p",{className:"empty-session-welcome__status",children:r?`${i} · 已准备好`:`${i} · 等待配置`}),e.jsx("h2",{id:"empty-session-welcome-title",children:"嗨,我在。"}),e.jsx("p",{className:"empty-session-welcome__prompt",children:r?"今天想一起做点什么?":"配置好 API Key 后,我就能开始。"})]}),e.jsx("div",{className:"empty-session-welcome__starters","aria-label":"开始一个任务",children:Gd.map(({prompt:a,Icon:o})=>e.jsxs("button",{type:"button","data-prompt":a,disabled:!r,onClick:()=>n(a),children:[e.jsx(o,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:a})]},a))})]})}function Jd({image:t,onClose:r}){return d.useEffect(()=>{if(!t)return;const n=document.body.style.overflow,i=a=>{a.key==="Escape"&&r()};return document.body.style.overflow="hidden",window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i),document.body.style.overflow=n}},[t,r]),t?Kt.createPortal(e.jsxs("div",{className:"message-image-lightbox",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:n=>{n.target===n.currentTarget&&r()},children:[e.jsx("img",{className:"message-image-lightbox__image",src:t.src,alt:t.alt}),e.jsx("button",{type:"button",className:"message-image-lightbox__close",onClick:r,"aria-label":"关闭图片预览",title:"关闭",autoFocus:!0,children:e.jsx(Ya,{size:22,"aria-hidden":"true"})})]}),document.body):null}const Xd={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function ec(t){const{title:r="视频工作台",shots:n=[],status:i="generating",composedVideoUrl:a}=t,[o,l]=d.useState(!1),[p,g]=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(!o),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:o?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",r]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[n.filter(h=>h.status==="done").length,"/",n.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:o?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!o&&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:Lr,children:"#"}),e.jsx("th",{style:{...Lr,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:Lr,children:"时长"}),e.jsx("th",{style:Lr,children:"状态"}),e.jsx("th",{style:Lr,children:"预览"})]})}),e.jsx("tbody",{children:n.map(h=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:Pr,children:h.index}),e.jsx("td",{style:{...Pr,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.description,children:h.description}),e.jsxs("td",{style:Pr,children:[h.duration,"s"]}),e.jsxs("td",{style:Pr,children:[Xd[h.status]??"⏳",h.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:h.error,children:"!"})]}),e.jsx("td",{style:Pr,children:h.videoUrl?e.jsx("button",{onClick:()=>g(h.videoUrl),style:{background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:6,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"▶ 播放"}):h.previewImageUrl?e.jsx("img",{src:h.previewImageUrl,alt:`shot-${h.index}`,style:{width:48,height:32,objectFit:"cover",borderRadius:4,border:"1px solid var(--border-subtle)"}}):e.jsx("span",{style:{color:"var(--text-muted)",fontSize:11},children:"—"})})]},h.index))})]}),p&&e.jsx("video",{src:p,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),a&&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:a,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:[i==="generating"&&e.jsx("span",{children:"🔄 生成中..."}),i==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),i==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),i==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const Lr={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},Pr={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},tc={storyboard_workbench:ec};function nc(t,r,n){return!t||r!==t?!1:n===null||n===t}function rc(t,r,n=Date.now()){return!t||t.sessionId!==r?t:{...t,until:n+9e4}}async function sc(t){const{text:r,projectId:n,createSession:i,activateSession:a,showUserMessage:o,onSessionCreated:l,isCancelled:p}=t,g=!t.sessionId;let h=t.sessionId??null;if(!h){const m=await i(r.slice(0,60)||"语音任务",n||void 0);if(p!=null&&p())return null;h=m.id}return a(h),o(r,h),g&&l&&await l(h),h}async function ja(t){var a,o;const r=((a=t.sessionId)==null?void 0:a.trim())||null,n=!r,i=r??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!i)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(i),t.showUserMessage(t.text,i),n&&await((o=t.onSessionCreated)==null?void 0:o.call(t,i)),i}const ic=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|[ \t]*\/[^)\n]+)\)/gi,ac=/`([^`\n]+)`/g,oc=/:codex-file-citation\{([^}\n]*)\}/g,ka=/([A-Za-z][\w-]*)="([^"\n]*)"/g,lc=/\uE200visualize\uE202([^\uE201\n]+)\uE201/g;function vi(t){if(!t.startsWith("/")||t.includes("?")||t.includes("#")||t.includes("\0"))return null;const r=t.match(/^(\/.*):([1-9]\d*)$/);return r?{path:r[1],line:Number(r[2])}:{path:t}}function dc(t){const r={};for(const a of t.matchAll(ka)){const o=a[1];if(o!=="path"&&o!=="purpose"||r[o]!==void 0)return null;r[o]=a[2]}if(t.replace(ka,"").trim())return null;const n=vi(r.path??"");if(!n||n.line!==void 0)return null;const i=n.path.slice(n.path.lastIndexOf("/")+1)||n.path;return{path:n.path,label:i}}function cc(t){try{const r=JSON.parse(t);if(!r||typeof r!="object"||Array.isArray(r))return null;const{path:n,title:i,mode:a}=r;if(typeof n!="string"||i!==void 0&&typeof i!="string"||a!==void 0&&typeof a!="string")return null;const o=vi(n);if(!o||o.line!==void 0)return null;const l=(i==null?void 0:i.trim())||o.path.slice(o.path.lastIndexOf("/")+1)||o.path;return{path:o.path,label:l}}catch{return null}}function uc(t,r){const n=[];let i=0;const a=[...[...t.matchAll(ic)].map(o=>({kind:"markdown",match:o})),...[...t.matchAll(oc)].map(o=>({kind:"citation",match:o})),...[...t.matchAll(lc)].map(o=>({kind:"visualize",match:o})),...[...t.matchAll(ac)].map(o=>({kind:"code",match:o}))].sort((o,l)=>(o.match.index??0)-(l.match.index??0));for(const o of a){const{match:l}=o,p=l.index??0;if(p<i)continue;if(p>i&&n.push({type:"text",value:t.slice(i,p)}),o.kind==="code"){n.push({type:"code",value:l[1]}),i=p+l[0].length;continue}if(o.kind==="citation"){const h=dc(l[1]);n.push(h?{type:"artifact",label:h.label,path:h.path,raw:l[0]}:{type:"text",value:l[0]}),i=p+l[0].length;continue}if(o.kind==="visualize"){const h=cc(l[1]);n.push(h?{type:"artifact",label:h.label,path:h.path,raw:l[0]}:{type:"text",value:l[0]}),i=p+l[0].length;continue}const g=l[2];if(/^https?:\/\//i.test(g))n.push({type:"link",label:l[1],href:g});else{const h=vi(g.replace(/^[ \t]+/,""));h?n.push({type:"artifact",label:l[1],path:h.path,...h.line?{line:h.line}:{},raw:l[0]}):n.push({type:"text",value:l[0]})}i=p+l[0].length}return i<t.length&&n.push({type:"text",value:t.slice(i)}),n.length>0?n:[{type:"text",value:t}]}function pc(t){return uc(t)}function go(t){var r,n;return t.role==="assistant"&&!!((r=t.toolCalls)!=null&&r.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((n=t.images)!=null&&n.length)&&!t.presentation}function fc(t){return go(t)&&t.content.trim().length===0}function gc(t){const r=[];for(const n of t){const i=r[r.length-1];if(i&&go(i)&&fc(n)){r[r.length-1]={...i,toolCalls:[...i.toolCalls,...n.toolCalls],timestamp:n.timestamp};continue}r.push(n)}return r}function hc(t){const r=[];for(const n of t){const i=Ed(n.toolCall.name),a=r[r.length-1];i&&(a==null?void 0:a.action)===i?a.items.push(n):r.push({action:i,items:[n]})}return r}function ho(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0}function xc(t){const r=ho(t);return r===void 0?void 0:`${Math.round(r/1e3)} 秒`}function mc(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function bc(t){var r,n,i;return t.role==="assistant"&&!!(t.content.trim()||(r=t.toolCalls)!=null&&r.length||(i=(n=t.presentation)==null?void 0:n.reasoning)!=null&&i.length||t.askUser||t.widget)}function yc(t,r,n){var o;const i=t[r];if((i==null?void 0:i.role)!=="assistant"||!i.content.trim()||(o=i.toolCalls)!=null&&o.length||i.isCompactionSummary)return!1;let a=!n;for(let l=r+1;l<t.length;l++){const p=t[l];if(!p.isCompactionSummary){if(mc(p)){a=!0;break}if(bc(p))return!1}}return a}function vc(t,r,n){const i=t[r];if(!i)return{showCopy:!1,showSpeak:!1,showCompletion:!1,compact:!1};if(i.role==="user")return{showCopy:!!i.content,showSpeak:!1,showCompletion:!1,compact:!1};const a=yc(t,r,n);return{showCopy:a,showSpeak:a,showCompletion:a,compact:i.role==="assistant"&&!a&&!i.isCompactionSummary}}const wc=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function jc(t,r){const n=[],i=[],a=[];for(const l of t){const p=l.type.trim().toLowerCase();p.startsWith("image/")?wc.has(p)?n.push(l):a.push(l):i.push(l)}const o=await Promise.all(n.map(async l=>{try{return{file:l,dataUrl:await r(l)}}catch{return{file:l,dataUrl:null}}}));return{images:o.flatMap(l=>l.dataUrl?[l.dataUrl]:[]),attachments:i,unsupportedImages:a,failedImages:o.flatMap(l=>l.dataUrl?[]:[l.file])}}function xo(t,r){return!!(t&&(r==null?void 0:r.sessionId)===t&&r.code==="SESSION_OCCUPIED")}function Sa(t,r){return((t==null?void 0:t.agentType)==="codex"||(t==null?void 0:t.agentType)==="opencode")&&(t.occupancy==="owned-externally"||xo(t.id,r))}async function kc(t){const r=await t.forkSession(t.sourceSessionId);return t.activateSession(r.id),await t.refreshAndSelect(r),r}const Mn=50;function Ia(t){return t.trim().replace(/^\/goal\s+/i,"").replace(/^\$([\w-]+)/,"/$1").trim()}function Vs(t){const n=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(n){const o=parseFloat(n[1]),l=n[2].toLowerCase(),p=l==="s"||l==="sec"||l==="秒"?o*1e3:l==="m"||l==="min"||l==="分"||l==="分钟"?o*6e4:o*36e5;return p>=36e5&&p%36e5===0?`每 ${p/36e5} 小时`:p>=6e4&&p%6e4===0?`每 ${p/6e4} 分钟`:`每 ${p/1e3} 秒`}const[i,a]=t.trim().split(/\s+/);return i==="0"&&a&&a!=="*"&&!a.includes("/")&&!a.includes(",")?`每天 ${a.padStart(2,"0")}:00`:`cron: ${t}`}function Sc(t){const r=t.split(/(`[^`\n]+`)/g);return r.length<=1?t:e.jsx(e.Fragment,{children:r.map((n,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:n.slice(1,-1)},i):e.jsx("span",{children:n},i))})}function mo(t,r){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((i,a)=>{const o=`${r}-${a}`;return i.startsWith("**")&&i.endsWith("**")&&i.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:i.slice(2,-2)},o):i.startsWith("*")&&i.endsWith("*")&&i.length>2?e.jsx("em",{children:i.slice(1,-1)},o):e.jsx("span",{children:i},o)})}function Ca(t,r){return t.split(/(`[^`\n]+`)/g).map((i,a)=>a%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:i.slice(1,-1)},`${r}-${a}`):mo(i,`${r}-${a}`))}function li(t){return pc(t).map((r,n)=>{if(r.type==="code")return e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:r.value},n);if(r.type==="link")return e.jsx("a",{className:"chat-message-link",href:r.href,target:"_blank",rel:"noopener noreferrer",children:Ca(r.label,`${n}-label`)},n);if(r.type==="artifact"){if(!or())return e.jsx("span",{children:r.raw},n);const i=r.line?`${r.path}:${r.line}`:r.path,a=r.label.replace(/^`([^`\n]+)`$/,"$1");return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:i,"aria-label":`打开交付物 ${a}`,onClick:()=>Wn(r.path),children:[e.jsx(xs,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Ca(r.label,`${n}-label`)})]},n)}return mo(r.value,`${n}`)})}function Ic(t){if(t.length<2)return null;const r=o=>o.replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim()),n=r(t[0]),i=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(i))return null;const a=t.slice(2).map(r);return{headers:n,rows:a}}function Cc(t,r){const n=i=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:i?600:400,color:i?"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((i,a)=>e.jsx("th",{style:n(!0),children:li(i)},a))})}),e.jsx("tbody",{children:r.map((i,a)=>e.jsx("tr",{style:{background:a%2===0?"transparent":"rgba(0,0,0,0.015)"},children:i.map((o,l)=>e.jsx("td",{style:n(!1),children:li(o)},l))},a))})]})})}function Ac(t,r){return e.jsxs("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"4px 10px",background:"var(--bg-deep)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em"},children:t||"code"}),e.jsx("pre",{style:{margin:0,padding:"10px 12px",fontSize:12,lineHeight:1.6,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto",maxHeight:420},children:r})]})}function Qs(t){const r=t.split(`
255
- `),n=[];let i=0,a=0;const o=p=>p.trimStart().startsWith("```"),l=p=>r[p].trimStart().startsWith("|")&&p+1<r.length&&/^\|[\s\-:|]+\|$/.test(r[p+1].trim());for(;i<r.length;){if(o(r[i])){const p=r[i].trim().slice(3).trim();i++;const g=[];for(;i<r.length&&!o(r[i]);)g.push(r[i]),i++;i++,n.push(e.jsx("div",{children:Ac(p,g.join(`
256
- `))},`code-${a++}`));continue}if(l(i)){const p=[];for(;i<r.length&&r[i].trimStart().startsWith("|");)p.push(r[i].trim()),i++;const g=Ic(p);g?n.push(e.jsx("div",{children:Cc(g.headers,g.rows)},`tbl-${a++}`)):n.push(e.jsx("span",{children:p.map((h,m)=>e.jsxs("span",{children:[Sc(h),m<p.length-1?`
257
- `:null]},m))},`tbl-fb-${a++}`))}else{const p=[];for(;i<r.length&&!l(i)&&!o(r[i]);)p.push(r[i]),i++;p.length>0&&n.push(e.jsx("span",{children:p.map((g,h)=>e.jsxs("span",{children:[li(g),h<p.length-1?`
258
- `:null]},h))},`txt-${a++}`))}}return e.jsx(e.Fragment,{children:n})}const bo=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Aa=Object.fromEntries(bo.map(t=>[t.value,t.label])),Ks={low:"低",medium:"中",high:"高",xhigh:"超高",max:"最大"},Ra={codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function Rc(t,r){return r==="codex"?t==="openai":r==="claude-code"?t==="anthropic":!1}const ps=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function Ta(t){return ps.some(r=>r.value===t)?t:"full-access"}function Tc({activeAgentType:t="customer-agent",selectedProjectId:r=null,selectedSessionId:n=null,onSessionCreated:i,onMessageSent:a,onSubSessionCreated:o,onSelectSession:l,onSubAgentEvent:p,onRunComplete:g,sessionTitle:h,sessionSummary:m,workspacePath:b=null,onOpenSettings:k,settingsOpen:I=!1,onHideToBackground:M,onToggleAppearance:O,appearanceOpen:_=!1,hideToBackgroundTitle:F,voiceCommand:y=null}){var Oi,Ui,qi,Hi,Vi,Qi,Ki,Gi,Zi,Yi,Ji;const{messages:j,runningSessionId:q,appendText:K,addMessage:A,setRunningSession:C,setSessionId:W,updateToolResult:E,updateSubAgentStatus:L,updateSubAgentProgress:ae,updateMessage:fe,setMessages:we,getMessagesForSession:G,contextUsageBySession:Ke,runtimeProgressBySession:kt,nativeSubagentsBySession:Ln,setContextUsage:Le,applyRuntimeProgress:Pn,setRuntimeProgress:zt,clearRuntimeProgress:_t,applyNativeSubagentActivity:pr,setNativeSubagentActivities:lt,applyReasoningSummary:S,clearMessages:U,sessionId:le,todos:pe,setTodos:be,cronTasks:Ie,setCronTasks:Ce}=ge(),Se=d.useMemo(()=>gc(j.filter(s=>!s.isQueued)),[j]),{isConfigured:Wt,profiles:dt,activeProfileId:St,switchActiveProfile:gt,loadFromSystem:Dn,contextWindow:Lt,reasoningEffort:ht,setField:ye,saveToSystem:fr}=ms(),[qe,xt]=d.useState(),[It,Ct]=d.useState(),[cn,un]=d.useState(!1),[pn,At]=d.useState(null),[Pt,Bn]=d.useState(null),H=n||le,he=Id(m,t),ue=(m==null?void 0:m.agentType)??t,[$r,Fn]=d.useState([]),Dt=d.useRef(null),[Ge,Rt]=d.useState(()=>na(ue)),[ct,fn]=d.useState(!1),$n=d.useRef(null);d.useEffect(()=>{Rt(na(ue)),fn(!1)},[ue]),d.useEffect(()=>{var s;!he||!((s=window.agentApi)!=null&&s.listAgentModels)||Dt.current!==ue&&(Dt.current=ue,Fn([]),window.agentApi.listAgentModels(ue).then(u=>Fn(u.models??[])).catch(()=>{Fn([]),Dt.current=null}))},[he,ue]),d.useEffect(()=>{if(!ct)return;const s=u=>{$n.current&&!$n.current.contains(u.target)&&fn(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ct]);const gr=d.useCallback(s=>{Rt(u=>{const f={...u,...s};return Ul(ue,f),f})},[ue]),On=d.useMemo(()=>he?$r.map(s=>({key:Ps(s),label:s.displayName||s.id,model:{id:s.id,...s.providerID?{providerID:s.providerID}:{}},reasoningEfforts:s.reasoningEfforts})):[],[he,$r]),hr=d.useMemo(()=>he?(dt??[]).filter(s=>{var u;return(u=s.modelId)==null?void 0:u.trim()}).filter(s=>ue==="opencode"||Rc(s.provider,ue)).map(s=>({key:ue==="opencode"?Ps({id:s.modelId,providerID:s.provider}):s.modelId,label:s.name||s.modelId,model:{id:s.modelId,...ue==="opencode"?{providerID:s.provider}:{}}})):[],[he,dt,ue]),Un=(Oi=Ge.model)!=null&&Oi.id?Ps(Ge.model):"",mt=d.useMemo(()=>{var u;const s=On.find(f=>f.key===Un);if((u=s==null?void 0:s.reasoningEfforts)!=null&&u.length)return s.reasoningEfforts;if(ue==="claude-code")return["low","medium","high","xhigh"]},[On,Un,ue]),xr=d.useMemo(()=>he?ue==="codex"?mt??[]:ue==="claude-code"?mt??["low","medium","high","xhigh"]:[]:[],[he,ue,mt]),Qe=Ge.reasoningEffort&&xr.includes(Ge.reasoningEffort)?Ge.reasoningEffort:void 0,mr=On.length>0||hr.length>0,gn=(m==null?void 0:m.messageQueueVersion)===1,Or=md(m==null?void 0:m.agentType),hn=pn===H?"direct":Pt?"incompatible":(Ui=m==null?void 0:m.compatibility)==null?void 0:Ui.status,Zt=hn!==void 0&&hn!=="direct",Ur=(m==null?void 0:m.occupancy)==="owned-externally"||Zt,ut=xo(H,qe),qn=Wt||he,bt=qn&&!Ur&&!ut,Bt=d.useRef(new Set),[xn,mn]=d.useState("idle"),Hn=d.useRef("idle"),Vn=d.useRef(null),[Qn,qr]=d.useState(()=>Date.now()),bn=!!(H&&(q===H||Bt.current.has(H))),Ze=Ad(m,bn),et=bn||Cd(m),Hr=H?kt[H]??[]:[],Vr=H?Ln[H]??{}:{},Tt=Vl(Hr),Yt=Se[Se.length-1],Mt=!!((Yt==null?void 0:Yt.role)==="assistant"&&xn==="thinking"&&((Hi=(qi=Yt.presentation)==null?void 0:qi.reasoning)!=null&&Hi.some(s=>s.text.trim()))),Qr=xn==="tools"&&Se.some(s=>{var u;return((u=s.toolCalls)==null?void 0:u.length)&&!Os(s.toolCalls)}),Ft=et&&!Tt&&!Mt&&!Qr;d.useEffect(()=>{Dn()},[]),d.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(s=>Ce(s))},[]);const[Ne,ze]=d.useState(""),[yt,Kn]=d.useState(null),[br,yn]=d.useState(""),[Jt,Kr]=d.useState(null),[tt,nt]=d.useState(null),_e=d.useRef(null),[Gr,yr]=d.useState(!1),[Xt,vt]=d.useState(!1),[$t,Gn]=d.useState(!1),[Ot,en]=d.useState("full-access"),[wt,Zr]=d.useState(!1),[We,Et]=d.useState({active:null,queued:[],history:[]}),[Zn,vr]=d.useState(null),[wr,ve]=d.useState(!1),Ut=d.useRef(null),He=d.useRef(null),je=d.useCallback((s,u)=>{const f=Pe.current||Xe.current;if(u===f&&Et(ba(s)),!u.startsWith("runtime:"))return;const x=G(u);we(Fs(x,$s(s)),u)},[G,we]);d.useEffect(()=>{if(!Xt)return;const s=u=>{Ut.current&&!Ut.current.contains(u.target)&&vt(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[Xt]),d.useEffect(()=>{if(!$t)return;const s=u=>{He.current&&!He.current.contains(u.target)&&Gn(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[$t]),d.useEffect(()=>{Gn(!1),en(Ta(m==null?void 0:m.permissionMode))},[he,n,m==null?void 0:m.permissionMode]);const[jr,re]=d.useState(null),[Yn,tn]=d.useState(null),[Jn,qt]=d.useState(0),[Ye,kr]=d.useState([]),[vn,wn]=d.useState([]),[Yr,jn]=d.useState(0),[ys,kn]=d.useState(null),rt=d.useRef(null),Jr=d.useRef(null),nn=d.useRef(null),Sr=d.useRef(()=>{}),Ir=d.useRef(()=>{}),st=d.useRef(null),Ht=d.useRef(null),c=d.useRef(null);c.current||(c.current=new sd);const w=d.useRef(null),R=d.useRef("latest"),N=d.useRef(null),P=d.useRef(!1),te=d.useRef(null),Y=d.useRef(0),se=d.useRef(0),Me=d.useRef(null),Ee=d.useRef(!1),Be=d.useRef(!1),oe=d.useRef(null),X=d.useRef(!1),Fe=d.useRef(!1),pt=d.useRef(new Set),it=d.useRef(null),jt=d.useRef(!1),Je=d.useRef(!1),Ae=d.useRef(null),Re=d.useRef(null),[de,$e]=d.useState(!1),[Xn,Xr]=d.useState(null),[vs,ws]=d.useState(null),[js,So]=d.useState("latest"),[Io,er]=d.useState(null),[Co,tr]=d.useState(null),[Ao,nr]=d.useState(!1),[Ro,ji]=d.useState(!1),[ks,es]=d.useState(!1),[ts,Ss]=d.useState(!1),[To,ns]=d.useState(!1),ki=d.useRef(null),Cr=d.useRef(null),Is=d.useRef(null),[rn,Si]=d.useState(null),[Mo,Ii]=d.useState([]),[Eo,Ci]=d.useState([]),[Ar,Cs]=d.useState([]),[Rr,Sn]=d.useState(null),[In,Cn]=d.useState(null),Nt=d.useCallback((s,u)=>{const f=window.agentApi;!u||!f||c.current.prefetch(s,u,()=>f.getSession(s,{before:u,limit:Mn})).catch(x=>{console.warn("[chat] failed to prefetch older history",{sessionId:s,error:x})})},[]),An=d.useCallback(s=>{R.current=s,So(s)},[]);d.useEffect(()=>{if(!he||!H){it.current=null;return}if(it.current!==H){it.current=H,ze(vd(H));return}if(jt.current&&Ne===""){jt.current=!1;return}Bs(H,Ne)},[Ne,he,H]);const No=()=>{const s=rt.current;s&&(s.scrollTop<=240&&Sr.current(),R.current==="anchored"&&s.scrollHeight-s.scrollTop-s.clientHeight<=240&&Ir.current(),s.classList.add("is-scrolling"),nn.current!==null&&window.clearTimeout(nn.current),nn.current=window.setTimeout(()=>{s.classList.remove("is-scrolling"),nn.current=null},700))};d.useEffect(()=>()=>{nn.current!==null&&window.clearTimeout(nn.current)},[]),d.useLayoutEffect(()=>{const s=Ae.current,u=rt.current;!s||!u||(u.scrollTop=s.scrollTop+(u.scrollHeight-s.scrollHeight),Ae.current=null)},[j]),d.useLayoutEffect(()=>{const s=Me.current,u=rt.current;if(!s||!u)return;const f=Array.from(u.querySelectorAll("[data-message-id]")).find(x=>x.dataset.messageId===s);f&&(Gs(u,f),Me.current=null,er(s))},[j]),d.useLayoutEffect(()=>{const s=rt.current;!Ee.current||!s||js!=="latest"||(Ee.current=!1,s.scrollTop=s.scrollHeight)},[js,j]);const[Ai,As]=d.useState(!1),[Tr,Mr]=d.useState(null),rs=d.useRef(null);d.useEffect(()=>{const s=window.agentApi;if(!(s!=null&&s.onTtsStart)||!s.onTtsPcm||!s.onTtsStreamEnd||!s.onTtsFlush)return;const u=new Jl(s),f=[s.onTtsStart(x=>u.start(x)),s.onTtsPcm(({generation:x,pcm:z})=>u.enqueue(x,z)),s.onTtsStreamEnd(({generation:x})=>u.finish(x)),s.onTtsFlush(({generation:x})=>u.flush(x)),s.onTtsEnd(()=>Mr(null))];return()=>{for(const x of f)x();u.dispose()}},[]);const zo=()=>{var f;if(Ai){(f=rs.current)==null||f.stop(),rs.current=null,As(!1);return}as(window.agentApi,Wr);const s=Ne?`${Ne.trimEnd()} `:"",u=Kl({onInterim:x=>ze(s+x),onFinal:x=>{var z;ze(s+x),(z=Cr.current)==null||z.focus()},onError:x=>re(x),onEnd:()=>{As(!1),rs.current=null}});u&&(rs.current=u,As(!0))},_o=async(s,u)=>{var f;if(Tr===s){await as(window.agentApi,Wr),Mr(null);return}if(await as(window.agentApi,Wr),!((f=window.agentApi)!=null&&f.ttsSpeak)){re("TTS 模型服务不可用");return}Mr(s);try{(await window.agentApi.ttsSpeak(u)).ok||(Mr(null),re("TTS 模型播报失败"))}catch(x){Mr(null),re(x instanceof Error?x.message:"TTS 模型播报失败")}},Oe=d.useRef(null),rr=d.useRef(!1),sr=d.useRef(new Set),Er=d.useRef(new Map),Ri=d.useRef(new Set),Pe=d.useRef(n??null),Xe=d.useRef(null),Nr=d.useRef(0);d.useEffect(()=>{Pe.current=n??null},[n]),d.useEffect(()=>{Xe.current=le},[le]),d.useEffect(()=>()=>{for(const s of Er.current.values())window.clearTimeout(s);Er.current.clear()},[]);const ss=d.useCallback(async s=>{var f;const u=s||Pe.current||Xe.current;if(!u||!((f=window.agentApi)!=null&&f.getSessionGoals)){Et({active:null,queued:[],history:[]});return}try{const x=await window.agentApi.getSessionGoals(u);je(x,u),x.active&&(Oe.current=u,C(u))}catch(x){re(x instanceof Error?x.message:"目标状态加载失败")}},[je,C]);d.useEffect(()=>{ss(H)},[H,ss]);const Ve=d.useCallback(s=>{const u=Pe.current||Xe.current;s==="thinking"&&(Hn.current!=="thinking"||Vn.current!==u)?(Vn.current=u,qr(Date.now())):s!=="thinking"&&(Vn.current=null),Hn.current=s,mn(s)},[]),Wo=d.useCallback(s=>{Vn.current=s,Hn.current="thinking",qr(Date.now()),mn("thinking")},[]);d.useEffect(()=>{xt(void 0),Ct(void 0),un(!1),kn(null)},[n]),d.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(s=>Ii(s)),window.agentApi.listSkills().then(s=>Ci(s.filter(u=>u.name))).catch(s=>console.error("[listSkills] mount error:",s)))},[]);const Ti=Rr===null?[]:Mo.filter(s=>Rr===""||s.name.toLowerCase().includes(Rr.toLowerCase())),Rs=In===null?[]:[...[{name:"goal",description:"目标模式:持续推进当前目标,后续目标自动排队"},{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(s=>In===""||s.name.toLowerCase().includes(In.toLowerCase())),...Eo.filter(s=>In===""||s.name.toLowerCase().includes(In.toLowerCase()))],Lo=s=>{Cs(u=>u.find(f=>f.id===s.id)?u:[...u,s]),ze(u=>u.replace(/@[\w\u4e00-\u9fff]*$/,"")),Sn(null),setTimeout(()=>{var u;return(u=Cr.current)==null?void 0:u.focus()},0)},Po=s=>{Cs(u=>u.filter(f=>f.id!==s))},Do=s=>{ze(u=>u.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${s.name} `)),Cn(null),setTimeout(()=>{var u;return(u=Cr.current)==null?void 0:u.focus()},0)},Mi=s=>{var x,z;ze(s);const u=s.match(/@([\w\u4e00-\u9fff]*)$/);if(u){window.agentApi&&window.agentApi.listAgentDefs().then(v=>Ii(v)),Si(((x=Is.current)==null?void 0:x.getBoundingClientRect())??null),Sn(u[1]),Cn(null);return}const f=s.match(/\/([-\w\u4e00-\u9fff]*)$/);if(f){window.agentApi&&window.agentApi.listSkills().then(v=>Ci(v.filter(T=>T.name))).catch(v=>console.error("[listSkills] slash error:",v)),Si(((z=Is.current)==null?void 0:z.getBoundingClientRect())??null),Cn(f[1]),Sn(null);return}Sn(null),Cn(null)},Bo=s=>{Mi(s),Sn(null),Cn(null),requestAnimationFrame(()=>{var u;return(u=Cr.current)==null?void 0:u.focus()})},Fo=s=>{s.key==="Escape"&&(Rr!==null||In!==null)?(s.preventDefault(),Sn(null),Cn(null)):s.key==="Escape"&&bn?(s.preventDefault(),Pi()):s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),$i())},$o=async s=>{const u=Array.from(s.target.files??[]);if(s.target.value="",u.length===0)return;const f=u.filter(x=>x.type.toLowerCase().startsWith("image/")).length;f>0&&jn(x=>x+1);try{const x=await jc(u,async v=>Ei(await ha(v)));x.attachments.length>0&&kr(v=>[...v,...x.attachments]),x.images.length>0&&(wn(v=>[...v,...x.images]),he||qo());const z=[...x.unsupportedImages,...x.failedImages];z.length>0&&re(`无法添加图片:${z.map(v=>v.name).join("、")}。仅支持 JPG、PNG、GIF 和 WebP。`)}finally{f>0&&jn(x=>Math.max(0,x-1))}},Oo=s=>{kr(u=>u.filter((f,x)=>x!==s))},Uo=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,Ts=s=>Uo.test(s),qo=()=>{const s=dt.find(f=>f.id===St);if(s&&Ts(s.modelId))return;const u=dt.find(f=>Ts(f.modelId));u&&gt(u.id)},Ho=s=>{wn(u=>[...u,s])},Vo=s=>{wn(u=>u.filter((f,x)=>x!==s))},Ei=s=>new Promise((u,f)=>{const x=new FileReader;x.onload=()=>u(x.result),x.onerror=f,x.readAsDataURL(s)});d.useEffect(()=>{const s=async u=>{if(!u.clipboardData)return;const f=Array.from(u.clipboardData.items).find(z=>z.type.startsWith("image/"));if(!f)return;u.preventDefault();const x=f.getAsFile();if(x){jn(z=>z+1);try{Ho(await Ei(await ha(x)))}catch{re("无法添加图片。仅支持 JPG、PNG、GIF 和 WebP。")}finally{jn(z=>Math.max(0,z-1))}}};return window.addEventListener("paste",s),()=>window.removeEventListener("paste",s)},[dt,St]),d.useEffect(()=>{var u;const s=Re.current;Re.current=null,s!=="skip"&&((u=Jr.current)==null||u.scrollIntoView({behavior:s==="instant"?"auto":"smooth"}))},[j]),d.useEffect(()=>window.agentApi?window.agentApi.onEvent(u=>Qo(u)):void 0,[le]),d.useEffect(()=>{const s=++Nr.current,u=n;let f=null;const x=()=>Nr.current===s&&Pe.current===u;return(async()=>{var $,D,B,ie,ee,V;const v=window.agentApi;if(!v||nc(Oe.current,Xe.current,u))return;if(!u){if(!x())return;($=c.current)==null||$.invalidate(),U(),re(null),tn(null),At(null),Bn(null),st.current=null,Ht.current=null,N.current=null,Y.current+=1,te.current=null,ws(null),An("latest"),er(null),tr(null),Be.current=!1,es(!1),nr(!1),Xr(null),Ss(!1),ns(!1),w.current=null,Xe.current=null,W(""),en("full-access");return}re(null),tn(null),At(null),Bn(null),Xr(null),(D=c.current)==null||D.invalidate(),se.current+=1,st.current=null,Ht.current=null,N.current=null,An("latest"),nr(!1),er(null),tr(null),Be.current=!1,es(!1),((B=te.current)==null?void 0:B.sessionId)!==u&&(Y.current+=1,te.current=null,ws(null)),Ss(!0),ns(!1),w.current=u,Xe.current=u,W(u);const T=G(u);we(T,u),f=window.setTimeout(()=>{x()&&ns(!0)},500);try{const Q=await ud(async()=>{if(!x())throw new DOMException("Session selection changed","AbortError");return v.getSession(u,{limit:Mn})}),J=Q,xe=ia((Q==null?void 0:Q.events)??[]),ce=sa((Q==null?void 0:Q.events)??[]),Te=aa((Q==null?void 0:Q.events)??[]),ke=ir(Q);if(!x())return;m!=null&&m.compatibility&&At(u),en(Ta((J==null?void 0:J.permissionMode)??((ie=J==null?void 0:J.metadata)==null?void 0:ie.permissionMode)));const De=((ee=Q==null?void 0:Q.history)==null?void 0:ee.nextCursor)??null;st.current=De,Ht.current=De,N.current=null;const Rn=G(u),Z=Rn.length>0&&ge.getState().runningSessionId===u?Rn:ke,Ue=Q!=null&&Q.goalState&&u.startsWith("runtime:")?Fs(Z,$s(Q.goalState)):Z;Re.current="instant",we(Ue,u),Nt(u,De),zt(ce,u),lt(Te,u),so(Q)?(Oe.current=u,C(u)):Oe.current===u&&(Oe.current=null,C(null)),xe&&Le(xe,u);const at=Ue[Ue.length-1];if((at==null?void 0:at.role)==="assistant"&&((V=at.toolCalls)!=null&&V.length)){const me=Os(at.toolCalls);Ve(me?"thinking":"tools")}else Ve((Q==null?void 0:Q.agentType)!=="customer-agent"&&(Q==null?void 0:Q.status)==="running"?"thinking":"idle")}catch(Q){if(!x())return;console.error("[chat] failed to restore session",{sessionId:u,error:Q});const J=cd(Q);tn(J),m!=null&&m.compatibility&&Bn(J)}finally{f!==null&&window.clearTimeout(f),x()&&(Ss(!1),ns(!1))}})(),()=>{f!==null&&window.clearTimeout(f),Nr.current===s&&(Nr.current+=1)}},[U,G,Nt,n,Jn,Le,An,we,W,Ve]);const sn=d.useCallback(async s=>{const u=window.agentApi;if(!(u!=null&&u.getSessionQueryIndex))return null;const f=++Y.current;try{const x=await u.getSessionQueryIndex(s);return Y.current!==f||Pe.current!==s||x.sessionId!==s?null:(te.current=x,ws(x),x)}catch(x){return Y.current===f&&console.warn("[chat] failed to load query index",{sessionId:s,error:x}),null}},[]);d.useEffect(()=>{var v;const s=n;if(!s||ts||!((v=window.agentApi)!=null&&v.getSessionQueryIndex))return;let u=!1;const f=()=>{!u&&Pe.current===s&&sn(s)},x=window,z=x.requestIdleCallback?x.requestIdleCallback(f,{timeout:1e3}):window.setTimeout(f,0);return()=>{u=!0,x.cancelIdleCallback&&x.requestIdleCallback?x.cancelIdleCallback(z):window.clearTimeout(z)}},[ts,sn,n,Jn]);const Ni=d.useCallback(async s=>{var u,f,x,z,v;if(!(!window.agentApi||document.visibilityState==="hidden")){if(R.current==="anchored"){nr(!0);return}if(oe.current!==s&&(oe.current=s,X.current=!1,Fe.current=!1),X.current){Fe.current=!0;return}X.current=!0;try{do{Fe.current=!1;const T=await window.agentApi.getSession(s,{limit:Mn});if(Pe.current!==s||w.current!==s)return;const $=ir(T),D=G(s),B=Xl(D,$),ie=T!=null&&T.goalState&&s.startsWith("runtime:")?Fs(B,$s(T.goalState)):B,ee=rt.current,V=!ee||ee.scrollHeight-ee.scrollTop-ee.clientHeight<80;Re.current=V?null:"skip",we(ie,s),T!=null&&T.goalState&&Et(ba(T.goalState));const Q=Ht.current,J=((u=T==null?void 0:T.history)==null?void 0:u.nextCursor)??null;if(st.current===Q){const Te=st.current!==J;st.current=J,Te&&((f=c.current)==null||f.invalidate(),Nt(s,J))}Ht.current=J,(x=T==null?void 0:T.history)!=null&&x.revision&&T.history.revision!==((z=te.current)==null?void 0:z.revision)&&sn(s);const xe=ia((T==null?void 0:T.events)??[]);zt(sa((T==null?void 0:T.events)??[]),s),lt(aa((T==null?void 0:T.events)??[]),s),xe&&Le(xe,s);const ce=ie[ie.length-1];(ce==null?void 0:ce.role)==="assistant"&&((v=ce.toolCalls)!=null&&v.length)?Ve(Os(ce.toolCalls)?"thinking":"tools"):Ve(gi(T)?"thinking":"idle")}while(Fe.current)}catch(T){console.error("[chat] failed to refresh native session history",{sessionId:s,error:T})}finally{oe.current===s&&(X.current=!1)}}},[G,sn,Nt,Le,we,Ve]);d.useEffect(()=>{const s=n,u=Rd(m,s),f=(m==null?void 0:m.occupancy)==="owned-externally"||(m==null?void 0:m.status)==="running";if(!s||!u||!window.agentApi)return;let x=null,z=null,v=!1;const T=()=>{!v&&document.visibilityState!=="hidden"&&Ni(s)},$=()=>{x==null||x(),x=null,z!==null&&window.clearInterval(z),z=null},D=()=>{v||z!==null||document.visibilityState==="hidden"||(T(),z=window.setInterval(T,2e3))},B=()=>{if(!(v||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){f&&D();return}try{x=window.agentApi.observeSession(s,T,()=>{x=null,f&&D()})}catch{f&&D()}}},ie=()=>{$(),document.visibilityState!=="hidden"&&(T(),B())};return B(),document.addEventListener("visibilitychange",ie),()=>{v=!0,document.removeEventListener("visibilitychange",ie),$(),oe.current===s&&(oe.current=null,Fe.current=!1)}},[Ni,n,q,m==null?void 0:m.agentType,m==null?void 0:m.occupancy,m==null?void 0:m.status]);const Ms=d.useCallback(async()=>{var z;const s=w.current,u=st.current,f=window.agentApi;if(!f||!s||!u||Je.current)return;Je.current=!0,Xr(null);const x=window.setTimeout(()=>{w.current===s&&Je.current&&$e(!0)},500);try{const v=await c.current.consume(s,u,()=>f.getSession(s,{before:u,limit:Mn}));if(w.current!==s||Pe.current!==s)return;const T=ir(v),$=G(s),D=rt.current;D&&T.length>0&&(Ae.current={scrollHeight:D.scrollHeight,scrollTop:D.scrollTop},Re.current="skip");const B=((z=v==null?void 0:v.history)==null?void 0:z.nextCursor)??null;st.current=B,T.length>0&&we([...T,...$],s),Nt(s,B)}catch(v){if(w.current!==s)return;console.error("[chat] failed to load older history",{sessionId:s,error:v}),Xr(v instanceof Error?v.message:"历史消息加载失败")}finally{window.clearTimeout(x),Je.current=!1,w.current===s&&$e(!1)}},[G,Nt,we]);d.useEffect(()=>{Sr.current=()=>{Ms()}},[Ms]);const zi=d.useCallback(async()=>{var f;const s=w.current,u=N.current;if(!(!window.agentApi||!s||!u||R.current!=="anchored"||P.current)){P.current=!0,ji(!0);try{const x=await window.agentApi.getSession(s,{after:u,limit:Mn});if(Pe.current!==s||w.current!==s||R.current!=="anchored")return;const z=G(s),v=new Set(z.map($=>$.id)),T=ir(x).filter($=>!v.has($.id));N.current=((f=x==null?void 0:x.history)==null?void 0:f.newerCursor)??null,T.length>0&&(Re.current="skip",we([...z,...T],s))}catch(x){console.error("[chat] failed to load newer anchored history",{sessionId:s,error:x})}finally{P.current=!1,ji(!1)}}},[G,we]);d.useEffect(()=>{Ir.current=()=>{zi()}},[zi]);const _i=d.useCallback(async()=>{var f,x,z,v,T,$;const s=Pe.current;if(!window.agentApi||!s||Be.current)return!1;const u=++se.current;Be.current=!0,es(!0),tr(null);try{const D=await window.agentApi.getSession(s,{limit:Mn});if(se.current!==u||Pe.current!==s)return!1;const B=ir(D),ie=((f=D==null?void 0:D.history)==null?void 0:f.nextCursor)??null;return(x=c.current)==null||x.invalidate(),st.current=ie,Ht.current=ie,N.current=null,An("latest"),nr(!1),er(((v=(z=te.current)==null?void 0:z.entries.at(-1))==null?void 0:v.messageId)??null),Ee.current=!0,Re.current="skip",we(B,s),Nt(s,ie),((T=D==null?void 0:D.history)==null?void 0:T.revision)!==(($=te.current)==null?void 0:$.revision)&&sn(s),!0}catch(D){return re(D instanceof Error?D.message:"返回最新消息失败"),!1}finally{Be.current=!1,es(!1)}},[sn,Nt,An,we]),Wi=d.useCallback(async(s,u=!0)=>{var T,$,D,B,ie,ee;const f=Pe.current,x=rt.current;if(!window.agentApi||!f||!x)return;const z=++se.current;er(s.messageId);const v=Array.from(x.querySelectorAll("[data-message-id]")).find(V=>V.dataset.messageId===s.messageId);if(v){tr(null),Gs(x,v,"smooth");return}tr(s.messageId),(T=c.current)==null||T.invalidate();try{const V=await window.agentApi.getSession(f,{anchor:s.pageToken,limit:Mn});if(se.current!==z||Pe.current!==f||(($=te.current)==null?void 0:$.revision)!==((D=V==null?void 0:V.history)==null?void 0:D.revision))return;const Q=ir(V),J=((B=V==null?void 0:V.history)==null?void 0:B.olderCursor)??((ie=V==null?void 0:V.history)==null?void 0:ie.nextCursor)??null;st.current=J,N.current=((ee=V==null?void 0:V.history)==null?void 0:ee.newerCursor)??null,An("anchored"),nr(!1),Me.current=s.messageId,Re.current="skip",we(Q,f),window.requestAnimationFrame(()=>{if(se.current!==z||Pe.current!==f)return;const xe=rt.current,ce=Array.from((xe==null?void 0:xe.querySelectorAll("[data-message-id]"))??[]).find(Te=>Te.dataset.messageId===s.messageId);!xe||!ce||(Gs(xe,ce),Me.current=null,er(s.messageId))}),Nt(f,J)}catch(V){if(V.code==="STALE_SESSION_ANCHOR"&&u){const J=await sn(f),xe=J==null?void 0:J.entries.find(ce=>ce.ordinal===s.ordinal);xe&&await Wi(xe,!1);return}console.error("[chat] failed to open indexed query",{sessionId:f,error:V}),re(V instanceof Error?V.message:"无法打开这条消息")}finally{se.current===z&&tr(null)}},[sn,Nt,An,we]),Li=s=>{if(sr.current.has(s)||Er.current.has(s))return;const u=window.setTimeout(()=>{Er.current.delete(s),(async()=>{var f;if(!sr.current.has(s))try{const x=await((f=window.agentApi)==null?void 0:f.getSessionGoals(s)),z=Pe.current||Xe.current;if(x&&s===z&&je(x,s),x!=null&&x.active){Oe.current=s,s===z&&(rr.current=!1,re(null),C(s));return}if(rr.current)return;const v=ge.getState().getMessagesForSession(s).find(T=>T.isQueued&&!T.queueItemId);if(!v){s===z&&(Oe.current=null,C(null));return}fe(v.id,T=>({...T,isQueued:!1}),s),is(v,s)}catch(x){re(x instanceof Error?x.message:"排队消息自动发送失败")}})()},150);Er.current.set(s,u)},Qo=s=>{var z,v,T;const u=Pe.current||Xe.current,f=s._sid||u||void 0;if(s._nativeRunId&&Number.isSafeInteger(s._nativeSequence)){const $=`${s._nativeRunId}:${s._nativeSequence}`;if(pt.current.has($))return;pt.current.add($),pt.current.size>2e3&&(pt.current=new Set([...pt.current].slice(-1e3)))}const x=!f||f===u;if(x&&R.current==="anchored"){nr(!0);return}switch(s.type){case"run_admitted":f&&f===u&&wd(f);break;case"context_usage":s.usage&&Le(s.usage,f);break;case"text_chunk":s.text&&(K(s.text,f),x&&Ve("thinking"));break;case"reasoning_summary_delta":typeof s.itemId=="string"&&Number.isSafeInteger(s.sectionIndex)&&typeof s.delta=="string"&&(S({type:"reasoning_summary_delta",itemId:s.itemId,sectionIndex:s.sectionIndex,delta:s.delta},f),x&&Ve("thinking"));break;case"runtime_progress":if(typeof s.progressId=="string"&&typeof s.label=="string"&&["thinking","tool","retry","status"].includes(s.phase??"")){const $={progressId:s.progressId,phase:s.phase,label:s.label,...s.detail===void 0?{}:{detail:s.detail},...s.toolCallId===void 0?{}:{toolCallId:s.toolCallId},...s.elapsedSeconds===void 0?{}:{elapsedSeconds:s.elapsedSeconds},...s.current===void 0?{}:{current:s.current},...s.total===void 0?{}:{total:s.total}};Pn($,f),x&&Ve($.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(z=s.activity)!=null&&z.parentToolCallId&&(pr(s.activity,f),x&&s.activity.status==="running"&&Ve("tools"));break;case"tool_call":x&&Ve("tools"),s.toolCall&&s.toolCall.name!=="dispatch_agent"&&s.toolCall.name!=="ask_user"&&s.toolCall.name!=="show_widget"&&A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:s.toolCall.id,name:s.toolCall.name,arguments:s.toolCall.arguments}],timestamp:Date.now()},f);break;case"tool_result":s.result&&E(s.result.toolCallId,s.result.content,s.result.isError,f);break;case"todo_update":s.todos&&be(s.todos);break;case"cron_update":s.tasks&&Ce(s.tasks);break;case"agent_dispatch":if(A({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:s.agentName,task:s.task??"",subSessionId:s.subSessionId}}],timestamp:Date.now()},f),s.subSessionId){Bt.current.add(s.subSessionId);const $=Oe.current||le;$&&o&&o($)}p==null||p({type:"started",agentName:s.agentName??"",task:s.task??"",subSessionId:s.subSessionId});break;case"agent_done":s.subSessionId&&(Bt.current.delete(s.subSessionId),L(s.subSessionId,s.status??"completed",s.status==="failed"?s.error:s.summary,f)),p==null||p({type:s.status==="failed"?"failed":"completed",agentName:s.agentName??"",task:s.task??"",subSessionId:s.subSessionId});break;case"agent_progress":s.subSessionId&&s.text&&ae(s.subSessionId,s.text,f);break;case"compacted":A({id:crypto.randomUUID(),role:"assistant",content:s.summary??"",isCompactionSummary:!0,timestamp:Date.now()},f);break;case"show_widget":{const $=s.data??s.widgetData,D={widgetId:s.widgetId,widgetType:s.widgetType,data:$??{}},ie=(f?ge.getState().getMessagesForSession(f):ge.getState().messages).find(ee=>{var V;return((V=ee.widget)==null?void 0:V.widgetId)===D.widgetId});ie?fe(ie.id,ee=>({...ee,widget:D}),f):A({id:crypto.randomUUID(),role:"assistant",content:"",widget:D,timestamp:Date.now()},f);break}case"ask_user":if(s.questionId&&(f?ge.getState().getMessagesForSession(f):ge.getState().messages).some(D=>{var B;return((B=D.askUser)==null?void 0:B.questionId)===s.questionId}))break;A({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:s.questionId??"",question:s.question??"",options:s.options,fields:s.fields,multiSelect:s.multiSelect},timestamp:Date.now()},f);break;case"approval_resolved":{if(!s.questionId)break;const D=(f?ge.getState().getMessagesForSession(f):ge.getState().messages).find(B=>{var ie;return((ie=B.askUser)==null?void 0:ie.questionId)===s.questionId});D&&fe(D.id,B=>({...B,askUser:B.askUser?{...B.askUser,answered:!0,answer:"已处理"}:B.askUser}),f);break}case"text_done":break;case"thinking":x&&Ve("thinking");break;case"done":if(f){const $=ho(s.durationMs);if($!==void 0){const D=[...G(f)].reverse().find(B=>{var ie;return B.role==="assistant"&&!!B.content.trim()&&!((ie=B.toolCalls)!=null&&ie.length)&&!B.isCompactionSummary});D&&fe(D.id,B=>({...B,presentation:{...B.presentation,completionDurationMs:$}}),f)}}if(_t(f),x&&!ge.getState().messages.some($=>$.isQueued)&&C(null),x&&(Ve("idle"),ot.getState().autoSpeak)){const D=[...ge.getState().messages].reverse().find(B=>B.role==="assistant"&&B.content&&!B.isCompactionSummary);D!=null&&D.content&&(v=window.agentApi)!=null&&v.ttsSpeak&&(Wr(),window.agentApi.ttsSpeak(D.content.slice(0,600)).then(B=>{B.ok||re("TTS 模型播报失败")}).catch(B=>{re(B instanceof Error?B.message:"TTS 模型播报失败")}))}f&&(sr.current.has(f)?window.setTimeout(()=>{ss(f)},150):Li(f));break;case"error":if(s._preserveActiveRun||_t(f),x){if(s._preserveActiveRun&&f&&(Ri.current.add(f),Oe.current=f,C(f),Ve("thinking")),s.code==="SESSION_ALREADY_RUNNING"){const $=f?ge.getState().getMessagesForSession(f):ge.getState().messages,D=kd($);if(D){const B=$.find(ie=>ie.id===D);fe(D,ie=>({...ie,isQueued:!0}),f),gn&&(f!=null&&f.startsWith("runtime:"))&&B&&((T=window.agentApi)!=null&&T.enqueueSessionMessage)&&window.agentApi.enqueueSessionMessage(f,{sourceMessageId:B.id,content:B.content,images:B.images,agentName:B.agentName}).then(ie=>je(ie,f)).catch(ie=>{re(ie instanceof Error?ie.message:"排队消息保存失败")})}Ct(void 0),xt(void 0),re(null)}else if(s.code==="SESSION_OCCUPIED"){const D=[...f?ge.getState().getMessagesForSession(f):ge.getState().messages].reverse().find(B=>B.role==="user"&&!B.isQueued);Ct(D==null?void 0:D.content),D!=null&&D.content&&(ze(D.content),f&&Bs(f,D.content)),f&&xt({sessionId:f,code:s.code}),re(null)}else{re(s.message??"Unknown error");const D=[...f?ge.getState().getMessagesForSession(f):ge.getState().messages].reverse().find(B=>B.role==="user"&&!B.isQueued);he&&(D!=null&&D.content)&&(ze(D.content),f&&Bs(f,D.content))}s._preserveActiveRun||(C(null),Ve("idle"))}f&&!s._preserveActiveRun&&(sr.current.has(f)?window.setTimeout(()=>{ss(f)},150):Li(f));break;case"turn_aborted":_t(f),x&&(C(null),Ve("idle"));break}},Ko=async s=>{var f;if(!H||!((f=window.agentApi)!=null&&f.setSessionPermissionMode)||wr)return;const u=Ot;en(s),Gn(!1),ve(!0);try{await window.agentApi.setSessionPermissionMode(H,s)}catch(x){en(u),re(x instanceof Error?x.message:"权限模式更新失败")}finally{ve(!1)}},Go=async()=>{var s;if(!(!H||!((s=window.agentApi)!=null&&s.handoffSession)))try{await window.agentApi.handoffSession(H),re(null)}catch(u){re(u instanceof Error?u.message:"交接到 Desktop 失败")}},Zo=async()=>{var s;if(!(!H||!((s=window.agentApi)!=null&&s.forkSession)||cn)){un(!0);try{await kc({sourceSessionId:H,forkSession:u=>window.agentApi.forkSession(u),activateSession:u=>{Xe.current=u,W(u)},refreshAndSelect:async u=>{i?await i(u.id,u):l==null||l(u.id)}}),It&&ze(It),Ct(void 0),xt(void 0),re(null)}catch(u){re(u instanceof Error?u.message:"创建会话副本失败")}finally{un(!1)}}},Pi=()=>{rr.current=!0,Nr.current+=1,window.agentApi&&window.agentApi.abort(H||void 0),Oe.current=null,C(null),Bt.current.clear()},Di=async s=>{const u=n||le;if(!u||!window.agentApi)return;const f=ge.getState().messages.find(x=>x.id===s);if(!(!f||!f.isQueued))try{f.queueItemId&&u.startsWith("runtime:")?je(await window.agentApi.steerSessionMessage(u,f.queueItemId),u):(await window.agentApi.steer(f.content,u,f.agentName),fe(s,x=>({...x,isQueued:!1,isSteered:!0}))),yt===s&&(Kn(null),yn(""))}catch(x){re(x instanceof Error?x.message:"引导失败")}},Yo=s=>{const u=ge.getState().messages.find(f=>f.id===s&&f.isQueued);u&&(Kn(s),yn(u.content))},Es=()=>{Kn(null),yn("")},Bi=async s=>{const u=br.trim(),f=ge.getState().messages.find(x=>x.id===s&&x.isQueued);if(!(!f||!u))try{f.queueItemId&&(H!=null&&H.startsWith("runtime:"))?je(await window.agentApi.updateSessionMessage(H,f.queueItemId,u),H):fe(s,x=>x.isQueued?{...x,content:u}:x,H||void 0),Es()}catch(x){re(x instanceof Error?x.message:"排队消息保存失败")}},Jo=async s=>{const u=ge.getState().messages.find(f=>f.id===s&&f.isQueued);if(u){if(!await Ds(u.content)){re("复制排队消息失败");return}Kr(s),window.setTimeout(()=>Kr(f=>f===s?null:f),1200)}},Xo=async s=>{const u=ge.getState().messages,f=u.find(x=>x.id===s&&x.isQueued);if(f)try{f.queueItemId&&(H!=null&&H.startsWith("runtime:"))?je(await window.agentApi.cancelSessionMessage(H,f.queueItemId),H):we(u.filter(x=>x.id!==s),H||void 0),yt===s&&Es()}catch(x){re(x instanceof Error?x.message:"排队消息删除失败")}},Ns=async(s,u)=>{const f=ge.getState().messages,x=Sd(f,s,u);if(x!==f){we(x,H||void 0);const z=x.filter(v=>v.isQueued&&v.queueItemId);if(H!=null&&H.startsWith("runtime:")&&z.length>0)try{je(await window.agentApi.reorderSessionMessages(H,z.map(v=>v.queueItemId)),H)}catch(v){we(f,H),re(v instanceof Error?v.message:"排队消息排序保存失败")}}},el=(s,u)=>{const f=ge.getState().messages.filter(v=>v.isQueued),x=f.findIndex(v=>v.id===s),z=f[x+u];z&&Ns(s,z.id)},tl=async s=>{const u=Zn;if(vr(null),!H||!u||u===s)return;const f=We.queued.map($=>$.id),x=f.indexOf(u),z=f.indexOf(s);if(x<0||z<0)return;const v=[...f];v.splice(z,0,v.splice(x,1)[0]);const T=We;Et({...We,queued:v.map(($,D)=>({...We.queued.find(B=>B.id===$),position:D}))});try{je(await window.agentApi.reorderSessionGoals(H,v),H)}catch($){Et(T),re($ instanceof Error?$.message:"目标排序保存失败")}},Fi=async s=>{if(H)try{const u=await window.agentApi.cancelSessionGoal(H,s);je(u,H),u.active||C(null)}catch(u){re(u instanceof Error?u.message:"目标删除失败")}};d.useEffect(()=>{yt&&(j.some(s=>s.id===yt&&s.isQueued)||(Kn(null),yn("")))},[yt,j]);async function is(s,u,f){var x,z;rr.current=!1,sr.current.add(u),Wo(u),Oe.current=u,C(u);try{if(window.agentApi){const v=he&&fs(ue)?{...(x=Ge.model)!=null&&x.id?{model:Ge.model}:{},...Qe?{reasoningEffort:Qe}:{}}:void 0;await window.agentApi.run(s.content,u,f,s.agentName,s.images,v)}}catch(v){re(v instanceof Error?v.message:"Agent run failed")}finally{if(sr.current.delete(u),Ri.current.delete(u)){Oe.current=u,C(u);return}const T=(z=window.agentApi)!=null&&z.getSessionGoals?await window.agentApi.getSessionGoals(u).catch(()=>{}):void 0;if(T&&u===(Pe.current||Xe.current)&&je(T,u),T!=null&&T.active){Oe.current=u,C(u),g&&g(r,u);return}const $=rr.current?void 0:ge.getState().getMessagesForSession(u).find(D=>D.isQueued&&!D.queueItemId);$?(fe($.id,D=>({...D,isQueued:!1}),u),g&&g(r,u),is($,u)):(Oe.current=null,C(null),g&&g(r,u))}}const $i=async()=>{var D,B,ie;if(!Ne.trim()||!bt||Yr>0||R.current==="anchored"&&!await _i())return;as(window.agentApi,Wr),re(null);const s=Ne.trim();if(/^\/loop\b/i.test(s)){const ee=s.slice(5).trim();if(ze(""),A({id:crypto.randomUUID(),role:"user",content:s,timestamp:Date.now()}),/^stop$/i.test(ee)){window.agentApi&&(await window.agentApi.cronDeleteAll(),Ce([]),A({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(ee)||ee===""){if(window.agentApi){const ce=await window.agentApi.cronList();Ce(ce);const Te=ce.length===0?"当前没有定时任务。":ce.map((ke,De)=>`**${De+1}.** \`${ke.id.slice(0,6)}\` · ${Vs(ke.cron)} · ${ke.enabled?"▶ 启用":"⏸ 已暂停"}
259
- ${ke.prompt}`).join(`
260
-
261
- `);A({id:crypto.randomUUID(),role:"assistant",content:Te,timestamp:Date.now()})}return}const V=ee.match(/^(?:pause|暂停)\s+(\S+)$/i);if(V){if(window.agentApi){const ce=Ie.find(ke=>ke.id.startsWith(V[1])),Te=await window.agentApi.cronPause((ce==null?void 0:ce.id)??V[1]);if(Te){const ke=await window.agentApi.cronList();Ce(ke),A({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${Te.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${V[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const Q=ee.match(/^(?:resume|恢复)\s+(\S+)$/i);if(Q){if(window.agentApi){const ce=Ie.find(ke=>ke.id.startsWith(Q[1])),Te=await window.agentApi.cronResume((ce==null?void 0:ce.id)??Q[1]);if(Te){const ke=await window.agentApi.cronList();Ce(ke),A({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${Te.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${Q[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const J=ee.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(J){if(window.agentApi){const ce=Ie.find(ke=>ke.id.startsWith(J[1]));if(await window.agentApi.cronDelete((ce==null?void 0:ce.id)??J[1])){const ke=await window.agentApi.cronList();Ce(ke),A({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${J[1]}\` 已删除。`,timestamp:Date.now()})}else A({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${J[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const xe=ee.match(/^(\S+)\s+(.+)$/s);if(xe){const ce=xe[1],Te=xe[2].trim();if(window.agentApi){let ke=n||le;if(!ke){const De=await window.agentApi.createSession(Te.slice(0,60)||"定时任务",r||void 0);ke=De.id,W(De.id),i&&await i(De.id)}try{const De=await window.agentApi.cronCreate(ce,Te,{sessionId:ke}),Rn=await window.agentApi.cronList();Ce(Rn),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${De.id.slice(0,6)}\`),${Vs(ce)}执行:${Te}`,timestamp:Date.now()})}catch(De){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${De instanceof Error?De.message:String(De)}`,timestamp:Date.now()})}}return}A({id:crypto.randomUUID(),role:"assistant",content:"**定时任务用法:**\n- `/loop <间隔/cron> <任务>` — 创建,如 `/loop 5m 检查系统状态` 或 `/loop 0 9 * * * 早报`\n- `/loop list` — 查看所有定时任务\n- `/loop pause <id>` — 暂停\n- `/loop resume <id>` — 恢复\n- `/loop delete <id>` — 删除\n- `/loop stop` — 删除全部\n\n间隔支持:`30s`、`5m`、`2h`;也支持 5 字段 cron 表达式。",timestamp:Date.now()});return}const u=s.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(u){const ee=u[1]+u[2],V=u[3].trim();if(V&&window.agentApi){let Q=n||le;if(!Q){const J=await window.agentApi.createSession(V.slice(0,60)||"定时任务",r||void 0);Q=J.id,W(J.id),i&&await i(J.id)}try{const J=await window.agentApi.cronCreate(ee,V,{sessionId:Q}),xe=await window.agentApi.cronList();Ce(xe),ze(""),A({id:crypto.randomUUID(),role:"user",content:s,timestamp:Date.now()}),A({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${J.id.slice(0,6)}\`),${Vs(ee)}执行:${V}`,timestamp:Date.now()})}catch(J){A({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${J instanceof Error?J.message:String(J)}`,timestamp:Date.now()})}return}}const f=Ne.trim(),x=f.match(/^\/goal(?:\s+([\s\S]+))?$/i),z=x?((D=x[1])==null?void 0:D.trim())??"":wt?f:null;if(z!==null&&!z){re("请输入目标内容");return}const v=Ar.length>0?Ar.map(ee=>ee.name).join(", "):void 0,T=vn.length>0?[...vn]:void 0,$=Ar.map(ee=>ee.id);if(Cs([]),he&&(n||le)&&(jt.current=!0),ze(""),kr([]),wn([]),z!==null){const ee=crypto.randomUUID();rr.current=!1;try{const V=await ja({text:z,projectId:r??null,sessionId:n||le,createSession:async(J,xe)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(J,xe)},activateSession:J=>{Xe.current=J,W(J),Oe.current=J,C(J)},showUserMessage:(J,xe)=>A({id:ee,role:"user",content:J,timestamp:Date.now(),agentName:v,images:T,isGoal:!0,goalId:ee},xe),onSessionCreated:i}),Q=await window.agentApi.enqueueSessionGoal(V,z,ee);je(Q,V),a&&a(V,z)}catch(V){C(null),re(V instanceof Error?V.message:"目标创建失败")}return}if(Ze){const ee=crypto.randomUUID(),V={id:ee,role:"user",content:f,timestamp:Date.now(),agentName:v,images:T,isQueued:!0};if(he&&gn&&H&&((B=window.agentApi)!=null&&B.enqueueSessionMessage))try{const Q=await window.agentApi.enqueueSessionMessage(H,{sourceMessageId:ee,content:f,images:T,agentIds:$,agentName:v});je(Q,H),((ie=Q.active)==null?void 0:ie.sourceMessageId)===ee&&A({...V,isQueued:!1},H)}catch(Q){ze(f),wn(T??[]),re(Q instanceof Error?Q.message:"排队消息保存失败")}else A(V);return}be([]);try{const ee=await ja({text:f,projectId:r??null,sessionId:n||le,createSession:async(V,Q)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(V,Q)},activateSession:V=>{Xe.current=V,W(V),Oe.current=V,C(V)},showUserMessage:(V,Q)=>A({id:crypto.randomUUID(),role:"user",content:V,timestamp:Date.now(),agentName:v,images:T},Q),onSessionCreated:i});a&&a(ee,f),await is({content:f,agentName:v,images:T},ee,$.length>0?$:void 0)}catch(ee){re(ee instanceof Error?ee.message:"Agent run failed")}};return d.useEffect(()=>{if(!y||!window.agentApi)return;const{text:s,projectId:u,sessionId:f}=y;let x=!1;return(async()=>{try{be([]);const z=await sc({text:s,projectId:u,sessionId:f,createSession:async(v,T)=>await window.agentApi.createSession(v,T),activateSession:v=>{Xe.current=v,W(v),Oe.current=v,C(v)},showUserMessage:(v,T)=>A({id:crypto.randomUUID(),role:"user",content:v,timestamp:Date.now()},T),onSessionCreated:i,isCancelled:()=>x});if(!z)return;a&&a(z,s),await is({content:s},z)}catch(z){re(z instanceof Error?z.message:"语音指令执行失败")}})(),()=>{x=!0}},[y==null?void 0:y.nonce]),e.jsxs("div",{className:"chat-view chat-view--codex-history",style:{display:"flex",flexDirection:"column",height:"100%",maxWidth:"var(--chat-max-width)",margin:"0 auto"},children:[e.jsxs("div",{className:"chat-top-bar",style:{display:"flex",alignItems:"center",padding:"var(--chat-header-padding)",height:"var(--chat-header-height)",flexShrink:0,borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"no-drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:h?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:h||"会话"}),k&&M&&O&&e.jsx(Kd,{appearanceOpen:_,settingsOpen:I,hideToBackgroundTitle:F,onHideToBackground:M,onToggleAppearance:O,onOpenSettings:k})]}),e.jsxs("div",{className:"chat-messages-frame",children:[e.jsxs("div",{ref:rt,className:"chat-messages",onScroll:No,style:{overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[j.length>0&&(de||Xn)&&e.jsx("div",{className:"chat-history-page-status",role:Xn?"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:Xn?"var(--danger)":"var(--text-muted)",fontSize:12},children:de?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 Ms(),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:[Xn,",点击重试"]})}),j.length===0&&ts&&To&&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:"正在加载历史消息"})]}),j.length===0&&!et&&!ts&&!jr&&e.jsx(Yd,{agentType:(m==null?void 0:m.agentType)??t,ready:bt,onSelectPrompt:Bo},H??"initial-empty-session"),Se.map((s,u)=>{var Q,J,xe,ce,Te,ke,De,Rn,zs;const f=s;if(f.isQueued)return null;const x=s.role==="user",z=x&&(f.isGoal===!0||[We.active,...We.queued,...We.history].some(Z=>!!(Z&&Ia(Z.objective)===Ia(s.content)))),v=vc(Se,u,et),T=xc((Q=f.presentation)==null?void 0:Q.completionDurationMs);if(f.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)"}})]},s.id);if(f.widget){const Z=tc[f.widget.widgetType];return Z?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(Z,{...f.widget.data,widgetId:f.widget.widgetId})},s.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(f.widget.data,null,2)},s.id)}if(f.askUser)return e.jsx(Ud,{questionId:f.askUser.questionId,question:f.askUser.question,options:f.askUser.options,fields:f.askUser.fields,multiSelect:f.askUser.multiSelect,answered:f.askUser.answered,answer:f.askUser.answer,onAnswer:(Z,Ue)=>{var at;fe(s.id,me=>({...me,askUser:{...me.askUser,answered:!0,answer:Z}})),(at=window.agentApi)==null||at.answerQuestion(f.askUser.questionId,Z,Ue)}},s.id);const $=f.agentName?f.agentName.charAt(0).toUpperCase():"你",D=!x&&u===Se.length-1,B=Se[u+1],ie=B&&B.role!==s.role&&!B.isCompactionSummary,ee=(s.toolCalls??[]).map((Z,Ue)=>{let at;if(Z.name==="write_file"&&Z.arguments.file_path){const me=Z.arguments.file_path;e:for(let ft=u;ft>=0;ft--){const Vt=Se[ft].toolCalls;if(!Vt)continue;const zr=ft===u?Ue-1:Vt.length-1;for(let Tn=zr;Tn>=0;Tn--){const Qt=Vt[Tn];if(Qt.name==="read_file"&&Qt.arguments.file_path===me&&Qt.result&&!Qt.isError){at=Qt.result;break e}}}}return{toolCall:Z,beforeContent:at,progress:Hl(Hr,Z.id),nativeSubagent:Vr[Z.id]}}),V=hc(ee);return e.jsx("div",{"data-message-id":s.id,className:`chat-message-group${v.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:v.compact?0:ie?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:e.jsxs("div",{className:`chat-message-row chat-message-row--${x?"user":"assistant"}`,style:{display:"flex",flexDirection:x?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[x?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:$}):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--${x?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:x?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${x?"user":"assistant"} ${s.role==="assistant"&&s.content?"message-card":""}`,style:{padding:s.content||x&&((J=f.images)!=null&&J.length)?x?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:x?"14px 4px 14px 14px":"4px 14px 14px 14px",background:s.content||x&&((xe=f.images)!=null&&xe.length)?x?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:s.content||x&&((ce=f.images)!=null&&ce.length)?x?"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:[s.role==="assistant"&&((Te=s.presentation)==null?void 0:Te.reasoning)&&e.jsx(Qd,{sections:s.presentation.reasoning,streaming:et&&D&&xn==="thinking",startedAt:Qn,renderContent:Qs}),x&&f.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"})]}),f.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:s.content})]}):s.role==="assistant"&&s.content?e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:Qs(s.content)}):s.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:x?s.content:Qs(s.content)}),x&&f.images&&f.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:s.content?8:0},children:f.images.map((Z,Ue)=>e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":"放大查看图片",onClick:()=>kn({src:Z,alt:`用户发送的图片 ${Ue+1}`}),children:e.jsx("img",{className:"chat-message-attachment-image",src:Z,alt:`用户发送的图片 ${Ue+1}`})},Ue))}),x&&!((ke=f.images)!=null&&ke.length)&&((De=f.presentation)==null?void 0:De.attachments)&&f.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:f.presentation.attachments.map((Z,Ue)=>Z.dataUrl?e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":`放大查看图片:${Z.name}`,onClick:()=>kn({src:Z.dataUrl,alt:Z.name}),children:e.jsx("img",{className:"chat-message-attachment-image",src:Z.dataUrl,alt:Z.name,title:Z.name})},`${Z.name}-${Ue}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${Z.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:Z.name}),e.jsx("span",{children:"图片已失效"})]},`${Z.name}-${Ue}`))}),x&&((Rn=f.presentation)==null?void 0:Rn.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:f.presentation.rawContent})]}),V.map(Z=>Z.action&&Z.items.length>1?e.jsx($d,{items:Z.items,onSelectSession:l,workspacePath:b,enableFilePreview:or()},`group-${Z.items[0].toolCall.id}`):e.jsx(yi,{toolCall:Z.items[0].toolCall,beforeContent:Z.items[0].beforeContent,progress:Z.items[0].progress,nativeSubagent:Z.items[0].nativeSubagent,onSelectSession:l,workspacePath:b,enableFilePreview:or()},Z.items[0].toolCall.id)),(()=>{const Z=(s.toolCalls??[]).filter(me=>me.name==="write_file"&&me.result&&!me.isError);if(Z.length===0)return null;const Ue=new Map;for(const me of Z){const ft=me.arguments.file_path??"",Vt=me.arguments.content??"",zr=Vt?Vt.split(`
262
- `).length:0;let Tn=0;e:for(let Qt=u;Qt>=0;Qt--){const Xi=Se[Qt].toolCalls??[];for(let _s=Xi.length-1;_s>=0;_s--){const _r=Xi[_s];if(_r.name==="read_file"&&_r.arguments.file_path===ft&&_r.result&&!_r.isError){Tn=_r.result.split(`
263
- `).length;break e}}}Ue.set(ft,{path:ft,lines:zr,added:Math.max(0,zr-Tn),removed:Math.max(0,Tn-zr)})}const at=[...Ue.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:"变更汇总"}),at.map(me=>{const ft=ro(me.path,b),Vt=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:me.path,children:me.path.replace(/\\/g,"/").split("/").pop()}),me.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",me.added]}),me.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",me.removed]}),me.added===0&&me.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[me.lines,"行"]})]});return or()&&ft?e.jsx("button",{type:"button",className:"chat-file-change-link",onClick:()=>Wn(ft),title:`预览 ${ft}`,"aria-label":`预览改动文件 ${me.path.replace(/\\/g,"/").split("/").pop()}`,children:Vt},me.path):e.jsx("span",{className:"chat-file-change-link chat-file-change-link--static",children:Vt},me.path)})]})})()]}),v.showCompletion&&e.jsxs("div",{className:"msg-completion-footer",children:[e.jsxs("span",{className:"msg-completion-status",children:[e.jsx(cs,{size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"已完成"}),T&&e.jsxs("span",{children:[" · 总耗时 ",T]})]}),e.jsxs("span",{className:"msg-completion-actions",children:[!or()&&v.showSpeak&&typeof((zs=window.agentApi)==null?void 0:zs.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>_o(s.id,s.content),title:Tr===s.id?"停止播报":"语音播报","aria-label":Tr===s.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${Tr===s.id?"is-active":""}`,children:Tr===s.id?e.jsx(_l,{size:12,fill:"currentColor","aria-hidden":"true"}):e.jsx(Ll,{size:13,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{Ds(s.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Ws,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]})]}),!v.showCompletion&&(v.showCopy||z)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[z&&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(Ls,{size:13,strokeWidth:1.9,"aria-hidden":"true"})}),v.showCopy&&e.jsx("button",{type:"button",onClick:()=>{Ds(s.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Ws,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]}),x&&(f.isQueued||f.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[f.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"})]}),"排队中"]}),Or&&e.jsxs("button",{onClick:()=>void Di(s.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:Z=>{Z.currentTarget.style.background="rgba(79,110,247,0.18)",Z.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:Z=>{Z.currentTarget.style.background="var(--accent-dim)",Z.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"})]}),"引导"]})]}),f.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"})}),"已引导"]})]})]})]})},s.id)}),et&&Tt&&e.jsx(lo,{progress:Tt,startedAt:Qn}),Ft&&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(Vd,{startedAt:Qn})}),(Yn||jr)&&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:Yn||jr}),Yn&&e.jsxs("button",{type:"button",onClick:()=>qt(s=>s+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(Ka,{size:14,"aria-hidden":"true"}),"重新加载"]})]}),e.jsx("div",{ref:Jr})]}),e.jsx(ld,{entries:(vs==null?void 0:vs.entries)??[],activeMessageId:Io,loadingMessageId:Co,onActivate:s=>{Wi(s)}}),js==="anchored"&&e.jsx("button",{type:"button",className:"chat-history-return-latest","data-has-updates":Ao,"data-loading-newer":Ro,"aria-busy":ks||void 0,"aria-label":"回到最新消息",title:"回到最新消息",disabled:ks,onClick:()=>{_i()},children:ks?e.jsx(dn,{className:"chat-history-return-latest__spinner",size:16,"aria-hidden":"true"}):e.jsx(dl,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[Zt&&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:hn==="incompatible"?"var(--danger)":"var(--text-muted)",fontSize:12},children:e.jsx("span",{style:{flex:1},children:hn==="incompatible"?Pt||((Vi=m==null?void 0:m.compatibility)==null?void 0:Vi.reason)||`Codex ${((Qi=m==null?void 0:m.compatibility)==null?void 0:Qi.producerVersion)??"未知版本"} 与当前 ${((Ki=m==null?void 0:m.compatibility)==null?void 0:Ki.readerVersion)??"运行时"} 不兼容`:`正在使用 Codex ${((Gi=m==null?void 0:m.compatibility)==null?void 0:Gi.readerVersion)??"当前版本"} 验证此会话`})}),((m==null?void 0:m.occupancy)==="owned-externally"||ut)&&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:Sa(m,qe)?"此会话仍由原客户端持有,可创建副本继续。":`此会话正在被 ${(m==null?void 0:m.sourceLabel)||"原客户端"} 使用,当前只读;原客户端释放后会自动恢复输入。`}),Sa(m,qe)&&e.jsx("button",{type:"button",onClick:()=>void Zo(),disabled:cn,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:cn?"wait":"pointer",opacity:cn?.65:1},children:cn?"正在创建…":"以副本继续"})]}),pe.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 s=new Set(pe.filter(u=>u.status==="completed").map(u=>u.title.toLowerCase()));return pe.map(u=>{const f=u.status==="pending",x=u.status==="in-progress",z=u.status==="completed",v=f&&(u.dependsOn??[]).some(T=>!s.has(T.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:z?.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:z?"rgba(52,211,153,0.15)":x?"var(--accent-dim)":v?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:z?"1.5px solid rgba(52,211,153,0.6)":x?"1.5px solid var(--accent)":v?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[z&&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"})}),x&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),v&&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"})}),f&&!v&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:z?"var(--text-muted)":v?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:z?"line-through":"none",flex:1},children:u.title}),v&&e.jsx("span",{title:`等待: ${(u.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:"等待前置"}),u.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:["@",u.agentName]})]},u.id)})})()})]}),Ie.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(),Ce([]),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:"全部删除"})]}),Ie.map(s=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:s.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:s.enabled?"#22c55e":"#9ca3af",boxShadow:s.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:s.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:s.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.label||s.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:s.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[s.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(s.id);const u=await window.agentApi.cronList();Ce(u)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:u=>{u.currentTarget.style.borderColor="#d97706",u.currentTarget.style.color="#d97706"},onMouseLeave:u=>{u.currentTarget.style.borderColor="var(--border-default)",u.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(s.id);const u=await window.agentApi.cronList();Ce(u)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:u=>{u.currentTarget.style.borderColor="#22c55e",u.currentTarget.style.color="#22c55e"},onMouseLeave:u=>{u.currentTarget.style.borderColor="var(--border-default)",u.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(s.id);const u=await window.agentApi.cronList();Ce(u)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:u=>{u.currentTarget.style.borderColor="var(--danger)",u.currentTarget.style.color="var(--danger)"},onMouseLeave:u=>{u.currentTarget.style.borderColor="var(--border-default)",u.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},s.id))]}),Ye.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:Ye.map((s,u)=>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:s.name}),e.jsx("button",{onClick:()=>Oo(u),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:"✕"})]},u))}),vn.length>0&&(()=>{const s=dt.find(f=>f.id===St),u=!he&&(!s||!Ts(s.modelId));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[u&&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"})]}),"当前模型(",(s==null?void 0:s.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:vn.map((f,x)=>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":`预览待发送图片 ${x+1}`,onClick:()=>kn({src:f,alt:`待发送图片 ${x+1}`}),children:e.jsx("img",{src:f,alt:`待发送图片 ${x+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":`删除待发送图片 ${x+1}`,onClick:()=>Vo(x),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:"✕"})]},x))})]})})(),(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(Ls,{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:()=>{Fi(We.active.id)},title:"停止当前目标","aria-label":"停止当前目标",children:e.jsx(us,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]}),We.queued.map((s,u)=>e.jsxs("div",{className:`goal-queue__row is-queued${Zn===s.id?" is-dragging":""}`,draggable:!0,onDragStart:()=>vr(s.id),onDragEnd:()=>vr(null),onDragOver:f=>f.preventDefault(),onDrop:()=>{tl(s.id)},children:[e.jsx(ea,{className:"goal-queue__grip",size:14,strokeWidth:1.8,"aria-hidden":"true"}),e.jsxs("span",{className:"goal-queue__state",children:["#",u+1]}),e.jsx("span",{className:"goal-queue__objective",title:s.objective,children:s.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Fi(s.id)},title:"移出目标队列","aria-label":"移出目标队列",children:e.jsx(us,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]},s.id))]}),(()=>{const s=j.filter(u=>u.isQueued);return s.length===0?null:e.jsx("div",{className:"queued-message-list",children:s.map(u=>{const f=u,x=yt===u.id,z=f.content.length>80?f.content.slice(0,80)+"…":f.content;return e.jsxs("div",{className:`queued-message-row${tt===u.id?" is-dragging":""}`,"data-queued-message-id":u.id,onDragOver:v=>{!tt||tt===u.id||(v.preventDefault(),v.dataTransfer.dropEffect="move")},onDrop:v=>{v.preventDefault(),tt&&Ns(tt,u.id),nt(null)},children:[e.jsx("button",{type:"button",className:"queued-message-grip",draggable:!x,"aria-label":"拖动调整排队顺序",title:"拖动调整顺序",onDragStart:v=>{nt(u.id),v.dataTransfer.effectAllowed="move",v.dataTransfer.setData("text/plain",u.id)},onDragEnd:()=>nt(null),onKeyDown:v=>{(v.key==="ArrowUp"||v.key==="ArrowDown")&&(v.preventDefault(),el(u.id,v.key==="ArrowUp"?-1:1))},onPointerDown:v=>{v.pointerType==="mouse"||x||(_e.current={id:u.id,pointerId:v.pointerId},v.currentTarget.setPointerCapture(v.pointerId),nt(u.id))},onPointerMove:v=>{var B;const T=_e.current;if(!T||T.pointerId!==v.pointerId)return;v.preventDefault();const $=(B=document.elementFromPoint(v.clientX,v.clientY))==null?void 0:B.closest("[data-queued-message-id]"),D=$==null?void 0:$.dataset.queuedMessageId;D&&D!==T.id&&Ns(T.id,D)},onPointerUp:v=>{var T;((T=_e.current)==null?void 0:T.pointerId)===v.pointerId&&(_e.current=null,nt(null))},onPointerCancel:()=>{_e.current=null,nt(null)},children:e.jsx(ea,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsxs("div",{className:"queued-message-content",children:[f.agentName&&e.jsxs("span",{className:"queued-message-agent",children:["@",f.agentName]}),x?e.jsx("input",{autoFocus:!0,className:"queued-message-edit-input",value:br,onChange:v=>yn(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.nativeEvent.isComposing?(v.preventDefault(),Bi(u.id)):v.key==="Escape"&&(v.preventDefault(),Es())},"aria-label":"编辑排队消息内容"}):e.jsx("span",{className:"queued-message-text",title:f.content,children:z})]}),e.jsxs("div",{className:"queued-message-actions",children:[Or&&e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--accent",onClick:()=>void Di(u.id),title:"引导到当前对话","aria-label":"引导排队消息到当前对话",children:e.jsx(gl,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>void Jo(u.id),title:Jt===u.id?"已复制":"复制","aria-label":"复制排队消息",children:Jt===u.id?e.jsx(cs,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Ws,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>x?Bi(u.id):Yo(u.id),disabled:x&&!br.trim(),title:x?"保存":"编辑","aria-label":x?"保存排队消息":"编辑排队消息",children:x?e.jsx(cs,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Qa,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--danger",onClick:()=>Xo(u.id),title:"删除","aria-label":"删除排队消息",children:e.jsx(us,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]})]},u.id)})})})(),e.jsx("div",{ref:Is,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:ki,type:"file",multiple:!0,style:{display:"none"},onChange:$o}),Ar.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:Ar.map(s=>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"})]}),"@",s.name,e.jsx("button",{onClick:()=>Po(s.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},s.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:Cr,rows:3,value:Ne,onChange:s=>Mi(s.target.value),onBlur:()=>setTimeout(()=>{Sn(null),Cn(null)},120),onKeyDown:Fo,placeholder:Zt?hn==="incompatible"?"Codex 版本不兼容":"正在验证会话兼容性":Ur?"原客户端使用中,当前只读":qn?wt?"输入要持续推进的目标":Ze?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!bt}),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":Gr,onClick:()=>yr(s=>!s),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"})})}),Gr&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var s;yr(!1),(s=ki.current)==null||s.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{yr(!1),zo()},children:"语音输入"})]})]}),e.jsx("button",{type:"button",className:`web-native-runtime-status goal-mode-toggle${wt?" is-active":""}`,"aria-pressed":wt,"aria-label":wt?"关闭目标模式":"开启目标模式",title:wt?"目标模式已开启":"目标模式",onClick:()=>Zr(s=>!s),children:e.jsx(Ls,{size:18,strokeWidth:1.9,"aria-hidden":"true"})}),e.jsxs("div",{className:"web-native-permission-wrap",ref:He,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${Ot}`,"aria-label":`会话权限:${(Zi=ps.find(s=>s.value===Ot))==null?void 0:Zi.label}`,"aria-haspopup":"menu","aria-expanded":$t,title:`会话权限:${(Yi=ps.find(s=>s.value===Ot))==null?void 0:Yi.label}`,disabled:!H||wr,onClick:()=>Gn(s=>!s),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"})]})}),$t&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:ps.map(s=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ot===s.value,className:Ot===s.value?"is-active":"",onClick:()=>{Ko(s.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:Ot===s.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:s.label}),e.jsx("small",{children:s.description})]})]},s.value))})]}),he&&(m==null?void 0:m.controller)==="web"&&typeof((Ji=window.agentApi)==null?void 0:Ji.handoffSession)=="function"&&e.jsx("button",{type:"button",className:"web-native-runtime-status",onClick:()=>{Go()},title:"交接到 Desktop",children:"交接到 Desktop"}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Hd,{usage:H?Ke[H]:void 0,contextWindowK:Lt,compact:!0})}),e.jsx("label",{className:`web-native-model-control${he?" web-native-model-control--native":""}`,title:"切换模型",children:he&&fs(ue)?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"web-native-model-agent",title:`${Ra[ue]} 会话`,children:[e.jsx(pi,{agentType:ue,size:14}),e.jsx("span",{className:"web-native-model-agent-name",children:Ra[ue]})]}),mr&&e.jsxs("select",{"aria-label":"当前模型",title:"切换模型",value:Un,onChange:s=>{gr({model:s.target.value?ql(s.target.value):void 0})},children:[e.jsx("option",{value:"",children:"默认模型"}),On.map(s=>e.jsx("option",{value:s.key,children:s.label},s.key)),hr.length>0&&e.jsx("optgroup",{label:"设置里的模型",children:hr.map(s=>e.jsx("option",{value:s.key,children:s.label},s.key))})]})]}):e.jsx("select",{"aria-label":"当前模型",value:St,disabled:dt.length===0,onChange:s=>{gt(s.target.value)},children:dt.length===0?e.jsx("option",{value:"",children:"未配置模型"}):dt.map(s=>e.jsx("option",{value:s.id,children:s.name||s.modelId},s.id))})}),bn?e.jsx("button",{type:"button",onClick:Pi,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"})})}):he&&xr.length>0?e.jsxs("div",{className:"web-native-effort-wrap",ref:$n,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":ct,"aria-label":`推理强度:${Qe?Ks[Qe]:"默认"}`,title:`推理强度:${Qe?Ks[Qe]:"默认"}(点击切换)`,onClick:()=>fn(s=>!s),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"})]})}),ct&&e.jsxs("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:[e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":!Qe,className:Qe?void 0:"is-active",onClick:()=>{gr({reasoningEffort:void 0}),fn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Qe?"":"✓"}),"默认"]}),xr.map(s=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Qe===s,className:Qe===s?"is-active":void 0,onClick:()=>{gr({reasoningEffort:s}),fn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Qe===s?"✓":""}),Ks[s]]},s))]})]}):he?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:Ut,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Xt,"aria-label":`推理强度:${Aa[ht]}`,title:`推理强度:${Aa[ht]}(点击切换)`,onClick:()=>vt(s=>!s),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"})]})}),Xt&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:bo.map(s=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":ht===s.value,className:ht===s.value?"is-active":void 0,onClick:()=>{ye("reasoningEffort",s.value),fr(),vt(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:ht===s.value?"✓":""}),s.label]},s.value))})]}),e.jsx("button",{type:"button",onClick:$i,disabled:!bt||Yr>0||!Ne.trim(),className:"web-native-send-button","aria-label":Ze?"排队发送":"发送",title:Ze?"排队发送":"发送",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 发送",wt?"目标":Ze?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",Ai?" · 🎤 正在聆听…":""]})]}),e.jsx(Jd,{image:ys,onClose:()=>kn(null)}),rn&&Rr!==null&&Ti.length>0&&Kt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-rn.top+8,left:rn.left,width:rn.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:"智能体"}),Ti.map(s=>e.jsxs("button",{onMouseDown:u=>{u.preventDefault(),Lo(s)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:u=>{u.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:u=>{u.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",s.name]}),s.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:s.description})]},s.id))]}),document.body),rn&&In!==null&&Rs.length>0&&Kt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-rn.top+8,left:rn.left,width:rn.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:["技能 (",Rs.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:Rs.map(s=>e.jsxs("button",{onMouseDown:u=>{u.preventDefault(),Do(s)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:u=>{u.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:u=>{u.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",s.name]}),s.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.description})]},s.name))})]}),document.body)]})}function Gs(t,r,n="auto"){const i=t.getBoundingClientRect(),a=r.getBoundingClientRect(),o=t.scrollTop+a.top-i.top-Math.max(0,(t.clientHeight-a.height)/2);t.scrollTo({top:Math.max(0,o),behavior:n})}function Zs({status:t,isRunning:r,needsInput:n}){return t==="failed"||t==="error"?"error":r?n?"needs-input":"running":"completed"}const Ys={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function yo(t,r){return t.map((n,i)=>({session:n,index:i})).sort((n,i)=>r(n.session,i.session)||n.index-i.index).map(({session:n})=>n)}function wi(t){return yo(t,(r,n)=>n.created.localeCompare(r.created))}function Mc(t,r){return yo(wi(t),(n,i)=>Number(r(i))-Number(r(n)))}const Ma={projectId:null,sessionId:null};function di(t){return typeof t=="string"&&t.trim()?t.trim():null}function Ea(t){return{projectId:di(t),sessionId:null}}function Js(t,r){return{projectId:di(t),sessionId:di(r)}}function Ec(t){return t.agentType==="customer-agent"?`确定永久删除会话“${t.title}”吗?此操作不可恢复。`:t.agentType==="codex"?`确定归档 Codex 会话“${t.title}”并从 AgentRoam 中移除吗?可在 Codex 的已归档会话中恢复。`:`确定从 AgentRoam 中移除会话“${t.title}”吗?原生客户端中的历史记录会保留。`}function Nc(t,r){const n=new Set(r);return{...t,selectedSessionId:t.selectedSessionId&&n.has(t.selectedSessionId)?null:t.selectedSessionId,sessions:Object.fromEntries(Object.entries(t.sessions).map(([i,a])=>[i,{...a,data:a.data.filter(o=>!n.has(o.id))}]))}}function zc(t,r){const n=new Set(r);let i=!1;const a=Object.fromEntries(Object.entries(t).map(([o,l])=>{const p=l.filter(g=>!n.has(g.id));return p.length!==l.length&&(i=!0),[o,p.length===l.length?l:p]}));return i?a:t}function _c(t,r,n,i){const a=[i,...(r[i]??[]).map(p=>p.id)],o=new Set(a),l=Object.fromEntries(Object.entries(r).flatMap(([p,g])=>{if(o.has(p))return[];const h=g.filter(m=>!o.has(m.id));return[[p,h.length===g.length?g:h]]}));return{sessionsByProject:zc(t,a),childSessionsByParent:l,otherLocalSessions:n.filter(p=>!o.has(p.id)),removedIds:a}}const Wc=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Na={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function za(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function Lc(){const{maxIterations:t,contextWindow:r,isConfigured:n,profiles:i,activeProfileId:a,setField:o,loadFromSystem:l,saveToSystem:p,addProfile:g,updateProfile:h,deleteProfile:m,switchActiveProfile:b}=ms(),[k,I]=d.useState(null),[M,O]=d.useState("success"),[_,F]=d.useState(null),[y,j]=d.useState(!1),[q,K]=d.useState(za());d.useEffect(()=>{l()},[]);const A=()=>{j(!0),F(null),K(za())},C=G=>{j(!1),F(G.id),K({name:G.name,provider:G.provider,modelId:G.modelId,apiKey:G.apiKey==="managed"?"":G.apiKey,baseUrl:G.baseUrl})},W=()=>{F(null),j(!1)},E=async()=>{if(!q.name.trim()||!q.apiKey.trim()||!q.modelId.trim()){I("名称、API Key 和模型 ID 为必填项"),O("error");return}y?g(q):_&&h(_,q),F(null),j(!1),I(null),setTimeout(()=>p(),0)},L=async G=>{m(G),setTimeout(()=>p(),0)},ae=async G=>{await b(G),I("已切换模型"),O("success"),setTimeout(()=>I(null),1500)},fe=async()=>{I(null);try{await p(),I("设置保存成功"),O("success")}catch(G){I(G instanceof Error?G.message:"保存失败"),O("error")}},we=y||_!==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:Dc,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[i.length===0&&!we&&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:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),i.map(G=>{const Ke=G.id===a,kt=G.id===_;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${Ke?"var(--accent)":"var(--border-default)"}`,background:Ke?"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:Ke?"var(--accent)":"var(--bg-deep)",color:Ke?"#fff":"var(--text-muted)",flexShrink:0},children:G.provider}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G.name||G.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[G.modelId," ",G.baseUrl?`· ${G.baseUrl}`:""]})]}),Ke&&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:[!Ke&&e.jsx("button",{onClick:()=>ae(G.id),style:Xs,children:"切换"}),e.jsx("button",{onClick:()=>kt?W():C(G),style:Xs,children:kt?"收起":"编辑"}),e.jsx("button",{onClick:()=>L(G.id),style:{...Xs,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),kt&&e.jsx(_a,{draft:q,setDraft:K,onSave:E,onCancel:W})]},G.id)}),y&&e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:"1px solid var(--accent)",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"10px 14px 0",fontSize:13,fontWeight:600,color:"var(--accent)"},children:"新建提供商"}),e.jsx(_a,{draft:q,setDraft:K,onSave:E,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(Nn,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:G=>o("maxIterations",parseInt(G.target.value)||10),min:1,max:50,style:zn})}),e.jsx(Nn,{label:"上下文窗口(K tokens)",children:e.jsx("input",{type:"number",value:r??100,onChange:G=>o("contextWindow",parseInt(G.target.value)||100),min:8,max:2e3,style:zn})})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:fe,style:vo,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:n?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:n?"var(--success)":"var(--text-muted)",border:`1px solid ${n?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:n?"● 已连接":"○ 未配置"})]}),k&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:M==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:M==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:M==="success"?"var(--success)":"var(--danger)",fontSize:13},children:k})]})}function _a({draft:t,setDraft:r,onSave:n,onCancel:i}){const a=(o,l)=>r(p=>{const g={...p,[o]:l};return o==="provider"&&!p.modelId&&(g.modelId=Na[l]??""),g});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(Nn,{label:"名称",children:e.jsx("input",{value:t.name,onChange:o=>a("name",o.target.value),placeholder:"我的 Claude",style:zn})}),e.jsx(Nn,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:o=>{a("provider",o.target.value),a("modelId",Na[o.target.value]??"")},style:zn,children:Wc.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))})})]}),e.jsx(Nn,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:o=>a("modelId",o.target.value),placeholder:"claude-sonnet-4-6",style:zn})}),e.jsx(Nn,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:o=>a("apiKey",o.target.value),placeholder:"sk-...",style:zn})}),e.jsx(Nn,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:o=>a("baseUrl",o.target.value),placeholder:"https://api.anthropic.com",style:zn})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:n,style:vo,children:"保存"}),e.jsx("button",{onClick:i,style:Pc,children:"取消"})]})]})}function Nn({label:t,children:r}){return e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:"var(--text-secondary)",marginBottom:6,fontWeight:500,textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),r]})}const zn={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"},vo={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)"},Pc={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)"},Dc={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)"},Xs={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)"},ei={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function Bc(){const[t,r]=d.useState([]),[n,i]=d.useState("stdio"),[a,o]=d.useState(ei),[l,p]=d.useState(!1),[g,h]=d.useState({id:!1,command:!1,url:!1}),[m,b]=d.useState({}),[k,I]=d.useState({}),[M,O]=d.useState(new Set),[_,F]=d.useState(null),[y,j]=d.useState(""),[q,K]=d.useState(!1),A=async S=>{var le;if(!((le=window.agentApi)!=null&&le.mcpProbe))return;O(pe=>new Set([...pe,S.id])),I(pe=>{const be={...pe};return delete be[S.id],be});const U=new Promise((pe,be)=>setTimeout(()=>be(new Error("连接超时(15s)")),15e3));try{const pe=await Promise.race([window.agentApi.mcpProbe(S),U]);b(be=>({...be,[S.id]:pe}))}catch(pe){const be=pe instanceof Error?pe.message:String(pe);console.warn(`[MCP] probe failed for ${S.id}:`,be),b(Ie=>{const Ce={...Ie};return delete Ce[S.id],Ce}),I(Ie=>({...Ie,[S.id]:be})),(S.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(be))&&(j(""),F({server:S}))}finally{O(pe=>{const be=new Set(pe);return be.delete(S.id),be})}};d.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(S=>{r(S),S.filter(U=>U.enabled!==!1).forEach(U=>A(U))}).catch(console.error)},[]);const[C,W]=d.useState(""),[E,L]=d.useState(""),[ae,fe]=d.useState(!1),we=async()=>{L("");let S;try{S=JSON.parse(C.trim());const U=S.mcpServers??S,le=Object.entries(U);if(le.length===0){L("未找到任何服务器");return}fe(!0);const pe=[];for(const[Ie,Ce]of le){const Se=Ce,Wt=Se.name||Ie,St=Se.disabled!==!0;let gt;if(Se.url||Se.type==="streamableHttp"||Se.type==="sse"){const Dn=Se.type==="sse"?"sse":"streamableHttp";gt={id:Ie,name:Wt,transport:Dn,url:Se.url,headers:Se.headers??{},env:Se.env??{},enabled:St}}else gt={id:Ie,name:Wt,transport:"stdio",command:Se.command,args:Se.args??[],env:Se.env??{},enabled:St};await window.agentApi.mcpSave(gt),pe.push(gt)}const be=await window.agentApi.mcpList();r(be),W(""),pe.filter(Ie=>Ie.enabled!==!1).forEach(Ie=>A(Ie))}catch(U){L(U instanceof Error?U.message:"JSON 解析失败")}finally{fe(!1)}},G=()=>a.id.trim()!==""&&a.command.trim()!=="",Ke=()=>a.id.trim()!==""&&a.url.trim()!=="",kt=S=>{const U={};for(const le of S.split(`
264
- `)){const pe=le.indexOf(":");if(pe<1)continue;const be=le.slice(0,pe).trim(),Ie=le.slice(pe+1).trim();be&&(U[be]=Ie)}return U},Ln=async()=>{if(h({id:!0,command:!0,url:!0}),!(n==="stdio"&&!G())&&!((n==="sse"||n==="streamableHttp")&&!Ke())){p(!0);try{const S=n==="sse"||n==="streamableHttp"?kt(a.headersRaw):{},U=n==="stdio"?{id:a.id,name:a.name||a.id,transport:"stdio",command:a.command,args:a.args.split(" ").filter(Boolean),enabled:!0}:{id:a.id,name:a.name||a.id,transport:n,url:a.url,headers:S,enabled:!0};await window.agentApi.mcpSave(U);const le=await window.agentApi.mcpList();r(le),o(ei),h({id:!1,command:!1,url:!1}),A(U)}catch(S){console.error("Failed to save MCP server",S)}finally{p(!1)}}},Le=async S=>{await window.agentApi.mcpDelete(S),r(t.filter(U=>U.id!==S))},Pn=async(S,U)=>{await window.agentApi.mcpSetEnabled(S,U),r(t.map(le=>le.id===S?{...le,enabled:U}:le))},zt=async()=>{if(!(!_||!y.trim())){K(!0);try{const S=_.server.transport==="streamableHttp"?{..._.server,headers:{..._.server.headers??{},Authorization:`Bearer ${y.trim()}`}}:{..._.server,env:{..._.server.env??{},Authorization:`Bearer ${y.trim()}`}};await window.agentApi.mcpSave(S);const U=await window.agentApi.mcpList();r(U),F(null),j("");const le=U.find(pe=>pe.id===S.id)??S;A(le)}finally{K(!1)}}},_t=S=>S==="stdio"?"本地":S==="streamableHttp"?"HTTP":"SSE",pr=S=>S==="stdio"?"#68d391":S==="streamableHttp"?"#f6ad55":"#63b3ed",lt=S=>S==="stdio"?"rgba(154,230,180,0.15)":S==="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(S=>e.jsx("button",{onClick:()=>{i(S),h({id:!1,command:!1,url:!1}),o(U=>({...ei,id:U.id,name:U.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:n===S?"var(--accent)":"transparent",color:n===S?"var(--text-inverse)":"var(--text-muted)"},children:S==="stdio"?"本地 stdio":S==="sse"?"远程 SSE":"HTTP"},S))})]}),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:a.id,onChange:S=>o(U=>({...U,id:S.target.value})),onBlur:()=>h(S=>({...S,id:!0})),placeholder:"服务器 ID *",style:{...an,...g.id&&!a.id?ti:{}}}),g.id&&!a.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:a.name,onChange:S=>o(U=>({...U,name:S.target.value})),placeholder:"显示名称",style:{...an,flex:1}})]}),n==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:a.command,onChange:S=>o(U=>({...U,command:S.target.value})),onBlur:()=>h(S=>({...S,command:!0})),placeholder:"命令(如 npx)*",style:{...an,...g.command&&!a.command?ti:{}}}),g.command&&!a.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:a.args,onChange:S=>o(U=>({...U,args:S.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...an,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:a.url,onChange:S=>o(U=>({...U,url:S.target.value})),onBlur:()=>h(S=>({...S,url:!0})),placeholder:n==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...an,...g.url&&!a.url?ti:{}}}),g.url&&!a.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:a.headersRaw,onChange:S=>o(U=>({...U,headersRaw:S.target.value})),placeholder:`access_token: abc123
265
- Authorization: Bearer sk-...`,rows:3,style:{...an,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:Ln,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:S=>{W(S.target.value),L("")},placeholder:`{
266
- "my-server": {
267
- "command": "npx",
268
- "args": ["-y", "some-mcp"]
269
- }
270
- }`,rows:5,style:{...an,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),E&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:E}),e.jsx("button",{onClick:we,disabled:!C.trim()||ae,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:C.trim()&&!ae?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:C.trim()&&!ae?1:.5},children:ae?"导入中…":"导入"})]}),t.filter(S=>S.transport===n).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",n==="stdio"?"本地 stdio":n==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(S=>S.transport===n).map(S=>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:S.name||S.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:lt(S.transport),color:pr(S.transport),fontWeight:600},children:_t(S.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[S.transport==="stdio"?`${S.command} ${(S.args??[]).join(" ")}`:S.url,S.transport!=="stdio"&&S.headers&&Object.keys(S.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(S.headers).length," 个请求头"]})]}),M.has(S.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"}}),"探测工具中…"]}):k[S.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:k[S.id]}),S.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(k[S.id])?e.jsx("button",{onClick:()=>{j(""),F({server:S})},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(S),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:"重试"})]}):m[S.id]&&m[S.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:m[S.id].map(U=>e.jsx("span",{title:U.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:U.name},U.name))}):m[S.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:S.enabled!==!1,onChange:U=>Pn(S.id,U.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Le(S.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:U=>{U.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:U=>{U.currentTarget.style.background="transparent"},children:"移除"})]})]},S.id))}),_&&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:S=>{S.target===S.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:_.server.name||_.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:y,onChange:S=>j(S.target.value),onKeyDown:S=>{S.key==="Enter"&&zt(),S.key==="Escape"&&F(null)},placeholder:"sk-… 或 Bearer token",style:{...an,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:zt,disabled:!y.trim()||q,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:y.trim()&&!q?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:y.trim()&&!q?1:.5},children:q?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const an={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)"},ti={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function Fc(){const[t,r]=d.useState([]),[n,i]=d.useState(""),[a,o]=d.useState(null),[l,p]=d.useState(!1),[g,h]=d.useState(""),[m,b]=d.useState(""),[k,I]=d.useState("user"),[M,O]=d.useState(""),[_,F]=d.useState(null),[y,j]=d.useState("success"),q=async()=>{if(window.agentApi){const W=await window.agentApi.listMemories();r(W)}};d.useEffect(()=>{q()},[]);const K=async()=>{if(!n.trim()){q();return}if(window.agentApi){const W=await window.agentApi.searchMemories(n);r(W.map(E=>E.entry))}},A=async()=>{if(!(!g.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:g.trim(),description:m,type:k,content:M,created:(a==null?void 0:a.created)??new Date().toISOString(),updated:new Date().toISOString()}),p(!1),o(null),h(""),b(""),O(""),I("user"),F("保存成功"),j("success"),await q()}catch(W){F(W instanceof Error?W.message:"保存失败"),j("error")}},C=W=>{o(W),h(W.name),b(W.description),I(W.type),O(W.content),p(!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:()=>{p(!0),o(null),h(""),b(""),O(""),I("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:n,onChange:W=>i(W.target.value),onKeyDown:W=>W.key==="Enter"&&K(),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:K,style:Wa,children:"搜索"})]}),_&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:y==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:y==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:y==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:_}),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:g,onChange:W=>h(W.target.value),placeholder:"名称",style:{...ls,marginBottom:10},disabled:!!a}),e.jsx("input",{value:m,onChange:W=>b(W.target.value),placeholder:"描述",style:{...ls,marginBottom:10}}),e.jsxs("select",{value:k,onChange:W=>I(W.target.value),style:{...ls,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:M,onChange:W=>O(W.target.value),placeholder:"内容",rows:5,style:{...ls,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:()=>p(!1),style:Wa,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:La,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(W.name),F("删除成功"),j("success"),await q()}catch(E){F(E instanceof Error?E.message:"删除失败"),j("error")}},style:{...La,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 ls={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"},Wa={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)"},La={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},$c=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function Oc(){const[t,r]=d.useState([]),[n,i]=d.useState(null),[a,o]=d.useState(!1),[l,p]=d.useState(null),[g,h]=d.useState("success"),[m,b]=d.useState(""),k=(C,W="success")=>{p(C),h(W),setTimeout(()=>p(null),3e3)},I=async()=>{if(!window.agentApi)return;const C=await window.agentApi.listSkills();r(C)};d.useEffect(()=>{I()},[]);const M=C=>{i({...C}),b((C.triggers??[]).join(", ")),o(!1)},O=()=>{i($c()),b(""),o(!0)},_=()=>{i(null),o(!1)},F=async()=>{if(!n||!window.agentApi)return;if(!n.name.trim()){k("名称不能为空","error");return}const C=m.split(",").map(W=>W.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:n.name.trim(),description:n.description,triggers:C,prompt:n.prompt,filePath:n.filePath??""}),k(a?"技能已创建":"技能已保存"),i(null),await I()}catch(W){k(W instanceof Error?W.message:"保存失败","error")}},y=async C=>{if(window.agentApi)try{await window.agentApi.deleteSkill(C),k("已删除"),(n==null?void 0:n.name)===C&&i(null),await I()}catch(W){k(W instanceof Error?W.message:"删除失败","error")}},j=async C=>{if(!window.agentApi)return;const W=!C.enabled;await window.agentApi.setSkillEnabled(C.name,W),await I()},q=async()=>{if(window.agentApi)try{const C=await window.agentApi.importSkill();if(!C)return;k(`已导入技能「${C.name}」,本次会话立即生效`),await I()}catch(C){k(C instanceof Error?C.message:"导入失败","error")}},K={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:q,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer"},children:"↓ 导入技能"}),e.jsx("button",{onClick:O,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"+ 新建技能"})]})]}),l&&e.jsx("div",{style:{marginBottom:16,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:g==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:g==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:g==="success"?"var(--success)":"var(--danger)",fontSize:13},children:l}),n&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:a?"新建技能":`编辑:${n.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:A,children:"名称"}),e.jsx("input",{style:K,value:n.name,disabled:!a,onChange:C=>i({...n,name:C.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"描述"}),e.jsx("input",{style:K,value:n.description,onChange:C=>i({...n,description:C.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"触发词(逗号分隔)"}),e.jsx("input",{style:K,value:m,onChange:C=>b(C.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:A,children:"提示词"}),e.jsx("textarea",{style:{...K,minHeight:120,resize:"vertical"},value:n.prompt,onChange:C=>i({...n,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:_,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!n&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(C=>{var 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:()=>j(C),title:C.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:C.enabled===!1?"var(--border-default)":"var(--accent)",cursor:"pointer",position:"relative",transition:"background 0.2s"},children:e.jsx("span",{style:{position:"absolute",top:2,left:C.enabled===!1?2:14,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:C.name}),((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:()=>M(C),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:12,cursor:"pointer"},children:"编辑"}),e.jsx("button",{onClick:()=>y(C.name),style:{padding:"5px 12px",borderRadius:"var(--radius-sm)",border:"1px solid rgba(244,63,94,0.3)",background:"transparent",color:"var(--danger)",fontSize:12,cursor:"pointer"},children:"删除"})]})]},C.name)})]})]})}const ds=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function wo(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function Uc(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:wo(),maxIterations:0,isDefault:!1}}const ci={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"},Dr={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},ln={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"},on={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function qc({ph:t,onChange:r,onDelete:n}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:ln,placeholder:"变量名 (e.g. project)",value:t.key,onChange:i=>r({...t,key:i.target.value})}),e.jsx("input",{style:ln,placeholder:"说明",value:t.description,onChange:i=>r({...t,description:i.target.value})}),e.jsx("input",{style:ln,placeholder:"默认值",value:t.defaultValue,onChange:i=>r({...t,defaultValue:i.target.value})}),e.jsx("button",{onClick:n,style:{...Dr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function Pa({initial:t,activeAgentId:r,onSave:n,onCancel:i}){const{profiles:a}=ms(),[o,l]=d.useState([]),[p,g]=d.useState([]),[h,m]=d.useState({...Uc(),...t,capabilities:{...wo(),...t.capabilities??{}}}),[b,k]=d.useState(null),[I,M]=d.useState(!1);d.useEffect(()=>{var E,L;window.agentApi&&(window.agentApi.listSkills().then(ae=>{l(ae.filter(fe=>fe.name))}),(L=(E=window.agentApi).listMCPServers)==null||L.call(E).then(ae=>{g(ae??[])}).catch(()=>{}))},[]);const O=E=>m(L=>({...L,capabilities:{...L.capabilities,...E}})),_=E=>{const L=h.capabilities.enabledTools;if(L.length===0){const ae=ds.map(fe=>fe.name).filter(fe=>fe!==E);O({enabledTools:ae})}else if(L.includes(E)){const ae=L.filter(fe=>fe!==E);O({enabledTools:ae})}else{const ae=[...L,E];ae.length===ds.length?O({enabledTools:[]}):O({enabledTools:ae})}},F=E=>{const L=h.capabilities.enabledSkills;O({enabledSkills:L.includes(E)?L.filter(ae=>ae!==E):[...L,E]})},y=E=>{const L=h.capabilities.enabledMCPServers;O({enabledMCPServers:L.includes(E)?L.filter(ae=>ae!==E):[...L,E]})},j=()=>m(E=>({...E,contextPlaceholders:[...E.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),q=(E,L)=>m(ae=>{const fe=[...ae.contextPlaceholders];return fe[E]=L,{...ae,contextPlaceholders:fe}}),K=E=>m(L=>({...L,contextPlaceholders:L.contextPlaceholders.filter((ae,fe)=>fe!==E)})),A=async()=>{if(!h.name.trim()){k("名称为必填项");return}M(!0);try{await n(h)}catch(E){k(E instanceof Error?E.message:"保存失败")}finally{M(!1)}},C=E=>h.capabilities.enabledTools.length===0||h.capabilities.enabledTools.includes(E),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:[b&&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:b}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:on,children:"名称 *"}),e.jsx("input",{style:ln,value:h.name,onChange:E=>m(L=>({...L,name:E.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:on,children:"描述"}),e.jsx("input",{style:ln,value:h.description,onChange:E=>m(L=>({...L,description:E.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:{...on,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:h.systemPrompt,onChange:E=>m(L=>({...L,systemPrompt:E.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
271
-
272
- 当前项目:{{project_name}}`,rows:6,style:{...ln,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:W,children:"上下文占位符"}),h.contextPlaceholders.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6},children:["变量名","说明","默认值",""].map(E=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:E},E))}),h.contextPlaceholders.map((E,L)=>e.jsx(qc,{ph:E,onChange:ae=>q(L,ae),onDelete:()=>K(L)},L))]}),e.jsx("button",{onClick:j,style:{...Dr,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:on,children:"模型"}),e.jsxs("select",{value:h.capabilities.profileId,onChange:E=>O({profileId:E.target.value}),style:{...ln,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),a.map(E=>e.jsxs("option",{value:E.id,children:[E.name||E.modelId," (",E.provider,")"]},E.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:on,children:["内置工具 ",h.capabilities.enabledTools.length===0?"(全部启用)":`(${h.capabilities.enabledTools.length}/${ds.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:ds.map(E=>{const L=C(E.name);return e.jsx("button",{onClick:()=>_(E.name),style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:E.label},E.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),o.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:on,children:["技能 ",h.capabilities.enabledSkills.length===0?"(全部)":`(${h.capabilities.enabledSkills.length}/${o.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:o.map(E=>{const L=h.capabilities.enabledSkills.length===0||h.capabilities.enabledSkills.includes(E.name);return e.jsx("button",{onClick:()=>F(E.name),title:E.description,style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:E.name},E.name)})})]}),p.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:on,children:["MCP 服务器 ",h.capabilities.enabledMCPServers.length===0?"(全部)":`(${h.capabilities.enabledMCPServers.length}/${p.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:p.map(E=>{const L=h.capabilities.enabledMCPServers.length===0||h.capabilities.enabledMCPServers.includes(E.id);return e.jsx("button",{onClick:()=>y(E.id),style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:E.name},E.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:on,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:ln,value:h.maxIterations,min:0,max:100,onChange:E=>m(L=>({...L,maxIterations:Number(E.target.value)}))})]}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",paddingBottom:2},children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:"var(--text-secondary)"},children:[e.jsx("input",{type:"checkbox",checked:h.isDefault,onChange:E=>m(L=>({...L,isDefault:E.target.checked})),style:{width:14,height:14,accentColor:"var(--accent)",cursor:"pointer"}}),"新会话默认使用此智能体"]})})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:A,disabled:I,style:{...ci,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:I?.6:1},children:I?"保存中…":"保存"}),e.jsx("button",{onClick:i,style:ci,children:"取消"})]})]})}function Hc(){const[t,r]=d.useState([]),[n,i]=d.useState([]),[a,o]=d.useState(null),[l,p]=d.useState(!1),[g,h]=d.useState(null),[m,b]=d.useState("success"),k=(y,j="success")=>{h(y),b(j),setTimeout(()=>h(null),2e3)},I=async()=>{if(!window.agentApi)return;const y=await window.agentApi.listAgentDefs();r(y);const j=await window.agentApi.getSettings();i(j.activeAgentIds??[])};d.useEffect(()=>{I()},[]);const M=async y=>{await window.agentApi.createAgentDef(y),p(!1),k("智能体已创建"),await I()},O=async(y,j)=>{await window.agentApi.updateAgentDef(y,j),o(null),k("保存成功"),await I()},_=async y=>{await window.agentApi.deleteAgentDef(y),a===y&&o(null),k("已删除"),await I()},F=async y=>{const q=(await window.agentApi.setActiveAgentDef(y)).activeAgentIds??[];i(q),k(q.includes(y)?"已激活":"已取消激活")};return e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:28,color:"var(--text-primary)",fontWeight:400,marginBottom:8,letterSpacing:"-0.02em"},children:"智能体"}),e.jsx("p",{style:{color:"var(--text-muted)",fontSize:14,marginBottom:28},children:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),g&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,border:m==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:m==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:m==="success"?"var(--success)":"var(--danger)",fontSize:13},children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{p(!0),o(null)},style:{...ci,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(Pa,{initial:{},activeAgentId:n[0]??"",onSave:M,onCancel:()=>p(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!l&&e.jsx("div",{style:{padding:"28px 20px",borderRadius:"var(--radius-sm)",border:"1px dashed var(--border-subtle)",textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"暂无智能体配置,点击「新建智能体」开始创建"}),t.map(y=>{const j=n.includes(y.id),q=y.id===a;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${j?"var(--accent)":"var(--border-default)"}`,background:j?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s, background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 16px"},children:[e.jsx("div",{style:{width:34,height:34,borderRadius:8,flexShrink:0,background:j?"var(--accent)":"var(--bg-deep)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:j?"#fff":"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"4"}),e.jsx("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:y.name}),j&&e.jsx("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",background:"rgba(79,110,247,0.12)",padding:"1px 6px",borderRadius:4,letterSpacing:"0.05em"},children:"激活"}),y.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),y.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[y.capabilities.profileId&&e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"rgba(79,110,247,0.08)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.15)"},children:"自定义模型"}),y.capabilities.enabledTools.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.capabilities.enabledTools.length," 工具"]}),y.capabilities.enabledSkills.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.capabilities.enabledSkills.length," 技能"]}),y.contextPlaceholders.length>0&&e.jsxs("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:10,background:"var(--bg-deep)",color:"var(--text-muted)",border:"1px solid var(--border-subtle)"},children:[y.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>F(y.id),style:{...Dr,color:j?"var(--accent)":"var(--text-muted)",borderColor:j?"var(--accent)":"var(--border-default)",background:j?"var(--accent-dim)":"transparent"},children:j?"取消激活":"激活"}),e.jsx("button",{onClick:()=>o(q?null:y.id),style:Dr,children:q?"收起":"编辑"}),e.jsx("button",{onClick:()=>_(y.id),style:{...Dr,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),q&&e.jsx(Pa,{initial:y,activeAgentId:n[0]??"",onSave:K=>O(y.id,K),onCancel:()=>o(null)})]},y.id)})]})]})}const Vc=[{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"}],ni={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function Qc(){const[t,r]=d.useState([]),[n,i]=d.useState(ni),[a,o]=d.useState(!1),[l,p]=d.useState(null),[g,h]=d.useState(null),m=async()=>{var y;if((y=window.agentApi)!=null&&y.lspList)try{const j=await window.agentApi.lspList();r(j)}catch(j){console.error("[LSP] load error",j)}};d.useEffect(()=>{m()},[]);const b=y=>{i(j=>({...j,name:y.label,language:y.language,fileTypes:y.fileTypes,command:y.command,args:y.args}))},k=y=>{p(y.id),i({id:y.id,name:y.name,language:y.language,fileTypes:y.fileTypes.join(","),command:y.command,args:y.args.join(" "),envRaw:y.env?Object.entries(y.env).map(([j,q])=>`${j}=${q}`).join(`
273
- `):""}),h(null)},I=()=>{p(null),i(ni)},M=async()=>{var A;if(!((A=window.agentApi)!=null&&A.lspSave))return;const y=n.name.trim(),j=n.command.trim();if(!y||!j)return;let q;if(n.envRaw.trim()){q={};for(const C of n.envRaw.split(`
274
- `)){const W=C.indexOf("=");W>0&&(q[C.slice(0,W).trim()]=C.slice(W+1).trim())}}const K={id:l??crypto.randomUUID(),name:y,language:n.language.trim(),fileTypes:n.fileTypes.split(",").map(C=>C.trim()).filter(Boolean),command:j,args:n.args.trim()?n.args.trim().split(/\s+/):[],env:q,enabled:!0};o(!0);try{await window.agentApi.lspSave(K),await m(),I()}finally{o(!1)}},O=async y=>{var j;(j=window.agentApi)!=null&&j.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(y),await m())},_=async y=>{var j;(j=window.agentApi)!=null&&j.lspSetEnabled&&(await window.agentApi.lspSetEnabled(y.id,!y.enabled),await m())},F=l!==null;return F&&l===null||!l&&n.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!F&&e.jsx("button",{onClick:()=>{p(""),i(ni)},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(y=>e.jsxs("div",{style:{background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",cursor:"pointer"},onClick:()=>h(g===y.id?null:y.id),children:[e.jsx("div",{onClick:j=>{j.stopPropagation(),_(y)},style:{width:32,height:18,borderRadius:9,background:y.enabled?"var(--success, #34d399)":"var(--border-default)",position:"relative",cursor:"pointer",flexShrink:0,transition:"background 0.2s"},children:e.jsx("div",{style:{position:"absolute",top:2,left:y.enabled?16:2,width:14,height:14,borderRadius:"50%",background:"#fff",transition:"left 0.2s"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:500,fontSize:13,color:"var(--text-primary)"},children:y.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[y.language,y.fileTypes.length>0?` · ${y.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[y.command,y.args.length?" "+y.args.join(" "):""]}),e.jsx("button",{onClick:j=>{j.stopPropagation(),k(y)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"编辑"}),e.jsx("button",{onClick:j=>{j.stopPropagation(),O(y.id)},style:{background:"none",border:"none",cursor:"pointer",color:"var(--danger, #f43f5e)",fontSize:13,padding:"2px 8px",fontFamily:"var(--font-body)"},children:"删除"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",style:{flexShrink:0,transition:"transform 0.2s",transform:g===y.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),g===y.id&&e.jsxs("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-muted)",borderTop:"1px solid var(--border-subtle)",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"命令:"}),e.jsxs("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:[y.command," ",y.args.join(" ")]})]}),y.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),y.fileTypes.join(", ")]}),y.env&&Object.keys(y.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(y.env).map(([j,q])=>`${j}=${q}`).join(", ")]})]})]},y.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:En,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Vc.map(y=>e.jsx("button",{onClick:()=>b(y),style:{background:"var(--bg-deep)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:"pointer",color:"var(--text-secondary)",fontFamily:"var(--font-body)"},children:y.label},y.label))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:En,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.name,onChange:y=>i(j=>({...j,name:y.target.value})),placeholder:"TypeScript Language Server",style:ar})]}),e.jsxs("div",{children:[e.jsx("label",{style:En,children:"语言"}),e.jsx("input",{value:n.language,onChange:y=>i(j=>({...j,language:y.target.value})),placeholder:"typescript",style:ar})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:En,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:n.fileTypes,onChange:y=>i(j=>({...j,fileTypes:y.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:ar})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:En,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:n.command,onChange:y=>i(j=>({...j,command:y.target.value})),placeholder:"typescript-language-server",style:{...ar,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:En,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:n.args,onChange:y=>i(j=>({...j,args:y.target.value})),placeholder:"--stdio",style:{...ar,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:En,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:n.envRaw,onChange:y=>i(j=>({...j,envRaw:y.target.value})),placeholder:`NODE_ENV=production
275
- TSPROTOCOL_LOG=verbose`,rows:3,style:{...ar,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),n.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void M(),disabled:a||!n.name.trim()||!n.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:a||!n.name.trim()||!n.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:a?"保存中…":"保存"}),e.jsx("button",{onClick:I,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"取消"})]})]})]})}const ar={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"},En={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function Kc({trigger:t,heardText:r}){const[n,i]=d.useState(!1);return d.useEffect(()=>{if(t<=0)return;i(!0);const a=setTimeout(()=>i(!1),2400);return()=>clearTimeout(a)},[t]),n?Kt.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(a=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${a}s var(--ease-out) infinite`}},a)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),r&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",r.slice(0,40),"”"]})]},t),document.body):null}const Gc=[{agentType:"customer-agent",label:"Customer Agent"},{agentType:"codex",label:"Codex"},{agentType:"claude-code",label:"Claude Code"},{agentType:"opencode",label:"OpenCode"}];function Zc({value:t,health:r,onChange:n}){return e.jsx("div",{className:"agent-workspace-switcher",role:"tablist","aria-label":"切换 Agent",children:Gc.map(i=>{const a=r.find(l=>l.agentType===i.agentType),o=(a==null?void 0:a.available)===!1;return e.jsxs("button",{type:"button",role:"tab","aria-selected":t===i.agentType,"aria-label":i.label,title:o?`${i.label} 不可用:${(a==null?void 0:a.error)??"未检测到运行时"}`:i.label,className:t===i.agentType?"is-active":"",onClick:()=>n(i.agentType),children:[e.jsx(pi,{agentType:i.agentType,size:22}),e.jsx("i",{className:o?"is-unavailable":"","aria-hidden":"true"})]},i.agentType)})})}const ri=264,Da=126;function Yc(t){const r=typeof window>"u"?1024:window.innerWidth,n=typeof window>"u"?768:window.innerHeight,i=Math.max(8,Math.min(t.left+t.width-ri,r-ri-8)),a=t.top+t.height+7,o=a+Da<=n-8?a:Math.max(8,t.top-Da-7);return{left:i,top:o,width:ri}}function Jc({message:t,anchor:r,mobile:n,pending:i,onCancel:a,onConfirm:o}){const l=p=>p.stopPropagation();return e.jsx("div",{className:`sidebar-delete-confirmation-layer${n?" is-mobile":""}`,onClick:i?void 0:a,children:e.jsxs("div",{className:"sidebar-delete-confirmation",role:"alertdialog","aria-modal":"true","aria-labelledby":"sidebar-delete-confirmation-title","aria-describedby":"sidebar-delete-confirmation-message",style:n?void 0:Yc(r),onClick:l,children:[e.jsx("strong",{id:"sidebar-delete-confirmation-title",children:"删除会话"}),e.jsx("p",{id:"sidebar-delete-confirmation-message",children:t}),e.jsxs("div",{className:"sidebar-delete-confirmation-actions",children:[e.jsx("button",{type:"button",onClick:a,disabled:i,children:"取消"}),e.jsx("button",{type:"button",className:"is-danger",onClick:o,disabled:i,children:i?"正在删除...":"删除"})]})]})})}function si({session:t,deleteLabel:r="删除会话",onSelect:n,onDelete:i}){var a,o;return e.jsxs("div",{className:`sidebar-row sidebar-session-row${t.child?" sidebar-session-row--child":""}${t.active?" sidebar-row-active":""}`,children:[e.jsxs("button",{type:"button",className:"sidebar-session-button",onClick:n,"aria-pressed":t.active,"aria-expanded":t.hasChildren?!!t.expanded:void 0,title:t.title,children:[e.jsx("span",{className:`sidebar-status-dot is-${t.visualState}`,title:t.statusLabel,"aria-label":t.statusLabel}),e.jsx("span",{className:"sidebar-session-title",children:t.title}),((a=t.compatibility)==null?void 0:a.status)==="checking"&&e.jsx("span",{className:"sidebar-session-compatibility",title:`正在验证 Codex ${t.compatibility.producerVersion??"未知版本"} 会话兼容性`,"aria-label":"正在验证会话兼容性",children:e.jsx(dn,{size:13,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"})}),((o=t.compatibility)==null?void 0:o.status)==="incompatible"&&e.jsx("span",{className:"sidebar-session-compatibility",title:t.compatibility.reason??"Codex 版本不兼容","aria-label":"Codex 版本不兼容",children:e.jsx(pl,{size:13,"aria-hidden":"true"})}),t.occupiedExternally&&e.jsx("span",{className:"sidebar-session-lock",title:"原客户端正在使用,只读","aria-label":"原客户端正在使用,只读",children:e.jsx(Rl,{size:13,"aria-hidden":"true"})}),t.hasChildren&&e.jsx(dr,{size:13,className:`sidebar-session-disclosure${t.expanded?" is-expanded":""}`,"aria-hidden":"true"})]}),t.canDelete&&i&&e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation();const p=l.currentTarget.getBoundingClientRect();i({top:p.top,left:p.left,width:p.width,height:p.height})},title:r,"aria-label":`${r}:${t.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(us,{size:14,"aria-hidden":"true"})})]})}const Xc=[["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"])]],eu=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function tu(t){var a;const r=t.toLocaleLowerCase(),n=eu.get(r);if(n)return n;if(r.startsWith(".env")||r===".gitignore"||r===".npmrc")return"text";const i=r.includes(".")&&r.split(".").pop()||"";return((a=Xc.find(([,o])=>o.has(i)))==null?void 0:a[0])??"file"}const nu={folder:{icon:Sl,label:"文件夹"},code:{icon:bl,label:"代码文件"},style:{icon:Ml,label:"样式文件"},image:{icon:yl,label:"图片文件"},video:{icon:jl,label:"视频文件"},audio:{icon:ml,label:"音频文件"},markdown:{icon:Tl,label:"Markdown 文件"},text:{icon:xs,label:"文本文件"},json:{icon:vl,label:"JSON 文件"},archive:{icon:xl,label:"压缩文件"},spreadsheet:{icon:wl,label:"表格文件"},presentation:{icon:El,label:"演示文件"},database:{icon:hl,label:"数据库文件"},file:{icon:kl,label:"文件"}};function ru(t,r){return r==="directory"?"folder":tu(t)}const Ba=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function su(t,r){const n=Ba(t),i=Ba(r),o=[{label:n==="/"?"/":n.split("/").filter(Boolean).pop()||n,path:n}];if(i===n)return o;const l=i.slice(n==="/"?1:n.length+1);let p=n;for(const g of l.split("/").filter(Boolean))p=p==="/"?`/${g}`:`${p}/${g}`,o.push({label:g,path:p});return o}function iu({open:t,onCancel:r,onConfirm:n}){const[i,a]=d.useState([]),[o,l]=d.useState(""),[p,g]=d.useState(""),[h,m]=d.useState([]),[b,k]=d.useState(!1),[I,M]=d.useState(""),[O,_]=d.useState(!1),F=d.useMemo(()=>su(o||"/",p||o||"/"),[o,p]),y=async A=>{if(window.agentApi){k(!0),M("");try{const C=await window.agentApi.listProjectDirectories(A);m(C),g(A)}catch(C){M(C instanceof Error?C.message:"无法读取目录")}finally{k(!1)}}};if(d.useEffect(()=>{if(!t||!window.agentApi)return;let A=!1;return k(!0),M(""),window.agentApi.listProjectRoots().then(async C=>{if(A)return;a(C);const W=C[0]??"";l(W),W?await y(W):M("未配置可用的宿主机目录")}).catch(C=>{A||M(C instanceof Error?C.message:"无法读取宿主机目录")}).finally(()=>{A||k(!1)}),()=>{A=!0}},[t]),d.useEffect(()=>{if(!t)return;const A=C=>{C.key==="Escape"&&r()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,r]),!t)return null;const j=A=>{l(A),y(A)},q=()=>{F.length<=1||y(F[F.length-2].path)},K=async()=>{if(!(!p||O)){_(!0),M("");try{await n(p)}catch(A){M(A instanceof Error?A.message:"项目导入失败")}finally{_(!1)}}};return Kt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:A=>{A.target===A.currentTarget&&r()},children:e.jsxs("section",{className:"host-project-picker",role:"dialog","aria-modal":"true","aria-labelledby":"host-project-picker-title",children:[e.jsxs("header",{className:"host-project-picker-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"host-project-picker-title",children:"选择宿主机项目"}),e.jsx("p",{children:"文件将直接在运行 AgentRoam 的机器上读写"})]}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(Ya,{size:16,"aria-hidden":"true"})})]}),i.length>1&&e.jsxs("label",{className:"host-project-picker-root",children:[e.jsx("span",{children:"根目录"}),e.jsx("select",{value:o,onChange:A=>j(A.target.value),children:i.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:q,disabled:F.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(cl,{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 y(A.path),children:A.label})]},A.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>p&&void y(p),disabled:!p||b,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(Ka,{size:15,"aria-hidden":"true"})})]}),o==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":b,children:b?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):I?e.jsx("div",{className:"host-project-picker-state is-error",children:I}):h.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):h.map(A=>{const C=ru(A.name,A.kind),{icon:W,label:E}=nu[C],L=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:E,children:L},`${A.name}:${A.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void y(A.path),title:E,children:[L,A.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(dr,{size:16})})]},`${A.name}:${A.path}`)})}),e.jsxs("footer",{className:"host-project-picker-footer",children:[e.jsx("code",{title:p,children:p}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:r,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!p||b||O,onClick:()=>void K(),children:O?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const jo="agentroam.agent-workspaces.v2",au=2,ko=["customer-agent","codex","claude-code","opencode"];function Fa(){return{version:2,activeAgent:"customer-agent",agents:{}}}function $a(){return{workspaces:[],nextCursor:null,watermark:null,expandedWorkspaceIds:[],selectedWorkspaceId:null,selectedSessionId:null,sidebarScrollTop:0,sessions:{}}}function ou(t=localStorage){try{const r=JSON.parse(t.getItem(jo)??"null");if(!_n(r)||r.version!==au)return Fa();const n=pu(r.activeAgent)?r.activeAgent:"customer-agent",i=_n(r.agents)?r.agents:{},a={};for(const o of ko){const l=uu(i[o],o);l&&(a[o]=l)}return{version:2,activeAgent:n,agents:a}}catch{return Fa()}}function Oa(t,r=localStorage){try{r.setItem(jo,JSON.stringify(t))}catch{}}function lu(t,r,n){const i=new Set(r.data.map(l=>l.workspaceId)),a=n?r.nextCursor?[...r.data,...t.filter(l=>!i.has(l.workspaceId))]:r.data:[...t,...r.data],o=new Set;return a.filter(l=>o.has(l.workspaceId)?!1:(o.add(l.workspaceId),!0))}function du(t,r,n){const i=new Set(r.data.map(l=>l.id)),a=n?r.nextCursor?[...r.data,...t.filter(l=>!i.has(l.id))]:r.data:[...t,...r.data],o=new Set;return a.filter(l=>o.has(l.id)?!1:(o.add(l.id),!0))}function cu(t,r){return!r||t.some(n=>n.id===r.id)?[...t]:[r,...t]}function uu(t,r){if(!_n(t))return null;const n=Array.isArray(t.workspaces)?t.workspaces.filter(a=>_n(a)&&a.agentType===r&&typeof a.workspaceId=="string"&&typeof a.name=="string"&&Array.isArray(a.roots)&&a.roots.every(o=>typeof o=="string")&&typeof a.order=="number"&&(a.canCreateSession===void 0||typeof a.canCreateSession=="boolean")):[],i={};if(_n(t.sessions))for(const[a,o]of Object.entries(t.sessions))!_n(o)||!Array.isArray(o.data)||(i[a]={data:o.data.filter(l=>_n(l)&&l.agentType===r&&typeof l.id=="string"),nextCursor:typeof o.nextCursor=="string"?o.nextCursor:null,loaded:o.loaded===!0});return{workspaces:n,nextCursor:typeof t.nextCursor=="string"?t.nextCursor:null,watermark:typeof t.watermark=="string"?t.watermark:null,expandedWorkspaceIds:Array.isArray(t.expandedWorkspaceIds)?t.expandedWorkspaceIds.filter(a=>typeof a=="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:i}}function pu(t){return typeof t=="string"&&ko.includes(t)}function _n(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Ua(t){var i;const r={},n={};for(const[a,o]of Object.entries(t)){const l=o.data;r[a]=wi(l.filter(p=>!p.parentSessionId));for(const p of l.filter(g=>g.parentSessionId))(n[i=p.parentSessionId]??(n[i]=[])).push(p)}for(const a of Object.values(n))a.sort((o,l)=>o.created.localeCompare(l.created));return{roots:r,children:n,projectIds:new Set(Object.entries(t).filter(([,a])=>a.loaded).map(([a])=>a))}}function ii(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 fu(){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 qa(t,r){r&&t.detail>0&&t.currentTarget.blur()}function gu(){const t=document.activeElement;t instanceof HTMLElement&&(t.matches("input, textarea, select")||t.isContentEditable)&&t.blur()}function mu(){var Sr,Ir,st,Ht;const[t]=d.useState(ou),r=t.activeAgent,n=t.agents[r]??$a(),[i]=d.useState(()=>Ua(n.sessions)),a=d.useRef(t),[o,l]=d.useState(r),p=d.useRef(o);p.current=o;const[g,h]=d.useState(n.workspaces.map(ii)),[m,b]=d.useState(n.nextCursor),[k,I]=d.useState(n.watermark),[M,O]=d.useState(!1),[_,F]=d.useState(!1),[y,j]=d.useState(null),[q,K]=d.useState(!1),[A,C]=d.useState(i.roots),[W,E]=d.useState(""),[L,ae]=d.useState(!1),[fe,we]=d.useState(10),[G,Ke]=d.useState(null),[kt,Ln]=d.useState(!1),[Le,Pn]=d.useState(null),zt=d.useRef(!1),[_t,pr]=d.useState([]),[lt,S]=d.useState(i.children),U=d.useRef(A),le=d.useRef(lt);U.current=A,le.current=lt;const[pe,be]=d.useState(i.projectIds),[Ie,Ce]=d.useState(new Set),[Se,Wt]=d.useState({}),[dt,St]=d.useState(new Set),[gt,Dn]=d.useState(Object.fromEntries(Object.entries(n.sessions).map(([c,w])=>[c,w.nextCursor]))),Lt=d.useRef(new Map),ht=d.useRef(new Map),[ye,fr]=d.useState(n.selectedWorkspaceId),[qe,xt]=d.useState(n.selectedSessionId),It=d.useRef(ye),Ct=d.useRef(qe);It.current=ye,Ct.current=qe;const[cn,un]=d.useState(new Set),[pn,At]=d.useState(new Set(n.expandedWorkspaceIds)),[Pt,Bn]=d.useState(new Set),[H,he]=d.useState(!1),[ue,$r]=d.useState("settings"),Fn=ge(c=>c.setTodos),Dt=ot(c=>c.skin),Ge=ot(c=>c.layout),Rt=ot(c=>c.wakeEnabled),ct=ot(c=>c.wakeWord),fn=ot(c=>c.setSkin),$n=ot(c=>c.setLayout),gr=ot(c=>c.setWakeEnabled),On=ot(c=>c.setWakeWord),hr=ot(c=>c.autoSpeak),Un=ot(c=>c.setAutoSpeak),mt=ot(c=>c.runningFirst),xr=ot(c=>c.setRunningFirst),Qe=ge(c=>c.runningSessionId),mr=ge(Bl(c=>Object.entries(c.messagesBySession).filter(([,w])=>w.some(R=>R.askUser&&!R.askUser.answered)).map(([w])=>w))),gn=d.useCallback(c=>c.status==="running"||Qe===c.id,[Qe]),Or=()=>{At(new Set),un(new Set(Object.keys(lt)))},hn=()=>{const c=g.filter(w=>!Pt.has(w.id)).map(w=>w.id);At(new Set(c)),un(new Set);for(const w of c){if(Ne.current.has(w))continue;const R=Ft.current.has(w);Ye(w,{refresh:R,background:R})}},Zt=or(),Ur=rl(),ut=Zt&&Ur,[qn,bt]=d.useState(!1),[Bt,xn]=d.useState(!1),[mn,Hn]=d.useState(null),[Vn,Qn]=d.useState(0),[qr,bn]=d.useState(void 0),Ze=d.useRef(null),et=d.useRef(!1),[Hr,Vr]=d.useState(null),Tt=d.useRef(null),Yt=d.useRef(!1),Mt=d.useRef(g);Mt.current=g;const Qr=d.useRef(Pt);Qr.current=Pt;const Ft=d.useRef(pe);Ft.current=pe;const Ne=d.useRef(Ie);Ne.current=Ie;const ze=d.useRef(null);d.useEffect(()=>{document.documentElement.setAttribute("data-skin",Dt)},[Dt]),d.useEffect(()=>{document.body.classList.toggle("layout-compact",Ge==="compact")},[Ge]),d.useEffect(()=>{var N;const c=g.map((P,te)=>({agentType:o,workspaceId:P.id,name:P.name,roots:P.description?[P.description]:[],order:te,updatedAt:P.updated||void 0,source:P.source??(P.agentType==="claude-code"?"derived":"native"),canCreateSession:P.canCreateSession})),w=Object.fromEntries(g.map(P=>[P.id,{data:[...A[P.id]??[],...Object.values(lt).flat().filter(te=>(A[P.id]??[]).some(Y=>Y.id===te.parentSessionId))],nextCursor:gt[P.id]??null,loaded:pe.has(P.id)}])),R={...a.current,version:2,activeAgent:o,agents:{...a.current.agents,[o]:{workspaces:c,nextCursor:m,watermark:k,expandedWorkspaceIds:[...pn],selectedWorkspaceId:ye,selectedSessionId:qe,sidebarScrollTop:((N=ze.current)==null?void 0:N.scrollTop)??0,sessions:w}}};a.current=R,Oa(R)},[o,lt,pn,pe,g,ye,qe,gt,A,m,k]);const yt=d.useCallback(()=>{if(!window.agentApi||!Rt||et.current||Ze.current)return;const c=()=>{Ql()&&!Ze.current&&(Ze.current=Gl({wakeWord:ct,onWake:w=>{var R;bn(w),Qn(N=>N+1),(R=window.agentApi)==null||R.showWindow()},onError:w=>console.warn("[wake]",w)}))};typeof window.agentApi.wakeStart=="function"?(et.current=!0,window.agentApi.wakeStart(ct).then(w=>{w.ok||(et.current=!1,c())}).catch(()=>{et.current=!1,c()})):c()},[Rt,ct]);d.useEffect(()=>{var c;if((c=window.agentApi)!=null&&c.onWake)return window.agentApi.onWake(w=>{et.current=!1,bn(w),Qn(R=>R+1)})},[]),d.useEffect(()=>{var c;if((c=window.agentApi)!=null&&c.onWakeCommand)return window.agentApi.onWakeCommand(w=>{var te;const R=((w==null?void 0:w.text)||"").trim();if(!R)return;const N=Tt.current&&Date.now()<Tt.current.until?Tt.current:null;if(N){N.until=Date.now()+9e4,xt(N.sessionId),(te=window.agentApi)==null||te.wakeConversation(!0),Vr({text:R,projectId:null,sessionId:N.sessionId,nonce:Date.now()}),ve(`语音追问:${R.length>40?R.slice(0,40)+"…":R}`),He("success"),setTimeout(()=>ve(null),4e3);return}const P=Mt.current.find(Y=>Y.name&&R.includes(Y.name)&&!Qr.current.has(Y.id));P&&(fr(P.id),At(Y=>{const se=new Set(Y);return se.add(P.id),se})),xt(null),Yt.current=!0,Un(!0),Vr({text:R,projectId:(P==null?void 0:P.id)??null,nonce:Date.now()}),ve(`语音指令:${R.length>40?R.slice(0,40)+"…":R}${P?`(项目:${P.name})`:""}`),He("success"),setTimeout(()=>ve(null),4e3)})},[]);const Kn=d.useCallback(async()=>{window.agentApi&&(yt(),await window.agentApi.hideWindow())},[yt]),br=d.useCallback(c=>{he(!1),Hn({right:c.right,bottom:c.bottom}),xn(w=>!w)},[]),yn=d.useCallback(()=>{xn(!1),he(c=>!c)},[]);d.useEffect(()=>{if(!Bt)return;const c=()=>{const R=document.querySelector(".chat-header-action--appearance");if(!R)return;const N=R.getBoundingClientRect();Hn(P=>(P==null?void 0:P.right)===N.right&&P.bottom===N.bottom?P:{right:N.right,bottom:N.bottom})},w=window.requestAnimationFrame(c);return window.addEventListener("resize",c),()=>{window.cancelAnimationFrame(w),window.removeEventListener("resize",c)}},[Ge,Bt]),d.useEffect(()=>{window.agentApi&&yt()},[yt]),d.useEffect(()=>{const c=()=>{var w;(w=Ze.current)==null||w.stop(),Ze.current=null};return window.addEventListener("focus",c),()=>window.removeEventListener("focus",c)},[]),d.useEffect(()=>{var c,w;Rt||((c=Ze.current)==null||c.stop(),Ze.current=null,et.current=!1,(w=window.agentApi)==null||w.wakeStop())},[Rt]),d.useEffect(()=>{!Rt||!window.agentApi||et.current&&window.agentApi.wakeStart(ct)},[ct]),d.useEffect(()=>()=>{var c;(c=Ze.current)==null||c.stop()},[]);const Jt=[...Object.values(A).flat(),...Object.values(lt).flat()],Kr=Jt,tt=W.trim().toLowerCase(),nt=tt?Jt.filter(c=>c.title.toLowerCase().includes(tt)||(c.cwd||"").toLowerCase().includes(tt)):null,_e=qe?Kr.find(c=>c.id===qe):void 0,Gr=_e==null?void 0:_e.title,yr=(_e==null?void 0:_e.cwd)||((Sr=g.find(c=>c.id===ye))==null?void 0:Sr.description)||null,Xt=g.filter(c=>!Pt.has(c.id)).map(c=>c.id),vt=Xt.length>0&&Xt.every(c=>!pn.has(c)),[$t,Gn]=d.useState(300),[Ot,en]=d.useState(!1),wt=d.useRef(!1),Zr=d.useRef(0),We=d.useRef(0),Et=d.useCallback(c=>{if(!wt.current)return;const w=Math.min(480,Math.max(160,We.current+c.clientX-Zr.current));Gn(w)},[]),Zn=d.useCallback(()=>{wt.current=!1,en(!1),document.removeEventListener("mousemove",Et),document.removeEventListener("mouseup",Zn)},[Et]),vr=d.useCallback(c=>{wt.current=!0,en(!0),Zr.current=c.clientX,We.current=$t,document.addEventListener("mousemove",Et),document.addEventListener("mouseup",Zn)},[$t,Et,Zn]),[wr,ve]=d.useState(null),[Ut,He]=d.useState("success"),je=c=>{It.current=c.projectId,Ct.current=c.sessionId,fr(c.projectId),xt(c.sessionId),c.sessionId||Fn([])},jr=c=>{var Y;if(c===p.current)return;const w=p.current,R=a.current.agents[w];R&&(a.current={...a.current,agents:{...a.current.agents,[w]:{...R,sidebarScrollTop:((Y=ze.current)==null?void 0:Y.scrollTop)??R.sidebarScrollTop}}});const N=a.current.agents[c]??$a(),P=Ua(N.sessions),te=N.workspaces.map(ii);p.current=c,Mt.current=te,l(c),h(te),b(N.nextCursor),I(N.watermark),O(!1),F(!1),j(null),U.current=P.roots,le.current=P.children,C(P.roots),S(P.children),be(P.projectIds),Ft.current=P.projectIds,Ce(new Set),Ne.current=new Set,Wt({}),St(new Set),Dn(Object.fromEntries(Object.entries(N.sessions).map(([se,Me])=>[se,Me.nextCursor]))),At(new Set(N.expandedWorkspaceIds)),Bn(new Set),je({projectId:N.selectedWorkspaceId,sessionId:N.selectedSessionId}),window.requestAnimationFrame(()=>{ze.current&&(ze.current.scrollTop=N.sidebarScrollTop)}),qt(c,{refresh:N.workspaces.length>0,since:N.watermark})},[re,Yn]=d.useState([]),tn=d.useCallback(c=>{Yn(w=>w.filter(R=>R.id!==c))},[]),Jn=d.useCallback(c=>{const w=crypto.randomUUID();Yn(R=>[...R,{...c,id:w}]),setTimeout(()=>tn(w),12e3)},[tn]);async function qt(c=p.current,w={}){if(!window.agentApi)return;const R=(ht.current.get(c)??0)+1;ht.current.set(c,R),O(!0),j(null);try{const N=await window.agentApi.listAgentWorkspaces(c,{cursor:w.cursor,limit:50,refresh:w.refresh,since:w.refresh?w.since??k:null});if(p.current!==c||ht.current.get(c)!==R)return;const P=Mt.current.map((oe,X)=>({agentType:c,workspaceId:oe.id,name:oe.name,roots:oe.description?[oe.description]:[],order:X,updatedAt:oe.updated,source:oe.source??(c==="claude-code"?"derived":"native"),canCreateSession:oe.canCreateSession})),Y=lu(P,N,!w.cursor).map(ii);Mt.current=Y,h(Y),b(N.nextCursor),I(N.watermark),F(N.stale===!0);const se=new Set(Y.map(oe=>oe.id)),Me=It.current;Me&&!se.has(Me)&&je(Ma);const Ee=new Set([...Ft.current].filter(oe=>se.has(oe)));Me&&se.has(Me)&&Ee.add(Me),C(oe=>Object.fromEntries(Object.entries(oe).filter(([X])=>se.has(X)))),be(oe=>{const X=new Set([...oe].filter(Fe=>se.has(Fe)));return Ft.current=X,X}),Ce(oe=>{const X=new Set([...oe].filter(Fe=>se.has(Fe)));return Ne.current=X,X}),Wt(oe=>Object.fromEntries(Object.entries(oe).filter(([X])=>se.has(X))));const Be=new Set;if(await Promise.all(Y.map(async oe=>{oe.description&&!await window.agentApi.checkProjectPath(oe.description)&&Be.add(oe.id)})),p.current!==c||ht.current.get(c)!==R)return;if(Bn(Be),w.refreshLoadedSessions!==!1)for(const oe of Ee)Be.has(oe)||Ne.current.has(oe)||Ye(oe,{refresh:!0,background:!0})}catch(N){p.current===c&&(Mt.current.length>0&&F(!0),j(N instanceof Error?N.message:"目录加载失败"))}finally{p.current===c&&ht.current.get(c)===R&&O(!1)}}async function Ye(c,w={}){var te;if(!window.agentApi)return;const R=p.current,N=`${R}:${c}`,P=(Lt.current.get(N)??0)+1;Lt.current.set(N,P),Ce(Y=>{const se=new Set(Y).add(c);return Ne.current=se,se}),Wt(Y=>{if(!(c in Y))return Y;const se={...Y};return delete se[c],se});try{const Y=await window.agentApi.listAgentWorkspaceSessions(R,c,{cursor:w.cursor,limit:20,refresh:w.refresh});if(p.current!==R||Lt.current.get(N)!==P)return;const se=U.current[c]??[],Me=w.pendingSession?{...w.pendingSession,projectId:c}:void 0,Ee=Me?[Me,...se.filter(de=>de.id!==Me.id)]:se,Be=new Set(Ee.map(de=>de.id)),oe=[...Ee,...[...Be].flatMap(de=>le.current[de]??[])],X=du(oe,Y,!w.cursor).map(de=>({...de,projectId:de.projectId??c})),Fe=wi(X.filter(de=>!de.parentSessionId)),pt=It.current,it=Ct.current,jt=cu(Fe,Me);pt===c&&it&&!X.some(de=>de.id===it)&&!jt.some(de=>de.id===it)&&je(Ma);const Je={};for(const de of X.filter($e=>$e.parentSessionId))(Je[te=de.parentSessionId]??(Je[te]=[])).push(de);for(const de of Object.values(Je))de.sort(($e,Xn)=>$e.created.localeCompare(Xn.created));Dn(de=>({...de,[c]:Y.nextCursor})),St(de=>{const $e=new Set(de);return Y.stale?$e.add(c):$e.delete(c),$e});const Ae={...U.current,[c]:jt},Re={...le.current};for(const de of Be)delete Re[de];for(const[de,$e]of Object.entries(Je))Re[de]=$e;U.current=Ae,le.current=Re,C(Ae),S(Re),be(de=>{const $e=new Set(de).add(c);return Ft.current=$e,$e})}catch(Y){if(Lt.current.get(N)!==P)return;Wt(se=>({...se,[c]:Y instanceof Error?Y.message:"会话加载失败"}))}finally{Lt.current.get(N)===P&&Ce(Y=>{const se=new Set(Y);return se.delete(c),Ne.current=se,se})}}const kr=async c=>{if(!window.agentApi)return;const w=await window.agentApi.listChildSessions(c);S(R=>({...R,[c]:w.sort((N,P)=>N.created<P.created?-1:1)}))},vn=async(c,w)=>{if(!window.agentApi)return;const R=Mt.current.find(N=>N.id===c);if(!R||R.canCreateSession===!1){ve("请先选择目录"),He("info"),setTimeout(()=>ve(null),3e3);return}if(!zt.current){zt.current=!0,Pn({projectId:c,agentType:w});try{const N=(R==null?void 0:R.source)==="imported"?void 0:c,P=await window.agentApi.createSession("新会话",N,w,R==null?void 0:R.description);if(p.current!==w)return;const te=P.projectId===c?P:{...P,projectId:c},Y={...U.current,[c]:[te,...(U.current[c]??[]).filter(se=>se.id!==P.id)]};U.current=Y,C(Y),je({projectId:c,sessionId:P.id}),ut&&bt(!1),w==="customer-agent"&&Ye(c,{refresh:!0,background:!0,pendingSession:te})}catch(N){ve(N instanceof Error?N.message:"新建会话失败"),He("error"),setTimeout(()=>ve(null),3e3)}finally{zt.current=!1,Pn(null)}}},wn=()=>{const c=Mt.current.find(w=>w.id===ye);if(!ye||(c==null?void 0:c.canCreateSession)===!1){ve("请先选择目录"),He("info"),setTimeout(()=>ve(null),3e3);return}vn(ye,o)};d.useEffect(()=>{var c;window.agentApi&&(qt(p.current,{refresh:(((c=a.current.agents[p.current])==null?void 0:c.workspaces.length)??0)>0}),ms.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(pr).catch(()=>{}))},[]),d.useEffect(()=>{const c=window.setInterval(()=>{document.visibilityState!=="visible"||M||qt(o,{refresh:!0,since:k,refreshLoadedSessions:!1})},15e3);return()=>window.clearInterval(c)},[o,M,k]),d.useEffect(()=>{if(!ye||!qe||(_e==null?void 0:_e.agentType)==="customer-agent"||!window.agentApi)return;let c=!1;const w=async()=>{document.visibilityState==="visible"&&(c||await Ye(ye,{refresh:!0,background:!0}))},R=window.setInterval(()=>void w(),1e4);return()=>{c=!0,window.clearInterval(R)}},[ye,qe,_e==null?void 0:_e.agentType]),d.useEffect(()=>{if(!ye||!window.agentApi)return;const c=g.find(R=>R.id===ye),w=c==null?void 0:c.description;w&&window.agentApi.setProjectWorkingDir(w)},[ye,g]);const Yr=c=>{je(Ea(c));const w=!pn.has(c);if(At(R=>{const N=new Set(R);return w?N.add(c):N.delete(c),N}),w&&!Ne.current.has(c)){const R=Ft.current.has(c);Ye(c,{refresh:R,background:R})}},jn=async c=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const w=c.replace(/\\/g,"/"),R=w.split("/").filter(Boolean),N=R[R.length-1]||w||"导入的项目",P=await window.agentApi.importAgentWorkspace(p.current,w,N);await qt(p.current,{refresh:!0,refreshLoadedSessions:!1}),je(Ea(P.workspace.workspaceId)),await Ye(P.workspace.workspaceId,{refresh:!0}),At(te=>{const Y=new Set(te);return Y.add(P.workspace.workspaceId),Y}),ve(P.existing?"该文件夹已在当前 Agent 的目录中":`已导入:${P.workspace.name}`),He(P.existing?"info":"success"),setTimeout(()=>ve(null),3e3)},ys=async()=>{try{if(!window.agentApi){ve("agentApi 未就绪,请重启应用"),He("error");return}if(Zt){K(!0);return}const c=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",c),!c)return;await jn(c)}catch(c){console.error("[import] error:",c),ve(c instanceof Error?c.message:String(c)),He("error"),setTimeout(()=>ve(null),5e3)}},kn=async c=>{if(window.agentApi)try{await window.agentApi.deleteProject(c),ye===c&&(fr(null),xt(null),Fn([])),ve("项目删除成功"),He("success"),setTimeout(()=>ve(null),2500),await qt()}catch(w){ve(w instanceof Error?w.message:"项目删除失败"),He("error"),setTimeout(()=>ve(null),4e3)}},rt=(c,w)=>{Ke({session:c,anchor:w})},Jr=async()=>{if(!window.agentApi||!G||kt)return;const{session:c}=G;Ln(!0);try{await window.agentApi.deleteSession(c.id);const w=c.projectId??It.current,R=c.agentType;if(w){const te=`${R}:${w}`;Lt.current.set(te,(Lt.current.get(te)??0)+1)}const N=_c(U.current,le.current,[],c.id);U.current=N.sessionsByProject,le.current=N.childSessionsByParent,C(N.sessionsByProject),S(N.childSessionsByParent);const P=a.current.agents[R];if(P){const te={...a.current,agents:{...a.current.agents,[R]:Nc(P,N.removedIds)}};a.current=te,Oa(te)}Ct.current&&N.removedIds.includes(Ct.current)&&je({projectId:It.current,sessionId:null}),ve("会话删除成功"),He("success"),setTimeout(()=>ve(null),2500),Ke(null),w&&Ye(w,{refresh:!0,background:!0})}catch(w){ve(w instanceof Error?w.message:"会话删除失败"),He("error"),setTimeout(()=>ve(null),4e3)}finally{Ln(!1)}},nn=[{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:Zt?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[ut&&qn&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>bt(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),ut&&!qn&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>bt(!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}}),Ge!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:$t,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 0",position:"relative",zIndex:10,overflow:"hidden",...ut?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:qn?"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(pi,{agentType:"customer-agent",size:24})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsx(Zc,{value:o,health:_t,onChange:jr}),e.jsxs("button",{type:"button",className:"sidebar-search-field",onClick:()=>{ae(!0),we(10)},title:"搜索会话","aria-label":"搜索会话",children:[e.jsx(Ga,{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":`${g.length} 个目录`,children:g.length})]}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:c=>{vt?hn():Or(),qa(c,vt)},title:vt?"展开全部会话":"折叠全部会话","aria-label":vt?"展开全部会话":"折叠全部会话","aria-pressed":vt,disabled:Xt.length===0,className:`ui-icon-button sidebar-collapse-all${vt?" 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:vt?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:c=>{xr(!mt),qa(c,mt)},title:mt?"按新建时间排序":"进行中会话优先","aria-label":mt?"按新建时间排序":"进行中会话优先","aria-pressed":mt,className:`ui-icon-button sidebar-session-sort${mt?" 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 ys(),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:ze,className:"app-sidebar-scroll",onPointerDownCapture:gu,onScroll:c=>{const w=c.currentTarget;w.scrollHeight-w.scrollTop-w.clientHeight<120&&m&&!M&&qt(o,{cursor:m})},style:{flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[g.map(c=>{var oe;const w=ye===c.id,R=pn.has(c.id),N=pe.has(c.id),P=Ie.has(c.id),te=Se[c.id],Y=A[c.id]??[],se=mt?Mc(Y,gn):Y,Me=se.length>10,Ee=Pt.has(c.id),Be=(Le==null?void 0:Le.agentType)===o&&Le.projectId===c.id;return e.jsxs("div",{className:"sidebar-project-block","aria-busy":P,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${w&&!Ee?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:Ee?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{Ee||Yr(c.id)},disabled:Ee,"aria-expanded":R,"aria-pressed":w,title:Ee?`路径不存在:${c.description}`:c.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:Ee?"var(--text-muted)":w?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:w&&!Ee?600:400,cursor:Ee?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[Ee?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"})]}):c.canCreateSession===!1?e.jsx(Il,{size:13,"aria-hidden":"true",style:{flexShrink:0,opacity:w?1:.5}}):e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:w?1:.5},children:R?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:c.name})]}),o==="customer-agent"&&!Zt&&e.jsx("button",{onClick:X=>{X.stopPropagation(),kn(c.id)},title:"删除目录","aria-label":`删除目录:${c.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(fu,{})}),c.canCreateSession!==!1&&e.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),vn(c.id,o)},title:Be?"正在创建会话":`新建 ${o==="customer-agent"?"Customer Agent":o==="claude-code"?"Claude Code":o==="codex"?"Codex":"OpenCode"} 会话`,"aria-label":Be?"正在创建会话":`在 ${c.name} 中新建会话`,"aria-busy":Be,disabled:Le!==null||Ee||((oe=_t.find(X=>X.agentType===o))==null?void 0:oe.available)===!1,className:"sidebar-runtime-create sidebar-project-add-action ui-icon-button ui-icon-button--small",children:Be?e.jsx(dn,{size:13,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):e.jsx(ta,{size:13,"aria-hidden":"true"})})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:R?Me?300:800:0,opacity:R?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:X=>{const Fe=X.currentTarget,pt=Fe.scrollHeight-Fe.scrollTop-Fe.clientHeight<80,it=gt[c.id];pt&&it&&!P&&Ye(c.id,{cursor:it})},style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...Me?{maxHeight:280,overflowY:"auto"}:{}},children:[se.map(X=>{const Fe=qe===X.id,pt=gn(X),it=Zs({status:X.status,isRunning:pt,needsInput:pt&&mr.includes(X.id)}),jt=lt[X.id]??[],Je=!cn.has(X.id);return e.jsxs("div",{children:[e.jsx(si,{session:{id:X.id,title:X.title,visualState:it,statusLabel:Ys[it],occupiedExternally:X.occupancy==="owned-externally",canDelete:X.canDelete,active:Fe,hasChildren:jt.length>0,expanded:Je,compatibility:X.compatibility},onSelect:()=>{ut&&bt(!1),je(Js(c.id,X.id)),jt.length>0&&un(Ae=>{const Re=new Set(Ae);return Re.has(X.id)?Re.delete(X.id):Re.add(X.id),Re})},onDelete:Ae=>rt(X,Ae)}),e.jsx("div",{className:"sidebar-child-sessions",style:{maxHeight:Je?jt.length*40:0,opacity:Je?1:0},children:jt.map(Ae=>{const Re=gn(Ae),de=Zs({status:Ae.status,isRunning:Re,needsInput:Re&&mr.includes(Ae.id)});return e.jsx(si,{session:{id:Ae.id,title:Ae.title,visualState:de,statusLabel:Ys[de],occupiedExternally:Ae.occupancy==="owned-externally",canDelete:Ae.canDelete,active:qe===Ae.id,child:!0,compatibility:Ae.compatibility},deleteLabel:"删除子会话",onSelect:()=>{ut&&bt(!1),je(Js(c.id,Ae.id))},onDelete:$e=>rt(Ae,$e)},Ae.id)})})]},X.id)}),P&&!N&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),te&&e.jsxs("div",{title:te,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 Ye(c.id,{refresh:N,background:N}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),dt.has(c.id)&&!te&&e.jsx("div",{className:"sidebar-cache-state",children:"显示缓存,会话将在下次刷新时更新"}),se.length===0&&N&&!P&&!te&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},c.id)}),g.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:M?"正在加载目录...":"暂无目录"}),g.length>0&&M&&e.jsx("div",{className:"sidebar-cache-state",children:"正在同步目录..."}),_&&!y&&e.jsx("div",{className:"sidebar-cache-state",children:"当前显示缓存目录"}),y&&e.jsxs("div",{className:"sidebar-load-error",title:y,children:[e.jsx("span",{children:g.length>0?"目录刷新失败,当前显示缓存":"目录加载失败"}),e.jsx("button",{type:"button",onClick:()=>void qt(o,{refresh:g.length>0}),children:"重试"})]})]})}),e.jsx("div",{className:"sidebar-bottom-action",children:e.jsx("button",{type:"button",className:"sidebar-new-session-primary",disabled:Le!==null||ye!==null&&Pt.has(ye)||((Ir=_t.find(c=>c.agentType===o))==null?void 0:Ir.available)===!1,"aria-busy":Le!==null,"aria-disabled":Le!==null||!ye||((st=g.find(c=>c.id===ye))==null?void 0:st.canCreateSession)===!1,title:Le?"正在创建会话":ye&&((Ht=g.find(c=>c.id===ye))==null?void 0:Ht.canCreateSession)!==!1?"新建会话":"请先选择目录",onClick:wn,children:Le?e.jsxs(e.Fragment,{children:[e.jsx(dn,{size:16,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}),e.jsx("span",{children:"正在创建..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(ta,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"新建会话"})]})})})]}),G&&e.jsx(Jc,{message:Ec(G.session),anchor:G.anchor,mobile:ut,pending:kt,onCancel:()=>Ke(null),onConfirm:()=>void Jr()}),!ut&&e.jsx("div",{className:`app-sidebar-resizer${Ot?" is-dragging":""}`,onMouseDown:vr,style:{left:$t}}),L&&e.jsx("div",{onClick:()=>ae(!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:c=>c.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:c=>E(c.target.value),onKeyDown:c=>{c.key==="Escape"&&ae(!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:[tt&&nt&&nt.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[nt.length," 个结果"]}),tt&&nt&&nt.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!tt&&Jt.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),(nt??Jt.slice(0,fe)).map(c=>{const w=qe===c.id,R=gn(c),N=Zs({status:c.status,isRunning:R,needsInput:R&&mr.includes(c.id)});return e.jsx(si,{session:{id:c.id,title:c.title,visualState:N,statusLabel:Ys[N],occupiedExternally:c.occupancy==="owned-externally",canDelete:c.canDelete,active:w,child:!!c.parentSessionId,compatibility:c.compatibility},onSelect:()=>{const P=c.projectId&&g.some(te=>te.id===c.projectId)?c.projectId:null;je(Js(P,c.id)),ae(!1),ut&&bt(!1)},onDelete:P=>rt(c,P)},c.id)}),!tt&&Jt.length>fe&&e.jsx("button",{type:"button",onClick:()=>we(c=>c+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:"更多…"})]})]})})]}),wr&&Kt.createPortal(e.jsxs("div",{className:`app-action-notice is-${Ut}`,role:Ut==="error"?"alert":"status","aria-live":Ut==="error"?"assertive":"polite",children:[e.jsx("span",{className:"app-action-notice-mark","aria-hidden":"true",children:Ut==="success"?"✓":Ut==="info"?"i":"!"}),e.jsx("span",{children:wr})]}),document.body),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[Ge==="focus"&&e.jsx("button",{onClick:()=>$n("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(Tc,{activeAgentType:o,selectedProjectId:ye,selectedSessionId:qe,sessionTitle:Gr,sessionSummary:_e,workspacePath:yr,voiceCommand:Hr,onOpenSettings:yn,settingsOpen:H,onHideToBackground:()=>void Kn(),onToggleAppearance:br,appearanceOpen:Bt,hideToBackgroundTitle:Rt?`隐藏到后台(说“${ct}”唤醒)`:"隐藏到后台",onSessionCreated:async(c,w)=>{var N;const R=It.current;je({projectId:R,sessionId:c}),Yt.current&&(Yt.current=!1,Tt.current={sessionId:c,until:Date.now()+9e4},(N=window.agentApi)==null||N.wakeConversation(!0)),R&&await Ye(R,{pendingSession:w})},onSubSessionCreated:async c=>{await kr(c)},onSelectSession:c=>{xt(c)},onSubAgentEvent:c=>{c.type==="started"?Jn({type:"info",title:"子会话已启动",body:`${c.agentName}:${c.task.slice(0,60)}`,sessionId:c.subSessionId}):c.type==="completed"?Jn({type:"success",title:"子会话已完成",body:`${c.agentName}:${c.task.slice(0,60)}`,sessionId:c.subSessionId}):Jn({type:"error",title:"子会话出错",body:`${c.agentName}:${c.task.slice(0,60)}`,sessionId:c.subSessionId})},onMessageSent:(c,w)=>{C(R=>{const N={};for(const[P,te]of Object.entries(R))N[P]=te.map(Y=>Y.id===c?{...Y,title:w.slice(0,60)||Y.title}:Y);return N})},onRunComplete:async(c,w)=>{var te;const R=Tt.current,N=rc(R,w);Tt.current=N,N!==R&&((te=window.agentApi)==null||te.wakeConversation(!0));const P=c||ye;P&&await Ye(P,{refresh:!0,background:!0})}})})]}),H&&Kt.createPortal(e.jsx("div",{onClick:()=>he(!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:c=>c.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:nn.map(c=>e.jsx("button",{onClick:()=>$r(c.id),className:`settings-tab ${ue===c.id?"settings-tab-active":""}`,children:c.label},c.id))}),e.jsx("button",{onClick:()=>he(!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:[ue==="settings"&&e.jsx(Lc,{}),ue==="mcp"&&e.jsx(Bc,{}),ue==="memory"&&e.jsx(Fc,{}),ue==="skill"&&e.jsx(Oc,{}),ue==="agent"&&e.jsx(Hc,{}),ue==="lsp"&&e.jsx(Qc,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),Bt&&mn&&Kt.createPortal(e.jsx("div",{onClick:()=>xn(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:c=>c.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(mn.right-320,window.innerWidth-332)),top:mn.bottom+8,width:320,maxHeight:`calc(100vh - ${mn.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:sl.map(c=>e.jsxs("button",{onClick:()=>fn(c.id),className:`appearance-choice ${Dt===c.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${c.preview[0]} 55%, ${c.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:Dt===c.id?600:400},children:c.label}),Dt===c.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"})})]},c.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:il.map(c=>e.jsx("button",{onClick:()=>$n(c.id),title:c.description,className:`appearance-segment ${Ge===c.id?"appearance-segment-active":""}`,children:c.label},c.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:hr,onChange:c=>Un(c.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:Rt,onChange:c=>gr(c.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:ct,onChange:c=>On(c.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(iu,{open:q,onCancel:()=>K(!1),onConfirm:async c=>{await jn(c),K(!1)}}),e.jsx(Kc,{trigger:Vn,heardText:qr}),re.length>0&&Kt.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:re.map(c=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${c.type==="error"?"rgba(220,38,38,0.25)":c.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${c.type==="error"?"var(--danger)":c.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:c.type==="error"?"var(--danger)":c.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[c.type==="error"?"✕":c.type==="success"?"✓":"◎"," ",c.title]}),e.jsx("button",{onClick:()=>tn(c.id),title:"关闭",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:14,lineHeight:1,padding:"2px 4px",borderRadius:4,transition:"color 0.15s"},onMouseEnter:w=>w.currentTarget.style.color="var(--text-primary)",onMouseLeave:w=>w.currentTarget.style.color="var(--text-muted)",children:"×"})]}),e.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)",lineHeight:1.5,wordBreak:"break-all"},children:c.body}),c.sessionId&&e.jsx("button",{onClick:()=>{xt(c.sessionId),tn(c.id)},style:{marginTop:8,padding:"4px 10px",fontSize:11,fontWeight:500,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid var(--border-glow)",borderRadius:6,cursor:"pointer",transition:"background 0.15s",WebkitAppRegion:"no-drag"},onMouseEnter:w=>w.currentTarget.style.background="var(--accent-glow)",onMouseLeave:w=>w.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},c.id))}),document.body)]})}export{mu as default};