agentroam-runtime-darwin-arm64 0.2.0-preview.21 → 0.2.0-preview.23

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 (156) hide show
  1. package/manifest.json +2 -2
  2. package/package.json +1 -1
  3. package/runtime/.next/BUILD_ID +1 -1
  4. package/runtime/.next/app-build-manifest.json +6 -6
  5. package/runtime/.next/app-path-routes-manifest.json +1 -1
  6. package/runtime/.next/build-manifest.json +3 -3
  7. package/runtime/.next/prerender-manifest.json +1 -1
  8. package/runtime/.next/required-server-files.json +1 -1
  9. package/runtime/.next/server/app/_not-found/page.js +1 -1
  10. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  11. package/runtime/.next/server/app/_not-found.html +1 -1
  12. package/runtime/.next/server/app/_not-found.rsc +1 -1
  13. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  14. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  15. package/runtime/.next/server/app/api/agent/harness/status/route.js +1 -1
  16. package/runtime/.next/server/app/api/agent/model/route.js +1 -1
  17. package/runtime/.next/server/app/api/agent/models/route.js +1 -1
  18. package/runtime/.next/server/app/api/agent/run/route.js +1 -1
  19. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  20. package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
  21. package/runtime/.next/server/app/api/agent/stream/route.js +2 -2
  22. package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
  23. package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
  24. package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
  25. package/runtime/.next/server/app/api/business/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 -1
  44. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  45. package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js +1 -1
  46. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  47. package/runtime/.next/server/app/api/settings/route.js +1 -1
  48. package/runtime/.next/server/app/api/skills/route.js +1 -1
  49. package/runtime/.next/server/app/api/tools/route.js +1 -1
  50. package/runtime/.next/server/app/api/update/check/route.js +1 -1
  51. package/runtime/.next/server/app/api/update/install/route.js +1 -1
  52. package/runtime/.next/server/app/api/update/status/route.js +1 -1
  53. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  54. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  55. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  56. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  57. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  58. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  59. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  60. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  61. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  62. package/runtime/.next/server/app/web/page.js +2 -2
  63. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  64. package/runtime/.next/server/app/web.html +1 -1
  65. package/runtime/.next/server/app/web.rsc +3 -3
  66. package/runtime/.next/server/app-paths-manifest.json +19 -19
  67. package/runtime/.next/server/chunks/1322.js +1 -1
  68. package/runtime/.next/server/chunks/2083.js +1 -1
  69. package/runtime/.next/server/chunks/5303.js +1 -1
  70. package/runtime/.next/server/middleware-build-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/pages-manifest.json +1 -1
  74. package/runtime/.next/server/server-reference-manifest.json +1 -1
  75. package/runtime/.next/static/chunks/app/web/{error-9b5f82c29dc27335.js → error-828d278147a0619d.js} +1 -1
  76. package/runtime/.next/static/chunks/app/web/{page-16895961b998f8df.js → page-93b87fd495171494.js} +1 -1
  77. package/runtime/.next/static/chunks/{main-app-e3fd18ce9c4c0d03.js → main-app-07d67f2d4e96ecb8.js} +1 -1
  78. package/runtime/lib/remote-control/remote-authorization.mjs +65 -12
  79. package/runtime/lib/remote-control/webrtc-video.mjs +12 -3
  80. package/runtime/native/AgentRoam Remote Desktop.app/Contents/MacOS/agentroam-remote-desktop +0 -0
  81. package/runtime/node_modules/.package-lock.json +84 -84
  82. package/runtime/node_modules/@agent/core/dist/domain/browser-live/BrowserLiveRegistry.d.ts +43 -0
  83. package/runtime/node_modules/@agent/core/dist/domain/browser-live/BrowserLiveRegistry.test.d.ts +2 -0
  84. package/runtime/node_modules/@agent/core/dist/domain/browser-live/entities.d.ts +57 -0
  85. package/runtime/node_modules/@agent/core/dist/domain/live-view/live-view-registry.d.ts.map +1 -1
  86. package/runtime/node_modules/@agent/core/dist/index.js +4 -2
  87. package/runtime/node_modules/@agent/core/dist/index.js.map +3 -3
  88. package/runtime/package-lock.json +189 -189
  89. package/runtime/webapp/dist/assets/App-C0GaUX7E.js +381 -0
  90. package/runtime/webapp/dist/assets/{abnfDiagram-VCTEODGH-BNxk5qEZ.js → abnfDiagram-VCTEODGH-DFIVS5-b.js} +1 -1
  91. package/runtime/webapp/dist/assets/{arc-7MQbjMvc.js → arc-BR_jY5YA.js} +1 -1
  92. package/runtime/webapp/dist/assets/{architectureDiagram-5GKGNRK7-Dhg4Rz1D.js → architectureDiagram-5GKGNRK7-B_RjH8A7.js} +1 -1
  93. package/runtime/webapp/dist/assets/{blockDiagram-I7D4REHJ-DeJHr92S.js → blockDiagram-I7D4REHJ-BS7yaS6P.js} +1 -1
  94. package/runtime/webapp/dist/assets/{c4Diagram-7LVT6UL2-RA8xRbEK.js → c4Diagram-7LVT6UL2-CSFzzphk.js} +1 -1
  95. package/runtime/webapp/dist/assets/channel-D_GjJ9-f.js +1 -0
  96. package/runtime/webapp/dist/assets/{chunk-2Q5K7J3B-CzoEDy2v.js → chunk-2Q5K7J3B-lxf-31fr.js} +1 -1
  97. package/runtime/webapp/dist/assets/{chunk-5VM5RSS4-IasmnKPT.js → chunk-5VM5RSS4-CealgGAH.js} +1 -1
  98. package/runtime/webapp/dist/assets/{chunk-F27PBJKO-ClQmWB2a.js → chunk-F27PBJKO-BVUWtnPQ.js} +1 -1
  99. package/runtime/webapp/dist/assets/{chunk-IMKFNOWR-BeWBx5Wn.js → chunk-IMKFNOWR-C9CDXZmG.js} +1 -1
  100. package/runtime/webapp/dist/assets/{chunk-JWPE2WC7-TcEEZ4Dp.js → chunk-JWPE2WC7-CBIKc-82.js} +1 -1
  101. package/runtime/webapp/dist/assets/{chunk-POPQ4Y6H-DuWXzzSb.js → chunk-POPQ4Y6H-H46jF2zC.js} +1 -1
  102. package/runtime/webapp/dist/assets/{chunk-SVP7TREG-D2X9Pa1W.js → chunk-SVP7TREG-BWLkgj_W.js} +1 -1
  103. package/runtime/webapp/dist/assets/{chunk-TICWLB2K-D_-XYQ_R.js → chunk-TICWLB2K-D4lbsBHo.js} +1 -1
  104. package/runtime/webapp/dist/assets/{chunk-XXDRQBXY-B2mHmyk9.js → chunk-XXDRQBXY-DixiVi8X.js} +1 -1
  105. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-BbKxNRrL.js +1 -0
  106. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-BbKxNRrL.js +1 -0
  107. package/runtime/webapp/dist/assets/{cose-bilkent-JH36ORCC-OmMALi3i.js → cose-bilkent-JH36ORCC-DApgY-7v.js} +1 -1
  108. package/runtime/webapp/dist/assets/{cynefin-OW5HDTMX-BVhxjnGZ.js → cynefin-OW5HDTMX-wPkyEnRo.js} +1 -1
  109. package/runtime/webapp/dist/assets/{cynefinDiagram-5FMLGOSQ-8EafeZWa.js → cynefinDiagram-5FMLGOSQ-BL3nX8zr.js} +1 -1
  110. package/runtime/webapp/dist/assets/{dagre-GXQ25YYZ-BlMjveyN.js → dagre-GXQ25YYZ-C-ST5Gq6.js} +1 -1
  111. package/runtime/webapp/dist/assets/{diagram-S7CK7UJ4-BTgDeYAz.js → diagram-S7CK7UJ4-1Uf0VNoU.js} +1 -1
  112. package/runtime/webapp/dist/assets/{diagram-UQ7AKVKN-9m-QUpEs.js → diagram-UQ7AKVKN-BqQU5Gdv.js} +1 -1
  113. package/runtime/webapp/dist/assets/{diagram-VSXAHHWV-BYWenf8W.js → diagram-VSXAHHWV-C59hTOGw.js} +1 -1
  114. package/runtime/webapp/dist/assets/{diagram-VX7I27RA-DQ-PRQyX.js → diagram-VX7I27RA-9Q55OM5Y.js} +1 -1
  115. package/runtime/webapp/dist/assets/{diagram-Z3DM3KII-BFCpyvaL.js → diagram-Z3DM3KII-CynlxwLb.js} +1 -1
  116. package/runtime/webapp/dist/assets/{ebnfDiagram-PWID7BFC-Ds9oV_wz.js → ebnfDiagram-PWID7BFC-Clg7fTnt.js} +1 -1
  117. package/runtime/webapp/dist/assets/{erDiagram-RLTQ6QDP-ncaaStop.js → erDiagram-RLTQ6QDP-BRtMTjkq.js} +1 -1
  118. package/runtime/webapp/dist/assets/{flowDiagram-HODETNUW-wL7U3M2L.js → flowDiagram-HODETNUW-1NtZ9wGO.js} +1 -1
  119. package/runtime/webapp/dist/assets/{ganttDiagram-EL5Y4UJY-CVZIk8qz.js → ganttDiagram-EL5Y4UJY-BqtMVkoY.js} +1 -1
  120. package/runtime/webapp/dist/assets/{gitGraphDiagram-WWUBYQGX-CGjtUEFY.js → gitGraphDiagram-WWUBYQGX-D-ugp1Bz.js} +1 -1
  121. package/runtime/webapp/dist/assets/{index-CixxJ3A7.js → index-Cg-anTNr.js} +29 -29
  122. package/runtime/webapp/dist/assets/{infoDiagram-27XIBGKW-BqTzY6Bv.js → infoDiagram-27XIBGKW-BbmiUqFV.js} +1 -1
  123. package/runtime/webapp/dist/assets/{ishikawaDiagram-5VMMS53U-9AARy1zU.js → ishikawaDiagram-5VMMS53U-DvsCcWwa.js} +1 -1
  124. package/runtime/webapp/dist/assets/{journeyDiagram-3NMN7TZE-D3w-levY.js → journeyDiagram-3NMN7TZE-yNHLBbVt.js} +1 -1
  125. package/runtime/webapp/dist/assets/{kanban-definition-UXKFOSKX-CNvdBbcg.js → kanban-definition-UXKFOSKX-C17XKWBo.js} +1 -1
  126. package/runtime/webapp/dist/assets/{layout-l0aDluv6.js → layout-Dhqc3tGq.js} +1 -1
  127. package/runtime/webapp/dist/assets/{linear-BlLgYv8s.js → linear-C2_mlhLl.js} +1 -1
  128. package/runtime/webapp/dist/assets/{mermaid.core-UNYsT27K.js → mermaid.core-CjC7QuvE.js} +5 -5
  129. package/runtime/webapp/dist/assets/{mindmap-definition-YA3MSWOX-BiVsBQL9.js → mindmap-definition-YA3MSWOX-D7AKW2qI.js} +1 -1
  130. package/runtime/webapp/dist/assets/{pegDiagram-XKGWAZYB-kr19ZOFB.js → pegDiagram-XKGWAZYB-BAI26fj8.js} +1 -1
  131. package/runtime/webapp/dist/assets/{pieDiagram-E7YTZNPT-BKWCGLlM.js → pieDiagram-E7YTZNPT-C_4G2czx.js} +1 -1
  132. package/runtime/webapp/dist/assets/{quadrantDiagram-AXDQQJYC-B1oUT2Jo.js → quadrantDiagram-AXDQQJYC-BhOZnXFN.js} +1 -1
  133. package/runtime/webapp/dist/assets/{railroadDiagram-O6MQD6OU-HSe2vXxQ.js → railroadDiagram-O6MQD6OU-760zGjdr.js} +1 -1
  134. package/runtime/webapp/dist/assets/{requirementDiagram-BXWQKSXE-Cy8adj_C.js → requirementDiagram-BXWQKSXE-D0-agCrc.js} +1 -1
  135. package/runtime/webapp/dist/assets/{sankeyDiagram-P5KCCOFB-tnBEmP5l.js → sankeyDiagram-P5KCCOFB-CsHjbmcp.js} +1 -1
  136. package/runtime/webapp/dist/assets/{sequenceDiagram-WJ2MYXX4-DvOTKmyz.js → sequenceDiagram-WJ2MYXX4-Ccp7FnLK.js} +1 -1
  137. package/runtime/webapp/dist/assets/{sizeCapture-INFHLROL-Da7A6hqr.js → sizeCapture-INFHLROL-DFCk9Vjd.js} +1 -1
  138. package/runtime/webapp/dist/assets/{stateDiagram-D77RDMKH-BU17k_M-.js → stateDiagram-D77RDMKH-tFA-WlZT.js} +1 -1
  139. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-CA4qjX_b.js +1 -0
  140. package/runtime/webapp/dist/assets/{swimlanes-42K2YHIH-DZZPRxnW.js → swimlanes-42K2YHIH-Bh-owCha.js} +1 -1
  141. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-DrldJDwD.js +8 -0
  142. package/runtime/webapp/dist/assets/{timeline-definition-24CTP7MA-26Xh93Et.js → timeline-definition-24CTP7MA-D5CQ3vgW.js} +1 -1
  143. package/runtime/webapp/dist/assets/{vennDiagram-4TSXK5OY-Q4-BkJH1.js → vennDiagram-4TSXK5OY-1m-k4Zip.js} +1 -1
  144. package/runtime/webapp/dist/assets/{wardleyDiagram-VM6X3IG4-DlUP-PlT.js → wardleyDiagram-VM6X3IG4-C5agAk3M.js} +1 -1
  145. package/runtime/webapp/dist/assets/{web-DWyw2SAG.js → web-CzXjoC1h.js} +1 -1
  146. package/runtime/webapp/dist/assets/{web-ueoOhAeL.js → web-DseRebF6.js} +1 -1
  147. package/runtime/webapp/dist/assets/{xychartDiagram-S5SC5T6Z-BQZRjKtR.js → xychartDiagram-S5SC5T6Z-EEKnPDSd.js} +1 -1
  148. package/runtime/webapp/dist/index.html +1 -1
  149. package/runtime/webapp/dist/assets/App-Cso_5v1O.js +0 -381
  150. package/runtime/webapp/dist/assets/channel-AsHr5ZE0.js +0 -1
  151. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-BZj1pbnq.js +0 -1
  152. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-BZj1pbnq.js +0 -1
  153. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-BROH63Ny.js +0 -1
  154. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-B4lr9wuD.js +0 -8
  155. /package/runtime/.next/static/{6OR2fRy79-A-DrqiN3FNa → ZqeC5NkIDDyPiS-mzOs28}/_buildManifest.js +0 -0
  156. /package/runtime/.next/static/{6OR2fRy79-A-DrqiN3FNa → ZqeC5NkIDDyPiS-mzOs28}/_ssgManifest.js +0 -0
@@ -1,381 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./mermaid.core-UNYsT27K.js","./index-CixxJ3A7.js","./index-DwNgokHq.css"])))=>i.map(i=>d[i]);
2
- var Ui=t=>{throw TypeError(t)};var Ic=(t,n,r)=>n.has(t)||Ui("Cannot "+r);var qi=(t,n,r)=>n.has(t)?Ui("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,r);var Vi=(t,n,r)=>(Ic(t,n,"access private method"),r);import{r as l,R as Cc,j as e,_ as Rc,b as Yt,d as Xa,B as Ac,i as Jn,O as Ki,u as St,e as Mc,S as Ec,L as Tc}from"./index-CixxJ3A7.js";/**
3
- * @license lucide-react v0.468.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const Nc=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Za=(...t)=>t.filter((n,r,s)=>!!n&&n.trim()!==""&&s.indexOf(n)===r).join(" ").trim();/**
8
- * @license lucide-react v0.468.0 - ISC
9
- *
10
- * This source code is licensed under the ISC license.
11
- * See the LICENSE file in the root directory of this source tree.
12
- */var zc={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"};/**
13
- * @license lucide-react v0.468.0 - ISC
14
- *
15
- * This source code is licensed under the ISC license.
16
- * See the LICENSE file in the root directory of this source tree.
17
- */const Lc=l.forwardRef(({color:t="currentColor",size:n=24,strokeWidth:r=2,absoluteStrokeWidth:s,className:o="",children:a,iconNode:c,...d},u)=>l.createElement("svg",{ref:u,...zc,width:n,height:n,stroke:t,strokeWidth:s?Number(r)*24/Number(n):r,className:Za("lucide",o),...d},[...c.map(([h,g])=>l.createElement(h,g)),...Array.isArray(a)?a:[a]]));/**
18
- * @license lucide-react v0.468.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const se=(t,n)=>{const r=l.forwardRef(({className:s,...o},a)=>l.createElement(Lc,{ref:a,iconNode:n,className:Za(`lucide-${Nc(t)}`,s),...o}));return r.displayName=`${t}`,r};/**
23
- * @license lucide-react v0.468.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */const Gi=se("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);/**
28
- * @license lucide-react v0.468.0 - ISC
29
- *
30
- * This source code is licensed under the ISC license.
31
- * See the LICENSE file in the root directory of this source tree.
32
- */const _c=se("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
33
- * @license lucide-react v0.468.0 - ISC
34
- *
35
- * This source code is licensed under the ISC license.
36
- * See the LICENSE file in the root directory of this source tree.
37
- */const Pc=se("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"}]]);/**
38
- * @license lucide-react v0.468.0 - ISC
39
- *
40
- * This source code is licensed under the ISC license.
41
- * See the LICENSE file in the root directory of this source tree.
42
- */const Xo=se("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"}]]);/**
43
- * @license lucide-react v0.468.0 - ISC
44
- *
45
- * This source code is licensed under the ISC license.
46
- * See the LICENSE file in the root directory of this source tree.
47
- */const Fr=se("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
48
- * @license lucide-react v0.468.0 - ISC
49
- *
50
- * This source code is licensed under the ISC license.
51
- * See the LICENSE file in the root directory of this source tree.
52
- */const Wc=se("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
53
- * @license lucide-react v0.468.0 - ISC
54
- *
55
- * This source code is licensed under the ISC license.
56
- * See the LICENSE file in the root directory of this source tree.
57
- */const Ur=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
58
- * @license lucide-react v0.468.0 - ISC
59
- *
60
- * This source code is licensed under the ISC license.
61
- * See the LICENSE file in the root directory of this source tree.
62
- */const Ja=se("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"}]]);/**
63
- * @license lucide-react v0.468.0 - ISC
64
- *
65
- * This source code is licensed under the ISC license.
66
- * See the LICENSE file in the root directory of this source tree.
67
- */const Dc=se("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"}]]);/**
68
- * @license lucide-react v0.468.0 - ISC
69
- *
70
- * This source code is licensed under the ISC license.
71
- * See the LICENSE file in the root directory of this source tree.
72
- */const go=se("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"}]]);/**
73
- * @license lucide-react v0.468.0 - ISC
74
- *
75
- * This source code is licensed under the ISC license.
76
- * See the LICENSE file in the root directory of this source tree.
77
- */const Bc=se("CornerUpRight",[["polyline",{points:"15 14 20 9 15 4",key:"1tbx3s"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]);/**
78
- * @license lucide-react v0.468.0 - ISC
79
- *
80
- * This source code is licensed under the ISC license.
81
- * See the LICENSE file in the root directory of this source tree.
82
- */const $c=se("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"}]]);/**
83
- * @license lucide-react v0.468.0 - ISC
84
- *
85
- * This source code is licensed under the ISC license.
86
- * See the LICENSE file in the root directory of this source tree.
87
- */const el=se("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
88
- * @license lucide-react v0.468.0 - ISC
89
- *
90
- * This source code is licensed under the ISC license.
91
- * See the LICENSE file in the root directory of this source tree.
92
- */const Oc=se("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
93
- * @license lucide-react v0.468.0 - ISC
94
- *
95
- * This source code is licensed under the ISC license.
96
- * See the LICENSE file in the root directory of this source tree.
97
- */const Fc=se("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"}]]);/**
98
- * @license lucide-react v0.468.0 - ISC
99
- *
100
- * This source code is licensed under the ISC license.
101
- * See the LICENSE file in the root directory of this source tree.
102
- */const Hc=se("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"}]]);/**
103
- * @license lucide-react v0.468.0 - ISC
104
- *
105
- * This source code is licensed under the ISC license.
106
- * See the LICENSE file in the root directory of this source tree.
107
- */const Uc=se("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"}]]);/**
108
- * @license lucide-react v0.468.0 - ISC
109
- *
110
- * This source code is licensed under the ISC license.
111
- * See the LICENSE file in the root directory of this source tree.
112
- */const qc=se("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"}]]);/**
113
- * @license lucide-react v0.468.0 - ISC
114
- *
115
- * This source code is licensed under the ISC license.
116
- * See the LICENSE file in the root directory of this source tree.
117
- */const Vc=se("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"}]]);/**
118
- * @license lucide-react v0.468.0 - ISC
119
- *
120
- * This source code is licensed under the ISC license.
121
- * See the LICENSE file in the root directory of this source tree.
122
- */const Kc=se("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"}]]);/**
123
- * @license lucide-react v0.468.0 - ISC
124
- *
125
- * This source code is licensed under the ISC license.
126
- * See the LICENSE file in the root directory of this source tree.
127
- */const qs=se("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"}]]);/**
128
- * @license lucide-react v0.468.0 - ISC
129
- *
130
- * This source code is licensed under the ISC license.
131
- * See the LICENSE file in the root directory of this source tree.
132
- */const Gc=se("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"}]]);/**
133
- * @license lucide-react v0.468.0 - ISC
134
- *
135
- * This source code is licensed under the ISC license.
136
- * See the LICENSE file in the root directory of this source tree.
137
- */const Qc=se("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"}]]);/**
138
- * @license lucide-react v0.468.0 - ISC
139
- *
140
- * This source code is licensed under the ISC license.
141
- * See the LICENSE file in the root directory of this source tree.
142
- */const Yc=se("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"}]]);/**
143
- * @license lucide-react v0.468.0 - ISC
144
- *
145
- * This source code is licensed under the ISC license.
146
- * See the LICENSE file in the root directory of this source tree.
147
- */const Qi=se("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"}]]);/**
148
- * @license lucide-react v0.468.0 - ISC
149
- *
150
- * This source code is licensed under the ISC license.
151
- * See the LICENSE file in the root directory of this source tree.
152
- */const Xc=se("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);/**
153
- * @license lucide-react v0.468.0 - ISC
154
- *
155
- * This source code is licensed under the ISC license.
156
- * See the LICENSE file in the root directory of this source tree.
157
- */const Zc=se("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"}]]);/**
158
- * @license lucide-react v0.468.0 - ISC
159
- *
160
- * This source code is licensed under the ISC license.
161
- * See the LICENSE file in the root directory of this source tree.
162
- */const xo=se("Keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]);/**
163
- * @license lucide-react v0.468.0 - ISC
164
- *
165
- * This source code is licensed under the ISC license.
166
- * See the LICENSE file in the root directory of this source tree.
167
- */const Jc=se("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/**
168
- * @license lucide-react v0.468.0 - ISC
169
- *
170
- * This source code is licensed under the ISC license.
171
- * See the LICENSE file in the root directory of this source tree.
172
- */const ed=se("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"}]]);/**
173
- * @license lucide-react v0.468.0 - ISC
174
- *
175
- * This source code is licensed under the ISC license.
176
- * See the LICENSE file in the root directory of this source tree.
177
- */const td=se("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"}]]);/**
178
- * @license lucide-react v0.468.0 - ISC
179
- *
180
- * This source code is licensed under the ISC license.
181
- * See the LICENSE file in the root directory of this source tree.
182
- */const Nt=se("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
183
- * @license lucide-react v0.468.0 - ISC
184
- *
185
- * This source code is licensed under the ISC license.
186
- * See the LICENSE file in the root directory of this source tree.
187
- */const nd=se("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"}]]);/**
188
- * @license lucide-react v0.468.0 - ISC
189
- *
190
- * This source code is licensed under the ISC license.
191
- * See the LICENSE file in the root directory of this source tree.
192
- */const rd=se("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
193
- * @license lucide-react v0.468.0 - ISC
194
- *
195
- * This source code is licensed under the ISC license.
196
- * See the LICENSE file in the root directory of this source tree.
197
- */const sd=se("Maximize",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]);/**
198
- * @license lucide-react v0.468.0 - ISC
199
- *
200
- * This source code is licensed under the ISC license.
201
- * See the LICENSE file in the root directory of this source tree.
202
- */const od=se("Minimize2",[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
203
- * @license lucide-react v0.468.0 - ISC
204
- *
205
- * This source code is licensed under the ISC license.
206
- * See the LICENSE file in the root directory of this source tree.
207
- */const id=se("Minimize",[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]);/**
208
- * @license lucide-react v0.468.0 - ISC
209
- *
210
- * This source code is licensed under the ISC license.
211
- * See the LICENSE file in the root directory of this source tree.
212
- */const mo=se("MonitorUp",[["path",{d:"m9 10 3-3 3 3",key:"11gsxs"}],["path",{d:"M12 13V7",key:"h0r20n"}],["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}]]);/**
213
- * @license lucide-react v0.468.0 - ISC
214
- *
215
- * This source code is licensed under the ISC license.
216
- * See the LICENSE file in the root directory of this source tree.
217
- */const ad=se("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
218
- * @license lucide-react v0.468.0 - ISC
219
- *
220
- * This source code is licensed under the ISC license.
221
- * See the LICENSE file in the root directory of this source tree.
222
- */const ld=se("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
223
- * @license lucide-react v0.468.0 - ISC
224
- *
225
- * This source code is licensed under the ISC license.
226
- * See the LICENSE file in the root directory of this source tree.
227
- */const cd=se("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"}]]);/**
228
- * @license lucide-react v0.468.0 - ISC
229
- *
230
- * This source code is licensed under the ISC license.
231
- * See the LICENSE file in the root directory of this source tree.
232
- */const dd=se("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"}]]);/**
233
- * @license lucide-react v0.468.0 - ISC
234
- *
235
- * This source code is licensed under the ISC license.
236
- * See the LICENSE file in the root directory of this source tree.
237
- */const ud=se("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);/**
238
- * @license lucide-react v0.468.0 - ISC
239
- *
240
- * This source code is licensed under the ISC license.
241
- * See the LICENSE file in the root directory of this source tree.
242
- */const tl=se("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"}]]);/**
243
- * @license lucide-react v0.468.0 - ISC
244
- *
245
- * This source code is licensed under the ISC license.
246
- * See the LICENSE file in the root directory of this source tree.
247
- */const pd=se("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);/**
248
- * @license lucide-react v0.468.0 - ISC
249
- *
250
- * This source code is licensed under the ISC license.
251
- * See the LICENSE file in the root directory of this source tree.
252
- */const Ho=se("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
253
- * @license lucide-react v0.468.0 - ISC
254
- *
255
- * This source code is licensed under the ISC license.
256
- * See the LICENSE file in the root directory of this source tree.
257
- */const fd=se("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"}]]);/**
258
- * @license lucide-react v0.468.0 - ISC
259
- *
260
- * This source code is licensed under the ISC license.
261
- * See the LICENSE file in the root directory of this source tree.
262
- */const Zo=se("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"}]]);/**
263
- * @license lucide-react v0.468.0 - ISC
264
- *
265
- * This source code is licensed under the ISC license.
266
- * See the LICENSE file in the root directory of this source tree.
267
- */const nl=se("RotateCcw",[["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"}]]);/**
268
- * @license lucide-react v0.468.0 - ISC
269
- *
270
- * This source code is licensed under the ISC license.
271
- * See the LICENSE file in the root directory of this source tree.
272
- */const rl=se("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
273
- * @license lucide-react v0.468.0 - ISC
274
- *
275
- * This source code is licensed under the ISC license.
276
- * See the LICENSE file in the root directory of this source tree.
277
- */const hd=se("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
278
- * @license lucide-react v0.468.0 - ISC
279
- *
280
- * This source code is licensed under the ISC license.
281
- * See the LICENSE file in the root directory of this source tree.
282
- */const gd=se("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"}]]);/**
283
- * @license lucide-react v0.468.0 - ISC
284
- *
285
- * This source code is licensed under the ISC license.
286
- * See the LICENSE file in the root directory of this source tree.
287
- */const xd=se("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"}]]);/**
288
- * @license lucide-react v0.468.0 - ISC
289
- *
290
- * This source code is licensed under the ISC license.
291
- * See the LICENSE file in the root directory of this source tree.
292
- */const md=se("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
293
- * @license lucide-react v0.468.0 - ISC
294
- *
295
- * This source code is licensed under the ISC license.
296
- * See the LICENSE file in the root directory of this source tree.
297
- */const bo=se("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"}]]);/**
298
- * @license lucide-react v0.468.0 - ISC
299
- *
300
- * This source code is licensed under the ISC license.
301
- * See the LICENSE file in the root directory of this source tree.
302
- */const xs=se("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"}]]);/**
303
- * @license lucide-react v0.468.0 - ISC
304
- *
305
- * This source code is licensed under the ISC license.
306
- * See the LICENSE file in the root directory of this source tree.
307
- */const bd=se("Unplug",[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]]);/**
308
- * @license lucide-react v0.468.0 - ISC
309
- *
310
- * This source code is licensed under the ISC license.
311
- * See the LICENSE file in the root directory of this source tree.
312
- */const yd=se("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
313
- * @license lucide-react v0.468.0 - ISC
314
- *
315
- * This source code is licensed under the ISC license.
316
- * See the LICENSE file in the root directory of this source tree.
317
- */const vd=se("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"}]]);/**
318
- * @license lucide-react v0.468.0 - ISC
319
- *
320
- * This source code is licensed under the ISC license.
321
- * See the LICENSE file in the root directory of this source tree.
322
- */const wd=se("Workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]);/**
323
- * @license lucide-react v0.468.0 - ISC
324
- *
325
- * This source code is licensed under the ISC license.
326
- * See the LICENSE file in the root directory of this source tree.
327
- */const sl=se("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"}]]);/**
328
- * @license lucide-react v0.468.0 - ISC
329
- *
330
- * This source code is licensed under the ISC license.
331
- * See the LICENSE file in the root directory of this source tree.
332
- */const qr=se("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/**
333
- * @license lucide-react v0.468.0 - ISC
334
- *
335
- * This source code is licensed under the ISC license.
336
- * See the LICENSE file in the root directory of this source tree.
337
- */const ol=se("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);/**
338
- * @license lucide-react v0.468.0 - ISC
339
- *
340
- * This source code is licensed under the ISC license.
341
- * See the LICENSE file in the root directory of this source tree.
342
- */const il=se("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function jd(t,n){if(Object.is(t,n))return!0;if(typeof t!="object"||t===null||typeof n!="object"||n===null)return!1;if(t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(const[s,o]of t)if(!Object.is(o,n.get(s)))return!1;return!0}if(t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(const s of t)if(!n.has(s))return!1;return!0}const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const s of r)if(!Object.prototype.hasOwnProperty.call(n,s)||!Object.is(t[s],n[s]))return!1;return!0}const{useRef:kd}=Cc;function Sd(t){const n=kd();return r=>{const s=t(r);return jd(n.current,s)?n.current:n.current=s}}const Id="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",Cd="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 Jo({agentType:t,size:n=16,className:r}){return t==="customer-agent"?e.jsxs("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"50 48 180 180",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M76 187V90Q76 74 92 74H188Q204 74 204 90V187",stroke:"currentColor",strokeWidth:"18",strokeLinecap:"round"}),e.jsx("path",{d:"m108 116 26 24-26 24m47 0h22M100 207h80",stroke:"currentColor",strokeWidth:"14",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("circle",{cx:"204",cy:"207",r:"11",fill:"currentColor"})]}):t==="codex"?e.jsx("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"29.487 29.964 121.035 119.954","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:Cd})}):t==="claude-code"?e.jsx("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:Id})}):e.jsx("svg",{className:r,"data-agent-icon":t,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M22 24H2V0h20zM17 4.8H7v14.4h10z",fillRule:"evenodd"})})}let Yi=Promise.resolve(),Rd=0;function al(t,n=!1){const r=Yi.then(async()=>{if(t.length>5e4)throw new Error("图表源码过长,请查看源码");const s=(await Rc(async()=>{const{default:a}=await import("./mermaid.core-UNYsT27K.js").then(c=>c.cb);return{default:a}},__vite__mapDeps([0,1,2]),import.meta.url)).default;s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",suppressErrorRendering:!0,maxTextSize:5e4,maxEdges:500,...n?{htmlLabels:!1,flowchart:{htmlLabels:!1}}:{},secure:["secure","securityLevel","startOnLoad","maxTextSize","maxEdges","suppressErrorRendering",...n?["htmlLabels","flowchart"]:[]]});const o=document.createElement("div");o.style.cssText="position:fixed;left:-100000px;top:0;visibility:hidden;pointer-events:none",document.body.appendChild(o);try{const{svg:a}=await s.render(`agentroam-mermaid-${++Rd}`,t,o);return a}finally{o.remove()}});return Yi=r.catch(()=>{}),r}function ll(t){var r;const n=(r=t.match(/<svg\b[^>]*\bviewBox=["']([^"']+)["']/i))==null?void 0:r[1].trim().split(/[\s,]+/).map(Number);return!n||n.length!==4||!n.every(Number.isFinite)||n[2]<=0||n[3]<=0?{width:640,height:480}:{width:n[2],height:n[3]}}function Ad(t,n,r){return Math.max(.001,Math.min(1,Math.max(1,n)/t.width,r===void 0?1:Math.max(1,r)/t.height))}function Xi(t,n){return Math.min(4,Math.max(Math.min(.1,n),t))}function Md(t){const n=Math.min(2,4096/t.width,4096/t.height);return{width:Math.max(1,Math.round(t.width*n)),height:Math.max(1,Math.round(t.height*n))}}async function Ed(t){const n=await al(t,!0),r=new DOMParser().parseFromString(n,"image/svg+xml");if(r.querySelector("parsererror, foreignObject"))throw new Error("此图包含暂不支持导出的内容,请查看源码。");if([...r.querySelectorAll("image")].some(c=>!String(c.getAttribute("href")??c.getAttribute("xlink:href")??"").startsWith("data:")))throw new Error("此图包含外部图片,暂不能导出 PNG。");const s=Md(ll(n)),o=r.documentElement;o.setAttribute("xmlns","http://www.w3.org/2000/svg"),o.setAttribute("width",String(s.width)),o.setAttribute("height",String(s.height)),o.style.maxWidth="none",o.style.width=`${s.width}px`,o.style.height=`${s.height}px`;const a=URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(o)],{type:"image/svg+xml;charset=utf-8"}));try{const c=new Image;await new Promise((h,g)=>{c.onload=()=>h(),c.onerror=()=>g(new Error("图表图片转换失败,请重试。")),c.src=a});const d=window.document.createElement("canvas");d.width=s.width,d.height=s.height;const u=d.getContext("2d");if(!u)throw new Error("当前浏览器无法导出图片。");return u.fillStyle="#fff",u.fillRect(0,0,s.width,s.height),u.drawImage(c,0,0,s.width,s.height),await new Promise((h,g)=>{d.toBlob(y=>y?h(y):g(new Error("图片导出失败,请重试。")),"image/png")})}finally{URL.revokeObjectURL(a)}}function Zi({label:t,onClose:n,children:r}){const s=l.useRef(null);return l.useEffect(()=>{var c,d;const o=document.activeElement,a=document.body.style.overflow;return document.body.style.overflow="hidden",(d=(c=s.current)==null?void 0:c.querySelector("button"))==null||d.focus(),()=>{document.body.style.overflow=a,o instanceof HTMLElement&&o.isConnected&&o.focus()}},[]),Yt.createPortal(e.jsxs("div",{className:"mermaid-dialog","data-tab-swipe-ignore":!0,ref:s,role:"dialog","aria-modal":"true","aria-label":t,onKeyDown:o=>{var u;if(o.key==="Escape"&&(o.stopPropagation(),n()),o.key!=="Tab")return;const a=[...((u=s.current)==null?void 0:u.querySelectorAll('button:not(:disabled), a[href], [tabindex="0"]'))??[]],c=a[0],d=a[a.length-1];o.shiftKey&&document.activeElement===c?(o.preventDefault(),d==null||d.focus()):!o.shiftKey&&document.activeElement===d&&(o.preventDefault(),c==null||c.focus())},children:[e.jsxs("div",{className:"mermaid-dialog-header",children:[e.jsx("strong",{children:t}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":`关闭${t}`,onClick:n,children:e.jsx(qr,{size:20})})]}),r]}),document.body)}function Td({svg:t,fullscreen:n,onFullscreen:r,onExport:s,exporting:o}){const a=l.useMemo(()=>ll(t),[t]),c=l.useRef(null),[d,u]=l.useState(a),[h,g]=l.useState(null),y=Ad(a,d.width,n?d.height:void 0),m=h===null?y:Xi(h,y),b=l.useRef(m);b.current=m;const C=l.useRef(!1),M=l.useRef(null);l.useLayoutEffect(()=>{const I=c.current;if(!I)return;const j=()=>u({width:Math.max(1,I.clientWidth-24),height:Math.max(1,I.clientHeight-24)});j();const S=new ResizeObserver(j);return S.observe(I),()=>S.disconnect()},[]);const A=l.useCallback((I,j)=>{const S=c.current;if(!S)return;const P=Xi(I,y),K=P/b.current,R=j??{x:S.clientWidth/2,y:S.clientHeight/2},T=(S.scrollLeft+R.x)*K-R.x,_=(S.scrollTop+R.y)*K-R.y;b.current=P,g(P),requestAnimationFrame(()=>{S.scrollLeft=T,S.scrollTop=_})},[y]);return l.useEffect(()=>{const I=c.current;if(!I)return;let j=null;const S=_=>Math.hypot(_[0].clientX-_[1].clientX,_[0].clientY-_[1].clientY),P=_=>{C.current=!1,_.touches.length===2&&(j={distance:Math.max(1,S(_.touches)),scale:b.current},C.current=!0)},K=_=>{if(C.current=!0,!j||_.touches.length!==2)return;_.preventDefault();const k=I.getBoundingClientRect();A(j.scale*S(_.touches)/j.distance,{x:(_.touches[0].clientX+_.touches[1].clientX)/2-k.left,y:(_.touches[0].clientY+_.touches[1].clientY)/2-k.top})},R=()=>{j=null},T=_=>{if(!_.ctrlKey&&!_.metaKey)return;_.preventDefault();const k=I.getBoundingClientRect();A(b.current*Math.exp(-_.deltaY*.01),{x:_.clientX-k.left,y:_.clientY-k.top})};return I.addEventListener("touchstart",P,{passive:!0}),I.addEventListener("touchmove",K,{passive:!1}),I.addEventListener("touchend",R),I.addEventListener("touchcancel",R),I.addEventListener("wheel",T,{passive:!1}),()=>{I.removeEventListener("touchstart",P),I.removeEventListener("touchmove",K),I.removeEventListener("touchend",R),I.removeEventListener("touchcancel",R),I.removeEventListener("wheel",T)}},[A]),e.jsxs("div",{className:`mermaid-viewer${n?" mermaid-viewer-fullscreen":""}`,children:[e.jsxs("div",{className:"mermaid-toolbar",role:"toolbar","aria-label":"图表操作",children:[e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"缩小图表",title:"缩小",disabled:m<=Math.min(.1,y),onClick:()=>A(m/1.25),children:e.jsx(il,{size:18})}),e.jsxs("span",{className:"mermaid-zoom-value","aria-label":"缩放比例",children:[Math.round(m*100),"%"]}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"放大图表",title:"放大",disabled:m>=4,onClick:()=>A(m*1.25),children:e.jsx(ol,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"自适应图表",title:"自适应",onClick:()=>{var I;g(null),(I=c.current)==null||I.scrollTo(0,0)},children:e.jsx(nl,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":n?"退出图表全屏":"全屏查看图表",title:n?"退出全屏":"全屏",onClick:r,children:n?e.jsx(od,{size:18}):e.jsx(rd,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"导出图表 PNG",title:"导出 PNG",disabled:o,onClick:s,children:e.jsx(el,{size:18})})]}),e.jsx("div",{className:"mermaid-block-preview",ref:c,tabIndex:0,"aria-label":"图表预览,可滚动或双指缩放",onPointerDown:I=>{if(I.pointerType!=="mouse"||I.button!==0)return;const j=I.currentTarget;C.current=!1,M.current={x:I.clientX,y:I.clientY,left:j.scrollLeft,top:j.scrollTop}},onPointerMove:I=>{const j=M.current;j&&(Math.hypot(I.clientX-j.x,I.clientY-j.y)>4&&(C.current||I.currentTarget.setPointerCapture(I.pointerId),C.current=!0),I.currentTarget.scrollLeft=j.left-(I.clientX-j.x),I.currentTarget.scrollTop=j.top-(I.clientY-j.y))},onPointerUp:()=>{M.current=null},onPointerCancel:()=>{M.current=null},children:e.jsx("div",{className:"mermaid-diagram-canvas",style:{width:a.width*m,height:a.height*m},role:n?"img":"button","aria-label":n?"Mermaid 图表":"点击全屏查看 Mermaid 图表",tabIndex:n?void 0:0,onClick:()=>{!n&&!C.current&&r()},onKeyDown:I=>{!n&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),r())},dangerouslySetInnerHTML:{__html:t}})}),e.jsx("div",{className:"mermaid-viewer-hint",children:o?"正在生成完整 PNG…":n?"双指缩放 · 滑动查看 · 导出完整图片":"点击图表全屏 · 双指缩放"})]})}function Nd({code:t,svg:n}){const r=l.useRef(null),[s,o]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(null),[h,g]=l.useState(null),y=l.useRef(0),m=l.useCallback(()=>{o(!1),requestAnimationFrame(()=>{var A,I;return(I=(A=r.current)==null?void 0:A.querySelector('button[aria-label="全屏查看图表"]'))==null?void 0:I.focus()})},[]),b=l.useCallback(()=>u(null),[]);l.useEffect(()=>()=>{y.current++},[t]),l.useEffect(()=>()=>{d&&URL.revokeObjectURL(d)},[d]);const C=async()=>{if(a)return;const A=y.current;c(!0),g(null);try{const I=await Ed(t);A===y.current&&u(URL.createObjectURL(I))}catch(I){A===y.current&&g(I instanceof Error?I.message:"图片导出失败,请重试。")}finally{A===y.current&&c(!1)}},M=e.jsx(Td,{svg:n,fullscreen:s,onFullscreen:()=>s?m():o(!0),onExport:()=>void C(),exporting:a});return e.jsxs("div",{className:"mermaid-diagram","data-tab-swipe-ignore":!0,ref:r,children:[s?e.jsxs(Zi,{label:"图表全屏",onClose:m,children:[M,h&&e.jsx("div",{className:"mermaid-block-status",role:"alert",children:h})]}):M,!s&&h&&e.jsx("div",{className:"mermaid-block-status",role:"alert",children:h}),d&&e.jsxs(Zi,{label:"导出图表图片",onClose:b,children:[e.jsxs("div",{className:"mermaid-export-actions",children:[e.jsx("span",{children:"手机可长按图片保存,或下载 PNG"}),e.jsx("a",{href:d,download:"mermaid-diagram.png",children:"下载 PNG"})]}),e.jsx("div",{className:"mermaid-export-preview",children:e.jsx("img",{src:d,alt:"完整 Mermaid 图表 PNG"})})]})]})}function zd({code:t,complete:n}){const[r,s]=l.useState(!1),[o,a]=l.useState(null),c=n&&(o==null?void 0:o.code)===t?o:null;l.useEffect(()=>{if(!n||!t.trim())return;let u=!1;const h=setTimeout(()=>{al(t).then(g=>{u||a({code:t,svg:g})},()=>{u||a({code:t,error:"图表暂时无法渲染,请查看源码。"})})},150);return()=>{u=!0,clearTimeout(h)}},[t,n]);const d=n?t.trim()?(c==null?void 0:c.error)??(c!=null&&c.svg?null:"正在渲染图表…"):"暂无图表内容":"图表生成中…";return e.jsxs("div",{className:"mermaid-block",children:[e.jsxs("div",{className:"mermaid-block-header",children:[e.jsx("span",{children:"Mermaid"}),e.jsx("button",{type:"button","aria-pressed":r,onClick:()=>s(!r),children:r?"图表":"源码"})]}),d&&e.jsx("div",{className:"mermaid-block-status",role:"status",children:d}),r||!(c!=null&&c.svg)?e.jsx("pre",{className:"mermaid-block-source",children:e.jsx("code",{children:t})}):e.jsx(Nd,{code:t,svg:c.svg},t)]})}const cl="webapp.nativeAgentRunPrefs.v1",Ld=["codex","claude-code","opencode"];function dl(){try{const t=JSON.parse(localStorage.getItem(cl)??"{}");return t&&typeof t=="object"?t:{}}catch{return{}}}function $s(t){return Ld.includes(t)}function Ji(t){return $s(t)?dl()[t]??{}:{}}function _d(t,n){if(!$s(t))return;const r=dl();r[t]=n;try{localStorage.setItem(cl,JSON.stringify(r))}catch{}}function yo(t){return t.providerID?`${t.providerID}/${t.id}`:t.id}function Pd(t){const n=t.indexOf("/");return n>0?{providerID:t.slice(0,n),id:t.slice(n+1)}:{id:t}}function Os(t,n){const r=t??[],s=r.findIndex(a=>a.itemId===n.itemId&&a.sectionIndex===n.sectionIndex);return(s<0?[...r,{itemId:n.itemId,sectionIndex:n.sectionIndex,text:n.delta}]:r.map((a,c)=>c===s?{...a,text:a.text+n.delta}:a)).sort((a,c)=>a.sectionIndex-c.sectionIndex)}function ea(t){let n=[];for(const r of t)if(r.type==="runtime_progress"){const{type:s,...o}=r;n=ul(n,o)}else(r.type==="done"||r.type==="turn_aborted"||r.type==="error")&&(n=[]);return n}function ul(t,n){const r=t.findIndex(s=>s.progressId===n.progressId);return r<0?[...t,n]:t.map((s,o)=>o===r?n:s)}function pl(t,n){return[...t].reverse().find(r=>r.toolCallId===n)}function Wd(t){return[...t].reverse().find(n=>!n.toolCallId)}function Dd(t,n){var s,o,a;const r=[];for(let c=0;c<t.length;c+=1){const d=t[c];r.push(d);const u=d.role==="user"?(o=(s=d.presentation)==null?void 0:s.executionTrace)==null?void 0:o.turnId:void 0;if(!u)continue;const h=t[c+1];((a=h==null?void 0:h.executionTrace)==null?void 0:a.turnId)===u?(r.push({...h,executionTrace:{...h.executionTrace,turnId:u,revision:n}}),c+=1):r.push({id:`codex-execution-trace:${u}`,role:"assistant",content:"",executionTrace:{turnId:u,revision:n},timestamp:d.timestamp})}return r}function Bd(t){var n,r,s,o;return t.role==="assistant"&&!!((n=t.toolCalls)!=null&&n.length||(s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length||((o=t.presentation)==null?void 0:o.agentMessagePhase)==="commentary")}function fl(t,n,r,s){return t.map(o=>{var a;return(a=o.toolCalls)!=null&&a.some(c=>c.id===n)?{...o,toolCalls:o.toolCalls.map(c=>c.id===n?{...c,result:r,isError:s}:c)}:o})}function $d(t,n,r,s){if(n.type==="text_chunk"){if(!n.text||n.messagePhase!=="commentary")return[...t];const o=n.itemId?`codex-trace:${s}:agent:${n.itemId}`:`codex-live-commentary:${s}`,a=t.findIndex(c=>c.id===o);return a<0?[...t,{id:o,role:"assistant",content:n.text,presentation:{agentMessagePhase:"commentary"},timestamp:r}]:t.map((c,d)=>d===a?{...c,content:c.content+n.text}:c)}if(n.type==="reasoning_summary_delta"){const o=t.findIndex(a=>{var c,d;return(d=(c=a.presentation)==null?void 0:c.reasoning)==null?void 0:d.some(u=>u.itemId===n.itemId)});return o<0?[...t,{id:`codex-live-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:Os(void 0,n)},timestamp:r}]:t.map((a,c)=>{var d;return c===o?{...a,presentation:{...a.presentation,reasoning:Os((d=a.presentation)==null?void 0:d.reasoning,n)}}:a})}if(n.type==="tool_call"){const o=t.findIndex(a=>{var c;return(c=a.toolCalls)==null?void 0:c.some(d=>d.id===n.toolCall.id)});return o>=0?t.map((a,c)=>{var d;return c===o?{...a,toolCalls:(d=a.toolCalls)==null?void 0:d.map(u=>u.id===n.toolCall.id?{...u,name:n.toolCall.name,arguments:n.toolCall.arguments}:u)}:a}):[...t,{id:`codex-live-tool:${n.toolCall.id}`,role:"assistant",content:"",toolCalls:[{...n.toolCall}],timestamp:r}]}return t.some(o=>{var a;return(a=o.toolCalls)==null?void 0:a.some(c=>c.id===n.result.toolCallId)})?fl(t,n.result.toolCallId,n.result.content,n.result.isError):[...t]}function Uo(t,n,r,s=Date.now()){var h;const o=t.findIndex(g=>{var y;return((y=g.executionTrace)==null?void 0:y.turnId)===n}),a=o>=0?((h=t[o].executionTrace)==null?void 0:h.liveMessages)??[]:[],c=$d(a,r,s,n);if(c.length===0&&a.length===0)return[...t];if(o>=0)return t.map((g,y)=>y===o?{...g,executionTrace:{...g.executionTrace,liveMessages:c}}:g);if(c===a)return[...t];const d=t.findLastIndex(g=>g.role==="user"&&!g.isQueued);if(d<0)return[...t];const u={id:`codex-execution-trace:${n}`,role:"assistant",content:"",executionTrace:{turnId:n,revision:`live:${n}`,liveMessages:c},timestamp:s};return[...t.slice(0,d+1),u,...t.slice(d+1)]}function qo(t,n){const r=new Map(t.map(s=>[`${s.itemId}:${s.sectionIndex}`,s]));for(const s of n){const o=`${s.itemId}:${s.sectionIndex}`,a=r.get(o),c=a?s.text.startsWith(a.text)?s.text:a.text.startsWith(s.text)?a.text:s.text:s.text;r.set(o,{...s,text:c})}return[...r.values()]}function ta(t){var n,r;return[...((n=t.presentation)==null?void 0:n.agentMessagePhase)==="commentary"?[`agent:${t.id}`]:[],...(((r=t.presentation)==null?void 0:r.reasoning)??[]).map(s=>`reasoning:${s.itemId}:${s.sectionIndex}`),...(t.toolCalls??[]).map(s=>`tool:${s.id}`)]}function Od(t,n){var r,s;return((r=t.presentation)==null?void 0:r.agentMessagePhase)==="commentary"&&((s=n.presentation)==null?void 0:s.agentMessagePhase)==="commentary"&&(t.id.startsWith("codex-live-commentary:")||n.id.startsWith("codex-live-commentary:"))&&(t.content.startsWith(n.content)||n.content.startsWith(t.content))}function Fd(t){var a,c,d,u,h,g,y,m,b,C,M;const n=[],r=new Map,s=new Map,o=new Map;for(const A of t){if(((a=A.presentation)==null?void 0:a.agentMessagePhase)==="commentary"){const R=r.get(A.id);if(R!==void 0){const T=n[R],_=A.content.startsWith(T.content)?A.content:T.content.startsWith(A.content)?T.content:A.content;n[R]={...T,...A,id:T.id,content:_};continue}}const I={...A,toolCalls:A.toolCalls?[]:void 0,presentation:(c=A.presentation)!=null&&c.reasoning?{...A.presentation,reasoning:[]}:A.presentation};for(const R of((d=A.presentation)==null?void 0:d.reasoning)??[]){const T=`${R.itemId}:${R.sectionIndex}`,_=s.get(T);if(_){const k=n[_.messageIndex],W=[...((u=k.presentation)==null?void 0:u.reasoning)??[]],Q=W[_.sectionIndex];W[_.sectionIndex]=qo([Q],[R])[0],n[_.messageIndex]={...k,presentation:{...k.presentation,reasoning:W}}}else{const k=I.presentation.reasoning.findIndex(W=>W.itemId===R.itemId&&W.sectionIndex===R.sectionIndex);k>=0?I.presentation.reasoning[k]=qo([I.presentation.reasoning[k]],[R])[0]:I.presentation.reasoning.push(R)}}for(const R of A.toolCalls??[]){const T=o.get(R.id);if(T){const _=n[T.messageIndex],k=[..._.toolCalls??[]];k[T.toolIndex]={...k[T.toolIndex],...R},n[T.messageIndex]={..._,toolCalls:k}}else{const _=I.toolCalls.findIndex(k=>k.id===R.id);_>=0?I.toolCalls[_]={...I.toolCalls[_],...R}:I.toolCalls.push(R)}}const j=((h=I.presentation)==null?void 0:h.agentMessagePhase)==="commentary",S=!!((y=(g=I.presentation)==null?void 0:g.reasoning)!=null&&y.length),P=!!((m=I.toolCalls)!=null&&m.length);if(!j&&!S&&!P)continue;const K=n.length;n.push(I),j&&r.set(I.id,K);for(let R=0;R<(((C=(b=I.presentation)==null?void 0:b.reasoning)==null?void 0:C.length)??0);R+=1){const T=I.presentation.reasoning[R];s.set(`${T.itemId}:${T.sectionIndex}`,{messageIndex:K,sectionIndex:R})}for(let R=0;R<(((M=I.toolCalls)==null?void 0:M.length)??0);R+=1)o.set(I.toolCalls[R].id,{messageIndex:K,toolIndex:R})}return n}function Hd(t,n,r){if(t.length<2)return t;const s=new Map;t.forEach((A,I)=>{for(const j of ta(A))s.set(j,I)});const o=A=>{for(const I of ta(A)){const j=s.get(I);if(j!==void 0)return j}return t.findIndex(I=>Od(I,A))},a=A=>{const I=[];for(const j of A){const S=o(j);S<0||I.at(-1)===S||I.push(S)}return I},c=a(n),d=a(r),u=Array.from({length:t.length},()=>new Set),h=Array.from({length:t.length},()=>0),g=A=>{for(let I=1;I<A.length;I+=1){const j=A[I-1],S=A[I];j===S||u[j].has(S)||(u[j].add(S),h[S]+=1)}};g(c),g(d);const y=new Map(c.map((A,I)=>[A,I])),m=new Map(d.map((A,I)=>[A,I])),b=(A,I)=>{const j=y.get(A)??Number.POSITIVE_INFINITY,S=y.get(I)??Number.POSITIVE_INFINITY;if(j!==S)return j-S;const P=m.get(A)??Number.POSITIVE_INFINITY,K=m.get(I)??Number.POSITIVE_INFINITY;return P!==K?P-K:A-I},C=h.flatMap((A,I)=>A===0?[I]:[]).sort(b),M=[];for(;C.length>0;){const A=C.shift();M.push(t[A]);for(const I of u[A])h[I]-=1,h[I]===0&&(C.push(I),C.sort(b))}return M.length===t.length?M:t}function Ud(t,n){var s,o,a,c,d;const r=t.map(u=>{var h,g;return{...u,toolCalls:(h=u.toolCalls)==null?void 0:h.map(y=>({...y})),presentation:(g=u.presentation)!=null&&g.reasoning?{...u.presentation,reasoning:[...u.presentation.reasoning]}:u.presentation}});for(const u of n){if(((s=u.presentation)==null?void 0:s.agentMessagePhase)==="commentary"){const g=r.findIndex(y=>{var m;return y.id===u.id||((m=y.presentation)==null?void 0:m.agentMessagePhase)==="commentary"&&(y.id.startsWith("codex-live-commentary:")||u.id.startsWith("codex-live-commentary:"))&&(u.content.startsWith(y.content)||y.content.startsWith(u.content))});if(g<0)r.push(u);else{const y=r[g],m=u.content.startsWith(y.content)?u.content:y.content.startsWith(u.content)?y.content:u.content;r[g]={...y,content:m,presentation:{...y.presentation,agentMessagePhase:"commentary"}}}continue}const h=(o=u.presentation)==null?void 0:o.reasoning;if(h!=null&&h.length){const g=r.findIndex(y=>{var m,b;return(b=(m=y.presentation)==null?void 0:m.reasoning)==null?void 0:b.some(C=>h.some(M=>M.itemId===C.itemId))});if(g>=0){const y=r[g];r[g]={...y,presentation:{...y.presentation,reasoning:qo(((a=y.presentation)==null?void 0:a.reasoning)??[],h)}}}else r.push(u)}for(const g of u.toolCalls??[]){const y=r.findIndex(m=>{var b;return(b=m.toolCalls)==null?void 0:b.some(C=>C.id===g.id)});if(y>=0){const m=r[y];r[y]={...m,toolCalls:(c=m.toolCalls)==null?void 0:c.map(b=>b.id===g.id?{...b,...g}:b)}}else r.push({...u,id:(((d=u.toolCalls)==null?void 0:d.length)??0)>1?`${u.id}:tool:${g.id}`:u.id,presentation:void 0,toolCalls:[g]})}}return Hd(Fd(r),t,n)}function na(t){for(let n=t.length-1;n>=0;n--)if(t[n].type==="context_usage"&&t[n].usage)return t[n].usage}function ra(t){var r;const n=new Map;for(const s of t)s.type==="native_subagent_update"&&((r=s.activity)!=null&&r.parentToolCallId)&&n.set(s.activity.parentToolCallId,s.activity);return[...n.values()]}function hl(t){var n;return!!(t&&t.role==="assistant"&&!((n=t.toolCalls)!=null&&n.length)&&!t.widget&&!t.askUser&&!t.isCompactionSummary&&!t.executionTrace)}function sa(t,n){var r;if(n.role==="assistant"&&((r=n.toolCalls)!=null&&r.length)){const s=t[t.length-1];if(hl(s))return[...t.slice(0,-1),{...s,content:s.content,toolCalls:n.toolCalls}]}return[...t,n]}function qd(t,n){if(!n)return t;const r=t[t.length-1];if(hl(r)){const s=[...t];return s[s.length-1]={...r,content:r.content+n},s}return[...t,{id:crypto.randomUUID(),role:"assistant",content:n,timestamp:Date.now()}]}function oa(t,n,r,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(c=>c.id===n?{...c,result:r,isError:s}:c);return{...o,toolCalls:a}})}function ia(t,n,r,s){return t.map(o=>{if(!o.toolCalls)return o;const a=o.toolCalls.map(c=>c.name==="dispatch_agent"&&c.arguments.subSessionId===n?{...c,arguments:{...c.arguments,subAgentStatus:r,subAgentDetail:s}}:c);return{...o,toolCalls:a}})}function aa(t,n,r){return t.map(s=>{if(!s.toolCalls)return s;const o=s.toolCalls.map(a=>a.name==="dispatch_agent"&&a.arguments.subSessionId===n?{...a,arguments:{...a.arguments,subAgentProgress:(a.arguments.subAgentProgress?a.arguments.subAgentProgress+`
343
- `+r:r).split(`
344
- `).slice(-30).join(`
345
- `)}}:a);return{...s,toolCalls:o}})}function la(t,n,r){return t.map(s=>s.id===n?r(s):s)}function ca(t,n){const r=t.findIndex(s=>{var o,a;return(a=(o=s.presentation)==null?void 0:o.reasoning)==null?void 0:a.some(c=>c.itemId===n.itemId)});return r<0?[...t,{id:`native-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:Os(void 0,n)},timestamp:Date.now()}]:t.map((s,o)=>{var a;return o===r?{...s,presentation:{...s.presentation,reasoning:Os((a=s.presentation)==null?void 0:a.reasoning,n)}}:s})}const We=Xa((t,n)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(r,s)=>t(o=>{const a=s??o.sessionId??void 0,c=a&&a!==o.sessionId?o.messages:sa(o.messages,r),d=a?{...o.messagesBySession,[a]:sa(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),r)}:o.messagesBySession;return{messages:c,messagesBySession:d,currentText:a&&a!==o.sessionId?o.currentText:""}}),appendText:(r,s)=>t(o=>{if(!r)return o;const a=s??o.sessionId??void 0,c=!a||a===o.sessionId,d=qd(c?o.messages:o.messagesBySession[a]??[],r),u=a?{...o.messagesBySession,[a]:d}:o.messagesBySession;return{messages:c?d:o.messages,messagesBySession:u,currentText:a&&a!==o.sessionId?o.currentText:o.currentText+r}}),setRunningSession:r=>t({runningSessionId:r}),setSessionId:r=>t(s=>s.sessionId===r?s:{sessionId:r,messages:s.messagesBySession[r]??[],currentText:""}),updateToolResult:(r,s,o,a)=>t(c=>{const d=a??c.sessionId??void 0,u=d&&d!==c.sessionId?c.messages:oa(c.messages,r,s,o),h=d?{...c.messagesBySession,[d]:oa(c.messagesBySession[d]??(d===c.sessionId?c.messages:[]),r,s,o)}:c.messagesBySession;return{messages:u,messagesBySession:h}}),setMessages:(r,s)=>t(o=>{const a=s??o.sessionId??void 0,c=!a||a===o.sessionId;return{messages:c?r:o.messages,messagesBySession:a?{...o.messagesBySession,[a]:r}:o.messagesBySession,currentText:c?"":o.currentText}}),getMessagesForSession:r=>n().messagesBySession[r]??[],setContextUsage:(r,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{contextUsageBySession:{...o.contextUsageBySession,[a]:r}}:o}),getContextUsageForSession:r=>n().contextUsageBySession[r],applyRuntimeProgress:(r,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:ul(o.runtimeProgressBySession[a]??[],r)}}:o}),setRuntimeProgress:(r,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{runtimeProgressBySession:{...o.runtimeProgressBySession,[a]:r}}:o}),clearRuntimeProgress:r=>t(s=>{var d;const o=r??s.sessionId??void 0;if(!o||!((d=s.runtimeProgressBySession[o])!=null&&d.length))return s;const{[o]:a,...c}=s.runtimeProgressBySession;return{runtimeProgressBySession:c}}),applyNativeSubagentActivity:(r,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:{...o.nativeSubagentsBySession[a]??{},[r.parentToolCallId]:r}}}:o}),setNativeSubagentActivities:(r,s)=>t(o=>{const a=s??o.sessionId??void 0;return a?{nativeSubagentsBySession:{...o.nativeSubagentsBySession,[a]:Object.fromEntries(r.map(c=>[c.parentToolCallId,c]))}}:o}),applyReasoningSummary:(r,s)=>t(o=>{const a=s??o.sessionId??void 0,c=a&&a!==o.sessionId?o.messages:ca(o.messages,r),d=a?{...o.messagesBySession,[a]:ca(o.messagesBySession[a]??(a===o.sessionId?o.messages:[]),r)}:o.messagesBySession;return{messages:c,messagesBySession:d}}),applyCodexExecutionEvent:(r,s,o)=>t(a=>{const c=o??a.sessionId??void 0,d=Date.now(),u=c&&c!==a.sessionId?a.messages:Uo(a.messages,r,s,d),h=c?{...a.messagesBySession,[c]:Uo(a.messagesBySession[c]??(c===a.sessionId?a.messages:[]),r,s,d)}:a.messagesBySession;return{messages:u,messagesBySession:h}}),updateMessage:(r,s,o)=>t(a=>{const c=o??a.sessionId??void 0,d=c&&c!==a.sessionId?a.messages:la(a.messages,r,s),u=c?{...a.messagesBySession,[c]:la(a.messagesBySession[c]??(c===a.sessionId?a.messages:[]),r,s)}:a.messagesBySession;return{messages:d,messagesBySession:u}}),updateSubAgentStatus:(r,s,o,a)=>t(c=>{const d=a??c.sessionId??void 0,u=d&&d!==c.sessionId?c.messages:ia(c.messages,r,s,o),h=d?{...c.messagesBySession,[d]:ia(c.messagesBySession[d]??(d===c.sessionId?c.messages:[]),r,s,o)}:c.messagesBySession;return{messages:u,messagesBySession:h}}),updateSubAgentProgress:(r,s,o)=>t(a=>{const c=o??a.sessionId??void 0,d=c&&c!==a.sessionId?a.messages:aa(a.messages,r,s),u=c?{...a.messagesBySession,[c]:aa(a.messagesBySession[c]??(c===a.sessionId?a.messages:[]),r,s)}:a.messagesBySession;return{messages:d,messagesBySession:u}}),clearMessages:r=>t(s=>{const o=r??s.sessionId??void 0;if(!o)return{messages:[],currentText:""};const{[o]:a,...c}=s.messagesBySession,{[o]:d,...u}=s.contextUsageBySession,{[o]:h,...g}=s.runtimeProgressBySession,{[o]:y,...m}=s.nativeSubagentsBySession;return{messages:o===s.sessionId?[]:s.messages,messagesBySession:c,contextUsageBySession:u,runtimeProgressBySession:g,nativeSubagentsBySession:m,currentText:o===s.sessionId?"":s.currentText}}),setTodos:r=>t({todos:r}),setCronTasks:r=>t({cronTasks:r})}));function ei(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function gl(){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 Vd(){return gl()!==null||ei()!==null}function Kd(t){var a,c;const n=gl();if(n){let d=!1,u=()=>{},h=()=>{};const g=()=>{var y;d||(d=!0,u(),h(),(y=t.onEnd)==null||y.call(t))};return u=n.onDictation(({text:y,isFinal:m})=>{const b=y.trim();b&&(m?(t.onFinal(b),g()):t.onInterim(b))}),h=n.onDictationError(y=>{var m;(m=t.onError)==null||m.call(t,y),g()}),n.dictationStart().then(y=>{var m;y.ok||((m=t.onError)==null||m.call(t,y.reason||"无法启动语音识别"),g())}).catch(()=>{var y;(y=t.onError)==null||y.call(t,"无法启动语音识别"),g()}),{stop:()=>{n.dictationStop()}}}const r=ei();if(!r)return(a=t.onError)==null||a.call(t,"当前环境不支持语音识别"),null;const s=new r;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let o="";s.onresult=d=>{let u="";for(let h=d.resultIndex;h<d.results.length;h++){const g=d.results[h];g.isFinal?o+=g[0].transcript:u+=g[0].transcript}u&&t.onInterim(o+u)},s.onerror=d=>{var u;d.error!=="no-speech"&&d.error!=="aborted"&&((u=t.onError)==null||u.call(t,`语音识别失败:${d.error??"未知错误"}`))},s.onend=()=>{var d;o&&t.onFinal(o.trim()),(d=t.onEnd)==null||d.call(t)};try{s.start()}catch{return(c=t.onEnd)==null||c.call(t),null}return{stop:()=>s.stop()}}function Gd(t){var c;const n=ei();if(!n)return(c=t.onError)==null||c.call(t,"当前环境不支持语音唤醒"),null;let r=!1,s=null,o=null;const a=()=>{if(!r){s=new n,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=d=>{var g,y,m;const u=d.results[d.results.length-1],h=(y=(g=u==null?void 0:u[0])==null?void 0:g.transcript)==null?void 0:y.trim();h&&(u.isFinal&&((m=t.onHeard)==null||m.call(t,h)),h.includes(t.wakeWord)&&t.onWake(h))},s.onerror=d=>{var u;d.error==="not-allowed"&&((u=t.onError)==null||u.call(t,"麦克风权限被拒绝,语音唤醒已停用"),r=!0)},s.onend=()=>{r||(o=setTimeout(a,400))};try{s.start()}catch{o=setTimeout(a,800)}}};return a(),{stop:()=>{r=!0,o&&clearTimeout(o);try{s==null||s.abort()}catch{}}}}function us(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function Ns(t,n){return n(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const Qd={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function Yd(t){const n=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(n.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const r=new Float32Array(n.byteLength/2),s=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let o=0;o<r.length;o+=1)r[o]=s.getInt16(o*2,!0)/32768;return r}class Xd{constructor(n,r=Qd){this.api=n,this.dependencies=r,this.context=null,this.node=null,this.ready=null,this.current=null}start(n){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const r={metadata:n,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=r,this.ensureReady().then(()=>{if(!(this.current!==r||!this.node)){this.node.port.postMessage({type:"start",generation:n.generation,sampleRate:n.sampleRate});for(const o of r.pending)this.postSamples(n.generation,o);r.pending=[],r.pendingSamples=0,r.finished&&this.node.port.postMessage({type:"finish",generation:n.generation})}}).catch(o=>this.fail(r,o))}enqueue(n,r){const s=this.current;if(!s||s.metadata.generation!==n||s.acknowledged)return;let o;try{o=Yd(r)}catch(a){this.fail(s,a);return}if(this.node){this.postSamples(n,o);return}if(s.pendingSamples+o.length>s.metadata.sampleRate){this.fail(s,new Error("TTS PCM queue overflow"));return}s.pending.push(o),s.pendingSamples+=o.length}finish(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||(r.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:n}))}flush(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:n}),r.pending=[],r.pendingSamples=0,this.acknowledge(r))}dispose(){var n,r;this.current&&this.flush(this.current.metadata.generation),(n=this.node)==null||n.disconnect(),this.node=null,(r=this.context)==null||r.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const n=this.dependencies.createContext();this.context=n,await n.audioWorklet.addModule(this.dependencies.workletUrl);const r=this.dependencies.createNode(n);r.port.onmessage=s=>this.onWorkletMessage(s.data),r.connect(n.destination),this.node=r,n.state!=="running"&&await n.resume()})(),this.ready)}postSamples(n,r){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:n,samples:r},[r.buffer])}onWorkletMessage(n){const r=this.current;if(!(!r||n.generation!==r.metadata.generation)){if(n.type==="drained"||n.type==="stopped"){this.acknowledge(r);return}n.type==="overflow"&&this.fail(r,new Error("TTS AudioWorklet buffer overflow"))}}fail(n,r){this.current!==n||n.acknowledged||(console.error("[tts] PCM playback failed",r),n.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(n.metadata.generation))}acknowledge(n){this.current!==n||n.acknowledged||(n.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(n.metadata.generation))}}async function Zd(t,n,r,s=50){var d;const o=u=>t.getSession(n,{view:"trace",revision:u,turnId:r.turnId});try{return{detail:await o(r.revision),revision:r.revision,recovered:!1}}catch(u){if(u.code!=="STALE_SESSION_ANCHOR")throw u}const a=await t.getSession(n,{view:"core",limit:s}),c=(d=a==null?void 0:a.history)==null?void 0:d.revision;if(!c)throw new Error("会话内容已更新,请刷新后重试");return{detail:await o(c),revision:c,recovered:!0}}async function Br(t,n,r,s,o,a,c){if(r!=="codex"){const u=c?await c():await t.getSession(n,s);a()&&o(u,"full");return}const d=c?await c():await t.getSession(n,{...s,view:"core"});a()&&o(d,"core")}function da(t,n,r,s){const o=r==="core"&&(s==null?void 0:s.delivery)!=="legacy-full"&&!!(s!=null&&s.revision),a=t.some(c=>!c.isQueued);return o&&a?Jd(t,n):ml(t,n)}function Jd(t,n){var I,j;if(n.length===0)return t;if(t.length===0)return n;let r=t.filter(S=>!S.isQueued);const s=t.filter(S=>S.isQueued),o=n.findLastIndex(S=>S.role==="user"&&!S.isCompactionSummary);if(o<0)return t;const a=n[o];let c=r.findLastIndex(S=>S.role==="user"&&!S.isCompactionSummary&&tr(S)===tr(a));if(c<0)return[...r,...n.slice(o),...s];const d=ml(r.slice(0,c),n.slice(0,o));r=[...d,...r.slice(c)],c=d.length;const u=r.findIndex((S,P)=>P>c&&S.role==="user"&&!S.isCompactionSummary),h=u<0?r.length:u,g=[];for(let S=c+1;S<h;S+=1)ua(r[S])&&g.push(S);const y=n.slice(o+1).filter(ua),m=(j=(I=n.find(S=>S.executionTrace))==null?void 0:I.executionTrace)==null?void 0:j.revision,b=r.map(S=>S.executionTrace&&m?{...S,executionTrace:{...S.executionTrace,revision:m}}:S),C=n.slice(o+1).find(S=>S.executionTrace),M=r.findIndex((S,P)=>{var K,R;return P>c&&P<h&&((K=S.executionTrace)==null?void 0:K.turnId)===((R=C==null?void 0:C.executionTrace)==null?void 0:R.turnId)});if(C&&M>=0){const S=r[M].executionTrace;b[M]={...C,id:r[M].id,timestamp:r[M].timestamp,executionTrace:{...C.executionTrace,...S!=null&&S.liveMessages?{liveMessages:S.liveMessages}:{}}}}const A=Math.min(g.length,y.length);for(let S=0;S<A;S+=1){const P=g[S],K=b[P],R=y[S];b[P]={...K,...R,id:R.id.startsWith("history-message.v1.")?R.id:K.id,timestamp:K.timestamp,images:R.images??K.images,presentation:R.presentation??K.presentation}}return y.length>A&&b.splice(h,0,...y.slice(A)),[...b,...s]}function ua(t){var n,r,s;return t.role==="assistant"&&!t.executionTrace&&!((n=t.toolCalls)!=null&&n.length)&&!t.askUser&&!t.isCompactionSummary&&!((s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length)}function $r(t){var o,a;const n=((o=t==null?void 0:t.history)==null?void 0:o.delivery)==="core",r=xl(t,!n),s=(a=t==null?void 0:t.history)==null?void 0:a.revision;return!n||!s?r:ou(Dd(r,s),(t==null?void 0:t.events)??[])}function eu(t){return xl(t).filter(Bd)}function xl(t,n=!0){var y;const r=(t==null?void 0:t.messages)??[],s=(t==null?void 0:t.events)??[],o=new Set(s.filter(m=>m.type==="approval_resolved"&&m.questionId).map(m=>m.questionId)),a=new Map;for(const m of s)m.type==="tool_result"&&((y=m.result)!=null&&y.toolCallId)&&a.set(m.result.toolCallId,{content:m.result.content??"",isError:m.result.isError});const c=r.filter(m=>(m.role==="user"||m.role==="assistant"||m.role==="tool")&&m.name!=="__interrupt__").map(su),d=new Map;for(const m of c)m.role==="tool"&&m.toolCallId&&d.set(m.toolCallId,m);let u=c.filter(m=>m.role!=="tool").map(m=>{var b;return m.isCompactionSummary?m:m.role==="assistant"&&((b=m.toolCalls)!=null&&b.length)?{...m,toolCalls:m.toolCalls.map(C=>{const M=d.get(C.id);if(M)return{...C,...M.toolResultRef?{resultRef:M.toolResultRef,isError:M.toolResultRef.isError}:{result:M.content}};const A=a.get(C.id);return A?{...C,result:A.content,isError:A.isError}:C})}:m.role==="user"&&m.name&&m.name!=="__compaction_checkpoint__"&&!m.name.startsWith("__native_")?{...m,agentName:m.name}:m});const h=iu(s,n);if(!u.some(m=>m.role==="assistant"&&!m.isCompactionSummary)&&h){const m=u.findLastIndex(b=>b.role==="user"&&!b.isCompactionSummary);u=m>=0?[...u.slice(0,m+1),h,...u.slice(m+1)]:[...u,h]}const g=new Set(u.flatMap(m=>{var b;return(b=m.askUser)!=null&&b.questionId?[m.askUser.questionId]:[]}));for(const m of s)m.type!=="ask_user"||!m.questionId||o.has(m.questionId)||g.has(m.questionId)||(g.add(m.questionId),u.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:m.questionId,question:m.question??"",options:m.options,fields:m.fields,multiSelect:m.multiSelect},timestamp:Date.now()}));return u}function ml(t,n){if(n.length===0)return t;if(t.length===0)return n;const r=t.map(Vo),s=n.map(Vo),o=Math.max(0,t.length-n.length),a=nu(t,n,o);let c={currentStart:o,length:0,distance:1/0};for(let m=0;m<r.length;m++)for(let b=0;b<s.length;b++){if(r[m]!==s[b])continue;const C=m-b;if(C<0)continue;let M=0;for(;m+M<r.length&&b+M<s.length&&r[m+M]===s[b+M];)M+=1;const A=Math.abs(C-o);(M>c.length||M===c.length&&A<c.distance)&&(c={currentStart:C,length:M,distance:A})}const d=a??(c.length>0?c.currentStart:o),u=n.map((m,b)=>{var I,j,S;const C=t[d+b];if(!C||!ru(C,m,s[b]))return m;const M=(j=(I=m.presentation)==null?void 0:I.attachments)==null?void 0:j.some(P=>P.dataUrl),A=(S=m.toolCalls)==null?void 0:S.map(P=>{var R;const K=(R=C.toolCalls)==null?void 0:R.find(T=>T.id===P.id);return(K==null?void 0:K.result)===void 0?P:{...P,result:K.result,isError:K.isError}});return{...m,id:m.id.startsWith("history-message.v1.")?m.id:C.id,timestamp:C.timestamp,images:M?void 0:m.images??C.images,...A?{toolCalls:A}:{}}}),h=t.filter(m=>m.isQueued),g=t.slice(d).filter(m=>!m.isQueued),y=tu(g,u);return[...t.slice(0,d).filter(m=>!m.isQueued),...y,...h]}function tu(t,n){const r=n.findLastIndex(C=>C.role==="user"&&!C.isQueued);if(r<0)return n;const s=tr(n[r]);let o=-1,a=1/0;for(let C=0;C<t.length;C+=1){const M=t[C];if(M.role!=="user"||M.isQueued||tr(M)!==s)continue;const A=Math.abs(C-r);A<a&&(o=C,a=A)}if(o<0)return n;const c=t.findIndex((C,M)=>M>o&&C.role==="user"&&!C.isQueued),d=t.slice(o+1,c<0?t.length:c),u=n.slice(r+1),h=pa(d),g=pa(u);if(h.length<=g.length||!h.startsWith(g))return n;const y=h.slice(g.length),m=n.findLastIndex((C,M)=>{var A;return M>r&&C.role==="assistant"&&!((A=C.toolCalls)!=null&&A.length)&&!C.askUser&&!C.isCompactionSummary});if(m>=0)return n.map((C,M)=>M===m?{...C,content:C.content+y}:C);const b=d.findLast(C=>C.role==="assistant"&&!!C.content&&!C.isCompactionSummary);return[...n,{id:(b==null?void 0:b.id)??crypto.randomUUID(),role:"assistant",content:y,timestamp:(b==null?void 0:b.timestamp)??Date.now()}]}function pa(t){return t.filter(n=>n.role==="assistant"&&!n.isCompactionSummary).map(n=>n.content).join("")}function nu(t,n,r){const s=n[0];if((s==null?void 0:s.role)!=="user")return null;const o=tr(s);let a=null;for(let c=0;c<t.length;c+=1){if(t[c].role!=="user"||t[c].isQueued||tr(t[c])!==o)continue;const d=Math.abs(c-r);(!a||d<a.distance)&&(a={start:c,distance:d})}return(a==null?void 0:a.start)??null}function ru(t,n,r){var s,o;return Vo(t)===r||t.role==="assistant"&&n.role==="assistant"&&t.content===n.content&&JSON.stringify(((s=t.toolCalls)==null?void 0:s.map(a=>a.id))??[])===JSON.stringify(((o=n.toolCalls)==null?void 0:o.map(a=>a.id))??[])?!0:t.role==="user"&&n.role==="user"&&tr(t)===tr(n)}function tr(t){var n;return JSON.stringify({role:t.role,content:t.content,name:(n=t.name)!=null&&n.startsWith("__native_")?void 0:t.name,agentName:t.agentName,isCompactionSummary:t.isCompactionSummary})}function Vo(t){return JSON.stringify({role:t.role,content:t.content,toolCalls:t.toolCalls,toolCallId:t.toolCallId,toolResultRef:t.toolResultRef,name:t.name,agentName:t.agentName,presentation:t.role==="user"?void 0:t.presentation,isCompactionSummary:t.isCompactionSummary})}function su(t){var n;if(t.name==="__compaction_checkpoint__"){let r="";try{r=JSON.parse(t.content??"{}").summary??""}catch{}return{id:crypto.randomUUID(),role:"user",content:r,name:t.name,isCompactionSummary:!0,timestamp:Date.now()}}return{id:t.historyId??crypto.randomUUID(),role:t.role,content:t.content??"",toolCalls:(n=t.toolCalls)!=null&&n.length?t.toolCalls:void 0,toolCallId:t.toolCallId,toolResultRef:t.toolResultRef,name:t.name,presentation:t.presentation,timestamp:Date.now()}}function ou(t,n){return n.reduce((r,s)=>{var a;if(!s.turnId)return r;let o=null;return s.type==="text_chunk"&&s.messagePhase==="commentary"&&typeof s.text=="string"&&s.text?o={type:"text_chunk",text:s.text,turnId:s.turnId,itemId:s.itemId,messagePhase:"commentary"}:s.type==="reasoning_summary_delta"&&s.itemId&&Number.isSafeInteger(s.sectionIndex)&&typeof s.delta=="string"?o={type:"reasoning_summary_delta",turnId:s.turnId,itemId:s.itemId,sectionIndex:s.sectionIndex,delta:s.delta}:s.type==="tool_call"&&s.toolCall?o={type:"tool_call",turnId:s.turnId,toolCall:s.toolCall}:s.type==="tool_result"&&((a=s.result)!=null&&a.toolCallId)&&(o={type:"tool_result",turnId:s.turnId,result:{toolCallId:s.result.toolCallId,content:s.result.content??"",isError:s.result.isError}}),o?Uo(r,s.turnId,o):r},t)}function iu(t,n=!0){var a;let r="";const s=[],o=new Map;for(const c of t){if(c.type==="text_chunk"&&c.text&&(r+=c.text),n&&c.type==="tool_call"&&c.toolCall){const d={id:c.toolCall.id,name:c.toolCall.name,arguments:c.toolCall.arguments};s.push(d),o.set(d.id,d)}if(n&&c.type==="tool_result"&&((a=c.result)!=null&&a.toolCallId)){const d=o.get(c.result.toolCallId);d&&(d.result=c.result.content??"",d.isError=c.result.isError)}}return!r.trim()&&s.length===0?null:{id:crypto.randomUUID(),role:"assistant",content:r.trim(),toolCalls:s.length>0?s:void 0,timestamp:Date.now()}}class au{constructor(){this.slot=null}prefetch(n,r,s){return this.getOrStart(n,r,s).promise}async consume(n,r,s){const o=this.getOrStart(n,r,s);try{return await o.promise}finally{this.slot===o&&(this.slot=null)}}invalidate(){this.slot=null}getOrStart(n,r,s){var c;if(((c=this.slot)==null?void 0:c.sessionId)===n&&this.slot.cursor===r)return this.slot;let o;try{o=s()}catch(d){o=Promise.reject(d)}const a={sessionId:n,cursor:r,promise:o};return this.slot=a,o.catch(()=>{this.slot===a&&(this.slot=null)}),a}}const bl=60,lu=32,cu=240,du=6,uu=10;function fa(t,n,r,s){if(s<=1||r<=0)return 0;const o=Math.max(0,Math.min(1,(t-n)/r));return Math.round(o*(s-1))}function pu(t){const n=Math.min(Math.max(0,t),bl);return n<=1?n===1?[0]:[]:Array.from({length:n},(r,s)=>Math.round(s/(n-1)*(t-1)))}function ha(t,n=du){return Math.min(cu,Math.max(lu,Math.min(Math.max(0,t),bl)*n))}function fu(t,n,r){if(r<=0)return null;const s=Math.max(5,Math.round(r/10));return n==="ArrowUp"||n==="ArrowLeft"?Math.max(0,t-1):n==="ArrowDown"||n==="ArrowRight"?Math.min(r-1,t+1):n==="PageUp"?Math.max(0,t-s):n==="PageDown"?Math.min(r-1,t+s):n==="Home"?0:n==="End"?r-1:null}function hu({entries:t,activeMessageId:n,loadingMessageId:r,onActivate:s}){const o=t.findIndex(A=>A.messageId===n),a=o>=0?o:Math.max(0,t.length-1),[c,d]=l.useState(a),[u,h]=l.useState(!1),g=l.useRef(!1),y=l.useMemo(()=>pu(t.length),[t.length]);if(l.useEffect(()=>d(a),[a]),t.length<2)return null;const m=Math.min(c,t.length-1),b=t[m],C=r===b.messageId,M=(A,I)=>{const j=I.getBoundingClientRect();d(fa(A,j.top,j.height,t.length))};return e.jsxs("div",{className:`query-navigation-rail${u?" query-navigation-rail--open":""}`,style:{"--query-navigation-rail-height":`${ha(t.length)}px`,"--query-navigation-rail-web-height":`${ha(t.length,uu)}px`},role:"slider",tabIndex:0,"aria-label":"用户消息导航","aria-orientation":"vertical","aria-valuemin":1,"aria-valuemax":t.length,"aria-valuenow":b.ordinal,"aria-valuetext":`第 ${b.ordinal} 条:${b.preview}`,"aria-busy":C||void 0,onPointerEnter:A=>{h(!0),M(A.clientY,A.currentTarget)},onPointerMove:A=>{A.pointerType==="touch"&&!g.current||M(A.clientY,A.currentTarget)},onPointerLeave:()=>{g.current||h(!1)},onPointerDown:A=>{g.current=!0,h(!0),A.currentTarget.setPointerCapture(A.pointerId),M(A.clientY,A.currentTarget)},onPointerUp:A=>{M(A.clientY,A.currentTarget);const I=fa(A.clientY,A.currentTarget.getBoundingClientRect().top,A.currentTarget.getBoundingClientRect().height,t.length);g.current=!1,A.currentTarget.releasePointerCapture(A.pointerId),s(t[I]),A.pointerType==="touch"&&h(!1)},onPointerCancel:()=>{g.current=!1,h(!1)},onFocus:()=>h(!0),onBlur:()=>h(!1),onKeyDown:A=>{if(A.key==="Enter"){A.preventDefault(),s(b);return}const I=fu(m,A.key,t.length);I!==null&&(A.preventDefault(),d(I))},children:[e.jsxs("div",{className:"query-navigation-rail__track","aria-hidden":"true",children:[y.map(A=>e.jsx("span",{className:`query-navigation-rail__tick${A===m?" is-selected":""}${t[A].messageId===n?" is-active":""}`},A)),e.jsx("span",{className:"query-navigation-rail__marker",style:{top:`${m/Math.max(1,t.length-1)*100}%`}})]}),C&&e.jsx("span",{className:"query-navigation-rail__loading",role:"status","aria-label":"正在定位消息",children:e.jsx(Nt,{size:14,"aria-hidden":"true"})}),u&&e.jsxs("div",{className:"query-navigation-rail__preview",role:"status",children:[e.jsxs("span",{children:[b.ordinal," / ",t.length]}),e.jsx("p",{children:b.preview})]})]})}const gu=/^(?:load failed|failed to fetch|network request failed|networkerror when attempting to fetch resource\.?|the network connection was lost\.?|fetch failed)$/i;function yl(t){return t instanceof Error&&t.name!=="AbortError"&&gu.test(t.message.trim())}function xu(t){return yl(t)?"网络连接中断,会话加载失败,请重新加载":t instanceof Error?t.message:"会话加载失败"}async function mu(t,n={}){const r=Math.max(1,Math.floor(n.maxAttempts??4)),s=Math.max(0,n.baseDelayMs??500),o=n.sleep??(a=>new Promise(c=>{setTimeout(c,a)}));for(let a=1;a<=r;a+=1)try{return await t()}catch(c){if(a===r||!yl(c))throw c;await o(s*2**(a-1))}throw new Error("会话加载失败")}const bu=2048,yu=2*1024*1024,vu=.85;function wu(t,n,r=bu){const s=Math.max(t,n);if(s<=r)return{width:t,height:n};const o=r/s;return{width:Math.max(1,Math.round(t*o)),height:Math.max(1,Math.round(n*o))}}async function ga(t,n=ju){if(t.type.toLowerCase()==="image/gif")return t;let r=null;try{r=await n.decode(t);const s=wu(r.width,r.height);if(!(s.width!==r.width||s.height!==r.height)&&t.size<=yu)return t;const a=t.type.toLowerCase()==="image/jpeg"?"image/jpeg":"image/webp",c=await n.encode(r,s.width,s.height,a,vu);return c&&c.size<t.size?c:t}catch{return t}finally{r==null||r.dispose()}}const ju={decode(t){return new Promise((n,r)=>{const s=URL.createObjectURL(t),o=new Image;let a=!1;const c=()=>URL.revokeObjectURL(s);o.onload=()=>{a=!0,n({source:o,width:o.naturalWidth,height:o.naturalHeight,dispose:c})},o.onerror=()=>{a||c(),r(new Error("无法解码图片"))},o.src=s})},encode(t,n,r,s,o){const a=document.createElement("canvas");a.width=n,a.height=r;const c=a.getContext("2d");return c?(c.drawImage(t.source,0,0,n,r),new Promise(d=>a.toBlob(d,s,o))):Promise.resolve(null)}};function ku(t){return t==="customer-agent"||t==="claude-code"}function Su(t){if(typeof document>"u"||!document.body||typeof document.execCommand!="function")return!1;const n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),Object.assign(n.style,{position:"fixed",top:"0",left:"-9999px",width:"1px",height:"1px",fontSize:"16px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(n);try{return n.focus(),n.select(),n.setSelectionRange(0,n.value.length),document.execCommand("copy")}catch{return!1}finally{n.remove()}}async function vo(t){const n=typeof navigator>"u"?void 0:navigator.clipboard;if(typeof(n==null?void 0:n.writeText)=="function"&&(typeof isSecureContext>"u"||isSecureContext))try{return await n.writeText(t),!0}catch{}return Su(t)}const Iu="agentroam:draft:";function Fs(t){return`${Iu}${t}`}function Cu(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(Fs(t))??""}catch{return""}}function wo(t,n){if(!(!t||typeof window>"u"))try{n?window.localStorage.setItem(Fs(t),n):window.localStorage.removeItem(Fs(t))}catch{}}function Ru(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(Fs(t))}catch{}}const Au="agent-webapp:artifact-open:v1";let xa=0;function ma(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function vl(t,n){const r=t.trim();if(!r||/[\0\r\n]/.test(r))return null;if(ma(r))return r;if(!n||!ma(n))return null;const s=r.replaceAll("\\","/").split("/").filter(a=>a&&a!==".");if(s.length===0||s.some(a=>a===".."))return null;const o=/^[A-Za-z]:[\\/]/.test(n)||n.startsWith("\\\\")?"\\":"/";return`${n.replace(/[\\/]+$/,"")}${o}${s.join(o)}`}function vr(t,n=window){return n.parent===n?!1:(xa+=1,n.parent.postMessage({type:Au,requestId:xa,path:t},n.location.origin),!0)}function Mu(t){var n;return((n=[...t].reverse().find(r=>r.role==="user"&&!r.isQueued))==null?void 0:n.id)??null}function Eu(t,n){const r=new Set(n.flatMap(s=>s.sourceMessageId?[s.sourceMessageId]:[]));return r.size===0?t:t.filter(s=>!r.has(s.id))}function jo(t,n){var c,d,u;const r=t.filter(h=>!h.isQueued),s=new Map(t.filter(h=>h.isQueued&&h.queueItemId).map(h=>[h.queueItemId,h])),o=((c=n.active)==null?void 0:c.kind)==="message"?n.active:null;if(o){const h=s.get(o.id),g=o.sourceMessageId||(h==null?void 0:h.id)||o.id,y=r.findLastIndex(M=>M.role==="user"),m=r.findLastIndex((M,A)=>M.id===g||M.queueItemId===o.id||!h&&A===y&&M.role==="user"&&M.content===o.objective),b=m>=0?r[m]:h,C={...b??{},id:(b==null?void 0:b.id)||g,role:"user",content:o.objective,timestamp:(b==null?void 0:b.timestamp)??o.createdAt,agentName:(b==null?void 0:b.agentName)??((d=o.messagePayload)==null?void 0:d.agentName),images:(b==null?void 0:b.images)??((u=o.messagePayload)==null?void 0:u.images),isQueued:!1,queueItemId:void 0};m>=0?r[m]=C:r.push(C)}const a=n.queued.filter(h=>h.kind==="message").map(h=>{var y,m;const g=s.get(h.id);return{...g??{},id:h.sourceMessageId||(g==null?void 0:g.id)||h.id,role:"user",content:h.objective,timestamp:(g==null?void 0:g.timestamp)??h.createdAt,agentName:(y=h.messagePayload)==null?void 0:y.agentName,images:(m=h.messagePayload)==null?void 0:m.images,isQueued:!0,queueItemId:h.id}});return[...r,...a]}function ba(t){var n;return{active:((n=t.active)==null?void 0:n.kind)==="message"?null:t.active,queued:t.queued.filter(r=>r.kind!=="message"),history:t.history.filter(r=>r.kind!=="message")}}function Tu(t,n,r){if(n===r)return t;const s=t.filter(h=>h.isQueued),o=s.findIndex(h=>h.id===n),a=s.findIndex(h=>h.id===r);if(o<0||a<0)return t;const c=[...s],[d]=c.splice(o,1);c.splice(a,0,d);let u=0;return t.map(h=>h.isQueued?c[u++]:h)}function Nu(t,n){return((t==null?void 0:t.agentType)??n)!=="customer-agent"}function ti(t){return(t==null?void 0:t.agentType)!==void 0&&t.agentType!=="customer-agent"&&t.status==="running"}function zu(t){return ti(t)&&(t==null?void 0:t.occupancy)==="owned-externally"}function wl(t){return ti(t)&&(t==null?void 0:t.occupancy)!=="owned-externally"}function Lu(t){return(t==null?void 0:t.agentType)==="customer-agent"&&t.status==="active"}function _u(t,n){return n||wl(t)}function Pu(t,n,r){return!!(n&&t&&t.agentType!=="customer-agent")}function zs(t,n){return t.find(r=>r.id===n)??null}const Vs=Xa((t,n)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",setField:(r,s)=>t(o=>{const a={...o,[r]:s};return a.isConfigured=!!(a.apiKey&&a.modelId),a}),loadFromSystem:async()=>{if(window.agentApi)try{const r=await window.agentApi.getSettings(),s=r.profiles??[],o=r.activeProfileId??"",a=zs(s,o);t({revision:r.revision,modelProvider:(a==null?void 0:a.provider)??r.modelProvider??"anthropic",modelId:(a==null?void 0:a.modelId)??r.modelId??"claude-sonnet-4-6",apiKey:(a==null?void 0:a.apiKey)??r.apiKey??"",baseUrl:(a==null?void 0:a.baseUrl)??r.baseUrl??"",maxIterations:r.maxIterations??10,contextWindow:r.contextWindow??100,workingDirectory:r.workingDirectory??"/",isConfigured:!!(((a==null?void 0:a.apiKey)??r.apiKey)&&((a==null?void 0:a.modelId)??r.modelId)),profiles:s,activeProfileId:o,reasoningEffort:["off","low","medium","high"].includes(r.reasoningEffort??"")?r.reasoningEffort:"off"})}catch(r){console.error("Failed to load settings:",r)}},saveToSystem:async()=>{if(!window.agentApi)return;const r=n();await window.agentApi.saveSettings({revision:r.revision,modelProvider:r.modelProvider,modelId:r.modelId,apiKey:r.apiKey,baseUrl:r.baseUrl,maxIterations:r.maxIterations,contextWindow:r.contextWindow,workingDirectory:r.workingDirectory,isConfigured:r.isConfigured,profiles:r.profiles,activeProfileId:r.activeProfileId,reasoningEffort:r.reasoningEffort}),await n().loadFromSystem()},addProfile:r=>{const o={id:crypto.randomUUID(),...r};t(a=>({profiles:[...a.profiles,o]}))},updateProfile:(r,s)=>{t(a=>({profiles:a.profiles.map(c=>c.id===r?{...c,...s}:c)}));const o=n();if(o.activeProfileId===r){const a=zs(o.profiles,r);a&&t({modelProvider:a.provider,modelId:a.modelId,apiKey:a.apiKey,baseUrl:a.baseUrl,isConfigured:!!(a.apiKey&&a.modelId)})}},deleteProfile:r=>{t(s=>{var d;const o=s.profiles.filter(u=>u.id!==r),a=s.activeProfileId===r?((d=o[0])==null?void 0:d.id)??"":s.activeProfileId,c=zs(o,a);return{profiles:o,activeProfileId:a,...c?{modelProvider:c.provider,modelId:c.modelId,apiKey:c.apiKey,baseUrl:c.baseUrl,isConfigured:!!(c.apiKey&&c.modelId)}:{},...c?{}:{modelProvider:"anthropic",modelId:"",apiKey:"",baseUrl:"",isConfigured:!1}}})},setActiveProfileLocal:r=>{const s=n(),o=zs(s.profiles,r);o&&t({activeProfileId:r,modelProvider:o.provider,modelId:o.modelId,apiKey:o.apiKey,baseUrl:o.baseUrl,isConfigured:!!(o.apiKey&&o.modelId)})},switchActiveProfile:async r=>{window.agentApi&&(await window.agentApi.setActiveProfile(r),await n().loadFromSystem())}}));function Vr(t){return t.result!==void 0||t.resultRef!==void 0}function ko(t){return t.every(Vr)}const ni=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),jl=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),kl=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]),Wu=new Set(["Read","read_file"]),Du=new Set(["Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]);function ri(t){return ni.has(t)?"command":jl.has(t)?"file":kl.has(t)?"search":"generic"}function si(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 Bu(t){var n;return((n=si(t))==null?void 0:n.done)??null}function Sl(t){return ni.has(t)?"终端":Wu.has(t)?"查阅":Du.has(t)?"写入":kl.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 So(t,n=60){const r=(t??"").split(`
346
- `)[0].trim();return r.length>n?r.slice(0,n)+"…":r}function $u(t,n){if(ni.has(t))return So(String(n.command??""));if(t==="apply_patch"){const s=(Array.isArray(n.changes)?n.changes:[]).map(o=>ya(String((o==null?void 0:o.path)??""))).filter(Boolean);return s.length?s.length<=3?s.join("、"):`${s.slice(0,3).join("、")} 等 ${s.length} 个文件`:null}return jl.has(t)?n.file_path?ya(String(n.file_path)):null:t==="Glob"||t==="glob_search"?String(n.pattern??"")||null:t==="Grep"||t==="grep_search"?String(n.pattern??n.query??"")||null:t==="Skill"?String(n.skill??"")||null:t==="Task"?So(String(n.description??n.task??""),80)||null:t==="WebSearch"?So(String(n.query??"")):t==="WebFetch"?String(n.url??"")||null:t.startsWith("mcp__")?t.split("__").slice(1).join("/"):t.includes(":")?t.split(":").slice(1).join(":"):null}function Ou(t,n){return Math.max(0,Math.floor((n-t)/1e3))}function oi({startedAt:t}){const[n,r]=l.useState(()=>Date.now());return l.useEffect(()=>{r(Date.now());const s=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(s)},[t]),e.jsxs("span",{className:"activity-elapsed-time",children:[" · 持续了 ",Ou(t,n)," 秒"]})}function Il({progress:t,compact:n=!1,startedAt:r}){const s=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),o=[t.label,s].filter(Boolean).join(","),a=!n&&t.phase==="thinking",c=!n&&t.phase==="status",d=a&&r!==void 0&&s===void 0;return e.jsxs("div",{className:`runtime-progress-row${n?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":o,children:[a?e.jsx("span",{className:"runtime-progress-row__brain","aria-hidden":"true",children:e.jsx(Xo,{size:17,strokeWidth:1.8})}):c?e.jsx("span",{className:"runtime-progress-row__status-icon","aria-hidden":"true",children:e.jsx(Nt,{size:17,strokeWidth:1.8})}):e.jsx("span",{className:"runtime-progress-row__spinner","aria-hidden":"true"}),e.jsx("span",{className:"runtime-progress-row__label",children:t.label}),s&&e.jsx("span",{className:"runtime-progress-row__detail",children:s}),d&&e.jsx(oi,{startedAt:r})]})}function Kr({isDone:t,isError:n,color:r,size:s=11}){return t?n?e.jsx(Dc,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Fr,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(Nt,{size:s,color:r,strokeWidth:2.5,style:{animation:"spin 1s linear infinite",flexShrink:0},"aria-hidden":"true"})}function ys({name:t,color:n,size:r=14}){const s=ri(t);return s==="command"?e.jsx(xd,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="search"?e.jsx(rl,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="file"?t==="Read"||t==="read_file"?e.jsx(qs,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(tl,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Skill"?e.jsx(gd,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="TodoWrite"?e.jsx(td,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Task"||t==="dispatch_agent"||t==="Agent"?e.jsx(yd,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(sl,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"})}function Ks({statusColor:t,isDone:n,expanded:r,onToggle:s,header:o,children:a,maxBodyHeight:c=600,primaryAction:d,primaryActionLabel:u,primaryActionTitle:h}){const g=e.jsxs("button",{type:"button",className:"tool-call-shell__header",...d?{onClick:d,"aria-label":u,title:h}:{onClick:s,"aria-expanded":r},style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:y=>y.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:y=>y.currentTarget.style.background="var(--bg-deep)",children:[o,!d&&e.jsx(Ur,{className:"tool-call-shell__chevron",size:12,color:"var(--text-muted)",strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:r?"rotate(90deg)":"rotate(0deg)",flexShrink:0},"aria-hidden":"true"})]});return e.jsxs("div",{className:"tool-call-shell",style:{marginTop:4,borderRadius:9,border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-deepest)",fontSize:12,minWidth:0},children:[e.jsxs("div",{className:"tool-call-shell__row",style:{display:"flex",alignItems:"stretch"},children:[e.jsx("div",{className:"tool-call-shell__status",style:{width:3,flexShrink:0,background:t,animation:n?"none":"statusBarPulse 1.8s ease-in-out infinite",borderRadius:"9px 0 0 0"}}),g,d&&e.jsx("button",{type:"button",className:"tool-call-shell__disclosure",onClick:s,"aria-expanded":r,"aria-label":r?"收起工具详情":"展开工具详情",title:r?"收起工具详情":"展开工具详情",children:e.jsx(Ur,{className:"tool-call-shell__chevron",size:12,strokeWidth:2.2,style:{transition:"transform 0.25s var(--ease-out)",transform:r?"rotate(90deg)":"rotate(0deg)"},"aria-hidden":"true"})})]}),r&&e.jsx("div",{className:"tool-call-shell__body",style:{overflow:"hidden",maxHeight:c,opacity:1,transition:"max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease"},children:e.jsx("div",{className:"tool-call-shell__body-content",style:{borderTop:"1px solid var(--border-subtle)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8,boxSizing:"border-box",maxWidth:"100%"},children:a})})]})}function bs({label:t,color:n="var(--text-muted)",bg:r="var(--bg-surface)"}){return e.jsx("span",{style:{fontSize:10,padding:"1px 7px",borderRadius:20,background:r,color:n,fontWeight:500,flexShrink:0,whiteSpace:"nowrap"},children:t})}function _n(t){return t.replace(/\\/g,"/").split("/").pop()??t}function Cl(t){return t?t.split(`
347
- `).length:0}function Gs(t,n,r=!1){const[s,o]=l.useState(r),[a,c]=l.useState(!1),[d,u]=l.useState(null),h=async()=>{if(!(!t.resultRef||t.result!==void 0||a||!n)){c(!0),u(null);try{await n(t.resultRef)}catch(y){u(y instanceof Error?y.message:"工具结果加载失败")}finally{c(!1)}}};return{expanded:s,setExpanded:o,toggle:()=>{const y=!s;o(y),y&&h()},loadingResult:a,resultError:d,loadResult:h}}function Qs({toolCall:t,loading:n,error:r,retry:s}){return!t.resultRef||t.result!==void 0?null:r?e.jsx("button",{type:"button",onClick:()=>void s(),className:"ui-text-button",children:"重新加载工具结果"}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,color:"var(--text-muted)",fontSize:11},children:[e.jsx(Nt,{size:11,strokeWidth:2.2,style:{animation:n?"spin 1s linear infinite":"none"},"aria-hidden":"true"}),n?"正在加载工具结果":`${t.resultRef.byteSize.toLocaleString()} 字节,展开后加载`]})}function Rl(t,n){const r=t.split(`
348
- `),s=n.split(`
349
- `);if(r.length*s.length>2e5)return s.map((b,C)=>({type:"added",text:b,lineNo:C+1}));const o=r.length,a=s.length,c=Array.from({length:o+1},()=>new Array(a+1).fill(0));for(let b=1;b<=o;b++)for(let C=1;C<=a;C++)c[b][C]=r[b-1]===s[C-1]?c[b-1][C-1]+1:Math.max(c[b-1][C],c[b][C-1]);const d=[];let u=o,h=a;for(;u>0&&h>0;)r[u-1]===s[h-1]?(d.unshift([u-1,h-1]),u--,h--):c[u-1][h]>=c[u][h-1]?u--:h--;const g=[];let y=0,m=0;for(const[b,C]of d){for(;y<b;)g.push({type:"removed",text:r[y],lineNo:y+1}),y++;for(;m<C;)g.push({type:"added",text:s[m],lineNo:m+1}),m++;g.push({type:"same",text:r[y],lineNo:y+1}),y++,m++}for(;y<o;)g.push({type:"removed",text:r[y],lineNo:y+1}),y++;for(;m<a;)g.push({type:"added",text:s[m],lineNo:m+1}),m++;return g}function Al({content:t,maxHeight:n=320}){const r=t.split(`
350
- `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:n,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:r.map((s,o)=>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:o+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:s||" "})]},o))})]})})}function Ml({diff:t,maxHeight:n=360}){if(t.filter(d=>d.type!=="same").length===0)return e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",padding:"10px 12px",fontFamily:"var(--font-mono)"},children:"内容未变化"});const s=new Set(t.map((d,u)=>d.type!=="same"?u:-1).filter(d=>d>=0)),o=new Set;s.forEach(d=>{for(let u=Math.max(0,d-3);u<=Math.min(t.length-1,d+3);u++)o.add(u)});const a=[];let c=-1;return[...o].sort((d,u)=>d-u).forEach(d=>{c>=0&&d>c+1&&a.push("ellipsis"),a.push({diffLine:t[d],diffIdx:d}),c=d}),e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:n,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:24}}),e.jsx("col",{style:{width:36}}),e.jsx("col",{})]}),e.jsx("tbody",{children:a.map((d,u)=>{if(d==="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${u}`);const{diffLine:h}=d,g=h.type==="added"?"rgba(5,150,105,0.08)":h.type==="removed"?"rgba(220,38,38,0.07)":"transparent",y=h.type==="added"?"+":h.type==="removed"?"−":" ",m=h.type==="added"?"var(--success)":h.type==="removed"?"var(--danger)":"transparent",b=h.type==="added"?"#059669":h.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:g},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:m,fontWeight:700,userSelect:"none"},children:y}),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:b,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:h.text||" "})]},u)})})]})})}function Fu({toolCall:t,beforeContent:n,previewPath:r,onLoadResult:s}){const o=Gs(t,s),{expanded:a}=o,[c,d]=l.useState("content"),u=t.arguments.file_path??"",h=t.arguments.content??"",g=Cl(h),y=t.isError,m=Vr(t),b=m?y?"var(--danger)":"var(--success)":"var(--accent)",C=l.useMemo(()=>n&&h?Rl(n,h):null,[n,h]),M=l.useMemo(()=>C?{added:C.filter(j=>j.type==="added").length,removed:C.filter(j=>j.type==="removed").length}:null,[C]),A=y?"var(--danger)":m?"var(--text-muted)":"var(--accent)",I=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(ys,{name:t.name,color:A})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:u,children:_n(u)}),e.jsx(bs,{label:`${g} 行`,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]})]}),(!m||y)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:b},children:[e.jsx(Kr,{isDone:m,isError:y,color:b}),y&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Ks,{statusColor:b,isDone:m,expanded:a,onToggle:o.toggle,header:I,primaryAction:r?()=>vr(r):void 0,primaryActionLabel:r?`预览文件 ${_n(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx(Qs,{toolCall:t,loading:o.loadingResult,error:o.resultError,retry:o.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:u}),C&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(j=>e.jsx("button",{onClick:()=>d(j),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:c===j?"var(--accent-dim)":"transparent",color:c===j?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:j==="content"?"文件内容":"变更行"},j))}),c==="diff"&&C?e.jsx(Ml,{diff:C}):e.jsx(Al,{content:h}),y&&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 Hu({toolCall:t,previewPath:n,onLoadResult:r}){const s=Gs(t,r),{expanded:o}=s,a=t.arguments.file_path??"",c=t.arguments.startLine,d=t.arguments.endLine,u=t.arguments.offset,h=t.arguments.limit,g=t.result??"",y=Cl(g),m=t.isError,b=Vr(t),C=b?m?"var(--danger)":"var(--success)":"var(--accent)",M=c!==void 0?`L${c}–${d??"?"}`:u!==void 0?`第${u}行起${h?` ×${h}`:""}`:null,A=m?"var(--danger)":b?"var(--text-muted)":"var(--accent)",I=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(ys,{name:t.name,color:A})}),e.jsx("span",{className:"tool-call-shell__label",children:"查阅"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:_n(a)}),M&&e.jsx(bs,{label:M,color:"var(--accent)",bg:"var(--accent-dim)"}),b&&!m&&e.jsx(bs,{label:`${y} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),(!b||m)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:C},children:[e.jsx(Kr,{isDone:b,isError:m,color:C}),m&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Ks,{statusColor:C,isDone:b,expanded:o,onToggle:s.toggle,header:I,maxBodyHeight:480,primaryAction:n?()=>vr(n):void 0,primaryActionLabel:n?`预览文件 ${_n(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(Qs,{toolCall:t,loading:s.loadingResult,error:s.resultError,retry:s.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),b&&!m?e.jsx(Al,{content:g}):b&&m&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:g})]})}function Uu({toolCall:t,previewPath:n,onLoadResult:r}){const s=Gs(t,r),{expanded:o}=s,a=t.arguments.file_path??"",c=t.arguments.old_string??"",d=t.arguments.new_string??"",u=t.isError,h=Vr(t),g=h?u?"var(--danger)":"var(--success)":"var(--accent)",y=u?"var(--danger)":h?"var(--text-muted)":"var(--accent)",m=l.useMemo(()=>c&&d?Rl(c,d):null,[c,d]),b=l.useMemo(()=>m?{added:m.filter(M=>M.type==="added").length,removed:m.filter(M=>M.type==="removed").length}:null,[m]),C=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(ys,{name:t.name,color:y})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:a,children:_n(a)}),b&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[b.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",b.added]}),b.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",b.removed]})]}),(!h||u)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:g},children:[e.jsx(Kr,{isDone:h,isError:u,color:g}),u&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Ks,{statusColor:g,isDone:h,expanded:o,onToggle:s.toggle,header:C,maxBodyHeight:480,primaryAction:n?()=>vr(n):void 0,primaryActionLabel:n?`预览文件 ${_n(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(Qs,{toolCall:t,loading:s.loadingResult,error:s.resultError,retry:s.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:a}),m?e.jsx(Ml,{diff:m}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("pre",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.12)",borderLeft:"3px solid var(--danger)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:c}),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:d})]}),u&&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 Hr({label:t,content:n,error:r,maxPreviewLines:s=8,maxPreviewHeight:o=200,maxExpandedHeight:a=2e3}){const[c,d]=l.useState(!1),u=n.split(`
351
- `),h=u.length>s,g=h&&!c?u.slice(0,s).join(`
352
- `)+`
353
- ...`:n;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:t}),e.jsx("pre",{style:{fontSize:11,color:r?"var(--danger)":"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,boxSizing:"border-box",maxWidth:"100%",background:r?"rgba(220,38,38,0.04)":"var(--bg-surface)",border:r?"1px solid rgba(220,38,38,0.15)":"1px solid var(--border-subtle)",borderLeft:r?"3px solid var(--danger)":"3px solid var(--success)",maxHeight:c?a:o,overflow:"auto",margin:0,lineHeight:1.6},children:g}),h&&e.jsx("button",{onClick:()=>d(!c),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:c?"收起":`展开全部 (${u.length} 行)`})]})}function qu({arguments:t}){var r;const n=t.task??"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 0"},children:[e.jsxs("div",{style:{display:"flex",gap:8,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",flexWrap:"wrap"},children:[e.jsx(bs,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(bs,{label:`sid: ${(r=t.subSessionId)==null?void 0:r.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),n&&e.jsx(Hr,{label:"任务",content:n,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Vu({raw:t}){const[n,r]=l.useState(!1);let s;try{const u=JSON.parse(t);delete u.subAgentProgress,delete u.subAgentStatus,delete u.subAgentDetail,s=JSON.stringify(u,null,2)}catch{s=t}const o=8,a=s.split(`
354
- `),c=a.length>o,d=c&&!n?a.slice(0,o).join(`
355
- `)+`
356
- ...`:s;return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:5},children:"参数"}),e.jsx("pre",{style:{fontSize:11,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--font-mono)",padding:"9px 11px",borderRadius:7,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",maxHeight:n?2e3:200,overflow:"auto",margin:0,lineHeight:1.6,boxSizing:"border-box",maxWidth:"100%"},children:d}),c&&e.jsx("button",{onClick:()=>r(!n),style:{marginTop:4,padding:"2px 10px",borderRadius:5,border:"1px solid var(--border-subtle)",background:"var(--bg-deep)",color:"var(--text-muted)",fontSize:10,cursor:"pointer",fontWeight:500},children:n?"收起":`展开全部 (${a.length} 行)`})]})}function Ku({activity:t,workspacePath:n,enableFilePreview:r}){const s=new Map(t.messages.flatMap(o=>o.role==="tool"&&o.toolCallId?[[o.toolCallId,{content:o.content,isError:o.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((o,a)=>{var c;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[o.role==="assistant"&&o.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:o.content}),o.role==="assistant"&&((c=o.toolCalls)==null?void 0:c.map(d=>{const u=s.get(d.id);return e.jsxs("div",{className:"native-subagent-activity__tool",children:[e.jsx(Ys,{toolCall:{...d,...u?{result:u.content,isError:u.isError}:{}},workspacePath:n,enableFilePreview:r}),u&&e.jsx("pre",{className:`native-subagent-activity__tool-result${u.isError?" native-subagent-activity__tool-result--error":""}`,children:u.content})]},d.id)})),o.role==="tool"&&o.toolCallId&&!t.messages.some(d=>{var u;return(u=d.toolCalls)==null?void 0:u.some(h=>h.id===o.toolCallId)})&&e.jsx(Hr,{label:"工具结果",content:o.content,error:o.name==="error",maxPreviewHeight:180})]},`${o.role}-${a}`)}),t.summary&&e.jsx(Hr,{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(Kr,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function Gu({toolCall:t,onSelectSession:n,nativeSubagent:r,previewPaths:s,workspacePath:o,enableFilePreview:a,onLoadResult:c}){const d=We(ae=>ae.runningSessionId),u=Gs(t,c,!!r),{expanded:h,setExpanded:g}=u,y=t.name==="dispatch_agent",m=t.name==="Agent"&&!!r,b=t.arguments.subAgentStatus,C=t.arguments.subAgentDetail,M=t.arguments.subAgentProgress,A=Vr(t);l.useEffect(()=>{y&&!b&&M&&g(!0),m&&(r.messages.length>0||r.summary)&&g(!0)},[y,m,r,b,M]);const I=y?b==="failed":m?r.status==="failed":t.isError,j=y?!!b||A&&!d:m?r.status!=="running":A,S=j?I?"var(--danger)":"var(--success)":"var(--accent)",P=I?"var(--danger)":j?"var(--text-muted)":"var(--accent)",K=y?null:si(t.name),R=I?"错误":K?"":m?r.status==="stopped"?"已停止":j?"已完成":"运行中":y?b==="failed"?"失败":j?"已完成":"运行中":j?"完成":"执行中",T=m?r.description:y?(()=>{const ve=(t.arguments.task??"").split(`
357
- `)[0];return ve.length>80?ve.slice(0,80)+"…":ve})():$u(t.name,t.arguments),_=m?`@${r.agentName??"agent"}`:y?`@${t.arguments.agentName??"agent"}`:Sl(t.name)??t.name,k=ri(t.name),W=!j||!!I||!!R,Q=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(ys,{name:t.name,color:P})}),e.jsx("span",{className:"tool-call-shell__label",title:K?t.name:void 0,style:{fontFamily:K?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:_}),T&&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:T}),!T&&e.jsx("span",{style:{flex:1}}),W&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:S},children:[e.jsx(Kr,{isDone:j,isError:!!I,color:S}),R&&e.jsx("span",{children:R})]})]});return e.jsxs(Ks,{statusColor:S,isDone:j,expanded:h,onToggle:u.toggle,header:Q,maxBodyHeight:800,primaryAction:s.length===1?()=>vr(s[0]):void 0,primaryActionLabel:s.length===1?`预览文件 ${_n(s[0])}`:void 0,primaryActionTitle:s.length===1?`预览 ${s[0]}`:void 0,children:[e.jsx(Qs,{toolCall:t,loading:u.loadingResult,error:u.resultError,retry:u.loadResult}),s.length>1&&e.jsx("div",{className:"tool-call-file-list","aria-label":"改动文件",children:s.map(ae=>e.jsxs("button",{type:"button",onClick:()=>vr(ae),"aria-label":`预览文件 ${_n(ae)}`,title:`预览 ${ae}`,children:[e.jsx(qs,{size:12,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:_n(ae)})]},ae))}),m?e.jsx(Ku,{activity:r,workspacePath:o,enableFilePreview:a}):y?e.jsx(qu,{arguments:t.arguments}):k==="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(Hr,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(Vu,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!y&&!m&&e.jsx(Hr,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),y&&b&&C&&e.jsx(Hr,{label:b==="failed"?"错误信息":"执行摘要",content:C,error:b==="failed",maxPreviewHeight:180}),y&&!b&&M&&(!!d||!A)&&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:[M,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:"​"})]})]}),y&&!b&&!M&&!!d&&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(ae=>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:`${ae*.16}s`}},ae)),"等待子 agent 响应..."]}),y&&t.arguments.subSessionId&&n&&e.jsxs("button",{onClick:()=>n(t.arguments.subSessionId),style:{alignSelf:"flex-start",padding:"4px 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--accent-dim)",color:"var(--accent)",fontSize:11,fontWeight:500,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s"},onMouseEnter:ae=>{ae.currentTarget.style.background="var(--accent)",ae.currentTarget.style.color="white"},onMouseLeave:ae=>{ae.currentTarget.style.background="var(--accent-dim)",ae.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 El({items:t,onSelectSession:n,workspacePath:r,enableFilePreview:s,onLoadResult:o}){var C;const[a,c]=l.useState(!1),d=(C=t[0])==null?void 0:C.toolCall,u=d?si(d.name):null;if(!d||!u||t.length<2)return null;const h=t.every(({toolCall:M})=>Vr(M)),g=t.filter(({toolCall:M})=>M.isError).length,y=g>0?"var(--danger)":h?"var(--text-muted)":"var(--accent)",m=Sl(d.name)??u.done,b=`${m},${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":b,onClick:()=>c(M=>!M),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(ys,{name:d.name,color:y})}),e.jsx("span",{className:"tool-call-group__label",children:m}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),g>0&&e.jsxs("span",{className:"tool-call-group__error",children:[g," 项失败"]}),!h&&e.jsx(Kr,{isDone:!1,color:y,size:11}),e.jsx(Ur,{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:A,progress:I,nativeSubagent:j})=>e.jsx(Ys,{toolCall:M,beforeContent:A,progress:I,nativeSubagent:j,onSelectSession:n,workspacePath:r,enableFilePreview:s,onLoadResult:o},M.id))})]})}function Qu(t,n){if(ri(t.name)!=="file")return[];const r=t.name==="apply_patch"&&Array.isArray(t.arguments.changes)?t.arguments.changes.map(s=>s.path):[t.arguments.file_path??t.arguments.path??t.arguments.notebook_path];return[...new Set(r.filter(s=>typeof s=="string").map(s=>vl(s,n)).filter(s=>!!s))]}function Ys({toolCall:t,onSelectSession:n,beforeContent:r,progress:s,nativeSubagent:o,workspacePath:a,enableFilePreview:c=!1,onLoadResult:d}){const u=c?Qu(t,a):[],h=t.name==="write_file"?e.jsx(Fu,{toolCall:t,beforeContent:r,previewPath:u[0],onLoadResult:d}):t.name==="read_file"?e.jsx(Hu,{toolCall:t,previewPath:u[0],onLoadResult:d}):t.name==="str_replace"?e.jsx(Uu,{toolCall:t,previewPath:u[0],onLoadResult:d}):e.jsx(Gu,{toolCall:t,onSelectSession:n,nativeSubagent:o,previewPaths:u,workspacePath:a,enableFilePreview:c,onLoadResult:d});return e.jsxs("div",{className:"tool-call-with-progress",children:[h,s&&e.jsx(Il,{progress:s,compact:!0})]})}function Yu({question:t,options:n,fields:r,multiSelect:s,answered:o,answer:a,onAnswer:c}){const[d,u]=l.useState(new Set),[h,g]=l.useState(""),[y,m]=l.useState({}),b=l.useRef(!1),[C,M]=l.useState(!1),[A,I]=l.useState(""),j=async(k,W)=>{if(!(o||b.current)){b.current=!0,M(!0),I("");try{await c(k,W)}catch(Q){I(Q instanceof Error?Q.message:"回答发送失败,请重试。")}finally{b.current=!1,M(!1)}}},S=!!(n!=null&&n.length),P=!!(r!=null&&r.length),K=k=>{o||u(W=>{const Q=new Set(W);return s?Q.has(k)?Q.delete(k):Q.add(k):(Q.clear(),Q.add(k)),Q})},R=()=>{if(d.size===0)return;const k=Array.from(d).map(W=>n[W].label);j(k.join(", "),Array.from(d))},T=()=>{const k=Array.from(d).map(Q=>n[Q].label),W=Object.fromEntries((r??[]).map(Q=>{var ae;return[Q.name,((ae=y[Q.name])==null?void 0:ae.trim())??""]}));!W.model&&k.length>0&&(W.model=k[0]),!(!Object.values(W).some(Boolean)&&k.length===0)&&j(JSON.stringify({fields:W,selectedOptions:k}),Array.from(d))},_=()=>{h.trim()&&j(h.trim())};return e.jsxs("div",{style:{marginBottom:12},children:[A&&!o&&e.jsx("div",{role:"alert",style:{color:"var(--danger)",marginBottom:8},children:A}),C&&e.jsx("div",{role:"status",children:"正在发送回答…"}),e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:o?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:o?"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:o?"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:o?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:o?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:o?"var(--text-muted)":"var(--accent)",flex:1},children:o?"已回答":"向你提问"}),s&&!o&&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}),o&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),P?"配置已提交(敏感字段已隐藏)":a]}),S&&!o&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[n.map((k,W)=>{const Q=d.has(W);return e.jsxs("button",{onClick:()=>K(W),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:Q?"var(--accent)":"var(--border-subtle)",background:Q?"rgba(79,110,247,0.06)":"var(--bg-surface)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-body)",transition:"all 0.15s ease",width:"100%"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:s?4:8,border:`2px solid ${Q?"var(--accent)":"var(--border-subtle)"}`,background:Q?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:Q&&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:Q?600:500,color:Q?"var(--text-primary)":"var(--text-secondary)"},children:k.label}),k.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:k.description})]})]},W)}),!P&&e.jsx("button",{onClick:R,disabled:C||d.size===0,style:{marginTop:2,padding:"7px 16px",borderRadius:8,border:"none",background:d.size>0?"var(--accent)":"var(--bg-surface)",color:d.size>0?"white":"var(--text-muted)",cursor:d.size>0?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end",transition:"all 0.15s ease"},children:"确认选择"})]}),P&&!o&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[r.map(k=>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:k.label}),e.jsx("input",{type:k.type==="secret"?"password":"text",value:y[k.name]??"",onChange:W=>m(Q=>({...Q,[k.name]:W.target.value})),placeholder:k.description,autoComplete:k.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"}}),k.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:k.description})]},k.name)),e.jsx("button",{onClick:T,disabled:C,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:"确认配置"})]}),!o&&!P&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:S?"1px solid var(--border-subtle)":"none",marginTop:S?2:0},children:[e.jsx("input",{type:"text",value:h,onChange:k=>g(k.target.value),onKeyDown:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),_())},placeholder:S?"或输入自定义回答…":"输入你的回答…",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:k=>{k.currentTarget.style.borderColor="var(--accent)"},onBlur:k=>{k.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:_,disabled:C||!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 Io={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"}},Co={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 Xu(t,n){const r=(t==null?void 0:t.maxTokens)??Math.max(1,n*1e3),s=(t==null?void 0:t.totalTokens)??0,o=Object.fromEntries(va.map(c=>[c,0]));for(const c of(t==null?void 0:t.segments)??[]){const d=Io[c.category];d&&(o[d.group]+=c.tokens)}const a=Math.min(s/r,1);return{hasUsage:!!t,totalTokens:s,maxTokens:r,ratio:a,percent:Math.round(a*100),groups:va.map(c=>({key:c,label:Co[c].label,color:Co[c].color,tokens:o[c]})),details:((t==null?void 0:t.segments)??[]).filter(c=>c.tokens>0).map(c=>{var d,u;return{category:c.category,label:((d=Io[c.category])==null?void 0:d.label)??c.category,color:Co[((u=Io[c.category])==null?void 0:u.group)??"overhead"].color,tokens:c.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function Ko(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function wa(t,n){return n?`${t.percent}%`:t.hasUsage?`${Ko(t.totalTokens)} / ${Ko(t.maxTokens)} · ${t.percent}%`:"尚无模型请求"}function Zu({usage:t,contextWindowK:n,compact:r=!1}){const[s,o]=l.useState(!1),[a,c]=l.useState(null),d=l.useRef(null),u=l.useMemo(()=>Xu(t,n),[t,n]),h=u.ratio>=.85?"var(--danger)":u.ratio>=.6?"#f59e0b":"var(--accent)",g=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:d,type:"button",onClick:()=>{var m;const y=((m=d.current)==null?void 0:m.getBoundingClientRect())??null;c(y),o(b=>!b)},title:"查看完整请求上下文占用估算",style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"6px 10px",border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-body)"},children:r?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"context-usage-ribbon__ring",width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:"currentColor",strokeWidth:"4",opacity:"0.14"}),e.jsx("circle",{cx:"14",cy:"14",r:"10",fill:"none",stroke:u.hasUsage?h:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeDasharray:`${u.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(u,!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:u.groups.map(y=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(y.tokens/u.maxTokens*100,100))}%`,background:y.color,opacity:y.key==="overhead"?.65:1,minWidth:y.tokens>0?1:0}},y.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:u.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:wa(u,!1)})]})}),s&&a&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>o(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:r?Math.min(Math.max(8,a.left),Math.max(8,g-Math.min(340,g-16)-8)):Math.max(8,a.left),top:a.top-8,transform:"translateY(-100%)",width:Math.min(r?340:a.width,g-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:u.hasUsage?h:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:u.hasUsage?`${u.percent}%`:"暂无"})]}),u.requestLabel&&e.jsx("div",{style:{marginBottom:10,fontSize:10,color:"var(--text-muted)",wordBreak:"break-all"},children:u.requestLabel}),u.hasUsage?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:u.details.map(y=>{const m=u.totalTokens>0?Math.round(y.tokens/u.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:y.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:y.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[Ko(y.tokens)," · ",m,"%"]})]},y.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 Ju({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(Xo,{size:17,strokeWidth:1.8})}),e.jsxs("span",{children:["思考中",e.jsx(oi,{startedAt:t})]})]})}function Tl({sections:t,streaming:n=!1,startedAt:r,renderContent:s}){const o=l.useMemo(()=>[...t].sort((h,g)=>h.sectionIndex-g.sectionIndex).map(h=>h.text.trim()).filter(Boolean).join(`
358
-
359
- `),[t]),a=l.useMemo(()=>(o.split(`
360
- `).find(g=>g.trim())??"").replace(/^#{1,6}\s+/,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1"),[o]),[c,d]=l.useState(n);if(l.useEffect(()=>{d(n)},[n]),!o)return null;const u=n?"思考中":"思考";return e.jsxs("div",{className:"reasoning-summary",children:[e.jsxs("button",{type:"button",className:"reasoning-summary__toggle","aria-expanded":c,"aria-label":`${u},${c?"收起":"展开"}`,onClick:()=>d(h=>!h),children:[e.jsx("span",{className:"reasoning-summary__brain","aria-hidden":"true",children:e.jsx(Xo,{size:17,strokeWidth:1.8})}),e.jsxs("span",{className:"reasoning-summary__label",children:[u,n&&r!==void 0&&e.jsx(oi,{startedAt:r})]}),!c&&e.jsx("span",{className:"reasoning-summary__preview",children:a}),e.jsx("span",{className:"reasoning-summary__spacer"}),n&&e.jsx(Nt,{className:"reasoning-summary__spinner",size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx(Ur,{className:"reasoning-summary__chevron",size:13,strokeWidth:2,"aria-hidden":"true"})]}),c&&e.jsx("div",{className:"reasoning-summary__content",children:s(o)})]})}function Nl(t){var n,r;return t.role==="assistant"&&!!((n=t.toolCalls)!=null&&n.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((r=t.images)!=null&&r.length)&&!t.presentation}function ep(t){return Nl(t)&&t.content.trim().length===0}function zl(t){const n=[];for(const r of t){const s=n[n.length-1];if(s&&Nl(s)&&ep(r)){n[n.length-1]={...s,toolCalls:[...s.toolCalls,...r.toolCalls],timestamp:r.timestamp};continue}n.push(r)}return n}function Ll(t){const n=[];for(const r of t){const s=Bu(r.toolCall.name),o=n[n.length-1];s&&(o==null?void 0:o.action)===s?o.items.push(r):n.push({action:s,items:[r]})}return n}function tp({trace:t,loadTrace:n,loadToolResult:r,renderContent:s,runtimeProgress:o,nativeSubagents:a,onSelectSession:c,workspacePath:d,enableFilePreview:u=!1,refreshSignal:h=0,autoLoad:g=!1}){const y=t.turnId,m=l.useRef(y),b=l.useRef(t.revision),C=l.useRef(h),M=l.useRef(null),[A,I]=l.useState(!1),[j,S]=l.useState(null),[P,K]=l.useState(null);l.useEffect(()=>{m.current=y,M.current=null,I(!1),S(null),K(null),C.current=h},[y]),l.useEffect(()=>{b.current=t.revision,M.current=null,I(!1),S(ae=>(ae==null?void 0:ae.map(ve=>{var Te;return{...ve,toolCalls:(Te=ve.toolCalls)==null?void 0:Te.map(we=>we.resultRef?{...we,resultRef:{...we.resultRef,revision:t.revision}}:we)}}))??null)},[t.revision]);const R=t.liveMessages??[],T=l.useMemo(()=>Ud(j??[],R),[R,j]),_=j!==null||R.length>0,k=l.useCallback(async(ae=!1)=>{if(!ae&&j)return j;if(!ae&&R.length>0)return R;if(M.current)return M.current;const ve=y,Te=t.revision;I(!0),K(null);const we=n(t);M.current=we;try{const Z=await we;return m.current===ve&&b.current===Te&&S(Z),Z}catch(Z){throw m.current===ve&&b.current===Te&&K(Z instanceof Error?Z.message:"执行过程加载失败"),Z}finally{m.current===ve&&b.current===Te&&(M.current=null,I(!1))}},[R,n,j,y,t]);l.useEffect(()=>{!g||_||k().catch(()=>{})},[g,k,_]),l.useEffect(()=>{!_&&!g||h===0||C.current!==h&&(C.current=h,k(!0).catch(()=>{}))},[g,k,_,h]);const W=l.useCallback(async ae=>{const ve=await r(ae);m.current===y&&S(Te=>Te&&fl(Te,ae.itemId,ve.content,ve.isError))},[r,y]),Q=A?"正在加载执行过程":P?"重新加载执行过程":"查看执行过程";return e.jsx("div",{className:"codex-execution-trace","data-turn-id":t.turnId,children:_?e.jsx(np,{messages:T,renderContent:s,runtimeProgress:o,nativeSubagents:a,onSelectSession:c,workspacePath:d,enableFilePreview:u,onLoadResult:W}):g&&!P?e.jsxs("div",{className:"codex-execution-trace__status",role:"status","aria-live":"polite","aria-busy":"true",children:[e.jsx("span",{className:"codex-execution-trace__icon","aria-hidden":"true",children:e.jsx(Nt,{size:14,strokeWidth:2})}),e.jsx("span",{className:"codex-execution-trace__label",children:"正在加载会话"})]}):e.jsxs("button",{type:"button",className:"codex-execution-trace__load","aria-busy":A||void 0,disabled:A,onClick:()=>void k().catch(()=>{}),children:[e.jsx("span",{className:"codex-execution-trace__icon","aria-hidden":"true",children:A?e.jsx(Nt,{size:14,strokeWidth:2}):P?e.jsx(Ja,{size:14,strokeWidth:2}):e.jsx(wd,{size:14,strokeWidth:1.8})}),e.jsx("span",{className:"codex-execution-trace__label",children:Q}),P&&e.jsx("span",{className:"codex-execution-trace__error",children:"加载失败"})]})})}function np({messages:t,renderContent:n,runtimeProgress:r,nativeSubagents:s,onSelectSession:o,workspacePath:a,enableFilePreview:c,onLoadResult:d}){const u=l.useMemo(()=>{const h=new Map;return zl(t).map(g=>{const y=(g.toolCalls??[]).map(m=>{const b=typeof m.arguments.file_path=="string"?m.arguments.file_path:void 0,C=m.name==="write_file"&&b?h.get(b):void 0;return m.name==="read_file"&&b&&m.result!==void 0&&!m.isError&&h.set(b,m.result),{toolCall:m,beforeContent:C,progress:pl(r,m.id),nativeSubagent:s[m.id]}});return{message:g,toolGroups:Ll(y)}})},[t,s,r]);return u.length===0?e.jsx("div",{className:"codex-execution-trace__empty",children:"这一轮没有可显示的执行过程"}):e.jsx("div",{className:"codex-execution-trace__timeline",children:u.map(({message:h,toolGroups:g})=>{var y,m,b;return e.jsxs("div",{className:"codex-execution-trace__item",children:[(m=(y=h.presentation)==null?void 0:y.reasoning)!=null&&m.length?e.jsx(Tl,{sections:h.presentation.reasoning,renderContent:n}):null,((b=h.presentation)==null?void 0:b.agentMessagePhase)==="commentary"&&h.content?e.jsx("div",{className:"codex-execution-trace__commentary",children:n(h.content)}):null,g.map(C=>C.action&&C.items.length>1?e.jsx(El,{items:C.items,onSelectSession:o,workspacePath:a,enableFilePreview:c,onLoadResult:d},`group-${C.items[0].toolCall.id}`):e.jsx(Ys,{toolCall:C.items[0].toolCall,beforeContent:C.items[0].beforeContent,progress:C.items[0].progress,nativeSubagent:C.items[0].nativeSubagent,onSelectSession:o,workspacePath:a,enableFilePreview:c,onLoadResult:d},C.items[0].toolCall.id))]},h.id)})})}function rp({appearanceOpen:t,settingsOpen:n,showSettings:r=!0,hideToBackgroundTitle:s="隐藏到后台",codexReleaseState:o="idle",onHideToBackground:a,onReleaseCodex:c,onOpenHub:d,onOpenDesktopLive:u,desktopLiveOpen:h=!1,onToggleAppearance:g,onOpenSettings:y}){const m=o==="releasing"?"正在停止 AgentRoam 使用此会话":o==="released"?"已停止在 AgentRoam 中使用;Codex Desktop 最长约 30 分钟后可用":"停止在 AgentRoam 中使用(Codex Desktop 最长约 30 分钟后可用)";return e.jsxs("div",{className:"chat-header-actions",children:[u&&e.jsx("button",{type:"button",onClick:u,title:"桌面直播与远程控制","aria-label":"桌面直播与远程控制","aria-expanded":h,className:`ui-icon-button chat-header-action ${h?"is-active":""}`,children:e.jsx(ad,{size:15,"aria-hidden":"true"})}),d&&e.jsx("button",{type:"button",onClick:d,title:"AI Hub · 多模型网页对比","aria-label":"打开 AI Hub",className:"ui-icon-button chat-header-action chat-header-action--ai-hub",children:e.jsx(Jc,{size:15,"aria-hidden":"true"})}),c&&e.jsx("button",{type:"button",onClick:c,title:m,"aria-label":m,disabled:o!=="idle",className:`ui-icon-button chat-header-action chat-header-action--codex-release is-${o}`,children:o==="releasing"?e.jsx(Nt,{size:15,className:"spin","aria-hidden":"true"}):o==="released"?e.jsx(Fr,{size:15,"aria-hidden":"true"}):e.jsx(bd,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:a,title:s,"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:b=>g(b.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"})]})}),r&&e.jsx("button",{type:"button",onClick:y,title:"设置","aria-label":"设置","aria-expanded":n,className:`ui-icon-button chat-header-action chat-header-action--settings ${n?"is-active":""}`,children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]})}var Us,_l;class sp{constructor(){qi(this,Us);this.points=new Map,this.origin=null,this.originDistance=0,this.moved=!1}reset(){this.points.clear(),this.origin=null,this.originDistance=0,this.moved=!1}down(n,r){this.points.size||(this.origin=r,this.moved=!1),this.points.set(n,r),this.points.size>1&&(this.moved=!0),this.originDistance=Vi(this,Us,_l).call(this)}move(n,r){const s=this.points.get(n);if(!s)return null;const o=[...this.points.values()];if(this.points.set(n,r),this.origin&&Math.hypot(r.x-this.origin.x,r.y-this.origin.y)>8&&(this.moved=!0),this.points.size===1)return this.moved?{scale:1,distanceRatio:1,from:s,to:r,pointers:1}:null;const a=[...this.points.values()],c=g=>({x:(g[0].x+g[1].x)/2,y:(g[0].y+g[1].y)/2}),d=g=>Math.hypot(g[0].x-g[1].x,g[0].y-g[1].y),u=d(o),h=this.originDistance>0?d(a)/this.originDistance:1;return{scale:u>0?d(a)/u:1,distanceRatio:h,from:c(o),to:c(a),pointers:this.points.size}}up(n,r,s=!1){if(!this.points.has(n))return!1;const o=!s&&!this.moved&&this.points.size===1&&!!this.origin&&Math.hypot(r.x-this.origin.x,r.y-this.origin.y)<=8;return this.points.delete(n),s&&(this.moved=!0),this.points.size||this.reset(),o}}Us=new WeakSet,_l=function(){const n=[...this.points.values()];return n.length>=2?Math.hypot(n[0].x-n[1].x,n[0].y-n[1].y):0};const op={"agent-controlled":"Agent 操作中","handoff-requested":"正在交接","user-controlled":"你正在操作","return-requested":"正在归还",resyncing:"Agent 正在同步页面"};function ja(t){return t==="desktop"?"桌面屏幕":t==="ego-browser"?"ego-browser":"内置 Browser"}function ka(t,n,r){var s,o;return t||(((s=n.find(a=>a.agentSessionId===r))==null?void 0:s.id)??((o=n[0])==null?void 0:o.id)??null)}function Sa(t){return[t.altKey?"Alt":"",t.ctrlKey?"Control":"",t.metaKey?"Meta":"",t.shiftKey?"Shift":""].filter(Boolean)}const ip=2;function ap(t,n,r,s,o=.02){if(!t||!n||!n.width||!n.height)return!1;const a=t.x/n.width-o,c=t.y/n.height-o,d=(t.x+t.w)/n.width+o,u=(t.y+t.h)/n.height+o;return r>=a&&r<=d&&s>=c&&s<=u}function lp(t,n,r=ip){const s={deltaX:Math.round(t.x-n.x),deltaY:Math.round(t.y-n.y)};return Math.abs(s.deltaX)<r&&Math.abs(s.deltaY)<r?null:s}function cp({open:t,agentSessionId:n,onClose:r}){const s=l.useContext(Ac),o=typeof window>"u"?void 0:window.browserLiveApi,a=l.useRef(null),[c,d]=l.useState(!1),u=async()=>{const v=a.current;if(v){if(c){document.fullscreenElement===v&&await document.exitFullscreen().catch(()=>{}),d(!1);return}d(!0),v.requestFullscreen&&await v.requestFullscreen().catch(()=>{})}};l.useEffect(()=>{if(!t){d(!1);return}const v=a.current,D=()=>d(document.fullscreenElement===v),O=ie=>{ie.key==="Escape"&&(document.fullscreenElement===v||v!=null&&v.classList.contains("is-fullscreen"))&&(ie.preventDefault(),ie.stopPropagation(),document.fullscreenElement===v&&document.exitFullscreen().catch(()=>{}),d(!1))};return document.addEventListener("fullscreenchange",D),document.addEventListener("keydown",O,!0),()=>{document.removeEventListener("fullscreenchange",D),document.removeEventListener("keydown",O,!0),v&&document.fullscreenElement===v&&document.exitFullscreen().catch(()=>{})}},[t]);const[h,g]=l.useState([]),[y,m]=l.useState(null),[b,C]=l.useState(null),[M,A]=l.useState(!1),[I,j]=l.useState(0),[S,P]=l.useState(null),[K,R]=l.useState(!1),[T,_]=l.useState(1),[k,W]=l.useState(!1),[Q,ae]=l.useState({width:0,height:0}),ve=l.useRef(null),Te=l.useRef(null),we=l.useRef(!1),Z=l.useRef(null),me=l.useRef(new sp),Be=l.useRef(T),It=l.useRef(null);l.useLayoutEffect(()=>{Be.current=T;const v=It.current,D=ve.current,O=D==null?void 0:D.querySelector(".browser-live-image-hit-area");if(!v||!D||!O)return;const ie=O.getBoundingClientRect();D.scrollLeft+=ie.left+v.x*ie.width-v.clientX,D.scrollTop+=ie.top+v.y*ie.height-v.clientY,It.current=null},[T]);const tt=l.useRef(null),[De,xt]=l.useState(!1),nt=l.useRef(!1),z=l.useRef(null),te=l.useRef(0),[Ne,je]=l.useState(!1),Ce=l.useRef(null),Oe=l.useRef(0),xe=l.useRef("none"),Ee=l.useRef(null),lt=l.useRef(null),[$t,Fe]=l.useState(null),[Se,Ct]=l.useState(!1),zt=l.useRef(null),B=l.useRef(null),[F,V]=l.useState("off"),Y=l.useRef(null),ne=l.useRef(null);l.useLayoutEffect(()=>{nt.current=De,De&&je(!1)},[De]);const L=l.useMemo(()=>h.find(v=>v.id===y)??null,[y,h]),Ie=(L==null?void 0:L.backend)==="desktop",ke=(L==null?void 0:L.isController)&&L.state==="user-controlled";l.useEffect(()=>{if(!t||!o||!y){Fe(null);return}let v=!0;const D=()=>{const ie=performance.now();o.request("browser:ping",{t:ie}).then(()=>{v&&Fe(Math.round(performance.now()-ie))}).catch(()=>{v&&Fe(null)})};D();const O=window.setInterval(D,3e3);return()=>{v=!1,window.clearInterval(O),Fe(null)}},[o,t,y]),l.useEffect(()=>{const v=navigator;if(!ke||!v.wakeLock)return;let D=!1,O=null;return v.wakeLock.request("screen").then(ie=>{if(D){ie.release();return}O=ie,zt.current=ie}).catch(()=>{}),()=>{D=!0,O==null||O.release().catch(()=>{}),zt.current=null}},[ke]);const Lt=(b==null?void 0:b.viewport)??(L==null?void 0:L.viewport),ct=Lt&&Q.width&&Q.height?Math.min(Q.width/Lt.width,Q.height/Lt.height):null;l.useEffect(()=>{var v;_(1),W(!1),Te.current=null,me.current.reset(),It.current=null,z.current=null,B.current=null,(v=ve.current)==null||v.scrollTo(0,0)},[t,y]),l.useEffect(()=>{const v=ve.current;if(!t||!v)return;const D=new ResizeObserver(()=>{ae({width:v.clientWidth,height:v.clientHeight})});return D.observe(v),()=>D.disconnect()},[t,Ie]),l.useEffect(()=>{const v=ve.current;if(!t||!v||!ke||k)return;const D=O=>O.preventDefault();return v.addEventListener("wheel",D,{passive:!1}),()=>v.removeEventListener("wheel",D)},[t,ke,k]);const Ot=l.useCallback(()=>{const v=tt.current;v&&(De?(v.blur(),xt(!1)):(v.focus({preventScroll:!0}),xt(!0)))},[De]);l.useEffect(()=>{var v;(!ke||k)&&De&&((v=tt.current)==null||v.blur(),xt(!1))},[ke,k,De]);const Rt=l.useCallback(v=>{const D=(b==null?void 0:b.viewport)??(L==null?void 0:L.viewport),O=ve.current,ie=O==null?void 0:O.querySelector(".browser-live-image-hit-area");if(!v||!D||!O||!ie)return;const ue=ie.getBoundingClientRect(),_e=O.getBoundingClientRect(),Ke=ue.top+v.y/D.height*ue.height,ze=Ke+v.h/D.height*ue.height,et=16;Ke>=_e.top+et&&ze<=_e.bottom-et||(O.scrollTop+=Ke-(_e.top+Math.max(et,_e.height*.3)))},[b==null?void 0:b.viewport,L==null?void 0:L.viewport]);l.useEffect(()=>{if(!De||!z.current)return;const v=window.setTimeout(()=>Rt(z.current),420);return()=>window.clearTimeout(v)},[De,Q.width,Q.height,Rt]);const oe=l.useCallback(v=>{var O;const D=v&&typeof v.input=="object"&&v.input!==null?v.input:v;if(typeof(D==null?void 0:D.editable)=="boolean"){if(!D.editable&&D.kind==="control"){const ie=D.bounds;ie&&["x","y","w","h"].every(ue=>typeof ie[ue]=="number")&&(B.current={rect:{x:ie.x,y:ie.y,w:ie.w,h:ie.h},at:Date.now()});return}if(D.editable){const ie=D.bounds,ue=ie&&["x","y","w","h"].every(_e=>typeof ie[_e]=="number")?{x:ie.x,y:ie.y,w:ie.w,h:ie.h}:null;ue&&(z.current=ue,te.current=Date.now()),nt.current?Rt(ue??z.current):je(!0)}else z.current=null,nt.current&&((O=tt.current)==null||O.blur(),xt(!1))}},[Rt]),pn=l.useMemo(()=>[{urls:"stun:stun.l.google.com:19302"}],[]),Xt=l.useCallback(async(v,D)=>{if(!(!o||!v||!D))try{let O=Y.current;O||(O=new RTCPeerConnection({iceServers:pn}),O.onicecandidate=ue=>{ue.candidate&&o.request("browser:webrtc",{sessionId:v,data:{kind:"ice",candidate:ue.candidate.toJSON()}}).catch(()=>{})},O.ontrack=ue=>{const _e=ne.current;_e&&ue.streams[0]&&(_e.srcObject=ue.streams[0],_e.play().catch(()=>{}))},O.onconnectionstatechange=()=>{const ue=O==null?void 0:O.connectionState;ue==="connected"?V("live"):(ue==="failed"||ue==="disconnected"||ue==="closed")&&V("failed")},Y.current=O),await O.setRemoteDescription(D);const ie=await O.createAnswer();await O.setLocalDescription(ie),V("connecting"),await o.request("browser:webrtc",{sessionId:v,data:{kind:"answer",sdp:O.localDescription.toJSON()}})}catch{V("failed")}},[o,pn]),mt=l.useCallback((v,D)=>{if(D){if(D.kind==="offer"){Xt(v,D.sdp);return}if(D.kind==="ice"){const O=D.candidate,ie=Y.current;ie&&O&&ie.addIceCandidate(O).catch(()=>{});return}if(D.kind==="state"){const O=String(D.state);O==="connected"?V("live"):(O==="failed"||O==="disconnected"||O==="closed")&&V("failed")}}},[Xt]),[rt,ft]=l.useState(null);l.useEffect(()=>{if(!b){ft(null);return}const v=typeof b.data=="string"?`data:${b.mime};base64,${b.data}`:URL.createObjectURL(new Blob([b.data],{type:b.mime}));let D=!1,O=!1;const ie=new Image;return ie.src=v,ie.decode().then(()=>{D||(O=!0,ft(v))}).catch(()=>{}),()=>{D=!0,!O&&v.startsWith("blob:")&&URL.revokeObjectURL(v)}},[b]),l.useEffect(()=>()=>{rt!=null&&rt.startsWith("blob:")&&URL.revokeObjectURL(rt)},[rt]);const st=l.useCallback(v=>{g(D=>{const O=D.findIndex(ue=>ue.id===v.id);if(O<0)return[v,...D];const ie=[...D];return ie[O]=v,ie.sort((ue,_e)=>_e.updatedAt-ue.updatedAt)}),m(D=>ka(D,[v],n)),R(!1)},[n]),dt=l.useCallback(async()=>{if(!(!o||!t)){A(!0),P(null);try{const v=await o.request("browser:list");g(v.sessions),m(D=>{const O=D&&v.sessions.some(ie=>ie.id===D)?D:null;return ka(O,v.sessions,n)}),y&&await o.request("browser:watch",{sessionId:y}).then(D=>st(D.session)).catch(()=>{}),j(D=>D+1)}catch(v){P(v instanceof Error?v.message:"无法读取浏览器会话")}finally{A(!1)}}},[n,o,st,t,y]);l.useEffect(()=>{if(!(!t||!o))return dt(),o.onEvent(v=>{if(v.type==="browser:frame"){const D=v;D.sessionId===y&&C(D);return}if(v.type==="browser:webrtc"){const D=v.data;v.sessionId===y&&mt(y,D);return}if(v.session&&typeof v.session=="object"&&st(v.session),v.type==="browser:closed"){const D=v.session;D&&(g(O=>O.filter(ie=>ie.id!==D.id)),D.id===y&&(C(null),m(null)))}})},[o,mt,st,t,dt,y]),l.useEffect(()=>{if(!(!t||!o||!y))return C(null),P(null),o.request("browser:watch",{sessionId:y}).then(v=>st(v.session)).catch(v=>P(v instanceof Error?v.message:"无法观看浏览器")),()=>{o.request("browser:unwatch").catch(()=>{})}},[o,st,t,y]),l.useEffect(()=>{var v,D;if(!t||!o||!ke||!Ie||!y){(v=Y.current)==null||v.close(),Y.current=null,ne.current&&(ne.current.srcObject=null),V("off");return}return(D=Y.current)==null||D.close(),Y.current=null,V("connecting"),o.request("browser:webrtc",{sessionId:y,data:{kind:"start"}}).catch(()=>V("failed")),()=>{var O;(O=Y.current)==null||O.close(),Y.current=null,ne.current&&(ne.current.srcObject=null),o.request("browser:webrtc",{sessionId:y,data:{kind:"stop"}}).catch(()=>{})}},[o,ke,Ie,t,y,I]);const Pn=l.useCallback(async()=>{if(!(!o||!L)){R(!0),P(null);try{const v=await o.request("browser:takeover",{sessionId:L.id});st(v.session)}catch(v){R(!1),P(v instanceof Error?v.message:"无法接管浏览器")}}},[o,st,L]),yn=l.useCallback(async()=>{if(!(!o||!L)){R(!0),P(null);try{const v=await o.request("browser:return",{sessionId:L.id});st(v.session)}catch(v){R(!1),P(v instanceof Error?v.message:"无法归还浏览器")}}},[o,st,L]),Ve=l.useCallback(v=>{!o||!(L!=null&&L.isController)||L.state!=="user-controlled"||o.request("browser:input",{sessionId:L.id,input:v}).catch(D=>{P(D instanceof Error?D.message:"浏览器输入失败")})},[o,L]),Je=l.useCallback((v,D,O=[])=>{Ve({kind:"key",action:"down",key:v,code:D,text:"",modifiers:O}),Ve({kind:"key",action:"up",key:v,code:D,text:"",modifiers:O})},[Ve]),bt=l.useCallback(v=>{Je(v,`Key${v.toUpperCase()}`,["Control"])},[Je]),_t=l.useCallback(v=>!o||!(L!=null&&L.isController)||L.state!=="user-controlled"?Promise.resolve(null):o.request("browser:input",{sessionId:L.id,input:v}).then(D=>D&&typeof D=="object"?D:null).catch(()=>null),[o,L]),Wn=l.useCallback((v,D)=>{_t({kind:"pointer",action:"up",...v,button:"left",...D&&D>1?{click:D}:{}}).then(oe)},[oe,_t]),Zt=l.useRef(!1),He=l.useRef(""),Le=l.useCallback(v=>{const D=He.current;if(v!==D){if(v.startsWith(D)){const O=v.slice(D.length);O&&Ve({kind:"key",action:"down",text:O,key:"",code:"",modifiers:[]})}He.current=v}},[Ve]),At=(L==null?void 0:L.displays)??null,fn=l.useRef(0),Pt=l.useCallback(()=>{if(!o||!y||!At||At.length<2)return;const v=At.findIndex(O=>O.selected),D=At[(v+1)%At.length];!D||D.selected||o.request("browser:set-display",{sessionId:y,displayId:D.id}).catch(O=>{P(O instanceof Error?O.message:"切换屏幕失败")})},[o,At,y]),at=l.useCallback(v=>{const D=v.currentTarget.getBoundingClientRect(),O=(b==null?void 0:b.viewport)??(L==null?void 0:L.viewport);if(!O)return null;const ie=Math.min(D.width/O.width,D.height/O.height),ue=O.width*ie,_e=O.height*ie,Ke=(D.width-ue)/2,ze=(D.height-_e)/2,et=(v.clientX-D.left-Ke)/ue,ut=(v.clientY-D.top-ze)/_e;return et<0||et>1||ut<0||ut>1?null:{x:et,y:ut}},[b==null?void 0:b.viewport,L==null?void 0:L.viewport]);if(!t||typeof document>"u")return null;const wr=(L==null?void 0:L.online)&&!L.controlledByAnotherViewer,vn=(L==null?void 0:L.availability)==="unavailable"?Ie?"桌面直播不可用":"浏览器直播不可用":(L==null?void 0:L.availability)==="starting"?"正在连接画面":Ie&&(L==null?void 0:L.state)==="agent-controlled"?"未被远程控制":L?op[L.state]:Ie?"等待桌面直播":"等待浏览器",wn=(L==null?void 0:L.availability)==="unavailable"?Ie?"桌面直播不可用":"浏览器直播不可用":(L==null?void 0:L.availability)==="starting"?"正在连接画面":h.length?"等待第一帧":Ie?"暂无桌面直播":"暂无浏览器直播",sn=(L==null?void 0:L.availability)==="unavailable"?L.capabilityError||(Ie?"需要在桌面 App 中开启并授予屏幕录制权限":"当前浏览器不支持实时画面传输"):h.length?"画面开始后会自动显示":Ie?"在桌面 App 设置中开启「桌面直播与远程控制」后,画面会出现在这里":"Agent 开始浏览网页后,会话会出现在这里";return Yt.createPortal(e.jsx("div",{className:"browser-live-backdrop","data-tab-swipe-ignore":!0,role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&r()},children:e.jsxs("section",{ref:a,className:`browser-live-panel ${c?"is-fullscreen":""} ${h.length>1?"has-session-tabs":""}`,role:"dialog","aria-modal":"true","aria-label":"浏览器直播",children:[e.jsxs("header",{className:"browser-live-header",children:[e.jsxs("div",{className:"browser-live-heading",children:[e.jsx(mo,{size:17,"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("strong",{children:"浏览器直播"}),e.jsx("span",{children:L?ja(L.backend):"实时观看与接管"})]}),s]}),e.jsxs("div",{className:"browser-live-header-actions",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>void u(),title:c?"退出全屏":"全屏","aria-label":c?"退出全屏":"全屏","aria-pressed":c,children:c?e.jsx(id,{size:17}):e.jsx(sd,{size:17})}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>void dt(),title:"刷新画面与会话","aria-label":"刷新直播画面与会话",children:e.jsx(nl,{size:15,className:M?"spin":void 0,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,title:"关闭","aria-label":"关闭浏览器直播",children:e.jsx(qr,{size:17,"aria-hidden":"true"})})]})]}),h.length>1&&e.jsx("div",{className:"browser-live-session-tabs",role:"tablist","aria-label":"浏览器会话",children:h.map(v=>e.jsxs("button",{type:"button",role:"tab","aria-selected":v.id===y,className:v.id===y?"is-active":"",onClick:()=>m(v.id),children:[e.jsx("span",{children:ja(v.backend)}),e.jsx("small",{children:v.title||"浏览器"})]},v.id))}),e.jsxs("div",{className:`browser-live-surface ${ke?"is-controlling":""} has-zoom ${ke&&!k&&Se?"has-quickkeys":""}`,children:[e.jsxs("div",{className:"browser-live-zoom",role:"group","aria-label":"桌面画面缩放",children:[e.jsx("button",{type:"button","aria-label":"缩小桌面画面",title:"缩小",disabled:!b||T<=.5,onClick:()=>_(v=>Math.max(.5,v-.25)),children:e.jsx(il,{size:16})}),e.jsxs("output",{"aria-label":"桌面缩放比例",children:[Math.round(T*100),"%"]}),e.jsx("button",{type:"button","aria-label":"放大桌面画面",title:"放大",disabled:!b||T>=5,onClick:()=>_(v=>Math.min(5,v+.25)),children:e.jsx(ol,{size:16})}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>{var v;_(1),W(!1),(v=ve.current)==null||v.scrollTo(0,0)},children:"适应窗口"}),e.jsxs("button",{type:"button","aria-label":"移动桌面画面","aria-pressed":k,title:"拖动或滚动画面,不发送远程输入",disabled:!b,onClick:()=>W(v=>!v),children:[e.jsx(Xc,{size:15}),"移动画面"]}),e.jsxs("button",{type:"button","aria-label":"唤起键盘","aria-pressed":De,title:"唤起/收起键盘(轻点输入框也会自动弹起)",className:Ne&&!De?"is-hint":void 0,disabled:!b||!ke,onClick:()=>{je(!1),Ot()},children:[e.jsx(xo,{size:15}),"键盘"]}),e.jsxs("button",{type:"button","aria-label":"快捷键条","aria-pressed":Se,title:"展开/收起快捷键(Esc/Tab/复制/粘贴/方向键)",disabled:!b||!ke,onClick:()=>Ct(v=>!v),children:[e.jsx(xo,{size:15}),Se?"收起":"快捷键"]}),e.jsxs("button",{type:"button","aria-label":"窗口控制",title:"全屏看不到左上角按钮时用:第 1 次点=退出全屏(ESC + Ctrl+Cmd+F),第 2 次点=关闭窗口(Cmd+W)",disabled:!b||!ke,onClick:()=>{const v=Date.now();if(v-fn.current<2500){Je("w","KeyW",["Meta"]),fn.current=0;return}fn.current=v,Je("Escape","Escape"),window.setTimeout(()=>{Je("f","KeyF",["Control","Meta"])},150)},children:[e.jsx(xo,{size:15}),"窗口"]}),Ie&&At&&At.length>1&&(()=>{const v=At.find(O=>O.selected)??At[0],D=v.primary?"主屏":v.label.split(" ").slice(0,2).join(" ");return e.jsxs("button",{type:"button","aria-label":`切换直播屏幕(当前:${v.label})`,title:`切换直播屏幕(当前:${v.label})`,disabled:!b,onClick:Pt,children:[e.jsx(mo,{size:15}),D]})})()]}),ke&&!k&&Se&&e.jsxs("div",{className:"browser-live-quickkeys",role:"group","aria-label":"快捷键",children:[e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("Escape","Escape"),children:"Esc"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("Tab","Tab"),children:"Tab"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("c"),children:"复制"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("v"),children:"粘贴"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("a"),children:"全选"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("z"),children:"撤销"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("s"),children:"保存"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>bt("f"),children:"查找"}),e.jsx("button",{type:"button",disabled:!b,title:"退出当前前台应用(Cmd+Q)",onClick:()=>Je("q","KeyQ",["Meta"]),children:"⌘Q"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("ArrowLeft","ArrowLeft"),children:"←"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("ArrowUp","ArrowUp"),children:"↑"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("ArrowDown","ArrowDown"),children:"↓"}),e.jsx("button",{type:"button",disabled:!b,onClick:()=>Je("ArrowRight","ArrowRight"),children:"→"})]}),e.jsx("div",{className:"browser-live-touch-hint",children:"滑动滚动 · 轻点点击 · 双击打开 · 长按拖动 · 按住1秒右键 · 双指缩放"}),e.jsx("div",{ref:ve,className:"browser-live-viewport",children:b&&rt?e.jsxs("div",{className:"browser-live-image-hit-area",style:ct&&Lt?{width:Lt.width*ct*T,height:Lt.height*ct*T,cursor:k?"grab":void 0}:void 0,tabIndex:ke&&!k?0:-1,onPointerDown:v=>{if(v.pointerType==="touch"){v.preventDefault(),me.current.down(v.pointerId,{x:v.clientX,y:v.clientY}),Z.current=ke&&!k?at(v):null,v.currentTarget.setPointerCapture(v.pointerId),Ee.current&&window.clearTimeout(Ee.current),xe.current="none",Ce.current=ke&&!k?{x:v.clientX,y:v.clientY}:null,Oe.current=Date.now(),Ce.current&&(Ee.current=window.setTimeout(()=>{xe.current="armed"},550));return}if(k&&ve.current){const O=ve.current;Te.current={x:v.clientX,y:v.clientY,left:O.scrollLeft,top:O.scrollTop},v.currentTarget.setPointerCapture(v.pointerId);return}if(!ke)return;const D=at(v);D&&(we.current=!0,v.currentTarget.setPointerCapture(v.pointerId),Ve({kind:"pointer",action:"down",...D,button:"left"}))},onPointerMove:v=>{if(v.pointerType==="touch"){v.preventDefault();const O=me.current.move(v.pointerId,{x:v.clientX,y:v.clientY}),ie=ve.current;if(!O||!ie)return;const ue=O.pointers>=2&&Math.abs(O.distanceRatio-1)>.05,_e=Math.max(.5,Math.min(5,Be.current*O.scale));if(ue&&_e!==Be.current){const ze=v.currentTarget.getBoundingClientRect();It.current={x:(O.from.x-ze.left)/ze.width,y:(O.from.y-ze.top)/ze.height,clientX:O.to.x,clientY:O.to.y},Be.current=_e,Yt.flushSync(()=>_(_e));return}if(Ee.current&&(window.clearTimeout(Ee.current),Ee.current=null),xe.current==="armed"&&Ce.current){xe.current="drag";const ze=at(v);ze&&Ve({kind:"pointer",action:"down",...ze,button:"left"})}if(xe.current==="drag"){const ze=at(v);ze&&Ve({kind:"pointer",action:"move",...ze,button:"left"});return}const Ke=Be.current<=1.001;if(ke&&!k&&(O.pointers>=2||Ke)){const ze=lp(O.from,O.to);if(ze){const et=Z.current??at(v);et&&Ve({kind:"pointer",action:"wheel",...et,...ze})}return}ie.scrollLeft+=O.from.x-O.to.x,ie.scrollTop+=O.from.y-O.to.y;return}if(k&&Te.current&&ve.current){const O=Te.current;ve.current.scrollTo(O.left+O.x-v.clientX,O.top+O.y-v.clientY);return}if(!ke||!we.current)return;const D=at(v);D&&Ve({kind:"pointer",action:"move",...D,button:"left"})},onPointerUp:v=>{var O,ie;if(v.pointerType==="touch"){v.preventDefault(),Ee.current&&(window.clearTimeout(Ee.current),Ee.current=null);const ue=at(v);if(Z.current=null,xe.current==="armed"&&(xe.current="none",(Oe.current?Date.now()-Oe.current:0)>=800&&ue&&ke&&!k)){me.current.reset(),Ve({kind:"pointer",action:"down",...ue,button:"right"}),Ve({kind:"pointer",action:"up",...ue,button:"right"});return}if(xe.current==="drag"){xe.current="none",me.current.reset(),ue&&ke&&Ve({kind:"pointer",action:"up",...ue,button:"left"});return}if(me.current.up(v.pointerId,{x:v.clientX,y:v.clientY})&&ue&&ke&&!k){const Ke=z.current,ze=Ke!==null&&Date.now()-te.current<6e4&&ap(Ke,(b==null?void 0:b.viewport)??(L==null?void 0:L.viewport),ue.x,ue.y,.03);ze&&!nt.current?((O=tt.current)==null||O.focus({preventScroll:!0}),xt(!0),je(!1)):!ze&&nt.current&&((ie=tt.current)==null||ie.blur(),xt(!1));const et=(b==null?void 0:b.viewport)??(L==null?void 0:L.viewport),ut=lt.current;ut!==null&&Date.now()-ut.at<400&&et!==void 0&&Math.hypot((ue.x-ut.x)*et.width,(ue.y-ut.y)*et.height)<et.width*.03?(Ve({kind:"pointer",action:"down",...ue,button:"left",click:2}),Wn(ue,2),lt.current=null):(Ve({kind:"pointer",action:"down",...ue,button:"left"}),Wn(ue),lt.current={at:Date.now(),x:ue.x,y:ue.y})}return}if(k){Te.current=null;return}if(!ke)return;const D=at(v);we.current=!1,D&&Wn(D)},onPointerCancel:v=>{me.current.up(v.pointerId,{x:v.clientX,y:v.clientY},!0),Te.current=null,we.current=!1,Z.current=null,Ee.current&&(window.clearTimeout(Ee.current),Ee.current=null),xe.current="none"},onLostPointerCapture:v=>{me.current.up(v.pointerId,{x:v.clientX,y:v.clientY},!0)},onWheel:v=>{if(!ke||k)return;const D=at(v);D&&Ve({kind:"pointer",action:"wheel",...D,deltaX:v.deltaX,deltaY:v.deltaY})},onKeyDown:v=>{!ke||k||v.target===tt.current&&v.key.length===1&&!v.ctrlKey&&!v.metaKey&&!v.altKey||(Ve({kind:"key",action:"down",key:v.key,code:v.code,text:v.key.length===1?v.key:"",modifiers:Sa(v)}),["Backspace","Tab","Enter","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","PageUp","PageDown","Home","End","Escape"].includes(v.key)&&v.preventDefault())},onKeyUp:v=>{!ke||k||v.target===tt.current&&v.key.length===1&&!v.ctrlKey&&!v.metaKey&&!v.altKey||ke&&Ve({kind:"key",action:"up",key:v.key,code:v.code,modifiers:Sa(v)})},children:[e.jsx("img",{src:rt,alt:(L==null?void 0:L.title)||"浏览器实时画面",draggable:!1,decoding:"async"}),e.jsx("video",{ref:ne,className:`browser-live-video ${F==="live"?"is-live":""}`,"aria-label":Ie?"桌面实时视频流":"浏览器实时视频流",autoPlay:!0,playsInline:!0,muted:!0}),e.jsx("input",{ref:tt,className:"browser-live-mobile-input","aria-label":"浏览器键盘输入",defaultValue:"",inputMode:"text",autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,onCompositionStart:()=>{Zt.current=!0},onCompositionEnd:v=>{Zt.current=!1,k||Le(v.target.value)},onBlur:v=>{Zt.current=!1,He.current="",v.target.value="",xt(!1)},onChange:v=>{!k&&!Zt.current&&Le(v.target.value)}})]}):e.jsxs("div",{className:"browser-live-empty",children:[M||(L==null?void 0:L.availability)==="starting"?e.jsx(Nt,{size:22,className:"spin","aria-hidden":"true"}):e.jsx(mo,{size:24,"aria-hidden":"true"}),e.jsx("strong",{children:M?"正在连接浏览器":wn}),e.jsx("span",{children:sn})]})}),ke&&!k&&e.jsxs("div",{className:"browser-live-control-cue",children:[e.jsx(ld,{size:13,"aria-hidden":"true"})," ",Ie?"当前输入会发送到本机":"当前输入会发送到浏览器",Ie&&F==="live"?" · 实时视频流":Ie&&F==="connecting"?" · 正在连接实时流":"",$t!=null?` · ${$t}ms`:""]})]}),e.jsxs("footer",{className:"browser-live-footer",children:[e.jsxs("div",{className:"browser-live-location",children:[e.jsx("span",{className:`browser-live-status-dot is-${(L==null?void 0:L.state)??"idle"}`,"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("strong",{children:vn}),e.jsx("span",{title:L==null?void 0:L.url,children:(L==null?void 0:L.capabilityError)||(Ie?"本机屏幕":L==null?void 0:L.url)||S||"等待可观看的直播会话"})]}),(L==null?void 0:L.url)&&!Ie&&e.jsx(Oc,{size:13,"aria-hidden":"true"})]}),L&&(ke?e.jsxs("button",{type:"button",className:"browser-live-control-button is-return",onClick:()=>void yn(),disabled:K,children:[K&&e.jsx(Nt,{size:14,className:"spin","aria-hidden":"true"}),Ie?"结束控制":"归还给 Agent"]}):e.jsxs("button",{type:"button",className:"browser-live-control-button",onClick:()=>void Pn(),disabled:!wr||K||L.state!=="agent-controlled"||L.availability!=="ready",children:[K&&e.jsx(Nt,{size:14,className:"spin","aria-hidden":"true"}),L.controlledByAnotherViewer?"其他设备操作中":Ie?"开始控制":"接管浏览器"]}))]}),S&&e.jsx("div",{className:"browser-live-error",role:"alert",children:S})]})}),document.body)}const dp=[{prompt:"带我熟悉这个项目",Icon:Pc},{prompt:"帮我排查一个问题",Icon:sl},{prompt:"一起实现一个新想法",Icon:ed}];function up(t){return t>=5&&t<9?{title:"早啊。",prompt:"新的一天,想做点什么?"}:t>=9&&t<12?{title:"上午好。",prompt:"今天想一起做点什么?"}:t>=12&&t<14?{title:"中午好。",prompt:"想趁午休推进点什么?"}:t>=14&&t<18?{title:"下午好。",prompt:"这个下午,想做点什么?"}:t>=18&&t<23?{title:"晚上好。",prompt:"今晚想一起做点什么?"}:{title:"夜深了。",prompt:"注意休息,重要的事可以先留给我。"}}const pp={"customer-agent":"Customer Agent",codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function fp({agentType:t,ready:n,now:r,onSelectPrompt:s}){const o=pp[t],a=up((r??new Date).getHours());return e.jsxs("section",{className:"empty-session-welcome","aria-labelledby":"empty-session-welcome-title",children:[e.jsxs("div",{className:"empty-session-welcome__core","aria-hidden":"true",children:[e.jsx("span",{className:"empty-session-welcome__glow"}),e.jsxs("svg",{viewBox:"0 0 120 120",role:"presentation",children:[e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--outer",cx:"60",cy:"60",r:"44"}),e.jsx("circle",{className:"empty-session-welcome__orbit empty-session-welcome__orbit--inner",cx:"60",cy:"60",r:"33"}),e.jsx("rect",{className:"empty-session-welcome__diamond",x:"43",y:"43",width:"34",height:"34",rx:"2"}),e.jsx("circle",{className:"empty-session-welcome__pulse",cx:"60",cy:"60",r:"3"})]})]}),e.jsxs("div",{className:"empty-session-welcome__copy",children:[e.jsx("p",{className:"empty-session-welcome__status",children:n?`${o} · 已准备好`:`${o} · 等待配置`}),e.jsx("h2",{id:"empty-session-welcome-title",children:a.title}),e.jsx("p",{className:"empty-session-welcome__prompt",children:n?a.prompt:"配置好 API Key 后,我就能开始。"})]}),e.jsx("div",{className:"empty-session-welcome__starters","aria-label":"开始一个任务",children:dp.map(({prompt:c,Icon:d})=>e.jsxs("button",{type:"button","data-prompt":c,disabled:!n,onClick:()=>s(c),children:[e.jsx(d,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:c})]},c))})]})}function hp({image:t,onClose:n}){return l.useEffect(()=>{if(!t)return;const r=document.body.style.overflow,s=o=>{o.key==="Escape"&&n()};return document.body.style.overflow="hidden",window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s),document.body.style.overflow=r}},[t,n]),t?Yt.createPortal(e.jsxs("div",{className:"message-image-lightbox",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:r=>{r.target===r.currentTarget&&n()},children:[e.jsx("img",{className:"message-image-lightbox__image",src:t.src,alt:t.alt}),e.jsx("button",{type:"button",className:"message-image-lightbox__close",onClick:n,"aria-label":"关闭图片预览",title:"关闭",autoFocus:!0,children:e.jsx(qr,{size:22,"aria-hidden":"true"})})]}),document.body):null}const gp={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function xp(t){const{title:n="视频工作台",shots:r=[],status:s="generating",composedVideoUrl:o,isAgentRunning:a}=t,[c,d]=l.useState(!1),[u,h]=l.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:()=>d(!c),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-deep)",cursor:"pointer",userSelect:"none",borderBottom:c?"none":"1px solid var(--border-subtle)"},children:[e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:["🎬 ",n]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[r.filter(g=>g.status==="done").length,"/",r.length," 完成",e.jsx("span",{style:{marginLeft:6,transform:c?"rotate(-90deg)":"none",display:"inline-block",transition:"transform 0.2s"},children:"▼"})]})]}),!c&&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:ps,children:"#"}),e.jsx("th",{style:{...ps,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:ps,children:"时长"}),e.jsx("th",{style:ps,children:"状态"}),e.jsx("th",{style:ps,children:"预览"})]})}),e.jsx("tbody",{children:r.map(g=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:fs,children:g.index}),e.jsx("td",{style:{...fs,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g.description,children:g.description}),e.jsxs("td",{style:fs,children:[g.duration,"s"]}),e.jsxs("td",{style:fs,children:[gp[g.status]??"⏳",g.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:g.error,children:"!"})]}),e.jsx("td",{style:fs,children:g.videoUrl?e.jsx("button",{onClick:()=>h(g.videoUrl),style:{background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(79,110,247,0.22)",borderRadius:6,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"▶ 播放"}):g.previewImageUrl?e.jsx("img",{src:g.previewImageUrl,alt:`shot-${g.index}`,style:{width:48,height:32,objectFit:"cover",borderRadius:4,border:"1px solid var(--border-subtle)"}}):e.jsx("span",{style:{color:"var(--text-muted)",fontSize:11},children:"—"})})]},g.index))})]}),u&&e.jsx("video",{src:u,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),o&&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:o,controls:!0,style:{width:"100%",borderRadius:8,border:"1px solid var(--border-subtle)"}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[s==="generating"&&e.jsx("span",{children:a===!1?"本轮已结束":"🔄 生成中..."}),s==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),s==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),s==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const ps={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},fs={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},mp={storyboard_workbench:xp};function bp(t,n,r){return!t||n!==t?!1:r===null||r===t}function yp(t,n,r=Date.now()){return!t||t.sessionId!==n?t:{...t,until:r+9e4}}async function vp(t){const{text:n,projectId:r,createSession:s,activateSession:o,showUserMessage:a,onSessionCreated:c,isCancelled:d}=t,u=!t.sessionId;let h=t.sessionId??null;if(!h){const g=await s(n.slice(0,60)||"语音任务",r||void 0);if(d!=null&&d())return null;h=g.id}return o(h),a(n,h),u&&c&&await c(h),h}async function Ia(t){var o,a;const n=((o=t.sessionId)==null?void 0:o.trim())||null,r=!n,s=n??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!s)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(s),t.showUserMessage(t.text,s),r&&await((a=t.onSessionCreated)==null?void 0:a.call(t,s)),s}const wp=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|[ \t]*\/[^)\n]+)\)/gi,jp=/`([^`\n]+)`/g,kp=/:codex-file-citation\{([^}\n]*)\}/g,Ca=/([A-Za-z][\w-]*)="([^"\n]*)"/g,Sp=/\uE200visualize\uE202([^\uE201\n]+)\uE201/g;function ii(t){if(!t.startsWith("/")||t.includes("?")||t.includes("#")||t.includes("\0"))return null;const n=t.match(/^(\/.*):([1-9]\d*)$/);return n?{path:n[1],line:Number(n[2])}:{path:t}}function Ip(t){const n={};for(const o of t.matchAll(Ca)){const a=o[1];if(a!=="path"&&a!=="purpose"||n[a]!==void 0)return null;n[a]=o[2]}if(t.replace(Ca,"").trim())return null;const r=ii(n.path??"");if(!r||r.line!==void 0)return null;const s=r.path.slice(r.path.lastIndexOf("/")+1)||r.path;return{path:r.path,label:s}}function Cp(t){try{const n=JSON.parse(t);if(!n||typeof n!="object"||Array.isArray(n))return null;const{path:r,title:s,mode:o}=n;if(typeof r!="string"||s!==void 0&&typeof s!="string"||o!==void 0&&typeof o!="string")return null;const a=ii(r);if(!a||a.line!==void 0)return null;const c=(s==null?void 0:s.trim())||a.path.slice(a.path.lastIndexOf("/")+1)||a.path;return{path:a.path,label:c}}catch{return null}}function Rp(t,n){const r=[];let s=0;const o=[...[...t.matchAll(wp)].map(a=>({kind:"markdown",match:a})),...[...t.matchAll(kp)].map(a=>({kind:"citation",match:a})),...[...t.matchAll(Sp)].map(a=>({kind:"visualize",match:a})),...[...t.matchAll(jp)].map(a=>({kind:"code",match:a}))].sort((a,c)=>(a.match.index??0)-(c.match.index??0));for(const a of o){const{match:c}=a,d=c.index??0;if(d<s)continue;if(d>s&&r.push({type:"text",value:t.slice(s,d)}),a.kind==="code"){r.push({type:"code",value:c[1]}),s=d+c[0].length;continue}if(a.kind==="citation"){const h=Ip(c[1]);r.push(h?{type:"artifact",label:h.label,path:h.path,raw:c[0]}:{type:"text",value:c[0]}),s=d+c[0].length;continue}if(a.kind==="visualize"){const h=Cp(c[1]);r.push(h?{type:"artifact",label:h.label,path:h.path,raw:c[0]}:{type:"text",value:c[0]}),s=d+c[0].length;continue}const u=c[2];if(/^https?:\/\//i.test(u))r.push({type:"link",label:c[1],href:u});else{const h=ii(u.replace(/^[ \t]+/,""));h?r.push({type:"artifact",label:c[1],path:h.path,...h.line?{line:h.line}:{},raw:c[0]}):r.push({type:"text",value:c[0]})}s=d+c[0].length}return s<t.length&&r.push({type:"text",value:t.slice(s)}),r.length>0?r:[{type:"text",value:t}]}function Ap(t){return Rp(t)}function Pl(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0}function Mp(t){const n=Pl(t);return n===void 0?void 0:`${Math.round(n/1e3)} 秒`}function Ep(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function Tp(t){var n,r,s;return t.role==="assistant"&&!!(t.content.trim()||(n=t.toolCalls)!=null&&n.length||(s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length||t.askUser||t.widget)}function Np(t,n,r){var a;const s=t[n];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(a=s.toolCalls)!=null&&a.length||s.isCompactionSummary)return!1;let o=!r;for(let c=n+1;c<t.length;c++){const d=t[c];if(!d.isCompactionSummary){if(Ep(d)){o=!0;break}if(Tp(d))return!1}}return o}function zp(t,n,r){const s=t[n];if(!s)return{showCopy:!1,showSpeak:!1,showCompletion:!1,compact:!1};if(s.role==="user")return{showCopy:!!s.content,showSpeak:!1,showCompletion:!1,compact:!1};const o=Np(t,n,r);return{showCopy:o,showSpeak:o,showCompletion:o,compact:s.role==="assistant"&&!o&&!s.isCompactionSummary}}const Lp=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function _p(t,n){const r=[],s=[],o=[];for(const c of t){const d=c.type.trim().toLowerCase();d.startsWith("image/")?Lp.has(d)?r.push(c):o.push(c):s.push(c)}const a=await Promise.all(r.map(async c=>{try{return{file:c,dataUrl:await n(c)}}catch{return{file:c,dataUrl:null}}}));return{images:a.flatMap(c=>c.dataUrl?[c.dataUrl]:[]),attachments:s,unsupportedImages:o,failedImages:a.flatMap(c=>c.dataUrl?[]:[c.file])}}function Ls(t,n){return n?t[n]:void 0}function Pp(t,n){const r=Object.fromEntries(Object.entries(t).filter(([,s])=>s.token!==n.token&&s.sourceSessionId!==n.sourceSessionId));return r[n.sourceSessionId]=n,n.forkSessionId&&(r[n.forkSessionId]=n),r}function Wp(t,n){const r=t[n];return r?Object.fromEntries(Object.entries(t).filter(([,s])=>s.token!==r.token)):t}function Dp(t,n,r=crypto.randomUUID()){return{token:r,sourceSessionId:t,payload:{...n,images:n.images?[...n.images]:void 0,agentIds:n.agentIds?[...n.agentIds]:void 0},sendAttempted:!1}}function Ra(t,n){return t.forkSessionId===n&&t.sendAttempted?t:{...t,forkSessionId:n,sendAttempted:!0}}function Bp(t){return`occupied-recovery:${t.token}`}function $p(t,n){return!!(t&&n&&(t.sourceSessionId===n||t.forkSessionId===n))}async function Op(t){const n=await t.forkSession(t.sourceSessionId);return t.activateSession(n.id),await t.refreshAndSelect(n),n}const Ln=50,Ro=1,hs=1,Aa=160;function Ma(t){return t.trim().replace(/^\/goal\s+/i,"").replace(/^\$([\w-]+)/,"/$1").trim()}function Ao(t){const r=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(r){const a=parseFloat(r[1]),c=r[2].toLowerCase(),d=c==="s"||c==="sec"||c==="秒"?a*1e3:c==="m"||c==="min"||c==="分"||c==="分钟"?a*6e4:a*36e5;return d>=36e5&&d%36e5===0?`每 ${d/36e5} 小时`:d>=6e4&&d%6e4===0?`每 ${d/6e4} 分钟`:`每 ${d/1e3} 秒`}const[s,o]=t.trim().split(/\s+/);return s==="0"&&o&&o!=="*"&&!o.includes("/")&&!o.includes(",")?`每天 ${o.padStart(2,"0")}:00`:`cron: ${t}`}function Fp(t){const n=t.split(/(`[^`\n]+`)/g);return n.length<=1?t:e.jsx(e.Fragment,{children:n.map((r,s)=>s%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:r.slice(1,-1)},s):e.jsx("span",{children:r},s))})}function Wl(t,n){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,o)=>{const a=`${n}-${o}`;return s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:s.slice(2,-2)},a):s.startsWith("*")&&s.endsWith("*")&&s.length>2?e.jsx("em",{children:s.slice(1,-1)},a):e.jsx("span",{children:s},a)})}function Ea(t,n){return t.split(/(`[^`\n]+`)/g).map((s,o)=>o%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:s.slice(1,-1)},`${n}-${o}`):Wl(s,`${n}-${o}`))}function Go(t){return Ap(t).map((n,r)=>{if(n.type==="code")return e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:n.value},r);if(n.type==="link")return e.jsx("a",{className:"chat-message-link",href:n.href,target:"_blank",rel:"noopener noreferrer",children:Ea(n.label,`${r}-label`)},r);if(n.type==="artifact"){if(!Jn())return e.jsx("span",{children:n.raw},r);const s=n.line?`${n.path}:${n.line}`:n.path,o=n.label.replace(/^`([^`\n]+)`$/,"$1");return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:s,"aria-label":`打开交付物 ${o}`,onClick:()=>vr(n.path),children:[e.jsx(qs,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Ea(n.label,`${r}-label`)})]},r)}return Wl(n.value,`${r}`)})}function Hp(t){if(t.length<2)return null;const n=a=>a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(c=>c.trim()),r=n(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const o=t.slice(2).map(n);return{headers:r,rows:o}}function Up(t,n){const r=s=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:s?600:400,color:s?"var(--text-primary)":"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"pre-wrap",wordBreak:"break-word"});return e.jsx("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"auto",background:"var(--bg-surface)"},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"var(--bg-deep)"},children:t.map((s,o)=>e.jsx("th",{style:r(!0),children:Go(s)},o))})}),e.jsx("tbody",{children:n.map((s,o)=>e.jsx("tr",{style:{background:o%2===0?"transparent":"rgba(0,0,0,0.015)"},children:s.map((a,c)=>e.jsx("td",{style:r(!1),children:Go(a)},c))},o))})]})})}function qp(t,n,r){return t.toLowerCase()==="mermaid"?e.jsx(zd,{code:n,complete:r}):e.jsxs("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"hidden",background:"var(--bg-surface)"},children:[e.jsx("div",{style:{padding:"4px 10px",background:"var(--bg-deep)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.07em"},children:t||"code"}),e.jsx("pre",{style:{margin:0,padding:"10px 12px",fontSize:12,lineHeight:1.6,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto",maxHeight:420},children:n})]})}function gs(t){const n=t.split(`
361
- `),r=[];let s=0,o=0;const a=d=>d.trimStart().startsWith("```"),c=d=>n[d].trimStart().startsWith("|")&&d+1<n.length&&/^\|[\s\-:|]+\|$/.test(n[d+1].trim());for(;s<n.length;){if(a(n[s])){const d=n[s].trim().slice(3).trim();s++;const u=[];for(;s<n.length&&!a(n[s]);)u.push(n[s]),s++;const h=s<n.length;s++,r.push(e.jsx("div",{children:qp(d,u.join(`
362
- `),h)},`code-${o++}`));continue}if(c(s)){const d=[];for(;s<n.length&&n[s].trimStart().startsWith("|");)d.push(n[s].trim()),s++;const u=Hp(d);u?r.push(e.jsx("div",{children:Up(u.headers,u.rows)},`tbl-${o++}`)):r.push(e.jsx("span",{children:d.map((h,g)=>e.jsxs("span",{children:[Fp(h),g<d.length-1?`
363
- `:null]},g))},`tbl-fb-${o++}`))}else{const d=[];for(;s<n.length&&!c(s)&&!a(n[s]);)d.push(n[s]),s++;d.length>0&&r.push(e.jsx("span",{children:d.map((u,h)=>e.jsxs("span",{children:[Go(u),h<d.length-1?`
364
- `:null]},h))},`txt-${o++}`))}}return e.jsx(e.Fragment,{children:r})}const Dl=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],Ta=Object.fromEntries(Dl.map(t=>[t.value,t.label])),Vp=750,Mo={low:"低",medium:"中",high:"高",xhigh:"超高",max:"最大"},Na={codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function Kp(t,n){return n==="codex"?t==="openai":n==="claude-code"?t==="anthropic":!1}const Bs=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function za(t){return Bs.some(n=>n.value===t)?t:"full-access"}function Gp({activeAgentType:t="customer-agent",selectedProjectId:n=null,selectedSessionId:r=null,onSessionCreated:s,onMessageSent:o,onSubSessionCreated:a,onSelectSession:c,onSubAgentEvent:d,onRunComplete:u,sessionTitle:h,sessionSummary:g,workspacePath:y=null,onOpenSettings:m,settingsOpen:b=!1,onHideToBackground:C,onOpenHub:M,onOpenDesktopLive:A,desktopLiveOpen:I=!1,onToggleAppearance:j,appearanceOpen:S=!1,hideToBackgroundTitle:P,voiceCommand:K=null}){var zi,Li,_i,Pi,Wi,Di,Bi,$i,Oi,Fi;const{messages:R,runningSessionId:T,appendText:_,addMessage:k,setRunningSession:W,setSessionId:Q,updateToolResult:ae,updateSubAgentStatus:ve,updateSubAgentProgress:Te,updateMessage:we,setMessages:Z,getMessagesForSession:me,contextUsageBySession:Be,runtimeProgressBySession:It,nativeSubagentsBySession:tt,setContextUsage:De,applyRuntimeProgress:xt,setRuntimeProgress:nt,clearRuntimeProgress:z,applyNativeSubagentActivity:te,setNativeSubagentActivities:Ne,applyReasoningSummary:je,applyCodexExecutionEvent:Ce,clearMessages:Oe,sessionId:xe,todos:Ee,setTodos:lt,cronTasks:$t,setCronTasks:Fe}=We(),[Se,Ct]=l.useState({active:null,queued:[],history:[]}),[zt,B]=l.useState(0),F=l.useMemo(()=>zl(Eu(R.filter(i=>!i.isQueued),Se.queued)),[Se.queued,R]),V=l.useMemo(()=>{var i,p;return(p=(i=F.findLast(x=>x.executionTrace))==null?void 0:i.executionTrace)==null?void 0:p.turnId},[F]),{isConfigured:Y,profiles:ne,activeProfileId:L,switchActiveProfile:Ie,loadFromSystem:ke,contextWindow:Lt,reasoningEffort:ct,setField:Ot,saveToSystem:Rt}=Vs(),oe=r||xe,[pn,Xt]=l.useState({}),mt=l.useRef({}),rt=l.useCallback((i,p)=>{const x=i?Pp(mt.current,i):p?Wp(mt.current,p):mt.current;mt.current=x,Xt(x)},[]),ft=Ls(pn,oe),[st,dt]=l.useState(!1),[Pn,yn]=l.useState("idle"),[Ve,Je]=l.useState(!1);l.useEffect(()=>{if(!Jn()||!window.browserLiveApi)return;const i=()=>Je(!0);return window.addEventListener(Ki,i),()=>window.removeEventListener(Ki,i)},[]);const[bt,_t]=l.useState(null),[Wn,Zt]=l.useState(null),He=Nu(g,t),Le=(g==null?void 0:g.agentType)??t,[At,fn]=l.useState([]),Pt=l.useRef(null),[at,wr]=l.useState(()=>Ji(Le)),[vn,wn]=l.useState(!1),sn=l.useRef(null);l.useEffect(()=>{wr(Ji(Le)),wn(!1)},[Le]),l.useEffect(()=>{var i;!He||!((i=window.agentApi)!=null&&i.listAgentModels)||Pt.current!==Le&&(Pt.current=Le,fn([]),window.agentApi.listAgentModels(Le).then(p=>fn(p.models??[])).catch(()=>{fn([]),Pt.current=null}))},[He,Le]),l.useEffect(()=>{if(!vn)return;const i=p=>{sn.current&&!sn.current.contains(p.target)&&wn(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[vn]);const v=l.useCallback(i=>{wr(p=>{const x={...p,...i};return _d(Le,x),x})},[Le]),D=l.useMemo(()=>He?At.map(i=>({key:yo(i),label:i.displayName||i.id,model:{id:i.id,...i.providerID?{providerID:i.providerID}:{}},reasoningEfforts:i.reasoningEfforts})):[],[He,At]),O=l.useMemo(()=>He?(ne??[]).filter(i=>{var p;return(p=i.modelId)==null?void 0:p.trim()}).filter(i=>Le==="opencode"||Kp(i.provider,Le)).map(i=>({key:Le==="opencode"?yo({id:i.modelId,providerID:i.provider}):i.modelId,label:i.name||i.modelId,model:{id:i.modelId,...Le==="opencode"?{providerID:i.provider}:{}}})):[],[He,ne,Le]),ie=(zi=at.model)!=null&&zi.id?yo(at.model):"",ue=l.useMemo(()=>{var p;const i=D.find(x=>x.key===ie);if((p=i==null?void 0:i.reasoningEfforts)!=null&&p.length)return i.reasoningEfforts;if(Le==="claude-code")return["low","medium","high","xhigh"]},[D,ie,Le]),_e=l.useMemo(()=>He?Le==="codex"?ue??[]:Le==="claude-code"?ue??["low","medium","high","xhigh"]:[]:[],[He,Le,ue]),Ke=at.reasoningEffort&&_e.includes(at.reasoningEffort)?at.reasoningEffort:void 0,ze=D.length>0||O.length>0,et=(g==null?void 0:g.messageQueueVersion)===1,ut=ku(g==null?void 0:g.agentType),on=bt===oe?"direct":Wn?"incompatible":(Li=g==null?void 0:g.compatibility)==null?void 0:Li.status,nr=on!==void 0&&on!=="direct",rr=nr||(g==null?void 0:g.occupancy)==="owned-externally"&&g.agentType!=="codex",jr=$p(ft,oe),vs=Y||He,sr=vs&&!rr&&!jr&&Pn!=="released",or=l.useRef(new Set),[kr,Jt]=l.useState("idle"),an=l.useRef("idle"),Sr=l.useRef(null),[Ir,jn]=l.useState(()=>Date.now()),Dn=!!(oe&&(T===oe||or.current.has(oe))),Wt=_u(g,Dn),hn=Dn||zu(g),ln=oe?It[oe]??[]:[],cn=oe?tt[oe]??{}:{},kn=Wd(ln),Sn=F[F.length-1],Xs=!!((Sn==null?void 0:Sn.role)==="assistant"&&kr==="thinking"&&((Pi=(_i=Sn.presentation)==null?void 0:_i.reasoning)!=null&&Pi.some(i=>i.text.trim()))),Zs=kr==="tools"&&F.some(i=>{var p;return((p=i.toolCalls)==null?void 0:p.length)&&!ko(i.toolCalls)}),Js=hn&&!kn&&!Xs&&!Zs;l.useEffect(()=>{ke()},[]),l.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(i=>Fe(i))},[]);const[Ft,ht]=l.useState(""),[In,ir]=l.useState(null),[Gr,Ht]=l.useState(""),[Cn,Ut]=l.useState(null),[ar,Bn]=l.useState(null),Rn=l.useRef(null),[gn,$n]=l.useState(!1),[Cr,Qr]=l.useState(!1),[lr,On]=l.useState(!1),[xn,Fn]=l.useState("full-access"),[en,Yr]=l.useState(!1),[ws,Rr]=l.useState(null),[Ge,Hn]=l.useState(!1),yt=l.useRef(null),Mt=l.useRef(null),Et=l.useCallback((i,p)=>{const x=Qe.current||Bt.current;p===x&&Ct(ba(i));const w=me(p);Z(jo(w,i),p)},[me,Z]);l.useEffect(()=>{if(!Cr)return;const i=p=>{yt.current&&!yt.current.contains(p.target)&&Qr(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Cr]),l.useEffect(()=>{if(!lr)return;const i=p=>{Mt.current&&!Mt.current.contains(p.target)&&On(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[lr]),l.useEffect(()=>{On(!1),Fn(za(g==null?void 0:g.permissionMode))},[He,r,g==null?void 0:g.permissionMode]);const[Ar,ye]=l.useState(null),[Un,cr]=l.useState(null),[mn,qt]=l.useState(0),[js,Mr]=l.useState([]),[Er,An]=l.useState([]),[Xr,Tr]=l.useState(0),[eo,Mn]=l.useState(null),Vt=l.useRef(null),ks=l.useRef(null),En=l.useRef(null),Zr=l.useRef(()=>{}),Jr=l.useRef(()=>{}),Kt=l.useRef(null),Tn=l.useRef(null),tn=l.useRef(null);tn.current||(tn.current=new au);const Gt=l.useRef(null),f=l.useRef("latest"),N=l.useRef(null),q=l.useRef(!1),G=l.useRef(null),X=l.useRef(0),he=l.useRef(0),de=l.useRef(null),ce=l.useRef(!1),Ue=l.useRef(!1),gt=l.useRef(null),vt=l.useRef(!1),ge=l.useRef(!1),Pe=l.useRef(null),Qt=l.useRef(null),pt=l.useRef(0),nn=l.useRef(null),dn=l.useRef(new Map),Dt=l.useRef(new Set),Nr=l.useRef(null),qn=l.useRef(!1),Re=l.useRef(!1),wt=l.useRef(null),un=l.useRef(null),[li,ci]=l.useState(!1),[Ss,Is]=l.useState(null),[to,no]=l.useState(null),[es,Ul]=l.useState("latest"),[ql,zr]=l.useState(null),[Vl,Lr]=l.useState(null),[Kl,_r]=l.useState(!1),[Gl,di]=l.useState(!1),[ro,Cs]=l.useState(!1),[Ql,ui]=l.useState(!1),[Rs,As]=l.useState(!1),[Yl,Ms]=l.useState(!1),pi=l.useRef(null),ts=l.useRef(null),so=l.useRef(null),[Vn,fi]=l.useState(null),[Xl,hi]=l.useState([]),[Zl,gi]=l.useState([]),[ns,oo]=l.useState([]),[rs,dr]=l.useState(null),[ur,pr]=l.useState(null),$e=l.useCallback(i=>Qe.current===i?g==null?void 0:g.agentType:i.startsWith("runtime:codex:")?"codex":void 0,[g==null?void 0:g.agentType]),jt=l.useCallback((i,p)=>{if(!p)return;const x=`${i}:${p}`;nn.current!==x&&(nn.current=x,dn.current.clear())},[]),io=l.useCallback(async i=>{const p=window.agentApi,x=Qe.current;if(!p||!x)throw new Error("当前会话不可用");jt(x,i.revision);const w=`${i.turnId}:${i.itemId}`;let $=dn.current.get(w);$||($=p.getSessionToolResult(x,i),dn.current.set(w,$),$.catch(()=>{dn.current.get(w)===$&&dn.current.delete(w)}));const E=await $;return Qe.current!==x||nn.current!==`${x}:${i.revision}`,E},[jt]),xi=l.useCallback(async i=>{const p=Qe.current;if(!p)throw new Error("当前会话不可用");const x=await io(i);Qe.current===p&&ae(i.itemId,x.content,x.isError,p)},[io,ae]),Jl=l.useCallback(async i=>{var E;const p=window.agentApi,x=Qe.current;if(!p||!x)throw new Error("当前会话不可用");const w=await Zd(p,x,i,Ln),$=w.detail;if(Qe.current!==x)throw new DOMException("Session selection changed","AbortError");if(((E=$==null?void 0:$.history)==null?void 0:E.revision)!==w.revision)throw new Error("会话内容已更新,请重新展开执行过程");return w.recovered&&Z(me(x).map(ee=>ee.executionTrace?{...ee,executionTrace:{...ee.executionTrace,revision:w.revision}}:ee),x),jt(x,w.revision),eu($)},[me,Z,jt]);l.useEffect(()=>{nn.current=null,dn.current.clear()},[r]);const bn=l.useCallback((i,p)=>{const x=window.agentApi;!p||!x||tn.current.prefetch(i,p,()=>x.getSession(i,{before:p,limit:$e(i)==="codex"?hs:Ln,...$e(i)==="codex"?{view:"core"}:{}})).catch(w=>{console.warn("[chat] failed to prefetch older history",{sessionId:i,error:w})})},[$e]),fr=l.useCallback(i=>{f.current=i,Ul(i)},[]);l.useEffect(()=>{if(!He||!oe){Nr.current=null;return}if(Nr.current!==oe){Nr.current=oe;const i=Ls(mt.current,oe);ht((i==null?void 0:i.payload.content)??Cu(oe)),An((i==null?void 0:i.payload.images)??[]);return}if(qn.current&&Ft===""){qn.current=!1;return}wo(oe,Ft)},[Ft,He,oe]);const ec=()=>{const i=Vt.current;i&&(i.scrollTop<=240&&Zr.current(),f.current==="anchored"&&i.scrollHeight-i.scrollTop-i.clientHeight<=240&&Jr.current(),ui(i.scrollHeight-i.scrollTop-i.clientHeight>Aa),i.classList.add("is-scrolling"),En.current!==null&&window.clearTimeout(En.current),En.current=window.setTimeout(()=>{i.classList.remove("is-scrolling"),En.current=null},700))};l.useEffect(()=>()=>{En.current!==null&&window.clearTimeout(En.current)},[]);const tc=l.useCallback(()=>{const i=Vt.current;if(!i)return;const p=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;i.scrollTo({top:i.scrollHeight,behavior:p?"auto":"smooth"})},[]);l.useLayoutEffect(()=>{const i=wt.current,p=Vt.current;!i||!p||(p.scrollTop=i.scrollTop+(p.scrollHeight-i.scrollHeight),wt.current=null)},[R]),l.useLayoutEffect(()=>{const i=de.current,p=Vt.current;if(!i||!p)return;const x=Array.from(p.querySelectorAll("[data-message-id]")).find(w=>w.dataset.messageId===i);x&&(Eo(p,x),de.current=null,zr(i))},[R]),l.useLayoutEffect(()=>{const i=Vt.current;!ce.current||!i||es!=="latest"||(ce.current=!1,i.scrollTop=i.scrollHeight)},[es,R]),l.useLayoutEffect(()=>{if(un.current!=="skip")return;const i=Vt.current;i&&ui(i.scrollHeight-i.scrollTop-i.clientHeight>Aa)},[R]);const[mi,ao]=l.useState(!1),[ss,os]=l.useState(null),Es=l.useRef(null);l.useEffect(()=>{const i=window.agentApi;if(!(i!=null&&i.onTtsStart)||!i.onTtsPcm||!i.onTtsStreamEnd||!i.onTtsFlush)return;const p=new Xd(i),x=[i.onTtsStart(w=>p.start(w)),i.onTtsPcm(({generation:w,pcm:$})=>p.enqueue(w,$)),i.onTtsStreamEnd(({generation:w})=>p.finish(w)),i.onTtsFlush(({generation:w})=>p.flush(w)),i.onTtsEnd(()=>os(null))];return()=>{for(const w of x)w();p.dispose()}},[]);const nc=()=>{var x;if(mi){(x=Es.current)==null||x.stop(),Es.current=null,ao(!1);return}Ns(window.agentApi,us);const i=Ft?`${Ft.trimEnd()} `:"",p=Kd({onInterim:w=>ht(i+w),onFinal:w=>{var $;ht(i+w),($=ts.current)==null||$.focus()},onError:w=>ye(w),onEnd:()=>{ao(!1),Es.current=null}});p&&(Es.current=p,ao(!0))},rc=async(i,p)=>{var x;if(ss===i){await Ns(window.agentApi,us),os(null);return}if(await Ns(window.agentApi,us),!((x=window.agentApi)!=null&&x.ttsSpeak)){ye("TTS 模型服务不可用");return}os(i);try{(await window.agentApi.ttsSpeak(p)).ok||(os(null),ye("TTS 模型播报失败"))}catch(w){os(null),ye(w instanceof Error?w.message:"TTS 模型播报失败")}},ot=l.useRef(null),hr=l.useRef(!1),Pr=l.useRef(new Set),is=l.useRef(new Map),bi=l.useRef(new Set),as=l.useRef(new Map),Kn=l.useRef(null),Qe=l.useRef(r??null),Bt=l.useRef(null),Wr=l.useRef(0);l.useEffect(()=>{Qe.current=r??null},[r]),l.useEffect(()=>{Bt.current=xe},[xe]),l.useEffect(()=>()=>{for(const i of is.current.values())window.clearTimeout(i);is.current.clear()},[]);const Ts=l.useCallback(async i=>{var x;const p=i||Qe.current||Bt.current;if(!p||!((x=window.agentApi)!=null&&x.getSessionGoals)){Ct({active:null,queued:[],history:[]});return}try{const w=await window.agentApi.getSessionGoals(p);Et(w,p),w.active&&(ot.current=p,W(p))}catch(w){ye(w instanceof Error?w.message:"目标状态加载失败")}},[Et,W]);l.useEffect(()=>{Ts(oe)},[oe,Ts]);const kt=l.useCallback(i=>{const p=Qe.current||Bt.current;i==="thinking"&&(an.current!=="thinking"||Sr.current!==p)?(Sr.current=p,jn(Date.now())):i!=="thinking"&&(Sr.current=null),an.current=i,Jt(i)},[]),sc=l.useCallback(i=>{Sr.current=i,an.current="thinking",jn(Date.now()),Jt("thinking")},[]);l.useEffect(()=>{dt(!1),yn("idle"),Mn(null)},[r]),l.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(i=>hi(i)),window.agentApi.listSkills().then(i=>gi(i.filter(p=>p.name))).catch(i=>console.error("[listSkills] mount error:",i)))},[]);const yi=rs===null?[]:Xl.filter(i=>rs===""||i.name.toLowerCase().includes(rs.toLowerCase())),lo=ur===null?[]:[...[{name:"goal",description:"目标模式:持续推进当前目标,后续目标自动排队"},{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(i=>ur===""||i.name.toLowerCase().includes(ur.toLowerCase())),...Zl.filter(i=>ur===""||i.name.toLowerCase().includes(ur.toLowerCase()))],oc=i=>{oo(p=>p.find(x=>x.id===i.id)?p:[...p,i]),ht(p=>p.replace(/@[\w\u4e00-\u9fff]*$/,"")),dr(null),setTimeout(()=>{var p;return(p=ts.current)==null?void 0:p.focus()},0)},ic=i=>{oo(p=>p.filter(x=>x.id!==i))},ac=i=>{ht(p=>p.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${i.name} `)),pr(null),setTimeout(()=>{var p;return(p=ts.current)==null?void 0:p.focus()},0)},vi=i=>{var w,$;ht(i);const p=i.match(/@([\w\u4e00-\u9fff]*)$/);if(p){window.agentApi&&window.agentApi.listAgentDefs().then(E=>hi(E)),fi(((w=so.current)==null?void 0:w.getBoundingClientRect())??null),dr(p[1]),pr(null);return}const x=i.match(/\/([-\w\u4e00-\u9fff]*)$/);if(x){window.agentApi&&window.agentApi.listSkills().then(E=>gi(E.filter(ee=>ee.name))).catch(E=>console.error("[listSkills] slash error:",E)),fi((($=so.current)==null?void 0:$.getBoundingClientRect())??null),pr(x[1]),dr(null);return}dr(null),pr(null)},lc=i=>{vi(i),dr(null),pr(null),requestAnimationFrame(()=>{var p;return(p=ts.current)==null?void 0:p.focus()})},cc=i=>{i.key==="Escape"&&(rs!==null||ur!==null)?(i.preventDefault(),dr(null),pr(null)):i.key==="Escape"&&Dn?(i.preventDefault(),Ai()):i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),Ni())},dc=async i=>{const p=Array.from(i.target.files??[]);if(i.target.value="",p.length===0)return;const x=p.filter(w=>w.type.toLowerCase().startsWith("image/")).length;x>0&&Tr(w=>w+1);try{const w=await _p(p,async E=>wi(await ga(E)));w.attachments.length>0&&Mr(E=>[...E,...w.attachments]),w.images.length>0&&(An(E=>[...E,...w.images]),He||fc());const $=[...w.unsupportedImages,...w.failedImages];$.length>0&&ye(`无法添加图片:${$.map(E=>E.name).join("、")}。仅支持 JPG、PNG、GIF 和 WebP。`)}finally{x>0&&Tr(w=>Math.max(0,w-1))}},uc=i=>{Mr(p=>p.filter((x,w)=>w!==i))},pc=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,co=i=>pc.test(i),fc=()=>{const i=ne.find(x=>x.id===L);if(i&&co(i.modelId))return;const p=ne.find(x=>co(x.modelId));p&&Ie(p.id)},hc=i=>{An(p=>[...p,i])},gc=i=>{An(p=>p.filter((x,w)=>w!==i))},wi=i=>new Promise((p,x)=>{const w=new FileReader;w.onload=()=>p(w.result),w.onerror=x,w.readAsDataURL(i)});l.useEffect(()=>{const i=async p=>{if(!p.clipboardData)return;const x=Array.from(p.clipboardData.items).find($=>$.type.startsWith("image/"));if(!x)return;p.preventDefault();const w=x.getAsFile();if(w){Tr($=>$+1);try{hc(await wi(await ga(w)))}catch{ye("无法添加图片。仅支持 JPG、PNG、GIF 和 WebP。")}finally{Tr($=>Math.max(0,$-1))}}};return window.addEventListener("paste",i),()=>window.removeEventListener("paste",i)},[ne,L]),l.useEffect(()=>{var p;const i=un.current;un.current=null,i!=="skip"&&((p=ks.current)==null||p.scrollIntoView({behavior:i==="instant"?"auto":"smooth"}))},[R]),l.useEffect(()=>window.agentApi?window.agentApi.onEvent(p=>xc(p)):void 0,[xe]),l.useEffect(()=>{const i=++Wr.current,p=r,x=()=>Wr.current===i&&Qe.current===p;return(async()=>{var ee,U,re;const $=window.agentApi;if(!$||bp(ot.current,Bt.current,p))return;if(!p){if(!x())return;(ee=tn.current)==null||ee.invalidate(),Oe(),ye(null),cr(null),_t(null),Zt(null),Kt.current=null,Tn.current=null,N.current=null,X.current+=1,G.current=null,no(null),fr("latest"),zr(null),Lr(null),Ue.current=!1,Cs(!1),_r(!1),Is(null),As(!1),Ms(!1),Gt.current=null,Bt.current=null,Q(""),Fn("full-access");return}ye(null),cr(null),_t(null),Zt(null),Is(null),(U=tn.current)==null||U.invalidate(),he.current+=1,Kt.current=null,Tn.current=null,N.current=null,fr("latest"),_r(!1),zr(null),Lr(null),Ue.current=!1,Cs(!1),((re=G.current)==null?void 0:re.sessionId)!==p&&(X.current+=1,G.current=null,no(null)),As(!0),Ms(!0),Gt.current=p,Bt.current=p,Q(p);const E=me(p);Z(E,p);try{await mu(async()=>{if(!x())throw new DOMException("Session selection changed","AbortError");return await Br($,p,$e(p),{limit:$e(p)==="codex"?Ro:Ln},(H,J)=>{var ls,fe,it,Yn;if(!x())return;const le=H,pe=na((H==null?void 0:H.events)??[]),be=ea((H==null?void 0:H.events)??[]),qe=ra((H==null?void 0:H.events)??[]),Ae=$r(H);jt(p,(ls=H==null?void 0:H.history)==null?void 0:ls.revision),g!=null&&g.compatibility&&_t(p),Fn(za((le==null?void 0:le.permissionMode)??((fe=le==null?void 0:le.metadata)==null?void 0:fe.permissionMode)));const Ye=((it=H==null?void 0:H.history)==null?void 0:it.nextCursor)??null;Kt.current=Ye,Tn.current=Ye,N.current=null;const Me=me(p),Ze=da(Me,Ae,J,H==null?void 0:H.history),rn=H!=null&&H.goalState?jo(Ze,H.goalState):Ze;un.current="instant",Z(rn,p),bn(p,Ye),nt(be,p),Ne(qe,p),wl(H)||Lu(H)?(ot.current=p,W(p)):ot.current===p&&(ot.current=null,W(null)),pe&&De(pe,p);const Qn=rn[rn.length-1];(Qn==null?void 0:Qn.role)==="assistant"&&((Yn=Qn.toolCalls)!=null&&Yn.length)?kt(ko(Qn.toolCalls)?"thinking":"tools"):kt((H==null?void 0:H.agentType)!=="customer-agent"&&(H==null?void 0:H.status)==="running"?"thinking":"idle"),As(!1),Ms(!1)},x),!0})}catch(H){if(!x())return;console.error("[chat] failed to restore session",{sessionId:p,error:H});const J=xu(H);cr(J),g!=null&&g.compatibility&&Zt(J)}finally{x()&&(As(!1),Ms(!1))}})(),()=>{Wr.current===i&&(Wr.current+=1)}},[Oe,me,$e,bn,r,mn,De,fr,Z,Q,jt,kt]);const Gn=l.useCallback(async i=>{const p=window.agentApi;if(!(p!=null&&p.getSessionQueryIndex))return null;const x=++X.current;try{const w=await p.getSessionQueryIndex(i);return X.current!==x||Qe.current!==i||w.sessionId!==i?null:(G.current=w,no(w),w)}catch(w){return X.current===x&&console.warn("[chat] failed to load query index",{sessionId:i,error:w}),null}},[]),ji=l.useCallback(i=>{if(Qt.current!==i&&(Pe.current!==null&&window.clearTimeout(Pe.current),Qt.current=i,Pe.current=null,pt.current=0),Pe.current!==null)return;const p=Math.max(0,Vp-(Date.now()-pt.current));Pe.current=window.setTimeout(()=>{Pe.current=null,pt.current=Date.now(),Qe.current===i&&B(x=>x+1)},p)},[]);l.useEffect(()=>{var E;const i=r;if(!i||Rs||!((E=window.agentApi)!=null&&E.getSessionQueryIndex))return;let p=!1;const x=()=>{!p&&Qe.current===i&&Gn(i)},w=window,$=w.requestIdleCallback?w.requestIdleCallback(x,{timeout:1e3}):window.setTimeout(x,0);return()=>{p=!0,w.cancelIdleCallback&&w.requestIdleCallback?w.cancelIdleCallback($):window.clearTimeout($)}},[Rs,Gn,r,mn]);const ki=l.useCallback(async i=>{if(!(!window.agentApi||document.visibilityState==="hidden")){if(f.current==="anchored"){_r(!0);return}if(gt.current!==i&&(gt.current=i,vt.current=!1,ge.current=!1),vt.current){ge.current=!0;return}vt.current=!0;try{do ge.current=!1,await Br(window.agentApi,i,$e(i),{limit:$e(i)==="codex"?Ro:Ln},(p,x)=>{var be,qe,Ae,Ye,Me,Ze;const w=$r(p),$=me(i),E=da($,w,x,p==null?void 0:p.history),ee=p!=null&&p.goalState?jo(E,p.goalState):E,U=Vt.current,re=!U||U.scrollHeight-U.scrollTop-U.clientHeight<80;un.current=re?null:"skip",Z(ee,i),jt(i,(be=p==null?void 0:p.history)==null?void 0:be.revision),p!=null&&p.goalState&&Ct(ba(p.goalState));const H=Tn.current,J=((qe=p==null?void 0:p.history)==null?void 0:qe.nextCursor)??null;if(Kt.current===H){const rn=Kt.current!==J;Kt.current=J,rn&&((Ae=tn.current)==null||Ae.invalidate(),bn(i,J))}Tn.current=J,(Ye=p==null?void 0:p.history)!=null&&Ye.revision&&p.history.revision!==((Me=G.current)==null?void 0:Me.revision)&&Gn(i);const le=na((p==null?void 0:p.events)??[]);nt(ea((p==null?void 0:p.events)??[]),i),Ne(ra((p==null?void 0:p.events)??[]),i),le&&De(le,i);const pe=ee[ee.length-1];(pe==null?void 0:pe.role)==="assistant"&&((Ze=pe.toolCalls)!=null&&Ze.length)?kt(ko(pe.toolCalls)?"thinking":"tools"):kt(ti(p)?"thinking":"idle")},()=>Qe.current===i&&Gt.current===i),$e(i)==="codex"&&ji(i);while(ge.current)}catch(p){console.error("[chat] failed to refresh native session history",{sessionId:i,error:p})}finally{gt.current===i&&(vt.current=!1)}}},[me,$e,Gn,bn,ji,De,Z,jt,kt]);l.useEffect(()=>{const i=r,p=Pu(g,i)||(g==null?void 0:g.agentType)==="customer-agent"&&i!==T,x=(g==null?void 0:g.agentType)==="customer-agent"||(g==null?void 0:g.occupancy)==="owned-externally"||(g==null?void 0:g.status)==="running";if(!i||!p||!window.agentApi)return;let w=null,$=null,E=!1;const ee=()=>{!E&&document.visibilityState!=="hidden"&&ki(i)},U=()=>{w==null||w(),w=null,$!==null&&window.clearInterval($),$=null},re=()=>{E||$!==null||document.visibilityState==="hidden"||(ee(),$=window.setInterval(ee,2e3))},H=()=>{if(!(E||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){x&&re();return}try{w=window.agentApi.observeSession(i,ee,()=>{w=null,x&&re()})}catch{x&&re()}}},J=()=>{U(),document.visibilityState!=="hidden"&&(ee(),H())};return H(),document.addEventListener("visibilitychange",J),()=>{E=!0,document.removeEventListener("visibilitychange",J),U(),gt.current===i&&(gt.current=null,ge.current=!1),Qt.current===i&&(Pe.current!==null&&window.clearTimeout(Pe.current),Qt.current=null,Pe.current=null,pt.current=0)}},[ki,r,T,g==null?void 0:g.agentType,g==null?void 0:g.occupancy,g==null?void 0:g.status]);const uo=l.useCallback(async()=>{const i=Gt.current,p=Kt.current,x=window.agentApi;if(!x||!i||!p||Re.current)return;Re.current=!0,Is(null);const w=window.setTimeout(()=>{Gt.current===i&&Re.current&&ci(!0)},500);try{const $=me(i);await Br(x,i,$e(i),{before:p,limit:$e(i)==="codex"?hs:Ln},(E,ee)=>{var J,le;const U=$r(E),re=Vt.current;ee!=="trace"&&re&&U.length>0&&(wt.current={scrollHeight:re.scrollHeight,scrollTop:re.scrollTop},un.current="skip");const H=((J=E==null?void 0:E.history)==null?void 0:J.nextCursor)??null;Kt.current=H,jt(i,(le=E==null?void 0:E.history)==null?void 0:le.revision),U.length>0&&Z([...U,...$],i),ee!=="trace"&&bn(i,H)},()=>Gt.current===i&&Qe.current===i,()=>tn.current.consume(i,p,()=>x.getSession(i,{before:p,limit:$e(i)==="codex"?hs:Ln,...$e(i)==="codex"?{view:"core"}:{}})))}catch($){if(Gt.current!==i)return;console.error("[chat] failed to load older history",{sessionId:i,error:$}),Is($ instanceof Error?$.message:"历史消息加载失败")}finally{window.clearTimeout(w),Re.current=!1,Gt.current===i&&ci(!1)}},[me,$e,bn,Z,jt]);l.useEffect(()=>{Zr.current=()=>{uo()}},[uo]);const Si=l.useCallback(async()=>{const i=Gt.current,p=N.current;if(!(!window.agentApi||!i||!p||f.current!=="anchored"||q.current)){q.current=!0,di(!0);try{const x=me(i),w=new Set(x.map($=>$.id));await Br(window.agentApi,i,$e(i),{after:p,limit:$e(i)==="codex"?hs:Ln},$=>{var ee,U;const E=$r($).filter(re=>!w.has(re.id));N.current=((ee=$==null?void 0:$.history)==null?void 0:ee.newerCursor)??null,jt(i,(U=$==null?void 0:$.history)==null?void 0:U.revision),E.length>0&&(un.current="skip",Z([...x,...E],i))},()=>Qe.current===i&&Gt.current===i&&f.current==="anchored")}catch(x){console.error("[chat] failed to load newer anchored history",{sessionId:i,error:x})}finally{q.current=!1,di(!1)}}},[me,$e,Z,jt]);l.useEffect(()=>{Jr.current=()=>{Si()}},[Si]);const Ii=l.useCallback(async()=>{const i=Qe.current;if(!window.agentApi||!i||Ue.current)return!1;const p=++he.current;Ue.current=!0,Cs(!0),Lr(null);try{let x=!1;return await Br(window.agentApi,i,$e(i),{limit:$e(i)==="codex"?Ro:Ln},(w,$)=>{var U,re,H,J,le,pe,be;x=!0;const E=$r(w),ee=((U=w==null?void 0:w.history)==null?void 0:U.nextCursor)??null;$!=="trace"&&((re=tn.current)==null||re.invalidate()),Kt.current=ee,Tn.current=ee,N.current=null,jt(i,(H=w==null?void 0:w.history)==null?void 0:H.revision),fr("latest"),_r(!1),zr(((le=(J=G.current)==null?void 0:J.entries.at(-1))==null?void 0:le.messageId)??null),ce.current=!0,un.current="skip",Z(E,i),$!=="trace"&&bn(i,ee),((pe=w==null?void 0:w.history)==null?void 0:pe.revision)!==((be=G.current)==null?void 0:be.revision)&&Gn(i)},()=>he.current===p&&Qe.current===i),x}catch(x){return ye(x instanceof Error?x.message:"返回最新消息失败"),!1}finally{Ue.current=!1,Cs(!1)}},[$e,Gn,bn,fr,Z,jt]),Ci=l.useCallback(async(i,p=!0)=>{var ee;const x=Qe.current,w=Vt.current;if(!window.agentApi||!x||!w)return;const $=++he.current;zr(i.messageId);const E=Array.from(w.querySelectorAll("[data-message-id]")).find(U=>U.dataset.messageId===i.messageId);if(E){Lr(null),Eo(w,E,"smooth");return}Lr(i.messageId),(ee=tn.current)==null||ee.invalidate();try{await Br(window.agentApi,x,$e(x),{anchor:i.pageToken,limit:$e(x)==="codex"?hs:Ln},(U,re)=>{var le,pe,be,qe,Ae,Ye;if(((le=G.current)==null?void 0:le.revision)!==((pe=U==null?void 0:U.history)==null?void 0:pe.revision))return;const H=$r(U),J=((be=U==null?void 0:U.history)==null?void 0:be.olderCursor)??((qe=U==null?void 0:U.history)==null?void 0:qe.nextCursor)??null;Kt.current=J,N.current=((Ae=U==null?void 0:U.history)==null?void 0:Ae.newerCursor)??null,jt(x,(Ye=U==null?void 0:U.history)==null?void 0:Ye.revision),fr("anchored"),_r(!1),de.current=i.messageId,un.current="skip",Z(H,x),re!=="trace"&&(window.requestAnimationFrame(()=>{if(he.current!==$||Qe.current!==x)return;const Me=Vt.current,Ze=Array.from((Me==null?void 0:Me.querySelectorAll("[data-message-id]"))??[]).find(rn=>rn.dataset.messageId===i.messageId);!Me||!Ze||(Eo(Me,Ze),de.current=null,zr(i.messageId))}),bn(x,J))},()=>he.current===$&&Qe.current===x)}catch(U){if(U.code==="STALE_SESSION_ANCHOR"&&p){const H=await Gn(x),J=H==null?void 0:H.entries.find(le=>le.ordinal===i.ordinal);J&&await Ci(J,!1);return}console.error("[chat] failed to open indexed query",{sessionId:x,error:U}),ye(U instanceof Error?U.message:"无法打开这条消息")}finally{he.current===$&&Lr(null)}},[$e,Gn,bn,fr,Z,jt]),Ri=i=>{if(Pr.current.has(i)||is.current.has(i))return;const p=window.setTimeout(()=>{is.current.delete(i),(async()=>{var x;if(!Pr.current.has(i))try{const w=await((x=window.agentApi)==null?void 0:x.getSessionGoals(i)),$=Qe.current||Bt.current;if(w&&i===$&&Et(w,i),w!=null&&w.active){ot.current=i,i===$&&(hr.current=!1,ye(null),W(i));return}if(hr.current)return;const E=We.getState().getMessagesForSession(i).find(ee=>ee.isQueued&&!ee.queueItemId);if(!E){i===$&&(ot.current=null,W(null));return}we(E.id,ee=>({...ee,isQueued:!1}),i),Dr(E,i)}catch(w){ye(w instanceof Error?w.message:"排队消息自动发送失败")}})()},150);is.current.set(i,p)},xc=i=>{var $,E,ee;const p=Qe.current||Bt.current,x=i._sid||p||void 0;if(i._nativeRunId&&Number.isSafeInteger(i._nativeSequence)){const U=`${i._nativeRunId}:${i._nativeSequence}`;if(Dt.current.has(U))return;Dt.current.add(U),Dt.current.size>2e3&&(Dt.current=new Set([...Dt.current].slice(-1e3)))}const w=!x||x===p;if(w&&f.current==="anchored"){_r(!0);return}switch(i.type){case"run_admitted":if(x){as.current.delete(x);const U=Ls(mt.current,x);U&&(Kn.current===U.token&&(Kn.current=null),rt(void 0,x)),Ru(x)}break;case"context_usage":i.usage&&De(i.usage,x);break;case"text_chunk":i.text&&(x&&i.turnId&&i.messagePhase==="commentary"&&$e(x)==="codex"?Ce(i.turnId,{type:"text_chunk",text:i.text,turnId:i.turnId,itemId:i.itemId,messagePhase:"commentary"},x):_(i.text,x),w&&kt("thinking"));break;case"reasoning_summary_delta":if(typeof i.itemId=="string"&&Number.isSafeInteger(i.sectionIndex)&&typeof i.delta=="string"){const U={type:"reasoning_summary_delta",itemId:i.itemId,sectionIndex:i.sectionIndex,delta:i.delta,...i.turnId?{turnId:i.turnId}:{}};x&&i.turnId&&$e(x)==="codex"?Ce(i.turnId,U,x):je(U,x),w&&kt("thinking")}break;case"runtime_progress":if(typeof i.progressId=="string"&&typeof i.label=="string"&&["thinking","tool","retry","status"].includes(i.phase??"")){const U={progressId:i.progressId,phase:i.phase,label:i.label,...i.detail===void 0?{}:{detail:i.detail},...i.toolCallId===void 0?{}:{toolCallId:i.toolCallId},...i.elapsedSeconds===void 0?{}:{elapsedSeconds:i.elapsedSeconds},...i.current===void 0?{}:{current:i.current},...i.total===void 0?{}:{total:i.total}};xt(U,x),w&&kt(U.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":($=i.activity)!=null&&$.parentToolCallId&&(te(i.activity,x),w&&i.activity.status==="running"&&kt("tools"));break;case"tool_call":w&&kt("tools"),i.toolCall&&i.toolCall.name!=="dispatch_agent"&&i.toolCall.name!=="ask_user"&&i.toolCall.name!=="show_widget"&&(x&&i.turnId&&$e(x)==="codex"?Ce(i.turnId,{type:"tool_call",toolCall:i.toolCall,turnId:i.turnId},x):k({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:i.toolCall.id,name:i.toolCall.name,arguments:i.toolCall.arguments}],timestamp:Date.now()},x));break;case"tool_result":i.result&&(x&&i.turnId&&$e(x)==="codex"?Ce(i.turnId,{type:"tool_result",result:i.result,turnId:i.turnId},x):ae(i.result.toolCallId,i.result.content,i.result.isError,x));break;case"todo_update":i.todos&&lt(i.todos);break;case"cron_update":i.tasks&&Fe(i.tasks);break;case"agent_dispatch":if(k({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:i.agentName,task:i.task??"",subSessionId:i.subSessionId}}],timestamp:Date.now()},x),i.subSessionId){or.current.add(i.subSessionId);const U=ot.current||xe;U&&a&&a(U)}d==null||d({type:"started",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_done":i.subSessionId&&(or.current.delete(i.subSessionId),ve(i.subSessionId,i.status??"completed",i.status==="failed"?i.error:i.summary,x)),d==null||d({type:i.status==="failed"?"failed":"completed",agentName:i.agentName??"",task:i.task??"",subSessionId:i.subSessionId});break;case"agent_progress":i.subSessionId&&i.text&&Te(i.subSessionId,i.text,x);break;case"compacted":k({id:crypto.randomUUID(),role:"assistant",content:i.summary??"",isCompactionSummary:!0,timestamp:Date.now()},x);break;case"show_widget":{const U=i.data??i.widgetData,re={widgetId:i.widgetId,widgetType:i.widgetType,data:U??{}},J=(x?We.getState().getMessagesForSession(x):We.getState().messages).find(le=>{var pe;return((pe=le.widget)==null?void 0:pe.widgetId)===re.widgetId});J?we(J.id,le=>({...le,widget:re}),x):k({id:crypto.randomUUID(),role:"assistant",content:"",widget:re,timestamp:Date.now()},x);break}case"ask_user":if(i.questionId&&(x?We.getState().getMessagesForSession(x):We.getState().messages).some(re=>{var H;return((H=re.askUser)==null?void 0:H.questionId)===i.questionId}))break;k({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:i.questionId??"",question:i.question??"",options:i.options,fields:i.fields,multiSelect:i.multiSelect},timestamp:Date.now()},x);break;case"approval_resolved":{if(!i.questionId)break;const re=(x?We.getState().getMessagesForSession(x):We.getState().messages).find(H=>{var J;return((J=H.askUser)==null?void 0:J.questionId)===i.questionId});re&&we(re.id,H=>({...H,askUser:H.askUser?{...H.askUser,answered:!0,answer:"已处理"}:H.askUser}),x);break}case"text_done":break;case"thinking":w&&kt("thinking");break;case"done":if(x){const U=Pl(i.durationMs);if(U!==void 0){const re=[...me(x)].reverse().find(H=>{var J;return H.role==="assistant"&&!!H.content.trim()&&!((J=H.toolCalls)!=null&&J.length)&&!H.isCompactionSummary});re&&we(re.id,H=>({...H,presentation:{...H.presentation,completionDurationMs:U}}),x)}}if(z(x),w&&!We.getState().messages.some(U=>U.isQueued)&&W(null),w&&(kt("idle"),St.getState().autoSpeak)){const re=[...We.getState().messages].reverse().find(H=>H.role==="assistant"&&H.content&&!H.isCompactionSummary);re!=null&&re.content&&(E=window.agentApi)!=null&&E.ttsSpeak&&(us(),window.agentApi.ttsSpeak(re.content.slice(0,600)).then(H=>{H.ok||ye("TTS 模型播报失败")}).catch(H=>{ye(H instanceof Error?H.message:"TTS 模型播报失败")}))}x&&(Pr.current.has(x)?window.setTimeout(()=>{Ts(x)},150):Ri(x));break;case"error":if(i._preserveActiveRun||z(x),x&&i.code==="SESSION_OCCUPIED"){const U=We.getState().getMessagesForSession(x),re=as.current.get(x),H=Ls(mt.current,x),J=re??(H==null?void 0:H.payload),le=J?[...U].reverse().find(be=>be.role==="user"&&!be.isQueued&&be.content===J.content):w?[...U].reverse().find(be=>be.role==="user"&&!be.isQueued):void 0,pe=J??(le?{content:le.content,images:le.images,agentName:le.agentName}:void 0);le&&Z(U.filter(be=>be.id!==le.id),x),as.current.delete(x),pe!=null&&pe.content&&(rt(H??Dp(x,pe)),wo(x,pe.content),w&&(ht(pe.content),An(pe.images??[]))),w&&ye(null)}if(w){if(i._preserveActiveRun&&x&&(bi.current.add(x),ot.current=x,W(x),kt("thinking")),i.code==="SESSION_ALREADY_RUNNING"){const U=x?We.getState().getMessagesForSession(x):We.getState().messages,re=Mu(U);if(re){const H=U.find(J=>J.id===re);we(re,J=>({...J,isQueued:!0}),x),et&&x&&H&&((ee=window.agentApi)!=null&&ee.enqueueSessionMessage)&&window.agentApi.enqueueSessionMessage(x,{sourceMessageId:H.id,content:H.content,images:H.images,agentName:H.agentName}).then(J=>Et(J,x)).catch(J=>{ye(J instanceof Error?J.message:"排队消息保存失败")})}x&&as.current.delete(x),x&&rt(void 0,x),ye(null)}else if(i.code!=="SESSION_OCCUPIED"){ye(i.message??"Unknown error");const re=[...x?We.getState().getMessagesForSession(x):We.getState().messages].reverse().find(H=>H.role==="user"&&!H.isQueued);He&&(re!=null&&re.content)&&(ht(re.content),x&&wo(x,re.content))}}if(!i._preserveActiveRun){const U=x??p;(!U||ot.current===U)&&(ot.current=null),(!U||We.getState().runningSessionId===U)&&W(null),w&&kt("idle")}x&&!i._preserveActiveRun&&(Pr.current.has(x)?window.setTimeout(()=>{Ts(x)},150):Ri(x));break;case"turn_aborted":z(x),w&&(W(null),kt("idle"));break}},mc=async i=>{var x;if(!oe||!((x=window.agentApi)!=null&&x.setSessionPermissionMode)||Ge)return;const p=xn;Fn(i),On(!1),Hn(!0);try{await window.agentApi.setSessionPermissionMode(oe,i)}catch(w){Fn(p),ye(w instanceof Error?w.message:"权限模式更新失败")}finally{Hn(!1)}},bc=async()=>{var i;if(!(!oe||(g==null?void 0:g.agentType)!=="codex"||!((i=window.agentApi)!=null&&i.releaseCodexSession)||Pn!=="idle")&&!(hn&&!window.confirm("停止当前执行并退出此会话?Codex Desktop 最长约 30 分钟后可用。"))){yn("releasing");try{await window.agentApi.releaseCodexSession(oe),hr.current=!0,Wr.current+=1,ot.current=null,W(null),or.current.clear(),Ct(p=>({...p,active:null,queued:[]})),Jt("idle"),ye(null),yn("released")}catch(p){yn("idle"),ye(p instanceof Error?p.message:"释放 Codex 会话失败")}}},yc=async()=>{var x;const i=ft;if(!i||!oe||st||Kn.current===i.token)return;Kn.current=i.token;const p=(w,$)=>{const E=Bp(w);me($).some(U=>U.id===E)||k({id:E,role:"user",content:w.payload.content,timestamp:Date.now(),agentName:w.payload.agentName,images:w.payload.images},$)};if(i.forkSessionId){dt(!0);const w=Ra(i,i.forkSessionId);rt(w),p(w,w.forkSessionId),Dr(w.payload,w.forkSessionId,w.payload.agentIds).finally(()=>{Kn.current=null,dt(!1)});return}if(!((x=window.agentApi)!=null&&x.forkSession)){Kn.current=null;return}dt(!0);try{const w=await Op({sourceSessionId:i.sourceSessionId,forkSession:E=>window.agentApi.forkSession(E),activateSession:E=>{Bt.current=E,Q(E)},refreshAndSelect:async E=>{s?await s(E.id,E):c==null||c(E.id)}}),$=Ra(i,w.id);rt($),p($,w.id),Dr($.payload,w.id,$.payload.agentIds).finally(()=>{Kn.current=null,dt(!1)}),ye(null)}catch(w){Kn.current=null,ye(w instanceof Error?w.message:"创建会话副本失败"),dt(!1)}},Ai=()=>{hr.current=!0,Wr.current+=1,window.agentApi&&window.agentApi.abort(oe||void 0),ot.current=null,W(null),or.current.clear()},Mi=async i=>{const p=r||xe;if(!p||!window.agentApi)return;const x=We.getState().messages.find(w=>w.id===i);if(!(!x||!x.isQueued))try{x.queueItemId?Et(await window.agentApi.steerSessionMessage(p,x.queueItemId),p):(await window.agentApi.steer(x.content,p,x.agentName),we(i,w=>({...w,isQueued:!1,isSteered:!0}))),In===i&&(ir(null),Ht(""))}catch(w){ye(w instanceof Error?w.message:"引导失败")}},vc=i=>{const p=We.getState().messages.find(x=>x.id===i&&x.isQueued);p&&(ir(i),Ht(p.content))},po=()=>{ir(null),Ht("")},Ei=async i=>{const p=Gr.trim(),x=We.getState().messages.find(w=>w.id===i&&w.isQueued);if(!(!x||!p))try{x.queueItemId&&oe?Et(await window.agentApi.updateSessionMessage(oe,x.queueItemId,p),oe):we(i,w=>w.isQueued?{...w,content:p}:w,oe||void 0),po()}catch(w){ye(w instanceof Error?w.message:"排队消息保存失败")}},wc=async i=>{const p=We.getState().messages.find(x=>x.id===i&&x.isQueued);if(p){if(!await vo(p.content)){ye("复制排队消息失败");return}Ut(i),window.setTimeout(()=>Ut(x=>x===i?null:x),1200)}},jc=async i=>{const p=We.getState().messages,x=p.find(w=>w.id===i&&w.isQueued);if(x)try{x.queueItemId&&oe?Et(await window.agentApi.cancelSessionMessage(oe,x.queueItemId),oe):Z(p.filter(w=>w.id!==i),oe||void 0),In===i&&po()}catch(w){ye(w instanceof Error?w.message:"排队消息删除失败")}},fo=async(i,p)=>{const x=We.getState().messages,w=Tu(x,i,p);if(w!==x){Z(w,oe||void 0);const $=w.filter(E=>E.isQueued&&E.queueItemId);if(oe&&$.length>0)try{Et(await window.agentApi.reorderSessionMessages(oe,$.map(E=>E.queueItemId)),oe)}catch(E){Z(x,oe),ye(E instanceof Error?E.message:"排队消息排序保存失败")}}},kc=(i,p)=>{const x=We.getState().messages.filter(E=>E.isQueued),w=x.findIndex(E=>E.id===i),$=x[w+p];$&&fo(i,$.id)},Sc=async i=>{const p=ws;if(Rr(null),!oe||!p||p===i)return;const x=Se.queued.map(U=>U.id),w=x.indexOf(p),$=x.indexOf(i);if(w<0||$<0)return;const E=[...x];E.splice($,0,E.splice(w,1)[0]);const ee=Se;Ct({...Se,queued:E.map((U,re)=>({...Se.queued.find(H=>H.id===U),position:re}))});try{Et(await window.agentApi.reorderSessionGoals(oe,E),oe)}catch(U){Ct(ee),ye(U instanceof Error?U.message:"目标排序保存失败")}},Ti=async i=>{if(!oe)return;const p=Se.queued.find(x=>x.id===i);try{const x=await window.agentApi.cancelSessionGoal(oe,i);if(Et(x,oe),p!=null&&p.sourceMessageId){const w=We.getState().getMessagesForSession(oe);Z(w.filter($=>$.id!==p.sourceMessageId),oe)}x.active||W(null)}catch(x){ye(x instanceof Error?x.message:"目标删除失败")}};l.useEffect(()=>{In&&(R.some(i=>i.id===In&&i.isQueued)||(ir(null),Ht("")))},[In,R]);async function Dr(i,p,x){var w,$;p.startsWith("runtime:")&&as.current.set(p,{content:i.content,images:i.images?[...i.images]:void 0,agentIds:x?[...x]:void 0,agentName:i.agentName}),hr.current=!1,Pr.current.add(p),sc(p),ot.current=p,W(p);try{if(window.agentApi){const E=He&&$s(Le)?{...(w=at.model)!=null&&w.id?{model:at.model}:{},...Ke?{reasoningEffort:Ke}:{}}:void 0;await window.agentApi.run(i.content,p,x,i.agentName,i.images,E)}}catch(E){ye(E instanceof Error?E.message:"Agent run failed")}finally{if(Pr.current.delete(p),bi.current.delete(p)){ot.current=p,W(p);return}const ee=($=window.agentApi)!=null&&$.getSessionGoals?await window.agentApi.getSessionGoals(p).catch(()=>{}):void 0;if(ee&&p===(Qe.current||Bt.current)&&Et(ee,p),ee!=null&&ee.active){ot.current=p,W(p),u&&u(n,p);return}const U=hr.current?void 0:We.getState().getMessagesForSession(p).find(re=>re.isQueued&&!re.queueItemId);U?(we(U.id,re=>({...re,isQueued:!1}),p),u&&u(n,p),Dr(U,p)):(ot.current=null,W(null),u&&u(n,p))}}const Ni=async()=>{var re,H;if(!Ft.trim()||!sr||Xr>0||f.current==="anchored"&&!await Ii())return;Ns(window.agentApi,us),ye(null);const i=Ft.trim();if(/^\/loop\b/i.test(i)){const J=i.slice(5).trim();if(ht(""),k({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),/^stop$/i.test(J)){window.agentApi&&(await window.agentApi.cronDeleteAll(),Fe([]),k({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(J)||J===""){if(window.agentApi){const Ae=await window.agentApi.cronList();Fe(Ae);const Ye=Ae.length===0?"当前没有定时任务。":Ae.map((Me,Ze)=>`**${Ze+1}.** \`${Me.id.slice(0,6)}\` · ${Ao(Me.cron)} · ${Me.enabled?"▶ 启用":"⏸ 已暂停"}
365
- ${Me.prompt}`).join(`
366
-
367
- `);k({id:crypto.randomUUID(),role:"assistant",content:Ye,timestamp:Date.now()})}return}const le=J.match(/^(?:pause|暂停)\s+(\S+)$/i);if(le){if(window.agentApi){const Ae=$t.find(Me=>Me.id.startsWith(le[1])),Ye=await window.agentApi.cronPause((Ae==null?void 0:Ae.id)??le[1]);if(Ye){const Me=await window.agentApi.cronList();Fe(Me),k({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${Ye.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else k({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${le[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const pe=J.match(/^(?:resume|恢复)\s+(\S+)$/i);if(pe){if(window.agentApi){const Ae=$t.find(Me=>Me.id.startsWith(pe[1])),Ye=await window.agentApi.cronResume((Ae==null?void 0:Ae.id)??pe[1]);if(Ye){const Me=await window.agentApi.cronList();Fe(Me),k({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${Ye.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else k({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${pe[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const be=J.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(be){if(window.agentApi){const Ae=$t.find(Me=>Me.id.startsWith(be[1]));if(await window.agentApi.cronDelete((Ae==null?void 0:Ae.id)??be[1])){const Me=await window.agentApi.cronList();Fe(Me),k({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${be[1]}\` 已删除。`,timestamp:Date.now()})}else k({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${be[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const qe=J.match(/^(\S+)\s+(.+)$/s);if(qe){const Ae=qe[1],Ye=qe[2].trim();if(window.agentApi){let Me=r||xe;if(!Me){const Ze=await window.agentApi.createSession(Ye.slice(0,60)||"定时任务",n||void 0);Me=Ze.id,Q(Ze.id),s&&await s(Ze.id)}try{const Ze=await window.agentApi.cronCreate(Ae,Ye,{sessionId:Me}),rn=await window.agentApi.cronList();Fe(rn),k({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${Ze.id.slice(0,6)}\`),${Ao(Ae)}执行:${Ye}`,timestamp:Date.now()})}catch(Ze){k({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${Ze instanceof Error?Ze.message:String(Ze)}`,timestamp:Date.now()})}}return}k({id:crypto.randomUUID(),role:"assistant",content:"**定时任务用法:**\n- `/loop <间隔/cron> <任务>` — 创建,如 `/loop 5m 检查系统状态` 或 `/loop 0 9 * * * 早报`\n- `/loop list` — 查看所有定时任务\n- `/loop pause <id>` — 暂停\n- `/loop resume <id>` — 恢复\n- `/loop delete <id>` — 删除\n- `/loop stop` — 删除全部\n\n间隔支持:`30s`、`5m`、`2h`;也支持 5 字段 cron 表达式。",timestamp:Date.now()});return}const p=i.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(p){const J=p[1]+p[2],le=p[3].trim();if(le&&window.agentApi){let pe=r||xe;if(!pe){const be=await window.agentApi.createSession(le.slice(0,60)||"定时任务",n||void 0);pe=be.id,Q(be.id),s&&await s(be.id)}try{const be=await window.agentApi.cronCreate(J,le,{sessionId:pe}),qe=await window.agentApi.cronList();Fe(qe),ht(""),k({id:crypto.randomUUID(),role:"user",content:i,timestamp:Date.now()}),k({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${be.id.slice(0,6)}\`),${Ao(J)}执行:${le}`,timestamp:Date.now()})}catch(be){k({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${be instanceof Error?be.message:String(be)}`,timestamp:Date.now()})}return}}const x=Ft.trim(),w=x.match(/^\/goal(?:\s+([\s\S]+))?$/i),$=w?((re=w[1])==null?void 0:re.trim())??"":en?x:null;if($!==null&&!$){ye("请输入目标内容");return}const E=ns.length>0?ns.map(J=>J.name).join(", "):void 0,ee=Er.length>0?[...Er]:void 0,U=ns.map(J=>J.id);if(oo([]),He&&(r||xe)&&(qn.current=!0),ht(""),Mr([]),An([]),$!==null){const J=crypto.randomUUID();let le=null;hr.current=!1;try{const pe=await Ia({text:$,projectId:n??null,sessionId:r||xe,createSession:async(qe,Ae)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(qe,Ae)},activateSession:qe=>{Bt.current=qe,Q(qe),ot.current=qe,W(qe)},showUserMessage:(qe,Ae)=>{le=Ae,k({id:J,role:"user",content:qe,timestamp:Date.now(),agentName:E,images:ee,isGoal:!0,goalId:J},Ae)},onSessionCreated:s}),be=await window.agentApi.enqueueSessionGoal(pe,$,J);Et(be,pe),o&&o(pe,$)}catch(pe){if(le){const be=We.getState().getMessagesForSession(le);Z(be.filter(qe=>qe.id!==J),le)}W(null),ye(pe instanceof Error?pe.message:"目标创建失败")}return}if(Wt){const J=crypto.randomUUID(),le={id:J,role:"user",content:x,timestamp:Date.now(),agentName:E,images:ee,isQueued:!0};if(et&&oe&&((H=window.agentApi)!=null&&H.enqueueSessionMessage))try{const pe=await window.agentApi.enqueueSessionMessage(oe,{sourceMessageId:J,content:x,images:ee,agentIds:U,agentName:E});Et(pe,oe)}catch(pe){ht(x),An(ee??[]),ye(pe instanceof Error?pe.message:"排队消息保存失败")}else k(le);return}lt([]);try{const J=await Ia({text:x,projectId:n??null,sessionId:r||xe,createSession:async(le,pe)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(le,pe)},activateSession:le=>{Bt.current=le,Q(le),ot.current=le,W(le)},showUserMessage:(le,pe)=>k({id:crypto.randomUUID(),role:"user",content:le,timestamp:Date.now(),agentName:E,images:ee},pe),onSessionCreated:s});o&&o(J,x),await Dr({content:x,agentName:E,images:ee},J,U.length>0?U:void 0)}catch(J){ye(J instanceof Error?J.message:"Agent run failed")}};return l.useEffect(()=>{if(!K||!window.agentApi)return;const{text:i,projectId:p,sessionId:x}=K;let w=!1;return(async()=>{try{lt([]);const $=await vp({text:i,projectId:p,sessionId:x,createSession:async(E,ee)=>await window.agentApi.createSession(E,ee),activateSession:E=>{Bt.current=E,Q(E),ot.current=E,W(E)},showUserMessage:(E,ee)=>k({id:crypto.randomUUID(),role:"user",content:E,timestamp:Date.now()},ee),onSessionCreated:s,isCancelled:()=>w});if(!$)return;o&&o($,i),await Dr({content:i},$)}catch($){ye($ instanceof Error?$.message:"语音指令执行失败")}})(),()=>{w=!0}},[K==null?void 0:K.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||"会话"}),m&&C&&j&&e.jsx(rp,{appearanceOpen:S,settingsOpen:b,showSettings:Le==="customer-agent",onOpenDesktopLive:A,desktopLiveOpen:I,hideToBackgroundTitle:P,codexReleaseState:Pn,onHideToBackground:C,onReleaseCodex:(g==null?void 0:g.agentType)==="codex"&&g.occupancy!=="owned-externally"?()=>{bc()}:void 0,onOpenHub:M,onToggleAppearance:j,onOpenSettings:m})]}),e.jsx(cp,{open:Ve,agentSessionId:oe,onClose:()=>Je(!1)}),e.jsxs("div",{className:"chat-messages-frame",children:[e.jsxs("div",{ref:Vt,className:"chat-messages",onScroll:ec,style:{overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[R.length>0&&(li||Ss)&&e.jsx("div",{className:"chat-history-page-status",role:Ss?"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:Ss?"var(--danger)":"var(--text-muted)",fontSize:12},children:li?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 uo(),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:[Ss,",点击重试"]})}),R.length===0&&Rs&&Yl&&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:"正在加载历史消息"})]}),R.length===0&&!hn&&!Rs&&!Ar&&e.jsx(fp,{agentType:(g==null?void 0:g.agentType)??t,ready:sr,onSelectPrompt:lc},oe??"initial-empty-session"),F.map((i,p)=>{var be,qe,Ae,Ye,Me,Ze,rn,Qn,ls;const x=i;if(x.isQueued)return null;if(x.executionTrace)return e.jsx(tp,{trace:x.executionTrace,loadTrace:Jl,loadToolResult:io,renderContent:gs,runtimeProgress:ln,nativeSubagents:cn,onSelectSession:c,workspacePath:y,enableFilePreview:Jn(),refreshSignal:x.executionTrace.turnId===V?zt:0,autoLoad:es==="latest"&&x.executionTrace.turnId===V},i.id);const w=i.role==="user",$=w&&(x.isGoal===!0||[Se.active,...Se.queued,...Se.history].some(fe=>!!(fe&&Ma(fe.objective)===Ma(i.content)))),E=zp(F,p,hn),ee=Mp((be=x.presentation)==null?void 0:be.completionDurationMs);if(x.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)"}})]},i.id);if(x.widget){const fe=mp[x.widget.widgetType];return fe?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(fe,{...x.widget.data,widgetId:x.widget.widgetId,isAgentRunning:hn&&!F.slice(p+1).some(it=>it.role==="user"&&!it.isQueued&&!it.isSteered)})},i.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(x.widget.data,null,2)},i.id)}if(x.askUser)return e.jsx(Yu,{questionId:x.askUser.questionId,question:x.askUser.question,options:x.askUser.options,fields:x.askUser.fields,multiSelect:x.askUser.multiSelect,answered:x.askUser.answered,answer:x.askUser.answer,onAnswer:async(fe,it)=>{var Xe;if(!await((Xe=window.agentApi)==null?void 0:Xe.answerQuestion(x.askUser.questionId,fe,it)))throw new Error("回答未发送成功,请重试;若问题已结束,请刷新会话。");we(i.id,Tt=>({...Tt,askUser:{...Tt.askUser,answered:!0,answer:fe}}),oe??void 0)}},i.id);const U=x.agentName?x.agentName.charAt(0).toUpperCase():"你",re=!w&&p===F.length-1,H=F[p+1],J=H&&H.role!==i.role&&!H.isCompactionSummary,le=(i.toolCalls??[]).map((fe,it)=>{let Yn;if(fe.name==="write_file"&&fe.arguments.file_path){const Xe=fe.arguments.file_path;e:for(let Tt=p;Tt>=0;Tt--){const Nn=F[Tt].toolCalls;if(!Nn)continue;const cs=Tt===p?it-1:Nn.length-1;for(let gr=cs;gr>=0;gr--){const zn=Nn[gr];if(zn.name==="read_file"&&zn.arguments.file_path===Xe&&zn.result&&!zn.isError){Yn=zn.result;break e}}}}return{toolCall:fe,beforeContent:Yn,progress:pl(ln,fe.id),nativeSubagent:cn[fe.id]}}),pe=Ll(le);return e.jsx("div",{"data-message-id":i.id,className:`chat-message-group${E.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:E.compact?0:J?"var(--chat-turn-gap)":"var(--chat-message-gap)"},children:e.jsxs("div",{className:`chat-message-row chat-message-row--${w?"user":"assistant"}`,style:{display:"flex",flexDirection:w?"row-reverse":"row",alignItems:"flex-start",gap:"var(--chat-row-gap)",animation:"fadeInUp 0.3s var(--ease-out) both"},children:[w?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:U}):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--${w?"user":"assistant"}`,style:{maxWidth:"var(--chat-content-max-width)",display:"flex",flexDirection:"column",gap:4,alignItems:w?"flex-end":"flex-start",minWidth:0},children:[e.jsxs("div",{className:`chat-message-bubble chat-message-bubble--${w?"user":"assistant"} ${i.role==="assistant"&&i.content?"message-card":""}`,style:{padding:i.content||w&&((qe=x.images)!=null&&qe.length)?w?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:w?"14px 4px 14px 14px":"4px 14px 14px 14px",background:i.content||w&&((Ae=x.images)!=null&&Ae.length)?w?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:i.content||w&&((Ye=x.images)!=null&&Ye.length)?w?"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:[i.role==="assistant"&&((Me=i.presentation)==null?void 0:Me.reasoning)&&e.jsx(Tl,{sections:i.presentation.reasoning,streaming:hn&&re&&kr==="thinking",startedAt:Ir,renderContent:gs}),w&&x.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"})]}),x.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:i.content})]}):i.role==="assistant"&&i.content?e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:gs(i.content)}):i.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:w?i.content:gs(i.content)}),w&&x.images&&x.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:i.content?8:0},children:x.images.map((fe,it)=>e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":"放大查看图片",onClick:()=>Mn({src:fe,alt:`用户发送的图片 ${it+1}`}),children:e.jsx("img",{className:"chat-message-attachment-image",src:fe,alt:`用户发送的图片 ${it+1}`})},it))}),w&&!((Ze=x.images)!=null&&Ze.length)&&((rn=x.presentation)==null?void 0:rn.attachments)&&x.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:x.presentation.attachments.map((fe,it)=>fe.dataUrl?e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":`放大查看图片:${fe.name}`,onClick:()=>Mn({src:fe.dataUrl,alt:fe.name}),children:e.jsx("img",{className:"chat-message-attachment-image",src:fe.dataUrl,alt:fe.name,title:fe.name})},`${fe.name}-${it}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${fe.name},图片已失效`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:fe.name}),e.jsx("span",{children:"图片已失效"})]},`${fe.name}-${it}`))}),w&&((Qn=x.presentation)==null?void 0:Qn.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:x.presentation.rawContent})]}),pe.map(fe=>fe.action&&fe.items.length>1?e.jsx(El,{items:fe.items,onSelectSession:c,workspacePath:y,enableFilePreview:Jn(),onLoadResult:xi},`group-${fe.items[0].toolCall.id}`):e.jsx(Ys,{toolCall:fe.items[0].toolCall,beforeContent:fe.items[0].beforeContent,progress:fe.items[0].progress,nativeSubagent:fe.items[0].nativeSubagent,onSelectSession:c,workspacePath:y,enableFilePreview:Jn(),onLoadResult:xi},fe.items[0].toolCall.id)),(()=>{const fe=(i.toolCalls??[]).filter(Xe=>Xe.name==="write_file"&&Xe.result&&!Xe.isError);if(fe.length===0)return null;const it=new Map;for(const Xe of fe){const Tt=Xe.arguments.file_path??"",Nn=Xe.arguments.content??"",cs=Nn?Nn.split(`
368
- `).length:0;let gr=0;e:for(let zn=p;zn>=0;zn--){const Hi=F[zn].toolCalls??[];for(let ho=Hi.length-1;ho>=0;ho--){const ds=Hi[ho];if(ds.name==="read_file"&&ds.arguments.file_path===Tt&&ds.result&&!ds.isError){gr=ds.result.split(`
369
- `).length;break e}}}it.set(Tt,{path:Tt,lines:cs,added:Math.max(0,cs-gr),removed:Math.max(0,gr-cs)})}const Yn=[...it.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:"变更汇总"}),Yn.map(Xe=>{const Tt=vl(Xe.path,y),Nn=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:Xe.path,children:Xe.path.replace(/\\/g,"/").split("/").pop()}),Xe.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",Xe.added]}),Xe.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",Xe.removed]}),Xe.added===0&&Xe.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[Xe.lines,"行"]})]});return Jn()&&Tt?e.jsx("button",{type:"button",className:"chat-file-change-link",onClick:()=>vr(Tt),title:`预览 ${Tt}`,"aria-label":`预览改动文件 ${Xe.path.replace(/\\/g,"/").split("/").pop()}`,children:Nn},Xe.path):e.jsx("span",{className:"chat-file-change-link chat-file-change-link--static",children:Nn},Xe.path)})]})})()]}),E.showCompletion&&e.jsxs("div",{className:"msg-completion-footer",children:[e.jsxs("span",{className:"msg-completion-status",children:[e.jsx(Fr,{size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"已完成"}),ee&&e.jsxs("span",{children:[" · 总耗时 ",ee]})]}),e.jsxs("span",{className:"msg-completion-actions",children:[!Jn()&&E.showSpeak&&typeof((ls=window.agentApi)==null?void 0:ls.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>rc(i.id,i.content),title:ss===i.id?"停止播报":"语音播报","aria-label":ss===i.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${ss===i.id?"is-active":""}`,children:ss===i.id?e.jsx(md,{size:12,fill:"currentColor","aria-hidden":"true"}):e.jsx(vd,{size:13,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{vo(i.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(go,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]})]}),!E.showCompletion&&(E.showCopy||$)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[$&&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(bo,{size:13,strokeWidth:1.9,"aria-hidden":"true"})}),E.showCopy&&e.jsx("button",{type:"button",onClick:()=>{vo(i.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(go,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]}),w&&(x.isQueued||x.isSteered)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[x.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"})]}),"排队中"]}),ut&&e.jsxs("button",{onClick:()=>void Mi(i.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:fe=>{fe.currentTarget.style.background="rgba(79,110,247,0.18)",fe.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:fe=>{fe.currentTarget.style.background="var(--accent-dim)",fe.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"})]}),"引导"]})]}),x.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"})}),"已引导"]})]})]})]})},i.id)}),hn&&kn&&e.jsx(Il,{progress:kn,startedAt:Ir}),Js&&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(Ju,{startedAt:Ir})}),(Un||Ar)&&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:Un||Ar}),Un&&e.jsxs("button",{type:"button",onClick:()=>qt(i=>i+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(Zo,{size:14,"aria-hidden":"true"}),"重新加载"]})]}),e.jsx("div",{ref:ks})]}),e.jsx(hu,{entries:(to==null?void 0:to.entries)??[],activeMessageId:ql,loadingMessageId:Vl,onActivate:i=>{Ci(i)}}),es==="anchored"&&e.jsx("button",{type:"button",className:"chat-history-return-latest","data-has-updates":Kl,"data-loading-newer":Gl,"aria-busy":ro||void 0,"aria-label":"回到最新消息",title:"回到最新消息",disabled:ro,onClick:()=>{Ii()},children:ro?e.jsx(Nt,{className:"chat-history-return-latest__spinner",size:16,"aria-hidden":"true"}):e.jsx(Gi,{size:16,"aria-hidden":"true"})}),es!=="anchored"&&Ql&&e.jsx("button",{type:"button",className:"chat-jump-to-bottom","aria-label":"回到底部",title:"回到底部",onClick:tc,children:e.jsx(Gi,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[nr&&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:on==="incompatible"?"var(--danger)":"var(--text-muted)",fontSize:12},children:e.jsx("span",{style:{flex:1},children:on==="incompatible"?Wn||((Wi=g==null?void 0:g.compatibility)==null?void 0:Wi.reason)||`Codex ${((Di=g==null?void 0:g.compatibility)==null?void 0:Di.producerVersion)??"未知版本"} 与当前 ${((Bi=g==null?void 0:g.compatibility)==null?void 0:Bi.readerVersion)??"运行时"} 不兼容`:`正在使用 Codex ${(($i=g==null?void 0:g.compatibility)==null?void 0:$i.readerVersion)??"当前版本"} 验证此会话`})}),jr&&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:ft!=null&&ft.forkSessionId?"副本已创建,但消息尚未发送成功。":"此会话仍由原客户端持有,可创建副本继续。"}),jr&&e.jsx("button",{type:"button",onClick:()=>void yc(),disabled:st,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:st?"wait":"pointer",opacity:st?.65:1},children:st?ft!=null&&ft.forkSessionId?"正在发送…":"正在创建…":ft!=null&&ft.forkSessionId?"重新发送":"以副本继续"})]}),Ee.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 i=new Set(Ee.filter(p=>p.status==="completed").map(p=>p.title.toLowerCase()));return Ee.map(p=>{const x=p.status==="pending",w=p.status==="in-progress",$=p.status==="completed",E=x&&(p.dependsOn??[]).some(ee=>!i.has(ee.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:$?.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:$?"rgba(52,211,153,0.15)":w?"var(--accent-dim)":E?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:$?"1.5px solid rgba(52,211,153,0.6)":w?"1.5px solid var(--accent)":E?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[$&&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"})}),w&&e.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",animation:"pulse 1.2s ease-in-out infinite"}}),E&&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"})}),x&&!E&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:$?"var(--text-muted)":E?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:$?"line-through":"none",flex:1},children:p.title}),E&&e.jsx("span",{title:`等待: ${(p.dependsOn??[]).join(", ")}`,style:{fontSize:10,color:"rgba(239,68,68,0.9)",background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:"等待前置"}),p.agentName&&e.jsxs("span",{style:{fontSize:10,color:"var(--accent)",background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.2)",borderRadius:8,padding:"1px 6px",flexShrink:0},children:["@",p.agentName]})]},p.id)})})()})]}),$t.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(),Fe([]),k({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:"全部删除"})]}),$t.map(i=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:i.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:i.enabled?"#22c55e":"#9ca3af",boxShadow:i.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:i.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:i.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.label||i.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:i.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[i.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(i.id);const p=await window.agentApi.cronList();Fe(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="#d97706",p.currentTarget.style.color="#d97706"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"⏸"}):e.jsx("button",{title:"恢复",onClick:async()=>{if(window.agentApi){await window.agentApi.cronResume(i.id);const p=await window.agentApi.cronList();Fe(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="#22c55e",p.currentTarget.style.color="#22c55e"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"▶"}),e.jsx("button",{title:"删除",onClick:async()=>{if(window.agentApi){await window.agentApi.cronDelete(i.id);const p=await window.agentApi.cronList();Fe(p)}},style:{background:"none",border:"1px solid var(--border-default)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",padding:"2px 7px",fontSize:11},onMouseEnter:p=>{p.currentTarget.style.borderColor="var(--danger)",p.currentTarget.style.color="var(--danger)"},onMouseLeave:p=>{p.currentTarget.style.borderColor="var(--border-default)",p.currentTarget.style.color="var(--text-muted)"},children:"🗑"})]})]},i.id))]}),js.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:js.map((i,p)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"3px 10px 3px 8px",borderRadius:20,background:"var(--accent-dim)",border:"1px solid rgba(79,110,247,0.18)",fontSize:12,color:"var(--accent)",maxWidth:220},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),e.jsx("button",{onClick:()=>uc(p),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,marginLeft:2,fontSize:13,lineHeight:1,display:"flex"},children:"✕"})]},p))}),Er.length>0&&(()=>{const i=ne.find(x=>x.id===L),p=!He&&(!i||!co(i.modelId));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:[p&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:"rgba(234,179,8,0.1)",border:"1px solid rgba(234,179,8,0.4)",color:"rgba(202,138,4,1)",fontSize:12},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"当前模型(",(i==null?void 0:i.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Er.map((x,w)=>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":`预览待发送图片 ${w+1}`,onClick:()=>Mn({src:x,alt:`待发送图片 ${w+1}`}),children:e.jsx("img",{src:x,alt:`待发送图片 ${w+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":`删除待发送图片 ${w+1}`,onClick:()=>gc(w),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:"✕"})]},w))})]})})(),(Se.active||Se.queued.length>0)&&e.jsxs("div",{className:"goal-queue","aria-label":"目标队列",children:[e.jsxs("div",{className:"goal-queue__header",children:[e.jsx(bo,{size:14,strokeWidth:1.9,"aria-hidden":"true"}),e.jsx("span",{children:"目标"}),e.jsx("span",{className:"goal-queue__count",children:Se.queued.length+(Se.active?1:0)})]}),Se.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:Se.active.objective,children:Se.active.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Ti(Se.active.id)},title:"停止当前目标","aria-label":"停止当前目标",children:e.jsx(xs,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]}),Se.queued.map((i,p)=>e.jsxs("div",{className:`goal-queue__row is-queued${ws===i.id?" is-dragging":""}`,draggable:!0,onDragStart:()=>Rr(i.id),onDragEnd:()=>Rr(null),onDragOver:x=>x.preventDefault(),onDrop:()=>{Sc(i.id)},children:[e.jsx(Qi,{className:"goal-queue__grip",size:14,strokeWidth:1.8,"aria-hidden":"true"}),e.jsxs("span",{className:"goal-queue__state",children:["#",p+1]}),e.jsx("span",{className:"goal-queue__objective",title:i.objective,children:i.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Ti(i.id)},title:"移出目标队列","aria-label":"移出目标队列",children:e.jsx(xs,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]},i.id))]}),(()=>{const i=R.filter(p=>p.isQueued);return i.length===0?null:e.jsx("div",{className:"queued-message-list",children:i.map(p=>{const x=p,w=In===p.id,$=x.content.length>80?x.content.slice(0,80)+"…":x.content;return e.jsxs("div",{className:`queued-message-row${ar===p.id?" is-dragging":""}`,"data-queued-message-id":p.id,onDragOver:E=>{!ar||ar===p.id||(E.preventDefault(),E.dataTransfer.dropEffect="move")},onDrop:E=>{E.preventDefault(),ar&&fo(ar,p.id),Bn(null)},children:[e.jsx("button",{type:"button",className:"queued-message-grip",draggable:!w,"aria-label":"拖动调整排队顺序",title:"拖动调整顺序",onDragStart:E=>{Bn(p.id),E.dataTransfer.effectAllowed="move",E.dataTransfer.setData("text/plain",p.id)},onDragEnd:()=>Bn(null),onKeyDown:E=>{(E.key==="ArrowUp"||E.key==="ArrowDown")&&(E.preventDefault(),kc(p.id,E.key==="ArrowUp"?-1:1))},onPointerDown:E=>{E.pointerType==="mouse"||w||(Rn.current={id:p.id,pointerId:E.pointerId},E.currentTarget.setPointerCapture(E.pointerId),Bn(p.id))},onPointerMove:E=>{var H;const ee=Rn.current;if(!ee||ee.pointerId!==E.pointerId)return;E.preventDefault();const U=(H=document.elementFromPoint(E.clientX,E.clientY))==null?void 0:H.closest("[data-queued-message-id]"),re=U==null?void 0:U.dataset.queuedMessageId;re&&re!==ee.id&&fo(ee.id,re)},onPointerUp:E=>{var ee;((ee=Rn.current)==null?void 0:ee.pointerId)===E.pointerId&&(Rn.current=null,Bn(null))},onPointerCancel:()=>{Rn.current=null,Bn(null)},children:e.jsx(Qi,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsxs("div",{className:"queued-message-content",children:[x.agentName&&e.jsxs("span",{className:"queued-message-agent",children:["@",x.agentName]}),w?e.jsx("input",{autoFocus:!0,className:"queued-message-edit-input",value:Gr,onChange:E=>Ht(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.nativeEvent.isComposing?(E.preventDefault(),Ei(p.id)):E.key==="Escape"&&(E.preventDefault(),po())},"aria-label":"编辑排队消息内容"}):e.jsx("span",{className:"queued-message-text",title:x.content,children:$})]}),e.jsxs("div",{className:"queued-message-actions",children:[ut&&e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--accent",onClick:()=>void Mi(p.id),title:"引导到当前对话","aria-label":"引导排队消息到当前对话",children:e.jsx(Bc,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>void wc(p.id),title:Cn===p.id?"已复制":"复制","aria-label":"复制排队消息",children:Cn===p.id?e.jsx(Fr,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(go,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>w?Ei(p.id):vc(p.id),disabled:w&&!Gr.trim(),title:w?"保存":"编辑","aria-label":w?"保存排队消息":"编辑排队消息",children:w?e.jsx(Fr,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(tl,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--danger",onClick:()=>jc(p.id),title:"删除","aria-label":"删除排队消息",children:e.jsx(xs,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]})]},p.id)})})})(),e.jsx("div",{ref:so,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:pi,type:"file",multiple:!0,style:{display:"none"},onChange:dc}),ns.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:ns.map(i=>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"})]}),"@",i.name,e.jsx("button",{onClick:()=>ic(i.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},i.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:ts,rows:3,value:Ft,onChange:i=>vi(i.target.value),onBlur:()=>setTimeout(()=>{dr(null),pr(null)},120),onKeyDown:cc,placeholder:Pn==="released"?"已停止在 AgentRoam 中使用;Codex Desktop 最长约 30 分钟后可用":nr?on==="incompatible"?"Codex 版本不兼容":"正在验证会话兼容性":rr?"原客户端使用中,当前只读":vs?en?"输入要持续推进的目标":Wt?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!sr}),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":gn,onClick:()=>$n(i=>!i),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"})})}),gn&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var i;$n(!1),(i=pi.current)==null||i.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{$n(!1),nc()},children:"语音输入"})]})]}),e.jsx("button",{type:"button",className:`web-native-runtime-status goal-mode-toggle${en?" is-active":""}`,"aria-pressed":en,"aria-label":en?"关闭目标模式":"开启目标模式",title:en?"目标模式已开启":"目标模式",onClick:()=>Yr(i=>!i),children:e.jsx(bo,{size:18,strokeWidth:1.9,"aria-hidden":"true"})}),e.jsxs("div",{className:"web-native-permission-wrap",ref:Mt,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${xn}`,"aria-label":`会话权限:${(Oi=Bs.find(i=>i.value===xn))==null?void 0:Oi.label}`,"aria-haspopup":"menu","aria-expanded":lr,title:`会话权限:${(Fi=Bs.find(i=>i.value===xn))==null?void 0:Fi.label}`,disabled:!oe||Ge,onClick:()=>On(i=>!i),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"})]})}),lr&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:Bs.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":xn===i.value,className:xn===i.value?"is-active":"",onClick:()=>{mc(i.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:xn===i.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:i.label}),e.jsx("small",{children:i.description})]})]},i.value))})]}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Zu,{usage:oe?Be[oe]:void 0,contextWindowK:Lt,compact:!0})}),e.jsx("label",{className:`web-native-model-control${He?" web-native-model-control--native":""}`,title:"切换模型",children:He&&$s(Le)?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"web-native-model-agent",title:`${Na[Le]} 会话`,children:[e.jsx(Jo,{agentType:Le,size:14}),e.jsx("span",{className:"web-native-model-agent-name",children:Na[Le]})]}),ze&&e.jsxs("select",{"aria-label":"当前模型",title:"切换模型",value:ie,onChange:i=>{v({model:i.target.value?Pd(i.target.value):void 0})},children:[e.jsx("option",{value:"",children:"默认模型"}),D.map(i=>e.jsx("option",{value:i.key,children:i.label},i.key)),O.length>0&&e.jsx("optgroup",{label:"设置里的模型",children:O.map(i=>e.jsx("option",{value:i.key,children:i.label},i.key))})]})]}):e.jsx("select",{"aria-label":"当前模型",value:L,disabled:ne.length===0,onChange:i=>{Ie(i.target.value)},children:ne.length===0?e.jsx("option",{value:"",children:"未配置模型"}):ne.map(i=>e.jsx("option",{value:i.id,children:i.name||i.modelId},i.id))})}),Dn?e.jsx("button",{type:"button",onClick:Ai,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&&_e.length>0?e.jsxs("div",{className:"web-native-effort-wrap",ref:sn,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":vn,"aria-label":`推理强度:${Ke?Mo[Ke]:"默认"}`,title:`推理强度:${Ke?Mo[Ke]:"默认"}(点击切换)`,onClick:()=>wn(i=>!i),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"})]})}),vn&&e.jsxs("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:[e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":!Ke,className:Ke?void 0:"is-active",onClick:()=>{v({reasoningEffort:void 0}),wn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Ke?"":"✓"}),"默认"]}),_e.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Ke===i,className:Ke===i?"is-active":void 0,onClick:()=>{v({reasoningEffort:i}),wn(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Ke===i?"✓":""}),Mo[i]]},i))]})]}):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:yt,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Cr,"aria-label":`推理强度:${Ta[ct]}`,title:`推理强度:${Ta[ct]}(点击切换)`,onClick:()=>Qr(i=>!i),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"})]})}),Cr&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:Dl.map(i=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":ct===i.value,className:ct===i.value?"is-active":void 0,onClick:()=>{Ot("reasoningEffort",i.value),Rt(),Qr(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:ct===i.value?"✓":""}),i.label]},i.value))})]}),e.jsx("button",{type:"button",onClick:Ni,disabled:!sr||Xr>0||!Ft.trim(),className:"web-native-send-button","aria-label":Wt?"排队发送":"发送",title:Wt?"排队发送":"发送",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 发送",en?"目标":Wt?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",mi?" · 🎤 正在聆听…":""]})]}),e.jsx(hp,{image:eo,onClose:()=>Mn(null)}),Vn&&rs!==null&&yi.length>0&&Yt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-Vn.top+8,left:Vn.left,width:Vn.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:"智能体"}),yi.map(i=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),oc(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:p=>{p.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:p=>{p.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["@",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:i.description})]},i.id))]}),document.body),Vn&&ur!==null&&lo.length>0&&Yt.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-Vn.top+8,left:Vn.left,width:Vn.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:["技能 (",lo.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:lo.map(i=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),ac(i)},style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",border:"none",background:"transparent",cursor:"pointer"},onMouseEnter:p=>{p.currentTarget.style.background="var(--accent-dim)"},onMouseLeave:p=>{p.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:["/",i.name]}),i.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.description})]},i.name))})]}),document.body)]})}function Eo(t,n,r="auto"){const s=t.getBoundingClientRect(),o=n.getBoundingClientRect(),a=t.scrollTop+o.top-s.top-Math.max(0,(t.clientHeight-o.height)/2);t.scrollTo({top:Math.max(0,a),behavior:r})}const _s=4,Qp=4e6,Yp=8,Xp=.12;function Zp(t,n,r=Xp){if(n<=0)return[];const s=Array.from({length:n},(u,h)=>{const g=Number(t[h]);return Number.isFinite(g)&&g>0?g:1}),o=s.reduce((u,h)=>u+h,0),c=s.map(u=>u/o).map(u=>Math.max(u,r)),d=c.reduce((u,h)=>u+h,0);return c.map(u=>u/d)}function Jp(t,n,r,s=Yp){if(n<=1||t.width<=0||t.height<=0)return t.width<=0||t.height<=0?[]:[{x:Math.round(t.x),y:Math.round(t.y),width:Math.round(t.width),height:Math.round(t.height)}];const o=Math.min(n,6),a=s*(o-1),c=t.width-a;if(c<=0)return[];const d=Zp(r,o),u=[];let h=t.x;for(let g=0;g<o;g+=1){const m=g===o-1?t.x+t.width-h:Math.floor(c*d[g]);u.push({x:Math.round(h),y:Math.round(t.y),width:Math.round(m),height:Math.round(t.height)}),h+=m+s}return u}function ef({siteId:t,name:n,onSetup:r}){const s=window.agentApi,[o,a]=l.useState(null),[c,d]=l.useState({connected:!1,tabs:[]}),[u,h]=l.useState(""),[g,y]=l.useState(!1),[m,b]=l.useState(Date.now()),[C,M]=l.useState(!0),A=l.useRef(null),I=!c.paused&&c.compatible!==!1&&c.tabs.some(P=>P.siteId===t);l.useEffect(()=>{let P=!1,K=!1,R=!1;s.hubChromeStatus().then(k=>{!P&&!K&&d(k)}),typeof s.hubChromeConversation!="function"?h("请重启 AI Hub 桌面端以启用消息面板"):s.hubChromeConversation(t).then(k=>{!P&&!R&&a(k)});const T=s.onHubChromeEvent(k=>{k.type==="chrome-conversation"&&k.conversation.siteId===t&&(R=!0,a(W=>!W||k.conversation.revision>W.revision?k.conversation:W),h("")),k.type==="chrome-status"&&(K=!0,d(k.status),k.status.tabs.some(W=>W.siteId===t)||(a(null),h(""))),k.type==="chrome-page-error"&&k.siteId===t&&h(k.error)}),_=setInterval(()=>b(Date.now()),1e3);return()=>{P=!0,T(),clearInterval(_)}},[s,t]),l.useLayoutEffect(()=>{C&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[o==null?void 0:o.revision,C]);const j=I&&!!o&&m-o.receivedAt>6e3,S=c.paused?"Chrome 网页连接已暂停,点击下方按钮即可恢复。":c.connected&&c.compatible===!1?"请从「连接 Chrome」加载新版自动连接扩展。":I?o?o.generating?"正在回复…":o.composerAvailable?"已同步 · 从下方输入框发送消息":"未找到输入框,请在 Chrome 检查页面":"正在读取网页对话…":"在日常 Chrome 中打开并登录此站点,扩展会自动接入;若已暂停,请在扩展中恢复自动连接。";return e.jsxs("div",{"data-aihub-native-pane":t,style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",minWidth:0},children:[e.jsx("div",{role:"status",style:{padding:"10px 16px",fontSize:12,lineHeight:1.6,color:"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)"},children:S}),e.jsx("div",{ref:A,onScroll:()=>{const P=A.current;P&&M(P.scrollHeight-P.scrollTop-P.clientHeight<60)},style:{flex:1,minHeight:0,overflow:"auto",padding:"18px 16px",overflowWrap:"anywhere"},children:I?o!=null&&o.messages.length?o.messages.map(P=>e.jsxs("article",{"data-message-id":P.id,style:{marginBottom:24,padding:P.role==="user"?"12px 14px":"0 2px",borderRadius:12,background:P.role==="user"?"var(--bg-deep)":"transparent"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8,fontSize:12,color:"var(--text-muted)"},children:[e.jsx("strong",{children:P.role==="user"?"你":n}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto","aria-label":`复制 ${P.role==="user"?"消息":n+" 回复"}`,style:{padding:"2px 5px",fontSize:11},onClick:()=>{navigator.clipboard.writeText(P.content).catch(()=>h("未能复制,请选择文字复制"))},children:"复制"})]}),e.jsx("div",{style:{fontSize:15,lineHeight:1.8,whiteSpace:"pre-wrap",color:"var(--text-primary)"},children:gs(P.content)})]},`${o.conversationId}:${P.id}`)):e.jsx("p",{style:{margin:"32px 0",color:"var(--text-muted)",fontSize:15,lineHeight:1.8},children:"连接后会显示当前网页对话。可以在下方输入消息,也可以在 Chrome 中继续聊天。"}):e.jsxs("div",{style:{display:"grid",gap:14,paddingTop:36,textAlign:"center",justifyItems:"center"},children:[e.jsx("strong",{style:{fontSize:18},children:c.paused?`${n} 已暂停`:`连接 ${n}`}),e.jsx("span",{style:{fontSize:14,color:"var(--text-secondary)",lineHeight:1.7},children:c.paused?"取消 Chrome 的调试提示也会暂停连接,无需重新登录。":"登录态保留在 Chrome,回复会以文字显示在这里。"}),c.paused&&e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",disabled:g,style:{padding:"8px 12px",color:"var(--accent)"},onClick:async()=>{y(!0),h("");try{d(await s.hubChromeResume())}catch(P){h(P instanceof Error?P.message:"恢复连接失败,请检查 Chrome 扩展")}finally{y(!1)}},children:g?"正在恢复…":"恢复全部 Chrome 连接"}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{padding:"8px 12px"},onClick:()=>{s.hubOpenChrome(t).catch(()=>h("无法打开 Chrome,请检查是否已安装"))},children:"登录 / 打开原网页"}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{padding:"8px 12px"},onClick:r,children:"连接设置"})]})}),!C&&e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{alignSelf:"center",padding:"7px 12px",margin:8},onClick:()=>M(!0),children:"回到最新回复 ↓"}),(u||j)&&e.jsx("div",{role:u?"alert":"status",title:u||"暂未收到网页更新,请检查 Chrome 标签页或扩展连接;不代表 AI 已停止回答",style:{padding:"6px 16px",fontSize:12,lineHeight:1.6,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:u?"var(--danger)":"var(--text-muted)"},children:u||"同步暂未更新"})]})}function tf({onClose:t}){const n=window.agentApi,[r,s]=l.useState(""),[o,a]=l.useState(!1),[c,d]=l.useState(""),[u,h]=l.useState(!1);l.useEffect(()=>{let y=!0;n.hubChromeStatus().then(b=>{y&&h(b.connected&&b.compatible!==!1)}).catch(()=>{y&&s("暂时无法检测插件连接,请稍后重试")});const m=n.onHubChromeEvent(b=>{b.type==="chrome-status"&&h(b.status.connected&&b.status.compatible!==!1)});return()=>{y=!1,m()}},[n]);const g=async()=>{a(!0),s("");try{const y=await n.hubChromeInstallExtension();d(y.path),s(y.browserOpened?"已打开 Chrome 扩展管理页,插件目录路径已复制。":"未能打开 Chrome。请先安装或打开 Google Chrome,再进入 chrome://extensions;插件目录路径已复制。")}catch{s("未能准备插件,请确认桌面端已启动,稍后重试。")}finally{a(!1)}};return e.jsxs("div",{"data-aihub-chrome-setup":"",style:{flexShrink:0,padding:"12px 18px",background:"var(--bg-elevated)",borderBottom:"1px solid var(--border-subtle)",fontSize:12},children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",marginBottom:8},children:[e.jsx("strong",{children:"连接日常 Google Chrome"}),e.jsx("span",{role:"status",children:u?"扩展已连接":"等待扩展连接"}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{marginLeft:"auto"},onClick:t,children:"收起"})]}),e.jsx("p",{style:{margin:"0 0 8px",lineHeight:1.7},children:"插件已随桌面端附带,无需另行下载。首次加载需要在 Chrome 中确认;加载后自动连接,连接成功后此引导会自动收起。已安装时刷新 AI Hub 扩展即可更新。"}),e.jsxs("ol",{style:{margin:0,paddingLeft:20,lineHeight:1.9},children:[e.jsx("li",{children:"点击「安装浏览器插件」,在打开的 Chrome 扩展管理页开启「开发者模式」。"}),e.jsx("li",{children:"选择「加载已解压的扩展程序」,选中 ai-hub-chrome-extension 文件夹。macOS 文件选择窗口可按 ⌘⇧G,粘贴已复制的路径并打开。"}),e.jsx("li",{children:"在同一个 Chrome 中完成网站登录,即可回到 AI Hub 查看回复并同步发送。取消 Chrome 顶部的调试提示会暂停连接;在 AI Hub 点击「恢复全部 Chrome 连接」即可继续。"})]}),e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",marginTop:8},children:[e.jsx("button",{type:"button",disabled:o,className:"ui-icon-button ui-icon-button--auto",onClick:()=>void g(),style:{padding:"5px 10px"},children:o?"正在打开…":"安装浏览器插件"}),e.jsx("button",{type:"button",className:"ui-icon-button ui-icon-button--auto",onClick:()=>{n.hubChromeRevealExtension().catch(()=>s("未能打开扩展目录"))},style:{padding:"5px 10px"},children:"打开插件文件夹"}),r&&e.jsx("span",{role:"status",children:r})]}),c&&e.jsxs("p",{style:{margin:"8px 0 0",overflowWrap:"anywhere",userSelect:"text"},children:["插件目录:",c]})]})}const nf=["chatgpt","gemini","grok"];function Ps(t){return nf.includes(t)}const rf=52,To=30,sf=4;function of(t,n){return t.includes(n)?t.length>1?t.filter(r=>r!==n):t:t.length<sf?[...t,n]:t}function af(t){return(t.trim()[0]||"?").toUpperCase()}function La(t){try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function lf({onExit:t}){const n=typeof window<"u"?window.agentApi:void 0,r=typeof(n==null?void 0:n.hubGetConfig)=="function",[s,o]=l.useState([]),[a,c]=l.useState([]),[d,u]=l.useState([]),[h,g]=l.useState(null),[y,m]=l.useState({}),[b,C]=l.useState({}),[M,A]=l.useState({}),[I,j]=l.useState(""),[S,P]=l.useState([]),[K,R]=l.useState(""),[T,_]=l.useState(!1),k=l.useRef(null),W=l.useRef(null),[Q,ae]=l.useState(!1),[ve,Te]=l.useState([]),[we,Z]=l.useState(!1),[me,Be]=l.useState(!1),[It,tt]=l.useState(""),[De,xt]=l.useState(""),[nt,z]=l.useState(!1),[te,Ne]=l.useState([]);l.useEffect(()=>{if(!(n!=null&&n.hubChromeStatus))return;let B=!1,F=!1;const V=ne=>{if(B)return;const L=ne.connected&&ne.compatible!==!1;Ne(L?ne.tabs.map(Ie=>Ie.siteId):[]),L?z(!1):F||z(!0),F=!0};n.hubChromeStatus().then(V).catch(()=>{!B&&!F&&(F=!0,z(!0))});const Y=n.onHubChromeEvent(ne=>{ne.type==="chrome-status"&&V(ne.status)});return()=>{B=!0,Y()}},[n]);const je=l.useRef(null),Ce=l.useRef(null);l.useRef(0),l.useLayoutEffect(()=>{const B=W.current;B&&(B.style.height="32px",I&&(B.style.height=`${Math.max(32,Math.min(B.scrollHeight,120))}px`))},[I,a.length]);const Oe=async B=>{if(!(Q||T)){_(!0),R("");try{if(B.length+S.length>_s)throw new Error(`最多添加 ${_s} 张图片`);const F=await Promise.all(B.map(async V=>{if(!/^image\/(png|jpeg|webp)$/.test(V.type))throw new Error("请选择 PNG、JPEG 或 WebP 图片");if(V.size*4/3+32>Qp)throw new Error("单张图片不能超过约 3 MB");return new Promise((Y,ne)=>{const L=new FileReader;L.onload=()=>Y(String(L.result)),L.onerror=()=>ne(new Error("图片读取失败,请重试")),L.readAsDataURL(V)})}));P(V=>[...V,...F].slice(0,_s))}catch(F){R(F instanceof Error?F.message:"图片读取失败")}finally{_(!1)}}},xe=l.useMemo(()=>h?Jp(h,a.length,d):[],[h,a.length,d]);l.useEffect(()=>{if(!r||xe.length===0)return;const B=a.map((F,V)=>{const Y=xe[V];return{siteId:F,x:Y.x,y:Y.y+To,width:Y.width,height:Math.max(Y.height-To,0)}});n==null||n.hubSetBounds(B)},[r,n,xe,a]),l.useEffect(()=>{if(r)for(const B of a)n==null||n.hubOpenSite(B)},[r,n,a]),l.useEffect(()=>{if(!r)return;const B=je.current;if(!B)return;const F=()=>{const ne=B.getBoundingClientRect();g(L=>L&&Math.abs(L.x-ne.x)<.5&&Math.abs(L.y-ne.y)<.5&&Math.abs(L.width-ne.width)<.5&&Math.abs(L.height-ne.height)<.5?L:{x:ne.x,y:ne.y,width:ne.width,height:ne.height})},V={current:0},Y=new ResizeObserver(()=>{cancelAnimationFrame(V.current),V.current=requestAnimationFrame(F)});return Y.observe(B),F(),()=>{Y.disconnect(),cancelAnimationFrame(V.current)}},[r,me]),l.useEffect(()=>{if(!we)return;const B=V=>{var Y;(Y=Ce.current)!=null&&Y.contains(V.target)||Z(!1)},F=()=>Z(!1);return document.addEventListener("pointerdown",B),window.addEventListener("blur",F),()=>{document.removeEventListener("pointerdown",B),window.removeEventListener("blur",F)}},[we]),l.useEffect(()=>{if(!r||!n)return;let B=!1;n.hubGetConfig().then(V=>{B||(o(V.sites),c(Y=>Y.length>0?Y:V.sites.slice(0,1).map(ne=>ne.id)))});const F=n.onHubEvent(V=>{V.type==="load-failed"?(m(Y=>({...Y,[V.siteId]:V.errorCode??-1})),C(Y=>({...Y,[V.siteId]:!1}))):V.type==="loaded"?(m(Y=>{if(!(V.siteId in Y))return Y;const ne={...Y};return delete ne[V.siteId],ne}),C(Y=>({...Y,[V.siteId]:!1}))):V.type==="loading"?(C(Y=>({...Y,[V.siteId]:!0})),A(Y=>{if(!(V.siteId in Y))return Y;const ne={...Y};return delete ne[V.siteId],ne})):V.type==="google-auth-external"&&A(Y=>({...Y,[V.siteId]:!0}))});return()=>{B=!0,F(),n.hubHideAll()}},[r,n]),l.useEffect(()=>{const B=Math.max(a.length,0);u(F=>F.length===B?F:Array.from({length:B},()=>B>0?1/B:0))},[a.length]);const Ee=l.useCallback(B=>{c(F=>of(F,B))},[]),lt=l.useCallback(B=>{m(F=>{const V={...F};return delete V[B],V}),n==null||n.hubReload(B),n==null||n.hubOpenSite(B)},[n]),$t=l.useCallback(B=>{a.length<=1||(n==null||n.hubCloseSite(B),c(F=>F.filter(V=>V!==B)))},[n,a.length]),Fe=l.useCallback(async()=>{const B=I.trim();if(!(!B&&S.length===0||!n||Q||T||a.length===0)){ae(!0);try{const F=await n.hubBroadcast(B,a,S),V=F.map(Y=>({...Y,at:Date.now()}));Te(V),F.length>0&&F.every(Y=>Y.ok)&&(j(""),P([]),R("")),setTimeout(()=>{Te(Y=>Y.filter(ne=>!ne.ok||Date.now()-ne.at<8e3))},8200)}catch(F){R(F instanceof Error?F.message:"发送失败,请重试")}finally{ae(!1)}}},[n,I,S,T,Q,a]),Se=l.useCallback(async()=>{if(!n||!La(De))return;const B=De.trim(),F=It.trim()||new URL(B).hostname,V={id:`custom-${Math.random().toString(36).slice(2,10)}`,name:F,url:B,adapter:"generic"},Y=await n.hubSetConfig({version:1,sites:[...s,V]});o(Y.sites),tt(""),xt(""),Be(!1)},[n,It,De,s]),Ct=l.useCallback(async B=>{if(!n||s.length<=1)return;n.hubCloseSite(B);const F=await n.hubSetConfig({version:1,sites:s.filter(V=>V.id!==B)});o(F.sites),c(V=>{const Y=V.filter(ne=>ne!==B);return Y.length>0?Y:F.sites.slice(0,1).map(ne=>ne.id)})},[n,s]),zt=l.useCallback((B,F)=>{F.preventDefault();const V=xe.length,Y=V>1?8:0,ne=((h==null?void 0:h.width)??0)-Y*(V-1);if(ne<=0)return;const L=F.clientX,Ie=[...d],ke=xe[B].width,Lt=Ie[B]+Ie[B+1],ct=Rt=>{const oe=Rt.clientX-L,pn=80,Xt=Lt*ne,mt=Math.min(Math.max(ke+oe,pn),Xt-pn),rt=[...Ie];rt[B]=mt/ne,rt[B+1]=(Xt-mt)/ne,u(rt)},Ot=()=>{window.removeEventListener("pointermove",ct),window.removeEventListener("pointerup",Ot)};window.addEventListener("pointermove",ct),window.addEventListener("pointerup",Ot)},[d,xe,h]);return r?e.jsxs("div",{style:{position:"absolute",inset:0,zIndex:30,display:"flex",flexDirection:"column",background:"var(--bg-workspace)"},children:[e.jsxs("div",{className:"aihub-topbar",style:{height:rf,display:"flex",alignItems:"center",gap:10,padding:"0 14px",borderBottom:"1px solid var(--border-subtle)",WebkitAppRegion:"drag"},children:[e.jsx("button",{type:"button",onClick:t,title:"返回对话","aria-label":"返回对话",className:"ui-icon-button ui-icon-button--auto",style:{WebkitAppRegion:"no-drag",padding:"5px 10px",whiteSpace:"nowrap"},children:"← 返回"}),e.jsx("strong",{style:{fontSize:14,color:"var(--text-secondary)"},children:"AI Hub"}),e.jsx("button",{type:"button",className:"ui-icon-button ui-icon-button--auto",onClick:()=>z(B=>!B),style:{WebkitAppRegion:"no-drag",marginLeft:"auto",padding:"5px 10px"},children:"连接 Chrome"})]}),nt&&e.jsx(tf,{onClose:()=>z(!1)}),e.jsxs("div",{ref:je,style:{flex:1,position:"relative",overflow:"hidden",minHeight:0},children:[xe.map((B,F)=>{const V=a[F],Y=s.find(L=>L.id===V),ne=V in y;return e.jsxs("div",{"data-aihub-pane":V,style:{position:"absolute",left:B.x-((h==null?void 0:h.x)??0),top:B.y-((h==null?void 0:h.y)??0),width:B.width,height:B.height,display:"flex",flexDirection:"column",borderRight:F<xe.length-1?"1px solid var(--border-subtle)":void 0},children:[e.jsxs("div",{style:{height:To,display:"flex",alignItems:"center",gap:6,padding:"0 8px",borderBottom:"1px solid var(--border-subtle)",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{"aria-hidden":"true",style:{width:8,height:8,borderRadius:"50%",background:Ps(V)?te.includes(V)?"var(--success)":"var(--text-muted)":ne?"#f7768e":b[V]?"var(--accent-glow)":"#9ece6a",flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:40,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(Y==null?void 0:Y.name)??V}),M[V]&&e.jsx("span",{title:"Google 登录已在系统浏览器打开,登录状态不会同步回 AI Hub。如需继续内嵌使用,请选择邮箱登录。","aria-label":"Google 登录受限",style:{flexShrink:0,fontSize:10,padding:"1px 6px",borderRadius:999,color:"#f7768e",border:"1px solid currentColor",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:180},children:"Google 登录已转至浏览器,内嵌请用邮箱"}),Ps(V)&&e.jsx("button",{type:"button","aria-label":`打开 ${(Y==null?void 0:Y.name)??V} Chrome 页面`,title:"在日常 Chrome 中登录或查看页面",className:"ui-icon-button ui-icon-button--auto",onClick:()=>{n.hubOpenChrome(V).catch(()=>z(!0))},style:{padding:"2px 6px",fontSize:11},children:"Chrome ↗"}),e.jsx("button",{type:"button",title:"刷新","aria-label":`刷新 ${(Y==null?void 0:Y.name)??V}`,onClick:()=>lt(V),className:"ui-icon-button",style:{padding:2},children:"⟳"}),a.length>1&&e.jsx("button",{type:"button",title:"关闭页面","aria-label":`关闭 ${(Y==null?void 0:Y.name)??V}`,onClick:()=>$t(V),className:"ui-icon-button",style:{padding:2},children:"×"})]}),e.jsxs("div",{style:{flex:1,position:"relative",background:"var(--bg-surface)"},children:[Ps(V)&&e.jsx(ef,{siteId:V,name:(Y==null?void 0:Y.name)??V,onSetup:()=>z(!0)}),!Ps(V)&&ne&&e.jsx("div",{style:{position:"absolute",inset:0,display:"grid",placeItems:"center"},children:e.jsxs("div",{style:{textAlign:"center",display:"grid",gap:10,color:"var(--text-muted)",fontSize:12},children:[e.jsxs("span",{children:["页面加载失败(",y[V],")"]}),e.jsx("button",{type:"button",onClick:()=>lt(V),className:"ui-icon-button ui-icon-button--auto",style:{justifySelf:"center",padding:"5px 12px"},children:"重试"})]})})]}),F<xe.length-1&&e.jsx("div",{"data-aihub-divider":F,onPointerDown:L=>zt(F,L),title:"拖动调整宽度",style:{position:"absolute",top:0,bottom:0,right:-5,width:10,cursor:"col-resize",zIndex:5}})]},V)}),xe.length===0&&e.jsx("div",{style:{position:"absolute",inset:0,display:"grid",placeItems:"center",color:"var(--text-muted)",fontSize:13},children:"从输入框选择一个 AI 站点"})]}),e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",padding:"8px 12px 10px",display:"flex",flexDirection:"column",gap:8,background:"var(--bg-surface)"},children:[e.jsxs("div",{ref:Ce,style:{position:"relative",display:"flex",flexDirection:"column",gap:8},children:[we&&e.jsxs("div",{role:"listbox","aria-label":"选择要发送的 AI 站点","data-aihub-site-picker":"",style:{width:"min(320px, 100%)",maxHeight:280,overflowY:"auto",padding:4,border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-workspace)",boxShadow:"0 -8px 24px rgba(0, 0, 0, 0.12)"},children:[s.map(B=>{const F=a.includes(B.id),V=B.id.startsWith("custom-");return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsxs("button",{type:"button",role:"option","aria-selected":F,onClick:()=>Ee(B.id),style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:0,borderRadius:6,background:F?"var(--bg-glass)":"transparent",color:"var(--text-secondary)",cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{"aria-hidden":"true",style:{width:20,height:20,display:"grid",placeItems:"center",borderRadius:"50%",border:`1px solid ${F?"var(--accent)":"var(--border-default)"}`,background:F?"var(--accent)":"transparent",color:F?"var(--bg-workspace)":"transparent",flexShrink:0},children:e.jsx(Fr,{size:13,strokeWidth:2.5})}),e.jsx("span",{"aria-hidden":"true",style:{width:24,height:24,display:"grid",placeItems:"center",borderRadius:6,background:"var(--accent-glow)",fontSize:12,fontWeight:600,flexShrink:0},children:af(B.name)}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13},children:B.name})]}),V&&e.jsx("button",{type:"button",title:`删除站点 ${B.name}`,"aria-label":`删除站点 ${B.name}`,onClick:()=>void Ct(B.id),className:"ui-icon-button",style:{width:30,height:30,padding:0,flexShrink:0},children:e.jsx(xs,{size:14,"aria-hidden":"true"})})]},B.id)}),e.jsx("div",{style:{height:1,margin:"4px 6px",background:"var(--border-subtle)"}}),me?e.jsxs("div",{style:{display:"grid",gap:6,padding:6},children:[e.jsx("input",{value:It,onChange:B=>tt(B.target.value),placeholder:"名称(可选)",style:{minWidth:0,padding:"7px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-secondary)",fontSize:12}}),e.jsx("input",{value:De,onChange:B=>xt(B.target.value),placeholder:"https://...",style:{minWidth:0,padding:"7px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-surface)",color:"var(--text-secondary)",fontSize:12}}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{type:"button",onClick:()=>void Se(),disabled:!La(De),className:"ui-icon-button ui-icon-button--auto",style:{padding:"5px 10px",fontSize:12},children:"添加"}),e.jsx("button",{type:"button",onClick:()=>Be(!1),className:"ui-icon-button ui-icon-button--auto",style:{padding:"5px 10px",fontSize:12},children:"取消"})]})]}):e.jsxs("button",{type:"button",onClick:()=>Be(!0),className:"ui-icon-button ui-icon-button--auto",style:{width:"100%",justifyContent:"flex-start",gap:7,padding:"7px 9px",fontSize:12},children:[e.jsx(Ho,{size:14,"aria-hidden":"true"}),"添加站点"]})]}),e.jsxs("div",{"data-aihub-composer":"",style:{display:"flex",alignItems:"center",gap:8,minHeight:48,padding:"6px 8px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-workspace)"},children:[e.jsxs("button",{type:"button",onClick:()=>Z(B=>!B),"aria-haspopup":"listbox","aria-expanded":we,"aria-label":"选择 AI 站点",title:"选择 AI 站点",className:"ui-icon-button ui-icon-button--auto",style:{height:34,gap:5,padding:"0 10px",fontSize:12,whiteSpace:"nowrap",flexShrink:0},children:[a.length," 个 AI",e.jsx(Wc,{size:14,"aria-hidden":"true",style:{transform:we?"rotate(180deg)":void 0}})]}),e.jsx("input",{ref:k,type:"file",accept:"image/png,image/jpeg,image/webp",multiple:!0,hidden:!0,onChange:B=>{const F=Array.from(B.target.files??[]);B.target.value="",Oe(F)}}),e.jsx("button",{type:"button","aria-label":"添加图片附件",title:"添加图片附件(也可粘贴截图)",disabled:Q||T||S.length>=_s,onClick:()=>{var B;return(B=k.current)==null?void 0:B.click()},className:"ui-icon-button",style:{width:34,height:34,padding:0,flexShrink:0},children:e.jsx(ud,{size:17,"aria-hidden":"true"})}),e.jsx("textarea",{ref:W,"aria-label":"发送给选中的 AI",disabled:Q,value:I,onChange:B=>j(B.target.value),onPaste:B=>{const F=Array.from(B.clipboardData.files);F.length!==0&&(B.preventDefault(),Oe(F))},onKeyDown:B=>{B.nativeEvent.isComposing||B.nativeEvent.keyCode===229||(B.key==="Enter"&&(!B.shiftKey||B.metaKey||B.ctrlKey)?(B.preventDefault(),Fe()):B.key==="Escape"&&we&&(B.preventDefault(),Z(!1)))},rows:1,placeholder:`一次输入,发到 ${a.length} 个选中的 AI(Enter 发送,Shift+Enter 换行)`,style:{flex:1,minWidth:0,height:32,minHeight:32,maxHeight:120,boxSizing:"border-box",resize:"none",padding:"4px 2px",border:0,outline:"none",boxShadow:"none",background:"transparent",color:"var(--text-primary)",fontSize:13,lineHeight:1.5,textAlign:I?"left":"center"}}),e.jsx("button",{type:"button",onClick:()=>void Fe(),disabled:!I.trim()&&S.length===0||Q||T||a.length===0,title:"同步发送(Enter)","aria-label":"同步发送",className:"ui-icon-button",style:{width:36,height:36,padding:0,borderRadius:"50%",background:(I.trim()||S.length>0)&&!Q?"var(--accent)":"var(--bg-glass)",color:(I.trim()||S.length>0)&&!Q?"var(--bg-workspace)":"var(--text-muted)",flexShrink:0},children:e.jsx(hd,{size:16,"aria-hidden":"true"})})]})]}),S.length>0&&e.jsx("div",{"aria-label":"待发送图片",style:{display:"flex",gap:8,flexWrap:"wrap"},children:S.map((B,F)=>e.jsxs("div",{style:{position:"relative",width:56,height:56},children:[e.jsx("img",{src:B,alt:`附件 ${F+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:6}}),e.jsx("button",{type:"button","aria-label":`移除附件 ${F+1}`,disabled:Q,onClick:()=>P(V=>V.filter((Y,ne)=>ne!==F)),className:"ui-icon-button",style:{position:"absolute",top:0,right:0,padding:2,background:"var(--bg-workspace)"},children:e.jsx(qr,{size:12})})]},`${F}-${B.length}`))}),K&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"var(--text-secondary)",textAlign:"center"},children:K}),ve.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center",minHeight:18},children:ve.map(B=>{var F;return e.jsx("span",{role:"status",style:{fontSize:11,padding:"3px 10px",borderRadius:999,color:B.ok?"#9ece6a":"#f7768e",background:"var(--bg-glass)",whiteSpace:"normal",overflowWrap:"anywhere"},children:(((F=s.find(V=>V.id===B.siteId))==null?void 0:F.name)??B.siteId)+(B.ok?" ✓":` ✕ ${B.reason??"失败"}`)},B.siteId)})})]})]}):e.jsx("div",{style:{position:"absolute",inset:0,display:"grid",placeItems:"center",background:"var(--bg-workspace)",zIndex:30},children:e.jsxs("div",{style:{textAlign:"center",color:"var(--text-muted)",fontSize:13,display:"grid",gap:12},children:[e.jsx("span",{children:"AI Hub 仅在桌面端可用"}),e.jsx("button",{type:"button",onClick:t,className:"ui-icon-button ui-icon-button--auto",style:{justifySelf:"center",padding:"6px 14px"},children:"返回"})]})})}const Bl=new Set(["downloading","installing","reconnecting"]),cf=new Set(["checking",...Bl]),df=6e3,uf=24e3;function pf(){const[t,n]=l.useState(null),[r,s]=l.useState(()=>sessionStorage.getItem("agentroam.dismissed-update"));if(l.useEffect(()=>{var C;let g=!0;const y=window.agentApi,m=((C=y.onUpdateStatus)==null?void 0:C.call(y,M=>{g&&n(M)}))??(()=>{});y.getUpdateStatus().then(M=>{g&&n(M)}).catch(()=>{});const b=window.setTimeout(()=>{y.checkForUpdate().then(M=>{g&&n(M)}).catch(()=>{})},df+Math.floor(Math.random()*(uf+1)));return()=>{g=!1,window.clearTimeout(b),m()}},[]),l.useEffect(()=>{if(!t||!cf.has(t.phase))return;const g=window.setInterval(()=>{window.agentApi.getUpdateStatus().then(n).catch(()=>{})},1500);return()=>window.clearInterval(g)},[t==null?void 0:t.phase]),!t||["idle","checking","up-to-date","unavailable"].includes(t.phase)||t.phase==="available"&&t.targetVersion===r)return null;const o=Bl.has(t.phase),a=t.phase==="failed",c=t.phase==="complete",d=o?t.phase==="downloading"?`正在下载${t.progress!==void 0?` ${t.progress}%`:""}`:t.phase==="installing"?"正在安装":"正在重连":a?"更新失败,重试":c?t.message??"更新已就绪":`发现 AgentRoam ${t.targetVersion}`,u=async()=>{try{n(await window.agentApi.installUpdate())}catch(g){n({...t,phase:"failed",message:g instanceof Error?g.message:"更新失败"})}},h=()=>{t.targetVersion&&(sessionStorage.setItem("agentroam.dismissed-update",t.targetVersion),s(t.targetVersion))};return e.jsxs("aside",{className:`update-notice${a?" update-notice--failed":""}`,"aria-live":"polite",children:[e.jsxs("div",{className:"update-notice__content",children:[e.jsx("strong",{children:d}),!o&&!c&&e.jsx("span",{children:"点击后才会下载安装文件"}),a&&t.message&&e.jsx("span",{children:t.message})]}),!o&&!c&&e.jsxs("button",{className:"update-notice__action",type:"button",onClick:()=>void u(),title:a?"重试更新":"下载更新",children:[a?e.jsx(Zo,{size:16}):e.jsx(el,{size:16}),e.jsx("span",{children:a?"重试":"更新"})]}),!o&&e.jsx("button",{className:"update-notice__close",type:"button",onClick:h,title:"关闭更新提醒","aria-label":"关闭更新提醒",children:e.jsx(qr,{size:16})})]})}function ff(){const[t,n]=l.useState(null);l.useEffect(()=>{const a=window.agentApi;if(!(a!=null&&a.desktopLiveGetStatus)||!(a!=null&&a.onDesktopLiveStatus))return;let c=!0;a.desktopLiveGetStatus().then(u=>{c&&n(u)}).catch(()=>{});const d=a.onDesktopLiveStatus(u=>n(u));return()=>{c=!1,d()}},[]);const r=t==null?void 0:t.controlState;if(!((t==null?void 0:t.enabled)&&r!==null&&r!==void 0&&r!=="agent-controlled"))return null;const o=r==="return-requested"||r==="resyncing";return e.jsxs("div",{className:"desktop-live-control-banner",role:"status",style:{position:"fixed",top:"calc(env(safe-area-inset-top) + 10px)",left:"50%",transform:"translateX(-50%)",zIndex:1300,display:"flex",alignItems:"center",gap:8,padding:"7px 14px",borderRadius:999,border:"1px solid rgba(251,191,36,0.45)",background:"rgba(69,49,10,0.92)",color:"#fcd34d",fontSize:13,fontWeight:600,backdropFilter:"blur(8px)",pointerEvents:"none"},children:[e.jsx("span",{"aria-hidden":"true",children:"●"}),o?"正在结束远程控制":"正在被远程控制"]})}function No({status:t,isRunning:n,needsInput:r}){return t==="failed"||t==="error"?"error":n?r?"needs-input":"running":"completed"}const zo={"needs-input":"需要输入",running:"运行中",completed:"执行完成",error:"执行错误"};function ai(t,n){return t.map((r,s)=>({session:r,index:s})).sort((r,s)=>n(r.session,s.session)||r.index-s.index).map(({session:r})=>r)}function Hs(t){return ai(t,(n,r)=>r.created.localeCompare(n.created))}function _a(t,n){return ai(Hs(t),(r,s)=>Number(n(s))-Number(n(r)))}function hf(t,n){return ai(t,(r,s)=>Number(n(s))-Number(n(r)))}const Pa={projectId:null,sessionId:null};function Qo(t){return typeof t=="string"&&t.trim()?t.trim():null}function Wa(t){return{projectId:Qo(t),sessionId:null}}function Lo(t,n){return{projectId:Qo(t),sessionId:Qo(n)}}function gf(t){return t.agentType==="customer-agent"?`确定永久删除会话“${t.title}”吗?此操作不可恢复。`:t.agentType==="codex"?`确定归档 Codex 会话“${t.title}”并从 AgentRoam 中移除吗?可在 Codex 的已归档会话中恢复。`:`确定从 AgentRoam 中移除会话“${t.title}”吗?原生客户端中的历史记录会保留。`}function xf(t,n){const r=new Set(n);return{...t,selectedSessionId:t.selectedSessionId&&r.has(t.selectedSessionId)?null:t.selectedSessionId,sessions:Object.fromEntries(Object.entries(t.sessions).map(([s,o])=>[s,{...o,data:o.data.filter(a=>!r.has(a.id))}]))}}function mf(t,n){const r=new Set(n);let s=!1;const o=Object.fromEntries(Object.entries(t).map(([a,c])=>{const d=c.filter(u=>!r.has(u.id));return d.length!==c.length&&(s=!0),[a,d.length===c.length?c:d]}));return s?o:t}function bf(t,n,r,s){const o=[s,...(n[s]??[]).map(d=>d.id)],a=new Set(o),c=Object.fromEntries(Object.entries(n).flatMap(([d,u])=>{if(a.has(d))return[];const h=u.filter(g=>!a.has(g.id));return[[d,h.length===u.length?u:h]]}));return{sessionsByProject:mf(t,o),childSessionsByParent:c,otherLocalSessions:r.filter(d=>!a.has(d.id)),removedIds:o}}const yf=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"}],Da={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat"};function Ba(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:""}}function vf(){const{maxIterations:t,contextWindow:n,isConfigured:r,profiles:s,activeProfileId:o,setField:a,loadFromSystem:c,saveToSystem:d,addProfile:u,updateProfile:h,deleteProfile:g,switchActiveProfile:y}=Vs(),[m,b]=l.useState(null),[C,M]=l.useState("success"),[A,I]=l.useState(String(Math.round((n??100)*1e3)));l.useEffect(()=>{I(String(Math.round((n??100)*1e3)))},[n]);const[j,S]=l.useState(null),[P,K]=l.useState(!1),[R,T]=l.useState(Ba());l.useEffect(()=>{c()},[]);const _=()=>{K(!0),S(null),T(Ba())},k=Z=>{K(!1),S(Z.id),T({name:Z.name,provider:Z.provider,modelId:Z.modelId,apiKey:["managed","__agentroam_stored_secret__"].includes(Z.apiKey)?"":Z.apiKey,baseUrl:Z.baseUrl})},W=()=>{S(null),K(!1)},Q=async()=>{if(!R.name.trim()||!R.apiKey.trim()||!R.modelId.trim()){b("名称、API Key 和模型 ID 为必填项"),M("error");return}P?u(R):j&&h(j,R),S(null),K(!1),b(null),setTimeout(()=>d(),0)},ae=async Z=>{g(Z),setTimeout(()=>d(),0)},ve=async Z=>{await y(Z),b("已切换模型"),M("success"),setTimeout(()=>b(null),1500)},Te=async()=>{b(null);const Z=Number(A);if(!Number.isInteger(Z)||Z<1024||Z>2e6){b("上下文窗口请输入 1024 到 2000000 之间的整数 tokens,例如 8192。"),M("error");return}a("contextWindow",Z/1e3);try{await d(),b("设置保存成功"),M("success")}catch(me){b(me instanceof Error?me.message:"保存失败"),M("error")}},we=P||j!==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:_,style:jf,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.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:"暂无配置,点击「+ 添加」创建第一个模型提供商"}),s.map(Z=>{const me=Z.id===o,Be=Z.id===j;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${me?"var(--accent)":"var(--border-default)"}`,background:me?"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:me?"var(--accent)":"var(--bg-deep)",color:me?"#fff":"var(--text-muted)",flexShrink:0},children:Z.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:Z.name||Z.modelId}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1},children:[Z.modelId," ",Z.baseUrl?`· ${Z.baseUrl}`:""]})]}),me&&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:[!me&&e.jsx("button",{onClick:()=>ve(Z.id),style:_o,children:"切换"}),e.jsx("button",{onClick:()=>Be?W():k(Z),style:_o,children:Be?"收起":"编辑"}),e.jsx("button",{onClick:()=>ae(Z.id),style:{..._o,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),Be&&e.jsx($a,{draft:R,setDraft:T,onSave:Q,onCancel:W})]},Z.id)}),P&&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:R,setDraft:T,onSave:Q,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(mr,{label:"最大迭代次数",children:e.jsx("input",{type:"number",value:t,onChange:Z=>a("maxIterations",parseInt(Z.target.value)||10),min:1,max:50,style:br})}),e.jsxs(mr,{label:"上下文窗口(tokens,输入与输出合计)",children:[e.jsx("input",{type:"number",value:A,onChange:Z=>I(Z.target.value),min:1024,max:2e6,step:1,style:br}),e.jsx("div",{style:{fontSize:12,opacity:.65},children:"8K 模型填 8192;不能超过模型服务实际启动的上下文大小。"})]})]})]}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:Te,style:$l,children:"保存"}),e.jsx("span",{style:{padding:"7px 14px",borderRadius:"var(--radius-sm)",fontSize:12,fontWeight:500,background:r?"rgba(52,211,153,0.1)":"rgba(255,255,255,0.04)",color:r?"var(--success)":"var(--text-muted)",border:`1px solid ${r?"rgba(52,211,153,0.2)":"var(--border-subtle)"}`},children:r?"● 已连接":"○ 未配置"})]}),m&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:C==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:C==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:C==="success"?"var(--success)":"var(--danger)",fontSize:13},children:m})]})}function $a({draft:t,setDraft:n,onSave:r,onCancel:s}){const o=(a,c)=>n(d=>{const u={...d,[a]:c};return a==="provider"&&!d.modelId&&(u.modelId=Da[c]??""),u});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(mr,{label:"名称",children:e.jsx("input",{value:t.name,onChange:a=>o("name",a.target.value),placeholder:"我的 Claude",style:br})}),e.jsx(mr,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:a=>{o("provider",a.target.value),o("modelId",Da[a.target.value]??"")},style:br,children:yf.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})})]}),e.jsx(mr,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:a=>o("modelId",a.target.value),placeholder:"claude-sonnet-4-6",style:br})}),e.jsx(mr,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:a=>o("apiKey",a.target.value),placeholder:"sk-...",style:br})}),e.jsx(mr,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:a=>o("baseUrl",a.target.value),placeholder:"https://api.anthropic.com",style:br})}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:r,style:$l,children:"保存"}),e.jsx("button",{onClick:s,style:wf,children:"取消"})]})]})}function mr({label:t,children:n}){return e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:"var(--text-secondary)",marginBottom:6,fontWeight:500,textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),n]})}const br={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"},$l={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)"},wf={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)"},jf={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)"},_o={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)"},kf={fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},Po={display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-surface)",fontSize:13};function Sf({onboarding:t=!1}){const n=typeof window>"u"?void 0:window.agentApi,r=!!(n!=null&&n.desktopLiveGetStatus),[s,o]=l.useState(null),[a,c]=l.useState(!1),[d,u]=l.useState(null),[h,g]=l.useState(!0),[y,m]=l.useState(null);l.useEffect(()=>{var K;if(!(n!=null&&n.desktopLiveGetStatus)||!(n!=null&&n.onDesktopLiveStatus))return;let S=!0;n.desktopLiveSetup().then(R=>{S&&(o(R.status),g(R.supported))}).catch(()=>{}),(K=n.desktopLiveGetDisplays)==null||K.call(n).then(R=>{S&&R.displays.length>1&&m(R.displays)}).catch(()=>{});const P=n.onDesktopLiveStatus(R=>o(R));return()=>{S=!1,P()}},[n]);const b=async()=>{if(n!=null&&n.desktopLiveRecheck)try{o(await n.desktopLiveRecheck()),u(null)}catch(S){u(S instanceof Error?S.message:String(S))}};l.useEffect(()=>{if(!r||!h)return;let S=!0,P=!1;const K=async()=>{if(!P){P=!0;try{const T=await n.desktopLiveRecheck();S&&o(T)}catch{}finally{P=!1}}};window.addEventListener("focus",K);const R=s!=null&&s.enabled&&(s.permissionScreen!=="granted"||s.accessibilityTrusted!==!0)?window.setInterval(K,3e3):void 0;return()=>{S=!1,window.removeEventListener("focus",K),R&&window.clearInterval(R)}},[n,r,h,s==null?void 0:s.enabled,s==null?void 0:s.permissionScreen,s==null?void 0:s.accessibilityTrusted]);const C=async S=>{if(n){c(!0);try{o(await n.desktopLiveSetEnabled(!0)),await n.desktopLiveOpenPermission(S),u(null)}catch(P){u(P instanceof Error?P.message:String(P))}finally{c(!1)}}},M=async S=>{var P;if(n!=null&&n.desktopLiveSetDisplay)try{await n.desktopLiveSetDisplay(S);const K=await((P=n.desktopLiveGetDisplays)==null?void 0:P.call(n));K&&m(K.displays)}catch{}};if(!r)return null;const A=async()=>{if(n!=null&&n.desktopLiveSetEnabled){c(!0);try{o(await n.desktopLiveSetEnabled(!(s!=null&&s.enabled))),u(null)}catch(S){u(S instanceof Error?S.message:String(S))}finally{c(!1)}}},I=(s==null?void 0:s.permissionScreen)==="granted",j=(s==null?void 0:s.accessibilityTrusted)===!0;return e.jsxs("section",{className:"desktop-permission-settings",children:[e.jsx("h3",{style:kf,children:t?"设置桌面端权限":"桌面直播与远程控制"}),e.jsx("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"0 0 14px",lineHeight:1.6},children:t?"欢迎使用 AgentRoam。请为桌面端开启以下系统权限,完成后手机即可查看电脑画面;允许辅助功能后还可操作鼠标和键盘。":"开启后,已配对手机可查看电脑画面,并在授予辅助功能权限后操作鼠标和键盘。"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsx("button",{type:"button",onClick:()=>void A(),disabled:a||!h,style:{padding:"7px 16px",borderRadius:"var(--radius-sm)",border:`1px solid ${s!=null&&s.enabled?"rgba(244,63,94,0.35)":"var(--accent)"}`,background:s!=null&&s.enabled?"rgba(244,63,94,0.1)":"var(--accent-dim)",color:s!=null&&s.enabled?"var(--danger)":"var(--accent)",fontSize:13,fontWeight:600,cursor:"pointer"},children:a?"处理中…":s!=null&&s.enabled?t?"暂停手机查看":"关闭桌面直播":t?"开启手机查看":"开启桌面直播"}),(s==null?void 0:s.enabled)&&e.jsx("span",{style:{fontSize:12,color:s.sessionOnline?"var(--success)":"var(--text-muted)"},children:s.sessionOnline?"● 已连接,可从手机查看":"○ 未连接"})]}),!h&&e.jsx("p",{role:"status",children:"当前远程桌面仅支持 macOS,其他桌面功能可正常使用。"}),h&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{className:"desktop-permission-row",style:Po,children:[e.jsx("span",{children:"屏幕录制(画面采集)"}),e.jsx("span",{style:{color:I?"var(--success)":"var(--danger)",fontWeight:600},children:I?"已授权":"未授权"}),!I&&e.jsx("button",{type:"button",className:"ui-quiet-button desktop-permission-button",disabled:a,onClick:()=>void C("screen"),children:"去授权"})]}),e.jsxs("div",{className:"desktop-permission-row",style:Po,children:[e.jsx("span",{children:"辅助功能(键鼠控制)"}),e.jsx("span",{style:{color:j?"var(--success)":"var(--danger)",fontWeight:600},children:(s==null?void 0:s.accessibilityTrusted)===null?"待检测":j?"已授权":"未授权"}),!j&&e.jsx("button",{type:"button",className:"ui-quiet-button desktop-permission-button",disabled:a,onClick:()=>void C("accessibility"),children:"去授权"})]}),y&&y.length>1&&e.jsxs("div",{style:Po,children:[e.jsx("span",{children:"直播画面来源"}),e.jsx("span",{style:{display:"flex",gap:6},children:y.map(S=>e.jsx("button",{type:"button",onClick:()=>void M(S.selected?null:S.id),style:{padding:"4px 10px",borderRadius:"var(--radius-sm)",border:`1px solid ${S.selected?"var(--accent)":"var(--border-subtle)"}`,background:S.selected?"var(--accent-dim)":"transparent",color:S.selected?"var(--accent)":"var(--text-secondary)",fontSize:12,fontWeight:600,cursor:"pointer"},children:S.label},S.id))})]})]}),h&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{marginTop:14,fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"点击对应权限的「去授权」,在系统设置中允许 AgentRoam,返回后自动检测。"}),e.jsxs("details",{className:"desktop-permission-more",children:[e.jsx("summary",{children:"更多操作"}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[e.jsx("button",{type:"button",className:"ui-quiet-button",onClick:()=>void b(),children:"重新检测"}),!I&&e.jsx("button",{type:"button",className:"ui-quiet-button",onClick:()=>void(n==null?void 0:n.desktopLiveRestart()),children:"重启桌面端"})]})]})]}),d&&e.jsx("p",{role:"alert",style:{color:"var(--danger)"},children:d}),(s==null?void 0:s.error)&&e.jsx("div",{style:{marginTop:10,fontSize:12,color:"var(--danger)"},role:"alert",children:s.error})]})}function If({onClose:t}){const n=l.useRef(null);return l.useEffect(()=>{var r;(r=n.current)==null||r.showModal()},[]),Yt.createPortal(e.jsx("dialog",{ref:n,"aria-label":"桌面直播与远程控制",onCancel:t,onClick:r=>{r.target===r.currentTarget&&t()},style:{width:"min(680px, calc(100vw - 48px))",maxHeight:"calc(100vh - 48px)",padding:0,margin:"auto",inset:0,overflowY:"auto",color:"var(--text-primary)",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)"},children:e.jsxs("div",{style:{padding:24},children:[e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:8},children:e.jsx("button",{type:"button",onClick:t,"aria-label":"关闭桌面直播设置",className:"ui-icon-button ui-icon-button--close",children:"×"})}),e.jsx(Sf,{}),e.jsx("div",{className:"desktop-permission-footer",children:e.jsx("button",{type:"button",className:"ui-quiet-button",onClick:t,children:"关闭"})})]})}),document.body)}const Wo={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function Cf(){const[t,n]=l.useState([]),[r,s]=l.useState("stdio"),[o,a]=l.useState(Wo),[c,d]=l.useState(!1),[u,h]=l.useState({id:!1,command:!1,url:!1}),[g,y]=l.useState({}),[m,b]=l.useState({}),[C,M]=l.useState(new Set),[A,I]=l.useState(null),[j,S]=l.useState(""),[P,K]=l.useState(!1),R=async z=>{var Ne;if(!((Ne=window.agentApi)!=null&&Ne.mcpProbe))return;M(je=>new Set([...je,z.id])),b(je=>{const Ce={...je};return delete Ce[z.id],Ce});const te=new Promise((je,Ce)=>setTimeout(()=>Ce(new Error("连接超时(15s)")),15e3));try{const je=await Promise.race([window.agentApi.mcpProbe(z),te]);y(Ce=>({...Ce,[z.id]:je}))}catch(je){const Ce=je instanceof Error?je.message:String(je);console.warn(`[MCP] probe failed for ${z.id}:`,Ce),y(Oe=>{const xe={...Oe};return delete xe[z.id],xe}),b(Oe=>({...Oe,[z.id]:Ce})),(z.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(Ce))&&(S(""),I({server:z}))}finally{M(je=>{const Ce=new Set(je);return Ce.delete(z.id),Ce})}};l.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(z=>{n(z),z.filter(te=>te.enabled!==!1).forEach(te=>R(te))}).catch(console.error)},[]);const[T,_]=l.useState(""),[k,W]=l.useState(""),[Q,ae]=l.useState(!1),ve=async()=>{W("");let z;try{z=JSON.parse(T.trim());const te=z.mcpServers??z,Ne=Object.entries(te);if(Ne.length===0){W("未找到任何服务器");return}ae(!0);const je=[];for(const[Oe,xe]of Ne){const Ee=xe,lt=Ee.name||Oe,Fe=Ee.disabled!==!0;let Se;if(Ee.url||Ee.type==="streamableHttp"||Ee.type==="sse"){const Ct=Ee.type==="sse"?"sse":"streamableHttp";Se={id:Oe,name:lt,transport:Ct,url:Ee.url,headers:Ee.headers??{},env:Ee.env??{},enabled:Fe}}else Se={id:Oe,name:lt,transport:"stdio",command:Ee.command,args:Ee.args??[],env:Ee.env??{},enabled:Fe};await window.agentApi.mcpSave(Se),je.push(Se)}const Ce=await window.agentApi.mcpList();n(Ce),_(""),je.filter(Oe=>Oe.enabled!==!1).forEach(Oe=>R(Oe))}catch(te){W(te instanceof Error?te.message:"JSON 解析失败")}finally{ae(!1)}},Te=()=>o.id.trim()!==""&&o.command.trim()!=="",we=()=>o.id.trim()!==""&&o.url.trim()!=="",Z=z=>{const te={};for(const Ne of z.split(`
370
- `)){const je=Ne.indexOf(":");if(je<1)continue;const Ce=Ne.slice(0,je).trim(),Oe=Ne.slice(je+1).trim();Ce&&(te[Ce]=Oe)}return te},me=async()=>{if(h({id:!0,command:!0,url:!0}),!(r==="stdio"&&!Te())&&!((r==="sse"||r==="streamableHttp")&&!we())){d(!0);try{const z=r==="sse"||r==="streamableHttp"?Z(o.headersRaw):{},te=r==="stdio"?{id:o.id,name:o.name||o.id,transport:"stdio",command:o.command,args:o.args.split(" ").filter(Boolean),enabled:!0}:{id:o.id,name:o.name||o.id,transport:r,url:o.url,headers:z,enabled:!0};await window.agentApi.mcpSave(te);const Ne=await window.agentApi.mcpList();n(Ne),a(Wo),h({id:!1,command:!1,url:!1}),R(te)}catch(z){console.error("Failed to save MCP server",z)}finally{d(!1)}}},Be=async z=>{await window.agentApi.mcpDelete(z),n(t.filter(te=>te.id!==z))},It=async(z,te)=>{await window.agentApi.mcpSetEnabled(z,te),n(t.map(Ne=>Ne.id===z?{...Ne,enabled:te}:Ne))},tt=async()=>{if(!(!A||!j.trim())){K(!0);try{const z=A.server.transport==="streamableHttp"?{...A.server,headers:{...A.server.headers??{},Authorization:`Bearer ${j.trim()}`}}:{...A.server,env:{...A.server.env??{},Authorization:`Bearer ${j.trim()}`}};await window.agentApi.mcpSave(z);const te=await window.agentApi.mcpList();n(te),I(null),S("");const Ne=te.find(je=>je.id===z.id)??z;R(Ne)}finally{K(!1)}}},De=z=>z==="stdio"?"本地":z==="streamableHttp"?"HTTP":"SSE",xt=z=>z==="stdio"?"#68d391":z==="streamableHttp"?"#f6ad55":"#63b3ed",nt=z=>z==="stdio"?"rgba(154,230,180,0.15)":z==="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(z=>e.jsx("button",{onClick:()=>{s(z),h({id:!1,command:!1,url:!1}),a(te=>({...Wo,id:te.id,name:te.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:r===z?"var(--accent)":"transparent",color:r===z?"var(--text-inverse)":"var(--text-muted)"},children:z==="stdio"?"本地 stdio":z==="sse"?"远程 SSE":"HTTP"},z))})]}),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:o.id,onChange:z=>a(te=>({...te,id:z.target.value})),onBlur:()=>h(z=>({...z,id:!0})),placeholder:"服务器 ID *",style:{...Xn,...u.id&&!o.id?Do:{}}}),u.id&&!o.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.name,onChange:z=>a(te=>({...te,name:z.target.value})),placeholder:"显示名称",style:{...Xn,flex:1}})]}),r==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:o.command,onChange:z=>a(te=>({...te,command:z.target.value})),onBlur:()=>h(z=>({...z,command:!0})),placeholder:"命令(如 npx)*",style:{...Xn,...u.command&&!o.command?Do:{}}}),u.command&&!o.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:o.args,onChange:z=>a(te=>({...te,args:z.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...Xn,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:o.url,onChange:z=>a(te=>({...te,url:z.target.value})),onBlur:()=>h(z=>({...z,url:!0})),placeholder:r==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...Xn,...u.url&&!o.url?Do:{}}}),u.url&&!o.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:o.headersRaw,onChange:z=>a(te=>({...te,headersRaw:z.target.value})),placeholder:`access_token: abc123
371
- Authorization: Bearer sk-...`,rows:3,style:{...Xn,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:me,disabled:c,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:c?"not-allowed":"pointer",fontFamily:"var(--font-body)"},children:c?"保存中…":"添加服务器"})]})]}),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:T,onChange:z=>{_(z.target.value),W("")},placeholder:`{
372
- "my-server": {
373
- "command": "npx",
374
- "args": ["-y", "some-mcp"]
375
- }
376
- }`,rows:5,style:{...Xn,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),k&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:k}),e.jsx("button",{onClick:ve,disabled:!T.trim()||Q,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:T.trim()&&!Q?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:T.trim()&&!Q?1:.5},children:Q?"导入中…":"导入"})]}),t.filter(z=>z.transport===r).length===0?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"40px 0",textAlign:"center"},children:["暂无",r==="stdio"?"本地 stdio":r==="sse"?"远程 SSE":"HTTP"," 服务器,点击上方添加。"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.filter(z=>z.transport===r).map(z=>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:z.name||z.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:nt(z.transport),color:xt(z.transport),fontWeight:600},children:De(z.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[z.transport==="stdio"?`${z.command} ${(z.args??[]).join(" ")}`:z.url,z.transport!=="stdio"&&z.headers&&Object.keys(z.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(z.headers).length," 个请求头"]})]}),C.has(z.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"}}),"探测工具中…"]}):m[z.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:m[z.id]}),z.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(m[z.id])?e.jsx("button",{onClick:()=>{S(""),I({server:z})},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:()=>R(z),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:"重试"})]}):g[z.id]&&g[z.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:g[z.id].map(te=>e.jsx("span",{title:te.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:te.name},te.name))}):g[z.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:z.enabled!==!1,onChange:te=>It(z.id,te.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Be(z.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:te=>{te.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:te=>{te.currentTarget.style.background="transparent"},children:"移除"})]})]},z.id))}),A&&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:z=>{z.target===z.currentTarget&&I(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:A.server.name||A.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:j,onChange:z=>S(z.target.value),onKeyDown:z=>{z.key==="Enter"&&tt(),z.key==="Escape"&&I(null)},placeholder:"sk-… 或 Bearer token",style:{...Xn,width:"100%",boxSizing:"border-box",marginBottom:16}}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:()=>I(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:tt,disabled:!j.trim()||P,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:j.trim()&&!P?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:j.trim()&&!P?1:.5},children:P?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const Xn={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)"},Do={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function Rf(){const[t,n]=l.useState([]),[r,s]=l.useState(""),[o,a]=l.useState(null),[c,d]=l.useState(!1),[u,h]=l.useState(""),[g,y]=l.useState(""),[m,b]=l.useState("user"),[C,M]=l.useState(""),[A,I]=l.useState(null),[j,S]=l.useState("success"),P=async()=>{if(window.agentApi){const _=await window.agentApi.listMemories();n(_)}};l.useEffect(()=>{P()},[]);const K=async()=>{if(!r.trim()){P();return}if(window.agentApi){const _=await window.agentApi.searchMemories(r);n(_.map(k=>k.entry))}},R=async()=>{if(!(!u.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:u.trim(),description:g,type:m,content:C,created:(o==null?void 0:o.created)??new Date().toISOString(),updated:new Date().toISOString()}),d(!1),a(null),h(""),y(""),M(""),b("user"),I("保存成功"),S("success"),await P()}catch(_){I(_ instanceof Error?_.message:"保存失败"),S("error")}},T=_=>{a(_),h(_.name),y(_.description),b(_.type),M(_.content),d(!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:()=>{d(!0),a(null),h(""),y(""),M(""),b("user")},style:{padding:"10px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"var(--font-body)"},children:"+ 新建"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:24},children:[e.jsx("input",{value:r,onChange:_=>s(_.target.value),onKeyDown:_=>_.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:Oa,children:"搜索"})]}),A&&e.jsx("div",{style:{padding:"10px 12px",borderRadius:"var(--radius-sm)",border:j==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:j==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:j==="success"?"var(--success)":"var(--danger)",fontSize:13,marginBottom:16},children:A}),c&&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:u,onChange:_=>h(_.target.value),placeholder:"名称",style:{...Ws,marginBottom:10},disabled:!!o}),e.jsx("input",{value:g,onChange:_=>y(_.target.value),placeholder:"描述",style:{...Ws,marginBottom:10}}),e.jsxs("select",{value:m,onChange:_=>b(_.target.value),style:{...Ws,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:C,onChange:_=>M(_.target.value),placeholder:"内容",rows:5,style:{...Ws,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:R,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:()=>d(!1),style:Oa,children:"取消"})]})]}),t.map(_=>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:_.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:_.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>T(_),style:Fa,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(_.name),I("删除成功"),S("success"),await P()}catch(k){I(k instanceof Error?k.message:"删除失败"),S("error")}},style:{...Fa,color:"var(--danger)"},children:"删除"})]})]}),_.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:_.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[_.content.slice(0,180),_.content.length>180?"…":""]})]},_.name)),t.length===0&&!c&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Ws={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"},Oa={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)"},Fa={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},Af=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function Mf(){const[t,n]=l.useState([]),[r,s]=l.useState(null),[o,a]=l.useState(!1),[c,d]=l.useState(null),[u,h]=l.useState("success"),[g,y]=l.useState(""),m=(T,_="success")=>{d(T),h(_),setTimeout(()=>d(null),3e3)},b=async()=>{if(!window.agentApi)return;const T=await window.agentApi.listSkills();n(T)};l.useEffect(()=>{b()},[]);const C=T=>{s({...T}),y((T.triggers??[]).join(", ")),a(!1)},M=()=>{s(Af()),y(""),a(!0)},A=()=>{s(null),a(!1)},I=async()=>{if(!r||!window.agentApi)return;if(!r.name.trim()){m("名称不能为空","error");return}const T=g.split(",").map(_=>_.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:r.name.trim(),description:r.description,triggers:T,prompt:r.prompt,filePath:r.filePath??""}),m(o?"技能已创建":"技能已保存"),s(null),await b()}catch(_){m(_ instanceof Error?_.message:"保存失败","error")}},j=async T=>{if(window.agentApi)try{await window.agentApi.deleteSkill(T),m("已删除"),(r==null?void 0:r.name)===T&&s(null),await b()}catch(_){m(_ instanceof Error?_.message:"删除失败","error")}},S=async T=>{if(!window.agentApi)return;const _=!T.enabled;await window.agentApi.setSkillEnabled(T.name,_),await b()},P=async()=>{if(window.agentApi)try{const T=await window.agentApi.importSkill();if(!T)return;m(`已导入技能「${T.name}」,本次会话立即生效`),await b()}catch(T){m(T instanceof Error?T.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"},R={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:P,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:M,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:"+ 新建技能"})]})]}),c&&e.jsx("div",{style:{marginBottom:16,padding:"8px 12px",borderRadius:"var(--radius-sm)",border:u==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:u==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:u==="success"?"var(--success)":"var(--danger)",fontSize:13},children:c}),r&&e.jsxs("div",{style:{marginBottom:24,padding:"20px 24px",borderRadius:"var(--radius-md)",border:"1px solid var(--border-glow)",background:"var(--bg-glass)"},children:[e.jsx("h3",{style:{margin:"0 0 16px",fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:o?"新建技能":`编辑:${r.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:R,children:"名称"}),e.jsx("input",{style:K,value:r.name,disabled:!o,onChange:T=>s({...r,name:T.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"描述"}),e.jsx("input",{style:K,value:r.description,onChange:T=>s({...r,description:T.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"触发词(逗号分隔)"}),e.jsx("input",{style:K,value:g,onChange:T=>y(T.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:R,children:"提示词"}),e.jsx("textarea",{style:{...K,minHeight:120,resize:"vertical"},value:r.prompt,onChange:T=>s({...r,prompt:T.target.value}),placeholder:"当触发词匹配时,注入到系统提示的内容..."})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:I,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:A,style:{padding:"8px 16px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:13,cursor:"pointer"},children:"取消"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&!r&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"暂无技能,点击「新建技能」创建第一个"}),t.map(T=>{var _;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:T.enabled===!1?.5:1},children:[e.jsx("button",{onClick:()=>S(T),title:T.enabled===!1?"已禁用,点击启用":"点击禁用",style:{flexShrink:0,marginTop:2,width:32,height:18,borderRadius:9,border:"none",background:T.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:T.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:T.name}),((_=T.triggers)==null?void 0:_.length)>0&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["触发词:",T.triggers.slice(0,3).join(" · "),T.triggers.length>3?" ...":""]})]}),T.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:T.description}),T.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:[T.prompt.slice(0,80),T.prompt.length>80?"...":""]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>C(T),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:()=>j(T.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:"删除"})]})]},T.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 Ol(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function Ef(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:Ol(),maxIterations:0,isDefault:!1}}const Yo={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"},ms={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},er={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"},Zn={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function Tf({ph:t,onChange:n,onDelete:r}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6,alignItems:"center"},children:[e.jsx("input",{style:er,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>n({...t,key:s.target.value})}),e.jsx("input",{style:er,placeholder:"说明",value:t.description,onChange:s=>n({...t,description:s.target.value})}),e.jsx("input",{style:er,placeholder:"默认值",value:t.defaultValue,onChange:s=>n({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:r,style:{...ms,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function Ha({initial:t,activeAgentId:n,onSave:r,onCancel:s}){const{profiles:o}=Vs(),[a,c]=l.useState([]),[d,u]=l.useState([]),[h,g]=l.useState({...Ef(),...t,capabilities:{...Ol(),...t.capabilities??{}}}),[y,m]=l.useState(null),[b,C]=l.useState(!1);l.useEffect(()=>{var k,W;window.agentApi&&(window.agentApi.listSkills().then(Q=>{c(Q.filter(ae=>ae.name))}),(W=(k=window.agentApi).listMCPServers)==null||W.call(k).then(Q=>{u(Q??[])}).catch(()=>{}))},[]);const M=k=>g(W=>({...W,capabilities:{...W.capabilities,...k}})),A=k=>{const W=h.capabilities.enabledTools;if(W.length===0){const Q=Ds.map(ae=>ae.name).filter(ae=>ae!==k);M({enabledTools:Q})}else if(W.includes(k)){const Q=W.filter(ae=>ae!==k);M({enabledTools:Q})}else{const Q=[...W,k];Q.length===Ds.length?M({enabledTools:[]}):M({enabledTools:Q})}},I=k=>{const W=h.capabilities.enabledSkills;M({enabledSkills:W.includes(k)?W.filter(Q=>Q!==k):[...W,k]})},j=k=>{const W=h.capabilities.enabledMCPServers;M({enabledMCPServers:W.includes(k)?W.filter(Q=>Q!==k):[...W,k]})},S=()=>g(k=>({...k,contextPlaceholders:[...k.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),P=(k,W)=>g(Q=>{const ae=[...Q.contextPlaceholders];return ae[k]=W,{...Q,contextPlaceholders:ae}}),K=k=>g(W=>({...W,contextPlaceholders:W.contextPlaceholders.filter((Q,ae)=>ae!==k)})),R=async()=>{if(!h.name.trim()){m("名称为必填项");return}C(!0);try{await r(h)}catch(k){m(k instanceof Error?k.message:"保存失败")}finally{C(!1)}},T=k=>h.capabilities.enabledTools.length===0||h.capabilities.enabledTools.includes(k),_={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:[y&&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:y}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:Zn,children:"名称 *"}),e.jsx("input",{style:er,value:h.name,onChange:k=>g(W=>({...W,name:k.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:Zn,children:"描述"}),e.jsx("input",{style:er,value:h.description,onChange:k=>g(W=>({...W,description:k.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:{...Zn,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:h.systemPrompt,onChange:k=>g(W=>({...W,systemPrompt:k.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
377
-
378
- 当前项目:{{project_name}}`,rows:6,style:{...er,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:_,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(k=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:k},k))}),h.contextPlaceholders.map((k,W)=>e.jsx(Tf,{ph:k,onChange:Q=>P(W,Q),onDelete:()=>K(W)},W))]}),e.jsx("button",{onClick:S,style:{...ms,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:_,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:Zn,children:"模型"}),e.jsxs("select",{value:h.capabilities.profileId,onChange:k=>M({profileId:k.target.value}),style:{...er,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),o.map(k=>e.jsxs("option",{value:k.id,children:[k.name||k.modelId," (",k.provider,")"]},k.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Zn,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(k=>{const W=T(k.name);return e.jsx("button",{onClick:()=>A(k.name),style:{padding:"4px 10px",borderRadius:20,border:W?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:W?"var(--accent-dim)":"transparent",color:W?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:k.label},k.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),a.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Zn,children:["技能 ",h.capabilities.enabledSkills.length===0?"(全部)":`(${h.capabilities.enabledSkills.length}/${a.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(k=>{const W=h.capabilities.enabledSkills.length===0||h.capabilities.enabledSkills.includes(k.name);return e.jsx("button",{onClick:()=>I(k.name),title:k.description,style:{padding:"4px 10px",borderRadius:20,border:W?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:W?"var(--accent-dim)":"transparent",color:W?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:k.name},k.name)})})]}),d.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Zn,children:["MCP 服务器 ",h.capabilities.enabledMCPServers.length===0?"(全部)":`(${h.capabilities.enabledMCPServers.length}/${d.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:d.map(k=>{const W=h.capabilities.enabledMCPServers.length===0||h.capabilities.enabledMCPServers.includes(k.id);return e.jsx("button",{onClick:()=>j(k.id),style:{padding:"4px 10px",borderRadius:20,border:W?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:W?"var(--accent-dim)":"transparent",color:W?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:k.name},k.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:Zn,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:er,value:h.maxIterations,min:0,max:100,onChange:k=>g(W=>({...W,maxIterations:Number(k.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:k=>g(W=>({...W,isDefault:k.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:R,disabled:b,style:{...Yo,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:b?.6:1},children:b?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:Yo,children:"取消"})]})]})}function Nf(){const[t,n]=l.useState([]),[r,s]=l.useState([]),[o,a]=l.useState(null),[c,d]=l.useState(!1),[u,h]=l.useState(null),[g,y]=l.useState("success"),m=(j,S="success")=>{h(j),y(S),setTimeout(()=>h(null),2e3)},b=async()=>{if(!window.agentApi)return;const j=await window.agentApi.listAgentDefs();n(j);const S=await window.agentApi.getSettings();s(S.activeAgentIds??[])};l.useEffect(()=>{b()},[]);const C=async j=>{await window.agentApi.createAgentDef(j),d(!1),m("智能体已创建"),await b()},M=async(j,S)=>{await window.agentApi.updateAgentDef(j,S),a(null),m("保存成功"),await b()},A=async j=>{await window.agentApi.deleteAgentDef(j),o===j&&a(null),m("已删除"),await b()},I=async j=>{const P=(await window.agentApi.setActiveAgentDef(j)).activeAgentIds??[];s(P),m(P.includes(j)?"已激活":"已取消激活")};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:"配置具有自定义角色、工具和模型的智能体,在消息框中按需切换。"}),u&&e.jsx("div",{style:{marginBottom:16,padding:"8px 14px",borderRadius:8,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:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{d(!0),a(null)},style:{...Yo,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600},children:"+ 新建智能体"})}),c&&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(Ha,{initial:{},activeAgentId:r[0]??"",onSave:C,onCancel:()=>d(!1)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.length===0&&!c&&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(j=>{const S=r.includes(j.id),P=j.id===o;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${S?"var(--accent)":"var(--border-default)"}`,background:S?"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:S?"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:S?"#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:j.name}),S&&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:"激活"}),j.isDefault&&e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",background:"var(--bg-deep)",padding:"1px 6px",borderRadius:4},children:"默认"})]}),j.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.description}),e.jsxs("div",{style:{display:"flex",gap:5,marginTop:5,flexWrap:"wrap"},children:[j.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:"自定义模型"}),j.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:[j.capabilities.enabledTools.length," 工具"]}),j.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:[j.capabilities.enabledSkills.length," 技能"]}),j.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:[j.contextPlaceholders.length," 变量"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsx("button",{onClick:()=>I(j.id),style:{...ms,color:S?"var(--accent)":"var(--text-muted)",borderColor:S?"var(--accent)":"var(--border-default)",background:S?"var(--accent-dim)":"transparent"},children:S?"取消激活":"激活"}),e.jsx("button",{onClick:()=>a(P?null:j.id),style:ms,children:P?"收起":"编辑"}),e.jsx("button",{onClick:()=>A(j.id),style:{...ms,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),P&&e.jsx(Ha,{initial:j,activeAgentId:r[0]??"",onSave:K=>M(j.id,K),onCancel:()=>a(null)})]},j.id)})]})]})}const zf=[{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"}],Bo={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function Lf(){const[t,n]=l.useState([]),[r,s]=l.useState(Bo),[o,a]=l.useState(!1),[c,d]=l.useState(null),[u,h]=l.useState(null),g=async()=>{var j;if((j=window.agentApi)!=null&&j.lspList)try{const S=await window.agentApi.lspList();n(S)}catch(S){console.error("[LSP] load error",S)}};l.useEffect(()=>{g()},[]);const y=j=>{s(S=>({...S,name:j.label,language:j.language,fileTypes:j.fileTypes,command:j.command,args:j.args}))},m=j=>{d(j.id),s({id:j.id,name:j.name,language:j.language,fileTypes:j.fileTypes.join(","),command:j.command,args:j.args.join(" "),envRaw:j.env?Object.entries(j.env).map(([S,P])=>`${S}=${P}`).join(`
379
- `):""}),h(null)},b=()=>{d(null),s(Bo)},C=async()=>{var R;if(!((R=window.agentApi)!=null&&R.lspSave))return;const j=r.name.trim(),S=r.command.trim();if(!j||!S)return;let P;if(r.envRaw.trim()){P={};for(const T of r.envRaw.split(`
380
- `)){const _=T.indexOf("=");_>0&&(P[T.slice(0,_).trim()]=T.slice(_+1).trim())}}const K={id:c??crypto.randomUUID(),name:j,language:r.language.trim(),fileTypes:r.fileTypes.split(",").map(T=>T.trim()).filter(Boolean),command:S,args:r.args.trim()?r.args.trim().split(/\s+/):[],env:P,enabled:!0};a(!0);try{await window.agentApi.lspSave(K),await g(),b()}finally{a(!1)}},M=async j=>{var S;(S=window.agentApi)!=null&&S.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(j),await g())},A=async j=>{var S;(S=window.agentApi)!=null&&S.lspSetEnabled&&(await window.agentApi.lspSetEnabled(j.id,!j.enabled),await g())},I=c!==null;return I&&c===null||!c&&r.name,e.jsxs("div",{style:{padding:"40px 48px",maxWidth:720,animation:"fadeInUp 0.4s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:20,fontWeight:600,color:"var(--text-primary)",margin:0},children:"LSP 服务器"}),e.jsxs("p",{style:{fontSize:13,color:"var(--text-muted)",margin:"4px 0 0"},children:["配置 Language Server Protocol 服务器,让 Agent 可通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_diagnostics"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_hover"}),"、",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:12,color:"var(--text-secondary)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:4},children:"lsp_definition"})," ","等工具进行代码分析。"]})]}),!I&&e.jsx("button",{onClick:()=>{d(""),s(Bo)},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&&!I&&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:I?24:0},children:t.map(j=>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(u===j.id?null:j.id),children:[e.jsx("div",{onClick:S=>{S.stopPropagation(),A(j)},style:{width:32,height:18,borderRadius:9,background:j.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:j.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:j.name}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:[j.language,j.fileTypes.length>0?` · ${j.fileTypes.join(", ")}`:""]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono, monospace)",flexShrink:0},children:[j.command,j.args.length?" "+j.args.join(" "):""]}),e.jsx("button",{onClick:S=>{S.stopPropagation(),m(j)},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:S=>{S.stopPropagation(),M(j.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:u===j.id?"rotate(180deg)":"none"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),u===j.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:[j.command," ",j.args.join(" ")]})]}),j.fileTypes.length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"文件类型:"}),j.fileTypes.join(", ")]}),j.env&&Object.keys(j.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:"环境变量:"}),Object.entries(j.env).map(([S,P])=>`${S}=${P}`).join(", ")]})]})]},j.id))}),I&&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:c?"编辑 LSP 服务器":"添加 LSP 服务器"}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:xr,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:zf.map(j=>e.jsx("button",{onClick:()=>y(j),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:j.label},j.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:xr,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.name,onChange:j=>s(S=>({...S,name:j.target.value})),placeholder:"TypeScript Language Server",style:Or})]}),e.jsxs("div",{children:[e.jsx("label",{style:xr,children:"语言"}),e.jsx("input",{value:r.language,onChange:j=>s(S=>({...S,language:j.target.value})),placeholder:"typescript",style:Or})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:xr,children:["文件类型",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"逗号分隔,如 .ts,.tsx"})]}),e.jsx("input",{value:r.fileTypes,onChange:j=>s(S=>({...S,fileTypes:j.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:Or})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:xr,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.command,onChange:j=>s(S=>({...S,command:j.target.value})),placeholder:"typescript-language-server",style:{...Or,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:xr,children:["参数",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"空格分隔"})]}),e.jsx("input",{value:r.args,onChange:j=>s(S=>({...S,args:j.target.value})),placeholder:"--stdio",style:{...Or,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:xr,children:["环境变量",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,marginLeft:6,color:"var(--text-muted)"},children:"每行 KEY=VALUE"})]}),e.jsx("textarea",{value:r.envRaw,onChange:j=>s(S=>({...S,envRaw:j.target.value})),placeholder:`NODE_ENV=production
381
- TSPROTOCOL_LOG=verbose`,rows:3,style:{...Or,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),r.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void C(),disabled:o||!r.name.trim()||!r.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:o||!r.name.trim()||!r.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:o?"保存中…":"保存"}),e.jsx("button",{onClick:b,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 Or={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"},xr={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function _f({trigger:t,heardText:n}){const[r,s]=l.useState(!1);return l.useEffect(()=>{if(t<=0)return;s(!0);const o=setTimeout(()=>s(!1),2400);return()=>clearTimeout(o)},[t]),r?Yt.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(o=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${o}s var(--ease-out) infinite`}},o)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),n&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",n.slice(0,40),"”"]})]},t),document.body):null}const Pf=[{agentType:"customer-agent",label:"Customer Agent"},{agentType:"codex",label:"Codex"},{agentType:"claude-code",label:"Claude Code"},{agentType:"opencode",label:"OpenCode"}];function Wf({value:t,health:n,onChange:r}){return e.jsx("div",{className:"agent-workspace-switcher",role:"tablist","aria-label":"切换 Agent",children:Pf.map(s=>{const o=n.find(c=>c.agentType===s.agentType),a=(o==null?void 0:o.available)===!1;return e.jsxs("button",{type:"button",role:"tab","aria-selected":t===s.agentType,"aria-label":s.label,title:a?`${s.label} 不可用:${(o==null?void 0:o.error)??"未检测到运行时"}`:s.label,className:t===s.agentType?"is-active":"",onClick:()=>r(s.agentType),children:[e.jsx(Jo,{agentType:s.agentType,size:22}),e.jsx("i",{className:a?"is-unavailable":"","aria-hidden":"true"})]},s.agentType)})})}const $o=264,Ua=126;function Df(t){const n=typeof window>"u"?1024:window.innerWidth,r=typeof window>"u"?768:window.innerHeight,s=Math.max(8,Math.min(t.left+t.width-$o,n-$o-8)),o=t.top+t.height+7,a=o+Ua<=r-8?o:Math.max(8,t.top-Ua-7);return{left:s,top:a,width:$o}}function Bf({message:t,anchor:n,mobile:r,pending:s,onCancel:o,onConfirm:a}){const c=d=>d.stopPropagation();return e.jsx("div",{className:`sidebar-delete-confirmation-layer${r?" is-mobile":""}`,onClick:s?void 0:o,children:e.jsxs("div",{className:"sidebar-delete-confirmation",role:"alertdialog","aria-modal":"true","aria-labelledby":"sidebar-delete-confirmation-title","aria-describedby":"sidebar-delete-confirmation-message",style:r?void 0:Df(n),onClick:c,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:o,disabled:s,children:"取消"}),e.jsx("button",{type:"button",className:"is-danger",onClick:a,disabled:s,children:s?"正在删除...":"删除"})]})]})})}function Oo({session:t,deleteLabel:n="删除会话",onSelect:r,onPin:s,onDelete:o}){var a,c;return e.jsxs("div",{className:`sidebar-row sidebar-session-row${t.child?" sidebar-session-row--child":""}${t.active?" sidebar-row-active":""}`,children:[e.jsxs("button",{type:"button",className:"sidebar-session-button",onClick:r,"aria-pressed":t.active,"aria-expanded":t.hasChildren?!!t.expanded:void 0,title:t.title,children:[e.jsx("span",{className:`sidebar-status-dot is-${t.visualState}`,title:t.statusLabel,"aria-label":t.statusLabel}),e.jsx("span",{className:"sidebar-session-title",children:t.title}),((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(Nt,{size:13,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"})}),((c=t.compatibility)==null?void 0:c.status)==="incompatible"&&e.jsx("span",{className:"sidebar-session-compatibility",title:t.compatibility.reason??"Codex 版本不兼容","aria-label":"Codex 版本不兼容",children:e.jsx(Ja,{size:13,"aria-hidden":"true"})}),t.occupiedExternally&&e.jsx("span",{className:"sidebar-session-lock",title:"原客户端正在使用,只读","aria-label":"原客户端正在使用,只读",children:e.jsx(nd,{size:13,"aria-hidden":"true"})}),t.hasChildren&&e.jsx(Ur,{size:13,className:`sidebar-session-disclosure${t.expanded?" is-expanded":""}`,"aria-hidden":"true"})]}),s&&!t.child&&e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),s()},title:t.pinned?"取消置顶":"置顶会话","aria-label":`${t.pinned?"取消置顶":"置顶会话"}:${t.title}`,"aria-pressed":!!t.pinned,className:`sidebar-session-pin sidebar-row-action ui-icon-button ui-icon-button--small${t.pinned?" sidebar-row-action--accent":""}`,children:e.jsx(pd,{size:14,"aria-hidden":"true"})}),t.canDelete&&o&&e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation();const u=d.currentTarget.getBoundingClientRect();o({top:u.top,left:u.left,width:u.width,height:u.height})},title:n,"aria-label":`${n}:${t.title}`,className:"sidebar-session-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",children:e.jsx(xs,{size:14,"aria-hidden":"true"})})]})}const $f=[["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"])]],Of=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function Ff(t){var o;const n=t.toLocaleLowerCase(),r=Of.get(n);if(r)return r;if(n.startsWith(".env")||n===".gitignore"||n===".npmrc")return"text";const s=n.includes(".")&&n.split(".").pop()||"";return((o=$f.find(([,a])=>a.has(s)))==null?void 0:o[0])??"file"}const Hf={folder:{icon:Yc,label:"文件夹"},code:{icon:Uc,label:"代码文件"},style:{icon:dd,label:"样式文件"},image:{icon:qc,label:"图片文件"},video:{icon:Gc,label:"视频文件"},audio:{icon:Hc,label:"音频文件"},markdown:{icon:cd,label:"Markdown 文件"},text:{icon:qs,label:"文本文件"},json:{icon:Vc,label:"JSON 文件"},archive:{icon:Fc,label:"压缩文件"},spreadsheet:{icon:Kc,label:"表格文件"},presentation:{icon:fd,label:"演示文件"},database:{icon:$c,label:"数据库文件"},file:{icon:Qc,label:"文件"}};function Uf(t,n){return n==="directory"?"folder":Ff(t)}const qa=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function qf(t,n){const r=qa(t),s=qa(n),a=[{label:r==="/"?"/":r.split("/").filter(Boolean).pop()||r,path:r}];if(s===r)return a;const c=s.slice(r==="/"?1:r.length+1);let d=r;for(const u of c.split("/").filter(Boolean))d=d==="/"?`/${u}`:`${d}/${u}`,a.push({label:u,path:d});return a}function Vf({open:t,onCancel:n,onConfirm:r}){const[s,o]=l.useState([]),[a,c]=l.useState(""),[d,u]=l.useState(""),[h,g]=l.useState([]),[y,m]=l.useState(!1),[b,C]=l.useState(""),[M,A]=l.useState(!1),I=l.useMemo(()=>qf(a||"/",d||a||"/"),[a,d]),j=async R=>{if(window.agentApi){m(!0),C("");try{const T=await window.agentApi.listProjectDirectories(R);g(T),u(R)}catch(T){C(T instanceof Error?T.message:"无法读取目录")}finally{m(!1)}}};if(l.useEffect(()=>{if(!t||!window.agentApi)return;let R=!1;return m(!0),C(""),window.agentApi.listProjectRoots().then(async T=>{if(R)return;o(T);const _=T[0]??"";c(_),_?await j(_):C("未配置可用的宿主机目录")}).catch(T=>{R||C(T instanceof Error?T.message:"无法读取宿主机目录")}).finally(()=>{R||m(!1)}),()=>{R=!0}},[t]),l.useEffect(()=>{if(!t)return;const R=T=>{T.key==="Escape"&&n()};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[t,n]),!t)return null;const S=R=>{c(R),j(R)},P=()=>{I.length<=1||j(I[I.length-2].path)},K=async()=>{if(!(!d||M)){A(!0),C("");try{await r(d)}catch(R){C(R instanceof Error?R.message:"项目导入失败")}finally{A(!1)}}};return Yt.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:R=>{R.target===R.currentTarget&&n()},children:e.jsxs("section",{className:"host-project-picker",role:"dialog","aria-modal":"true","aria-labelledby":"host-project-picker-title",children:[e.jsxs("header",{className:"host-project-picker-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"host-project-picker-title",children:"选择宿主机项目"}),e.jsx("p",{children:"文件将直接在运行 AgentRoam 的机器上读写"})]}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:n,"aria-label":"关闭目录选择器",title:"关闭",children:e.jsx(qr,{size:16,"aria-hidden":"true"})})]}),s.length>1&&e.jsxs("label",{className:"host-project-picker-root",children:[e.jsx("span",{children:"根目录"}),e.jsx("select",{value:a,onChange:R=>S(R.target.value),children:s.map(R=>e.jsx("option",{value:R,children:R},R))})]}),e.jsxs("nav",{className:"host-project-picker-nav","aria-label":"当前目录",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:P,disabled:I.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(_c,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:I.map((R,T)=>e.jsxs("span",{children:[T>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void j(R.path),children:R.label})]},R.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>d&&void j(d),disabled:!d||y,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(Zo,{size:15,"aria-hidden":"true"})})]}),a==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":y,children:y?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):b?e.jsx("div",{className:"host-project-picker-state is-error",children:b}):h.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):h.map(R=>{const T=Uf(R.name,R.kind),{icon:_,label:k}=Hf[T],W=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${T}`,"aria-hidden":"true",children:e.jsx(_,{size:18,strokeWidth:1.8})}),e.jsx("span",{className:"host-project-picker-name",children:R.name})]});return R.kind==="file"?e.jsx("div",{className:"host-project-picker-row is-file",title:k,children:W},`${R.name}:${R.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void j(R.path),title:k,children:[W,R.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(Ur,{size:16})})]},`${R.name}:${R.path}`)})}),e.jsxs("footer",{className:"host-project-picker-footer",children:[e.jsx("code",{title:d,children:d}),e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"host-project-picker-cancel",onClick:n,children:"取消"}),e.jsx("button",{type:"button",className:"host-project-picker-confirm",disabled:!d||y||M,onClick:()=>void K(),children:M?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const Fl="agentroam.agent-workspaces.v2",Kf=2,Hl=["customer-agent","codex","claude-code","opencode"];function Va(){return{version:2,activeAgent:"customer-agent",agents:{}}}function Ka(){return{workspaces:[],nextCursor:null,watermark:null,expandedWorkspaceIds:[],selectedWorkspaceId:null,selectedSessionId:null,sidebarScrollTop:0,sessions:{}}}function Gf(t=localStorage){try{const n=JSON.parse(t.getItem(Fl)??"null");if(!yr(n)||n.version!==Kf)return Va();const r=Jf(n.activeAgent)?n.activeAgent:"customer-agent",s=yr(n.agents)?n.agents:{},o={};for(const a of Hl){const c=Zf(s[a],a);c&&(o[a]=c)}return{version:2,activeAgent:r,agents:o}}catch{return Va()}}function Ga(t,n=localStorage){try{n.setItem(Fl,JSON.stringify(t))}catch{}}function Qf(t,n,r){const s=new Set(n.data.map(c=>c.workspaceId)),o=r?n.nextCursor?[...n.data,...t.filter(c=>!s.has(c.workspaceId))]:n.data:[...t,...n.data],a=new Set;return o.filter(c=>a.has(c.workspaceId)?!1:(a.add(c.workspaceId),!0))}function Yf(t,n,r){const s=new Set(n.data.map(c=>c.id)),o=r?n.nextCursor?[...n.data,...t.filter(c=>!s.has(c.id))]:n.data:[...t,...n.data],a=new Set;return o.filter(c=>a.has(c.id)?!1:(a.add(c.id),!0))}function Xf(t,n){return!n||t.some(r=>r.id===n.id)?[...t]:[n,...t]}function Zf(t,n){if(!yr(t))return null;const r=Array.isArray(t.workspaces)?t.workspaces.filter(o=>yr(o)&&o.agentType===n&&typeof o.workspaceId=="string"&&typeof o.name=="string"&&Array.isArray(o.roots)&&o.roots.every(a=>typeof a=="string")&&typeof o.order=="number"&&(o.canCreateSession===void 0||typeof o.canCreateSession=="boolean")):[],s={};if(yr(t.sessions))for(const[o,a]of Object.entries(t.sessions))!yr(a)||!Array.isArray(a.data)||(s[o]={data:a.data.filter(c=>yr(c)&&c.agentType===n&&typeof c.id=="string"),nextCursor:typeof a.nextCursor=="string"?a.nextCursor:null,loaded:a.loaded===!0});return{workspaces:r,nextCursor:typeof t.nextCursor=="string"?t.nextCursor:null,watermark:typeof t.watermark=="string"?t.watermark:null,expandedWorkspaceIds:Array.isArray(t.expandedWorkspaceIds)?t.expandedWorkspaceIds.filter(o=>typeof o=="string"):[],selectedWorkspaceId:typeof t.selectedWorkspaceId=="string"?t.selectedWorkspaceId:null,selectedSessionId:typeof t.selectedSessionId=="string"?t.selectedSessionId:null,sidebarScrollTop:typeof t.sidebarScrollTop=="number"&&t.sidebarScrollTop>=0?t.sidebarScrollTop:0,sessions:s}}function Jf(t){return typeof t=="string"&&Hl.includes(t)}function yr(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Qa(t){var s;const n={},r={};for(const[o,a]of Object.entries(t)){const c=a.data;n[o]=Hs(c.filter(d=>!d.parentSessionId));for(const d of c.filter(u=>u.parentSessionId))(r[s=d.parentSessionId]??(r[s]=[])).push(d)}for(const o of Object.values(r))o.sort((a,c)=>a.created.localeCompare(c.created));return{roots:n,children:r,projectIds:new Set(Object.entries(t).filter(([,o])=>o.loaded).map(([o])=>o))}}function Fo(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 eh(){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 Ya(t,n){n&&t.detail>0&&t.currentTarget.blur()}function th(){const t=document.activeElement;t instanceof HTMLElement&&(t.matches("input, textarea, select")||t.isContentEditable)&&t.blur()}function oh(){var Zr,Jr,Kt,Tn,tn,Gt;const[t]=l.useState(Gf),n=t.activeAgent,r=t.agents[n]??Ka(),[s]=l.useState(()=>Qa(r.sessions)),o=l.useRef(t),[a,c]=l.useState(n),d=l.useRef(a);d.current=a;const[u,h]=l.useState(r.workspaces.map(Fo)),[g,y]=l.useState(r.nextCursor),[m,b]=l.useState(r.watermark),[C,M]=l.useState(!1),[A,I]=l.useState(!1),[j,S]=l.useState(null),[P,K]=l.useState(!1),[R,T]=l.useState(s.roots),[_,k]=l.useState(""),[W,Q]=l.useState(!1),[ae,ve]=l.useState(10),[Te,we]=l.useState(null),[Z,me]=l.useState(!1),[Be,It]=l.useState(null),tt=l.useRef(!1),[De,xt]=l.useState([]),[nt,z]=l.useState(s.children),te=l.useRef(R),Ne=l.useRef(nt);te.current=R,Ne.current=nt;const[je,Ce]=l.useState(s.projectIds),[Oe,xe]=l.useState(new Set),[Ee,lt]=l.useState({}),[$t,Fe]=l.useState(new Set),[Se,Ct]=l.useState(Object.fromEntries(Object.entries(r.sessions).map(([f,N])=>[f,N.nextCursor]))),zt=l.useRef(new Map),B=l.useRef(new Map),[F,V]=l.useState(r.selectedWorkspaceId),[Y,ne]=l.useState(r.selectedSessionId),L=l.useRef(F),Ie=l.useRef(Y);L.current=F,Ie.current=Y;const[ke,Lt]=l.useState(new Set),[ct,Ot]=l.useState(new Set(r.expandedWorkspaceIds)),[Rt,oe]=l.useState(new Set),[pn,Xt]=l.useState(!1),[mt,rt]=l.useState(!1),[ft,st]=l.useState(!1),[dt,Pn]=l.useState("settings"),yn=We(f=>f.setTodos),Ve=St(f=>f.skin),Je=St(f=>f.layout),bt=St(f=>f.wakeEnabled),_t=St(f=>f.wakeWord),Wn=St(f=>f.setSkin),Zt=St(f=>f.setLayout),He=St(f=>f.setWakeEnabled),Le=St(f=>f.setWakeWord),At=St(f=>f.autoSpeak),fn=St(f=>f.setAutoSpeak),Pt=St(f=>f.runningFirst),at=St(f=>f.setRunningFirst),wr=St(f=>f.pinnedSessionIds),vn=St(f=>f.togglePinnedSession),wn=St(f=>f.removePinnedSessions),sn=new Set(wr),v=We(f=>f.runningSessionId),D=We(Sd(f=>Object.entries(f.messagesBySession).filter(([,N])=>N.some(q=>q.askUser&&!q.askUser.answered)).map(([N])=>N))),O=l.useCallback(f=>f.status==="running"||v===f.id,[v]),ie=()=>{Ot(new Set),Lt(new Set(Object.keys(nt)))},ue=()=>{const f=u.filter(N=>!Rt.has(N.id)).map(N=>N.id);Ot(new Set(f)),Lt(new Set);for(const N of f){if(cn.current.has(N))continue;const q=ln.current.has(N);qt(N,{refresh:q,background:q})}},_e=Jn(),Ke=Mc(),ze=_e&&Ke,[et,ut]=l.useState(!1),[on,nr]=l.useState(!1),[rr,jr]=l.useState(null),[vs,sr]=l.useState(0),[or,kr]=l.useState(void 0),Jt=l.useRef(null),an=l.useRef(!1),[Sr,Ir]=l.useState(null),jn=l.useRef(null),Dn=l.useRef(!1),Wt=l.useRef(u);Wt.current=u;const hn=l.useRef(Rt);hn.current=Rt;const ln=l.useRef(je);ln.current=je;const cn=l.useRef(Oe);cn.current=Oe;const kn=l.useRef(null);l.useEffect(()=>{document.documentElement.setAttribute("data-skin",Ve)},[Ve]),l.useEffect(()=>{document.body.classList.toggle("layout-compact",Je==="compact")},[Je]),l.useEffect(()=>{var G;const f=u.map((X,he)=>({agentType:a,workspaceId:X.id,name:X.name,roots:X.description?[X.description]:[],order:he,updatedAt:X.updated||void 0,source:X.source??(X.agentType==="claude-code"?"derived":"native"),canCreateSession:X.canCreateSession})),N=Object.fromEntries(u.map(X=>[X.id,{data:[...R[X.id]??[],...Object.values(nt).flat().filter(he=>(R[X.id]??[]).some(de=>de.id===he.parentSessionId))],nextCursor:Se[X.id]??null,loaded:je.has(X.id)}])),q={...o.current,version:2,activeAgent:a,agents:{...o.current.agents,[a]:{workspaces:f,nextCursor:g,watermark:m,expandedWorkspaceIds:[...ct],selectedWorkspaceId:F,selectedSessionId:Y,sidebarScrollTop:((G=kn.current)==null?void 0:G.scrollTop)??0,sessions:N}}};o.current=q,Ga(q)},[a,nt,ct,je,u,F,Y,Se,R,g,m]);const Sn=l.useCallback(()=>{if(!window.agentApi||!bt||an.current||Jt.current)return;const f=()=>{Vd()&&!Jt.current&&(Jt.current=Gd({wakeWord:_t,onWake:N=>{var q;kr(N),sr(G=>G+1),(q=window.agentApi)==null||q.showWindow()},onError:N=>console.warn("[wake]",N)}))};typeof window.agentApi.wakeStart=="function"?(an.current=!0,window.agentApi.wakeStart(_t).then(N=>{N.ok||(an.current=!1,f())}).catch(()=>{an.current=!1,f()})):f()},[bt,_t]);l.useEffect(()=>{var f;if((f=window.agentApi)!=null&&f.onWake)return window.agentApi.onWake(N=>{an.current=!1,kr(N),sr(q=>q+1)})},[]),l.useEffect(()=>{var f;if((f=window.agentApi)!=null&&f.onWakeAiHub)return window.agentApi.onWakeAiHub(()=>{st(!0),Zt("focus")})},[]),l.useEffect(()=>{var f;if((f=window.agentApi)!=null&&f.onWakeCommand)return window.agentApi.onWakeCommand(N=>{var he;const q=((N==null?void 0:N.text)||"").trim();if(!q)return;const G=jn.current&&Date.now()<jn.current.until?jn.current:null;if(G){G.until=Date.now()+9e4,ne(G.sessionId),(he=window.agentApi)==null||he.wakeConversation(!0),Ir({text:q,projectId:null,sessionId:G.sessionId,nonce:Date.now()}),Ge(`语音追问:${q.length>40?q.slice(0,40)+"…":q}`),yt("success"),setTimeout(()=>Ge(null),4e3);return}const X=Wt.current.find(de=>de.name&&q.includes(de.name)&&!hn.current.has(de.id));X&&(V(X.id),Ot(de=>{const ce=new Set(de);return ce.add(X.id),ce})),ne(null),Dn.current=!0,fn(!0),Ir({text:q,projectId:(X==null?void 0:X.id)??null,nonce:Date.now()}),Ge(`语音指令:${q.length>40?q.slice(0,40)+"…":q}${X?`(项目:${X.name})`:""}`),yt("success"),setTimeout(()=>Ge(null),4e3)})},[]);const Xs=l.useCallback(async()=>{window.agentApi&&(Sn(),await window.agentApi.hideWindow())},[Sn]),Zs=l.useCallback(f=>{Xt(!1),jr({right:f.right,bottom:f.bottom}),nr(N=>!N)},[]),Js=l.useCallback(()=>{nr(!1),Xt(f=>!f)},[]);l.useEffect(()=>{if(!on)return;const f=()=>{const q=document.querySelector(".chat-header-action--appearance");if(!q)return;const G=q.getBoundingClientRect();jr(X=>(X==null?void 0:X.right)===G.right&&X.bottom===G.bottom?X:{right:G.right,bottom:G.bottom})},N=window.requestAnimationFrame(f);return window.addEventListener("resize",f),()=>{window.cancelAnimationFrame(N),window.removeEventListener("resize",f)}},[Je,on]),l.useEffect(()=>{window.agentApi&&Sn()},[Sn]),l.useEffect(()=>{const f=()=>{var N;(N=Jt.current)==null||N.stop(),Jt.current=null};return window.addEventListener("focus",f),()=>window.removeEventListener("focus",f)},[]),l.useEffect(()=>{var f,N;bt||((f=Jt.current)==null||f.stop(),Jt.current=null,an.current=!1,(N=window.agentApi)==null||N.wakeStop())},[bt]),l.useEffect(()=>{!bt||!window.agentApi||an.current&&window.agentApi.wakeStart(_t)},[_t]),l.useEffect(()=>()=>{var f;(f=Jt.current)==null||f.stop()},[]);const Ft=[...Object.values(R).flat(),...Object.values(nt).flat()],ht=hf(Ft,f=>sn.has(f.id)),In=Object.entries(R).flatMap(([f,N])=>N.filter(q=>sn.has(q.id)).map(q=>({projectId:f,session:q,created:q.created}))),ir=Pt?_a(In,({session:f})=>O(f)):Hs(In),Gr=Ft,Ht=_.trim().toLowerCase(),Cn=Ht?ht.filter(f=>f.title.toLowerCase().includes(Ht)||(f.cwd||"").toLowerCase().includes(Ht)):null,Ut=Y?Gr.find(f=>f.id===Y):void 0,ar=Ut==null?void 0:Ut.title,Bn=(Ut==null?void 0:Ut.cwd)||((Zr=u.find(f=>f.id===F))==null?void 0:Zr.description)||null,Rn=u.filter(f=>!Rt.has(f.id)).map(f=>f.id),gn=Rn.length>0&&Rn.every(f=>!ct.has(f)),[$n,Cr]=l.useState(300),[Qr,lr]=l.useState(!1),On=l.useRef(!1),xn=l.useRef(0),Fn=l.useRef(0),en=l.useCallback(f=>{if(!On.current)return;const N=Math.min(480,Math.max(160,Fn.current+f.clientX-xn.current));Cr(N)},[]),Yr=l.useCallback(()=>{On.current=!1,lr(!1),document.removeEventListener("mousemove",en),document.removeEventListener("mouseup",Yr)},[en]),ws=l.useCallback(f=>{On.current=!0,lr(!0),xn.current=f.clientX,Fn.current=$n,document.addEventListener("mousemove",en),document.addEventListener("mouseup",Yr)},[$n,en,Yr]),[Rr,Ge]=l.useState(null),[Hn,yt]=l.useState("success"),Mt=f=>{L.current=f.projectId,Ie.current=f.sessionId,V(f.projectId),ne(f.sessionId),f.sessionId||yn([])},Et=f=>{var de;if(f===d.current)return;const N=d.current,q=o.current.agents[N];q&&(o.current={...o.current,agents:{...o.current.agents,[N]:{...q,sidebarScrollTop:((de=kn.current)==null?void 0:de.scrollTop)??q.sidebarScrollTop}}});const G=o.current.agents[f]??Ka(),X=Qa(G.sessions),he=G.workspaces.map(Fo);d.current=f,Wt.current=he,c(f),h(he),y(G.nextCursor),b(G.watermark),M(!1),I(!1),S(null),te.current=X.roots,Ne.current=X.children,T(X.roots),z(X.children),Ce(X.projectIds),ln.current=X.projectIds,xe(new Set),cn.current=new Set,lt({}),Fe(new Set),Ct(Object.fromEntries(Object.entries(G.sessions).map(([ce,Ue])=>[ce,Ue.nextCursor]))),Ot(new Set(G.expandedWorkspaceIds)),oe(new Set),Mt({projectId:G.selectedWorkspaceId,sessionId:G.selectedSessionId}),window.requestAnimationFrame(()=>{kn.current&&(kn.current.scrollTop=G.sidebarScrollTop)}),mn(f,{refresh:G.workspaces.length>0,since:G.watermark})},[Ar,ye]=l.useState([]),Un=l.useCallback(f=>{ye(N=>N.filter(q=>q.id!==f))},[]),cr=l.useCallback(f=>{const N=crypto.randomUUID();ye(q=>[...q,{...f,id:N}]),setTimeout(()=>Un(N),12e3)},[Un]);async function mn(f=d.current,N={}){if(!window.agentApi)return;const q=(B.current.get(f)??0)+1;B.current.set(f,q),M(!0),S(null);try{const G=await window.agentApi.listAgentWorkspaces(f,{cursor:N.cursor,limit:50,refresh:N.refresh,since:N.refresh?N.since??m:null});if(d.current!==f||B.current.get(f)!==q)return;const X=Wt.current.map((ge,Pe)=>({agentType:f,workspaceId:ge.id,name:ge.name,roots:ge.description?[ge.description]:[],order:Pe,updatedAt:ge.updated,source:ge.source??(f==="claude-code"?"derived":"native"),canCreateSession:ge.canCreateSession})),de=Qf(X,G,!N.cursor).map(Fo);Wt.current=de,h(de),y(G.nextCursor),b(G.watermark),I(G.stale===!0);const ce=new Set(de.map(ge=>ge.id)),Ue=L.current;Ue&&!ce.has(Ue)&&Mt(Pa);const gt=new Set([...ln.current].filter(ge=>ce.has(ge)));Ue&&ce.has(Ue)&&gt.add(Ue),T(ge=>Object.fromEntries(Object.entries(ge).filter(([Pe])=>ce.has(Pe)))),Ce(ge=>{const Pe=new Set([...ge].filter(Qt=>ce.has(Qt)));return ln.current=Pe,Pe}),xe(ge=>{const Pe=new Set([...ge].filter(Qt=>ce.has(Qt)));return cn.current=Pe,Pe}),lt(ge=>Object.fromEntries(Object.entries(ge).filter(([Pe])=>ce.has(Pe))));const vt=new Set;if(await Promise.all(de.map(async ge=>{ge.description&&!await window.agentApi.checkProjectPath(ge.description)&&vt.add(ge.id)})),d.current!==f||B.current.get(f)!==q)return;if(oe(vt),N.refreshLoadedSessions!==!1)for(const ge of gt)vt.has(ge)||cn.current.has(ge)||qt(ge,{refresh:!0,background:!0})}catch(G){d.current===f&&(Wt.current.length>0&&I(!0),S(G instanceof Error?G.message:"目录加载失败"))}finally{d.current===f&&B.current.get(f)===q&&M(!1)}}async function qt(f,N={}){var he;if(!window.agentApi)return;const q=d.current,G=`${q}:${f}`,X=(zt.current.get(G)??0)+1;zt.current.set(G,X),xe(de=>{const ce=new Set(de).add(f);return cn.current=ce,ce}),lt(de=>{if(!(f in de))return de;const ce={...de};return delete ce[f],ce});try{const de=await window.agentApi.listAgentWorkspaceSessions(q,f,{cursor:N.cursor,limit:20,refresh:N.refresh});if(d.current!==q||zt.current.get(G)!==X)return;const ce=te.current[f]??[],Ue=N.pendingSession?{...N.pendingSession,projectId:f}:void 0,gt=Ue?[Ue,...ce.filter(Re=>Re.id!==Ue.id)]:ce,vt=new Set(gt.map(Re=>Re.id)),ge=[...gt,...[...vt].flatMap(Re=>Ne.current[Re]??[])],Pe=Yf(ge,de,!N.cursor).map(Re=>({...Re,projectId:Re.projectId??f})),Qt=Hs(Pe.filter(Re=>!Re.parentSessionId)),pt=L.current,nn=Ie.current,dn=Xf(Qt,Ue);pt===f&&nn&&!Pe.some(Re=>Re.id===nn)&&!dn.some(Re=>Re.id===nn)&&Mt(Pa);const Dt={};for(const Re of Pe.filter(wt=>wt.parentSessionId))(Dt[he=Re.parentSessionId]??(Dt[he]=[])).push(Re);for(const Re of Object.values(Dt))Re.sort((wt,un)=>wt.created.localeCompare(un.created));Ct(Re=>({...Re,[f]:de.nextCursor})),Fe(Re=>{const wt=new Set(Re);return de.stale?wt.add(f):wt.delete(f),wt});const Nr={...te.current,[f]:dn},qn={...Ne.current};for(const Re of vt)delete qn[Re];for(const[Re,wt]of Object.entries(Dt))qn[Re]=wt;te.current=Nr,Ne.current=qn,T(Nr),z(qn),Ce(Re=>{const wt=new Set(Re).add(f);return ln.current=wt,wt})}catch(de){if(zt.current.get(G)!==X)return;lt(ce=>({...ce,[f]:de instanceof Error?de.message:"会话加载失败"}))}finally{zt.current.get(G)===X&&xe(de=>{const ce=new Set(de);return ce.delete(f),cn.current=ce,ce})}}const js=async f=>{if(!window.agentApi)return;const N=await window.agentApi.listChildSessions(f);z(q=>({...q,[f]:N.sort((G,X)=>G.created<X.created?-1:1)}))},Mr=async(f,N)=>{if(!window.agentApi)return;const q=Wt.current.find(G=>G.id===f);if(!q||q.canCreateSession===!1){Ge("请先选择目录"),yt("info"),setTimeout(()=>Ge(null),3e3);return}if(!tt.current){tt.current=!0,It({projectId:f,agentType:N});try{const G=(q==null?void 0:q.source)==="imported"?void 0:f,X=await window.agentApi.createSession("新会话",G,N,q==null?void 0:q.description);if(d.current!==N)return;const he=X.projectId===f?X:{...X,projectId:f},de={...te.current,[f]:[he,...(te.current[f]??[]).filter(ce=>ce.id!==X.id)]};te.current=de,T(de),Mt({projectId:f,sessionId:X.id}),ze&&ut(!1),N==="customer-agent"&&qt(f,{refresh:!0,background:!0,pendingSession:he})}catch(G){Ge(G instanceof Error?G.message:"新建会话失败"),yt("error"),setTimeout(()=>Ge(null),3e3)}finally{tt.current=!1,It(null)}}},Er=()=>{const f=Wt.current.find(N=>N.id===F);if(!F||(f==null?void 0:f.canCreateSession)===!1){Ge("请先选择目录"),yt("info"),setTimeout(()=>Ge(null),3e3);return}Mr(F,a)};l.useEffect(()=>{var f;window.agentApi&&(mn(d.current,{refresh:(((f=o.current.agents[d.current])==null?void 0:f.workspaces.length)??0)>0}),Vs.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(xt).catch(()=>{}))},[]),l.useEffect(()=>{const f=window.setInterval(()=>{document.visibilityState!=="visible"||C||mn(a,{refresh:!0,since:m,refreshLoadedSessions:!1})},15e3);return()=>window.clearInterval(f)},[a,C,m]),l.useEffect(()=>{if(!F||!Y||!window.agentApi)return;let f=!1;const N=async()=>{document.visibilityState==="visible"&&(f||await qt(F,{refresh:!0,background:!0}))},q=window.setInterval(()=>void N(),1e4);return()=>{f=!0,window.clearInterval(q)}},[F,Y,Ut==null?void 0:Ut.agentType]),l.useEffect(()=>{if(!F||!window.agentApi)return;const f=u.find(q=>q.id===F),N=f==null?void 0:f.description;N&&window.agentApi.setProjectWorkingDir(N)},[F,u]);const An=f=>{Mt(Wa(f));const N=!ct.has(f);if(Ot(q=>{const G=new Set(q);return N?G.add(f):G.delete(f),G}),N&&!cn.current.has(f)){const q=ln.current.has(f);qt(f,{refresh:q,background:q})}},Xr=async f=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const N=f.replace(/\\/g,"/"),q=N.split("/").filter(Boolean),G=q[q.length-1]||N||"导入的项目",X=await window.agentApi.importAgentWorkspace(d.current,N,G);await mn(d.current,{refresh:!0,refreshLoadedSessions:!1}),Mt(Wa(X.workspace.workspaceId)),await qt(X.workspace.workspaceId,{refresh:!0}),Ot(he=>{const de=new Set(he);return de.add(X.workspace.workspaceId),de}),Ge(X.existing?"该文件夹已在当前 Agent 的目录中":`已导入:${X.workspace.name}`),yt(X.existing?"info":"success"),setTimeout(()=>Ge(null),3e3)},Tr=async()=>{try{if(!window.agentApi){Ge("agentApi 未就绪,请重启应用"),yt("error");return}if(_e){K(!0);return}const f=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",f),!f)return;await Xr(f)}catch(f){console.error("[import] error:",f),Ge(f instanceof Error?f.message:String(f)),yt("error"),setTimeout(()=>Ge(null),5e3)}},eo=async f=>{if(window.agentApi)try{await window.agentApi.deleteProject(f),F===f&&(V(null),ne(null),yn([])),Ge("项目删除成功"),yt("success"),setTimeout(()=>Ge(null),2500),await mn()}catch(N){Ge(N instanceof Error?N.message:"项目删除失败"),yt("error"),setTimeout(()=>Ge(null),4e3)}},Mn=(f,N)=>{we({session:f,anchor:N})},Vt=async()=>{if(!window.agentApi||!Te||Z)return;const{session:f}=Te;me(!0);try{await window.agentApi.deleteSession(f.id);const N=f.projectId??L.current,q=f.agentType;if(N){const he=`${q}:${N}`;zt.current.set(he,(zt.current.get(he)??0)+1)}const G=bf(te.current,Ne.current,[],f.id);te.current=G.sessionsByProject,Ne.current=G.childSessionsByParent,T(G.sessionsByProject),z(G.childSessionsByParent),wn(G.removedIds);const X=o.current.agents[q];if(X){const he={...o.current,agents:{...o.current.agents,[q]:xf(X,G.removedIds)}};o.current=he,Ga(he)}Ie.current&&G.removedIds.includes(Ie.current)&&Mt({projectId:L.current,sessionId:null}),Ge("会话删除成功"),yt("success"),setTimeout(()=>Ge(null),2500),we(null),N&&qt(N,{refresh:!0,background:!0})}catch(N){Ge(N instanceof Error?N.message:"会话删除失败"),yt("error"),setTimeout(()=>Ge(null),4e3)}finally{me(!1)}},ks=[{id:"settings",label:"设置"},{id:"mcp",label:"MCP"},{id:"memory",label:"记忆"},{id:"skill",label:"技能"},{id:"agent",label:"智能体"},{id:"lsp",label:"LSP"}],En=(f,N)=>{const q=Y===f.id,G=O(f),X=No({status:f.status,isRunning:G,needsInput:G&&D.includes(f.id)}),he=nt[f.id]??[],de=!ke.has(f.id);return e.jsxs("div",{className:"sidebar-session-tree",children:[e.jsx(Oo,{session:{id:f.id,title:f.title,visualState:X,statusLabel:zo[X],occupiedExternally:f.agentType!=="codex"&&f.occupancy==="owned-externally",canDelete:f.canDelete,active:q,hasChildren:he.length>0,expanded:de,compatibility:f.compatibility,pinned:sn.has(f.id)},onSelect:()=>{ze&&ut(!1),Mt(Lo(N,f.id)),he.length>0&&Lt(ce=>{const Ue=new Set(ce);return Ue.has(f.id)?Ue.delete(f.id):Ue.add(f.id),Ue})},onPin:()=>vn(f.id),onDelete:ce=>Mn(f,ce)}),e.jsx("div",{className:"sidebar-child-sessions",style:{maxHeight:de?he.length*40:0,opacity:de?1:0},children:he.map(ce=>{const Ue=O(ce),gt=No({status:ce.status,isRunning:Ue,needsInput:Ue&&D.includes(ce.id)});return e.jsx(Oo,{session:{id:ce.id,title:ce.title,visualState:gt,statusLabel:zo[gt],occupiedExternally:ce.agentType!=="codex"&&ce.occupancy==="owned-externally",canDelete:ce.canDelete,active:Y===ce.id,child:!0,compatibility:ce.compatibility},deleteLabel:"删除子会话",onSelect:()=>{ze&&ut(!1),Mt(Lo(N,ce.id))},onDelete:vt=>Mn(ce,vt)},ce.id)})})]},f.id)};return e.jsxs("div",{className:"app-shell",style:{display:"flex",height:_e?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[e.jsx(pf,{}),e.jsx(ff,{}),ze&&et&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>ut(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),ze&&!et&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>ut(!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}}),Je!=="focus"&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:$n,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 0",position:"relative",zIndex:10,overflow:"hidden",...ze?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:et?"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(Jo,{agentType:"customer-agent",size:24})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"})]})}),e.jsx(Wf,{value:a,health:De,onChange:Et}),e.jsxs("button",{type:"button",className:"sidebar-search-field",onClick:()=>{Q(!0),ve(10)},title:"搜索会话","aria-label":"搜索会话",children:[e.jsx(rl,{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":`${u.length} 个目录`,children:u.length})]}),e.jsxs("div",{className:"sidebar-project-actions",children:[e.jsx("button",{type:"button",onClick:f=>{gn?ue():ie(),Ya(f,gn)},title:gn?"展开全部会话":"折叠全部会话","aria-label":gn?"展开全部会话":"折叠全部会话","aria-pressed":gn,disabled:Rn.length===0,className:`ui-icon-button sidebar-collapse-all${gn?" 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:gn?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m7 6 5 5 5-5"}),e.jsx("path",{d:"m7 13 5 5 5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m17 11-5-5-5 5"}),e.jsx("path",{d:"m17 18-5-5-5 5"})]})})}),e.jsx("button",{type:"button",onClick:f=>{at(!Pt),Ya(f,Pt)},title:Pt?"按新建时间排序":"进行中会话优先","aria-label":Pt?"按新建时间排序":"进行中会话优先","aria-pressed":Pt,className:`ui-icon-button sidebar-session-sort${Pt?" 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 Tr(),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:kn,className:"app-sidebar-scroll",onPointerDownCapture:th,onScroll:f=>{const N=f.currentTarget;N.scrollHeight-N.scrollTop-N.clientHeight<120&&g&&!C&&mn(a,{cursor:g})},style:{flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[ir.length>0&&e.jsxs("section",{className:"sidebar-pinned-section","aria-label":"置顶会话",children:[e.jsx("div",{className:"sidebar-pinned-heading",children:"置顶"}),ir.map(({projectId:f,session:N})=>En(N,f))]}),u.map(f=>{var Qt;const N=F===f.id,q=ct.has(f.id),G=je.has(f.id),X=Oe.has(f.id),he=Ee[f.id],de=R[f.id]??[],ce=de.filter(pt=>!sn.has(pt.id)),gt=Pt?_a(ce,O):ce,vt=gt.length>10,ge=Rt.has(f.id),Pe=(Be==null?void 0:Be.agentType)===a&&Be.projectId===f.id;return e.jsxs("div",{className:"sidebar-project-block","aria-busy":X,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${N&&!ge?"sidebar-row-active":""}`,style:{paddingRight:4,opacity:ge?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{ge||An(f.id)},disabled:ge,"aria-expanded":q,"aria-pressed":N,title:ge?`路径不存在:${f.description}`:f.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:ge?"var(--text-muted)":N?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:N&&!ge?600:400,cursor:ge?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[ge?e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.6},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):f.canCreateSession===!1?e.jsx(Zc,{size:13,"aria-hidden":"true",style:{flexShrink:0,opacity:N?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:N?1:.5},children:q?e.jsx("path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6A2 2 0 0 1 18.46 20H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}):e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:f.name})]}),a==="customer-agent"&&!_e&&e.jsx("button",{onClick:pt=>{pt.stopPropagation(),eo(f.id)},title:"删除目录","aria-label":`删除目录:${f.name}`,className:"sidebar-project-delete sidebar-row-action ui-icon-button ui-icon-button--small ui-icon-button--danger",style:{flexShrink:0},children:e.jsx(eh,{})}),f.canCreateSession!==!1&&e.jsx("button",{type:"button",onClick:pt=>{pt.stopPropagation(),Mr(f.id,a)},title:Pe?"正在创建会话":`新建 ${a==="customer-agent"?"Customer Agent":a==="claude-code"?"Claude Code":a==="codex"?"Codex":"OpenCode"} 会话`,"aria-label":Pe?"正在创建会话":`在 ${f.name} 中新建会话`,"aria-busy":Pe,disabled:Be!==null||ge||((Qt=De.find(pt=>pt.agentType===a))==null?void 0:Qt.available)===!1,className:"sidebar-runtime-create sidebar-project-add-action ui-icon-button ui-icon-button--small",children:Pe?e.jsx(Nt,{size:13,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):e.jsx(Ho,{size:13,"aria-hidden":"true"})})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:q?vt?300:800:0,opacity:q?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:pt=>{const nn=pt.currentTarget,dn=nn.scrollHeight-nn.scrollTop-nn.clientHeight<80,Dt=Se[f.id];dn&&Dt&&!X&&qt(f.id,{cursor:Dt})},style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...vt?{maxHeight:280,overflowY:"auto"}:{}},children:[gt.map(pt=>En(pt,f.id)),X&&!G&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),he&&e.jsxs("div",{title:he,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 qt(f.id,{refresh:G,background:G}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),$t.has(f.id)&&!he&&e.jsx("div",{className:"sidebar-cache-state",children:"显示缓存,会话将在下次刷新时更新"}),de.length===0&&G&&!X&&!he&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},f.id)}),u.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:C?"正在加载目录...":"暂无目录"}),u.length>0&&C&&e.jsx("div",{className:"sidebar-cache-state",children:"正在同步目录..."}),A&&!j&&e.jsx("div",{className:"sidebar-cache-state",children:"当前显示缓存目录"}),j&&e.jsxs("div",{className:"sidebar-load-error",title:j,children:[e.jsx("span",{children:u.length>0?"目录刷新失败,当前显示缓存":"目录加载失败"}),e.jsx("button",{type:"button",onClick:()=>void mn(a,{refresh:u.length>0}),children:"重试"})]})]})}),e.jsx("div",{className:"sidebar-bottom-action",children:e.jsx("button",{type:"button",className:"sidebar-new-session-primary",disabled:Be!==null||F!==null&&Rt.has(F)||((Jr=De.find(f=>f.agentType===a))==null?void 0:Jr.available)===!1,"aria-busy":Be!==null,"aria-disabled":Be!==null||!F||((Kt=u.find(f=>f.id===F))==null?void 0:Kt.canCreateSession)===!1,title:Be?"正在创建会话":F&&((Tn=u.find(f=>f.id===F))==null?void 0:Tn.canCreateSession)!==!1?"新建会话":"请先选择目录",onClick:Er,children:Be?e.jsxs(e.Fragment,{children:[e.jsx(Nt,{size:16,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}),e.jsx("span",{children:"正在创建..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ho,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"新建会话"})]})})})]}),Te&&e.jsx(Bf,{message:gf(Te.session),anchor:Te.anchor,mobile:ze,pending:Z,onCancel:()=>we(null),onConfirm:()=>void Vt()}),!ze&&e.jsx("div",{className:`app-sidebar-resizer${Qr?" is-dragging":""}`,onMouseDown:ws,style:{left:$n}}),W&&e.jsx("div",{onClick:()=>Q(!1),style:{position:"fixed",inset:0,zIndex:1300,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"12vh 16px 16px"},children:e.jsxs("div",{onClick:f=>f.stopPropagation(),style:{width:"min(560px, 100%)",maxHeight:"64vh",display:"flex",flexDirection:"column",borderRadius:12,border:"1px solid var(--border-default)",background:"var(--bg-surface)",boxShadow:"0 18px 48px rgba(17,24,39,0.28)",overflow:"hidden"},children:[e.jsx("div",{style:{padding:10,borderBottom:"1px solid var(--border-subtle)"},children:e.jsx("input",{autoFocus:!0,value:_,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key==="Escape"&&Q(!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:[Ht&&Cn&&Cn.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[Cn.length," 个结果"]}),Ht&&Cn&&Cn.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!Ht&&ht.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),(Cn??ht.slice(0,ae)).map(f=>{const N=Y===f.id,q=O(f),G=No({status:f.status,isRunning:q,needsInput:q&&D.includes(f.id)});return e.jsx(Oo,{session:{id:f.id,title:f.title,visualState:G,statusLabel:zo[G],occupiedExternally:f.agentType!=="codex"&&f.occupancy==="owned-externally",canDelete:f.canDelete,active:N,child:!!f.parentSessionId,compatibility:f.compatibility,pinned:sn.has(f.id)},onSelect:()=>{const X=f.projectId&&u.some(he=>he.id===f.projectId)?f.projectId:null;Mt(Lo(X,f.id)),Q(!1),ze&&ut(!1)},onPin:f.parentSessionId?void 0:()=>vn(f.id),onDelete:X=>Mn(f,X)},f.id)}),!Ht&&ht.length>ae&&e.jsx("button",{type:"button",onClick:()=>ve(f=>f+10),style:{width:"100%",padding:"8px 10px",border:0,borderTop:"1px solid var(--border-subtle)",background:"transparent",color:"var(--text-muted)",fontSize:12,cursor:"pointer",textAlign:"center"},children:"更多…"})]})]})})]}),Rr&&Yt.createPortal(e.jsxs("div",{className:`app-action-notice is-${Hn}`,role:Hn==="error"?"alert":"status","aria-live":Hn==="error"?"assertive":"polite",children:[e.jsx("span",{className:"app-action-notice-mark","aria-hidden":"true",children:Hn==="success"?"✓":Hn==="info"?"i":"!"}),e.jsx("span",{children:Rr})]}),document.body),e.jsxs("main",{className:"app-main",style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[Je==="focus"&&e.jsx("button",{onClick:()=>Zt("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,display:ft?"none":void 0},children:e.jsx(Gp,{activeAgentType:a,selectedProjectId:F,selectedSessionId:Y,sessionTitle:ar,sessionSummary:Ut,workspacePath:Bn,voiceCommand:Sr,onOpenSettings:Js,settingsOpen:pn,desktopLiveOpen:mt,onOpenDesktopLive:!_e&&((tn=window.agentApi)!=null&&tn.desktopLiveGetStatus)?()=>rt(!0):void 0,onHideToBackground:()=>void Xs(),onOpenHub:(Gt=window.agentApi)!=null&&Gt.hubGetConfig?()=>st(!0):void 0,onToggleAppearance:Zs,appearanceOpen:on,hideToBackgroundTitle:bt?`隐藏到后台(说“${_t}”唤醒)`:"隐藏到后台",onSessionCreated:async(f,N)=>{var G;const q=L.current;Mt({projectId:q,sessionId:f}),Dn.current&&(Dn.current=!1,jn.current={sessionId:f,until:Date.now()+9e4},(G=window.agentApi)==null||G.wakeConversation(!0)),q&&await qt(q,{pendingSession:N})},onSubSessionCreated:async f=>{await js(f)},onSelectSession:f=>{ne(f)},onSubAgentEvent:f=>{f.type==="started"?cr({type:"info",title:"子会话已启动",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId}):f.type==="completed"?cr({type:"success",title:"子会话已完成",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId}):cr({type:"error",title:"子会话出错",body:`${f.agentName}:${f.task.slice(0,60)}`,sessionId:f.subSessionId})},onMessageSent:(f,N)=>{T(q=>{const G={};for(const[X,he]of Object.entries(q))G[X]=he.map(de=>de.id===f?{...de,title:N.slice(0,60)||de.title}:de);return G})},onRunComplete:async(f,N)=>{var he;const q=jn.current,G=yp(q,N);jn.current=G,G!==q&&((he=window.agentApi)==null||he.wakeConversation(!0));const X=f||F;X&&await qt(X,{refresh:!0,background:!0})}})}),ft&&e.jsx(lf,{onExit:()=>st(!1)})]}),mt&&e.jsx(If,{onClose:()=>rt(!1)}),pn&&Yt.createPortal(e.jsx("div",{onClick:()=>Xt(!1),style:{position:"fixed",inset:0,zIndex:10001,background:"rgba(17,24,39,0.18)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.2s var(--ease-out)",WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:f=>f.stopPropagation(),style:{width:"min(920px, calc(100vw - 48px))",height:"min(760px, calc(100vh - 48px))",background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:"var(--shadow-md)",overflow:"hidden",display:"flex",flexDirection:"column",animation:"fadeInUp 0.25s var(--ease-out)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border-subtle)",padding:"8px 10px",background:"var(--bg-deepest)"},children:[e.jsx("div",{style:{display:"flex",gap:6},children:ks.map(f=>e.jsx("button",{onClick:()=>Pn(f.id),className:`settings-tab ${dt===f.id?"settings-tab-active":""}`,children:f.label},f.id))}),e.jsx("button",{onClick:()=>Xt(!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:[dt==="settings"&&e.jsx(vf,{}),dt==="mcp"&&e.jsx(Cf,{}),dt==="memory"&&e.jsx(Rf,{}),dt==="skill"&&e.jsx(Mf,{}),dt==="agent"&&e.jsx(Nf,{}),dt==="lsp"&&e.jsx(Lf,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),on&&rr&&Yt.createPortal(e.jsx("div",{onClick:()=>nr(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:f=>f.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(rr.right-320,window.innerWidth-332)),top:rr.bottom+8,width:320,maxHeight:`calc(100vh - ${rr.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:Ec.map(f=>e.jsxs("button",{onClick:()=>Wn(f.id),className:`appearance-choice ${Ve===f.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${f.preview[0]} 55%, ${f.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:Ve===f.id?600:400},children:f.label}),Ve===f.id&&e.jsx("svg",{className:"appearance-choice-check",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m5 12 4 4L19 6"})})]},f.id))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:8},children:"布局"}),e.jsx("div",{className:"appearance-segmented",children:Tc.map(f=>e.jsx("button",{onClick:()=>Zt(f.id),title:f.description,className:`appearance-segment ${Je===f.id?"appearance-segment-active":""}`,children:f.label},f.id))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,borderTop:"1px solid var(--border-subtle)",paddingTop:12},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.08em"},children:"语音"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["助手回复自动播报",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:At,onChange:f=>fn(f.target.checked)})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:12,color:"var(--text-secondary)",cursor:"pointer"},children:["隐藏后语音唤醒",e.jsx("input",{className:"appearance-switch",type:"checkbox",checked:bt,onChange:f=>He(f.target.checked)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{flexShrink:0},children:"唤醒词"}),e.jsx("input",{value:_t,onChange:f=>Le(f.target.value||"小智"),style:{flex:1,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--bg-deep)",color:"var(--text-primary)",fontSize:12}})]})]})]})}),document.body),e.jsx(Vf,{open:P,onCancel:()=>K(!1),onConfirm:async f=>{await Xr(f),K(!1)}}),e.jsx(_f,{trigger:vs,heardText:or}),Ar.length>0&&Yt.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:Ar.map(f=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${f.type==="error"?"rgba(220,38,38,0.25)":f.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${f.type==="error"?"var(--danger)":f.type==="success"?"var(--success)":"var(--accent)"}`,borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-md)",padding:"12px 14px",animation:"fadeInUp 0.22s var(--ease-out)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsxs("span",{style:{fontSize:12,fontWeight:600,color:f.type==="error"?"var(--danger)":f.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[f.type==="error"?"✕":f.type==="success"?"✓":"◎"," ",f.title]}),e.jsx("button",{onClick:()=>Un(f.id),title:"关闭",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:14,lineHeight:1,padding:"2px 4px",borderRadius:4,transition:"color 0.15s"},onMouseEnter:N=>N.currentTarget.style.color="var(--text-primary)",onMouseLeave:N=>N.currentTarget.style.color="var(--text-muted)",children:"×"})]}),e.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)",lineHeight:1.5,wordBreak:"break-all"},children:f.body}),f.sessionId&&e.jsx("button",{onClick:()=>{ne(f.sessionId),Un(f.id)},style:{marginTop:8,padding:"4px 10px",fontSize:11,fontWeight:500,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid var(--border-glow)",borderRadius:6,cursor:"pointer",transition:"background 0.15s",WebkitAppRegion:"no-drag"},onMouseEnter:N=>N.currentTarget.style.background="var(--accent-glow)",onMouseLeave:N=>N.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},f.id))}),document.body)]})}export{oh as default};