agentroam-runtime-darwin-arm64 0.2.0-preview.37 → 0.2.0-preview.39

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 (203) 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 +14 -14
  5. package/runtime/.next/app-path-routes-manifest.json +1 -1
  6. package/runtime/.next/build-manifest.json +6 -6
  7. package/runtime/.next/prerender-manifest.json +1 -1
  8. package/runtime/.next/react-loadable-manifest.json +12 -4
  9. package/runtime/.next/required-server-files.json +1 -1
  10. package/runtime/.next/routes-manifest.json +1 -1
  11. package/runtime/.next/server/app/_not-found/page.js +1 -1
  12. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/runtime/.next/server/app/_not-found.html +1 -1
  14. package/runtime/.next/server/app/_not-found.rsc +1 -1
  15. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  16. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  17. package/runtime/.next/server/app/api/agent/harness/status/route.js +1 -1
  18. package/runtime/.next/server/app/api/agent/model/route.js +1 -1
  19. package/runtime/.next/server/app/api/agent/models/route.js +1 -1
  20. package/runtime/.next/server/app/api/agent/run/route.js +3 -3
  21. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  22. package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
  23. package/runtime/.next/server/app/api/agent/stream/route.js +3 -3
  24. package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
  25. package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
  26. package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
  27. package/runtime/.next/server/app/api/business/route.js +1 -1
  28. package/runtime/.next/server/app/api/client-logs/route.js +1 -1
  29. package/runtime/.next/server/app/api/flow/v1/catalog/route.js +1 -1
  30. package/runtime/.next/server/app/api/flow/v1/runs/[runId]/cancel/route.js +1 -1
  31. package/runtime/.next/server/app/api/flow/v1/runs/[runId]/events/route.js +2 -2
  32. package/runtime/.next/server/app/api/flow/v1/runs/route.js +1 -1
  33. package/runtime/.next/server/app/api/flow-studio/config/route.js +1 -1
  34. package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
  35. package/runtime/.next/server/app/api/mcp/disconnect/route.js +1 -1
  36. package/runtime/.next/server/app/api/mcp/servers/route.js +1 -1
  37. package/runtime/.next/server/app/api/memory/[key]/route.js +1 -1
  38. package/runtime/.next/server/app/api/memory/route.js +1 -1
  39. package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
  40. package/runtime/.next/server/app/api/projects/[id]/route.js +1 -1
  41. package/runtime/.next/server/app/api/projects/check/route.js +1 -1
  42. package/runtime/.next/server/app/api/projects/directories/route.js +1 -1
  43. package/runtime/.next/server/app/api/projects/roots/route.js +1 -1
  44. package/runtime/.next/server/app/api/projects/route.js +1 -1
  45. package/runtime/.next/server/app/api/push/subscribe/route.js +2 -2
  46. package/runtime/.next/server/app/api/push/unsubscribe/route.js +2 -2
  47. package/runtime/.next/server/app/api/push/vapid/route.js +2 -2
  48. package/runtime/.next/server/app/api/push/vapid.body +1 -1
  49. package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
  50. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
  51. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
  52. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js.nft.json +1 -1
  53. package/runtime/.next/server/app/api/sessions/[id]/fork-at/route.js +1 -0
  54. package/runtime/.next/server/app/api/sessions/[id]/fork-at/route.js.nft.json +1 -0
  55. package/runtime/.next/server/app/api/sessions/[id]/goals/route.js +1 -1
  56. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
  57. package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js +1 -1
  58. package/runtime/.next/server/app/api/sessions/[id]/release/route.js +1 -1
  59. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  60. package/runtime/.next/server/app/api/sessions/[id]/thread-goal/route.js +1 -1
  61. package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js +1 -1
  62. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  63. package/runtime/.next/server/app/api/settings/route.js +1 -1
  64. package/runtime/.next/server/app/api/skills/route.js +1 -1
  65. package/runtime/.next/server/app/api/tool-policies/[policyId]/route.js +1 -1
  66. package/runtime/.next/server/app/api/tool-policies/route.js +1 -1
  67. package/runtime/.next/server/app/api/tools/route.js +1 -1
  68. package/runtime/.next/server/app/api/update/check/route.js +1 -1
  69. package/runtime/.next/server/app/api/update/install/route.js +1 -1
  70. package/runtime/.next/server/app/api/update/status/route.js +1 -1
  71. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  72. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  73. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  74. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  75. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  76. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  77. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  78. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  79. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  80. package/runtime/.next/server/app/web/page.js +2 -2
  81. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  82. package/runtime/.next/server/app-paths-manifest.json +20 -19
  83. package/runtime/.next/server/chunks/1322.js +72 -69
  84. package/runtime/.next/server/chunks/1773.js +38 -38
  85. package/runtime/.next/server/chunks/2293.js +1 -1
  86. package/runtime/.next/server/chunks/366.js +1 -0
  87. package/runtime/.next/server/chunks/5303.js +1 -1
  88. package/runtime/.next/server/chunks/8532.js +1 -1
  89. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  90. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  91. package/runtime/.next/server/pages/404.html +1 -1
  92. package/runtime/.next/server/pages/500.html +1 -1
  93. package/runtime/.next/server/server-reference-manifest.json +1 -1
  94. package/runtime/.next/static/chunks/326.567dcaf52a3fbf80.js +1 -0
  95. package/runtime/.next/static/chunks/693-41d7c8e27a8513d1.js +1 -0
  96. package/runtime/.next/static/chunks/784.1394d774230a5516.js +1 -0
  97. package/runtime/.next/static/chunks/834.801325c7f934eee6.js +1 -0
  98. package/runtime/.next/static/chunks/940.56137a61c838fa42.js +1 -0
  99. package/runtime/.next/static/chunks/95.ff2ef92ac2b1c909.js +1 -0
  100. package/runtime/.next/static/chunks/app/web/{error-7bdc841dab0f7345.js → error-f69dbd3718cb2107.js} +1 -1
  101. package/runtime/.next/static/chunks/app/web/layout-e0dd41d18df8ee9e.js +1 -0
  102. package/runtime/.next/static/chunks/app/web/page-f9926cbf4c1badd4.js +1 -0
  103. package/runtime/.next/static/chunks/{main-app-851d67ddcf02e2c2.js → main-app-d527fa0b25a0c755.js} +1 -1
  104. package/runtime/.next/static/chunks/webpack-d4e32619d2ce6d30.js +1 -0
  105. package/runtime/.next/static/css/e87416656ec8a57e.css +1 -0
  106. package/runtime/lib/remote-control/helper-manager.mjs +4 -1
  107. package/runtime/lib/remote-control/remote-authorization.mjs +21 -7
  108. package/runtime/native/AgentRoam Remote Desktop.app/Contents/MacOS/agentroam-remote-desktop +0 -0
  109. package/runtime/node_modules/.package-lock.json +11 -11
  110. package/runtime/node_modules/@agent/core/dist/index.js +123 -9
  111. package/runtime/node_modules/@agent/native-runtime/dist/index.js +141 -35
  112. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +77 -76
  113. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +48 -48
  114. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-2haqfy07.mjs +33 -0
  115. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-a92dt75k.mjs +40 -0
  116. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core.mjs +17 -17
  117. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +19 -25
  118. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -29
  119. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/package.json +12 -12
  120. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +53 -53
  121. package/runtime/package-lock.json +35 -35
  122. package/runtime/server.js +1 -1
  123. package/runtime/webapp/dist/assets/App-COIcZZvf.js +487 -0
  124. package/runtime/webapp/dist/assets/{App-CMOzoP5A.css → App-iUeP1CBo.css} +1 -1
  125. package/runtime/webapp/dist/assets/{abnfDiagram-VCTEODGH-CEAlrV9-.js → abnfDiagram-VCTEODGH-d4urtMQU.js} +1 -1
  126. package/runtime/webapp/dist/assets/{arc-CGetF_lO.js → arc-DiQEpEJQ.js} +1 -1
  127. package/runtime/webapp/dist/assets/{architectureDiagram-5GKGNRK7-BVksDtm9.js → architectureDiagram-5GKGNRK7-CWYKGqND.js} +1 -1
  128. package/runtime/webapp/dist/assets/{blockDiagram-I7D4REHJ-BvCo3epW.js → blockDiagram-I7D4REHJ-J2I0b5Zn.js} +1 -1
  129. package/runtime/webapp/dist/assets/{c4Diagram-7LVT6UL2-DwUEj82r.js → c4Diagram-7LVT6UL2-C-0xWeN3.js} +1 -1
  130. package/runtime/webapp/dist/assets/channel-B6S3kcST.js +1 -0
  131. package/runtime/webapp/dist/assets/{chunk-2Q5K7J3B-BQmtZUl-.js → chunk-2Q5K7J3B-CqodmK6L.js} +1 -1
  132. package/runtime/webapp/dist/assets/{chunk-5VM5RSS4-BXDY0cCC.js → chunk-5VM5RSS4-DClUnQcr.js} +1 -1
  133. package/runtime/webapp/dist/assets/{chunk-F27PBJKO-BPhfHsOp.js → chunk-F27PBJKO-CpaDg7Bg.js} +1 -1
  134. package/runtime/webapp/dist/assets/{chunk-IMKFNOWR-Dw-LyvaC.js → chunk-IMKFNOWR-CTIf9EjK.js} +1 -1
  135. package/runtime/webapp/dist/assets/{chunk-JWPE2WC7-Cdi61XTf.js → chunk-JWPE2WC7-DKalSWMm.js} +1 -1
  136. package/runtime/webapp/dist/assets/{chunk-POPQ4Y6H-eqgC5BfH.js → chunk-POPQ4Y6H-69MmeyRW.js} +1 -1
  137. package/runtime/webapp/dist/assets/{chunk-SVP7TREG-Dyzqf0xA.js → chunk-SVP7TREG-DCXWXzhU.js} +1 -1
  138. package/runtime/webapp/dist/assets/{chunk-TICWLB2K-DMy_FAyQ.js → chunk-TICWLB2K-B5nbTEng.js} +1 -1
  139. package/runtime/webapp/dist/assets/{chunk-XXDRQBXY-Dc3ya8KM.js → chunk-XXDRQBXY-DsJvkUuN.js} +1 -1
  140. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-CyUA2YaV.js +1 -0
  141. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-CyUA2YaV.js +1 -0
  142. package/runtime/webapp/dist/assets/codeSyntax-DJH88FPL.js +5 -0
  143. package/runtime/webapp/dist/assets/{cose-bilkent-JH36ORCC-8SpbJGQ_.js → cose-bilkent-JH36ORCC-BamzQ_e_.js} +1 -1
  144. package/runtime/webapp/dist/assets/{cynefin-OW5HDTMX-DZ8NcP4L.js → cynefin-OW5HDTMX-BI_j1tbW.js} +1 -1
  145. package/runtime/webapp/dist/assets/{cynefinDiagram-5FMLGOSQ-C-g805uS.js → cynefinDiagram-5FMLGOSQ-DuxMrVM2.js} +1 -1
  146. package/runtime/webapp/dist/assets/{dagre-GXQ25YYZ-Cr8OiP_4.js → dagre-GXQ25YYZ-Y9_ne36w.js} +1 -1
  147. package/runtime/webapp/dist/assets/{diagram-S7CK7UJ4-Be71Foqh.js → diagram-S7CK7UJ4-DIIjO29m.js} +1 -1
  148. package/runtime/webapp/dist/assets/{diagram-UQ7AKVKN-CeDsu1RS.js → diagram-UQ7AKVKN-C4m2VMIy.js} +1 -1
  149. package/runtime/webapp/dist/assets/{diagram-VSXAHHWV-CObfkAwP.js → diagram-VSXAHHWV-Cw5aPZ0o.js} +1 -1
  150. package/runtime/webapp/dist/assets/{diagram-VX7I27RA-B6lAuke7.js → diagram-VX7I27RA-W8nmVcOl.js} +1 -1
  151. package/runtime/webapp/dist/assets/{diagram-Z3DM3KII-8oGhKMeq.js → diagram-Z3DM3KII-TksnHlQo.js} +1 -1
  152. package/runtime/webapp/dist/assets/{ebnfDiagram-PWID7BFC-DmiqrULj.js → ebnfDiagram-PWID7BFC-B3WM1b4a.js} +1 -1
  153. package/runtime/webapp/dist/assets/{erDiagram-RLTQ6QDP-BB_7Zdd4.js → erDiagram-RLTQ6QDP-BWctPuya.js} +1 -1
  154. package/runtime/webapp/dist/assets/{flowDiagram-HODETNUW-DbuKFxoO.js → flowDiagram-HODETNUW-BG5RMrLN.js} +1 -1
  155. package/runtime/webapp/dist/assets/{ganttDiagram-EL5Y4UJY-DAM3Gwd_.js → ganttDiagram-EL5Y4UJY-CPcR7Kn_.js} +1 -1
  156. package/runtime/webapp/dist/assets/{gitGraphDiagram-WWUBYQGX-Ci91dL5m.js → gitGraphDiagram-WWUBYQGX-Sg6KChEd.js} +1 -1
  157. package/runtime/webapp/dist/assets/{index-NmsboYZi.css → index-CtJgsVah.css} +1 -1
  158. package/runtime/webapp/dist/assets/{index-ZpxfzUdy.js → index-tQnPGo1_.js} +4 -4
  159. package/runtime/webapp/dist/assets/{infoDiagram-27XIBGKW-D717Ys7n.js → infoDiagram-27XIBGKW-BvrtvnrY.js} +1 -1
  160. package/runtime/webapp/dist/assets/{ishikawaDiagram-5VMMS53U-BF6gmyPX.js → ishikawaDiagram-5VMMS53U-Bz-dZQLJ.js} +1 -1
  161. package/runtime/webapp/dist/assets/{journeyDiagram-3NMN7TZE-B6ZY-IXx.js → journeyDiagram-3NMN7TZE-Cb4s9jRE.js} +1 -1
  162. package/runtime/webapp/dist/assets/{kanban-definition-UXKFOSKX-DH3FR2sI.js → kanban-definition-UXKFOSKX-IjMPUHg9.js} +1 -1
  163. package/runtime/webapp/dist/assets/{layout-BOnxGXiM.js → layout-DHjqr0PJ.js} +1 -1
  164. package/runtime/webapp/dist/assets/{linear-M6pkDoQ3.js → linear-COctZkFy.js} +1 -1
  165. package/runtime/webapp/dist/assets/{mermaid.core-DxK9Epxh.js → mermaid.core-BnonXfHT.js} +5 -5
  166. package/runtime/webapp/dist/assets/{mindmap-definition-YA3MSWOX-DpZ-X_Vf.js → mindmap-definition-YA3MSWOX-hxBlXJJE.js} +1 -1
  167. package/runtime/webapp/dist/assets/{pegDiagram-XKGWAZYB-ZxLpbtO1.js → pegDiagram-XKGWAZYB-D6KJ8Ftm.js} +1 -1
  168. package/runtime/webapp/dist/assets/{pieDiagram-E7YTZNPT-B26_pDmg.js → pieDiagram-E7YTZNPT-BzKWZmHN.js} +1 -1
  169. package/runtime/webapp/dist/assets/{quadrantDiagram-AXDQQJYC-C-qB9cbX.js → quadrantDiagram-AXDQQJYC-ZhiPKt96.js} +1 -1
  170. package/runtime/webapp/dist/assets/{railroadDiagram-O6MQD6OU-C54V-8Ku.js → railroadDiagram-O6MQD6OU-BtKhiOPG.js} +1 -1
  171. package/runtime/webapp/dist/assets/{requirementDiagram-BXWQKSXE-CaMYVKMk.js → requirementDiagram-BXWQKSXE-OFr_TA8V.js} +1 -1
  172. package/runtime/webapp/dist/assets/{sankeyDiagram-P5KCCOFB-DsrVKW_h.js → sankeyDiagram-P5KCCOFB-qNTDFxAX.js} +1 -1
  173. package/runtime/webapp/dist/assets/{sequenceDiagram-WJ2MYXX4-C5ImABz1.js → sequenceDiagram-WJ2MYXX4-B7s5-R4s.js} +1 -1
  174. package/runtime/webapp/dist/assets/{sizeCapture-INFHLROL-wM9HJhkr.js → sizeCapture-INFHLROL-DdFabbN6.js} +1 -1
  175. package/runtime/webapp/dist/assets/{stateDiagram-D77RDMKH-BY8hQ5ro.js → stateDiagram-D77RDMKH-CmAN4pX7.js} +1 -1
  176. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-DsxpCqde.js +1 -0
  177. package/runtime/webapp/dist/assets/{swimlanes-42K2YHIH-OsTKRKJW.js → swimlanes-42K2YHIH-BQlIJAhf.js} +1 -1
  178. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-tji3GZVz.js +8 -0
  179. package/runtime/webapp/dist/assets/{timeline-definition-24CTP7MA-DqyQVkVW.js → timeline-definition-24CTP7MA--Y1zJ9mc.js} +1 -1
  180. package/runtime/webapp/dist/assets/{vennDiagram-4TSXK5OY-Di3KXYdD.js → vennDiagram-4TSXK5OY-CUn6FScx.js} +1 -1
  181. package/runtime/webapp/dist/assets/{wardleyDiagram-VM6X3IG4-CnJpZdMd.js → wardleyDiagram-VM6X3IG4-Bbz-WBd5.js} +1 -1
  182. package/runtime/webapp/dist/assets/{web-BMb61xwV.js → web-DzBEnE5q.js} +1 -1
  183. package/runtime/webapp/dist/assets/{web-eq1eso0Y.js → web-harvpkJj.js} +1 -1
  184. package/runtime/webapp/dist/assets/{xychartDiagram-S5SC5T6Z-frC_Dy5B.js → xychartDiagram-S5SC5T6Z-RA9edGdQ.js} +1 -1
  185. package/runtime/webapp/dist/index.html +2 -2
  186. package/runtime/ws-server.mjs +5 -5
  187. package/runtime/.next/static/chunks/221.80fc551c3d6118e2.js +0 -1
  188. package/runtime/.next/static/chunks/326.c10c95f947d32ecb.js +0 -1
  189. package/runtime/.next/static/chunks/750-1766abd7e24fd1d6.js +0 -1
  190. package/runtime/.next/static/chunks/942.1dec0ce762e131a5.js +0 -1
  191. package/runtime/.next/static/chunks/app/web/layout-e5b1780d2961e7c0.js +0 -1
  192. package/runtime/.next/static/chunks/app/web/page-f5171cee114f2892.js +0 -1
  193. package/runtime/.next/static/chunks/webpack-3ff471b94db6b1b2.js +0 -1
  194. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-reghh1vn.mjs +0 -33
  195. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-tm6xdb2r.mjs +0 -40
  196. package/runtime/webapp/dist/assets/App-DQ5fJODJ.js +0 -476
  197. package/runtime/webapp/dist/assets/channel-BjAaNinW.js +0 -1
  198. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-BA6foNu5.js +0 -1
  199. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-BA6foNu5.js +0 -1
  200. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-D7wp4Sey.js +0 -1
  201. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-Dq79H5La.js +0 -8
  202. /package/runtime/.next/static/{ENg3PaHjA_727MHwcEIkE → BmUH3xLHQfGkG3yzEK37i}/_buildManifest.js +0 -0
  203. /package/runtime/.next/static/{ENg3PaHjA_727MHwcEIkE → BmUH3xLHQfGkG3yzEK37i}/_ssgManifest.js +0 -0
@@ -1,476 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./mermaid.core-DxK9Epxh.js","./index-ZpxfzUdy.js","./index-NmsboYZi.css"])))=>i.map(i=>d[i]);
2
- var Ja=t=>{throw TypeError(t)};var Ru=(t,n,r)=>n.has(t)||Ja("Cannot "+r);var Za=(t,n,r)=>n.has(t)?Ja("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,r);var el=(t,n,r)=>(Ru(t,n,"access private method"),r);import{r as a,R as Eu,j as e,_ as Mu,b as $n,d as Nc,B as Au,i as Fo,O as tl,u as fn,e as Tu,S as Nu,L as _u}from"./index-ZpxfzUdy.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 zu=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),_c=(...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 Lu={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 Pu=a.forwardRef(({color:t="currentColor",size:n=24,strokeWidth:r=2,absoluteStrokeWidth:s,className:i="",children:o,iconNode:c,...d},u)=>a.createElement("svg",{ref:u,...Lu,width:n,height:n,stroke:t,strokeWidth:s?Number(r)*24/Number(n):r,className:_c("lucide",i),...d},[...c.map(([g,f])=>a.createElement(g,f)),...Array.isArray(o)?o:[o]]));/**
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=a.forwardRef(({className:s,...i},o)=>a.createElement(Pu,{ref:o,iconNode:n,className:_c(`lucide-${zu(t)}`,s),...i}));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 nl=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 Zo=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 Du=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 Wu=se("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);/**
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 Bu=se("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
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 ea=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"}]]);/**
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 $r=se("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
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 Li=se("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
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 Ur=se("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
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 zc=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"}]]);/**
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 Fu=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"}]]);/**
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 Ti=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"}]]);/**
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 Ou=se("CornerDownLeft",[["polyline",{points:"9 10 4 15 9 20",key:"r3jprv"}],["path",{d:"M20 4v7a4 4 0 0 1-4 4H4",key:"6o5b7l"}]]);/**
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 rl=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"}]]);/**
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 Lc=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"}]]);/**
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 ta=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"}]]);/**
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 $u=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"}]]);/**
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 Uu=se("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
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 Pc=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"}]]);/**
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 Dc=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"}]]);/**
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 Wc=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"}]]);/**
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 Bc=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"}]]);/**
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 Fc=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"}]]);/**
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 Oc=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"}]]);/**
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 ai=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"}]]);/**
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 $c=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"}]]);/**
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 Uc=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"}]]);/**
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 sl=se("FolderOpen",[["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-1.95 1.5H4a2 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",key:"usdka0"}]]);/**
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 Oo=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"}]]);/**
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 il=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"}]]);/**
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 Hu=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"}]]);/**
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 qu=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"}]]);/**
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 ho=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"}]]);/**
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 Vu=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"}]]);/**
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 Gu=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"}]]);/**
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 Ku=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"}]]);/**
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 lt=se("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
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 Qu=se("LocateFixed",[["line",{x1:"2",x2:"5",y1:"12",y2:"12",key:"bvdh0s"}],["line",{x1:"19",x2:"22",y1:"12",y2:"12",key:"1tbv5k"}],["line",{x1:"12",x2:"12",y1:"2",y2:"5",key:"11lu5j"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}],["circle",{cx:"12",cy:"12",r:"7",key:"fim9np"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
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 Xu=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"}]]);/**
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 ol=se("LockOpen",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]]);/**
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 Yu=se("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);/**
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 Ju=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"}]]);/**
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 Zu=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"}]]);/**
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 ep=se("MicOff",[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M18.89 13.23A7.12 7.12 0 0 0 19 12v-2",key:"80xlxr"}],["path",{d:"M5 10v2a7 7 0 0 0 12 5",key:"p2k8kg"}],["path",{d:"M15 9.34V5a3 3 0 0 0-5.68-1.33",key:"1gzdoj"}],["path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12",key:"r2i35w"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
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 al=se("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
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 tp=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"}]]);/**
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 go=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"}]]);/**
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 ll=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"}]]);/**
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 np=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"}]]);/**
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 rp=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"}]]);/**
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 Hc=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"}]]);/**
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 qc=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"}]]);/**
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 sp=se("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
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 ip=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"}]]);/**
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 na=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"}]]);/**
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 op=se("PhoneOff",[["path",{d:"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67m-2.67-3.34a19.79 19.79 0 0 1-3.07-8.63A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91",key:"z86iuo"}],["line",{x1:"22",x2:"2",y1:"2",y2:"22",key:"11kh81"}]]);/**
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 ap=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"}]]);/**
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 lp=se("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
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 $o=se("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
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 cl=se("Power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]);/**
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 Vc=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"}]]);/**
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 _s=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"}]]);/**
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 ra=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"}]]);/**
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 cp=se("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);/**
343
- * @license lucide-react v0.468.0 - ISC
344
- *
345
- * This source code is licensed under the ISC license.
346
- * See the LICENSE file in the root directory of this source tree.
347
- */const dp=se("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
348
- * @license lucide-react v0.468.0 - ISC
349
- *
350
- * This source code is licensed under the ISC license.
351
- * See the LICENSE file in the root directory of this source tree.
352
- */const sa=se("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
353
- * @license lucide-react v0.468.0 - ISC
354
- *
355
- * This source code is licensed under the ISC license.
356
- * See the LICENSE file in the root directory of this source tree.
357
- */const up=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"}]]);/**
358
- * @license lucide-react v0.468.0 - ISC
359
- *
360
- * This source code is licensed under the ISC license.
361
- * See the LICENSE file in the root directory of this source tree.
362
- */const pp=se("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/**
363
- * @license lucide-react v0.468.0 - ISC
364
- *
365
- * This source code is licensed under the ISC license.
366
- * See the LICENSE file in the root directory of this source tree.
367
- */const fp=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"}]]);/**
368
- * @license lucide-react v0.468.0 - ISC
369
- *
370
- * This source code is licensed under the ISC license.
371
- * See the LICENSE file in the root directory of this source tree.
372
- */const hp=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"}]]);/**
373
- * @license lucide-react v0.468.0 - ISC
374
- *
375
- * This source code is licensed under the ISC license.
376
- * See the LICENSE file in the root directory of this source tree.
377
- */const dl=se("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
378
- * @license lucide-react v0.468.0 - ISC
379
- *
380
- * This source code is licensed under the ISC license.
381
- * See the LICENSE file in the root directory of this source tree.
382
- */const ki=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"}]]);/**
383
- * @license lucide-react v0.468.0 - ISC
384
- *
385
- * This source code is licensed under the ISC license.
386
- * See the LICENSE file in the root directory of this source tree.
387
- */const Ts=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"}]]);/**
388
- * @license lucide-react v0.468.0 - ISC
389
- *
390
- * This source code is licensed under the ISC license.
391
- * See the LICENSE file in the root directory of this source tree.
392
- */const Gc=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"}]]);/**
393
- * @license lucide-react v0.468.0 - ISC
394
- *
395
- * This source code is licensed under the ISC license.
396
- * See the LICENSE file in the root directory of this source tree.
397
- */const gp=se("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
398
- * @license lucide-react v0.468.0 - ISC
399
- *
400
- * This source code is licensed under the ISC license.
401
- * See the LICENSE file in the root directory of this source tree.
402
- */const Kc=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"}]]);/**
403
- * @license lucide-react v0.468.0 - ISC
404
- *
405
- * This source code is licensed under the ISC license.
406
- * See the LICENSE file in the root directory of this source tree.
407
- */const mp=se("VolumeX",[["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"}],["line",{x1:"22",x2:"16",y1:"9",y2:"15",key:"1ewh16"}],["line",{x1:"16",x2:"22",y1:"9",y2:"15",key:"5ykzw1"}]]);/**
408
- * @license lucide-react v0.468.0 - ISC
409
- *
410
- * This source code is licensed under the ISC license.
411
- * See the LICENSE file in the root directory of this source tree.
412
- */const xp=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"}]]);/**
413
- * @license lucide-react v0.468.0 - ISC
414
- *
415
- * This source code is licensed under the ISC license.
416
- * See the LICENSE file in the root directory of this source tree.
417
- */const Qc=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"}]]);/**
418
- * @license lucide-react v0.468.0 - ISC
419
- *
420
- * This source code is licensed under the ISC license.
421
- * See the LICENSE file in the root directory of this source tree.
422
- */const Rr=se("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/**
423
- * @license lucide-react v0.468.0 - ISC
424
- *
425
- * This source code is licensed under the ISC license.
426
- * See the LICENSE file in the root directory of this source tree.
427
- */const Xc=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"}]]);/**
428
- * @license lucide-react v0.468.0 - ISC
429
- *
430
- * This source code is licensed under the ISC license.
431
- * See the LICENSE file in the root directory of this source tree.
432
- */const Yc=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 bp(t,n){if(Object.is(t,n))return!0;if(typeof t!="object"||t===null||typeof n!="object"||n===null)return!1;if(t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(const[s,i]of t)if(!Object.is(i,n.get(s)))return!1;return!0}if(t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(const s of t)if(!n.has(s))return!1;return!0}const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const s of r)if(!Object.prototype.hasOwnProperty.call(n,s)||!Object.is(t[s],n[s]))return!1;return!0}const{useRef:yp}=Eu;function vp(t){const n=yp();return r=>{const s=t(r);return bp(n.current,s)?n.current:n.current=s}}class wp{constructor(){this.origin=null}start(n){this.origin=n.length===1?{clientX:n[0].clientX,clientY:n[0].clientY}:null}reset(){this.origin=null}move(n,r){if(n.length!==1)return this.reset(),!1;if(!this.origin)return!1;const s=n[0].clientX-this.origin.clientX,i=n[0].clientY-this.origin.clientY;return i<48||Math.abs(s)>=i||r>240?!1:(this.reset(),!0)}}const Ni={completionEnabled:!0,soundEnabled:!0,notifyWhileForeground:!1};function ul(t,n){const r=Array.from(t.trim());return r.length<=n?r.join(""):`${r.slice(0,n-1).join("")}…`}function jp(t){return{completionEnabled:(t==null?void 0:t.completionEnabled)??Ni.completionEnabled,soundEnabled:(t==null?void 0:t.soundEnabled)??Ni.soundEnabled,notifyWhileForeground:(t==null?void 0:t.notifyWhileForeground)??Ni.notifyWhileForeground}}function kp(t,n){return!n.completionEnabled||t.outcome!=="completed"||t.stale||!t.sessionId||!t.runId?null:{notificationId:`${t.sessionId}:${t.runId}:completed`,sessionId:t.sessionId,runId:t.runId,title:ul(t.title,80)||"任务已完成",body:ul(t.finalText??"",160)||"运行已结束"}}const Sp="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",Cp="M75.91 73.628V62.232c0-.96.36-1.68 1.199-2.16l22.912-13.194c3.119-1.8 6.838-2.639 10.676-2.639 14.394 0 23.511 11.157 23.511 23.032 0 .839 0 1.799-.12 2.758l-23.752-13.914c-1.439-.84-2.879-.84-4.318 0L75.91 73.627Zm53.499 44.383v-27.23c0-1.68-.72-2.88-2.159-3.719L97.142 69.55l9.836-5.638c.839-.48 1.559-.48 2.399 0l22.912 13.195c6.598 3.839 11.035 11.995 11.035 19.912 0 9.116-5.397 17.513-13.915 20.992v.001Zm-60.577-23.99-9.836-5.758c-.84-.48-1.2-1.2-1.2-2.16v-26.39c0-12.834 9.837-22.55 23.152-22.55 5.039 0 9.716 1.679 13.676 4.678L70.993 55.516c-1.44.84-2.16 2.039-2.16 3.719v34.787-.002Zm21.173 12.234L75.91 98.339V81.546l14.095-7.917 14.094 7.917v16.793l-14.094 7.916Zm9.056 36.467c-5.038 0-9.716-1.68-13.675-4.678l23.631-13.676c1.439-.839 2.159-2.038 2.159-3.718V85.863l9.956 5.757c.84.48 1.2 1.2 1.2 2.16v26.389c0 12.835-9.957 22.552-23.27 22.552v.001Zm-28.43-26.75L47.72 102.778c-6.599-3.84-11.036-11.996-11.036-19.913 0-9.236 5.518-17.513 14.034-20.992v27.35c0 1.68.72 2.879 2.16 3.718l29.989 17.393-9.837 5.638c-.84.48-1.56.48-2.399 0Zm-1.318 19.673c-13.555 0-23.512-10.196-23.512-22.792 0-.959.12-1.919.24-2.879l23.63 13.675c1.44.84 2.88.84 4.32 0l30.108-17.392v11.395c0 .96-.361 1.68-1.2 2.16l-22.912 13.194c-3.119 1.8-6.837 2.639-10.675 2.639Zm29.748 14.274c14.515 0 26.63-10.316 29.39-23.991 13.434-3.479 22.071-16.074 22.071-28.91 0-8.396-3.598-16.553-10.076-22.43.6-2.52.96-5.039.96-7.557 0-17.153-13.915-29.99-29.989-29.99-3.239 0-6.358.48-9.477 1.56-5.398-5.278-12.835-8.637-20.992-8.637-14.515 0-26.63 10.316-29.39 23.991-13.434 3.48-22.07 16.074-22.07 28.91 0 8.396 3.598 16.553 10.075 22.431-.6 2.519-.96 5.038-.96 7.556 0 17.154 13.915 29.989 29.99 29.989 3.238 0 6.357-.479 9.476-1.559 5.397 5.278 12.835 8.637 20.992 8.637Z";function ia({agentType:t,size: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:Cp})}):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:Sp})}):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 pl=Promise.resolve(),Ip=0;function Jc(t,n=!1){const r=pl.then(async()=>{if(t.length>5e4)throw new Error("图表源码过长,请查看源码");const s=(await Mu(async()=>{const{default:o}=await import("./mermaid.core-DxK9Epxh.js").then(c=>c.cb);return{default:o}},__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 i=document.createElement("div");i.style.cssText="position:fixed;left:-100000px;top:0;visibility:hidden;pointer-events:none",document.body.appendChild(i);try{const{svg:o}=await s.render(`agentroam-mermaid-${++Ip}`,t,i);return o}finally{i.remove()}});return pl=r.catch(()=>{}),r}function Zc(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 Rp(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 fl(t,n){return Math.min(4,Math.max(Math.min(.1,n),t))}function Ep(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 Mp(t){const n=await Jc(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=Ep(Zc(n)),i=r.documentElement;i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.setAttribute("width",String(s.width)),i.setAttribute("height",String(s.height)),i.style.maxWidth="none",i.style.width=`${s.width}px`,i.style.height=`${s.height}px`;const o=URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(i)],{type:"image/svg+xml;charset=utf-8"}));try{const c=new Image;await new Promise((g,f)=>{c.onload=()=>g(),c.onerror=()=>f(new Error("图表图片转换失败,请重试。")),c.src=o});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((g,f)=>{d.toBlob(x=>x?g(x):f(new Error("图片导出失败,请重试。")),"image/png")})}finally{URL.revokeObjectURL(o)}}function hl({label:t,onClose:n,children:r}){const s=a.useRef(null);return a.useEffect(()=>{var c,d;const i=document.activeElement,o=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=o,i instanceof HTMLElement&&i.isConnected&&i.focus()}},[]),$n.createPortal(e.jsxs("div",{className:"mermaid-dialog","data-tab-swipe-ignore":!0,ref:s,role:"dialog","aria-modal":"true","aria-label":t,onKeyDown:i=>{var u;if(i.key==="Escape"&&(i.stopPropagation(),n()),i.key!=="Tab")return;const o=[...((u=s.current)==null?void 0:u.querySelectorAll('button:not(:disabled), a[href], [tabindex="0"]'))??[]],c=o[0],d=o[o.length-1];i.shiftKey&&document.activeElement===c?(i.preventDefault(),d==null||d.focus()):!i.shiftKey&&document.activeElement===d&&(i.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(Rr,{size:20})})]}),r]}),document.body)}function Ap({svg:t,fullscreen:n,onFullscreen:r,onExport:s,exporting:i}){const o=a.useMemo(()=>Zc(t),[t]),c=a.useRef(null),[d,u]=a.useState(o),[g,f]=a.useState(null),x=Rp(o,d.width,n?d.height:void 0),y=g===null?x:fl(g,x),v=a.useRef(y);v.current=y;const S=a.useRef(!1),E=a.useRef(null);a.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 k=new ResizeObserver(j);return k.observe(I),()=>k.disconnect()},[]);const C=a.useCallback((I,j)=>{const k=c.current;if(!k)return;const W=fl(I,x),ee=W/v.current,N=j??{x:k.clientWidth/2,y:k.clientHeight/2},T=(k.scrollLeft+N.x)*ee-N.x,A=(k.scrollTop+N.y)*ee-N.y;v.current=W,f(W),requestAnimationFrame(()=>{k.scrollLeft=T,k.scrollTop=A})},[x]);return a.useEffect(()=>{const I=c.current;if(!I)return;let j=null;const k=A=>Math.hypot(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY),W=A=>{S.current=!1,A.touches.length===2&&(j={distance:Math.max(1,k(A.touches)),scale:v.current},S.current=!0)},ee=A=>{if(S.current=!0,!j||A.touches.length!==2)return;A.preventDefault();const R=I.getBoundingClientRect();C(j.scale*k(A.touches)/j.distance,{x:(A.touches[0].clientX+A.touches[1].clientX)/2-R.left,y:(A.touches[0].clientY+A.touches[1].clientY)/2-R.top})},N=()=>{j=null},T=A=>{if(!A.ctrlKey&&!A.metaKey)return;A.preventDefault();const R=I.getBoundingClientRect();C(v.current*Math.exp(-A.deltaY*.01),{x:A.clientX-R.left,y:A.clientY-R.top})};return I.addEventListener("touchstart",W,{passive:!0}),I.addEventListener("touchmove",ee,{passive:!1}),I.addEventListener("touchend",N),I.addEventListener("touchcancel",N),I.addEventListener("wheel",T,{passive:!1}),()=>{I.removeEventListener("touchstart",W),I.removeEventListener("touchmove",ee),I.removeEventListener("touchend",N),I.removeEventListener("touchcancel",N),I.removeEventListener("wheel",T)}},[C]),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:y<=Math.min(.1,x),onClick:()=>C(y/1.25),children:e.jsx(Yc,{size:18})}),e.jsxs("span",{className:"mermaid-zoom-value","aria-label":"缩放比例",children:[Math.round(y*100),"%"]}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"放大图表",title:"放大",disabled:y>=4,onClick:()=>C(y*1.25),children:e.jsx(Xc,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"自适应图表",title:"自适应",onClick:()=>{var I;f(null),(I=c.current)==null||I.scrollTo(0,0)},children:e.jsx(ra,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":n?"退出图表全屏":"全屏查看图表",title:n?"退出全屏":"全屏",onClick:r,children:n?e.jsx(tp,{size:18}):e.jsx(Ju,{size:18})}),e.jsx("button",{type:"button",className:"mermaid-control","aria-label":"导出图表 PNG",title:"导出 PNG",disabled:i,onClick:s,children:e.jsx(ta,{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;S.current=!1,E.current={x:I.clientX,y:I.clientY,left:j.scrollLeft,top:j.scrollTop}},onPointerMove:I=>{const j=E.current;j&&(Math.hypot(I.clientX-j.x,I.clientY-j.y)>4&&(S.current||I.currentTarget.setPointerCapture(I.pointerId),S.current=!0),I.currentTarget.scrollLeft=j.left-(I.clientX-j.x),I.currentTarget.scrollTop=j.top-(I.clientY-j.y))},onPointerUp:()=>{E.current=null},onPointerCancel:()=>{E.current=null},children:e.jsx("div",{className:"mermaid-diagram-canvas",style:{width:o.width*y,height:o.height*y},role:n?"img":"button","aria-label":n?"Mermaid 图表":"点击全屏查看 Mermaid 图表",tabIndex:n?void 0:0,onClick:()=>{!n&&!S.current&&r()},onKeyDown:I=>{!n&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),r())},dangerouslySetInnerHTML:{__html:t}})}),e.jsx("div",{className:"mermaid-viewer-hint",children:i?"正在生成完整 PNG…":n?"双指缩放 · 滑动查看 · 导出完整图片":"点击图表全屏 · 双指缩放"})]})}function Tp({code:t,svg:n}){const r=a.useRef(null),[s,i]=a.useState(!1),[o,c]=a.useState(!1),[d,u]=a.useState(null),[g,f]=a.useState(null),x=a.useRef(0),y=a.useCallback(()=>{i(!1),requestAnimationFrame(()=>{var C,I;return(I=(C=r.current)==null?void 0:C.querySelector('button[aria-label="全屏查看图表"]'))==null?void 0:I.focus()})},[]),v=a.useCallback(()=>u(null),[]);a.useEffect(()=>()=>{x.current++},[t]),a.useEffect(()=>()=>{d&&URL.revokeObjectURL(d)},[d]);const S=async()=>{if(o)return;const C=x.current;c(!0),f(null);try{const I=await Mp(t);C===x.current&&u(URL.createObjectURL(I))}catch(I){C===x.current&&f(I instanceof Error?I.message:"图片导出失败,请重试。")}finally{C===x.current&&c(!1)}},E=e.jsx(Ap,{svg:n,fullscreen:s,onFullscreen:()=>s?y():i(!0),onExport:()=>void S(),exporting:o});return e.jsxs("div",{className:"mermaid-diagram","data-tab-swipe-ignore":!0,ref:r,children:[s?e.jsxs(hl,{label:"图表全屏",onClose:y,children:[E,g&&e.jsx("div",{className:"mermaid-block-status",role:"alert",children:g})]}):E,!s&&g&&e.jsx("div",{className:"mermaid-block-status",role:"alert",children:g}),d&&e.jsxs(hl,{label:"导出图表图片",onClose:v,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 Np({code:t,complete:n}){const[r,s]=a.useState(!1),[i,o]=a.useState(null),c=n&&(i==null?void 0:i.code)===t?i:null;a.useEffect(()=>{if(!n||!t.trim())return;let u=!1;const g=setTimeout(()=>{Jc(t).then(f=>{u||o({code:t,svg:f})},()=>{u||o({code:t,error:"图表暂时无法渲染,请查看源码。"})})},150);return()=>{u=!0,clearTimeout(g)}},[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(Tp,{code:t,svg:c.svg},t)]})}function _p(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 _i(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 _p(t)}const ed=2e5,zp=24,Lp=12,Pp=80,Dp=30,Wp=500,Bp=160,Fp=1e3,Pi=200,Op={"/help":"使用帮助","/whoami":"关于我","/works":"项目与作品","/jobs":"求职信息","/timeline":"经历时间线","/contact":"联系方式"};function Uo(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function os(t,n){if(typeof t!="string")return;const r=t.trim();return r?r.slice(0,n):void 0}function gl(t,n,r){return Array.isArray(t)?t.slice(0,n).filter(s=>typeof s=="string").map(s=>s.trim().slice(0,r)).filter(Boolean):[]}function $p(t){if(Uo(t)){const n=os(t.type,Pi)??"unknown";if(n==="text"){const r=os(t.text,ed);if(r){const s=os(t.tone,Pi);return{kind:"text",text:r,...s?{tone:s}:{}}}}return{kind:"unknown",blockType:n,value:t}}return{kind:"unknown",blockType:"unknown",value:t}}function Up(t){if(typeof t.schemaVersion!="number"||!Number.isFinite(t.schemaVersion))return null;const n=os(t.title,Bp);if(!n||!Array.isArray(t.blocks))return null;const r=os(t.skill,Pi),s=os(t.summary,Fp),i=os(t.generatedAt,Pi);return{schemaVersion:t.schemaVersion,title:n,...r?{skill:r}:{},...s?{summary:s}:{},...i?{generatedAt:i}:{},blocks:t.blocks.slice(0,zp).map($p),suggestions:gl(t.suggestions,Lp,Pp),sources:gl(t.sources,Dp,Wp),original:t}}function Hp(t,n=!0){const r=t.trim();if(!n||r.length===0||r.length>ed||r.startsWith("```"))return null;let s;try{s=JSON.parse(r)}catch{return null}if(!Uo(s)&&!Array.isArray(s))return null;if(Uo(s)){const i=Up(s);if(i)return{kind:"envelope",raw:r,value:i}}return{kind:"json",raw:r,value:s}}function ml(t){const n=t.trim(),r=Op[n.toLowerCase()];if(r)return r;const s=n.match(/^\/project\s+([a-z0-9-]+)$/i);return s?`查看项目:${s[1]}`:n}const qp=40,xl=8;function Vp(t){return Array.isArray(t)?t.map((n,r)=>[String(r),n]):Object.entries(t)}function Gp({value:t}){return t===null?e.jsx("span",{className:"json-tree__value json-tree__value--null",children:"null"}):typeof t=="boolean"?e.jsx("span",{className:"json-tree__value json-tree__value--boolean",children:String(t)}):typeof t=="number"?e.jsx("span",{className:"json-tree__value json-tree__value--number",children:t}):e.jsxs("span",{className:"json-tree__value json-tree__value--string",children:[e.jsx("span",{"aria-hidden":"true",children:'"'}),t,e.jsx("span",{"aria-hidden":"true",children:'"'})]})}function oa({value:t,label:n,depth:r=0}){const[s,i]=a.useState(!1);if(t===null||typeof t!="object")return e.jsxs("div",{className:"json-tree__row",children:[n!==void 0&&e.jsx("span",{className:"json-tree__key",children:n}),n!==void 0&&e.jsx("span",{className:"json-tree__separator",children:":"}),e.jsx(Gp,{value:t})]});const o=Vp(t),c=Array.isArray(t)?`数组 · ${o.length} 项`:`对象 · ${o.length} 项`;if(r>=xl)return e.jsxs("div",{className:"json-tree__row json-tree__row--limit",children:[n!==void 0&&e.jsx("span",{className:"json-tree__key",children:n}),e.jsxs("span",{className:"json-tree__limit",children:[c,",已折叠至深度 ",xl]})]});const d=s?o:o.slice(0,qp),u=o.length-d.length;return e.jsxs("details",{className:"json-tree",open:r===0,children:[e.jsxs("summary",{className:"json-tree__summary",children:[n!==void 0&&e.jsx("span",{className:"json-tree__key",children:n}),e.jsx("span",{className:"json-tree__container-label",children:c})]}),e.jsxs("div",{className:"json-tree__children",children:[o.length===0&&e.jsx("div",{className:"json-tree__empty",children:"空"}),d.map(([g,f])=>e.jsx(oa,{value:f,label:g,depth:r+1},g)),u>0&&e.jsxs("button",{type:"button",className:"json-tree__more",onClick:()=>i(!0),children:["显示其余 ",u," 项"]})]})]})}function Kp(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}function td({raw:t,onCopyFailed:n}){const r=async()=>{await _i(t)||n==null||n()};return e.jsxs("details",{className:"structured-agent-message__raw",children:[e.jsx("summary",{children:"查看原始 JSON"}),e.jsx("div",{className:"structured-agent-message__raw-toolbar",children:e.jsx("button",{type:"button",title:"复制原始 JSON","aria-label":"复制原始 JSON",onClick:()=>{r()},children:e.jsx(Ti,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})}),e.jsx("pre",{children:Kp(t)})]})}function Qp({envelope:t,raw:n,renderText:r,suggestionsEnabled:s,onSuggestionSend:i,onCopyFailed:o}){return e.jsxs("section",{className:"structured-agent-message","data-kind":"envelope",children:[e.jsxs("header",{className:"structured-agent-message__header",children:[e.jsx("h3",{className:"structured-agent-message__title",children:t.title}),t.summary&&e.jsx("p",{className:"structured-agent-message__summary",children:t.summary})]}),e.jsx("div",{className:"structured-agent-message__blocks",children:t.blocks.map((c,d)=>c.kind==="text"?e.jsx("div",{className:"structured-agent-message__text","data-tone":c.tone??"body",children:r(c.text)},d):e.jsxs("details",{className:"structured-agent-message__unknown-block",children:[e.jsxs("summary",{children:[c.blockType," 内容"]}),e.jsx(oa,{value:c.value})]},d))}),t.suggestions.length>0&&e.jsx("div",{className:"structured-agent-message__suggestions","aria-label":"继续提问",children:t.suggestions.map(c=>e.jsx("button",{type:"button",className:"structured-agent-suggestion",disabled:!s,title:`发送 ${c}`,"aria-label":`${ml(c)},发送 ${c}`,onClick:()=>i(c),children:ml(c)},c))}),t.sources.length>0&&e.jsxs("details",{className:"structured-agent-message__details",children:[e.jsxs("summary",{children:["参考来源 ",t.sources.length]}),e.jsx("ul",{children:t.sources.map(c=>e.jsx("li",{children:c},c))})]}),e.jsxs("details",{className:"structured-agent-message__details",children:[e.jsx("summary",{children:"消息信息"}),e.jsxs("dl",{children:[e.jsxs("div",{children:[e.jsx("dt",{children:"格式版本"}),e.jsx("dd",{children:t.schemaVersion})]}),t.skill&&e.jsxs("div",{children:[e.jsx("dt",{children:"能力"}),e.jsx("dd",{children:t.skill})]}),t.generatedAt&&e.jsxs("div",{children:[e.jsx("dt",{children:"生成时间"}),e.jsx("dd",{children:t.generatedAt})]})]})]}),e.jsx(td,{raw:n,onCopyFailed:o})]})}function Xp({message:t,renderText:n,suggestionsEnabled:r,onSuggestionSend:s,onCopyFailed:i}){return t.kind==="envelope"?e.jsx(Qp,{envelope:t.value,raw:t.raw,renderText:n,suggestionsEnabled:r,onSuggestionSend:s,onCopyFailed:i}):e.jsxs("section",{className:"structured-agent-message","data-kind":"json",children:[e.jsxs("div",{className:"structured-agent-message__data-title",children:[e.jsx(Bu,{size:15,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:"结构化数据"})]}),e.jsx(oa,{value:t.value}),e.jsx(td,{raw:t.raw,onCopyFailed:i})]})}function Yp({text:t,complete:n,renderText:r,suggestionsEnabled:s,onSuggestionSend:i,onCopyFailed:o}){const c=a.useMemo(()=>Hp(t,n),[n,t]);return c?e.jsx(Xp,{message:c,renderText:r,suggestionsEnabled:s,onSuggestionSend:i,onCopyFailed:o}):e.jsx(e.Fragment,{children:r(t)})}const nd="webapp.nativeAgentRunPrefs.v1",Jp=["codex","claude-code","opencode"];function rd(){try{const t=JSON.parse(localStorage.getItem(nd)??"{}");return t&&typeof t=="object"?t:{}}catch{return{}}}function Di(t){return Jp.includes(t)}function bl(t){return Di(t)?rd()[t]??{}:{}}function yl(t,n){if(!Di(t))return;const r=rd();r[t]=n;try{localStorage.setItem(nd,JSON.stringify(r))}catch{}}function Zp(t,n,r){var s;return!r||!((s=t.model)!=null&&s.id)||n.has(si(t.model))?t:{}}function si(t){return t.providerID?`${t.providerID}/${t.id}`:t.id}function ef(t){const n=t.indexOf("/");return n>0?{providerID:t.slice(0,n),id:t.slice(n+1)}:{id:t}}function tf(t){var r,s;const n=new Map;for(const i of t){const o=(r=i.providerID)==null?void 0:r.trim(),c=((s=i.providerDisplayName)==null?void 0:s.trim())||o||"其他供应商",d=o||"__other__",u=n.get(d)??{key:d,label:o==="opencode-go"?`${c}(需订阅)`:c,models:[]};u.models.push({...i,optionLabel:i.displayName||i.id}),n.set(d,u)}return[...n.values()]}const sd="context-compaction";function Wi(t,n){const r=t??[],s=r.findIndex(o=>o.itemId===n.itemId&&o.sectionIndex===n.sectionIndex);return(s<0?[...r,{itemId:n.itemId,sectionIndex:n.sectionIndex,text:n.delta}]:r.map((o,c)=>c===s?{...o,text:o.text+n.delta}:o)).sort((o,c)=>o.sectionIndex-c.sectionIndex)}function vl(t){let n=[];for(const r of t)if(r.type==="runtime_progress"){const{type:s,...i}=r;n=id(n,i)}else r.type==="context_usage"?n=n.filter(s=>s.progressId!==sd):(r.type==="done"||r.type==="turn_aborted"||r.type==="error")&&(n=[]);return n}function id(t,n){const r=t.findIndex(s=>s.progressId===n.progressId);return r<0?[...t,n]:t.map((s,i)=>i===r?n:s)}function od(t,n){return[...t].reverse().find(r=>r.toolCallId===n)}function nf(t){return[...t].reverse().find(n=>!n.toolCallId)}function rf(t,n){var i,o;const r=[],s=new Map;for(let c=0;c<t.length;c+=1){const d=t[c];r.push(d);const u=d.role==="user"?(i=d.presentation)==null?void 0:i.executionTrace:void 0,g=u==null?void 0:u.turnId;if(!g)continue;const f=u.segmentIndex??s.get(g)??0;s.set(g,Math.max(s.get(g)??0,f+1));const x=t[c+1];((o=x==null?void 0:x.executionTrace)==null?void 0:o.turnId)===g&&(x.executionTrace.segmentIndex??0)===f?(r.push({...x,executionTrace:{...x.executionTrace,turnId:g,revision:n,segmentIndex:f}}),c+=1):r.push({id:ld(g,f),role:"assistant",content:"",executionTrace:{turnId:g,revision:n,segmentIndex:f},timestamp:d.timestamp})}return r}function sf(t){var n,r,s,i;return t.role==="assistant"&&!!((n=t.toolCalls)!=null&&n.length||(s=(r=t.presentation)==null?void 0:r.reasoning)!=null&&s.length||((i=t.presentation)==null?void 0:i.agentMessagePhase)==="commentary")}function ad(t,n,r,s){return t.map(i=>{var o;return(o=i.toolCalls)!=null&&o.some(c=>c.id===n)?{...i,toolCalls:i.toolCalls.map(c=>c.id===n?{...c,result:r,isError:s}:c)}:i})}function of(t,n,r,s){if(n.type==="text_chunk"){if(!n.text||n.messagePhase!=="commentary")return[...t];const i=n.itemId?`codex-trace:${s}:agent:${n.itemId}`:`codex-live-commentary:${s}`,o=t.findIndex(c=>c.id===i);return o<0?[...t,{id:i,role:"assistant",content:n.text,presentation:{agentMessagePhase:"commentary"},timestamp:r}]:t.map((c,d)=>d===o?{...c,content:c.content+n.text}:c)}if(n.type==="reasoning_summary_delta"){const i=t.findIndex(o=>{var c,d;return(d=(c=o.presentation)==null?void 0:c.reasoning)==null?void 0:d.some(u=>u.itemId===n.itemId)});return i<0?[...t,{id:`codex-live-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:Wi(void 0,n)},timestamp:r}]:t.map((o,c)=>{var d;return c===i?{...o,presentation:{...o.presentation,reasoning:Wi((d=o.presentation)==null?void 0:d.reasoning,n)}}:o})}if(n.type==="tool_call"){const i=t.findIndex(o=>{var c;return(c=o.toolCalls)==null?void 0:c.some(d=>d.id===n.toolCall.id)});return i>=0?t.map((o,c)=>{var d;return c===i?{...o,toolCalls:(d=o.toolCalls)==null?void 0:d.map(u=>u.id===n.toolCall.id?{...u,name:n.toolCall.name,arguments:n.toolCall.arguments}:u)}:o}):[...t,{id:`codex-live-tool:${n.toolCall.id}`,role:"assistant",content:"",toolCalls:[{...n.toolCall}],timestamp:r}]}return t.some(i=>{var o;return(o=i.toolCalls)==null?void 0:o.some(c=>c.id===n.result.toolCallId)})?ad(t,n.result.toolCallId,n.result.content,n.result.isError):[...t]}function Ho(t,n,r,s=Date.now()){var v,S;const i=t.findLastIndex(E=>{var C;return((C=E.executionTrace)==null?void 0:C.turnId)===n&&af(E.executionTrace.liveMessages??[],r)}),o=t.findLastIndex(E=>{var C;return((C=E.executionTrace)==null?void 0:C.turnId)===n}),c=t.findLastIndex(E=>E.role==="user"&&!E.isQueued),d=i>=0?i:o>c||o>=0&&!((v=t[c])!=null&&v.isSteered)?o:-1,u=d>=0?((S=t[d].executionTrace)==null?void 0:S.liveMessages)??[]:[],g=of(u,r,s,n);if(g.length===0&&u.length===0)return[...t];if(d>=0)return t.map((E,C)=>C===d?{...E,executionTrace:{...E.executionTrace,liveMessages:g}}:E);if(g===u)return[...t];const f=c;if(f<0)return[...t];const x=t.reduce((E,C)=>{var I;return((I=C.executionTrace)==null?void 0:I.turnId)===n?Math.max(E,C.executionTrace.segmentIndex??0):E},-1)+1,y={id:ld(n,x),role:"assistant",content:"",executionTrace:{turnId:n,revision:`live:${n}`,segmentIndex:x,liveMessages:g},timestamp:s};return[...t.slice(0,f+1),y,...t.slice(f+1)]}function ld(t,n){return n===0?`codex-execution-trace:${t}`:`codex-execution-trace:${t}:${n}`}function af(t,n){if(n.type==="text_chunk")return n.itemId?t.some(s=>s.id===`codex-trace:${n.turnId}:agent:${n.itemId}`):!1;if(n.type==="reasoning_summary_delta")return t.some(s=>{var i,o;return(o=(i=s.presentation)==null?void 0:i.reasoning)==null?void 0:o.some(c=>c.itemId===n.itemId)});const r=n.type==="tool_call"?n.toolCall.id:n.result.toolCallId;return t.some(s=>{var i;return(i=s.toolCalls)==null?void 0:i.some(o=>o.id===r)})}function lf(t,n){return t.some(s=>{var i,o;return((o=(i=s.presentation)==null?void 0:i.executionTrace)==null?void 0:o.segmentIndex)!==void 0})?t.filter(s=>{var i,o;return((o=(i=s.presentation)==null?void 0:i.executionTrace)==null?void 0:o.segmentIndex)===n}):n===0?[...t]:[]}function qo(t,n){const r=new Map(t.map(s=>[`${s.itemId}:${s.sectionIndex}`,s]));for(const s of n){const i=`${s.itemId}:${s.sectionIndex}`,o=r.get(i),c=o?s.text.startsWith(o.text)?s.text:o.text.startsWith(s.text)?o.text:s.text:s.text;r.set(i,{...s,text:c})}return[...r.values()]}function wl(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 cf(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 df(t){var o,c,d,u,g,f,x,y,v,S,E;const n=[],r=new Map,s=new Map,i=new Map;for(const C of t){if(((o=C.presentation)==null?void 0:o.agentMessagePhase)==="commentary"){const N=r.get(C.id);if(N!==void 0){const T=n[N],A=C.content.startsWith(T.content)?C.content:T.content.startsWith(C.content)?T.content:C.content;n[N]={...T,...C,id:T.id,content:A};continue}}const I={...C,toolCalls:C.toolCalls?[]:void 0,presentation:(c=C.presentation)!=null&&c.reasoning?{...C.presentation,reasoning:[]}:C.presentation};for(const N of((d=C.presentation)==null?void 0:d.reasoning)??[]){const T=`${N.itemId}:${N.sectionIndex}`,A=s.get(T);if(A){const R=n[A.messageIndex],L=[...((u=R.presentation)==null?void 0:u.reasoning)??[]],H=L[A.sectionIndex];L[A.sectionIndex]=qo([H],[N])[0],n[A.messageIndex]={...R,presentation:{...R.presentation,reasoning:L}}}else{const R=I.presentation.reasoning.findIndex(L=>L.itemId===N.itemId&&L.sectionIndex===N.sectionIndex);R>=0?I.presentation.reasoning[R]=qo([I.presentation.reasoning[R]],[N])[0]:I.presentation.reasoning.push(N)}}for(const N of C.toolCalls??[]){const T=i.get(N.id);if(T){const A=n[T.messageIndex],R=[...A.toolCalls??[]];R[T.toolIndex]={...R[T.toolIndex],...N},n[T.messageIndex]={...A,toolCalls:R}}else{const A=I.toolCalls.findIndex(R=>R.id===N.id);A>=0?I.toolCalls[A]={...I.toolCalls[A],...N}:I.toolCalls.push(N)}}const j=((g=I.presentation)==null?void 0:g.agentMessagePhase)==="commentary",k=!!((x=(f=I.presentation)==null?void 0:f.reasoning)!=null&&x.length),W=!!((y=I.toolCalls)!=null&&y.length);if(!j&&!k&&!W)continue;const ee=n.length;n.push(I),j&&r.set(I.id,ee);for(let N=0;N<(((S=(v=I.presentation)==null?void 0:v.reasoning)==null?void 0:S.length)??0);N+=1){const T=I.presentation.reasoning[N];s.set(`${T.itemId}:${T.sectionIndex}`,{messageIndex:ee,sectionIndex:N})}for(let N=0;N<(((E=I.toolCalls)==null?void 0:E.length)??0);N+=1)i.set(I.toolCalls[N].id,{messageIndex:ee,toolIndex:N})}return n}function uf(t,n,r){if(t.length<2)return t;const s=new Map;t.forEach((C,I)=>{for(const j of wl(C))s.set(j,I)});const i=C=>{for(const I of wl(C)){const j=s.get(I);if(j!==void 0)return j}return t.findIndex(I=>cf(I,C))},o=C=>{const I=[];for(const j of C){const k=i(j);k<0||I.at(-1)===k||I.push(k)}return I},c=o(n),d=o(r),u=Array.from({length:t.length},()=>new Set),g=Array.from({length:t.length},()=>0),f=C=>{for(let I=1;I<C.length;I+=1){const j=C[I-1],k=C[I];j===k||u[j].has(k)||(u[j].add(k),g[k]+=1)}};f(c),f(d);const x=new Map(c.map((C,I)=>[C,I])),y=new Map(d.map((C,I)=>[C,I])),v=(C,I)=>{const j=x.get(C)??Number.POSITIVE_INFINITY,k=x.get(I)??Number.POSITIVE_INFINITY;if(j!==k)return j-k;const W=y.get(C)??Number.POSITIVE_INFINITY,ee=y.get(I)??Number.POSITIVE_INFINITY;return W!==ee?W-ee:C-I},S=g.flatMap((C,I)=>C===0?[I]:[]).sort(v),E=[];for(;S.length>0;){const C=S.shift();E.push(t[C]);for(const I of u[C])g[I]-=1,g[I]===0&&(S.push(I),S.sort(v))}return E.length===t.length?E:t}function pf(t,n){var s,i,o,c,d;const r=t.map(u=>{var g,f;return{...u,toolCalls:(g=u.toolCalls)==null?void 0:g.map(x=>({...x})),presentation:(f=u.presentation)!=null&&f.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 f=r.findIndex(x=>{var y;return x.id===u.id||((y=x.presentation)==null?void 0:y.agentMessagePhase)==="commentary"&&(x.id.startsWith("codex-live-commentary:")||u.id.startsWith("codex-live-commentary:"))&&(u.content.startsWith(x.content)||x.content.startsWith(u.content))});if(f<0)r.push(u);else{const x=r[f],y=u.content.startsWith(x.content)?u.content:x.content.startsWith(u.content)?x.content:u.content;r[f]={...x,content:y,presentation:{...x.presentation,agentMessagePhase:"commentary"}}}continue}const g=(i=u.presentation)==null?void 0:i.reasoning;if(g!=null&&g.length){const f=r.findIndex(x=>{var y,v;return(v=(y=x.presentation)==null?void 0:y.reasoning)==null?void 0:v.some(S=>g.some(E=>E.itemId===S.itemId))});if(f>=0){const x=r[f];r[f]={...x,presentation:{...x.presentation,reasoning:qo(((o=x.presentation)==null?void 0:o.reasoning)??[],g)}}}else r.push(u)}for(const f of u.toolCalls??[]){const x=r.findIndex(y=>{var v;return(v=y.toolCalls)==null?void 0:v.some(S=>S.id===f.id)});if(x>=0){const y=r[x];r[x]={...y,toolCalls:(c=y.toolCalls)==null?void 0:c.map(v=>v.id===f.id?{...v,...f}:v)}}else r.push({...u,id:(((d=u.toolCalls)==null?void 0:d.length)??0)>1?`${u.id}:tool:${f.id}`:u.id,presentation:void 0,toolCalls:[f]})}}return uf(df(r),t,n)}function jl(t){for(let n=t.length-1;n>=0;n--)if(t[n].type==="context_usage"&&t[n].usage)return t[n].usage}function kl(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 ff(t,n,r,s){return s!==void 0&&s!==r?s?n[s]??[]:[]:t}function cd(t){var n;return!!(t&&t.role==="assistant"&&!((n=t.toolCalls)!=null&&n.length)&&!t.widget&&!t.askUser&&!t.isCompactionSummary&&!t.executionTrace)}function Sl(t,n){var r;if(n.role==="assistant"&&((r=n.toolCalls)!=null&&r.length)){const s=t[t.length-1];if(cd(s))return[...t.slice(0,-1),{...s,content:s.content,toolCalls:n.toolCalls}]}return[...t,n]}function hf(t,n){if(!n)return t;const r=t[t.length-1];if(cd(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 Cl(t,n,r,s){return t.map(i=>{if(!i.toolCalls)return i;const o=i.toolCalls.map(c=>c.id===n?{...c,result:r,isError:s}:c);return{...i,toolCalls:o}})}function Il(t,n,r,s){return t.map(i=>{if(!i.toolCalls)return i;const o=i.toolCalls.map(c=>c.name==="dispatch_agent"&&c.arguments.subSessionId===n?{...c,arguments:{...c.arguments,subAgentStatus:r,subAgentDetail:s}}:c);return{...i,toolCalls:o}})}function Rl(t,n,r){return t.map(s=>{if(!s.toolCalls)return s;const i=s.toolCalls.map(o=>o.name==="dispatch_agent"&&o.arguments.subSessionId===n?{...o,arguments:{...o.arguments,subAgentProgress:(o.arguments.subAgentProgress?o.arguments.subAgentProgress+`
433
- `+r:r).split(`
434
- `).slice(-30).join(`
435
- `)}}:o);return{...s,toolCalls:i}})}function El(t,n,r){return t.map(s=>s.id===n?r(s):s)}function Ml(t,n){const r=t.findIndex(s=>{var i,o;return(o=(i=s.presentation)==null?void 0:i.reasoning)==null?void 0:o.some(c=>c.itemId===n.itemId)});return r<0?[...t,{id:`native-reasoning:${n.itemId}`,role:"assistant",content:"",presentation:{reasoning:Wi(void 0,n)},timestamp:Date.now()}]:t.map((s,i)=>{var o;return i===r?{...s,presentation:{...s.presentation,reasoning:Wi((o=s.presentation)==null?void 0:o.reasoning,n)}}:s})}const et=Nc((t,n)=>({messages:[],messagesBySession:{},contextUsageBySession:{},runtimeProgressBySession:{},nativeSubagentsBySession:{},runningSessionId:null,currentText:"",sessionId:null,todos:[],cronTasks:[],addMessage:(r,s)=>t(i=>{const o=s??i.sessionId??void 0,c=o&&o!==i.sessionId?i.messages:Sl(i.messages,r),d=o?{...i.messagesBySession,[o]:Sl(i.messagesBySession[o]??(o===i.sessionId?i.messages:[]),r)}:i.messagesBySession;return{messages:c,messagesBySession:d,currentText:o&&o!==i.sessionId?i.currentText:""}}),appendText:(r,s)=>t(i=>{if(!r)return i;const o=s??i.sessionId??void 0,c=!o||o===i.sessionId,d=hf(c?i.messages:i.messagesBySession[o]??[],r),u=o?{...i.messagesBySession,[o]:d}:i.messagesBySession;return{messages:c?d:i.messages,messagesBySession:u,currentText:o&&o!==i.sessionId?i.currentText:i.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,i,o)=>t(c=>{const d=o??c.sessionId??void 0,u=d&&d!==c.sessionId?c.messages:Cl(c.messages,r,s,i),g=d?{...c.messagesBySession,[d]:Cl(c.messagesBySession[d]??(d===c.sessionId?c.messages:[]),r,s,i)}:c.messagesBySession;return{messages:u,messagesBySession:g}}),setMessages:(r,s)=>t(i=>{const o=s??i.sessionId??void 0,c=!o||o===i.sessionId;return{messages:c?r:i.messages,messagesBySession:o?{...i.messagesBySession,[o]:r}:i.messagesBySession,currentText:c?"":i.currentText}}),getMessagesForSession:r=>n().messagesBySession[r]??[],setContextUsage:(r,s)=>t(i=>{const o=s??i.sessionId??void 0;return o?{contextUsageBySession:{...i.contextUsageBySession,[o]:r}}:i}),getContextUsageForSession:r=>n().contextUsageBySession[r],applyRuntimeProgress:(r,s)=>t(i=>{const o=s??i.sessionId??void 0;return o?{runtimeProgressBySession:{...i.runtimeProgressBySession,[o]:id(i.runtimeProgressBySession[o]??[],r)}}:i}),setRuntimeProgress:(r,s)=>t(i=>{const o=s??i.sessionId??void 0;return o?{runtimeProgressBySession:{...i.runtimeProgressBySession,[o]:r}}:i}),clearRuntimeProgress:r=>t(s=>{var d;const i=r??s.sessionId??void 0;if(!i||!((d=s.runtimeProgressBySession[i])!=null&&d.length))return s;const{[i]:o,...c}=s.runtimeProgressBySession;return{runtimeProgressBySession:c}}),applyNativeSubagentActivity:(r,s)=>t(i=>{const o=s??i.sessionId??void 0;return o?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[o]:{...i.nativeSubagentsBySession[o]??{},[r.parentToolCallId]:r}}}:i}),setNativeSubagentActivities:(r,s)=>t(i=>{const o=s??i.sessionId??void 0;return o?{nativeSubagentsBySession:{...i.nativeSubagentsBySession,[o]:Object.fromEntries(r.map(c=>[c.parentToolCallId,c]))}}:i}),applyReasoningSummary:(r,s)=>t(i=>{const o=s??i.sessionId??void 0,c=o&&o!==i.sessionId?i.messages:Ml(i.messages,r),d=o?{...i.messagesBySession,[o]:Ml(i.messagesBySession[o]??(o===i.sessionId?i.messages:[]),r)}:i.messagesBySession;return{messages:c,messagesBySession:d}}),applyCodexExecutionEvent:(r,s,i)=>t(o=>{const c=i??o.sessionId??void 0,d=Date.now(),u=c&&c!==o.sessionId?o.messages:Ho(o.messages,r,s,d),g=c?{...o.messagesBySession,[c]:Ho(o.messagesBySession[c]??(c===o.sessionId?o.messages:[]),r,s,d)}:o.messagesBySession;return{messages:u,messagesBySession:g}}),updateMessage:(r,s,i)=>t(o=>{const c=i??o.sessionId??void 0,d=c&&c!==o.sessionId?o.messages:El(o.messages,r,s),u=c?{...o.messagesBySession,[c]:El(o.messagesBySession[c]??(c===o.sessionId?o.messages:[]),r,s)}:o.messagesBySession;return{messages:d,messagesBySession:u}}),updateSubAgentStatus:(r,s,i,o)=>t(c=>{const d=o??c.sessionId??void 0,u=d&&d!==c.sessionId?c.messages:Il(c.messages,r,s,i),g=d?{...c.messagesBySession,[d]:Il(c.messagesBySession[d]??(d===c.sessionId?c.messages:[]),r,s,i)}:c.messagesBySession;return{messages:u,messagesBySession:g}}),updateSubAgentProgress:(r,s,i)=>t(o=>{const c=i??o.sessionId??void 0,d=c&&c!==o.sessionId?o.messages:Rl(o.messages,r,s),u=c?{...o.messagesBySession,[c]:Rl(o.messagesBySession[c]??(c===o.sessionId?o.messages:[]),r,s)}:o.messagesBySession;return{messages:d,messagesBySession:u}}),clearMessages:r=>t(s=>{const i=r??s.sessionId??void 0;if(!i)return{messages:[],currentText:""};const{[i]:o,...c}=s.messagesBySession,{[i]:d,...u}=s.contextUsageBySession,{[i]:g,...f}=s.runtimeProgressBySession,{[i]:x,...y}=s.nativeSubagentsBySession;return{messages:i===s.sessionId?[]:s.messages,messagesBySession:c,contextUsageBySession:u,runtimeProgressBySession:f,nativeSubagentsBySession:y,currentText:i===s.sessionId?"":s.currentText}}),setTodos:r=>t({todos:r}),setCronTasks:r=>t({cronTasks:r})}));function aa(){const t=window;return t.SpeechRecognition??t.webkitSpeechRecognition??null}function dd(){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 gf(){return dd()!==null||aa()!==null}function mf(t){var o,c;const n=dd();if(n){let d=!1,u=()=>{},g=()=>{};const f=()=>{var x;d||(d=!0,u(),g(),(x=t.onEnd)==null||x.call(t))};return u=n.onDictation(({text:x,isFinal:y})=>{const v=x.trim();v&&(y?(t.onFinal(v),f()):t.onInterim(v))}),g=n.onDictationError(x=>{var y;(y=t.onError)==null||y.call(t,x),f()}),n.dictationStart().then(x=>{var y;x.ok||((y=t.onError)==null||y.call(t,x.reason||"无法启动语音识别"),f())}).catch(()=>{var x;(x=t.onError)==null||x.call(t,"无法启动语音识别"),f()}),{stop:()=>{n.dictationStop()}}}const r=aa();if(!r)return(o=t.onError)==null||o.call(t,"当前环境不支持语音识别"),null;const s=new r;s.lang=t.lang??"zh-CN",s.continuous=!1,s.interimResults=!0;let i="";s.onresult=d=>{let u="";for(let g=d.resultIndex;g<d.results.length;g++){const f=d.results[g];f.isFinal?i+=f[0].transcript:u+=f[0].transcript}u&&t.onInterim(i+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;i&&t.onFinal(i.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 xf(t){var c;const n=aa();if(!n)return(c=t.onError)==null||c.call(t,"当前环境不支持语音唤醒"),null;let r=!1,s=null,i=null;const o=()=>{if(!r){s=new n,s.lang=t.lang??"zh-CN",s.continuous=!0,s.interimResults=!0,s.onresult=d=>{var f,x,y;const u=d.results[d.results.length-1],g=(x=(f=u==null?void 0:u[0])==null?void 0:f.transcript)==null?void 0:x.trim();g&&(u.isFinal&&((y=t.onHeard)==null||y.call(t,g)),g.includes(t.wakeWord)&&t.onWake(g))},s.onerror=d=>{var u;d.error==="not-allowed"&&((u=t.onError)==null||u.call(t,"麦克风权限被拒绝,语音唤醒已停用"),r=!0)},s.onend=()=>{r||(i=setTimeout(o,400))};try{s.start()}catch{i=setTimeout(o,800)}}};return o(),{stop:()=>{r=!0,i&&clearTimeout(i);try{s==null||s.abort()}catch{}}}}function Zs(){typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}function Si(t,n){return n(),typeof(t==null?void 0:t.ttsStop)=="function"?t.ttsStop().then(()=>{}):Promise.resolve()}const bf={createContext:()=>new AudioContext,createNode:t=>new AudioWorkletNode(t,"pcm-stream-player",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]}),workletUrl:"./pcm-audio-worklet.js"};function yf(t){const n=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(n.byteLength%2!==0)throw new Error("PCM chunk contains an incomplete int16 sample");const r=new Float32Array(n.byteLength/2),s=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let i=0;i<r.length;i+=1)r[i]=s.getInt16(i*2,!0)/32768;return r}class vf{constructor(n,r=bf){this.api=n,this.dependencies=r,this.context=null,this.node=null,this.ready=null,this.current=null}start(n){var s;this.current&&!this.current.acknowledged&&((s=this.node)==null||s.port.postMessage({type:"flush",generation:this.current.metadata.generation}));const r={metadata:n,pending:[],pendingSamples:0,finished:!1,acknowledged:!1};this.current=r,this.ensureReady().then(()=>{if(!(this.current!==r||!this.node)){this.node.port.postMessage({type:"start",generation:n.generation,sampleRate:n.sampleRate});for(const i of r.pending)this.postSamples(n.generation,i);r.pending=[],r.pendingSamples=0,r.finished&&this.node.port.postMessage({type:"finish",generation:n.generation})}}).catch(i=>this.fail(r,i))}enqueue(n,r){const s=this.current;if(!s||s.metadata.generation!==n||s.acknowledged)return;let i;try{i=yf(r)}catch(o){this.fail(s,o);return}if(this.node){this.postSamples(n,i);return}if(s.pendingSamples+i.length>s.metadata.sampleRate){this.fail(s,new Error("TTS PCM queue overflow"));return}s.pending.push(i),s.pendingSamples+=i.length}finish(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||(r.finished=!0,(s=this.node)==null||s.port.postMessage({type:"finish",generation:n}))}flush(n){var s;const r=this.current;!r||r.metadata.generation!==n||r.acknowledged||((s=this.node)==null||s.port.postMessage({type:"flush",generation:n}),r.pending=[],r.pendingSamples=0,this.acknowledge(r))}dispose(){var n,r;this.current&&this.flush(this.current.metadata.generation),(n=this.node)==null||n.disconnect(),this.node=null,(r=this.context)==null||r.close(),this.context=null,this.ready=null}ensureReady(){return this.ready?this.ready:(this.ready=(async()=>{const n=this.dependencies.createContext();this.context=n,await n.audioWorklet.addModule(this.dependencies.workletUrl);const r=this.dependencies.createNode(n);r.port.onmessage=s=>this.onWorkletMessage(s.data),r.connect(n.destination),this.node=r,n.state!=="running"&&await n.resume()})(),this.ready)}postSamples(n,r){var s;(s=this.node)==null||s.port.postMessage({type:"chunk",generation:n,samples:r},[r.buffer])}onWorkletMessage(n){const r=this.current;if(!(!r||n.generation!==r.metadata.generation)){if(n.type==="drained"||n.type==="stopped"){this.acknowledge(r);return}n.type==="overflow"&&this.fail(r,new Error("TTS AudioWorklet buffer overflow"))}}fail(n,r){this.current!==n||n.acknowledged||(console.error("[tts] PCM playback failed",r),n.acknowledged=!0,this.current=null,this.api.ttsStop(),this.api.ttsPlaybackEnded(n.metadata.generation))}acknowledge(n){this.current!==n||n.acknowledged||(n.acknowledged=!0,this.current=null,this.api.ttsPlaybackEnded(n.metadata.generation))}}async function wf(t,n,r,s=50){var d;const i=u=>t.getSession(n,{view:"trace",revision:u,turnId:r.turnId});try{return{detail:await i(r.revision),revision:r.revision,recovered:!1}}catch(u){if(u.code!=="STALE_SESSION_ANCHOR")throw u}const o=await t.getSession(n,{view:"core",limit:s}),c=(d=o==null?void 0:o.history)==null?void 0:d.revision;if(!c)throw new Error("会话内容已更新,请刷新后重试");return{detail:await i(c),revision:c,recovered:!0}}async function Ss(t,n,r,s,i,o,c){if(r!=="codex"){const u=c?await c():await t.getSession(n,s);o()&&i(u,"full");return}const d=c?await c():await t.getSession(n,{...s,view:"core"});o()&&i(d,"core")}function jf(t,n,r){var i,o;const s=((i=n==null?void 0:n.history)==null?void 0:i.nextCursor)??null;return((o=n==null?void 0:n.history)==null?void 0:o.hasMore)===!1||!s||r===0&&s===t?null:s}function Al(t,n,r,s){const i=r==="core"&&(s==null?void 0:s.delivery)!=="legacy-full"&&!!(s!=null&&s.revision),o=t.some(c=>!c.isQueued);return i&&o?kf(t,n):pd(t,n)}function kf(t,n){var I,j;if(n.length===0)return t;if(t.length===0)return n;let r=t.filter(k=>!k.isQueued);const s=t.filter(k=>k.isQueued),i=n.findLastIndex(k=>k.role==="user"&&!k.isCompactionSummary);if(i<0)return t;const o=n[i];let c=r.findLastIndex(k=>k.role==="user"&&!k.isCompactionSummary&&er(k)===er(o));if(c<0)return[...r,...n.slice(i),...s];const d=pd(r.slice(0,c),n.slice(0,i));r=[...d,...r.slice(c)],c=d.length;const u=r.findIndex((k,W)=>W>c&&k.role==="user"&&!k.isCompactionSummary),g=u<0?r.length:u,f=[];for(let k=c+1;k<g;k+=1)Tl(r[k])&&f.push(k);const x=n.slice(i+1).filter(Tl),y=(j=(I=n.find(k=>k.executionTrace))==null?void 0:I.executionTrace)==null?void 0:j.revision,v=r.map(k=>k.executionTrace&&y?{...k,executionTrace:{...k.executionTrace,revision:y}}:k),S=n.slice(i+1).find(k=>k.executionTrace),E=r.findIndex((k,W)=>{var ee,N;return W>c&&W<g&&((ee=k.executionTrace)==null?void 0:ee.turnId)===((N=S==null?void 0:S.executionTrace)==null?void 0:N.turnId)});if(S&&E>=0){const k=r[E].executionTrace;v[E]={...S,id:r[E].id,timestamp:r[E].timestamp,executionTrace:{...S.executionTrace,...k!=null&&k.liveMessages?{liveMessages:k.liveMessages}:{}}}}const C=Math.min(f.length,x.length);for(let k=0;k<C;k+=1){const W=f[k],ee=v[W],N=x[k];v[W]={...ee,...N,id:N.id.startsWith("history-message.v1.")?N.id:ee.id,timestamp:ee.timestamp,images:N.images??ee.images,presentation:N.presentation??ee.presentation}}return x.length>C&&v.splice(g,0,...x.slice(C)),[...v,...s]}function Tl(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 Cs(t){var i,o;const n=((i=t==null?void 0:t.history)==null?void 0:i.delivery)==="core",r=ud(t,!n),s=(o=t==null?void 0:t.history)==null?void 0:o.revision;return!n||!s?r:Tf(rf(r,s),(t==null?void 0:t.events)??[])}function Sf(t){return ud(t).filter(sf)}function ud(t,n=!0){var x;const r=(t==null?void 0:t.messages)??[],s=(t==null?void 0:t.events)??[],i=new Set(s.filter(y=>y.type==="approval_resolved"&&y.questionId).map(y=>y.questionId)),o=new Map;for(const y of s)y.type==="tool_result"&&((x=y.result)!=null&&x.toolCallId)&&o.set(y.result.toolCallId,{content:y.result.content??"",isError:y.result.isError});const c=r.filter(y=>(y.role==="user"||y.role==="assistant"||y.role==="tool")&&y.name!=="__interrupt__").map(Af),d=new Map;for(const y of c)y.role==="tool"&&y.toolCallId&&d.set(y.toolCallId,y);let u=c.filter(y=>y.role!=="tool").map(y=>{var v;if(y.isCompactionSummary)return y;if(y.role==="assistant"&&((v=y.toolCalls)!=null&&v.length)){const S=y.toolCalls.filter(E=>E.name!=="ask_user");return S.length===0&&!y.content.trim()?null:{...y,toolCalls:S.map(E=>{const C=d.get(E.id);if(C)return{...E,...C.toolResultRef?{resultRef:C.toolResultRef,isError:C.toolResultRef.isError}:{result:C.content}};const I=o.get(E.id);return I?{...E,result:I.content,isError:I.isError}:E})}}return y.role==="user"&&y.name&&y.name!=="__compaction_checkpoint__"&&!y.name.startsWith("__native_")?{...y,agentName:y.name}:y}).filter(y=>y!==null);const g=Nf(s,n);if(!u.some(y=>y.role==="assistant"&&!y.isCompactionSummary)&&g){const y=u.findLastIndex(v=>v.role==="user"&&!v.isCompactionSummary);u=y>=0?[...u.slice(0,y+1),g,...u.slice(y+1)]:[...u,g]}const f=new Set(u.flatMap(y=>{var v;return(v=y.askUser)!=null&&v.questionId?[y.askUser.questionId]:[]}));for(const y of s)y.type!=="ask_user"||!y.questionId||i.has(y.questionId)||f.has(y.questionId)||(f.add(y.questionId),u.push({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:y.questionId,question:y.question??"",options:y.options,fields:y.fields,multiSelect:y.multiSelect},timestamp:Date.now()}));return u}function pd(t,n){if(n.length===0)return t;if(t.length===0)return n;const r=t.map(Vo),s=n.map(Vo),i=Math.max(0,t.length-n.length),o=Ef(t,n,i);let c={currentStart:i,length:0,distance:1/0};for(let S=0;S<r.length;S++)for(let E=0;E<s.length;E++){if(r[S]!==s[E])continue;const C=S-E;if(C<0)continue;let I=0;for(;S+I<r.length&&E+I<s.length&&r[S+I]===s[E+I];)I+=1;const j=Math.abs(C-i);(I>c.length||I===c.length&&j<c.distance)&&(c={currentStart:C,length:I,distance:j})}const d=o??(c.length>0?c.currentStart:i),u=n.map((S,E)=>{var W,ee,N;const C=t[d+E];if(!C||!Mf(C,S,s[E]))return S;const I=(ee=(W=S.presentation)==null?void 0:W.attachments)==null?void 0:ee.some(T=>T.dataUrl),j=(N=S.toolCalls)==null?void 0:N.map(T=>{var R;const A=(R=C.toolCalls)==null?void 0:R.find(L=>L.id===T.id);return(A==null?void 0:A.result)===void 0?T:{...T,result:A.result,isError:A.isError}});return{...If(C,S),id:S.id.startsWith("history-message.v1.")?S.id:C.id,timestamp:C.timestamp,images:I?void 0:S.images??C.images,...j?{toolCalls:j}:{}}}),g=t.filter(S=>S.isQueued),f=t.slice(d).filter(S=>!S.isQueued),x=Rf(f,u),y=t.findLastIndex((S,E)=>E>=d&&S.role==="user"&&S.sendState==="pending"&&!S.isQueued&&!Cf(t,u,d,E)),v=y<0?[]:t.slice(y).filter(S=>!S.isQueued);return[...t.slice(0,d).filter(S=>!S.isQueued),...x,...v,...g]}function Cf(t,n,r,s){const i=t[s];if(!i||i.role!=="user")return!1;if(n.some(u=>u.id===i.id))return!0;const o=er(i),c=t.slice(r,s+1).filter(u=>u.role==="user"&&!u.isQueued&&er(u)===o).length;return n.filter(u=>u.role==="user"&&er(u)===o).length>=c}function If(t,n){var o,c;const r=(o=n.presentation)==null?void 0:o.attachments,s=(c=t==null?void 0:t.presentation)==null?void 0:c.attachments;if(!(r!=null&&r.length)||!(s!=null&&s.length)||r.every(d=>d.dataUrl||d.unavailable))return n;const i=r.map(d=>{if(d.dataUrl||d.unavailable||!d.omitted)return d;const u=s.find(g=>g.name===d.name&&g.dataUrl);return u?{...d,dataUrl:u.dataUrl,omitted:void 0}:d});return{...n,presentation:{...n.presentation,attachments:i}}}function Rf(t,n){const r=n.findLastIndex(S=>S.role==="user"&&!S.isQueued);if(r<0)return n;const s=er(n[r]);let i=-1,o=1/0;for(let S=0;S<t.length;S+=1){const E=t[S];if(E.role!=="user"||E.isQueued||er(E)!==s)continue;const C=Math.abs(S-r);C<o&&(i=S,o=C)}if(i<0)return n;const c=t.findIndex((S,E)=>E>i&&S.role==="user"&&!S.isQueued),d=t.slice(i+1,c<0?t.length:c),u=n.slice(r+1),g=Nl(d),f=Nl(u);if(g.length<=f.length||!g.startsWith(f))return n;const x=g.slice(f.length),y=n.findLastIndex((S,E)=>{var C;return E>r&&S.role==="assistant"&&!((C=S.toolCalls)!=null&&C.length)&&!S.askUser&&!S.isCompactionSummary});if(y>=0)return n.map((S,E)=>E===y?{...S,content:S.content+x}:S);const v=d.findLast(S=>S.role==="assistant"&&!!S.content&&!S.isCompactionSummary);return[...n,{id:(v==null?void 0:v.id)??crypto.randomUUID(),role:"assistant",content:x,timestamp:(v==null?void 0:v.timestamp)??Date.now()}]}function Nl(t){return t.filter(n=>n.role==="assistant"&&!n.isCompactionSummary).map(n=>n.content).join("")}function Ef(t,n,r){const s=n[0];if((s==null?void 0:s.role)!=="user")return null;const i=er(s);let o=null;for(let c=0;c<t.length;c+=1){if(t[c].role!=="user"||t[c].isQueued||er(t[c])!==i)continue;const d=Math.abs(c-r);(!o||d<o.distance)&&(o={start:c,distance:d})}return(o==null?void 0:o.start)??null}function Mf(t,n,r){var s,i;return Vo(t)===r||t.role==="assistant"&&n.role==="assistant"&&t.content===n.content&&JSON.stringify(((s=t.toolCalls)==null?void 0:s.map(o=>o.id))??[])===JSON.stringify(((i=n.toolCalls)==null?void 0:i.map(o=>o.id))??[])?!0:t.role==="user"&&n.role==="user"&&er(t)===er(n)}function er(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 Af(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 Tf(t,n){return n.reduce((r,s)=>{var o;if(!s.turnId)return r;let i=null;return s.type==="text_chunk"&&s.messagePhase==="commentary"&&typeof s.text=="string"&&s.text?i={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"?i={type:"reasoning_summary_delta",turnId:s.turnId,itemId:s.itemId,sectionIndex:s.sectionIndex,delta:s.delta}:s.type==="tool_call"&&s.toolCall?i={type:"tool_call",turnId:s.turnId,toolCall:s.toolCall}:s.type==="tool_result"&&((o=s.result)!=null&&o.toolCallId)&&(i={type:"tool_result",turnId:s.turnId,result:{toolCallId:s.result.toolCallId,content:s.result.content??"",isError:s.result.isError}}),i?Ho(r,s.turnId,i):r},t)}function Nf(t,n=!0){var o;let r="";const s=[],i=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),i.set(d.id,d)}if(n&&c.type==="tool_result"&&((o=c.result)!=null&&o.toolCallId)){const d=i.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 _f{constructor(){this.slot=null}prefetch(n,r,s){return this.getOrStart(n,r,s).promise}async consume(n,r,s){const i=this.getOrStart(n,r,s);try{return await i.promise}finally{this.slot===i&&(this.slot=null)}}invalidate(){this.slot=null}getOrStart(n,r,s){var c;if(((c=this.slot)==null?void 0:c.sessionId)===n&&this.slot.cursor===r)return this.slot;let i;try{i=s()}catch(d){i=Promise.reject(d)}const o={sessionId:n,cursor:r,promise:i};return this.slot=o,i.catch(()=>{this.slot===o&&(this.slot=null)}),o}}const fd=60,zf=32,Lf=240,Pf=6,Df=10;function _l(t,n,r,s){if(s<=1||r<=0)return 0;const i=Math.max(0,Math.min(1,(t-n)/r));return Math.round(i*(s-1))}function Wf(t){const n=Math.min(Math.max(0,t),fd);return n<=1?n===1?[0]:[]:Array.from({length:n},(r,s)=>Math.round(s/(n-1)*(t-1)))}function zl(t,n=Pf){return Math.min(Lf,Math.max(zf,Math.min(Math.max(0,t),fd)*n))}function Bf(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 Ff({entries:t,activeMessageId:n,loadingMessageId:r,onActivate:s}){const i=t.findIndex(C=>C.messageId===n),o=i>=0?i:Math.max(0,t.length-1),[c,d]=a.useState(o),[u,g]=a.useState(!1),f=a.useRef(!1),x=a.useMemo(()=>Wf(t.length),[t.length]);if(a.useEffect(()=>d(o),[o]),t.length<2)return null;const y=Math.min(c,t.length-1),v=t[y],S=r===v.messageId,E=(C,I)=>{const j=I.getBoundingClientRect();d(_l(C,j.top,j.height,t.length))};return e.jsxs("div",{className:`query-navigation-rail${u?" query-navigation-rail--open":""}`,style:{"--query-navigation-rail-height":`${zl(t.length)}px`,"--query-navigation-rail-web-height":`${zl(t.length,Df)}px`},role:"slider",tabIndex:0,"aria-label":"用户消息导航","aria-orientation":"vertical","aria-valuemin":1,"aria-valuemax":t.length,"aria-valuenow":v.ordinal,"aria-valuetext":`第 ${v.ordinal} 条:${v.preview}`,"aria-busy":S||void 0,onPointerEnter:C=>{g(!0),E(C.clientY,C.currentTarget)},onPointerMove:C=>{C.pointerType==="touch"&&!f.current||E(C.clientY,C.currentTarget)},onPointerLeave:()=>{f.current||g(!1)},onPointerDown:C=>{f.current=!0,g(!0),C.currentTarget.setPointerCapture(C.pointerId),E(C.clientY,C.currentTarget)},onPointerUp:C=>{E(C.clientY,C.currentTarget);const I=_l(C.clientY,C.currentTarget.getBoundingClientRect().top,C.currentTarget.getBoundingClientRect().height,t.length);f.current=!1,C.currentTarget.releasePointerCapture(C.pointerId),s(t[I]),C.pointerType==="touch"&&g(!1)},onPointerCancel:()=>{f.current=!1,g(!1)},onFocus:()=>g(!0),onBlur:()=>g(!1),onKeyDown:C=>{if(C.key==="Enter"){C.preventDefault(),s(v);return}const I=Bf(y,C.key,t.length);I!==null&&(C.preventDefault(),d(I))},children:[e.jsxs("div",{className:"query-navigation-rail__track","aria-hidden":"true",children:[x.map(C=>e.jsx("span",{className:`query-navigation-rail__tick${C===y?" is-selected":""}${t[C].messageId===n?" is-active":""}`},C)),e.jsx("span",{className:"query-navigation-rail__marker",style:{top:`${y/Math.max(1,t.length-1)*100}%`}})]}),S&&e.jsx("span",{className:"query-navigation-rail__loading",role:"status","aria-label":"正在定位消息",children:e.jsx(lt,{size:14,"aria-hidden":"true"})}),u&&e.jsxs("div",{className:"query-navigation-rail__preview",role:"status",children:[e.jsxs("span",{children:[v.ordinal," / ",t.length]}),e.jsx("p",{children:v.preview})]})]})}const Of=/^(?:load failed|failed to fetch|network request failed|networkerror when attempting to fetch resource\.?|the network connection was lost\.?|fetch failed)$/i;function hd(t){return t instanceof Error&&t.name!=="AbortError"&&Of.test(t.message.trim())}function $f(t){return hd(t)?"网络连接中断,会话加载失败,请重新加载":t instanceof Error?t.message:"会话加载失败"}async function Uf(t,n={}){const r=Math.max(1,Math.floor(n.maxAttempts??4)),s=Math.max(0,n.baseDelayMs??500),i=n.sleep??(o=>new Promise(c=>{setTimeout(c,o)}));for(let o=1;o<=r;o+=1)try{return await t()}catch(c){if(o===r||!hd(c))throw c;await i(s*2**(o-1))}throw new Error("会话加载失败")}const Hf=2048,qf=2*1024*1024,Vf=.85;function Gf(t,n,r=Hf){const s=Math.max(t,n);if(s<=r)return{width:t,height:n};const i=r/s;return{width:Math.max(1,Math.round(t*i)),height:Math.max(1,Math.round(n*i))}}async function Ll(t,n=Kf){if(t.type.toLowerCase()==="image/gif")return t;let r=null;try{r=await n.decode(t);const s=Gf(r.width,r.height);if(!(s.width!==r.width||s.height!==r.height)&&t.size<=qf)return t;const o=t.type.toLowerCase()==="image/jpeg"?"image/jpeg":"image/webp",c=await n.encode(r,s.width,s.height,o,Vf);return c&&c.size<t.size?c:t}catch{return t}finally{r==null||r.dispose()}}const Kf={decode(t){return new Promise((n,r)=>{const s=URL.createObjectURL(t),i=new Image;let o=!1;const c=()=>URL.revokeObjectURL(s);i.onload=()=>{o=!0,n({source:i,width:i.naturalWidth,height:i.naturalHeight,dispose:c})},i.onerror=()=>{o||c(),r(new Error("无法解码图片"))},i.src=s})},encode(t,n,r,s,i){const o=document.createElement("canvas");o.width=n,o.height=r;const c=o.getContext("2d");return c?(c.drawImage(t.source,0,0,n,r),new Promise(d=>o.toBlob(d,s,i))):Promise.resolve(null)}};function Qf(t){return t==="customer-agent"||t==="codex"||t==="claude-code"}function Pl(t){return t!=null&&t.length?[...t]:void 0}function Xf(t){const n=Pl(t.agentIds),r=Pl(t.images);return{text:t.text.trim(),origin:"composer",applyGoalMode:!0,clearComposer:!0,restoreDraftOnFailure:!0,...n?{agentIds:n}:{},...t.agentName?{agentName:t.agentName}:{},...r?{images:r}:{}}}function Yf(t){return{text:t.trim(),origin:"suggestion",applyGoalMode:!1,clearComposer:!1,restoreDraftOnFailure:!1}}const Jf="agentroam:draft:";function Bi(t){return`${Jf}${t}`}function Zf(t){if(!t||typeof window>"u")return"";try{return window.localStorage.getItem(Bi(t))??""}catch{return""}}function Wr(t,n){if(!(!t||typeof window>"u"))try{n?window.localStorage.setItem(Bi(t),n):window.localStorage.removeItem(Bi(t))}catch{}}function Is(t){if(!(!t||typeof window>"u"))try{window.localStorage.removeItem(Bi(t))}catch{}}function eh(t,n,r){return n?t!==n?{type:"restore",ownerSessionId:n}:{type:"persist",ownerSessionId:n,value:r}:{type:"inactive",ownerSessionId:null}}const th="agentroam-composer-drafts",nh=1,Rs="session-image-drafts";function Dl(t){if(!t||typeof t!="object")return[];const n=t.images;return Array.isArray(n)?n.filter(r=>typeof r=="string"&&r.startsWith("data:image/")):[]}class rh{constructor(n){this.databasePromise=null,this.mutationQueue=Promise.resolve(),this.factory=n===void 0?typeof indexedDB>"u"?null:indexedDB:n}async read(n){if(!n||!this.factory)return[];await this.mutationQueue;const r=await this.openDatabase();return r?await new Promise(s=>{try{const i=r.transaction(Rs,"readonly"),o=i.objectStore(Rs).get(n);o.onsuccess=()=>s(Dl(o.result)),o.onerror=()=>s([]),i.onabort=()=>s([])}catch{s([])}}):[]}write(n,r){if(!n||!this.factory)return Promise.resolve();const s=Dl({images:r});return this.enqueueMutation(async()=>{const i=await this.openDatabase();i&&await this.runMutation(i,o=>{s.length===0?o.delete(n):o.put({sessionId:n,images:s})})})}clear(n){return!n||!this.factory?Promise.resolve():this.enqueueMutation(async()=>{const r=await this.openDatabase();r&&await this.runMutation(r,s=>s.delete(n))})}enqueueMutation(n){const r=this.mutationQueue.then(n,n).catch(()=>{});return this.mutationQueue=r,r}openDatabase(){return this.databasePromise?this.databasePromise:this.factory?(this.databasePromise=new Promise(n=>{try{const r=this.factory.open(th,nh);r.onupgradeneeded=()=>{const s=r.result;s.objectStoreNames.contains(Rs)||s.createObjectStore(Rs,{keyPath:"sessionId"})},r.onsuccess=()=>n(r.result),r.onerror=()=>n(null),r.onblocked=()=>n(null)}catch{n(null)}}),this.databasePromise):Promise.resolve(null)}runMutation(n,r){return new Promise(s=>{try{const i=n.transaction(Rs,"readwrite");r(i.objectStore(Rs)),i.oncomplete=()=>s(),i.onerror=()=>s(),i.onabort=()=>s()}catch{s()}})}}class sh{constructor(n){this.repository=n,this.selectedSessionId=null,this.selectionGeneration=0}async restore(n){const r=++this.selectionGeneration;if(this.selectedSessionId=n??null,!n)return null;const s=await this.repository.read(n);return r!==this.selectionGeneration||this.selectedSessionId!==n?null:{sessionId:n,images:s}}save(n,r){return this.invalidatePendingRestore(n),this.repository.write(n,r)}saveSelected(n,r){return this.selectedSessionId!==n?Promise.resolve():this.repository.write(n,r)}clear(n){return this.invalidatePendingRestore(n),this.repository.clear(n)}invalidatePendingRestore(n){this.selectedSessionId===n&&(this.selectionGeneration+=1)}}const ih="agent-webapp:artifact-open:v1";let Wl=0;function Bl(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function gd(t,n){const r=t.trim();if(!r||/[\0\r\n]/.test(r))return null;if(Bl(r))return r;if(!n||!Bl(n))return null;const s=r.replaceAll("\\","/").split("/").filter(o=>o&&o!==".");if(s.length===0||s.some(o=>o===".."))return null;const i=/^[A-Za-z]:[\\/]/.test(n)||n.startsWith("\\\\")?"\\":"/";return`${n.replace(/[\\/]+$/,"")}${i}${s.join(i)}`}function oh(t,n=window){return n.parent===n?!1:(Wl+=1,n.parent.postMessage({type:ih,requestId:Wl,path:t},n.location.origin),!0)}function ah(t){var n;return((n=[...t].reverse().find(r=>r.role==="user"&&!r.isQueued))==null?void 0:n.id)??null}function lh(t){var n;return((n=[...t].reverse().find(r=>r.role==="user"&&!r.isQueued&&r.sendState==="pending"))==null?void 0:n.id)??null}function ch(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 Fl(t,n,r=Date.now()){const s=t.findIndex(c=>c.id===n);if(s<0)return t;const o={...t[s],timestamp:r,isQueued:!1,isSteered:!0,queueItemId:void 0,sendState:void 0};return[...t.slice(0,s),...t.slice(s+1),o]}function mo(t,n){var c,d,u;const r=t.filter(g=>!g.isQueued),s=new Map(t.filter(g=>g.isQueued&&g.queueItemId).map(g=>[g.queueItemId,g])),i=((c=n.active)==null?void 0:c.kind)==="message"?n.active:null;if(i){const g=s.get(i.id),f=i.sourceMessageId||(g==null?void 0:g.id)||i.id,x=r.findLastIndex(C=>C.role==="user"),y=r.findLastIndex((C,I)=>C.id===f||C.queueItemId===i.id||!g&&I===x&&C.role==="user"&&C.content===i.objective),v=y>=0?r[y]:g,S=y>=0&&r.slice(y+1).some(C=>C.role==="assistant"),E={...v??{},id:(v==null?void 0:v.id)||f,role:"user",content:i.objective,timestamp:(v==null?void 0:v.timestamp)??i.createdAt,agentName:(v==null?void 0:v.agentName)??((d=i.messagePayload)==null?void 0:d.agentName),images:(v==null?void 0:v.images)??((u=i.messagePayload)==null?void 0:u.images),isQueued:!1,queueItemId:void 0,...v&&"sendState"in v?{sendState:v.sendState}:S?{}:{sendState:"pending"}};y>=0?r[y]=E:r.push(E)}const o=n.queued.filter(g=>g.kind==="message").map(g=>{var x,y;const f=s.get(g.id);return{...f??{},id:g.sourceMessageId||(f==null?void 0:f.id)||g.id,role:"user",content:g.objective,timestamp:(f==null?void 0:f.timestamp)??g.createdAt,agentName:(x=g.messagePayload)==null?void 0:x.agentName,images:(y=g.messagePayload)==null?void 0:y.images,isQueued:!0,queueItemId:g.id}});return[...r,...o]}function Ol(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 dh(t,n,r){if(n===r)return t;const s=t.filter(g=>g.isQueued),i=s.findIndex(g=>g.id===n),o=s.findIndex(g=>g.id===r);if(i<0||o<0)return t;const c=[...s],[d]=c.splice(i,1);c.splice(o,0,d);let u=0;return t.map(g=>g.isQueued?c[u++]:g)}function uh(t){let n=!0,r=!1;return{onScroll(s){const i=s>t;return i?r||(n=!1):(n=!0,r=!1),i},requestReturn(){n=!0,r=!0},reset(){n=!0,r=!1},shouldFollow(s){return s==="skip"?!1:(s==="instant"&&(n=!0,r=!1),n)},isFollowing(){return n}}}function ph(t,n,r){return t?(n==null?void 0:n.id)!==t?{agentType:r,ready:!1}:{agentType:n.agentType,ready:!0}:{agentType:r,ready:!0}}function fh(t){return typeof t=="string"&&t.trim().length>0?t:null}function hh(t){return!["run_admitted","done","error","turn_aborted","goal_updated","goal_cleared"].includes(t)}function gh(t,n){return((t==null?void 0:t.agentType)??n)!=="customer-agent"}function la(t){return(t==null?void 0:t.agentType)!==void 0&&t.agentType!=="customer-agent"&&t.status==="running"}function mh(t){return la(t)&&(t==null?void 0:t.occupancy)==="owned-externally"}function md(t){return la(t)&&(t==null?void 0:t.occupancy)!=="owned-externally"}function xh(t){return(t==null?void 0:t.agentType)==="customer-agent"&&t.status==="active"}function bh(t,n){return n||md(t)}function yh(t,n,r){return!!(n&&t&&t.agentType!=="customer-agent")}const xd=["modelProvider","modelId","apiKey","baseUrl","maxIterations","contextWindow","workingDirectory","isConfigured","profiles","activeProfileId","reasoningEffort","taskNotifications"];let $l=null;function Ul(t){return Object.fromEntries(xd.map(n=>[n,t[n]]))}function vh(t,n){return t?Object.fromEntries(xd.filter(r=>JSON.stringify(t[r])!==JSON.stringify(n[r])).map(r=>[r,n[r]])):n}function Ci(t,n){return t.find(r=>r.id===n)??null}function xo(t){return t.provider==="aihub"?!!t.modelId:!!(t.apiKey&&t.modelId)}const Ui=Nc((t,n)=>({modelProvider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxIterations:10,contextWindow:100,workingDirectory:"/",isConfigured:!1,profiles:[],activeProfileId:"",reasoningEffort:"off",taskNotifications:Ni,setField:(r,s)=>t(i=>{const o={...i,[r]:s};return o.isConfigured=o.modelProvider==="aihub"?!!o.modelId:!!(o.apiKey&&o.modelId),o}),loadFromSystem:async()=>{if(window.agentApi)try{const r=await window.agentApi.getSettings(),s=r.profiles??[],i=r.activeProfileId??"",o=Ci(s,i),c={revision:r.revision,modelProvider:(o==null?void 0:o.provider)??r.modelProvider??"anthropic",modelId:(o==null?void 0:o.modelId)??r.modelId??"claude-sonnet-4-6",apiKey:(o==null?void 0:o.apiKey)??r.apiKey??"",baseUrl:(o==null?void 0:o.baseUrl)??r.baseUrl??"",maxIterations:r.maxIterations??10,contextWindow:r.contextWindow??100,workingDirectory:r.workingDirectory??"/",isConfigured:((o==null?void 0:o.provider)??r.modelProvider)==="aihub"?!!((o==null?void 0:o.modelId)??r.modelId):!!(((o==null?void 0:o.apiKey)??r.apiKey)&&((o==null?void 0:o.modelId)??r.modelId)),profiles:s,activeProfileId:i,reasoningEffort:["off","low","medium","high"].includes(r.reasoningEffort??"")?r.reasoningEffort:"off",taskNotifications:jp(r.taskNotifications)};$l=Ul(c),t(c)}catch(r){console.error("Failed to load settings:",r)}},saveToSystem:async()=>{if(!window.agentApi)return;const r=n(),s=Ul(r),i=vh($l,s);try{await window.agentApi.saveSettings({...i,revision:r.revision})}catch(o){if((o==null?void 0:o.status)!==409)throw o;const c=await window.agentApi.getSettings();await window.agentApi.saveSettings({...i,revision:c.revision})}await n().loadFromSystem()},addProfile:r=>{const i={id:crypto.randomUUID(),...r};t(o=>({profiles:[...o.profiles,i]}))},updateProfile:(r,s)=>{t(o=>({profiles:o.profiles.map(c=>c.id===r?{...c,...s}:c)}));const i=n();if(i.activeProfileId===r){const o=Ci(i.profiles,r);o&&t({modelProvider:o.provider,modelId:o.modelId,apiKey:o.apiKey,baseUrl:o.baseUrl,isConfigured:xo(o)})}},deleteProfile:r=>{t(s=>{var d;const i=s.profiles.filter(u=>u.id!==r),o=s.activeProfileId===r?((d=i[0])==null?void 0:d.id)??"":s.activeProfileId,c=Ci(i,o);return{profiles:i,activeProfileId:o,...c?{modelProvider:c.provider,modelId:c.modelId,apiKey:c.apiKey,baseUrl:c.baseUrl,isConfigured:xo(c)}:{},...c?{}:{modelProvider:"anthropic",modelId:"",apiKey:"",baseUrl:"",isConfigured:!1}}})},setActiveProfileLocal:r=>{const s=n(),i=Ci(s.profiles,r);i&&t({activeProfileId:r,modelProvider:i.provider,modelId:i.modelId,apiKey:i.apiKey,baseUrl:i.baseUrl,isConfigured:xo(i)})},switchActiveProfile:async r=>{window.agentApi&&(await window.agentApi.setActiveProfile(r),await n().loadFromSystem())}}));function zs(t){return t.result!==void 0||t.resultRef!==void 0}function bo(t){return t.every(zs)}const ca=new Set(["shell","bash","Bash","execute_command","run_command","BashOutput","KillShell"]),bd=new Set(["Read","read_file","Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]),yd=new Set(["Glob","glob_search","Grep","grep_search","WebSearch","WebFetch"]),wh=new Set(["Read","read_file"]),jh=new Set(["Write","write_file","Edit","MultiEdit","str_replace","apply_patch","NotebookEdit"]);function da(t){return ca.has(t)?"command":bd.has(t)?"file":yd.has(t)?"search":"generic"}function ua(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 kh(t){var n;return((n=ua(t))==null?void 0:n.done)??null}function vd(t){return ca.has(t)?"终端":wh.has(t)?"查阅":jh.has(t)?"写入":yd.has(t)?"查阅":t==="Skill"?"技能":t==="Task"||t==="dispatch_agent"||t==="Agent"?"子任务":t==="TodoWrite"?"任务":t.startsWith("mcp__")||t.includes(":")?"工具":null}function Hl(t){return t.replace(/\\/g,"/").split("/").pop()??t}function yo(t,n=60){const r=(t??"").split(`
436
- `)[0].trim();return r.length>n?r.slice(0,n)+"…":r}function Sh(t,n){if(ca.has(t))return yo(String(n.command??""));if(t==="apply_patch"){const s=(Array.isArray(n.changes)?n.changes:[]).map(i=>Hl(String((i==null?void 0:i.path)??""))).filter(Boolean);return s.length?s.length<=3?s.join("、"):`${s.slice(0,3).join("、")} 等 ${s.length} 个文件`:null}return bd.has(t)?n.file_path?Hl(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"?yo(String(n.description??n.task??""),80)||null:t==="WebSearch"?yo(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 Ch(t,n){return Math.max(0,Math.floor((n-t)/1e3))}function pa({startedAt:t}){const[n,r]=a.useState(()=>Date.now());return a.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:[" · 持续了 ",Ch(t,n)," 秒"]})}function wd({progress:t,compact:n=!1,startedAt:r}){const s=t.detail??(t.elapsedSeconds===void 0?void 0:`${Math.round(t.elapsedSeconds)} 秒`),i=[t.label,s].filter(Boolean).join(","),o=!n&&t.phase==="thinking",c=!n&&t.phase==="status",d=o&&r!==void 0&&s===void 0;return e.jsxs("div",{className:`runtime-progress-row${n?" runtime-progress-row--compact":""}`,role:"status","aria-live":"polite","aria-label":i,children:[o?e.jsx("span",{className:"runtime-progress-row__brain","aria-hidden":"true",children:e.jsx(ea,{size:17,strokeWidth:1.8})}):c?e.jsx("span",{className:"runtime-progress-row__status-icon","aria-hidden":"true",children:e.jsx(lt,{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(pa,{startedAt:r})]})}function Ls({isDone:t,isError:n,color:r,size:s=11}){return t?n?e.jsx(Fu,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx($r,{size:s,color:r,strokeWidth:2.5,"aria-hidden":"true"}):e.jsx(lt,{size:s,color:r,strokeWidth:2.5,style:{animation:"spin 1s linear infinite",flexShrink:0},"aria-hidden":"true"})}function li({name:t,color:n,size:r=14}){const s=da(t);return s==="command"?e.jsx(hp,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="search"?e.jsx(sa,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):s==="file"?t==="Read"||t==="read_file"?e.jsx(ai,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(na,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Skill"?e.jsx(fp,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="TodoWrite"?e.jsx(Ku,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):t==="Task"||t==="dispatch_agent"||t==="Agent"?e.jsx(gp,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Qc,{size:r,color:n,strokeWidth:1.8,"aria-hidden":"true"})}function Hi({statusColor:t,isDone:n,expanded:r,onToggle:s,header:i,children:o,maxBodyHeight:c=600,primaryAction:d,primaryActionLabel:u,primaryActionTitle:g}){const f=e.jsxs("button",{type:"button",className:"tool-call-shell__header",...d?{onClick:d,"aria-label":u,title:g}:{onClick:s,"aria-expanded":r},style:{flex:1,border:"none",background:"var(--bg-deep)",cursor:"pointer",padding:"7px 10px 7px 9px",display:"flex",alignItems:"center",gap:7,fontFamily:"var(--font-body)",transition:"background 0.12s",textAlign:"left",minWidth:0},onMouseEnter:x=>x.currentTarget.style.background="var(--bg-elevated)",onMouseLeave:x=>x.currentTarget.style.background="var(--bg-deep)",children:[i,!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"}}),f,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:o})})]})}function oi({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 Ir(t){return t.replace(/\\/g,"/").split("/").pop()??t}function jd(t){return t?t.split(`
437
- `).length:0}function qi(t,n,r=!1){const[s,i]=a.useState(r),[o,c]=a.useState(!1),[d,u]=a.useState(null),g=async()=>{if(!(!t.resultRef||t.result!==void 0||o||!n)){c(!0),u(null);try{await n(t.resultRef)}catch(x){u(x instanceof Error?x.message:"工具结果加载失败")}finally{c(!1)}}};return{expanded:s,setExpanded:i,toggle:()=>{const x=!s;i(x),x&&g()},loadingResult:o,resultError:d,loadResult:g}}function Vi({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(lt,{size:11,strokeWidth:2.2,style:{animation:n?"spin 1s linear infinite":"none"},"aria-hidden":"true"}),n?"正在加载工具结果":`${t.resultRef.byteSize.toLocaleString()} 字节,展开后加载`]})}function kd(t,n){const r=t.split(`
438
- `),s=n.split(`
439
- `);if(r.length*s.length>2e5)return s.map((v,S)=>({type:"added",text:v,lineNo:S+1}));const i=r.length,o=s.length,c=Array.from({length:i+1},()=>new Array(o+1).fill(0));for(let v=1;v<=i;v++)for(let S=1;S<=o;S++)c[v][S]=r[v-1]===s[S-1]?c[v-1][S-1]+1:Math.max(c[v-1][S],c[v][S-1]);const d=[];let u=i,g=o;for(;u>0&&g>0;)r[u-1]===s[g-1]?(d.unshift([u-1,g-1]),u--,g--):c[u-1][g]>=c[u][g-1]?u--:g--;const f=[];let x=0,y=0;for(const[v,S]of d){for(;x<v;)f.push({type:"removed",text:r[x],lineNo:x+1}),x++;for(;y<S;)f.push({type:"added",text:s[y],lineNo:y+1}),y++;f.push({type:"same",text:r[x],lineNo:x+1}),x++,y++}for(;x<i;)f.push({type:"removed",text:r[x],lineNo:x+1}),x++;for(;y<o;)f.push({type:"added",text:s[y],lineNo:y+1}),y++;return f}function Sd({content:t,maxHeight:n=320}){const r=t.split(`
440
- `);return e.jsx("div",{style:{background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:n,fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.65},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{})]}),e.jsx("tbody",{children:r.map((s,i)=>e.jsxs("tr",{children:[e.jsx("td",{style:{padding:"0 8px",color:"var(--text-muted)",textAlign:"right",userSelect:"none",borderRight:"1px solid var(--border-subtle)",background:"var(--bg-deep)",fontSize:10,minWidth:36},children:i+1}),e.jsx("td",{style:{padding:"0 12px",color:"var(--text-secondary)",wordBreak:"break-all",whiteSpace:"pre-wrap"},children:s||" "})]},i))})]})})}function Cd({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)),i=new Set;s.forEach(d=>{for(let u=Math.max(0,d-3);u<=Math.min(t.length-1,d+3);u++)i.add(u)});const o=[];let c=-1;return[...i].sort((d,u)=>d-u).forEach(d=>{c>=0&&d>c+1&&o.push("ellipsis"),o.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:o.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:g}=d,f=g.type==="added"?"rgba(5,150,105,0.08)":g.type==="removed"?"rgba(220,38,38,0.07)":"transparent",x=g.type==="added"?"+":g.type==="removed"?"−":" ",y=g.type==="added"?"var(--success)":g.type==="removed"?"var(--danger)":"transparent",v=g.type==="added"?"#059669":g.type==="removed"?"var(--danger)":"var(--text-secondary)";return e.jsxs("tr",{style:{background:f},children:[e.jsx("td",{style:{padding:"0 4px",textAlign:"center",color:y,fontWeight:700,userSelect:"none"},children:x}),e.jsx("td",{style:{padding:"0 6px",color:"var(--text-muted)",textAlign:"right",fontSize:10,borderRight:"1px solid var(--border-subtle)",userSelect:"none"},children:g.lineNo}),e.jsx("td",{style:{padding:"0 12px",color:v,wordBreak:"break-all",whiteSpace:"pre-wrap"},children:g.text||" "})]},u)})})]})})}function Ih({toolCall:t,beforeContent:n,previewPath:r,onOpenArtifact:s,onLoadResult:i}){const o=qi(t,i),{expanded:c}=o,[d,u]=a.useState("content"),g=t.arguments.file_path??"",f=t.arguments.content??"",x=jd(f),y=t.isError,v=zs(t),S=v?y?"var(--danger)":"var(--success)":"var(--accent)",E=a.useMemo(()=>n&&f?kd(n,f):null,[n,f]),C=a.useMemo(()=>E?{added:E.filter(k=>k.type==="added").length,removed:E.filter(k=>k.type==="removed").length}:null,[E]),I=y?"var(--danger)":v?"var(--text-muted)":"var(--accent)",j=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(li,{name:t.name,color:I})}),e.jsx("span",{className:"tool-call-shell__label",children:"写入"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:g,children:Ir(g)}),e.jsx(oi,{label:`${x} 行`,color:"var(--accent)",bg:"var(--accent-dim)"}),C&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[C.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",C.added]}),C.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",C.removed]})]}),(!v||y)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:S},children:[e.jsx(Ls,{isDone:v,isError:y,color:S}),y&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Hi,{statusColor:S,isDone:v,expanded:c,onToggle:o.toggle,header:j,primaryAction:r&&s?()=>s(r):void 0,primaryActionLabel:r?`预览文件 ${Ir(r)}`:void 0,primaryActionTitle:r?`预览 ${r}`:void 0,children:[e.jsx(Vi,{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:g}),E&&e.jsx("div",{style:{display:"flex",gap:3},children:["content","diff"].map(k=>e.jsx("button",{onClick:()=>u(k),style:{padding:"2px 9px",borderRadius:5,border:"none",cursor:"pointer",fontSize:11,fontWeight:500,background:d===k?"var(--accent-dim)":"transparent",color:d===k?"var(--accent)":"var(--text-muted)",transition:"background 0.12s"},children:k==="content"?"文件内容":"变更行"},k))}),d==="diff"&&E?e.jsx(Cd,{diff:E}):e.jsx(Sd,{content:f}),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 Rh({toolCall:t,previewPath:n,onOpenArtifact:r,onLoadResult:s}){const i=qi(t,s),{expanded:o}=i,c=t.arguments.file_path??"",d=t.arguments.startLine,u=t.arguments.endLine,g=t.arguments.offset,f=t.arguments.limit,x=t.result??"",y=jd(x),v=t.isError,S=zs(t),E=S?v?"var(--danger)":"var(--success)":"var(--accent)",C=d!==void 0?`L${d}–${u??"?"}`:g!==void 0?`第${g}行起${f?` ×${f}`:""}`:null,I=v?"var(--danger)":S?"var(--text-muted)":"var(--accent)",j=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(li,{name:t.name,color:I})}),e.jsx("span",{className:"tool-call-shell__label",children:"查阅"}),e.jsx("span",{className:"tool-call-shell__preview",style:{flex:1},title:c,children:Ir(c)}),C&&e.jsx(oi,{label:C,color:"var(--accent)",bg:"var(--accent-dim)"}),S&&!v&&e.jsx(oi,{label:`${y} 行`,color:"var(--text-muted)",bg:"var(--bg-surface)"}),(!S||v)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:E},children:[e.jsx(Ls,{isDone:S,isError:v,color:E}),v&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Hi,{statusColor:E,isDone:S,expanded:o,onToggle:i.toggle,header:j,maxBodyHeight:480,primaryAction:n&&r?()=>r(n):void 0,primaryActionLabel:n?`预览文件 ${Ir(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(Vi,{toolCall:t,loading:i.loadingResult,error:i.resultError,retry:i.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:c}),S&&!v?e.jsx(Sd,{content:x}):S&&v&&e.jsx("div",{style:{fontSize:11,color:"var(--danger)",fontFamily:"var(--font-mono)",padding:"8px 12px",background:"rgba(220,38,38,0.04)",border:"1px solid rgba(220,38,38,0.15)",borderLeft:"3px solid var(--danger)",borderRadius:7},children:x})]})}function Eh({toolCall:t,previewPath:n,onOpenArtifact:r,onLoadResult:s}){const i=qi(t,s),{expanded:o}=i,c=t.arguments.file_path??"",d=t.arguments.old_string??"",u=t.arguments.new_string??"",g=t.isError,f=zs(t),x=f?g?"var(--danger)":"var(--success)":"var(--accent)",y=g?"var(--danger)":f?"var(--text-muted)":"var(--accent)",v=a.useMemo(()=>d&&u?kd(d,u):null,[d,u]),S=a.useMemo(()=>v?{added:v.filter(C=>C.type==="added").length,removed:v.filter(C=>C.type==="removed").length}:null,[v]),E=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(li,{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:c,children:Ir(c)}),S&&e.jsxs("span",{style:{display:"flex",gap:3,fontSize:10,flexShrink:0},children:[S.added>0&&e.jsxs("span",{style:{color:"var(--success)"},children:["+",S.added]}),S.removed>0&&e.jsxs("span",{style:{color:"var(--danger)"},children:["−",S.removed]})]}),(!f||g)&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:x},children:[e.jsx(Ls,{isDone:f,isError:g,color:x}),g&&e.jsx("span",{children:"错误"})]})]});return e.jsxs(Hi,{statusColor:x,isDone:f,expanded:o,onToggle:i.toggle,header:E,maxBodyHeight:480,primaryAction:n&&r?()=>r(n):void 0,primaryActionLabel:n?`预览文件 ${Ir(n)}`:void 0,primaryActionTitle:n?`预览 ${n}`:void 0,children:[e.jsx(Vi,{toolCall:t,loading:i.loadingResult,error:i.resultError,retry:i.loadResult}),e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:c}),v?e.jsx(Cd,{diff:v}):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:d}),e.jsx("pre",{style:{fontSize:11,color:"var(--success)",fontFamily:"var(--font-mono)",padding:"8px 10px",borderRadius:6,background:"rgba(5,150,105,0.04)",border:"1px solid rgba(5,150,105,0.12)",borderLeft:"3px solid var(--success)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:u})]}),g&&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 Ns({label:t,content:n,error:r,maxPreviewLines:s=8,maxPreviewHeight:i=200,maxExpandedHeight:o=2e3}){const[c,d]=a.useState(!1),u=n.split(`
441
- `),g=u.length>s,f=g&&!c?u.slice(0,s).join(`
442
- `)+`
443
- ...`: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?o:i,overflow:"auto",margin:0,lineHeight:1.6},children:f}),g&&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 Mh({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(oi,{label:`agent: ${t.agentName}`,color:"var(--accent)",bg:"var(--accent-dim)"}),e.jsx(oi,{label:`sid: ${(r=t.subSessionId)==null?void 0:r.slice(0,8)}…`,color:"var(--text-muted)",bg:"var(--bg-surface)"})]}),n&&e.jsx(Ns,{label:"任务",content:n,error:!1,maxPreviewLines:3,maxPreviewHeight:80,maxExpandedHeight:2e3})]})}function Ah({raw:t}){const[n,r]=a.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 i=8,o=s.split(`
444
- `),c=o.length>i,d=c&&!n?o.slice(0,i).join(`
445
- `)+`
446
- ...`: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?"收起":`展开全部 (${o.length} 行)`})]})}function Th({activity:t,workspacePath:n,onOpenArtifact:r}){const s=new Map(t.messages.flatMap(i=>i.role==="tool"&&i.toolCallId?[[i.toolCallId,{content:i.content,isError:i.name==="error"}]]:[]));return e.jsxs("div",{className:"native-subagent-activity",children:[e.jsxs("div",{className:"native-subagent-activity__meta",children:[t.elapsedSeconds!==void 0&&e.jsxs("span",{children:[t.elapsedSeconds," 秒"]}),t.toolUses!==void 0&&e.jsxs("span",{children:[t.toolUses," 次工具调用"]}),t.lastToolName&&e.jsxs("span",{children:["正在使用 ",t.lastToolName]})]}),t.messages.map((i,o)=>{var c;return e.jsxs("div",{className:"native-subagent-activity__entry",children:[i.role==="assistant"&&i.content&&e.jsx("pre",{className:"native-subagent-activity__text",children:i.content}),i.role==="assistant"&&((c=i.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(Gi,{toolCall:{...d,...u?{result:u.content,isError:u.isError}:{}},workspacePath:n,onOpenArtifact:r}),u&&e.jsx("pre",{className:`native-subagent-activity__tool-result${u.isError?" native-subagent-activity__tool-result--error":""}`,children:u.content})]},d.id)})),i.role==="tool"&&i.toolCallId&&!t.messages.some(d=>{var u;return(u=d.toolCalls)==null?void 0:u.some(g=>g.id===i.toolCallId)})&&e.jsx(Ns,{label:"工具结果",content:i.content,error:i.name==="error",maxPreviewHeight:180})]},`${i.role}-${o}`)}),t.summary&&e.jsx(Ns,{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(Ls,{isDone:!1,color:"var(--accent)",size:10}),"子 agent 正在工作"]})]})}function Nh({toolCall:t,onSelectSession:n,nativeSubagent:r,previewPaths:s,workspacePath:i,onOpenArtifact:o,onLoadResult:c}){const d=et(de=>de.runningSessionId),u=qi(t,c,!!r),{expanded:g,setExpanded:f}=u,x=t.name==="dispatch_agent",y=t.name==="Agent"&&!!r,v=t.arguments.subAgentStatus,S=t.arguments.subAgentDetail,E=t.arguments.subAgentProgress,C=zs(t);a.useEffect(()=>{x&&!v&&E&&f(!0),y&&(r.messages.length>0||r.summary)&&f(!0)},[x,y,r,v,E]);const I=x?v==="failed":y?r.status==="failed":t.isError,j=x?!!v||C&&!d:y?r.status!=="running":C,k=j?I?"var(--danger)":"var(--success)":"var(--accent)",W=I?"var(--danger)":j?"var(--text-muted)":"var(--accent)",ee=x?null:ua(t.name),N=I?"错误":ee?"":y?r.status==="stopped"?"已停止":j?"已完成":"运行中":x?v==="failed"?"失败":j?"已完成":"运行中":j?"完成":"执行中",T=y?r.description:x?(()=>{const Fe=(t.arguments.task??"").split(`
447
- `)[0];return Fe.length>80?Fe.slice(0,80)+"…":Fe})():Sh(t.name,t.arguments),A=y?`@${r.agentName??"agent"}`:x?`@${t.arguments.agentName??"agent"}`:vd(t.name)??t.name,R=da(t.name),L=!j||!!I||!!N,H=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tool-call-shell__icon",children:e.jsx(li,{name:t.name,color:W})}),e.jsx("span",{className:"tool-call-shell__label",title:ee?t.name:void 0,style:{fontFamily:ee?"var(--font-body)":"var(--font-mono)",fontSize:11.5,color:"var(--text-primary)",fontWeight:600,flexShrink:0},children:A}),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}}),L&&e.jsxs("span",{className:"tool-call-shell__state",style:{color:k},children:[e.jsx(Ls,{isDone:j,isError:!!I,color:k}),N&&e.jsx("span",{children:N})]})]});return e.jsxs(Hi,{statusColor:k,isDone:j,expanded:g,onToggle:u.toggle,header:H,maxBodyHeight:800,primaryAction:s.length===1&&o?()=>o(s[0]):void 0,primaryActionLabel:s.length===1?`预览文件 ${Ir(s[0])}`:void 0,primaryActionTitle:s.length===1?`预览 ${s[0]}`:void 0,children:[e.jsx(Vi,{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(de=>e.jsxs("button",{type:"button",onClick:()=>o==null?void 0:o(de),"aria-label":`预览文件 ${Ir(de)}`,title:`预览 ${de}`,children:[e.jsx(ai,{size:12,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:Ir(de)})]},de))}),y?e.jsx(Th,{activity:r,workspacePath:i,onOpenArtifact:o}):x?e.jsx(Mh,{arguments:t.arguments}):R==="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(Ns,{label:"命令",content:t.arguments.command,maxPreviewLines:6,maxPreviewHeight:160})]}):e.jsx(Ah,{raw:JSON.stringify(t.arguments,null,2)}),t.result&&!x&&!y&&e.jsx(Ns,{label:t.isError?"错误信息":"返回结果",content:t.result,error:t.isError,maxPreviewHeight:240}),x&&v&&S&&e.jsx(Ns,{label:v==="failed"?"错误信息":"执行摘要",content:S,error:v==="failed",maxPreviewHeight:180}),x&&!v&&E&&(!!d||!C)&&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:[E,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:"​"})]})]}),x&&!v&&!E&&!!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(de=>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:`${de*.16}s`}},de)),"等待子 agent 响应..."]}),x&&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:de=>{de.currentTarget.style.background="var(--accent)",de.currentTarget.style.color="white"},onMouseLeave:de=>{de.currentTarget.style.background="var(--accent-dim)",de.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 Id({items:t,onSelectSession:n,workspacePath:r,onOpenArtifact:s,onLoadResult:i}){var S;const[o,c]=a.useState(!1),d=(S=t[0])==null?void 0:S.toolCall,u=d?ua(d.name):null;if(!d||!u||t.length<2)return null;const g=t.every(({toolCall:E})=>zs(E)),f=t.filter(({toolCall:E})=>E.isError).length,x=f>0?"var(--danger)":g?"var(--text-muted)":"var(--accent)",y=vd(d.name)??u.done,v=`${y},${t.length} 项,${o?"收起":"展开"}`;return e.jsxs("div",{className:"tool-call-group",children:[e.jsxs("button",{type:"button",className:"tool-call-group__summary","aria-expanded":o,"aria-label":v,onClick:()=>c(E=>!E),children:[e.jsx("span",{className:"tool-call-group__icon","aria-hidden":"true",children:e.jsx(li,{name:d.name,color:x})}),e.jsx("span",{className:"tool-call-group__label",children:y}),e.jsxs("span",{className:"tool-call-group__count",children:[t.length," 项"]}),e.jsx("span",{className:"tool-call-group__spacer"}),f>0&&e.jsxs("span",{className:"tool-call-group__error",children:[f," 项失败"]}),!g&&e.jsx(Ls,{isDone:!1,color:x,size:11}),e.jsx(Ur,{className:"tool-call-group__chevron",size:13,strokeWidth:2.2,"aria-hidden":"true"})]}),o&&e.jsx("div",{className:"tool-call-group__items",children:t.map(({toolCall:E,beforeContent:C,progress:I,nativeSubagent:j})=>e.jsx(Gi,{toolCall:E,beforeContent:C,progress:I,nativeSubagent:j,onSelectSession:n,workspacePath:r,onOpenArtifact:s,onLoadResult:i},E.id))})]})}function _h(t,n){if(da(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=>gd(s,n)).filter(s=>!!s))]}function Gi({toolCall:t,onSelectSession:n,beforeContent:r,progress:s,nativeSubagent:i,workspacePath:o,onOpenArtifact:c,onLoadResult:d}){const u=c?_h(t,o):[],g=t.name==="write_file"?e.jsx(Ih,{toolCall:t,beforeContent:r,previewPath:u[0],onOpenArtifact:c,onLoadResult:d}):t.name==="read_file"?e.jsx(Rh,{toolCall:t,previewPath:u[0],onOpenArtifact:c,onLoadResult:d}):t.name==="str_replace"?e.jsx(Eh,{toolCall:t,previewPath:u[0],onOpenArtifact:c,onLoadResult:d}):e.jsx(Nh,{toolCall:t,onSelectSession:n,nativeSubagent:i,previewPaths:u,workspacePath:o,onOpenArtifact:c,onLoadResult:d});return e.jsxs("div",{className:"tool-call-with-progress",children:[g,s&&e.jsx(wd,{progress:s,compact:!0})]})}function zh({question:t,options:n,fields:r,multiSelect:s,answered:i,answer:o,onAnswer:c}){const[d,u]=a.useState(new Set),[g,f]=a.useState(""),[x,y]=a.useState({}),v=a.useRef(!1),[S,E]=a.useState(!1),[C,I]=a.useState(""),j=async(R,L)=>{if(!(i||v.current)){v.current=!0,E(!0),I("");try{await c(R,L)}catch(H){I(H instanceof Error?H.message:"回答发送失败,请重试。")}finally{v.current=!1,E(!1)}}},k=!!(n!=null&&n.length),W=!!(r!=null&&r.length),ee=R=>{i||u(L=>{const H=new Set(L);return s?H.has(R)?H.delete(R):H.add(R):(H.clear(),H.add(R)),H})},N=()=>{if(d.size===0)return;const R=Array.from(d).map(L=>n[L].label);j(R.join(", "),Array.from(d))},T=()=>{const R=Array.from(d).map(H=>n[H].label),L=Object.fromEntries((r??[]).map(H=>{var de;return[H.name,((de=x[H.name])==null?void 0:de.trim())??""]}));!L.model&&R.length>0&&(L.model=R[0]),!(!Object.values(L).some(Boolean)&&R.length===0)&&j(JSON.stringify({fields:L,selectedOptions:R}),Array.from(d))},A=()=>{g.trim()&&j(g.trim())};return e.jsxs("div",{style:{marginBottom:12},children:[C&&!i&&e.jsx("div",{role:"alert",style:{color:"var(--danger)",marginBottom:8},children:C}),S&&e.jsx("div",{role:"status",children:"正在发送回答…"}),e.jsxs("div",{style:{borderRadius:12,border:"1px solid",borderColor:i?"var(--border-subtle)":"rgba(79,110,247,0.35)",background:i?"var(--bg-deep)":"linear-gradient(135deg, rgba(79,110,247,0.04) 0%, var(--bg-deep) 100%)",overflow:"hidden",transition:"border-color 0.2s ease"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",borderBottom:i?"1px solid var(--border-subtle)":"1px solid rgba(79,110,247,0.15)"},children:[e.jsx("div",{style:{width:24,height:24,borderRadius:6,background:i?"var(--bg-surface)":"rgba(79,110,247,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:i?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),e.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:i?"var(--text-muted)":"var(--accent)",flex:1},children:i?"已回答":"向你提问"}),s&&!i&&e.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:10,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:500},children:"可多选"})]}),e.jsx("div",{style:{padding:"12px 14px 8px",fontSize:13,color:"var(--text-primary)",lineHeight:1.6,fontWeight:500,whiteSpace:"pre-wrap"},children:t}),i&&e.jsxs("div",{style:{padding:"6px 14px 12px",fontSize:12,color:"var(--text-secondary)"},children:[e.jsx("span",{style:{fontWeight:500},children:"回答:"}),W?"配置已提交(敏感字段已隐藏)":o]}),k&&!i&&e.jsxs("div",{style:{padding:"4px 14px 6px",display:"flex",flexDirection:"column",gap:6},children:[n.map((R,L)=>{const H=d.has(L);return e.jsxs("button",{onClick:()=>ee(L),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"9px 12px",borderRadius:8,border:"1px solid",borderColor:H?"var(--accent)":"var(--border-subtle)",background:H?"rgba(79,110,247,0.06)":"var(--bg-surface)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-body)",transition:"all 0.15s ease",width:"100%"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:s?4:8,border:`2px solid ${H?"var(--accent)":"var(--border-subtle)"}`,background:H?"var(--accent)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"all 0.15s ease"},children:H&&e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:H?600:500,color:H?"var(--text-primary)":"var(--text-secondary)"},children:R.label}),R.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2,lineHeight:1.4},children:R.description})]})]},L)}),!W&&e.jsx("button",{onClick:N,disabled:S||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:"确认选择"})]}),W&&!i&&e.jsxs("div",{style:{padding:"6px 14px 12px",display:"flex",flexDirection:"column",gap:10},children:[r.map(R=>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:R.label}),e.jsx("input",{type:R.type==="secret"?"password":"text",value:x[R.name]??"",onChange:L=>y(H=>({...H,[R.name]:L.target.value})),placeholder:R.description,autoComplete:R.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"}}),R.description&&e.jsx("span",{style:{fontSize:10.5,color:"var(--text-muted)",lineHeight:1.4},children:R.description})]},R.name)),e.jsx("button",{onClick:T,disabled:S,style:{padding:"8px 16px",borderRadius:8,border:"none",background:"var(--accent)",color:"white",cursor:"pointer",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",alignSelf:"flex-end"},children:"确认配置"})]}),!i&&!W&&e.jsxs("div",{style:{padding:"4px 14px 12px",display:"flex",gap:8,borderTop:k?"1px solid var(--border-subtle)":"none",marginTop:k?2:0},children:[e.jsx("input",{type:"text",value:g,onChange:R=>f(R.target.value),onKeyDown:R=>{R.key==="Enter"&&!R.shiftKey&&(R.preventDefault(),A())},placeholder:k?"或输入自定义回答…":"输入你的回答…",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:R=>{R.currentTarget.style.borderColor="var(--accent)"},onBlur:R=>{R.currentTarget.style.borderColor="var(--border-subtle)"}}),e.jsx("button",{onClick:A,disabled:S||!g.trim(),style:{padding:"8px 16px",borderRadius:8,border:"none",background:g.trim()?"var(--accent)":"var(--bg-surface)",color:g.trim()?"white":"var(--text-muted)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:600,fontFamily:"var(--font-body)",transition:"all 0.15s ease"},children:"发送"})]})]})]})}const vo={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"}},wo={system:{label:"系统",color:"#8b5cf6"},messages:{label:"消息",color:"#4f6ef7"},tools:{label:"工具",color:"#f59e0b"},images:{label:"图片",color:"#ec4899"},overhead:{label:"协议开销",color:"#94a3b8"}},ql=["system","messages","tools","images","overhead"];function Lh(t,n){const r=(t==null?void 0:t.maxTokens)??Math.max(1,n*1e3),s=(t==null?void 0:t.totalTokens)??0,i=Object.fromEntries(ql.map(u=>[u,0]));for(const u of(t==null?void 0:t.segments)??[]){const g=vo[u.category];g&&(i[g.group]+=u.tokens)}const o=Math.min(s/r,1),c=o*100,d=c===0?"0%":c<1?`${c.toFixed(2)}%`:c<10?`${c.toFixed(1)}%`:`${Math.round(c)}%`;return{hasUsage:!!t,totalTokens:s,maxTokens:r,ratio:o,percent:Math.round(o*100),percentLabel:d,groups:ql.map(u=>({key:u,label:wo[u].label,color:wo[u].color,tokens:i[u]})),details:((t==null?void 0:t.segments)??[]).filter(u=>u.tokens>0).map(u=>{var g,f;return{category:u.category,label:((g=vo[u.category])==null?void 0:g.label)??u.category,color:wo[((f=vo[u.category])==null?void 0:f.group)??"overhead"].color,tokens:u.tokens}}),requestLabel:t?`${t.providerId} · ${t.modelId} · 第 ${t.requestIndex} 次请求`:void 0}}function Go(t){return t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${t}`}function Vl(t,n){return n?t.percentLabel:t.hasUsage?`${Go(t.totalTokens)} / ${Go(t.maxTokens)} · ${t.percentLabel}`:"尚无模型请求"}function Ph({usage:t,contextWindowK:n,compact:r=!1}){const[s,i]=a.useState(!1),[o,c]=a.useState(null),d=a.useRef(null),u=a.useMemo(()=>Lh(t,n),[t,n]),g=u.ratio>=.85?"var(--danger)":u.ratio>=.6?"#f59e0b":"var(--accent)",f=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 y;const x=((y=d.current)==null?void 0:y.getBoundingClientRect())??null;c(x),i(v=>!v)},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?g:"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:Vl(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(x=>e.jsx("div",{style:{width:`${Math.max(0,Math.min(x.tokens/u.maxTokens*100,100))}%`,background:x.color,opacity:x.key==="overhead"?.65:1,minWidth:x.tokens>0?1:0}},x.key))}),e.jsx("span",{className:"context-usage-ribbon__summary",style:{fontSize:11,color:u.hasUsage?g:"var(--text-muted)",fontVariantNumeric:"tabular-nums",minWidth:110,textAlign:"right"},children:Vl(u,!1)})]})}),s&&o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>i(!1),style:{position:"fixed",inset:0,zIndex:9998,background:"transparent"}}),e.jsxs("div",{style:{position:"fixed",left:r?Math.min(Math.max(8,o.left),Math.max(8,f-Math.min(340,f-16)-8)):Math.max(8,o.left),top:o.top-8,transform:"translateY(-100%)",width:Math.min(r?340:o.width,f-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?g:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:u.hasUsage?u.percentLabel:"暂无"})]}),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(x=>{const y=u.totalTokens>0?Math.round(x.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:x.color}}),e.jsx("span",{style:{flex:1,fontSize:12,color:"var(--text-secondary)"},children:x.label}),e.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[Go(x.tokens)," · ",y,"%"]})]},x.category)})}):e.jsx("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:"发送第一条消息后,将显示最新一次模型请求的完整上下文组成。"})]})]})]})}function Dh({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(ea,{size:17,strokeWidth:1.8})}),e.jsxs("span",{children:["思考中",e.jsx(pa,{startedAt:t})]})]})}function Rd({sections:t,streaming:n=!1,startedAt:r,renderContent:s}){const i=a.useMemo(()=>[...t].sort((g,f)=>g.sectionIndex-f.sectionIndex).map(g=>g.text.trim()).filter(Boolean).join(`
448
-
449
- `),[t]),o=a.useMemo(()=>(i.split(`
450
- `).find(f=>f.trim())??"").replace(/^#{1,6}\s+/,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1"),[i]),[c,d]=a.useState(n);if(a.useEffect(()=>{d(n)},[n]),!i)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(g=>!g),children:[e.jsx("span",{className:"reasoning-summary__brain","aria-hidden":"true",children:e.jsx(ea,{size:17,strokeWidth:1.8})}),e.jsxs("span",{className:"reasoning-summary__label",children:[u,n&&r!==void 0&&e.jsx(pa,{startedAt:r})]}),!c&&e.jsx("span",{className:"reasoning-summary__preview",children:o}),e.jsx("span",{className:"reasoning-summary__spacer"}),n&&e.jsx(lt,{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(i)})]})}function Ed(t){var r,s;const n=Object.keys(t.presentation??{});return t.role==="assistant"&&!!((r=t.toolCalls)!=null&&r.length)&&!t.isCompactionSummary&&!t.widget&&!t.askUser&&!((s=t.images)!=null&&s.length)&&n.every(i=>i==="executionTrace")}function Wh(t){return Ed(t)&&t.content.trim().length===0}function Md(t){const n=[];for(const r of t){const s=n[n.length-1];if(s&&Ed(s)&&Wh(r)){n[n.length-1]={...s,toolCalls:[...s.toolCalls,...r.toolCalls],timestamp:r.timestamp};continue}n.push(r)}return n}function Ad(t){const n=[];for(const r of t){const s=kh(r.toolCall.name),i=n[n.length-1];s&&(i==null?void 0:i.action)===s?i.items.push(r):n.push({action:s,items:[r]})}return n}function Bh({trace:t,loadTrace:n,loadToolResult:r,renderContent:s,runtimeProgress:i,nativeSubagents:o,onSelectSession:c,workspacePath:d,onOpenArtifact:u,refreshSignal:g=0,autoLoad:f=!1}){const x=t.segmentIndex??0,y=`${t.turnId}:${x}`,v=a.useRef(y),S=a.useRef(t.revision),E=a.useRef(g),C=a.useRef(null),[I,j]=a.useState(!1),[k,W]=a.useState(null),[ee,N]=a.useState(null);a.useEffect(()=>{v.current=y,C.current=null,j(!1),W(null),N(null),E.current=g},[y]),a.useEffect(()=>{S.current=t.revision,C.current=null,j(!1),W(fe=>(fe==null?void 0:fe.map(je=>{var ze;return{...je,toolCalls:(ze=je.toolCalls)==null?void 0:ze.map(Ge=>Ge.resultRef?{...Ge,resultRef:{...Ge.resultRef,revision:t.revision}}:Ge)}}))??null)},[t.revision]);const T=t.liveMessages??[],A=a.useMemo(()=>lf(k??[],x),[k,x]),R=a.useMemo(()=>pf(A,T),[T,A]),L=k!==null||T.length>0,H=a.useCallback(async(fe=!1)=>{if(!fe&&k)return k;if(!fe&&T.length>0)return T;if(C.current)return C.current;const je=y,ze=t.revision;j(!0),N(null);const Ge=n(t);C.current=Ge;try{const Ke=await Ge;return v.current===je&&S.current===ze&&W(Ke),Ke}catch(Ke){throw v.current===je&&S.current===ze&&N(Ke instanceof Error?Ke.message:"执行过程加载失败"),Ke}finally{v.current===je&&S.current===ze&&(C.current=null,j(!1))}},[T,n,k,y,t]);a.useEffect(()=>{!f||L||H().catch(()=>{})},[f,H,L]),a.useEffect(()=>{!L&&!f||g===0||E.current!==g&&(E.current=g,H(!0).catch(()=>{}))},[f,H,L,g]);const de=a.useCallback(async fe=>{const je=await r(fe);v.current===y&&W(ze=>ze&&ad(ze,fe.itemId,je.content,je.isError))},[r,y]),Fe=I?"正在加载执行过程":ee?"重新加载执行过程":"查看执行过程";return e.jsx("div",{className:"codex-execution-trace","data-turn-id":t.turnId,children:L?e.jsx(Fh,{messages:R,renderContent:s,runtimeProgress:i,nativeSubagents:o,onSelectSession:c,workspacePath:d,onOpenArtifact:u,onLoadResult:de}):f&&!ee?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(lt,{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":I||void 0,disabled:I,onClick:()=>void H().catch(()=>{}),children:[e.jsx("span",{className:"codex-execution-trace__icon","aria-hidden":"true",children:I?e.jsx(lt,{size:14,strokeWidth:2}):ee?e.jsx(zc,{size:14,strokeWidth:2}):e.jsx(xp,{size:14,strokeWidth:1.8})}),e.jsx("span",{className:"codex-execution-trace__label",children:Fe}),ee&&e.jsx("span",{className:"codex-execution-trace__error",children:"加载失败"})]})})}function Fh({messages:t,renderContent:n,runtimeProgress:r,nativeSubagents:s,onSelectSession:i,workspacePath:o,onOpenArtifact:c,onLoadResult:d}){const u=a.useMemo(()=>{const g=new Map;return Md(t).map(f=>{const x=(f.toolCalls??[]).map(y=>{const v=typeof y.arguments.file_path=="string"?y.arguments.file_path:void 0,S=y.name==="write_file"&&v?g.get(v):void 0;return y.name==="read_file"&&v&&y.result!==void 0&&!y.isError&&g.set(v,y.result),{toolCall:y,beforeContent:S,progress:od(r,y.id),nativeSubagent:s[y.id]}});return{message:f,toolGroups:Ad(x)}})},[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:g,toolGroups:f})=>{var x,y,v;return e.jsxs("div",{className:"codex-execution-trace__item",children:[(y=(x=g.presentation)==null?void 0:x.reasoning)!=null&&y.length?e.jsx(Rd,{sections:g.presentation.reasoning,renderContent:n}):null,((v=g.presentation)==null?void 0:v.agentMessagePhase)==="commentary"&&g.content?e.jsx("div",{className:"codex-execution-trace__commentary",children:n(g.content)}):null,f.map(S=>S.action&&S.items.length>1?e.jsx(Id,{items:S.items,onSelectSession:i,workspacePath:o,onOpenArtifact:c,onLoadResult:d},`group-${S.items[0].toolCall.id}`):e.jsx(Gi,{toolCall:S.items[0].toolCall,beforeContent:S.items[0].beforeContent,progress:S.items[0].progress,nativeSubagent:S.items[0].nativeSubagent,onSelectSession:i,workspacePath:o,onOpenArtifact:c,onLoadResult:d},S.items[0].toolCall.id))]},g.id)})})}function Oh(t){return t.supported?t.needsSetup||t.status.enabled&&(t.status.permissionScreen!=="granted"||t.status.accessibilityTrusted!==!0):!1}function $h(t){const[n,r]=a.useState(!1);return a.useEffect(()=>{if(!t)return;const s=window.agentApi;if(!(s!=null&&s.desktopLiveSetup)||!(s!=null&&s.onDesktopLiveStatus))return;let i=!0,o=null,c=null;const d=()=>{i&&o&&c&&r(Oh({...o,status:c}))},u=()=>void s.desktopLiveSetup().then(f=>{i&&(o={supported:f.supported,needsSetup:f.needsSetup},d())}).catch(()=>{});u();const g=s.onDesktopLiveStatus(f=>{c=f,o!=null&&o.needsSetup&&f.enabled&&f.permissionScreen==="granted"&&f.accessibilityTrusted===!0&&u(),d()});return()=>{i=!1,g()}},[t]),n}function Uh({appearanceOpen:t,settingsOpen:n,showSettings:r=!0,hideToBackgroundTitle:s="隐藏到后台",codexReleaseState:i="idle",onHideToBackground:o,onReleaseCodex:c,onOpenHub:d,onOpenDesktopLive:u,desktopLiveOpen:g=!1,filesOpen:f=!1,onToggleFiles:x,onToggleAppearance:y,onOpenSettings:v}){const S=$h(!!u),E=i==="releasing"?"正在停止 AgentRoam 使用此会话":i==="released"?"已停止在 AgentRoam 中使用;Codex Desktop 最长约 30 分钟后可用":"停止在 AgentRoam 中使用(Codex Desktop 最长约 30 分钟后可用)";return e.jsxs("div",{className:"chat-header-actions",style:{WebkitAppRegion:"no-drag"},children:[u&&e.jsxs("button",{type:"button",onClick:u,title:S?"桌面直播与远程控制(待授权)":"桌面直播与远程控制","aria-label":"桌面直播与远程控制","aria-expanded":g,className:`ui-icon-button chat-header-action ${g?"is-active":""}`,style:{position:"relative"},children:[e.jsx(np,{size:15,"aria-hidden":"true"}),S&&e.jsx("span",{"data-desktop-live-pending":"","aria-hidden":"true",style:{position:"absolute",top:5,right:5,width:7,height:7,borderRadius:"50%",background:"var(--warning, #f59e0b)",border:"1px solid var(--bg-surface, #fff)"}})]}),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(Vu,{size:15,"aria-hidden":"true"})}),x&&e.jsx("button",{type:"button",onClick:x,title:"我的文件","aria-label":"我的文件","aria-expanded":f,className:`ui-icon-button chat-header-action chat-header-action--files ${f?"is-active":""}`,children:e.jsx(sp,{size:15,"aria-hidden":"true"})}),c&&e.jsx("button",{type:"button",onClick:c,title:E,"aria-label":E,disabled:i!=="idle",className:`ui-icon-button chat-header-action chat-header-action--codex-release is-${i}`,children:i==="releasing"?e.jsx(lt,{size:15,className:"spin","aria-hidden":"true"}):i==="released"?e.jsx($r,{size:15,"aria-hidden":"true"}):e.jsx(Gc,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:o,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:C=>y(C.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:v,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"})]})})]})}function Gl({label:t,title:n,value:r,busy:s,disabled:i,compact:o,onChange:c,children:d}){return e.jsxs("span",{className:`live-view-select${o?" live-view-select--compact":""}`,children:[e.jsx("select",{"aria-label":t,"aria-busy":s,title:n,value:r,disabled:i||s,onChange:u=>c(u.target.value),children:d}),s?e.jsx("span",{className:"live-view-select-icon",role:"status","aria-label":`${t}正在切换`,children:e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"})}):e.jsx(Li,{size:14,className:"live-view-select-icon","aria-hidden":"true"})]})}const Hh=5e3,qh=1e4;class Vh{constructor(){this.startedAt=null,this.lastFrameAt=null,this.lastFrameCount=null}begin(n){this.startedAt=n,this.lastFrameAt=null,this.lastFrameCount=null}observe(n,r){typeof n!="number"||!Number.isFinite(n)||this.lastFrameCount!==null&&n===this.lastFrameCount||(this.lastFrameCount=n,this.lastFrameAt=r)}evaluate(n){const r=this.lastFrameAt??this.startedAt;if(r===null)return{state:"streaming",silentForMs:0};const s=Math.max(0,n-r),i=this.lastFrameAt===null?Hh:qh;return{state:s>=i?"stalled":"streaming",silentForMs:s}}}var $i,Td;class Gh{constructor(){Za(this,$i);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=el(this,$i,Td).call(this)}move(n,r){const s=this.points.get(n);if(!s)return null;const i=[...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 o=[...this.points.values()],c=f=>({x:(f[0].x+f[1].x)/2,y:(f[0].y+f[1].y)/2}),d=f=>Math.hypot(f[0].x-f[1].x,f[0].y-f[1].y),u=d(i),g=this.originDistance>0?d(o)/this.originDistance:1;return{scale:u>0?d(o)/u:1,distanceRatio:g,from:c(i),to:c(o),pointers:this.points.size}}up(n,r,s=!1){if(!this.points.has(n))return!1;const i=!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(),i}}$i=new WeakSet,Td=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 Zn=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0;function Kh(t){var r,s,i;const n=new Set;for(const o of t??[]){if(((r=o.mimeType)==null?void 0:r.toLowerCase())!=="video/h264")continue;const c=(i=(s=/(?:^|;)\s*profile-level-id=([0-9a-f]{6})/i.exec(o.sdpFmtpLine??""))==null?void 0:s[1])==null?void 0:i.toLowerCase();c!=null&&c.startsWith("64")&&n.add("high"),(!c||c.startsWith("42"))&&n.add("baseline")}return[...n]}function Qh(){var n;if(typeof RTCRtpReceiver>"u"||typeof RTCRtpReceiver.getCapabilities!="function")return["baseline"];const t=Kh((n=RTCRtpReceiver.getCapabilities("video"))==null?void 0:n.codecs);return t.length?t:["baseline"]}function Xh(t){var r,s;const n=(s=(r=/(?:^|;)\s*profile-level-id=([0-9a-f]{6})/i.exec(typeof t=="string"?t:""))==null?void 0:r[1])==null?void 0:s.toLowerCase();if(n!=null&&n.startsWith("64"))return"high";if(!n||n.startsWith("42"))return"baseline"}function Yh(t,n,r=Date.now()){const i=[...typeof t.values=="function"?t.values():t],o=i.find(H=>H.type==="inbound-rtp"&&(H.kind==="video"||H.mediaType==="video"));if(!o)return null;const c=i.find(H=>H.id===o.codecId),d=i.find(H=>H.type==="candidate-pair"&&H.state==="succeeded"&&(H.nominated===!0||H.selected===!0)),u=i.find(H=>H.id===(d==null?void 0:d.localCandidateId)),g=i.find(H=>H.id===(d==null?void 0:d.remoteCandidateId)),f=[u==null?void 0:u.candidateType,g==null?void 0:g.candidateType].map(String),x=["relay","srflx","prflx","host"].find(H=>f.includes(H))??void 0,y=Zn(o.bytesReceived)??0,v=Zn(o.packetsReceived)??0,S=Zn(o.packetsLost)??0,E=Zn(o.framesDropped)??0,C=n?Math.max(1,r-n.at):0,I=n?Math.max(0,v-n.packetsReceived):0,j=n?Math.max(0,S-n.packetsLost):0,k=n?Math.max(0,E-n.framesDropped):0,W=Zn(d==null?void 0:d.currentRoundTripTime),ee=Zn(o.jitter),N=typeof o.decoderImplementation=="string"?o.decoderImplementation.slice(0,120):void 0,T=typeof o.powerEfficientDecoder=="boolean"?o.powerEfficientDecoder:void 0,A=N!==void 0||T!==void 0?{implementation:N,powerEfficient:T,acceleration:T===!0?"hardware":T===!1?"software":"unknown"}:void 0,R={codec:typeof(c==null?void 0:c.mimeType)=="string"?c.mimeType.replace(/^video\//i,""):void 0,codecProfile:Xh(c==null?void 0:c.sdpFmtpLine),decoder:A,width:Zn(o.frameWidth),height:Zn(o.frameHeight),fps:Zn(o.framesPerSecond),rttMs:W!==void 0?W*1e3:void 0,jitterMs:ee!==void 0?ee*1e3:void 0,lossRate:I+j>0?j/(I+j):0,droppedFrames:k,receiveBitrate:n?Math.max(0,Math.round((y-n.bytesReceived)*8e3/C)):void 0,availableBitrate:Zn(d==null?void 0:d.availableIncomingBitrate),candidateType:x,protocol:(u==null?void 0:u.protocol)==="tcp"||(g==null?void 0:g.protocol)==="tcp"?"tcp":d?"udp":void 0};for(const H of Object.keys(R))R[H]===void 0&&delete R[H];const L=Zn(o.framesDecoded);return{sample:R,cursor:{at:r,bytesReceived:y,packetsReceived:v,packetsLost:S,framesDropped:E,...L!==void 0?{framesDecoded:L}:{}}}}function Jh(t){if(!t)return null;const n=[t.candidateType==="relay"?"TURN 中继":t.candidateType?"P2P 直连":null];return t.codec&&n.push(t.codec),t.width&&t.height&&n.push(`${t.width}x${t.height}${t.fps?`@${Math.round(t.fps)}`:""}`),t.receiveBitrate&&n.push(`${(t.receiveBitrate/1e6).toFixed(1)}Mbps`),t.rttMs!==void 0&&n.push(`${Math.round(t.rttMs)}ms`),n.filter(Boolean).join(" · ")||null}function Zh(t){const n=t==null?void 0:t.decoder;if(!n)return null;const r=n.acceleration==="hardware"?"硬件解码":n.acceleration==="software"?"软件解码":"解码方式未知";return n.implementation?`${r} · ${n.implementation}`:r}const eg={"agent-controlled":"Agent 操作中","handoff-requested":"正在交接","user-controlled":"你正在操作","return-requested":"正在归还",resyncing:"Agent 正在同步页面"},tg={smooth:"流畅",hd:"高清",original:"原画"};function jo(t){return t==="desktop"?"桌面屏幕":t==="ego-browser"?"ego-browser":"内置 Browser"}function Kl(t,n,r){var s,i;return t||(((s=n.find(o=>o.agentSessionId===r))==null?void 0:s.id)??((i=n[0])==null?void 0:i.id)??null)}function Ql(t){return[t.altKey?"Alt":"",t.ctrlKey?"Control":"",t.metaKey?"Meta":"",t.shiftKey?"Shift":""].filter(Boolean)}function ng(t){const n=new Uint8Array(t.length*2),r=new DataView(n.buffer);for(let i=0;i<t.length;i+=1){const o=Math.max(-1,Math.min(1,t[i]));r.setInt16(i*2,o<0?o*32768:o*32767,!0)}let s="";for(let i=0;i<n.length;i+=8192)s+=String.fromCharCode(...n.subarray(i,i+8192));return btoa(s)}function rg(t,n){const r=atob(t),s=Math.floor(r.length/2/n),i=Array.from({length:n},()=>new Float32Array(s));for(let o=0;o<s;o+=1)for(let c=0;c<n;c+=1){const d=(o*n+c)*2,u=r.charCodeAt(d)|r.charCodeAt(d+1)<<8;i[c][o]=(u&32768?u-65536:u)/32768}return i}async function sg(t){const n=[],r=()=>{for(const i of n.splice(0))i()};let s=!1;t.addEventListener("abort",r);try{if(t.aborted)return null;const i=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1});if(n.push(()=>{for(const y of i.getTracks())y.stop()}),t.aborted)return null;const o=window.AudioContext,c=new o({latencyHint:"interactive"});n.push(()=>{c.close().catch(()=>{})});const d=new o({latencyHint:"interactive"});if(n.push(()=>{d.close().catch(()=>{})}),await Promise.all([c.resume(),d.resume()]),t.aborted)return null;const u=d.createGain();u.connect(d.destination);const g=c.createMediaStreamSource(i),f=c.createScriptProcessor(2048,1,1),x=c.createGain();return x.gain.value=0,g.connect(f),f.connect(x),x.connect(c.destination),s=!0,{stream:i,microphoneContext:c,remoteContext:d,remoteGain:u,source:g,processor:f,sink:x,dispose:r}}finally{t.removeEventListener("abort",r),s||r()}}function ig(t,n){return t?t.state==="user-controlled"&&t.isController===!0&&n.state==="handoff-requested"||t.state==="agent-controlled"&&n.state==="return-requested":!1}const og=2;function ag(t,n,r,s,i=.02){if(!t||!n||!n.width||!n.height)return!1;const o=t.x/n.width-i,c=t.y/n.height-i,d=(t.x+t.w)/n.width+i,u=(t.y+t.h)/n.height+i;return r>=o&&r<=d&&s>=c&&s<=u}function lg(t,n,r=og){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 cg({open:t,agentSessionId:n,onClose:r}){const s=a.useContext(Au),i=typeof window>"u"?void 0:window.browserLiveApi,o=a.useRef(null),[c,d]=a.useState(!1),u=async()=>{const b=o.current;if(b){if(c){document.fullscreenElement===b&&await document.exitFullscreen().catch(()=>{}),d(!1);return}d(!0),b.requestFullscreen&&await b.requestFullscreen().catch(()=>{})}};a.useEffect(()=>{if(!t){d(!1);return}const b=o.current,M=()=>d(document.fullscreenElement===b),F=ie=>{ie.key==="Escape"&&(document.fullscreenElement===b||b!=null&&b.classList.contains("is-fullscreen"))&&(ie.preventDefault(),ie.stopPropagation(),document.fullscreenElement===b&&document.exitFullscreen().catch(()=>{}),d(!1))};return document.addEventListener("fullscreenchange",M),document.addEventListener("keydown",F,!0),()=>{document.removeEventListener("fullscreenchange",M),document.removeEventListener("keydown",F,!0),b&&document.fullscreenElement===b&&document.exitFullscreen().catch(()=>{})}},[t]);const[g,f]=a.useState([]),[x,y]=a.useState(null),[v,S]=a.useState(null),[E,C]=a.useState("hd"),[I,j]=a.useState(null),[k,W]=a.useState(null),[ee,N]=a.useState(!1),[T,A]=a.useState(0),[R,L]=a.useState(null),[H,de]=a.useState(!1),[Fe,fe]=a.useState(null),[je,ze]=a.useState(!1),[Ge,Ke]=a.useState(""),[Ct,it]=a.useState(!1),[te,ge]=a.useState(null),[Qe,B]=a.useState(1),[G,Y]=a.useState(!1),[ae,me]=a.useState({width:0,height:0}),le=a.useRef(null),Se=a.useRef(null),Te=a.useRef(!1),mt=a.useRef(null),$e=a.useRef(new Gh),yt=a.useRef(Qe),st=a.useRef(null);a.useLayoutEffect(()=>{yt.current=Qe;const b=st.current,M=le.current,F=M==null?void 0:M.querySelector(".browser-live-image-hit-area");if(!b||!M||!F)return;const ie=F.getBoundingClientRect();M.scrollLeft+=ie.left+b.x*ie.width-b.clientX,M.scrollTop+=ie.top+b.y*ie.height-b.clientY,st.current=null},[Qe]);const tt=a.useRef(null),[It,ft]=a.useState(!1),P=a.useRef(!1),K=a.useRef(null),X=a.useRef(0);a.useEffect(()=>{t||(ze(!1),Ke(""),ge(null))},[t]);const[J,ne]=a.useState(!1),ct=a.useRef(null),ht=a.useRef(0),ot=a.useRef("none"),Ue=a.useRef(null),$t=a.useRef(null),[tn,Xe]=a.useState(null),[pt,Dt]=a.useState(!1),Bt=a.useRef(null),gn=a.useRef(null),[Ut,Re]=a.useState("off"),[Tn,Nn]=a.useState(null),_n=a.useRef(null),Z=a.useRef(null),_t=a.useRef(0),Xt=a.useRef(null),Tt=a.useRef(new Vh),[Et,at]=a.useState("idle"),[Ft,qt]=a.useState(!1),[zt,Sn]=a.useState(!1),tr=a.useRef(!1),Qn=a.useRef(!1),Cn=a.useRef(null),Un=a.useRef(null),Yt=a.useRef(null),Xn=a.useRef(null),mn=a.useRef(null),Ie=a.useRef(null),xt=a.useRef(null),Vt=a.useRef(0),Yn=a.useRef(0),Hn=a.useRef(0),on=a.useRef(null);a.useLayoutEffect(()=>{P.current=It,It&&ne(!1)},[It]);const O=a.useMemo(()=>g.find(b=>b.id===x)??null,[x,g]),Ye=(O==null?void 0:O.backend)==="desktop",qn=Ye&&(O==null?void 0:O.platform)==="win32",Ot=(O==null?void 0:O.availability)==="unavailable"&&(O==null?void 0:O.capabilityErrorCode)==="desktop-locked",q=(O==null?void 0:O.isController)&&O.state==="user-controlled",re=O==null?void 0:O.audioCapabilities,ce=!!(re!=null&&re.fullDuplex&&re.systemAudio&&re.microphonePlayback&&re.selfPlaybackExclusion),Ce=!!(O!=null&&O.online&&O.availability==="ready"&&!O.controlledByAnotherViewer);a.useEffect(()=>{if(!t||!i||!x){Xe(null);return}let b=!0;const M=()=>{const ie=performance.now();i.request("browser:ping",{t:ie}).then(()=>{b&&Xe(Math.round(performance.now()-ie))}).catch(()=>{b&&Xe(null)})};M();const F=window.setInterval(M,3e3);return()=>{b=!1,window.clearInterval(F),Xe(null)}},[i,t,x]),a.useEffect(()=>{const b=navigator;if(!q||!b.wakeLock)return;let M=!1,F=null;return b.wakeLock.request("screen").then(ie=>{if(M){ie.release();return}F=ie,Bt.current=ie}).catch(()=>{}),()=>{M=!0,F==null||F.release().catch(()=>{}),Bt.current=null}},[q]);const He=(k==null?void 0:k.viewport)??(O==null?void 0:O.viewport),xn=He&&ae.width&&ae.height?Math.min(ae.width/He.width,ae.height/He.height):null;a.useEffect(()=>{var b;B(1),Y(!1),Se.current=null,$e.current.reset(),st.current=null,K.current=null,gn.current=null,(b=le.current)==null||b.scrollTo(0,0)},[t,x]),a.useEffect(()=>{const b=le.current;if(!t||!b)return;const M=new ResizeObserver(()=>{me({width:b.clientWidth,height:b.clientHeight})});return M.observe(b),()=>M.disconnect()},[t,Ye]),a.useEffect(()=>{const b=le.current;if(!t||!b||!q||G)return;const M=F=>F.preventDefault();return b.addEventListener("wheel",M,{passive:!1}),()=>b.removeEventListener("wheel",M)},[t,q,G]);const Jn=a.useCallback(()=>{const b=tt.current;b&&(It?(b.blur(),ft(!1)):(b.focus({preventScroll:!0}),ft(!0)))},[It]);a.useEffect(()=>{var b;(!q||G)&&It&&((b=tt.current)==null||b.blur(),ft(!1))},[q,G,It]);const Lt=a.useCallback(b=>{const M=(k==null?void 0:k.viewport)??(O==null?void 0:O.viewport),F=le.current,ie=F==null?void 0:F.querySelector(".browser-live-image-hit-area");if(!b||!M||!F||!ie)return;const ue=ie.getBoundingClientRect(),Je=F.getBoundingClientRect(),Ne=ue.top+b.y/M.height*ue.height,Ee=Ne+b.h/M.height*ue.height,qe=16;Ne>=Je.top+qe&&Ee<=Je.bottom-qe||(F.scrollTop+=Ne-(Je.top+Math.max(qe,Je.height*.3)))},[k==null?void 0:k.viewport,O==null?void 0:O.viewport]);a.useEffect(()=>{if(!It||!K.current)return;const b=window.setTimeout(()=>Lt(K.current),420);return()=>window.clearTimeout(b)},[It,ae.width,ae.height,Lt]);const nn=a.useCallback(b=>{var F;const M=b&&typeof b.input=="object"&&b.input!==null?b.input:b;if(typeof(M==null?void 0:M.editable)=="boolean"){if(!M.editable&&M.kind==="control"){const ie=M.bounds;ie&&["x","y","w","h"].every(ue=>typeof ie[ue]=="number")&&(gn.current={rect:{x:ie.x,y:ie.y,w:ie.w,h:ie.h},at:Date.now()});return}if(M.editable){const ie=M.bounds,ue=ie&&["x","y","w","h"].every(Je=>typeof ie[Je]=="number")?{x:ie.x,y:ie.y,w:ie.w,h:ie.h}:null;ue&&(K.current=ue,X.current=Date.now()),P.current?Lt(ue??K.current):ne(!0)}else K.current=null,P.current&&((F=tt.current)==null||F.blur(),ft(!1))}},[Lt]),Gt=a.useCallback((b=!0)=>{var ue,Je,Ne,Ee,qe;(ue=on.current)==null||ue.abort(),on.current=null;const M=Cn.current;Cn.current=null;for(const vt of(M==null?void 0:M.getTracks())??[])vt.stop();(Je=Yt.current)==null||Je.disconnect(),(Ne=Xn.current)==null||Ne.disconnect(),(Ee=mn.current)==null||Ee.disconnect(),Yt.current=null,Xn.current=null,mn.current=null;const F=Un.current;Un.current=null,F&&F.close().catch(()=>{});const ie=Ie.current;Ie.current=null,(qe=xt.current)==null||qe.disconnect(),xt.current=null,Vt.current=0,Hn.current=0,ie&&ie.close().catch(()=>{}),tr.current=!1,Qn.current=!1,qt(!1),Sn(!1),at("idle"),b&&i&&x&&i.request("browser:webrtc",{sessionId:x,data:{kind:"audio-stop"}}).catch(()=>{})},[i,x]),Er=a.useCallback(b=>{var Mn;if(Qn.current||typeof b.data!="string")return;const M=Ie.current,F=Number(b.sampleRate),ie=Number(b.channels);if(!M||!Number.isSafeInteger(F)||!Number.isSafeInteger(ie)||ie<1||ie>2)return;const ue=rg(b.data,ie);if(!((Mn=ue[0])!=null&&Mn.length))return;const Je=M.createBuffer(ie,ue[0].length,F);for(let vn=0;vn<ie;vn+=1)Je.copyToChannel(ue[vn],vn);const Ne=M.createBufferSource();Ne.buffer=Je;const Ee=xt.current;if(!Ee)return;Ne.connect(Ee);const qe=M.currentTime,vt=Math.max(qe+.02,Vt.current);Vt.current=vt-qe>.35?qe+.02:vt,Ne.start(Vt.current),Vt.current+=Je.duration},[]),Mr=a.useCallback(async()=>{var M;if(!i||!x||!q||!ce||document.visibilityState!=="visible")return;const b=new AbortController;(M=on.current)==null||M.abort(),on.current=b,L(null),at("starting");try{const F=await sg(b.signal);if(!F||b.signal.aborted||document.visibilityState!=="visible"){F==null||F.dispose();return}const{stream:ie,microphoneContext:ue,remoteContext:Je,remoteGain:Ne,source:Ee,processor:qe,sink:vt}=F;Cn.current=ie,Un.current=ue,Yt.current=Ee,Xn.current=qe,mn.current=vt,Ie.current=Je,xt.current=Ne,Yn.current=0,qe.onaudioprocess=Mn=>{if(b.signal.aborted||tr.current||!Cn.current||!i||!x||Hn.current>=4)return;const vn=new Float32Array(Mn.inputBuffer.getChannelData(0));Hn.current+=1,i.request("browser:webrtc",{sessionId:x,data:{kind:"audio-microphone",sequence:++Yn.current,sampleRate:ue.sampleRate,channels:1,data:ng(vn)}}).catch(()=>{}).finally(()=>{Hn.current=Math.max(0,Hn.current-1)})},await i.request("browser:webrtc",{sessionId:x,data:{kind:"audio-start"}})}catch(F){if(b.signal.aborted)return;Gt(!1),at("failed"),L(F instanceof Error?F.message:"无法开始语音")}},[i,q,x,Gt,ce]);a.useEffect(()=>{t&&q&&ce||Et!=="idle"&&Gt(!0)},[Et,q,t,Gt,ce]),a.useEffect(()=>{const b=()=>{document.visibilityState!=="visible"&&Et!=="idle"&&Gt(!0)};return document.addEventListener("visibilitychange",b),()=>document.removeEventListener("visibilitychange",b)},[Et,Gt]),a.useEffect(()=>()=>Gt(!0),[Gt]);const Nt=a.useMemo(()=>[{urls:"stun:stun.l.google.com:19302"}],[]),as=a.useCallback(async(b,M,F)=>{if(!(!i||!b||!M))try{const ie=Z.current;Z.current=null,ie==null||ie.close();let ue=Z.current;if(ue||(ue=new RTCPeerConnection({iceServers:F!=null&&F.length?F:Nt}),ue.onicecandidate=Ne=>{Ne.candidate&&i.request("browser:webrtc",{sessionId:b,data:{kind:"ice",candidate:Ne.candidate.toJSON()}}).catch(()=>{})},ue.ontrack=Ne=>{const Ee=Xt.current;Ee&&Ne.streams[0]&&(Ee.srcObject=Ne.streams[0],Ee.play().catch(()=>{}))},ue.onconnectionstatechange=()=>{if(Z.current!==ue)return;const Ne=ue==null?void 0:ue.connectionState;Ne==="connected"?Re("live"):(Ne==="failed"||Ne==="disconnected"||Ne==="closed")&&Re("failed")},Z.current=ue),await ue.setRemoteDescription(M),Z.current!==ue)return;const Je=await ue.createAnswer();if(await ue.setLocalDescription(Je),Z.current!==ue)return;Re("connecting"),await i.request("browser:webrtc",{sessionId:b,data:{kind:"answer",sdp:ue.localDescription.toJSON()}})}catch{Re("failed")}},[i,Nt]),nr=a.useCallback((b,M)=>{if(M){if(M.kind==="quality-state"&&["smooth","hd","original"].includes(String(M.quality))){C(String(M.quality)),j(null),typeof M.error=="string"&&L(M.error);return}if(M.kind==="audio-system"){Er(M);return}if(M.kind==="audio-state"){const F=String(M.state);["idle","starting","live","failed"].includes(F)&&at(F),typeof M.error=="string"&&(L(M.error),Gt(!1),at("failed"));return}if(M.kind==="offer"){typeof M.warning=="string"&&L(M.warning),as(b,M.sdp,Array.isArray(M.iceServers)?M.iceServers:void 0);return}if(M.kind==="ice"){const F=M.candidate,ie=Z.current;ie&&F&&ie.addIceCandidate(F).catch(()=>{});return}if(M.kind==="state"){const F=String(M.state);F==="connected"?Re("live"):(F==="failed"||F==="disconnected"||F==="closed")&&Re("failed")}}},[as,Er,Gt]),[bn,zn]=a.useState(null);a.useEffect(()=>{if(!k){zn(null);return}const b=typeof k.data=="string"?`data:${k.mime};base64,${k.data}`:URL.createObjectURL(new Blob([k.data],{type:k.mime}));let M=!1,F=!1;const ie=new Image;return ie.src=b,ie.decode().then(()=>{M||(F=!0,zn(b))}).catch(()=>{}),()=>{M=!0,!F&&b.startsWith("blob:")&&URL.revokeObjectURL(b)}},[k]),a.useEffect(()=>()=>{bn!=null&&bn.startsWith("blob:")&&URL.revokeObjectURL(bn)},[bn]);const rn=a.useCallback(b=>{f(M=>{const F=M.findIndex(ue=>ue.id===b.id);if(F>=0&&ig(M[F],b))return M;if(F<0)return[b,...M];const ie=[...M];return ie[F]=b,ie.sort((ue,Je)=>Je.updatedAt-ue.updatedAt)}),y(M=>Kl(M,[b],n)),de(!1)},[n]),dr=a.useCallback(async()=>{if(!(!i||!t)){N(!0),L(null);try{const b=await i.request("browser:list");f(b.sessions),y(M=>{const F=M&&b.sessions.some(ie=>ie.id===M)?M:null;return Kl(F,b.sessions,n)}),x&&await i.request("browser:watch",{sessionId:x}).then(M=>rn(M.session)).catch(()=>{}),A(M=>M+1)}catch(b){L(b instanceof Error?b.message:"无法读取浏览器会话")}finally{N(!1)}}},[n,i,rn,t,x]);a.useEffect(()=>{if(!(!t||!i))return dr(),i.onEvent(b=>{var M;if(b.type==="browser:connection"){(M=Z.current)==null||M.close(),Z.current=null,Re("off"),de(!1),f([]),W(null),b.connected===!0?dr():L("远程连接已断开,正在重新连接");return}if(b.type==="browser:frame"){const F=b;F.sessionId===x&&W(F);return}if(b.type==="browser:webrtc"){const F=b.data;b.sessionId===x&&nr(x,F);return}if(b.session&&typeof b.session=="object"&&rn(b.session),b.type==="browser:closed"){const F=b.session;F&&(f(ie=>ie.filter(ue=>ue.id!==F.id)),F.id===x&&(W(null),y(null)))}})},[i,nr,rn,t,dr,x]),a.useEffect(()=>{if(!(!t||!i||!x))return W(null),L(null),i.request("browser:watch",{sessionId:x}).then(b=>rn(b.session)).catch(b=>L(b instanceof Error?b.message:"无法观看浏览器")),()=>{i.request("browser:unwatch").catch(()=>{})}},[i,rn,t,x]),a.useEffect(()=>{var b,M;if(!t||!i||!q||!Ye||!x){_t.current=0,(b=Z.current)==null||b.close(),Z.current=null,Xt.current&&(Xt.current.srcObject=null),_n.current=null,Nn(null),Re("off");return}return(M=Z.current)==null||M.close(),Z.current=null,_n.current=null,Nn(null),Re("connecting"),Tt.current.begin(Date.now()),i.request("browser:webrtc",{sessionId:x,data:{kind:"start",receiverProfiles:Qh()}}).catch(()=>Re("failed")),()=>{var F;(F=Z.current)==null||F.close(),Z.current=null,Xt.current&&(Xt.current.srcObject=null),_n.current=null,Nn(null),i.request("browser:webrtc",{sessionId:x,data:{kind:"stop"}}).catch(()=>{})}},[i,q,Ye,t,x,T]),a.useEffect(()=>{if(!t||!q||!Ye||Ut!=="failed"||_t.current>=2)return;const b=window.setTimeout(()=>{_t.current+=1,A(M=>M+1)},2e3*(_t.current+1));return()=>window.clearTimeout(b)},[t,q,Ye,Ut]),a.useEffect(()=>{if(!i||!x||Ut!=="live"){_n.current=null,Nn(null);return}let b=!0,M=!1;const F=async()=>{const ue=Z.current;if(!(!ue||M)){M=!0;try{const Je=await ue.getStats();if(!b||ue!==Z.current)return;const Ne=Date.now(),Ee=Yh(Je,_n.current);if(Ee&&(_n.current=Ee.cursor,Tt.current.observe(Ee.cursor.framesDecoded,Ne),Nn(Ee.sample),i.request("browser:webrtc",{sessionId:x,data:{kind:"stats",...Ee.sample}}).catch(()=>{})),Tt.current.evaluate(Ne).state==="stalled"){const qe=Tt.current.evaluate(Ne);Tt.current.begin(Ne),Re(vt=>vt==="live"?"failed":vt),L(vt=>vt??"实时画面超时,已切换为 JPEG 兜底画面"),i.request("browser:webrtc",{sessionId:x,data:{kind:"viewer-trace",event:"jpeg-fallback",silentForMs:qe.silentForMs,...Tn?{sample:Tn}:{}}}).catch(()=>{})}}catch{}finally{M=!1}}};F();const ie=window.setInterval(()=>void F(),1e3);return()=>{b=!1,window.clearInterval(ie)}},[i,x,Ut]);const Hr=a.useCallback(async()=>{if(!(!i||!O)){de(!0),L(null);try{const b=await i.request("browser:takeover",{sessionId:O.id});rn(b.session)}catch(b){de(!1),L(b instanceof Error?b.message:"无法接管浏览器")}}},[i,rn,O]),ls=a.useCallback(async()=>{if(!(!i||!O)){de(!0),L(null);try{const b=await i.request("browser:return",{sessionId:O.id});rn(b.session)}catch(b){de(!1),L(b instanceof Error?b.message:"无法归还浏览器")}}},[i,rn,O]),ur=a.useCallback(async(b,M)=>{if(!(!i||!x)){fe(b),L(null);try{await i.request("browser:system",{sessionId:x,action:b,...M?{password:M}:{}}),window.setTimeout(()=>A(F=>F+1),800)}catch(F){L(F instanceof Error?F.message:"系统操作失败")}finally{fe(null)}}},[i,x]),an=a.useCallback(async()=>{if(!(!i||!x||!Ge)){it(!0),ge(null);try{await i.request("browser:system",{sessionId:x,action:"unlock",password:Ge}),Ke(""),ze(!1),window.setTimeout(()=>A(b=>b+1),2500)}catch(b){ge(b instanceof Error?b.message:"解锁失败")}finally{Ke(""),it(!1)}}},[i,x,Ge]),dt=a.useCallback(b=>{!i||v||I||!(O!=null&&O.isController)||O.state!=="user-controlled"||i.request("browser:input",{sessionId:O.id,input:{...b,mobile:window.matchMedia("(pointer: coarse)").matches}}).catch(M=>{L(M instanceof Error?M.message:"浏览器输入失败")})},[i,O,v,I]),Jt=a.useCallback((b,M,F=[])=>{dt({kind:"key",action:"down",key:b,code:M,text:"",modifiers:F}),dt({kind:"key",action:"up",key:b,code:M,text:"",modifiers:F})},[dt]),Ln=a.useCallback(b=>{Jt(b,`Key${b.toUpperCase()}`,["Control"])},[Jt]),In=a.useCallback(b=>!i||v||I||!(O!=null&&O.isController)||O.state!=="user-controlled"?Promise.resolve(null):i.request("browser:input",{sessionId:O.id,input:{...b,mobile:window.matchMedia("(pointer: coarse)").matches}}).then(M=>M&&typeof M=="object"?M:null).catch(()=>null),[i,O,v,I]),Pn=a.useCallback((b,M)=>{In({kind:"pointer",action:"up",...b,button:"left",...M&&M>1?{click:M}:{}}).then(nn)},[nn,In]),Zt=a.useRef(!1),rr=a.useRef(""),yn=a.useCallback(b=>{const M=rr.current;if(b!==M){if(b.startsWith(M)){const F=b.slice(M.length);F&&dt({kind:"key",action:"down",text:F,key:"",code:"",modifiers:[]})}rr.current=b}},[dt]),gt=(O==null?void 0:O.displays)??null;a.useEffect(()=>{if(!I)return;const b=window.setTimeout(()=>{j(null),L("画质切换未完成,请刷新画面后重试")},14e3);return()=>window.clearTimeout(b)},[I]),a.useEffect(()=>{j(null),C("hd")},[t,x]);const Dn=b=>{!i||!Ce||v||I||!x||(j(b),i.request("browser:webrtc",{sessionId:x,data:{kind:"quality",quality:b}}).catch(M=>{j(null),L(M instanceof Error?M.message:"画质切换失败")}))};a.useEffect(()=>{if(!v)return;if(gt!=null&&gt.some(M=>M.id===v&&M.selected)){S(null);return}const b=window.setTimeout(()=>{S(null),L("切换屏幕未完成,请刷新画面后重试")},14e3);return()=>window.clearTimeout(b)},[gt,v]),a.useEffect(()=>{S(null)},[t,x]);const sn=a.useRef(0),qr=a.useCallback(b=>{!i||v||I||!x||!Ce||!(gt!=null&&gt.some(M=>M.id===b&&!M.selected))||(S(b),i.request("browser:set-display",{sessionId:x,displayId:b}).catch(M=>{S(null),L(M instanceof Error?M.message:"切换屏幕失败")}))},[i,gt,x,Ce,v,I]),Rn=a.useCallback(b=>{const M=b.currentTarget.getBoundingClientRect(),F=(k==null?void 0:k.viewport)??(O==null?void 0:O.viewport);if(!F)return null;const ie=Math.min(M.width/F.width,M.height/F.height),ue=F.width*ie,Je=F.height*ie,Ne=(M.width-ue)/2,Ee=(M.height-Je)/2,qe=(b.clientX-M.left-Ne)/ue,vt=(b.clientY-M.top-Ee)/Je;return qe<0||qe>1||vt<0||vt>1?null:{x:qe,y:vt}},[k==null?void 0:k.viewport,O==null?void 0:O.viewport]);if(!t||typeof document>"u")return null;const Vr=(O==null?void 0:O.online)&&!O.controlledByAnotherViewer,pr=(O==null?void 0:O.availability)==="unavailable"?Ye?"桌面直播不可用":"浏览器直播不可用":(O==null?void 0:O.availability)==="starting"?"正在连接画面":Ye&&(O==null?void 0:O.state)==="agent-controlled"?"未被远程控制":O?eg[O.state]:Ye?"等待桌面直播":"等待浏览器",Ar=(O==null?void 0:O.availability)==="unavailable"?Ye?"桌面直播不可用":"浏览器直播不可用":(O==null?void 0:O.availability)==="starting"?"正在连接画面":g.length?"等待第一帧":Ye?"暂无桌面直播":"暂无浏览器直播",Ps=(O==null?void 0:O.availability)==="unavailable"?O.capabilityError||(Ye?"需要在桌面 App 中开启并授予屏幕录制权限":"当前浏览器不支持实时画面传输"):g.length?"画面开始后会自动显示":Ye?"在桌面 App 设置中开启「桌面直播与远程控制」后,画面会出现在这里":"Agent 开始浏览网页后,会话会出现在这里",cs=Jh(Tn),En=Zh(Tn),Kt=Ut==="live"?cs||"WebRTC 实时流":Ut==="connecting"?"正在连接 WebRTC":bn?"JPEG 兜底":null;return $n.createPortal(e.jsxs("div",{className:"browser-live-backdrop","data-tab-swipe-ignore":!0,role:"presentation",onMouseDown:b=>{b.target===b.currentTarget&&r()},children:[e.jsxs("section",{ref:o,className:`browser-live-panel ${c?"is-fullscreen":""}`,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(ll,{size:17,"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("strong",{children:"浏览器直播"}),e.jsx("span",{children:O?jo(O.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(go,{size:17}):e.jsx(Zu,{size:17})}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>void dr(),title:"刷新画面与会话","aria-label":"刷新直播画面与会话",children:e.jsx(ra,{size:15,className:ee?"spin":void 0,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:r,title:"关闭","aria-label":"关闭浏览器直播",children:e.jsx(Rr,{size:17,"aria-hidden":"true"})})]})]}),e.jsxs("div",{className:`browser-live-surface ${q?"is-controlling":""} has-zoom ${q&&!G&&pt?"has-quickkeys":""}`,children:[e.jsxs("div",{className:"browser-live-zoom",role:"group","aria-label":"桌面画面缩放",children:[c&&e.jsxs("button",{type:"button","aria-label":"退出全屏",title:"退出全屏",onClick:()=>void u(),children:[e.jsx(go,{size:15,"aria-hidden":"true"}),"退出全屏"]}),g.length>1&&e.jsx("div",{className:"browser-live-session-tabs",role:"tablist","aria-label":"切换直播屏幕",children:g.map(b=>e.jsx("button",{type:"button",role:"tab","aria-selected":b.id===x,className:b.id===x?"is-active":"",title:`${jo(b.backend)} · ${b.title||"浏览器"}`,onClick:()=>y(b.id),children:b.title||jo(b.backend)},b.id))}),Ye&&gt&&gt.length>1&&e.jsx(Gl,{label:"选择直播屏幕",title:Ce?"选择直播屏幕":"其他设备控制中或画面暂不可用",value:(gt.find(b=>b.selected)??gt[0]).id,busy:!!v,disabled:!k||!Ce||I||gt.length<2,onChange:qr,children:gt.map((b,M)=>e.jsx("option",{value:b.id,children:`第 ${M+1} 屏${b.primary?"(主屏)":""}`},b.id))}),Ye&&e.jsxs(Gl,{label:"视频画质",title:Ce?"视频画质":"其他设备控制中或画面暂不可用",value:E,busy:I!==null,disabled:!Ce||!!v,compact:!0,onChange:Dn,children:[e.jsx("option",{value:"smooth",children:"流畅"}),e.jsx("option",{value:"hd",children:"高清"}),e.jsx("option",{value:"original",children:"原画"})]}),Ye&&q&&ce&&Et!=="live"&&e.jsxs("button",{type:"button","aria-label":"开始语音",title:"开始双向语音",disabled:Et==="starting",onClick:()=>void Mr(),children:[Et==="starting"?e.jsx(lt,{size:15,className:"spin","aria-hidden":"true"}):e.jsx(al,{size:15,"aria-hidden":"true"}),Et==="starting"?"正在连接":"开始语音"]}),Ye&&q&&ce&&Et==="live"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":Ft?"取消麦克风静音":"麦克风静音","aria-pressed":Ft,title:Ft?"打开麦克风":"关闭麦克风",onClick:()=>{var M;const b=!tr.current;tr.current=b;for(const F of((M=Cn.current)==null?void 0:M.getAudioTracks())??[])F.enabled=!b;qt(b)},children:Ft?e.jsx(ep,{size:15,"aria-hidden":"true"}):e.jsx(al,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button","aria-label":zt?"取消扬声器静音":"扬声器静音","aria-pressed":zt,title:zt?"打开电脑声音":"关闭电脑声音",onClick:()=>{const b=!Qn.current;Qn.current=b,xt.current&&(xt.current.gain.value=b?0:1),Sn(b),b&&(Vt.current=0)},children:zt?e.jsx(mp,{size:15,"aria-hidden":"true"}):e.jsx(Kc,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button","aria-label":"结束语音",title:"结束双向语音",onClick:()=>Gt(!0),children:e.jsx(op,{size:15,"aria-hidden":"true"})})]}),e.jsx("button",{type:"button","aria-label":"缩小桌面画面",title:"缩小",disabled:!k||Qe<=.5,onClick:()=>B(b=>Math.max(.5,b-.25)),children:e.jsx(Yc,{size:16})}),e.jsxs("output",{"aria-label":"桌面缩放比例",children:[Math.round(Qe*100),"%"]}),e.jsx("button",{type:"button","aria-label":"放大桌面画面",title:"放大",disabled:!k||Qe>=5,onClick:()=>B(b=>Math.min(5,b+.25)),children:e.jsx(Xc,{size:16})}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>{var b;B(1),Y(!1),(b=le.current)==null||b.scrollTo(0,0)},children:"适应窗口"}),e.jsxs("button",{type:"button","aria-label":"移动桌面画面","aria-pressed":G,title:"拖动或滚动画面,不发送远程输入",disabled:!k,onClick:()=>Y(b=>!b),children:[e.jsx(Hu,{size:15}),"移动画面"]}),e.jsxs("button",{type:"button","aria-label":"唤起键盘","aria-pressed":It,title:"唤起/收起键盘(轻点输入框也会自动弹起)",className:J&&!It?"is-hint":void 0,disabled:!k||!q,onClick:()=>{ne(!1),Jn()},children:[e.jsx(ho,{size:15}),"键盘"]}),e.jsxs("button",{type:"button","aria-label":"快捷键条","aria-pressed":pt,title:"展开/收起快捷键(Esc/Tab/复制/粘贴/方向键)",disabled:!k||!q,onClick:()=>Dt(b=>!b),children:[e.jsx(ho,{size:15}),pt?"收起":"快捷键"]}),e.jsxs("button",{type:"button","aria-label":"窗口控制",title:"全屏看不到左上角按钮时用:第 1 次点=退出全屏(ESC + Ctrl+Cmd+F),第 2 次点=关闭窗口(Cmd+W)",disabled:!k||!q,onClick:()=>{const b=Date.now();if(b-sn.current<2500){Jt("w","KeyW",["Meta"]),sn.current=0;return}sn.current=b,Jt("Escape","Escape"),window.setTimeout(()=>{Jt("f","KeyF",["Control","Meta"])},150)},children:[e.jsx(ho,{size:15}),"窗口"]}),qn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-label":"锁屏",title:"锁屏(锁屏后仍可从空态区唤醒或远程解锁)",disabled:!k||!!Fe,onClick:()=>void ur("lock"),children:[Fe==="lock"?e.jsx(lt,{size:15,className:"spin"}):e.jsx(Yu,{size:15}),"锁屏"]}),e.jsxs("button",{type:"button","aria-label":"唤醒屏幕",title:"唤醒显示器或锁屏界面",disabled:!!Fe,onClick:()=>void ur("wake"),children:[Fe==="wake"?e.jsx(lt,{size:15,className:"spin"}):e.jsx(cl,{size:15}),"唤醒"]})]})]}),q&&!G&&pt&&e.jsxs("div",{className:"browser-live-quickkeys",role:"group","aria-label":"快捷键",children:[e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("Escape","Escape"),children:"Esc"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("Tab","Tab"),children:"Tab"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("c"),children:"复制"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("v"),children:"粘贴"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("a"),children:"全选"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("z"),children:"撤销"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("s"),children:"保存"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Ln("f"),children:"查找"}),e.jsx("button",{type:"button",disabled:!k,title:"退出当前前台应用(Cmd+Q)",onClick:()=>Jt("q","KeyQ",["Meta"]),children:"⌘Q"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("ArrowLeft","ArrowLeft"),children:"←"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("ArrowUp","ArrowUp"),children:"↑"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("ArrowDown","ArrowDown"),children:"↓"}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>Jt("ArrowRight","ArrowRight"),children:"→"})]}),e.jsx("div",{className:"browser-live-touch-hint",children:"滑动滚动 · 轻点点击 · 双击打开 · 长按拖动 · 按住1秒右键 · 双指缩放"}),e.jsx("div",{ref:le,className:"browser-live-viewport",children:k&&bn?e.jsxs("div",{className:"browser-live-image-hit-area",style:xn&&He?{width:He.width*xn*Qe,height:He.height*xn*Qe,cursor:G?"grab":void 0}:void 0,tabIndex:q&&!G?0:-1,onPointerDown:b=>{if(b.pointerType==="touch"){b.preventDefault(),$e.current.down(b.pointerId,{x:b.clientX,y:b.clientY}),mt.current=q&&!G?Rn(b):null,b.currentTarget.setPointerCapture(b.pointerId),Ue.current&&window.clearTimeout(Ue.current),ot.current="none",ct.current=q&&!G?{x:b.clientX,y:b.clientY}:null,ht.current=Date.now(),ct.current&&(Ue.current=window.setTimeout(()=>{ot.current="armed"},550));return}if(G&&le.current){const F=le.current;Se.current={x:b.clientX,y:b.clientY,left:F.scrollLeft,top:F.scrollTop},b.currentTarget.setPointerCapture(b.pointerId);return}if(!q)return;const M=Rn(b);M&&(Te.current=!0,b.currentTarget.setPointerCapture(b.pointerId),dt({kind:"pointer",action:"down",...M,button:"left"}))},onPointerMove:b=>{if(b.pointerType==="touch"){b.preventDefault();const F=$e.current.move(b.pointerId,{x:b.clientX,y:b.clientY}),ie=le.current;if(!F||!ie)return;const ue=F.pointers>=2&&Math.abs(F.distanceRatio-1)>.05,Je=Math.max(.5,Math.min(5,yt.current*F.scale));if(ue&&Je!==yt.current){const Ee=b.currentTarget.getBoundingClientRect();st.current={x:(F.from.x-Ee.left)/Ee.width,y:(F.from.y-Ee.top)/Ee.height,clientX:F.to.x,clientY:F.to.y},yt.current=Je,$n.flushSync(()=>B(Je));return}if(Ue.current&&(window.clearTimeout(Ue.current),Ue.current=null),ot.current==="armed"&&ct.current){ot.current="drag";const Ee=Rn(b);Ee&&dt({kind:"pointer",action:"down",...Ee,button:"left"})}if(ot.current==="drag"){const Ee=Rn(b);Ee&&dt({kind:"pointer",action:"move",...Ee,button:"left"});return}const Ne=yt.current<=1.001;if(q&&!G&&(F.pointers>=2||Ne)){const Ee=lg(F.from,F.to);if(Ee){const qe=mt.current??Rn(b);qe&&dt({kind:"pointer",action:"wheel",...qe,...Ee})}return}ie.scrollLeft+=F.from.x-F.to.x,ie.scrollTop+=F.from.y-F.to.y;return}if(G&&Se.current&&le.current){const F=Se.current;le.current.scrollTo(F.left+F.x-b.clientX,F.top+F.y-b.clientY);return}if(!q||!Te.current)return;const M=Rn(b);M&&dt({kind:"pointer",action:"move",...M,button:"left"})},onPointerUp:b=>{var F,ie;if(b.pointerType==="touch"){b.preventDefault(),Ue.current&&(window.clearTimeout(Ue.current),Ue.current=null);const ue=Rn(b);if(mt.current=null,ot.current==="armed"&&(ot.current="none",(ht.current?Date.now()-ht.current:0)>=800&&ue&&q&&!G)){$e.current.reset(),dt({kind:"pointer",action:"down",...ue,button:"right"}),dt({kind:"pointer",action:"up",...ue,button:"right"});return}if(ot.current==="drag"){ot.current="none",$e.current.reset(),ue&&q&&dt({kind:"pointer",action:"up",...ue,button:"left"});return}if($e.current.up(b.pointerId,{x:b.clientX,y:b.clientY})&&ue&&q&&!G){const Ne=K.current,Ee=Ne!==null&&Date.now()-X.current<6e4&&ag(Ne,(k==null?void 0:k.viewport)??(O==null?void 0:O.viewport),ue.x,ue.y,.03);Ee&&!P.current?((F=tt.current)==null||F.focus({preventScroll:!0}),ft(!0),ne(!1)):!Ee&&P.current&&((ie=tt.current)==null||ie.blur(),ft(!1));const qe=(k==null?void 0:k.viewport)??(O==null?void 0:O.viewport),vt=$t.current;vt!==null&&Date.now()-vt.at<400&&qe!==void 0&&Math.hypot((ue.x-vt.x)*qe.width,(ue.y-vt.y)*qe.height)<qe.width*.03?(dt({kind:"pointer",action:"down",...ue,button:"left",click:2}),Pn(ue,2),$t.current=null):(dt({kind:"pointer",action:"down",...ue,button:"left"}),Pn(ue),$t.current={at:Date.now(),x:ue.x,y:ue.y})}return}if(G){Se.current=null;return}if(!q)return;const M=Rn(b);Te.current=!1,M&&Pn(M)},onPointerCancel:b=>{$e.current.up(b.pointerId,{x:b.clientX,y:b.clientY},!0),Se.current=null,Te.current=!1,mt.current=null,Ue.current&&(window.clearTimeout(Ue.current),Ue.current=null),ot.current="none"},onLostPointerCapture:b=>{$e.current.up(b.pointerId,{x:b.clientX,y:b.clientY},!0)},onWheel:b=>{if(!q||G)return;const M=Rn(b);M&&dt({kind:"pointer",action:"wheel",...M,deltaX:b.deltaX,deltaY:b.deltaY})},onKeyDown:b=>{!q||G||b.target===tt.current&&b.key.length===1&&!b.ctrlKey&&!b.metaKey&&!b.altKey||(dt({kind:"key",action:"down",key:b.key,code:b.code,text:b.key.length===1?b.key:"",modifiers:Ql(b)}),["Backspace","Tab","Enter","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","PageUp","PageDown","Home","End","Escape"].includes(b.key)&&b.preventDefault())},onKeyUp:b=>{!q||G||b.target===tt.current&&b.key.length===1&&!b.ctrlKey&&!b.metaKey&&!b.altKey||q&&dt({kind:"key",action:"up",key:b.key,code:b.code,modifiers:Ql(b)})},children:[e.jsx("img",{src:bn,alt:(O==null?void 0:O.title)||"浏览器实时画面",draggable:!1,decoding:"async"}),e.jsx("video",{ref:Xt,className:`browser-live-video ${Ut==="live"?"is-live":""}`,"aria-label":Ye?"桌面实时视频流":"浏览器实时视频流",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:b=>{Zt.current=!1,G||yn(b.target.value)},onBlur:b=>{Zt.current=!1,rr.current="",b.target.value="",ft(!1)},onChange:b=>{!G&&!Zt.current&&yn(b.target.value)}}),I&&e.jsxs("div",{className:"browser-live-quality-pending",role:"status",children:[e.jsx(lt,{size:13,className:"spin","aria-hidden":"true"}),"正在切换至",tg[I]??I,"画质…"]})]}):e.jsxs("div",{className:"browser-live-empty",children:[ee||(O==null?void 0:O.availability)==="starting"?e.jsx(lt,{size:22,className:"spin","aria-hidden":"true"}):e.jsx(ll,{size:24,"aria-hidden":"true"}),e.jsx("strong",{children:ee?"正在连接浏览器":Ar}),e.jsx("span",{children:Ps}),Ot&&e.jsxs("div",{role:"group","aria-label":"锁屏远程操作",style:{display:"flex",gap:8,marginTop:12},children:[e.jsxs("button",{type:"button",className:"browser-live-control-button",disabled:!!Fe,onClick:()=>void ur("wake"),children:[Fe==="wake"?e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"}):e.jsx(cl,{size:14,"aria-hidden":"true"}),"唤醒屏幕"]}),qn&&e.jsxs("button",{type:"button",className:"browser-live-control-button",disabled:Ct,onClick:()=>{ge(null),ze(!0)},children:[e.jsx(ol,{size:14,"aria-hidden":"true"}),"远程解锁"]})]})]})}),c&&e.jsxs("button",{type:"button",className:"browser-live-exit-fullscreen",onClick:()=>void u(),children:[e.jsx(go,{size:14,"aria-hidden":"true"}),"退出全屏"]}),q&&!G&&e.jsxs("div",{className:"browser-live-control-cue",children:[e.jsx(rp,{size:13,"aria-hidden":"true"})," ",Ye?"当前输入会发送到本机":"当前输入会发送到浏览器",Ye&&Kt?` · ${Kt}`:"",Ye&&En?` · ${En}`:"",tn!=null?` · 控制 ${tn}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-${(O==null?void 0:O.state)??"idle"}`,"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("strong",{children:pr}),e.jsx("span",{title:O==null?void 0:O.url,children:(O==null?void 0:O.capabilityError)||(Ye?"本机屏幕":O==null?void 0:O.url)||R||"等待可观看的直播会话"})]}),(O==null?void 0:O.url)&&!Ye&&e.jsx($u,{size:13,"aria-hidden":"true"})]}),O&&(q?e.jsxs("button",{type:"button",className:"browser-live-control-button is-return",onClick:()=>void ls(),disabled:H,children:[H&&e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"}),Ye?"结束控制":"归还给 Agent"]}):e.jsxs("button",{type:"button",className:"browser-live-control-button",onClick:()=>void Hr(),disabled:!Vr||H||O.state!=="agent-controlled"||O.availability!=="ready",children:[H&&e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"}),O.controlledByAnotherViewer?"其他设备操作中":Ye?"开始控制":"接管浏览器"]}))]}),R&&e.jsx("div",{className:"browser-live-error",role:"alert",children:R})]}),je&&e.jsx("div",{className:"browser-live-unlock-backdrop",role:"presentation",onMouseDown:b=>{b.target===b.currentTarget&&!Ct&&(ze(!1),Ke(""),ge(null))},children:e.jsxs("form",{className:"browser-live-unlock-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"browser-live-unlock-title",onSubmit:b=>{b.preventDefault(),an()},children:[e.jsxs("div",{className:"browser-live-unlock-heading",children:[e.jsx(ol,{size:18,"aria-hidden":"true"}),e.jsx("strong",{id:"browser-live-unlock-title",children:"远程解锁 Windows"})]}),e.jsx("label",{htmlFor:"browser-live-unlock-password",children:"Windows 密码或 PIN"}),e.jsx("input",{id:"browser-live-unlock-password",type:"password",autoComplete:"off",autoFocus:!0,maxLength:256,value:Ge,disabled:Ct,onChange:b=>Ke(b.target.value)}),te&&e.jsx("p",{role:"alert",children:te}),e.jsxs("div",{className:"browser-live-unlock-actions",children:[e.jsx("button",{type:"button",className:"browser-live-control-button is-return",disabled:Ct,onClick:()=>{ze(!1),Ke(""),ge(null)},children:"取消"}),e.jsxs("button",{type:"submit",className:"browser-live-control-button",disabled:Ct||!Ge,children:[Ct&&e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"}),"解锁"]})]})]})})]}),document.body)}const dg=[{prompt:"带我熟悉这个项目",Icon:Du},{prompt:"帮我排查一个问题",Icon:Qc},{prompt:"一起实现一个新想法",Icon:Gu}];function ug(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 pg={"customer-agent":"Customer Agent",codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function fg({agentType:t,ready:n,now:r,onSelectPrompt:s}){const i=pg[t],o=ug((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?`${i} · 已准备好`:`${i} · 等待配置`}),e.jsx("h2",{id:"empty-session-welcome-title",children:o.title}),e.jsx("p",{className:"empty-session-welcome__prompt",children:n?o.prompt:"配置好 API Key 后,我就能开始。"})]}),e.jsx("div",{className:"empty-session-welcome__starters","aria-label":"开始一个任务",children:dg.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 hg({image:t,onClose:n}){return a.useEffect(()=>{if(!t)return;const r=document.body.style.overflow,s=i=>{i.key==="Escape"&&n()};return document.body.style.overflow="hidden",window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s),document.body.style.overflow=r}},[t,n]),t?$n.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(Rr,{size:22,"aria-hidden":"true"})})]}),document.body):null}const gg={pending:"⏳",image_generating:"🎨",video_generating:"🎬",done:"✅",error:"❌"};function mg(t){const{title:n="视频工作台",shots:r=[],status:s="generating",composedVideoUrl:i,isAgentRunning:o}=t,[c,d]=a.useState(!1),[u,g]=a.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(f=>f.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:ei,children:"#"}),e.jsx("th",{style:{...ei,textAlign:"left",minWidth:120},children:"画面描述"}),e.jsx("th",{style:ei,children:"时长"}),e.jsx("th",{style:ei,children:"状态"}),e.jsx("th",{style:ei,children:"预览"})]})}),e.jsx("tbody",{children:r.map(f=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx("td",{style:ti,children:f.index}),e.jsx("td",{style:{...ti,textAlign:"left",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:f.description,children:f.description}),e.jsxs("td",{style:ti,children:[f.duration,"s"]}),e.jsxs("td",{style:ti,children:[gg[f.status]??"⏳",f.error&&e.jsx("span",{style:{color:"var(--danger)",fontSize:11,marginLeft:4},title:f.error,children:"!"})]}),e.jsx("td",{style:ti,children:f.videoUrl?e.jsx("button",{onClick:()=>g(f.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:"▶ 播放"}):f.previewImageUrl?e.jsx("img",{src:f.previewImageUrl,alt:`shot-${f.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:"—"})})]},f.index))})]}),u&&e.jsx("video",{src:u,controls:!0,autoPlay:!0,style:{width:"100%",borderRadius:8,marginBottom:12,border:"1px solid var(--border-subtle)"}}),i&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"完整视频"}),e.jsx("video",{src:i,controls:!0,style:{width:"100%",borderRadius:8,border:"1px solid var(--border-subtle)"}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[s==="generating"&&e.jsx("span",{children:o===!1?"本轮已结束":"🔄 生成中..."}),s==="preview_ready"&&e.jsx("span",{children:"📷 预览图已就绪"}),s==="video_ready"&&e.jsx("span",{children:"🎬 视频片段已就绪"}),s==="composed"&&e.jsx("span",{children:"✅ 合成完成"})]})]})]})}const ei={padding:"6px 10px",textAlign:"center",fontWeight:600,fontSize:12,color:"var(--text-muted)",borderBottom:"1px solid var(--border-subtle)"},ti={padding:"6px 10px",textAlign:"center",fontSize:13,color:"var(--text-secondary)"},xg={storyboard_workbench:mg};function bg(t,n,r){return!t||n!==t?!1:r===null||r===t}function yg(t,n,r=Date.now()){return!t||t.sessionId!==n?t:{...t,until:r+9e4}}async function vg(t){const{text:n,projectId:r,createSession:s,activateSession:i,showUserMessage:o,onSessionCreated:c,isCancelled:d}=t,u=!t.sessionId;let g=t.sessionId??null;if(!g){const f=await s(n.slice(0,60)||"语音任务",r||void 0);if(d!=null&&d())return null;g=f.id}return i(g),o(n,g),u&&c&&await c(g),g}async function Xl(t){var i,o,c;const n=((i=t.sessionId)==null?void 0:i.trim())||null,r=!n,s=n??(await t.createSession(t.text.slice(0,60)||"New Session",t.projectId||void 0)).id.trim();if(!s)throw new Error("创建会话失败:服务端未返回会话 ID");return t.activateSession(s),t.showUserMessage(t.text,s),await((o=t.afterUserMessageShown)==null?void 0:o.call(t)),r&&await((c=t.onSessionCreated)==null?void 0:c.call(t,s)),s}function wg(t=window){return new Promise(n=>{let r=!1,s;const i=()=>{r||(r=!0,s!==void 0&&t.clearTimeout(s),n())};s=t.setTimeout(i,100),t.requestAnimationFrame(()=>{t.setTimeout(i,0)})})}const jg=/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|[ \t]*\/[^)\n]+)\)/gi,kg=/`([^`\n]+)`/g,Sg=/:codex-file-citation\{([^}\n]*)\}/g,Yl=/([A-Za-z][\w-]*)="([^"\n]*)"/g,Cg=/\uE200visualize\uE202([^\uE201\n]+)\uE201/g;function fa(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 Ig(t){const n={};for(const i of t.matchAll(Yl)){const o=i[1];if(o!=="path"&&o!=="purpose"||n[o]!==void 0)return null;n[o]=i[2]}if(t.replace(Yl,"").trim())return null;const r=fa(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 Rg(t){try{const n=JSON.parse(t);if(!n||typeof n!="object"||Array.isArray(n))return null;const{path:r,title:s,mode:i}=n;if(typeof r!="string"||s!==void 0&&typeof s!="string"||i!==void 0&&typeof i!="string")return null;const o=fa(r);if(!o||o.line!==void 0)return null;const c=(s==null?void 0:s.trim())||o.path.slice(o.path.lastIndexOf("/")+1)||o.path;return{path:o.path,label:c}}catch{return null}}function Eg(t,n){const r=[];let s=0;const i=[...[...t.matchAll(jg)].map(o=>({kind:"markdown",match:o})),...[...t.matchAll(Sg)].map(o=>({kind:"citation",match:o})),...[...t.matchAll(Cg)].map(o=>({kind:"visualize",match:o})),...[...t.matchAll(kg)].map(o=>({kind:"code",match:o}))].sort((o,c)=>(o.match.index??0)-(c.match.index??0));for(const o of i){const{match:c}=o,d=c.index??0;if(d<s)continue;if(d>s&&r.push({type:"text",value:t.slice(s,d)}),o.kind==="code"){r.push({type:"code",value:c[1]}),s=d+c[0].length;continue}if(o.kind==="citation"){const g=Ig(c[1]);r.push(g?{type:"artifact",label:g.label,path:g.path,raw:c[0]}:{type:"text",value:c[0]}),s=d+c[0].length;continue}if(o.kind==="visualize"){const g=Rg(c[1]);r.push(g?{type:"artifact",label:g.label,path:g.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 g=fa(u.replace(/^[ \t]+/,""));g?r.push({type:"artifact",label:c[1],path:g.path,...g.line?{line:g.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 Mg(t){return Eg(t)}function Nd(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0}function Ag(t){const n=Nd(t);return n===void 0?void 0:`${Math.round(n/1e3)} 秒`}function Tg(t){return t.role==="user"&&!t.isQueued&&!t.isSteered}function Ng(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 _g(t,n,r){var o;const s=t[n];if((s==null?void 0:s.role)!=="assistant"||!s.content.trim()||(o=s.toolCalls)!=null&&o.length||s.isCompactionSummary)return!1;let i=!r;for(let c=n+1;c<t.length;c++){const d=t[c];if(!d.isCompactionSummary){if(Tg(d)){i=!0;break}if(Ng(d))return!1}}return i}function zg(t,n,r){const s=t[n];if(!s)return{showCopy:!1,showSpeak:!1,showCompletion:!1,compact:!1};if(s.role==="user")return{showCopy:!!s.content,showSpeak:!1,showCompletion:!1,compact:!1};const i=_g(t,n,r);return{showCopy:i,showSpeak:i,showCompletion:i,compact:s.role==="assistant"&&!i&&!s.isCompactionSummary}}const Lg=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function Pg(t,n){const r=[],s=[],i=[];for(const c of t){const d=c.type.trim().toLowerCase();d.startsWith("image/")?Lg.has(d)?r.push(c):i.push(c):s.push(c)}const o=await Promise.all(r.map(async c=>{try{return{file:c,dataUrl:await n(c)}}catch{return{file:c,dataUrl:null}}}));return{images:o.flatMap(c=>c.dataUrl?[c.dataUrl]:[]),attachments:s,unsupportedImages:i,failedImages:o.flatMap(c=>c.dataUrl?[]:[c.file])}}function Es(t,n){return n?t[n]:void 0}function Dg(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 Wg(t,n){const r=t[n];return r?Object.fromEntries(Object.entries(t).filter(([,s])=>s.token!==r.token)):t}function Bg(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,restoreDraftOnFailure:n.restoreDraftOnFailure},sendAttempted:!1}}function Jl(t,n){return t.forkSessionId===n&&t.sendAttempted?t:{...t,forkSessionId:n,sendAttempted:!0}}function Zl(t){return`occupied-recovery:${t.token}`}function Fg(t,n){return!!(t&&n&&(t.sourceSessionId===n||t.forkSessionId===n))}async function Og(t){const n=await t.forkSession(t.sourceSessionId);return t.activateSession(n.id),await t.refreshAndSelect(n),n}const kr=50,ko=1,ni=1,ec=160;function tc(t){return t.trim().replace(/^\/goal\s+/i,"").replace(/^\$([\w-]+)/,"/$1").trim()}function So(t){const r=t.trim().replace(/^每(?:隔)?/,"").match(/^(\d+(?:\.\d+)?)\s*(s|sec|秒|m|min|分钟?|h|hr|小时)$/i);if(r){const o=parseFloat(r[1]),c=r[2].toLowerCase(),d=c==="s"||c==="sec"||c==="秒"?o*1e3:c==="m"||c==="min"||c==="分"||c==="分钟"?o*6e4:o*36e5;return d>=36e5&&d%36e5===0?`每 ${d/36e5} 小时`:d>=6e4&&d%6e4===0?`每 ${d/6e4} 分钟`:`每 ${d/1e3} 秒`}const[s,i]=t.trim().split(/\s+/);return s==="0"&&i&&i!=="*"&&!i.includes("/")&&!i.includes(",")?`每天 ${i.padStart(2,"0")}:00`:`cron: ${t}`}function $g(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 _d(t,n){return t.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).map((s,i)=>{const o=`${n}-${i}`;return s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:s.slice(2,-2)},o):s.startsWith("*")&&s.endsWith("*")&&s.length>2?e.jsx("em",{children:s.slice(1,-1)},o):e.jsx("span",{children:s},o)})}function nc(t,n){return t.split(/(`[^`\n]+`)/g).map((s,i)=>i%2===1?e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:s.slice(1,-1)},`${n}-${i}`):_d(s,`${n}-${i}`))}function Ko(t,n){return Mg(t).map((r,s)=>{if(r.type==="code")return e.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.84em",background:"rgba(17,24,39,0.06)",padding:"1px 5px",borderRadius:4,color:"var(--accent)",border:"1px solid var(--border-subtle)"},children:r.value},s);if(r.type==="link")return e.jsx("a",{className:"chat-message-link",href:r.href,target:"_blank",rel:"noopener noreferrer",children:nc(r.label,`${s}-label`)},s);if(r.type==="artifact"){if(!n)return e.jsx("span",{children:r.raw},s);const i=r.line?`${r.path}:${r.line}`:r.path,o=r.label.replace(/^`([^`\n]+)`$/,"$1");return e.jsxs("button",{type:"button",className:"chat-message-artifact-link",title:i,"aria-label":`打开交付物 ${o}`,onClick:()=>n(r.path),children:[e.jsx(ai,{size:16,strokeWidth:1.8,"aria-hidden":"true"}),e.jsx("span",{children:nc(r.label,`${s}-label`)})]},s)}return _d(r.value,`${s}`)})}function Ug(t){if(t.length<2)return null;const n=o=>o.replace(/^\|/,"").replace(/\|$/,"").split("|").map(c=>c.trim()),r=n(t[0]),s=t[1].replace(/^\|/,"").replace(/\|$/,"");if(!/^[\s\-:|]+$/.test(s))return null;const i=t.slice(2).map(n);return{headers:r,rows:i}}function Hg(t,n,r){const s=i=>({padding:"6px 14px",textAlign:"left",fontSize:13,fontWeight:i?600:400,color:i?"var(--text-primary)":"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"pre-wrap",wordBreak:"break-word"});return e.jsx("div",{style:{margin:"8px 0",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",overflow:"auto",background:"var(--bg-surface)"},children:e.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"var(--bg-deep)"},children:t.map((i,o)=>e.jsx("th",{style:s(!0),children:Ko(i,r)},o))})}),e.jsx("tbody",{children:n.map((i,o)=>e.jsx("tr",{style:{background:o%2===0?"transparent":"rgba(0,0,0,0.015)"},children:i.map((c,d)=>e.jsx("td",{style:s(!1),children:Ko(c,r)},d))},o))})]})})}function qg(t,n,r){return t.toLowerCase()==="mermaid"?e.jsx(Np,{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 zd(t,n){const s=t.replace(/(^|\n)(?:[a-z][\w+#.-]{0,20}\n)?(?:复制|copy)\n(?:下载|download)(?:\n|$)/gi,"$1").split(`
451
- `),i=[];let o=0,c=0;const d=g=>g.trimStart().startsWith("```"),u=g=>s[g].trimStart().startsWith("|")&&g+1<s.length&&/^\|[\s\-:|]+\|$/.test(s[g+1].trim());for(;o<s.length;){if(d(s[o])){const g=s[o].trim().slice(3).trim();o++;const f=[];for(;o<s.length&&!d(s[o]);)f.push(s[o]),o++;const x=o<s.length;o++,i.push(e.jsx("div",{children:qg(g,f.join(`
452
- `),x)},`code-${c++}`));continue}if(u(o)){const g=[];for(;o<s.length&&s[o].trimStart().startsWith("|");)g.push(s[o].trim()),o++;const f=Ug(g);f?i.push(e.jsx("div",{children:Hg(f.headers,f.rows,n)},`tbl-${c++}`)):i.push(e.jsx("span",{children:g.map((x,y)=>e.jsxs("span",{children:[$g(x),y<g.length-1?`
453
- `:null]},y))},`tbl-fb-${c++}`))}else{const g=[];for(;o<s.length&&!u(o)&&!d(s[o]);)g.push(s[o]),o++;g.length>0&&i.push(e.jsx("span",{children:g.map((f,x)=>e.jsxs("span",{children:[Ko(f,n),x<g.length-1?`
454
- `:null]},x))},`txt-${c++}`))}}return e.jsx(e.Fragment,{children:i})}const Ld=[{value:"off",label:"关"},{value:"low",label:"低"},{value:"medium",label:"中"},{value:"high",label:"高"}],rc=Object.fromEntries(Ld.map(t=>[t.value,t.label])),Vg=750,Co={low:"低",medium:"中",high:"高",xhigh:"超高",max:"最大"},sc={codex:"Codex","claude-code":"Claude Code",opencode:"OpenCode"};function Gg(t,n){return n==="codex"?t==="openai":n==="claude-code"?t==="anthropic":!1}const zi=[{value:"request-approval",label:"请求批准",description:"编辑外部文件和使用互联网时始终询问"},{value:"auto-approval",label:"帮我批准",description:"仅对检测到的风险操作请求批准"},{value:"full-access",label:"完全访问权限",description:"可不受限制地访问互联网和你电脑上的任何文件"}];function ic(t){return zi.some(n=>n.value===t)?t:"full-access"}function Kg({activeAgentType:t="customer-agent",selectedProjectId:n=null,selectedSessionId:r=null,onSessionCreated:s,onMessageSent:i,onSubSessionCreated:o,onSelectSession:c,onSubAgentEvent:d,onRunComplete:u,sessionTitle:g,sessionSummary:f,workspacePath:x=null,onOpenSettings:y,settingsOpen:v=!1,onHideToBackground:S,onOpenHub:E,onOpenDesktopLive:C,desktopLiveOpen:I=!1,fileDrawerOpen:j=!1,onToggleFiles:k,onOpenArtifact:W,onToggleAppearance:ee,appearanceOpen:N=!1,hideToBackgroundTitle:T,voiceCommand:A=null}){var Oa,$a,Ua,Ha,qa,Va,Ga,Ka,Qa,Xa;const R=a.useCallback(l=>zd(l,W),[W]),{messages:L,messagesBySession:H,runningSessionId:de,appendText:Fe,addMessage:fe,setRunningSession:je,setSessionId:ze,updateToolResult:Ge,updateSubAgentStatus:Ke,updateSubAgentProgress:Ct,updateMessage:it,setMessages:te,getMessagesForSession:ge,contextUsageBySession:Qe,runtimeProgressBySession:B,nativeSubagentsBySession:G,setContextUsage:Y,applyRuntimeProgress:ae,setRuntimeProgress:me,clearRuntimeProgress:le,applyNativeSubagentActivity:Se,setNativeSubagentActivities:Te,applyReasoningSummary:mt,applyCodexExecutionEvent:$e,clearMessages:yt,sessionId:st,todos:tt,setTodos:It,cronTasks:ft,setCronTasks:P}=et(),[K,X]=a.useState({active:null,queued:[],history:[]}),[J,ne]=a.useState(null),[ct,ht]=a.useState(0),ot=ff(L,H,st,r),Ue=a.useMemo(()=>Md(ch(ot.filter(l=>!l.isQueued),K.queued)),[K.queued,ot]),$t=a.useMemo(()=>{var l,p;return(p=(l=Ue.findLast(h=>h.executionTrace))==null?void 0:l.executionTrace)==null?void 0:p.turnId},[Ue]),{revision:tn,isConfigured:Xe,profiles:pt,activeProfileId:Dt,switchActiveProfile:Bt,loadFromSystem:gn,contextWindow:Ut,reasoningEffort:Re,taskNotifications:Tn,setField:Nn,saveToSystem:_n}=Ui(),Z=r||st,[_t,Xt]=a.useState({}),Tt=a.useRef({}),Et=a.useCallback((l,p)=>{const h=l?Dg(Tt.current,l):p?Wg(Tt.current,p):Tt.current;Tt.current=h,Xt(h)},[]),at=Es(_t,Z),[Ft,qt]=a.useState(!1),[zt,Sn]=a.useState("idle"),[tr,Qn]=a.useState(!1);a.useEffect(()=>{if(!Fo()||!window.browserLiveApi)return;const l=()=>Qn(!0);return window.addEventListener(tl,l),()=>window.removeEventListener(tl,l)},[]);const[Cn,Un]=a.useState(null),[Yt,Xn]=a.useState(null),mn=ph(r,f,t),Ie=mn.agentType,xt=mn.ready&&gh(f,t),[Vt,Yn]=a.useState([]),[Hn,on]=a.useState(null),O=a.useRef(null),[Ye,qn]=a.useState(()=>bl(Ie)),[Ot,q]=a.useState(!1),re=a.useRef(null);a.useEffect(()=>{qn(bl(Ie)),q(!1)},[Ie]),a.useEffect(()=>{var p;if(!xt||!((p=window.agentApi)!=null&&p.listAgentModels)||O.current===Ie)return;const l=Ie;O.current=l,Yn([]),on(null),window.agentApi.listAgentModels(l).then(h=>{O.current===l&&(Yn(h.models??[]),on(l))}).catch(()=>{O.current===l&&(Yn([]),on(null),O.current=null)})},[xt,Ie]),a.useEffect(()=>{if(!Ot)return;const l=p=>{re.current&&!re.current.contains(p.target)&&q(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[Ot]);const ce=a.useCallback(l=>{qn(p=>{const h={...p,...l};return yl(Ie,h),h})},[Ie]),Ce=a.useMemo(()=>xt?Vt.map(l=>({key:si(l),label:l.displayName||l.id,model:{id:l.id,...l.providerID?{providerID:l.providerID}:{}},reasoningEfforts:l.reasoningEfforts})):[],[xt,Vt]),He=a.useMemo(()=>xt?(pt??[]).filter(l=>{var p;return(p=l.modelId)==null?void 0:p.trim()}).filter(l=>Ie==="opencode"||Gg(l.provider,Ie)).map(l=>({key:Ie==="opencode"?si({id:l.modelId,providerID:l.provider}):l.modelId,label:l.name||l.modelId,model:{id:l.modelId,...Ie==="opencode"?{providerID:l.provider}:{}}})):[],[xt,pt,Ie]),xn=a.useMemo(()=>Ie==="opencode"?tf(Vt):[],[Ie,Vt]),Jn=a.useMemo(()=>new Set([...Ce.map(l=>l.key),...He.map(l=>l.key)]),[Ce,He]),Lt=Hn===Ie&&tn!==void 0,nn=a.useMemo(()=>Zp(Ye,Jn,Lt),[Jn,Lt,Ye]);a.useEffect(()=>{nn!==Ye&&(qn(nn),yl(Ie,nn))},[Ie,nn,Ye]);const Gt=(Oa=nn.model)!=null&&Oa.id?si(nn.model):"",Er=a.useMemo(()=>{var p;const l=Ce.find(h=>h.key===Gt);if((p=l==null?void 0:l.reasoningEfforts)!=null&&p.length)return l.reasoningEfforts;if(Ie==="claude-code")return["low","medium","high","xhigh"]},[Ce,Gt,Ie]),Mr=a.useMemo(()=>xt?Ie==="codex"?Er??[]:Ie==="claude-code"?Er??["low","medium","high","xhigh"]:[]:[],[xt,Ie,Er]),Nt=nn.reasoningEffort&&Mr.includes(nn.reasoningEffort)?nn.reasoningEffort:void 0,as=Ce.length>0||He.length>0,nr=(f==null?void 0:f.messageQueueVersion)===1,bn=Qf(f==null?void 0:f.agentType),zn=Cn===Z?"direct":Yt?"incompatible":($a=f==null?void 0:f.compatibility)==null?void 0:$a.status,rn=zn!==void 0&&zn!=="direct",dr=rn||(f==null?void 0:f.occupancy)==="owned-externally"&&f.agentType!=="codex",Hr=Fg(at,Z),ls=Hr&&(at==null?void 0:at.forkSessionId)!==Z,ur=Xe||xt,an=mn.ready&&ur&&!dr&&!Hr&&zt!=="released",dt=a.useRef(new Set),[Jt,Ln]=a.useState("idle"),In=a.useRef("idle"),Pn=a.useRef(null),[Zt,rr]=a.useState(()=>Date.now()),yn=a.useCallback(l=>{Pn.current=l,In.current="thinking",rr(Date.now()),Ln("thinking")},[]),gt=!!(Z&&(de===Z||dt.current.has(Z))),Dn=bh(f,gt),sn=gt||mh(f),qr=Z?B[Z]??[]:[],Rn=Z?G[Z]??{}:{},Vr=nf(qr),pr=Ue[Ue.length-1],Ar=!!((pr==null?void 0:pr.role)==="assistant"&&Jt==="thinking"&&((Ha=(Ua=pr.presentation)==null?void 0:Ua.reasoning)!=null&&Ha.some(l=>l.text.trim()))),Ps=Jt==="tools"&&Ue.some(l=>{var p;return((p=l.toolCalls)==null?void 0:p.length)&&!bo(l.toolCalls)}),cs=sn&&!Vr&&!Ar&&!Ps;a.useEffect(()=>{gn()},[]),a.useEffect(()=>{window.agentApi&&window.agentApi.cronList().then(l=>P(l))},[]);const[En,Kt]=a.useState(""),[b,M]=a.useState(null),[F,ie]=a.useState(""),[ue,Je]=a.useState(null),[Ne,Ee]=a.useState(()=>new Set),qe=a.useRef(new Set),[vt,Mn]=a.useState(null),vn=a.useRef(null),[ds,us]=a.useState(!1),[Gr,Tr]=a.useState(!1),[Nr,ps]=a.useState(!1),[fr,Ve]=a.useState("full-access"),[hr,en]=a.useState(!1),[gr,fs]=a.useState(null),[hs,Ds]=a.useState(!1),Ws=a.useRef(null),ln=a.useRef(null),wn=a.useCallback((l,p)=>{var D;const h=rt.current||Pt.current;if(p===h&&(X(Ol(l)),((D=l.active)==null?void 0:D.kind)==="message"&&(In.current!=="thinking"||Pn.current!==p)&&yn(p),m.current==="anchored"))return;const w=ge(p);te(mo(w,l),p)},[yn,ge,te]);a.useEffect(()=>{if(!Gr)return;const l=p=>{Ws.current&&!Ws.current.contains(p.target)&&Tr(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[Gr]),a.useEffect(()=>{if(!Nr)return;const l=p=>{ln.current&&!ln.current.contains(p.target)&&ps(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[Nr]),a.useEffect(()=>{ps(!1),Ve(ic(f==null?void 0:f.permissionMode))},[xt,r,f==null?void 0:f.permissionMode]);const[gs,_e]=a.useState(null),[sr,ir]=a.useState(null),[Wn,cn]=a.useState(null),[ci,di]=a.useState(0),[ui,Bs]=a.useState([]),[mr,dn]=a.useState([]),[Fs,ms]=a.useState(0),[Os,Kr]=a.useState(null),Bn=a.useRef(null),pi=a.useRef(null),_r=a.useRef(null),xs=a.useRef(()=>{}),Qr=a.useRef(new wp),$s=a.useRef(()=>{}),Fn=a.useRef(null),xr=a.useRef(null),Vn=a.useRef(null);Vn.current||(Vn.current=new _f);const On=a.useRef(null),m=a.useRef("latest"),_=a.useRef(null),U=a.useRef(!1),V=a.useRef(null),Q=a.useRef(0),we=a.useRef(0),ve=a.useRef(null),Le=a.useRef(!1),Ze=a.useRef(!1),Qt=a.useRef(null),An=a.useRef(!1),Me=a.useRef(!1),bt=a.useRef(null),jn=a.useRef(null),Mt=a.useRef(0),or=a.useRef(null),ar=a.useRef(new Map),Gn=a.useRef(new Set),Xr=a.useRef(null),br=a.useRef(!1),Ht=a.useRef(null),lr=a.useRef(null),nt=a.useRef(null);nt.current||(nt.current=new sh(new rh));const ut=nt.current,bs=a.useRef(!1),Ki=a.useRef(null),yr=a.useRef(null),fi=a.useRef(uh(ec)),[ma,xa]=a.useState(!1),[hi,gi]=a.useState(null),[Qi,Xi]=a.useState(null),[Us,Gd]=a.useState("latest"),[Kd,ys]=a.useState(null),[Qd,vs]=a.useState(null),[Xd,ws]=a.useState(!1),[Yd,ba]=a.useState(!1),[Yi,mi]=a.useState(!1),[Jd,Ji]=a.useState(!1),[xi,bi]=a.useState(!1),[Zd,yi]=a.useState(!1),ya=a.useRef(null),Hs=a.useRef(null),Zi=a.useRef(null),[zr,va]=a.useState(null),[eu,wa]=a.useState([]),[tu,ja]=a.useState([]),[qs,eo]=a.useState([]),[Vs,Yr]=a.useState(null),[Jr,Zr]=a.useState(null),wt=a.useCallback(l=>rt.current===l?f==null?void 0:f.agentType:l.startsWith("runtime:codex:")?"codex":void 0,[f==null?void 0:f.agentType]),un=a.useCallback((l,p)=>{if(!p)return;const h=`${l}:${p}`;or.current!==h&&(or.current=h,ar.current.clear())},[]),to=a.useCallback(async l=>{const p=window.agentApi,h=rt.current;if(!p||!h)throw new Error("当前会话不可用");un(h,l.revision);const w=`${l.turnId}:${l.itemId}`;let D=ar.current.get(w);D||(D=p.getSessionToolResult(h,l),ar.current.set(w,D),D.catch(()=>{ar.current.get(w)===D&&ar.current.delete(w)}));const z=await D;return rt.current!==h||or.current!==`${h}:${l.revision}`,z},[un]),ka=a.useCallback(async l=>{const p=rt.current;if(!p)throw new Error("当前会话不可用");const h=await to(l);rt.current===p&&Ge(l.itemId,h.content,h.isError,p)},[to,Ge]),nu=a.useCallback(async l=>{var z;const p=window.agentApi,h=rt.current;if(!p||!h)throw new Error("当前会话不可用");const w=await wf(p,h,l,kr),D=w.detail;if(rt.current!==h)throw new DOMException("Session selection changed","AbortError");if(((z=D==null?void 0:D.history)==null?void 0:z.revision)!==w.revision)throw new Error("会话内容已更新,请重新展开执行过程");return w.recovered&&te(ge(h).map(xe=>xe.executionTrace?{...xe,executionTrace:{...xe.executionTrace,revision:w.revision}}:xe),h),un(h,w.revision),Sf(D)},[ge,te,un]);a.useEffect(()=>{or.current=null,ar.current.clear()},[r]);const cr=a.useCallback((l,p)=>{const h=window.agentApi;!p||!h||Vn.current.prefetch(l,p,()=>h.getSession(l,{before:p,limit:wt(l)==="codex"?ni:kr,...wt(l)==="codex"?{view:"core"}:{}})).catch(w=>{console.warn("[chat] failed to prefetch older history",{sessionId:l,error:w})})},[wt]),es=a.useCallback(l=>{m.current=l,Gd(l)},[]);a.useEffect(()=>{const l=eh(Xr.current,Z,En);if(Xr.current=l.ownerSessionId,l.type==="inactive"){lr.current=null,ut.restore(null),dn([]);return}if(l.type==="restore"){const h=l.ownerSessionId.startsWith("runtime:")?Es(Tt.current,l.ownerSessionId):void 0;Kt((h==null?void 0:h.payload.content)??Zf(l.ownerSessionId)),dn([]),lr.current=l.ownerSessionId,ut.restore(l.ownerSessionId).then(w=>{if(!w||Xr.current!==w.sessionId)return;lr.current===w.sessionId&&(lr.current=null);const D=(h==null?void 0:h.payload.images)??w.images;dn(D),h&&ut.save(w.sessionId,D)});return}if(br.current&&En===""){br.current=!1;return}Wr(l.ownerSessionId,l.value)},[ut,En,Z]),a.useEffect(()=>{if(!(!Z||Xr.current!==Z)&&lr.current!==Z){if(Ht.current===Z&&mr.length===0){Ht.current=null;return}ut.saveSelected(Z,mr)}},[ut,mr,Z]);const ru=()=>{const l=Bn.current;if(!l)return;const p=l.scrollHeight-l.scrollTop-l.clientHeight;l.scrollTop<=240&&xs.current(),m.current==="anchored"&&p<=240&&$s.current(),Ji(fi.current.onScroll(p)),l.classList.add("is-scrolling"),_r.current!==null&&window.clearTimeout(_r.current),_r.current=window.setTimeout(()=>{l.classList.remove("is-scrolling"),_r.current=null},700)};a.useEffect(()=>()=>{_r.current!==null&&window.clearTimeout(_r.current)},[]);const su=a.useCallback(()=>{const l=Bn.current;if(!l)return;fi.current.requestReturn();const p=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;l.scrollTo({top:l.scrollHeight,behavior:p?"auto":"smooth"})},[]);a.useEffect(()=>{fi.current.reset(),Ji(!1)},[r]),a.useLayoutEffect(()=>{const l=Ki.current,p=Bn.current;!l||!p||(p.scrollTop=l.scrollTop+(p.scrollHeight-l.scrollHeight),Ki.current=null)},[ot]),a.useLayoutEffect(()=>{const l=ve.current,p=Bn.current;if(!l||!p)return;const h=Array.from(p.querySelectorAll("[data-message-id]")).find(w=>w.dataset.messageId===l);h&&(Io(p,h),ve.current=null,ys(l))},[ot]),a.useLayoutEffect(()=>{const l=Bn.current;!Le.current||!l||Us!=="latest"||(Le.current=!1,l.scrollTop=l.scrollHeight)},[Us,ot]),a.useLayoutEffect(()=>{if(yr.current!=="skip")return;const l=Bn.current;l&&Ji(l.scrollHeight-l.scrollTop-l.clientHeight>ec)},[ot]);const[Sa,no]=a.useState(!1),[Gs,Ks]=a.useState(null),vi=a.useRef(null);a.useEffect(()=>{const l=window.agentApi;if(!(l!=null&&l.onTtsStart)||!l.onTtsPcm||!l.onTtsStreamEnd||!l.onTtsFlush)return;const p=new vf(l),h=[l.onTtsStart(w=>p.start(w)),l.onTtsPcm(({generation:w,pcm:D})=>p.enqueue(w,D)),l.onTtsStreamEnd(({generation:w})=>p.finish(w)),l.onTtsFlush(({generation:w})=>p.flush(w)),l.onTtsEnd(()=>Ks(null))];return()=>{for(const w of h)w();p.dispose()}},[]);const iu=()=>{var h;if(Sa){(h=vi.current)==null||h.stop(),vi.current=null,no(!1);return}Si(window.agentApi,Zs);const l=En?`${En.trimEnd()} `:"",p=mf({onInterim:w=>Kt(l+w),onFinal:w=>{var D;Kt(l+w),(D=Hs.current)==null||D.focus()},onError:w=>_e(w),onEnd:()=>{no(!1),vi.current=null}});p&&(vi.current=p,no(!0))},ou=async(l,p)=>{var h;if(Gs===l){await Si(window.agentApi,Zs),Ks(null);return}if(await Si(window.agentApi,Zs),!((h=window.agentApi)!=null&&h.ttsSpeak)){_e("TTS 模型服务不可用");return}Ks(l);try{(await window.agentApi.ttsSpeak(p)).ok||(Ks(null),_e("TTS 模型播报失败"))}catch(w){Ks(null),_e(w instanceof Error?w.message:"TTS 模型播报失败")}},Rt=a.useRef(null),ts=a.useRef(!1),vr=a.useRef(new Set),Qs=a.useRef(new Map),Ca=a.useRef(new Set),Kn=a.useRef(new Map),Lr=a.useRef(null),rt=a.useRef(r??null),Ia=a.useRef({onRunComplete:u,selectedProjectId:n}),Pt=a.useRef(null),js=a.useRef(0);a.useEffect(()=>{rt.current=r??null},[r]),a.useEffect(()=>{Ia.current={onRunComplete:u,selectedProjectId:n}},[u,n]),a.useEffect(()=>{Pt.current=st},[st]),a.useEffect(()=>()=>{for(const l of Qs.current.values())window.clearTimeout(l);Qs.current.clear()},[]);const wi=a.useCallback(async l=>{var h;const p=l||rt.current||Pt.current;if(!p||!((h=window.agentApi)!=null&&h.getSessionGoals)){X({active:null,queued:[],history:[]});return}try{const w=await window.agentApi.getSessionGoals(p);wn(w,p),w.active&&(Rt.current=p,je(p))}catch(w){_e(w instanceof Error?w.message:"目标状态加载失败")}},[wn,je]);a.useEffect(()=>{wi(Z)},[Z,wi]);const Xs=a.useCallback(async l=>{var h;const p=l||rt.current||Pt.current;if(!p||typeof((h=window.agentApi)==null?void 0:h.getThreadGoal)!="function"){ne(null);return}try{ne(await window.agentApi.getThreadGoal(p))}catch{ne(null)}},[]);a.useEffect(()=>{Xs(Z)},[Z,Xs]);const ro=a.useCallback(async l=>{var h;const p=rt.current||Pt.current;if(!(!p||typeof((h=window.agentApi)==null?void 0:h.clearThreadGoal)!="function"))try{l==="clear"?(await window.agentApi.clearThreadGoal(p),ne(null)):typeof window.agentApi.updateThreadGoal=="function"&&ne(await window.agentApi.updateThreadGoal(p,l))}catch(w){_e(w instanceof Error?w.message:"目标模式操作失败")}},[_e]),pn=a.useCallback(l=>{const p=rt.current||Pt.current;l==="thinking"&&(In.current!=="thinking"||Pn.current!==p)?(Pn.current=p,rr(Date.now())):l!=="thinking"&&(Pn.current=null),In.current=l,Ln(l)},[]);a.useEffect(()=>{qt(!1),Sn("idle"),ir(null),Kr(null)},[r]),a.useEffect(()=>{window.agentApi&&(window.agentApi.listAgentDefs().then(l=>wa(l)),window.agentApi.listSkills().then(l=>ja(l.filter(p=>p.name))).catch(l=>console.error("[listSkills] mount error:",l)))},[]);const Ra=Vs===null?[]:eu.filter(l=>Vs===""||l.name.toLowerCase().includes(Vs.toLowerCase())),so=Jr===null?[]:[...[{name:"goal",description:"目标模式:持续推进当前目标,后续目标自动排队"},{name:"compact",description:"主动压缩当前会话上下文,并在下轮重新注入环境"},{name:"loop",description:"定时任务:/loop 5m 任务 | list | pause/resume/delete <id> | stop"}].filter(l=>Jr===""||l.name.toLowerCase().includes(Jr.toLowerCase())),...tu.filter(l=>Jr===""||l.name.toLowerCase().includes(Jr.toLowerCase()))],au=l=>{eo(p=>p.find(h=>h.id===l.id)?p:[...p,l]),Kt(p=>p.replace(/@[\w\u4e00-\u9fff]*$/,"")),Yr(null),setTimeout(()=>{var p;return(p=Hs.current)==null?void 0:p.focus()},0)},lu=l=>{eo(p=>p.filter(h=>h.id!==l))},cu=l=>{Kt(p=>p.replace(/\/[\w\u4e00-\u9fff\-_]*$/,`/${l.name} `)),Zr(null),setTimeout(()=>{var p;return(p=Hs.current)==null?void 0:p.focus()},0)},Ea=l=>{var w,D;Kt(l);const p=l.match(/@([\w\u4e00-\u9fff]*)$/);if(p){window.agentApi&&window.agentApi.listAgentDefs().then(z=>wa(z)),va(((w=Zi.current)==null?void 0:w.getBoundingClientRect())??null),Yr(p[1]),Zr(null);return}const h=l.match(/\/([-\w\u4e00-\u9fff]*)$/);if(h){window.agentApi&&window.agentApi.listSkills().then(z=>ja(z.filter(xe=>xe.name))).catch(z=>console.error("[listSkills] slash error:",z)),va(((D=Zi.current)==null?void 0:D.getBoundingClientRect())??null),Zr(h[1]),Yr(null);return}Yr(null),Zr(null)},du=l=>{Ea(l),Yr(null),Zr(null),requestAnimationFrame(()=>{var p;return(p=Hs.current)==null?void 0:p.focus()})},uu=l=>{l.key==="Escape"&&(Vs!==null||Jr!==null)?(l.preventDefault(),Yr(null),Zr(null)):l.key==="Escape"&&gt?(l.preventDefault(),co()):l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),Fa())},pu=async l=>{const p=Array.from(l.target.files??[]);if(l.target.value="",p.length===0)return;const h=p.filter(w=>w.type.toLowerCase().startsWith("image/")).length;h>0&&ms(w=>w+1);try{const w=await Pg(p,async z=>Ma(await Ll(z)));w.attachments.length>0&&Bs(z=>[...z,...w.attachments]),w.images.length>0&&(dn(z=>[...z,...w.images]),xt||gu());const D=[...w.unsupportedImages,...w.failedImages];D.length>0&&_e(`无法添加图片:${D.map(z=>z.name).join("、")}。仅支持 JPG、PNG、GIF 和 WebP。`)}finally{h>0&&ms(w=>Math.max(0,w-1))}},fu=l=>{Bs(p=>p.filter((h,w)=>w!==l))},hu=/claude-3|gpt-4-vision|gpt-4o|gpt-4-turbo|gemini|deepseek-vl/i,io=l=>hu.test(l),gu=()=>{const l=pt.find(h=>h.id===Dt);if(l&&io(l.modelId))return;const p=pt.find(h=>io(h.modelId));p&&Bt(p.id)},mu=l=>{dn(p=>[...p,l])},xu=l=>{dn(p=>p.filter((h,w)=>w!==l))},Ma=l=>new Promise((p,h)=>{const w=new FileReader;w.onload=()=>p(w.result),w.onerror=h,w.readAsDataURL(l)});a.useEffect(()=>{const l=async p=>{if(!p.clipboardData)return;const h=Array.from(p.clipboardData.items).find(D=>D.type.startsWith("image/"));if(!h)return;p.preventDefault();const w=h.getAsFile();if(w){ms(D=>D+1);try{mu(await Ma(await Ll(w)))}catch{_e("无法添加图片。仅支持 JPG、PNG、GIF 和 WebP。")}finally{ms(D=>Math.max(0,D-1))}}};return window.addEventListener("paste",l),()=>window.removeEventListener("paste",l)},[pt,Dt]),a.useEffect(()=>{var p;const l=yr.current;yr.current=null,fi.current.shouldFollow(l)&&((p=pi.current)==null||p.scrollIntoView({behavior:"auto"}))},[ot]),a.useEffect(()=>window.agentApi?window.agentApi.onEvent(p=>bu(p)):void 0,[st]),a.useEffect(()=>{const l=++js.current,p=r,h=()=>js.current===l&&rt.current===p;return(async()=>{var xe,pe,Pe;const D=window.agentApi;if(!D||bg(Rt.current,Pt.current,p))return;if(!p){if(!h())return;(xe=Vn.current)==null||xe.invalidate(),yt(),_e(null),cn(null),Un(null),Xn(null),Fn.current=null,xr.current=null,_.current=null,Q.current+=1,V.current=null,Xi(null),es("latest"),ys(null),vs(null),Ze.current=!1,mi(!1),ws(!1),gi(null),bi(!1),yi(!1),On.current=null,Pt.current=null,ze(""),Ve("full-access");return}_e(null),cn(null),Un(null),Xn(null),gi(null),(pe=Vn.current)==null||pe.invalidate(),we.current+=1,Fn.current=null,xr.current=null,_.current=null,es("latest"),ws(!1),ys(null),vs(null),Ze.current=!1,mi(!1),((Pe=V.current)==null?void 0:Pe.sessionId)!==p&&(Q.current+=1,V.current=null,Xi(null)),bi(!0),yi(!0),On.current=p,Pt.current=p,ze(p);const z=ge(p);te(z,p);try{await Uf(async()=>{if(!h())throw new DOMException("Session selection changed","AbortError");return await Ss(D,p,wt(p),{limit:wt(p)==="codex"?ko:kr},($,be)=>{var St,ye,Wt,Dr;if(!h())return;const oe=$,Ae=jl(($==null?void 0:$.events)??[]),Be=vl(($==null?void 0:$.events)??[]),he=kl(($==null?void 0:$.events)??[]),ke=Cs($);un(p,(St=$==null?void 0:$.history)==null?void 0:St.revision),f!=null&&f.compatibility&&Un(p),Ve(ic((oe==null?void 0:oe.permissionMode)??((ye=oe==null?void 0:oe.metadata)==null?void 0:ye.permissionMode)));const Oe=((Wt=$==null?void 0:$.history)==null?void 0:Wt.nextCursor)??null;Fn.current=Oe,xr.current=Oe,_.current=null;const De=ge(p),jt=Al(De,ke,be,$==null?void 0:$.history),We=$!=null&&$.goalState?mo(jt,$.goalState):jt;yr.current="instant",te(We,p),cr(p,Oe),me(Be,p),Te(he,p),md($)||xh($)?(Rt.current=p,je(p)):Rt.current===p&&(Rt.current=null,je(null)),Ae&&Y(Ae,p);const kt=We[We.length-1];(kt==null?void 0:kt.role)==="assistant"&&((Dr=kt.toolCalls)!=null&&Dr.length)?pn(bo(kt.toolCalls)?"thinking":"tools"):pn(($==null?void 0:$.agentType)!=="customer-agent"&&($==null?void 0:$.status)==="running"?"thinking":"idle"),bi(!1),yi(!1)},h),!0})}catch($){if(!h())return;console.error("[chat] failed to restore session",{sessionId:p,error:$});const be=$f($);cn(be),f!=null&&f.compatibility&&Xn(be)}finally{h()&&(bi(!1),yi(!1))}})(),()=>{js.current===l&&(js.current+=1)}},[yt,ge,wt,cr,r,ci,Y,es,te,ze,un,pn]);const Pr=a.useCallback(async l=>{const p=window.agentApi;if(!(p!=null&&p.getSessionQueryIndex))return null;const h=++Q.current;try{const w=await p.getSessionQueryIndex(l);return Q.current!==h||rt.current!==l||w.sessionId!==l?null:(V.current=w,Xi(w),w)}catch(w){return Q.current===h&&console.warn("[chat] failed to load query index",{sessionId:l,error:w}),null}},[]),Aa=a.useCallback(l=>{if(jn.current!==l&&(bt.current!==null&&window.clearTimeout(bt.current),jn.current=l,bt.current=null,Mt.current=0),bt.current!==null)return;const p=Math.max(0,Vg-(Date.now()-Mt.current));bt.current=window.setTimeout(()=>{bt.current=null,Mt.current=Date.now(),rt.current===l&&ht(h=>h+1)},p)},[]);a.useEffect(()=>{var z;const l=r;if(!l||xi||!((z=window.agentApi)!=null&&z.getSessionQueryIndex))return;let p=!1;const h=()=>{!p&&rt.current===l&&Pr(l)},w=window,D=w.requestIdleCallback?w.requestIdleCallback(h,{timeout:1e3}):window.setTimeout(h,0);return()=>{p=!0,w.cancelIdleCallback&&w.requestIdleCallback?w.cancelIdleCallback(D):window.clearTimeout(D)}},[xi,Pr,r,ci]);const oo=a.useCallback(async l=>{if(!(!window.agentApi||document.visibilityState==="hidden")){if(m.current==="anchored"){ws(!0);return}if(Qt.current!==l&&(Qt.current=l,An.current=!1,Me.current=!1),An.current){Me.current=!0;return}An.current=!0;try{do Me.current=!1,await Ss(window.agentApi,l,wt(l),{limit:wt(l)==="codex"?ko:kr},(p,h)=>{var Be,he,ke,Oe,De,jt;const w=Cs(p),D=ge(l),z=Al(D,w,h,p==null?void 0:p.history),xe=p!=null&&p.goalState?mo(z,p.goalState):z,pe=Bn.current,Pe=!pe||pe.scrollHeight-pe.scrollTop-pe.clientHeight<80;yr.current=Pe?null:"skip",te(xe,l),un(l,(Be=p==null?void 0:p.history)==null?void 0:Be.revision),p!=null&&p.goalState&&X(Ol(p.goalState));const $=xr.current,be=((he=p==null?void 0:p.history)==null?void 0:he.nextCursor)??null;if(Fn.current===$){const We=Fn.current!==be;Fn.current=be,We&&((ke=Vn.current)==null||ke.invalidate(),cr(l,be))}xr.current=be,(Oe=p==null?void 0:p.history)!=null&&Oe.revision&&p.history.revision!==((De=V.current)==null?void 0:De.revision)&&Pr(l);const oe=jl((p==null?void 0:p.events)??[]);me(vl((p==null?void 0:p.events)??[]),l),Te(kl((p==null?void 0:p.events)??[]),l),oe&&Y(oe,l);const Ae=xe[xe.length-1];(Ae==null?void 0:Ae.role)==="assistant"&&((jt=Ae.toolCalls)!=null&&jt.length)?pn(bo(Ae.toolCalls)?"thinking":"tools"):pn(la(p)?"thinking":"idle")},()=>rt.current===l&&On.current===l),wt(l)==="codex"&&Aa(l);while(Me.current)}catch(p){console.error("[chat] failed to refresh native session history",{sessionId:l,error:p})}finally{Qt.current===l&&(An.current=!1)}}},[ge,wt,Pr,cr,Aa,Y,te,un,pn]);a.useEffect(()=>{const l=r,p=yh(f,l)||(f==null?void 0:f.agentType)==="customer-agent"&&l!==de,h=(f==null?void 0:f.agentType)==="customer-agent"||(f==null?void 0:f.occupancy)==="owned-externally"||(f==null?void 0:f.status)==="running";if(!l||!p||!window.agentApi)return;let w=null,D=null,z=!1;const xe=()=>{!z&&document.visibilityState!=="hidden"&&oo(l)},pe=()=>{w==null||w(),w=null,D!==null&&window.clearInterval(D),D=null},Pe=()=>{z||D!==null||document.visibilityState==="hidden"||(xe(),D=window.setInterval(xe,2e3))},$=()=>{if(!(z||document.visibilityState==="hidden")){if(typeof window.agentApi.observeSession!="function"){h&&Pe();return}try{w=window.agentApi.observeSession(l,xe,()=>{w=null,h&&Pe()})}catch{h&&Pe()}}},be=()=>{pe(),document.visibilityState!=="hidden"&&(xe(),$())};return $(),document.addEventListener("visibilitychange",be),()=>{z=!0,document.removeEventListener("visibilitychange",be),pe(),Qt.current===l&&(Qt.current=null,Me.current=!1),jn.current===l&&(bt.current!==null&&window.clearTimeout(bt.current),jn.current=null,bt.current=null,Mt.current=0)}},[oo,r,de,f==null?void 0:f.agentType,f==null?void 0:f.occupancy,f==null?void 0:f.status]);const ao=a.useCallback(async()=>{const l=On.current,p=Fn.current,h=window.agentApi;if(!h||!l||!p||bs.current)return;bs.current=!0,gi(null);const w=window.setTimeout(()=>{On.current===l&&bs.current&&xa(!0)},500);try{const D=ge(l);await Ss(h,l,wt(l),{before:p,limit:wt(l)==="codex"?ni:kr},(z,xe)=>{var be;const pe=Cs(z),Pe=Bn.current;xe!=="trace"&&Pe&&pe.length>0&&(Ki.current={scrollHeight:Pe.scrollHeight,scrollTop:Pe.scrollTop},yr.current="skip");const $=jf(p,z,pe.length);Fn.current=$,un(l,(be=z==null?void 0:z.history)==null?void 0:be.revision),pe.length>0&&te([...pe,...D],l),xe!=="trace"&&cr(l,$)},()=>On.current===l&&rt.current===l,()=>Vn.current.consume(l,p,()=>h.getSession(l,{before:p,limit:wt(l)==="codex"?ni:kr,...wt(l)==="codex"?{view:"core"}:{}})))}catch(D){if(On.current!==l)return;console.error("[chat] failed to load older history",{sessionId:l,error:D}),gi(D instanceof Error?D.message:"历史消息加载失败")}finally{window.clearTimeout(w),bs.current=!1,On.current===l&&xa(!1)}},[ge,wt,cr,te,un]);a.useEffect(()=>{xs.current=()=>{ao()}},[ao]);const Ta=a.useCallback(async()=>{const l=On.current,p=_.current;if(!(!window.agentApi||!l||!p||m.current!=="anchored"||U.current)){U.current=!0,ba(!0);try{const h=ge(l),w=new Set(h.map(D=>D.id));await Ss(window.agentApi,l,wt(l),{after:p,limit:wt(l)==="codex"?ni:kr},D=>{var xe,pe;const z=Cs(D).filter(Pe=>!w.has(Pe.id));_.current=((xe=D==null?void 0:D.history)==null?void 0:xe.newerCursor)??null,un(l,(pe=D==null?void 0:D.history)==null?void 0:pe.revision),z.length>0&&(yr.current="skip",te([...h,...z],l))},()=>rt.current===l&&On.current===l&&m.current==="anchored")}catch(h){console.error("[chat] failed to load newer anchored history",{sessionId:l,error:h})}finally{U.current=!1,ba(!1)}}},[ge,wt,te,un]);a.useEffect(()=>{$s.current=()=>{Ta()}},[Ta]);const Na=a.useCallback(async()=>{const l=rt.current;if(!window.agentApi||!l||Ze.current)return!1;const p=++we.current;Ze.current=!0,mi(!0),vs(null);try{let h=!1;return await Ss(window.agentApi,l,wt(l),{limit:wt(l)==="codex"?ko:kr},(w,D)=>{var pe,Pe,$,be,oe,Ae,Be;h=!0;const z=Cs(w),xe=((pe=w==null?void 0:w.history)==null?void 0:pe.nextCursor)??null;D!=="trace"&&((Pe=Vn.current)==null||Pe.invalidate()),Fn.current=xe,xr.current=xe,_.current=null,un(l,($=w==null?void 0:w.history)==null?void 0:$.revision),es("latest"),ws(!1),ys(((oe=(be=V.current)==null?void 0:be.entries.at(-1))==null?void 0:oe.messageId)??null),Le.current=!0,yr.current="skip",te(z,l),D!=="trace"&&cr(l,xe),((Ae=w==null?void 0:w.history)==null?void 0:Ae.revision)!==((Be=V.current)==null?void 0:Be.revision)&&Pr(l)},()=>we.current===p&&rt.current===l),h}catch(h){return _e(h instanceof Error?h.message:"返回最新消息失败"),!1}finally{Ze.current=!1,mi(!1)}},[wt,Pr,cr,es,te,un]),_a=a.useCallback(async(l,p=!0)=>{var xe;const h=rt.current,w=Bn.current;if(!window.agentApi||!h||!w)return;const D=++we.current;ys(l.messageId);const z=Array.from(w.querySelectorAll("[data-message-id]")).find(pe=>pe.dataset.messageId===l.messageId);if(z){vs(null),Io(w,z,"smooth");return}vs(l.messageId),(xe=Vn.current)==null||xe.invalidate();try{await Ss(window.agentApi,h,wt(h),{anchor:l.pageToken,limit:wt(h)==="codex"?ni:kr},(pe,Pe)=>{var oe,Ae,Be,he,ke,Oe;if(((oe=V.current)==null?void 0:oe.revision)!==((Ae=pe==null?void 0:pe.history)==null?void 0:Ae.revision))return;const $=Cs(pe),be=((Be=pe==null?void 0:pe.history)==null?void 0:Be.olderCursor)??((he=pe==null?void 0:pe.history)==null?void 0:he.nextCursor)??null;Fn.current=be,_.current=((ke=pe==null?void 0:pe.history)==null?void 0:ke.newerCursor)??null,un(h,(Oe=pe==null?void 0:pe.history)==null?void 0:Oe.revision),es("anchored"),ws(!1),ve.current=l.messageId,yr.current="skip",te($,h),Pe!=="trace"&&(window.requestAnimationFrame(()=>{if(we.current!==D||rt.current!==h)return;const De=Bn.current,jt=Array.from((De==null?void 0:De.querySelectorAll("[data-message-id]"))??[]).find(We=>We.dataset.messageId===l.messageId);!De||!jt||(Io(De,jt),ve.current=null,ys(l.messageId))}),cr(h,be))},()=>we.current===D&&rt.current===h)}catch(pe){if(pe.code==="STALE_SESSION_ANCHOR"&&p){const $=await Pr(h),be=$==null?void 0:$.entries.find(oe=>oe.ordinal===l.ordinal);be&&await _a(be,!1);return}console.error("[chat] failed to open indexed query",{sessionId:h,error:pe}),_e(pe instanceof Error?pe.message:"无法打开这条消息")}finally{we.current===D&&vs(null)}},[wt,Pr,cr,es,te,un]),za=l=>{if(vr.current.has(l)||Qs.current.has(l))return;const p=window.setTimeout(()=>{Qs.current.delete(l),(async()=>{var h;if(!vr.current.has(l))try{const w=await((h=window.agentApi)==null?void 0:h.getSessionGoals(l));if(vr.current.has(l))return;const D=rt.current||Pt.current;if(w&&l===D&&wn(w,l),w!=null&&w.active){Rt.current=l,l===D&&(ts.current=!1,_e(null),je(l));return}if(ts.current)return;const z=et.getState().getMessagesForSession(l).find(xe=>xe.isQueued&&!xe.queueItemId);if(!z){Rt.current===l&&(Rt.current=null),et.getState().runningSessionId===l&&je(null);return}it(z.id,xe=>({...xe,isQueued:!1}),l),ks(z,l)}catch(w){_e(w instanceof Error?w.message:"排队消息自动发送失败")}})()},150);Qs.current.set(l,p)},ji=(l,p)=>{const h=et.getState().getMessagesForSession(l),w=lh(h);w&&it(w,D=>({...D,sendState:p}),l)},lo=(l,p)=>{const h=Zl(p),w=et.getState().getMessagesForSession(l);te(w.filter(D=>D.id!==h),l),Wr(l,p.payload.content),ut.save(l,p.payload.images??[]),(rt.current||Pt.current)===l&&(Kt(p.payload.content),dn(p.payload.images??[])),Kn.current.delete(l),Ht.current===l&&(Ht.current=null),Et(void 0,l)},bu=l=>{var z,xe,pe,Pe;const p=rt.current||Pt.current,h=fh(l._sid)??void 0;if(!h&&l.type!=="cron_update")return;if(l._nativeRunId&&Number.isSafeInteger(l._nativeSequence)){const $=`${l._nativeRunId}:${l._nativeSequence}`;if(Gn.current.has($))return;Gn.current.add($),Gn.current.size>2e3&&(Gn.current=new Set([...Gn.current].slice(-1e3)))}const w=!h||h===p,D=w&&m.current==="anchored";if(l._nativeRecoveredFromSnapshot&&h&&w&&oo(h),!(D&&(ws(!0),hh(l.type)))){if(h&&["run_admitted","thinking","text_chunk","reasoning_summary_delta","runtime_progress","tool_call","todo_update","done"].includes(l.type)&&ji(h),h&&w&&!l._preserveActiveRun&&["done","error","turn_aborted"].includes(l.type)&&!vr.current.has(h)){const $=Ia.current;(z=$.onRunComplete)==null||z.call($,$.selectedProjectId??null,h)}switch(l.type){case"run_admitted":if(h&&sr===h&&(ir(null),w&&_e(null)),h){Kn.current.delete(h);const $=Es(Tt.current,h);$&&(Lr.current===$.token&&(Lr.current=null),Et(void 0,h)),Is(h),ut.clear(h),Ht.current===h&&(Ht.current=null)}break;case"context_usage":if(l.usage&&(Y(l.usage,h),h&&!h.startsWith("runtime:"))){const $=(et.getState().runtimeProgressBySession[h]??[]).filter(be=>be.progressId!==sd);me($,h)}break;case"text_chunk":l.text&&(h&&l.turnId&&l.messagePhase==="commentary"&&wt(h)==="codex"?$e(l.turnId,{type:"text_chunk",text:l.text,turnId:l.turnId,itemId:l.itemId,messagePhase:"commentary"},h):Fe(l.text,h),w&&pn("thinking"));break;case"reasoning_summary_delta":if(typeof l.itemId=="string"&&Number.isSafeInteger(l.sectionIndex)&&typeof l.delta=="string"){const $={type:"reasoning_summary_delta",itemId:l.itemId,sectionIndex:l.sectionIndex,delta:l.delta,...l.turnId?{turnId:l.turnId}:{}};h&&l.turnId&&wt(h)==="codex"?$e(l.turnId,$,h):mt($,h),w&&pn("thinking")}break;case"runtime_progress":if(typeof l.progressId=="string"&&typeof l.label=="string"&&["thinking","tool","retry","status"].includes(l.phase??"")){const $={progressId:l.progressId,phase:l.phase,label:l.label,...l.detail===void 0?{}:{detail:l.detail},...l.toolCallId===void 0?{}:{toolCallId:l.toolCallId},...l.elapsedSeconds===void 0?{}:{elapsedSeconds:l.elapsedSeconds},...l.current===void 0?{}:{current:l.current},...l.total===void 0?{}:{total:l.total}};ae($,h),w&&pn($.phase==="tool"?"tools":"thinking")}break;case"native_subagent_update":(xe=l.activity)!=null&&xe.parentToolCallId&&(Se(l.activity,h),w&&l.activity.status==="running"&&pn("tools"));break;case"tool_call":w&&pn("tools"),l.toolCall&&l.toolCall.name!=="dispatch_agent"&&l.toolCall.name!=="ask_user"&&l.toolCall.name!=="show_widget"&&(h&&l.turnId&&wt(h)==="codex"?$e(l.turnId,{type:"tool_call",toolCall:l.toolCall,turnId:l.turnId},h):fe({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:l.toolCall.id,name:l.toolCall.name,arguments:l.toolCall.arguments}],timestamp:Date.now()},h));break;case"tool_result":l.result&&(h&&l.turnId&&wt(h)==="codex"?$e(l.turnId,{type:"tool_result",result:l.result,turnId:l.turnId},h):Ge(l.result.toolCallId,l.result.content,l.result.isError,h));break;case"todo_update":l.todos&&It(l.todos);break;case"cron_update":l.tasks&&P(l.tasks);break;case"agent_dispatch":if(fe({id:crypto.randomUUID(),role:"assistant",content:"",toolCalls:[{id:crypto.randomUUID(),name:"dispatch_agent",arguments:{agentName:l.agentName,task:l.task??"",subSessionId:l.subSessionId}}],timestamp:Date.now()},h),l.subSessionId){dt.current.add(l.subSessionId);const $=Rt.current||st;$&&o&&o($)}d==null||d({type:"started",agentName:l.agentName??"",task:l.task??"",subSessionId:l.subSessionId});break;case"agent_done":l.subSessionId&&(dt.current.delete(l.subSessionId),Ke(l.subSessionId,l.status??"completed",l.status==="failed"?l.error:l.summary,h)),d==null||d({type:l.status==="failed"?"failed":"completed",agentName:l.agentName??"",task:l.task??"",subSessionId:l.subSessionId});break;case"agent_progress":l.subSessionId&&l.text&&Ct(l.subSessionId,l.text,h);break;case"compacted":fe({id:crypto.randomUUID(),role:"assistant",content:l.summary??"",isCompactionSummary:!0,timestamp:Date.now()},h);break;case"show_widget":{const $=l.data??l.widgetData,be={widgetId:l.widgetId,widgetType:l.widgetType,data:$??{}},Ae=(h?et.getState().getMessagesForSession(h):et.getState().messages).find(Be=>{var he;return((he=Be.widget)==null?void 0:he.widgetId)===be.widgetId});Ae?it(Ae.id,Be=>({...Be,widget:be}),h):fe({id:crypto.randomUUID(),role:"assistant",content:"",widget:be,timestamp:Date.now()},h);break}case"ask_user":if(l.questionId&&(h?et.getState().getMessagesForSession(h):et.getState().messages).some(be=>{var oe;return((oe=be.askUser)==null?void 0:oe.questionId)===l.questionId}))break;fe({id:crypto.randomUUID(),role:"assistant",content:"",askUser:{questionId:l.questionId??"",question:l.question??"",options:l.options,fields:l.fields,multiSelect:l.multiSelect},timestamp:Date.now()},h);break;case"approval_resolved":{if(!l.questionId)break;const be=(h?et.getState().getMessagesForSession(h):et.getState().messages).find(oe=>{var Ae;return((Ae=oe.askUser)==null?void 0:Ae.questionId)===l.questionId});be&&it(be.id,oe=>({...oe,askUser:oe.askUser?{...oe.askUser,answered:!0,answer:"已处理"}:oe.askUser}),h);break}case"text_done":break;case"thinking":w&&pn("thinking");break;case"done":if(h&&sr===h&&(ir(null),w&&_e(null)),h&&!D){const $=Nd(l.durationMs);if($!==void 0){const be=[...ge(h)].reverse().find(oe=>{var Ae;return oe.role==="assistant"&&!!oe.content.trim()&&!((Ae=oe.toolCalls)!=null&&Ae.length)&&!oe.isCompactionSummary});be&&it(be.id,oe=>({...oe,presentation:{...oe.presentation,completionDurationMs:$}}),h)}}if(le(h),h&&!ge(h).some($=>$.isQueued)&&(Rt.current===h&&(Rt.current=null),et.getState().runningSessionId===h&&je(null)),w&&(pn("idle"),!D&&fn.getState().autoSpeak)){const be=[...et.getState().messages].reverse().find(oe=>oe.role==="assistant"&&oe.content&&!oe.isCompactionSummary);be!=null&&be.content&&(pe=window.agentApi)!=null&&pe.ttsSpeak&&(Zs(),window.agentApi.ttsSpeak(be.content.slice(0,600)).then(oe=>{oe.ok||_e("TTS 模型播报失败")}).catch(oe=>{_e(oe instanceof Error?oe.message:"TTS 模型播报失败")}))}h&&(vr.current.has(h)?window.setTimeout(()=>{wi(h)},150):za(h),Xs(h));break;case"error":if(l._preserveActiveRun||le(h),h&&l.code==="SESSION_OCCUPIED"&&!D){const $=et.getState().getMessagesForSession(h),be=Kn.current.get(h),oe=Es(Tt.current,h),Ae=(oe==null?void 0:oe.forkSessionId)===h?oe:void 0,Be=be??(oe==null?void 0:oe.payload),he=Be?[...$].reverse().find(Oe=>Oe.role==="user"&&!Oe.isQueued&&Oe.content===Be.content):w?[...$].reverse().find(Oe=>Oe.role==="user"&&!Oe.isQueued):void 0,ke=Be??(he?{content:he.content,images:he.images,agentName:he.agentName}:void 0);Ae?lo(h,Ae):(he&&te($.filter(Oe=>Oe.id!==he.id),h),Kn.current.delete(h),ke!=null&&ke.content&&(Et(oe??Bg(h,ke)),Wr(h,ke.content),ut.save(h,ke.images??[]),w&&(Kt(ke.content),dn(ke.images??[]))),Ht.current===h&&(Ht.current=null)),w&&_e(null)}if(h&&h.startsWith("runtime:")&&l.code!=="SESSION_OCCUPIED"&&l.code!=="SESSION_ALREADY_RUNNING"&&l.code!=="CANCEL_CONFIRMATION_TIMEOUT"&&!D){const $=et.getState().getMessagesForSession(h),be=Kn.current.get(h),oe=Es(Tt.current,h),Ae=(oe==null?void 0:oe.forkSessionId)===h?oe:void 0,Be=be?[...$].reverse().find(ke=>ke.role==="user"&&!ke.isQueued&&ke.content===be.content):[...$].reverse().find(ke=>ke.role==="user"&&!ke.isQueued),he=be??(Be?{content:Be.content,images:Be.images,agentName:Be.agentName}:void 0);Ae?lo(h,Ae):he!=null&&he.content&&(Wr(h,he.content),ut.save(h,he.images??[]),w&&(Kt(he.content),dn(he.images??[]))),Kn.current.delete(h),Ht.current===h&&(Ht.current=null)}if(w)if(l._preserveActiveRun&&h&&(Ca.current.add(h),Rt.current=h,je(h),pn("thinking")),l.code==="SESSION_ALREADY_RUNNING"&&!D){const $=h?Kn.current.get(h):void 0,be=h?et.getState().getMessagesForSession(h):et.getState().messages,oe=ah(be);if(oe){const Ae=be.find(Be=>Be.id===oe);it(oe,Be=>({...Be,isQueued:!0,sendState:void 0}),h),nr&&h&&Ae&&((Pe=window.agentApi)!=null&&Pe.enqueueSessionMessage)?window.agentApi.enqueueSessionMessage(h,{sourceMessageId:Ae.id,content:Ae.content,images:Ae.images,agentName:Ae.agentName}).then(Be=>{wn(Be,h),Is(h),ut.clear(h)}).catch(Be=>{const he=($==null?void 0:$.content)??Ae.content,ke=($==null?void 0:$.images)??Ae.images??[];Wr(h,he),ut.save(h,ke),(rt.current||Pt.current)===h&&(Kt(he),dn(ke)),_e(Be instanceof Error?Be.message:"排队消息保存失败")}):h&&(Is(h),ut.clear(h))}h&&Kn.current.delete(h),h&&Ht.current===h&&(Ht.current=null),h&&Et(void 0,h),_e(null)}else l.code!=="SESSION_OCCUPIED"&&(_e(l.message??"Unknown error"),ir(l.code==="CANCEL_CONFIRMATION_TIMEOUT"?h??null:null),h&&l.code==="CANCEL_CONFIRMATION_TIMEOUT"&&(Kn.current.delete(h),Ht.current===h&&(Ht.current=null)),h&&l.code!=="CANCEL_CONFIRMATION_TIMEOUT"&&ji(h,"failed"));if(!l._preserveActiveRun){const $=h??p;(!$||Rt.current===$)&&(Rt.current=null),(!$||et.getState().runningSessionId===$)&&je(null),w&&pn("idle")}h&&!l._preserveActiveRun&&(vr.current.has(h)?window.setTimeout(()=>{wi(h)},150):za(h),Xs(h));break;case"turn_aborted":h&&sr===h&&(ir(null),w&&_e(null)),le(h),Rt.current===h&&(Rt.current=null),et.getState().runningSessionId===h&&je(null),w&&pn("idle"),Xs(h);break;case"goal_updated":h===(rt.current||Pt.current)&&ne(l.goal??null);break;case"goal_cleared":h===(rt.current||Pt.current)&&ne(null);break}}},yu=async l=>{var h;if(!Z||!((h=window.agentApi)!=null&&h.setSessionPermissionMode)||hs)return;const p=fr;Ve(l),ps(!1),Ds(!0);try{await window.agentApi.setSessionPermissionMode(Z,l)}catch(w){Ve(p),_e(w instanceof Error?w.message:"权限模式更新失败")}finally{Ds(!1)}},La=async()=>{var l;if(!(!Z||(f==null?void 0:f.agentType)!=="codex"||!((l=window.agentApi)!=null&&l.releaseCodexSession)||zt!=="idle")&&!(sn&&!window.confirm("停止当前执行并退出此会话?Codex Desktop 最长约 30 分钟后可用。"))){Sn("releasing");try{await window.agentApi.releaseCodexSession(Z),ts.current=!0,js.current+=1,Rt.current=null,je(null),dt.current.clear(),X(p=>({...p,active:null,queued:[]})),Ln("idle"),_e(null),ir(null),Sn("released")}catch(p){Sn("idle"),_e(p instanceof Error?p.message:"释放 Codex 会话失败")}}},vu=async()=>{var h;const l=at;if(!l||!Z||Ft||Lr.current===l.token)return;Lr.current=l.token;const p=(w,D)=>{const z=Zl(w);if(ge(D).some(pe=>pe.id===z)){it(z,pe=>({...pe,sendState:"pending"}),D);return}fe({id:z,role:"user",content:w.payload.content,timestamp:Date.now(),agentName:w.payload.agentName,images:w.payload.images,sendState:"pending"},D)};if(l.forkSessionId){qt(!0);const w=Jl(l,l.forkSessionId);Et(w),p(w,w.forkSessionId),ks(w.payload,w.forkSessionId,w.payload.agentIds).finally(()=>{Lr.current=null,qt(!1)});return}if(!((h=window.agentApi)!=null&&h.forkSession)){Lr.current=null;return}qt(!0);try{const w=await Og({sourceSessionId:l.sourceSessionId,forkSession:z=>window.agentApi.forkSession(z),activateSession:z=>{Pt.current=z,ze(z)},refreshAndSelect:async z=>{s?await s(z.id,z):c==null||c(z.id)}}),D=Jl(l,w.id);Et(D),p(D,w.id),ks(D.payload,w.id,D.payload.agentIds).finally(()=>{Lr.current=null,qt(!1)}),_e(null)}catch(w){Lr.current=null,_e(w instanceof Error?w.message:"创建会话副本失败"),qt(!1)}},co=()=>{ts.current=!0,js.current+=1,window.agentApi&&window.agentApi.abort(Z||void 0).catch(l=>{_e(l instanceof Error?l.message:"停止执行失败")}),Ie!=="codex"&&(Rt.current=null,je(null),dt.current.clear())},Pa=async l=>{const p=r||st;if(!p||!window.agentApi||qe.current.has(l))return;const h=ge(p).find(w=>w.id===l);if(!(!h||!h.isQueued)){qe.current.add(l),Ee(new Set(qe.current));try{if(h.queueItemId){const w=await window.agentApi.steerSessionMessage(p,h.queueItemId);te(Fl(ge(p),l,Date.now()),p),wn(w,p)}else await window.agentApi.steer(h.content,p,h.agentName),te(Fl(ge(p),l,Date.now()),p);b===l&&(M(null),ie(""))}catch(w){_e(w instanceof Error?w.message:"引导失败")}finally{qe.current.delete(l),Ee(new Set(qe.current))}}},wu=l=>{const p=et.getState().messages.find(h=>h.id===l&&h.isQueued);p&&(M(l),ie(p.content))},uo=()=>{M(null),ie("")},Da=async l=>{const p=F.trim(),h=et.getState().messages.find(w=>w.id===l&&w.isQueued);if(!(!h||!p))try{h.queueItemId&&Z?wn(await window.agentApi.updateSessionMessage(Z,h.queueItemId,p),Z):it(l,w=>w.isQueued?{...w,content:p}:w,Z||void 0),uo()}catch(w){_e(w instanceof Error?w.message:"排队消息保存失败")}},ju=async l=>{const p=et.getState().messages.find(h=>h.id===l&&h.isQueued);if(p){if(!await _i(p.content)){_e("复制排队消息失败");return}Je(l),window.setTimeout(()=>Je(h=>h===l?null:h),1200)}},ku=async l=>{const p=et.getState().messages,h=p.find(w=>w.id===l&&w.isQueued);if(h)try{h.queueItemId&&Z?wn(await window.agentApi.cancelSessionMessage(Z,h.queueItemId),Z):te(p.filter(w=>w.id!==l),Z||void 0),b===l&&uo()}catch(w){_e(w instanceof Error?w.message:"排队消息删除失败")}},po=async(l,p)=>{const h=et.getState().messages,w=dh(h,l,p);if(w!==h){te(w,Z||void 0);const D=w.filter(z=>z.isQueued&&z.queueItemId);if(Z&&D.length>0)try{wn(await window.agentApi.reorderSessionMessages(Z,D.map(z=>z.queueItemId)),Z)}catch(z){te(h,Z),_e(z instanceof Error?z.message:"排队消息排序保存失败")}}},Su=(l,p)=>{const h=et.getState().messages.filter(z=>z.isQueued),w=h.findIndex(z=>z.id===l),D=h[w+p];D&&po(l,D.id)},Cu=async l=>{const p=gr;if(fs(null),!Z||!p||p===l)return;const h=K.queued.map(pe=>pe.id),w=h.indexOf(p),D=h.indexOf(l);if(w<0||D<0)return;const z=[...h];z.splice(D,0,z.splice(w,1)[0]);const xe=K;X({...K,queued:z.map((pe,Pe)=>({...K.queued.find($=>$.id===pe),position:Pe}))});try{wn(await window.agentApi.reorderSessionGoals(Z,z),Z)}catch(pe){X(xe),_e(pe instanceof Error?pe.message:"目标排序保存失败")}},Wa=async l=>{if(!Z)return;const p=K.queued.find(h=>h.id===l);try{const h=await window.agentApi.cancelSessionGoal(Z,l);if(wn(h,Z),p!=null&&p.sourceMessageId){const w=et.getState().getMessagesForSession(Z);te(w.filter(D=>D.id!==p.sourceMessageId),Z)}h.active||je(null)}catch(h){_e(h instanceof Error?h.message:"目标删除失败")}};a.useEffect(()=>{b&&(L.some(l=>l.id===b&&l.isQueued)||(M(null),ie("")))},[b,L]);async function ks(l,p,h){var z,xe,pe,Pe;const w=crypto.randomUUID();let D=!1;p.startsWith("runtime:")&&Kn.current.set(p,{content:l.content,images:l.images?[...l.images]:void 0,agentIds:h?[...h]:void 0,agentName:l.agentName,restoreDraftOnFailure:l.restoreDraftOnFailure}),ts.current=!1,vr.current.add(p),yn(p),Rt.current=p,je(p);try{if(window.agentApi){const $=xt&&Di(Ie)?{...(z=nn.model)!=null&&z.id?{model:nn.model}:{},...Nt?{reasoningEffort:Nt}:{}}:Dt?{profileId:Dt}:void 0;await window.agentApi.run(l.content,p,h,l.agentName,l.images,$),D=!0}}catch($){const be=Es(Tt.current,p);if((be==null?void 0:be.forkSessionId)===p)lo(p,be);else{ji(p,"failed");const oe=Kn.current.get(p);p.startsWith("runtime:")&&(oe!=null&&oe.content)&&(oe.restoreDraftOnFailure!==!1&&(Wr(p,oe.content),ut.save(p,oe.images??[]),(rt.current||Pt.current)===p&&(Kt(oe.content),dn(oe.images??[]))),Kn.current.delete(p),Ht.current===p&&(Ht.current=null))}_e($ instanceof Error?$.message:"Agent run failed")}finally{if(vr.current.delete(p),Ca.current.delete(p)){Rt.current=p,je(p);return}const be=(xe=window.agentApi)!=null&&xe.getSessionGoals?await window.agentApi.getSessionGoals(p).catch(()=>{}):void 0;if(vr.current.has(p))return;if(be&&p===(rt.current||Pt.current)&&wn(be,p),be!=null&&be.active){Rt.current=p,je(p),u&&u(n,p);return}const oe=ts.current?void 0:et.getState().getMessagesForSession(p).find(Ae=>Ae.isQueued&&!Ae.queueItemId);if(oe)it(oe.id,Ae=>({...Ae,isQueued:!1}),p),u&&u(n,p),ks(oe,p);else{if(D&&((pe=window.agentApi)!=null&&pe.notifyTaskCompletion)){const Ae=(Pe=[...et.getState().getMessagesForSession(p)].reverse().find(he=>he.role==="assistant"&&he.content.trim()&&!he.isCompactionSummary))==null?void 0:Pe.content,Be=kp({sessionId:p,runId:w,title:"任务已完成",finalText:Ae,outcome:"completed"},Tn);Be&&window.agentApi.notifyTaskCompletion(Be,Tn)}Rt.current===p&&(Rt.current=null),et.getState().runningSessionId===p&&je(null),u&&u(n,p)}}}const Ba=async l=>{var Ae,Be;if(!l.text||!an||Fs>0||m.current==="anchored"&&!await Na())return;Si(window.agentApi,Zs),sr!==Z&&_e(null);const p=l.text,h=()=>{l.clearComposer&&(Kt(""),Bs([]),dn([]))};if(/^\/loop\b/i.test(p)){const he=p.slice(5).trim();if(h(),fe({id:crypto.randomUUID(),role:"user",content:p,timestamp:Date.now()}),/^stop$/i.test(he)){window.agentApi&&(await window.agentApi.cronDeleteAll(),P([]),fe({id:crypto.randomUUID(),role:"assistant",content:"✅ 所有定时任务已删除。",timestamp:Date.now()}));return}if(/^(?:list|status|查看|列表)$/i.test(he)||he===""){if(window.agentApi){const We=await window.agentApi.cronList();P(We);const kt=We.length===0?"当前没有定时任务。":We.map((St,ye)=>`**${ye+1}.** \`${St.id.slice(0,6)}\` · ${So(St.cron)} · ${St.enabled?"▶ 启用":"⏸ 已暂停"}
455
- ${St.prompt}`).join(`
456
-
457
- `);fe({id:crypto.randomUUID(),role:"assistant",content:kt,timestamp:Date.now()})}return}const ke=he.match(/^(?:pause|暂停)\s+(\S+)$/i);if(ke){if(window.agentApi){const We=ft.find(St=>St.id.startsWith(ke[1])),kt=await window.agentApi.cronPause((We==null?void 0:We.id)??ke[1]);if(kt){const St=await window.agentApi.cronList();P(St),fe({id:crypto.randomUUID(),role:"assistant",content:`⏸ 定时任务 \`${kt.id.slice(0,6)}\` 已暂停。`,timestamp:Date.now()})}else fe({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${ke[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const Oe=he.match(/^(?:resume|恢复)\s+(\S+)$/i);if(Oe){if(window.agentApi){const We=ft.find(St=>St.id.startsWith(Oe[1])),kt=await window.agentApi.cronResume((We==null?void 0:We.id)??Oe[1]);if(kt){const St=await window.agentApi.cronList();P(St),fe({id:crypto.randomUUID(),role:"assistant",content:`▶ 定时任务 \`${kt.id.slice(0,6)}\` 已恢复。`,timestamp:Date.now()})}else fe({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${Oe[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const De=he.match(/^(?:delete|del|删除|stop)\s+(\S+)$/i);if(De){if(window.agentApi){const We=ft.find(St=>St.id.startsWith(De[1]));if(await window.agentApi.cronDelete((We==null?void 0:We.id)??De[1])){const St=await window.agentApi.cronList();P(St),fe({id:crypto.randomUUID(),role:"assistant",content:`🗑 定时任务 \`${De[1]}\` 已删除。`,timestamp:Date.now()})}else fe({id:crypto.randomUUID(),role:"assistant",content:`未找到 ID 以 \`${De[1]}\` 开头的定时任务。`,timestamp:Date.now()})}return}const jt=he.match(/^(\S+)\s+(.+)$/s);if(jt){const We=jt[1],kt=jt[2].trim();if(window.agentApi){let St=r||st;if(!St){const ye=await window.agentApi.createSession(kt.slice(0,60)||"定时任务",n||void 0);St=ye.id,ze(ye.id),s&&await s(ye.id)}try{const ye=await window.agentApi.cronCreate(We,kt,{sessionId:St}),Wt=await window.agentApi.cronList();P(Wt),fe({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${ye.id.slice(0,6)}\`),${So(We)}执行:${kt}`,timestamp:Date.now()})}catch(ye){fe({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${ye instanceof Error?ye.message:String(ye)}`,timestamp:Date.now()})}}return}fe({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 w=p.match(/(?:每(?:隔)?|定时每)\s*(\d+(?:\.\d+)?)\s*(分钟|秒|小时|min|sec|h)\s*(.+)/is);if(w){const he=w[1]+w[2],ke=w[3].trim();if(ke&&window.agentApi){let Oe=r||st;if(!Oe){const De=await window.agentApi.createSession(ke.slice(0,60)||"定时任务",n||void 0,Ie,Ie!=="customer-agent"?x??void 0:void 0);Oe=De.id,ze(De.id),s&&await s(De.id)}try{const De=await window.agentApi.cronCreate(he,ke,{sessionId:Oe}),jt=await window.agentApi.cronList();P(jt),h(),fe({id:crypto.randomUUID(),role:"user",content:p,timestamp:Date.now()}),fe({id:crypto.randomUUID(),role:"assistant",content:`⏰ 定时任务已创建(ID: \`${De.id.slice(0,6)}\`),${So(he)}执行:${ke}`,timestamp:Date.now()})}catch(De){fe({id:crypto.randomUUID(),role:"assistant",content:`❌ 创建失败:${De instanceof Error?De.message:String(De)}`,timestamp:Date.now()})}return}}const D=l.text,z=D.match(/^\/goal(?:\s+([\s\S]+))?$/i),xe=z?((Ae=z[1])==null?void 0:Ae.trim())??"":l.applyGoalMode&&hr?D:null;if(xe!==null&&!xe){_e("请输入目标内容");return}const pe=l.agentName,Pe=l.images,$=l.agentIds??[];if(l.clearComposer&&eo([]),xe!==null){const he=crypto.randomUUID();let ke=null,Oe=null;ts.current=!1,l.clearComposer&&Z&&(Is(Z),ut.clear(Z)),h();try{const De=await Xl({text:xe,projectId:n??null,sessionId:r||st,createSession:async(We,kt)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(We,kt,Ie,Ie!=="customer-agent"?x??void 0:void 0)},activateSession:We=>{Pt.current=We,ze(We),Rt.current=We,je(We)},showUserMessage:(We,kt)=>{ke=kt,fe({id:he,role:"user",content:We,timestamp:Date.now(),agentName:pe,images:Pe,isGoal:!0,goalId:he},kt)},onSessionCreated:s});Oe=De,l.clearComposer&&De!==Z&&(Is(De),ut.clear(De));const jt=await window.agentApi.enqueueSessionGoal(De,xe,he);wn(jt,De),i&&i(De,xe)}catch(De){if(ke){const kt=et.getState().getMessagesForSession(ke);te(kt.filter(St=>St.id!==he),ke)}const jt=Oe??ke??Z;l.restoreDraftOnFailure&&jt&&(Wr(jt,D),ut.save(jt,Pe??[]));const We=rt.current||Pt.current;l.restoreDraftOnFailure&&(jt&&We===jt||!jt&&!We)&&(Kt(D),dn(Pe??[])),je(null),_e(De instanceof Error?De.message:"目标创建失败")}return}if(Dn){const he=Z,ke=crypto.randomUUID(),Oe={id:ke,role:"user",content:D,timestamp:Date.now(),agentName:pe,images:Pe,isQueued:!0};if(l.clearComposer&&he&&(Is(he),ut.clear(he)),h(),nr&&he&&((Be=window.agentApi)!=null&&Be.enqueueSessionMessage)){fe(Oe,he);try{const De=await window.agentApi.enqueueSessionMessage(he,{sourceMessageId:ke,content:D,images:Pe,agentIds:$,agentName:pe});wn(De,he)}catch(De){const jt=et.getState().getMessagesForSession(he);te(jt.filter(We=>We.id!==ke),he),l.restoreDraftOnFailure&&(Wr(he,D),ut.save(he,Pe??[]),(rt.current||Pt.current)===he&&(Kt(D),dn(Pe??[]))),_e(De instanceof Error?De.message:"排队消息保存失败")}}else fe(Oe,he??void 0);return}const be=r||st;l.clearComposer&&xt&&be&&(br.current=!0,Ht.current=be),h(),It([]);const oe=crypto.randomUUID();try{const he=await Xl({text:D,projectId:n??null,sessionId:r||st,createSession:async(ke,Oe)=>{if(!window.agentApi)throw new Error("agentApi 未就绪");return await window.agentApi.createSession(ke,Oe,Ie,Ie!=="customer-agent"?x??void 0:void 0)},activateSession:ke=>{Pt.current=ke,ze(ke),Rt.current=ke},showUserMessage:(ke,Oe)=>fe({id:oe,role:"user",content:ke,timestamp:Date.now(),agentName:pe,images:Pe,sendState:"pending"},Oe),afterUserMessageShown:wg,onSessionCreated:s});i&&i(he,D),await ks({content:D,agentName:pe,images:Pe,restoreDraftOnFailure:l.restoreDraftOnFailure},he,$.length>0?$:void 0)}catch(he){const ke=r||st;ke&&ji(ke,"failed"),_e(he instanceof Error?he.message:"Agent run failed")}},Fa=async()=>Ba(Xf({text:En,agentIds:qs.map(l=>l.id),agentName:qs.length>0?qs.map(l=>l.name).join(", "):void 0,images:mr})),Iu=l=>{Ba(Yf(l))};return a.useEffect(()=>{if(!A||!window.agentApi)return;const{text:l,projectId:p,sessionId:h}=A;let w=!1;return(async()=>{try{It([]);const D=await vg({text:l,projectId:p,sessionId:h,createSession:async(z,xe)=>await window.agentApi.createSession(z,xe,Ie,Ie!=="customer-agent"?x??void 0:void 0),activateSession:z=>{Pt.current=z,ze(z),Rt.current=z,je(z)},showUserMessage:(z,xe)=>fe({id:crypto.randomUUID(),role:"user",content:z,timestamp:Date.now()},xe),onSessionCreated:s,isCancelled:()=>w});if(!D)return;i&&i(D,l),await ks({content:l},D)}catch(D){_e(D instanceof Error?D.message:"语音指令执行失败")}})(),()=>{w=!0}},[A==null?void 0:A.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:"drag"},children:[e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14,fontWeight:500,color:g?"var(--text-primary)":"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",letterSpacing:"-0.01em"},children:g||"会话"}),y&&S&&ee&&e.jsx(Uh,{appearanceOpen:N,settingsOpen:v,showSettings:Ie==="customer-agent",onOpenDesktopLive:C,desktopLiveOpen:I,filesOpen:j,onToggleFiles:k,hideToBackgroundTitle:T,codexReleaseState:zt,onHideToBackground:S,onReleaseCodex:(f==null?void 0:f.agentType)==="codex"&&f.occupancy!=="owned-externally"?()=>{La()}:void 0,onOpenHub:E,onToggleAppearance:ee,onOpenSettings:y})]}),e.jsx(cg,{open:tr,agentSessionId:Z,onClose:()=>Qn(!1)}),e.jsxs("div",{className:"chat-messages-frame",children:[e.jsxs("div",{ref:Bn,className:"chat-messages",onScroll:ru,onTouchStart:l=>Qr.current.start(l.touches),onTouchMove:l=>{Qr.current.move(l.touches,l.currentTarget.scrollTop)&&xs.current()},onTouchEnd:()=>Qr.current.reset(),onTouchCancel:()=>Qr.current.reset(),style:{overflow:"auto",position:"relative",padding:"var(--chat-messages-padding)"},children:[ot.length>0&&(ma||hi)&&e.jsx("div",{className:"chat-history-page-status",role:hi?"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:hi?"var(--danger)":"var(--text-muted)",fontSize:12},children:ma?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 ao(),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:[hi,",点击重试"]})}),ot.length===0&&xi&&Zd&&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:"正在加载历史消息"})]}),ot.length===0&&!sn&&!xi&&!gs&&e.jsx(fg,{agentType:(f==null?void 0:f.agentType)??t,ready:an,onSelectPrompt:du},Z??"initial-empty-session"),Ue.map((l,p)=>{var Be,he,ke,Oe,De,jt,We,kt,St;const h=l;if(h.isQueued)return null;if(h.executionTrace)return e.jsx(Bh,{trace:h.executionTrace,loadTrace:nu,loadToolResult:to,renderContent:R,runtimeProgress:qr,nativeSubagents:Rn,onSelectSession:c,workspacePath:x,onOpenArtifact:W,refreshSignal:h.executionTrace.turnId===$t?ct:0,autoLoad:Us==="latest"&&h.executionTrace.turnId===$t},l.id);const w=l.role==="user",D=w&&(h.isGoal===!0||[K.active,...K.queued,...K.history].some(ye=>!!(ye&&tc(ye.objective)===tc(l.content)))),z=zg(Ue,p,sn),xe=Ag((Be=h.presentation)==null?void 0:Be.completionDurationMs);if(h.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)"}})]},l.id);if(h.widget){const ye=xg[h.widget.widgetType];return ye?e.jsx("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-start"},children:e.jsx(ye,{...h.widget.data,widgetId:h.widget.widgetId,isAgentRunning:sn&&!Ue.slice(p+1).some(Wt=>Wt.role==="user"&&!Wt.isQueued&&!Wt.isSteered)})},l.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(h.widget.data,null,2)},l.id)}if(h.askUser)return e.jsx(zh,{questionId:h.askUser.questionId,question:h.askUser.question,options:h.askUser.options,fields:h.askUser.fields,multiSelect:h.askUser.multiSelect,answered:h.askUser.answered,answer:h.askUser.answer,onAnswer:async(ye,Wt)=>{var At;if(!await((At=window.agentApi)==null?void 0:At.answerQuestion(h.askUser.questionId,ye,Wt)))throw new Error("回答未发送成功,请重试;若问题已结束,请刷新会话。");it(l.id,kn=>({...kn,askUser:{...kn.askUser,answered:!0,answer:ye}}),Z??void 0)}},l.id);const pe=h.agentName?h.agentName.charAt(0).toUpperCase():"你",Pe=!w&&p===Ue.length-1,$=Ue[p+1],be=$&&$.role!==l.role&&!$.isCompactionSummary,oe=(l.toolCalls??[]).map((ye,Wt)=>{let Dr;if(ye.name==="write_file"&&ye.arguments.file_path){const At=ye.arguments.file_path;e:for(let kn=p;kn>=0;kn--){const wr=Ue[kn].toolCalls;if(!wr)continue;const Ys=kn===p?Wt-1:wr.length-1;for(let ns=Ys;ns>=0;ns--){const jr=wr[ns];if(jr.name==="read_file"&&jr.arguments.file_path===At&&jr.result&&!jr.isError){Dr=jr.result;break e}}}}return{toolCall:ye,beforeContent:Dr,progress:od(qr,ye.id),nativeSubagent:Rn[ye.id]}}),Ae=Ad(oe);return e.jsx("div",{"data-message-id":l.id,className:`chat-message-group${z.compact?" chat-message-group--intermediate":""}`,style:{marginBottom:z.compact?0:be?"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:pe}):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"} ${l.role==="assistant"&&l.content?"message-card":""}`,style:{padding:l.content||w&&((he=h.images)!=null&&he.length)?w?"var(--chat-user-bubble-padding)":"var(--chat-assistant-bubble-padding)":0,borderRadius:w?"14px 4px 14px 14px":"4px 14px 14px 14px",background:l.content||w&&((ke=h.images)!=null&&ke.length)?w?"rgba(79, 110, 247, 0.08)":void 0:"transparent",border:l.content||w&&((Oe=h.images)!=null&&Oe.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(--chat-history-text)",letterSpacing:"0.01em"},children:[l.role==="assistant"&&((De=l.presentation)==null?void 0:De.reasoning)&&e.jsx(Rd,{sections:l.presentation.reasoning,streaming:sn&&Pe&&Jt==="thinking",startedAt:Zt,renderContent:R}),w&&h.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"})]}),h.agentName]}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",verticalAlign:"middle"},children:l.content})]}):l.role==="assistant"&&l.content?e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.jsx(Yp,{text:l.content,complete:!(sn&&Pe),renderText:R,suggestionsEnabled:an&&Fs===0,onSuggestionSend:Iu,onCopyFailed:()=>_e("复制失败,请选择文字后复制")})}):l.content&&e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:w?l.content:R(l.content)}),w&&h.images&&h.images.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:l.content?8:0},children:h.images.map((ye,Wt)=>e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":"放大查看图片",onClick:()=>Kr({src:ye,alt:`用户发送的图片 ${Wt+1}`}),children:e.jsx("img",{className:"chat-message-attachment-image",src:ye,alt:`用户发送的图片 ${Wt+1}`})},Wt))}),w&&!((jt=h.images)!=null&&jt.length)&&((We=h.presentation)==null?void 0:We.attachments)&&h.presentation.attachments.length>0&&e.jsx("div",{className:"chat-message-attachments",children:h.presentation.attachments.map((ye,Wt)=>ye.dataUrl?e.jsx("button",{type:"button",className:"chat-message-image-button","aria-label":`放大查看图片:${ye.name}`,onClick:()=>Kr({src:ye.dataUrl,alt:ye.name}),children:e.jsx("img",{className:"chat-message-attachment-image",src:ye.dataUrl,alt:ye.name,title:ye.name})},`${ye.name}-${Wt}`):e.jsxs("div",{className:"chat-message-attachment-unavailable","aria-label":`${ye.name},${ye.omitted&&!ye.unavailable?"图片未随页面加载":"图片已失效"}`,children:[e.jsx("span",{className:"chat-message-attachment-name",children:ye.name}),e.jsx("span",{children:ye.omitted&&!ye.unavailable?"图片未随页面加载":"图片已失效"})]},`${ye.name}-${Wt}`))}),w&&((kt=h.presentation)==null?void 0:kt.rawContent)&&e.jsxs("details",{className:"chat-message-raw-content",children:[e.jsx("summary",{children:"查看原始内容"}),e.jsx("pre",{children:h.presentation.rawContent})]}),Ae.map(ye=>ye.action&&ye.items.length>1?e.jsx(Id,{items:ye.items,onSelectSession:c,workspacePath:x,onOpenArtifact:W,onLoadResult:ka},`group-${ye.items[0].toolCall.id}`):e.jsx(Gi,{toolCall:ye.items[0].toolCall,beforeContent:ye.items[0].beforeContent,progress:ye.items[0].progress,nativeSubagent:ye.items[0].nativeSubagent,onSelectSession:c,workspacePath:x,onOpenArtifact:W,onLoadResult:ka},ye.items[0].toolCall.id)),(()=>{const ye=(l.toolCalls??[]).filter(At=>At.name==="write_file"&&At.result&&!At.isError);if(ye.length===0)return null;const Wt=new Map;for(const At of ye){const kn=At.arguments.file_path??"",wr=At.arguments.content??"",Ys=wr?wr.split(`
458
- `).length:0;let ns=0;e:for(let jr=p;jr>=0;jr--){const Ya=Ue[jr].toolCalls??[];for(let fo=Ya.length-1;fo>=0;fo--){const Js=Ya[fo];if(Js.name==="read_file"&&Js.arguments.file_path===kn&&Js.result&&!Js.isError){ns=Js.result.split(`
459
- `).length;break e}}}Wt.set(kn,{path:kn,lines:Ys,added:Math.max(0,Ys-ns),removed:Math.max(0,ns-Ys)})}const Dr=[...Wt.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:"变更汇总"}),Dr.map(At=>{const kn=gd(At.path,x),wr=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text-secondary)",maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:At.path,children:At.path.replace(/\\/g,"/").split("/").pop()}),At.added>0&&e.jsxs("span",{style:{color:"var(--success)",fontWeight:600},children:["+",At.added]}),At.removed>0&&e.jsxs("span",{style:{color:"var(--danger)",fontWeight:600},children:["−",At.removed]}),At.added===0&&At.removed===0&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[At.lines,"行"]})]});return W&&kn?e.jsx("button",{type:"button",className:"chat-file-change-link",onClick:()=>W(kn),title:`预览 ${kn}`,"aria-label":`预览改动文件 ${At.path.replace(/\\/g,"/").split("/").pop()}`,children:wr},At.path):e.jsx("span",{className:"chat-file-change-link chat-file-change-link--static",children:wr},At.path)})]})})(),w&&(h.sendState||h.isSteered)&&e.jsxs("div",{className:`msg-send-status${h.sendState?` is-${h.sendState}`:""}`,role:"status","aria-label":h.sendState==="pending"?"正在发送":h.sendState==="failed"?"发送失败":"已引导",children:[h.sendState==="pending"&&e.jsxs("span",{className:"msg-send-status__dots","aria-hidden":"true",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),h.sendState==="failed"&&e.jsx("span",{children:"发送失败"}),h.isSteered&&e.jsx("span",{className:"msg-steered-status",title:"已引导","aria-label":"已引导",role:"img",children:e.jsx(rl,{size:13,strokeWidth:2,"aria-hidden":"true"})})]})]}),z.showCompletion&&e.jsxs("div",{className:"msg-completion-footer",children:[e.jsxs("span",{className:"msg-completion-status",children:[e.jsx($r,{size:13,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"已完成"}),xe&&e.jsxs("span",{children:[" · 总耗时 ",xe]})]}),e.jsxs("span",{className:"msg-completion-actions",children:[!Fo()&&z.showSpeak&&typeof((St=window.agentApi)==null?void 0:St.ttsSpeak)=="function"&&e.jsx("button",{type:"button",onClick:()=>ou(l.id,l.content),title:Gs===l.id?"停止播报":"语音播报","aria-label":Gs===l.id?"停止播报":"语音播报",className:`ui-icon-button ui-icon-button--small msg-action-button ${Gs===l.id?"is-active":""}`,children:Gs===l.id?e.jsx(dl,{size:12,fill:"currentColor","aria-hidden":"true"}):e.jsx(Kc,{size:13,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{_i(l.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Ti,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]})]}),!z.showCompletion&&(z.showCopy||D)&&e.jsxs("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",gap:4},children:[D&&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(ki,{size:13,strokeWidth:1.9,"aria-hidden":"true"})}),z.showCopy&&e.jsx("button",{type:"button",onClick:()=>{_i(l.content)},title:"复制内容","aria-label":"复制内容",className:"ui-icon-button ui-icon-button--small msg-action-button",children:e.jsx(Ti,{size:13,strokeWidth:1.8,"aria-hidden":"true"})})]}),w&&h.isQueued&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},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"})]}),"排队中"]}),bn&&e.jsxs("button",{onClick:()=>void Pa(l.id),disabled:Ne.has(l.id),title:Ne.has(l.id)?"正在引导":"将此消息引导到当前对话",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:Ne.has(l.id)?"wait":"pointer",opacity:Ne.has(l.id)?.6:1,transition:"all 0.15s",fontFamily:"var(--font-body)"},onMouseEnter:ye=>{ye.currentTarget.style.background="rgba(79,110,247,0.18)",ye.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:ye=>{ye.currentTarget.style.background="var(--accent-dim)",ye.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"})]}),Ne.has(l.id)?"引导中":"引导"]})]})]})]})},l.id)}),sn&&Vr&&e.jsx(wd,{progress:Vr,startedAt:Zt}),cs&&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(Dh,{startedAt:Zt})}),(Wn||gs)&&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",flexWrap:"wrap",gap:10},children:[e.jsx("span",{style:{flex:1,minWidth:0},children:Wn||gs}),!Wn&&sr===Z&&e.jsxs("div",{style:{display:"inline-flex",gap:6,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:co,"aria-label":"再次停止",title:"再次停止",className:"ui-icon-button",children:e.jsx(dl,{size:14,fill:"currentColor","aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>{La()},"aria-label":"释放会话",title:"释放会话",className:"ui-icon-button",disabled:zt!=="idle",children:zt==="releasing"?e.jsx(lt,{size:14,className:"spin","aria-hidden":"true"}):e.jsx(Gc,{size:14,"aria-hidden":"true"})})]}),Wn&&e.jsxs("button",{type:"button",onClick:()=>di(l=>l+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(_s,{size:14,"aria-hidden":"true"}),"重新加载"]})]}),e.jsx("div",{ref:pi})]}),e.jsx(Ff,{entries:(Qi==null?void 0:Qi.entries)??[],activeMessageId:Kd,loadingMessageId:Qd,onActivate:l=>{_a(l)}}),Us==="anchored"&&e.jsx("button",{type:"button",className:"chat-history-return-latest","data-has-updates":Xd,"data-loading-newer":Yd,"aria-busy":Yi||void 0,"aria-label":"回到最新消息",title:"回到最新消息",disabled:Yi,onClick:()=>{Na()},children:Yi?e.jsx(lt,{className:"chat-history-return-latest__spinner",size:16,"aria-hidden":"true"}):e.jsx(nl,{size:16,"aria-hidden":"true"})}),Us!=="anchored"&&Jd&&e.jsx("button",{type:"button",className:"chat-jump-to-bottom","aria-label":"回到底部",title:"回到底部",onClick:su,children:e.jsx(nl,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"chat-input-area",style:{padding:"var(--chat-input-padding)",background:"var(--bg-workspace)"},children:[rn&&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:zn==="incompatible"?"var(--danger)":"var(--text-muted)",fontSize:12},children:e.jsx("span",{style:{flex:1},children:zn==="incompatible"?Yt||((qa=f==null?void 0:f.compatibility)==null?void 0:qa.reason)||`Codex ${((Va=f==null?void 0:f.compatibility)==null?void 0:Va.producerVersion)??"未知版本"} 与当前 ${((Ga=f==null?void 0:f.compatibility)==null?void 0:Ga.readerVersion)??"运行时"} 不兼容`:`正在使用 Codex ${((Ka=f==null?void 0:f.compatibility)==null?void 0:Ka.readerVersion)??"当前版本"} 验证此会话`})}),ls&&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:at!=null&&at.forkSessionId?"副本已创建,但消息尚未发送成功。":"此会话仍由原客户端持有,可创建副本继续。"}),ls&&e.jsx("button",{type:"button",onClick:()=>void vu(),disabled:Ft,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:Ft?"wait":"pointer",opacity:Ft?.65:1},children:Ft?at!=null&&at.forkSessionId?"正在发送…":"正在创建…":at!=null&&at.forkSessionId?"重新发送":"以副本继续"})]}),tt.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 l=new Set(tt.filter(p=>p.status==="completed").map(p=>p.title.toLowerCase()));return tt.map(p=>{const h=p.status==="pending",w=p.status==="in-progress",D=p.status==="completed",z=h&&(p.dependsOn??[]).some(xe=>!l.has(xe.toLowerCase()));return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,opacity:D?.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:D?"rgba(52,211,153,0.15)":w?"var(--accent-dim)":z?"rgba(239,68,68,0.08)":"rgba(0,0,0,0.04)",border:D?"1.5px solid rgba(52,211,153,0.6)":w?"1.5px solid var(--accent)":z?"1.5px solid rgba(239,68,68,0.5)":"1.5px solid var(--border-default)"},children:[D&&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"}}),z&&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"})}),h&&!z&&e.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:"var(--border-default)"}})]}),e.jsx("span",{style:{fontSize:12,color:D?"var(--text-muted)":z?"rgba(239,68,68,0.8)":"var(--text-primary)",textDecoration:D?"line-through":"none",flex:1},children:p.title}),z&&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)})})()})]}),ft.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(),P([]),fe({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:"全部删除"})]}),ft.map(l=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border-subtle)",opacity:l.enabled?1:.7},children:[e.jsx("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:l.enabled?"#22c55e":"#9ca3af",boxShadow:l.enabled?"0 0 5px rgba(34,197,94,0.55)":"none",animation:l.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:l.cron}),e.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.label||l.prompt}),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexShrink:0},children:l.id.slice(0,6)}),e.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[l.enabled?e.jsx("button",{title:"暂停",onClick:async()=>{if(window.agentApi){await window.agentApi.cronPause(l.id);const p=await window.agentApi.cronList();P(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(l.id);const p=await window.agentApi.cronList();P(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(l.id);const p=await window.agentApi.cronList();P(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:"🗑"})]})]},l.id))]}),ui.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:ui.map((l,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:l.name}),e.jsx("button",{onClick:()=>fu(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))}),mr.length>0&&(()=>{const l=pt.find(h=>h.id===Dt),p=!xt&&(!l||!io(l.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"})]}),"当前模型(",(l==null?void 0:l.modelId)??"未配置",")不支持图片,发送前请切换到支持视觉的模型(如 claude-3、gpt-4o)"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:mr.map((h,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:()=>Kr({src:h,alt:`待发送图片 ${w+1}`}),children:e.jsx("img",{src:h,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:()=>xu(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))})]})})(),J&&(()=>{const l={active:"推进中",paused:"已暂停",blocked:"已受阻",usage_limited:"用量受限",budget_limited:"预算耗尽",complete:"已完成"},p=J.status!=="active"&&J.status!=="complete";return e.jsxs("div",{className:`goal-queue thread-goal is-${J.status}`,"aria-label":"目标模式",children:[e.jsxs("div",{className:"goal-queue__header",children:[e.jsx(ki,{size:14,strokeWidth:1.9,"aria-hidden":"true"}),e.jsx("span",{children:"目标模式"}),e.jsx("span",{className:"goal-queue__count",children:l[J.status]}),e.jsx("span",{className:"thread-goal__usage",children:J.tokenBudget!==null?`${J.tokensUsed}/${J.tokenBudget} tokens · ${J.turnCount} 轮`:`${J.tokensUsed} tokens · ${J.turnCount} 轮`})]}),e.jsxs("div",{className:"goal-queue__row is-active",children:[e.jsx("span",{className:"goal-queue__objective",title:J.objective,children:J.objective}),J.status==="active"&&e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{ro("pause")},title:"暂停目标续跑","aria-label":"暂停目标续跑",children:"⏸"}),p&&e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{ro("resume")},title:"恢复目标续跑","aria-label":"恢复目标续跑",children:e.jsx(lp,{size:12,strokeWidth:2,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{ro("clear")},title:"清除目标,停止续跑","aria-label":"清除目标,停止续跑",children:e.jsx(Ts,{size:12,strokeWidth:2,"aria-hidden":"true"})})]})]})})(),(K.active||K.queued.length>0)&&e.jsxs("div",{className:"goal-queue","aria-label":"目标队列",children:[e.jsxs("div",{className:"goal-queue__header",children:[e.jsx(ki,{size:14,strokeWidth:1.9,"aria-hidden":"true"}),e.jsx("span",{children:"目标"}),e.jsx("span",{className:"goal-queue__count",children:K.queued.length+(K.active?1:0)})]}),K.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:K.active.objective,children:K.active.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Wa(K.active.id)},title:"停止当前目标","aria-label":"停止当前目标",children:e.jsx(Ts,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]}),K.queued.map((l,p)=>e.jsxs("div",{className:`goal-queue__row is-queued${gr===l.id?" is-dragging":""}`,draggable:!0,onDragStart:()=>fs(l.id),onDragEnd:()=>fs(null),onDragOver:h=>h.preventDefault(),onDrop:()=>{Cu(l.id)},children:[e.jsx(il,{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:l.objective,children:l.objective}),e.jsx("button",{type:"button",className:"goal-queue__action",onClick:()=>{Wa(l.id)},title:"移出目标队列","aria-label":"移出目标队列",children:e.jsx(Ts,{size:14,strokeWidth:1.8,"aria-hidden":"true"})})]},l.id))]}),(()=>{const l=L.filter(p=>p.isQueued);return l.length===0?null:e.jsx("div",{className:"queued-message-list",children:l.map(p=>{const h=p,w=b===p.id,D=h.content.length>80?h.content.slice(0,80)+"…":h.content;return e.jsxs("div",{className:`queued-message-row${vt===p.id?" is-dragging":""}`,"data-queued-message-id":p.id,onDragOver:z=>{!vt||vt===p.id||(z.preventDefault(),z.dataTransfer.dropEffect="move")},onDrop:z=>{z.preventDefault(),vt&&po(vt,p.id),Mn(null)},children:[e.jsx("button",{type:"button",className:"queued-message-grip",draggable:!w,"aria-label":"拖动调整排队顺序",title:"拖动调整顺序",onDragStart:z=>{Mn(p.id),z.dataTransfer.effectAllowed="move",z.dataTransfer.setData("text/plain",p.id)},onDragEnd:()=>Mn(null),onKeyDown:z=>{(z.key==="ArrowUp"||z.key==="ArrowDown")&&(z.preventDefault(),Su(p.id,z.key==="ArrowUp"?-1:1))},onPointerDown:z=>{z.pointerType==="mouse"||w||(vn.current={id:p.id,pointerId:z.pointerId},z.currentTarget.setPointerCapture(z.pointerId),Mn(p.id))},onPointerMove:z=>{var $;const xe=vn.current;if(!xe||xe.pointerId!==z.pointerId)return;z.preventDefault();const pe=($=document.elementFromPoint(z.clientX,z.clientY))==null?void 0:$.closest("[data-queued-message-id]"),Pe=pe==null?void 0:pe.dataset.queuedMessageId;Pe&&Pe!==xe.id&&po(xe.id,Pe)},onPointerUp:z=>{var xe;((xe=vn.current)==null?void 0:xe.pointerId)===z.pointerId&&(vn.current=null,Mn(null))},onPointerCancel:()=>{vn.current=null,Mn(null)},children:e.jsx(il,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsxs("div",{className:"queued-message-content",children:[h.agentName&&e.jsxs("span",{className:"queued-message-agent",children:["@",h.agentName]}),w?e.jsx("input",{autoFocus:!0,className:"queued-message-edit-input",value:F,onChange:z=>ie(z.target.value),onKeyDown:z=>{z.key==="Enter"&&!z.nativeEvent.isComposing?(z.preventDefault(),Da(p.id)):z.key==="Escape"&&(z.preventDefault(),uo())},"aria-label":"编辑排队消息内容"}):e.jsx("span",{className:"queued-message-text",title:h.content,children:D})]}),e.jsxs("div",{className:"queued-message-actions",children:[bn&&e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--accent",onClick:()=>void Pa(p.id),disabled:Ne.has(p.id),title:Ne.has(p.id)?"正在引导":"引导到当前对话","aria-label":Ne.has(p.id)?"正在引导排队消息":"引导排队消息到当前对话",children:Ne.has(p.id)?e.jsx(lt,{className:"spin",size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(rl,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>void ju(p.id),title:ue===p.id?"已复制":"复制","aria-label":"复制排队消息",children:ue===p.id?e.jsx($r,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(Ti,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action",onClick:()=>w?Da(p.id):wu(p.id),disabled:w&&!F.trim(),title:w?"保存":"编辑","aria-label":w?"保存排队消息":"编辑排队消息",children:w?e.jsx($r,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(na,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"queued-message-action queued-message-action--danger",onClick:()=>ku(p.id),title:"删除","aria-label":"删除排队消息",children:e.jsx(Ts,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]})]},p.id)})})})(),e.jsx("div",{ref:Zi,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:ya,type:"file",multiple:!0,style:{display:"none"},onChange:pu}),qs.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0,flexWrap:"nowrap",overflow:"hidden",maxWidth:300},children:qs.map(l=>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"})]}),"@",l.name,e.jsx("button",{onClick:()=>lu(l.id),style:{background:"none",border:"none",color:"rgba(79,110,247,0.55)",cursor:"pointer",padding:0,lineHeight:1,fontSize:12,display:"flex"},children:"✕"})]},l.id))}),e.jsx("textarea",{className:"composer-text-input web-native-composer-textarea",ref:Hs,rows:3,value:En,onChange:l=>Ea(l.target.value),onBlur:()=>setTimeout(()=>{Yr(null),Zr(null)},120),onKeyDown:uu,placeholder:zt==="released"?"已停止在 AgentRoam 中使用;Codex Desktop 最长约 30 分钟后可用":rn?zn==="incompatible"?"Codex 版本不兼容":"正在验证会话兼容性":dr?"原客户端使用中,当前只读":ur?hr?"输入要持续推进的目标":Dn?"输入下一条排队消息":"提出后续修改要求":"请先在设置中配置 API Key",disabled:!an}),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":ds,onClick:()=>us(l=>!l),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"})})}),ds&&e.jsxs("div",{className:"web-native-add-menu",children:[e.jsx("button",{type:"button",onClick:()=>{var l;us(!1),(l=ya.current)==null||l.click()},children:"附件 / 图片"}),e.jsx("button",{type:"button",onClick:()=>{us(!1),iu()},children:"语音输入"})]})]}),e.jsx("button",{type:"button",className:`web-native-runtime-status goal-mode-toggle${hr?" is-active":""}`,"aria-pressed":hr,"aria-label":hr?"关闭目标模式":"开启目标模式",title:hr?"目标模式已开启":"目标模式",onClick:()=>en(l=>!l),children:e.jsx(ki,{size:18,strokeWidth:1.9,"aria-hidden":"true"})}),e.jsxs("div",{className:"web-native-permission-wrap",ref:ln,children:[e.jsx("button",{type:"button",className:`web-native-runtime-status web-native-permission-button mode-${fr}`,"aria-label":`会话权限:${(Qa=zi.find(l=>l.value===fr))==null?void 0:Qa.label}`,"aria-haspopup":"menu","aria-expanded":Nr,title:`会话权限:${(Xa=zi.find(l=>l.value===fr))==null?void 0:Xa.label}`,disabled:!Z||hs,onClick:()=>ps(l=>!l),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"})]})}),Nr&&e.jsx("div",{className:"web-native-permission-menu",role:"menu","aria-label":"会话权限模式",children:zi.map(l=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":fr===l.value,className:fr===l.value?"is-active":"",onClick:()=>{yu(l.value)},children:[e.jsx("span",{className:"web-native-permission-check","aria-hidden":"true",children:fr===l.value?"✓":""}),e.jsxs("span",{className:"web-native-permission-copy",children:[e.jsx("strong",{children:l.label}),e.jsx("small",{children:l.description})]})]},l.value))})]}),e.jsx("div",{className:"web-native-context-control",children:e.jsx(Ph,{usage:Z?Qe[Z]:void 0,contextWindowK:Ut,compact:!0})}),e.jsx("label",{className:`web-native-model-control${xt?" web-native-model-control--native":""}`,title:"切换模型",children:xt&&Di(Ie)?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"web-native-model-agent",title:`${sc[Ie]} 会话`,children:[e.jsx(ia,{agentType:Ie,size:14}),e.jsx("span",{className:"web-native-model-agent-name",children:sc[Ie]})]}),as&&e.jsxs("select",{"aria-label":"当前模型",title:"切换模型",value:Gt,onChange:l=>{ce({model:l.target.value?ef(l.target.value):void 0})},children:[e.jsx("option",{value:"",children:"默认模型"}),Ie==="opencode"?xn.map(l=>e.jsx("optgroup",{label:l.label,children:l.models.map(p=>{const h=si(p);return e.jsx("option",{value:h,children:p.optionLabel},h)})},l.key)):Ce.map(l=>e.jsx("option",{value:l.key,children:l.label},l.key)),He.length>0&&e.jsx("optgroup",{label:"设置里的模型",children:He.map(l=>e.jsx("option",{value:l.key,children:l.label},l.key))})]})]}):e.jsx("select",{"aria-label":"当前模型",value:Dt,disabled:pt.length===0,onChange:l=>{Bt(l.target.value)},children:pt.length===0?e.jsx("option",{value:"",children:"未配置模型"}):pt.map(l=>e.jsx("option",{value:l.id,children:l.name||l.modelId},l.id))})}),gt?e.jsx("button",{type:"button",onClick:co,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"})})}):xt&&Mr.length>0?e.jsxs("div",{className:"web-native-effort-wrap",ref:re,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Ot,"aria-label":`推理强度:${Nt?Co[Nt]:"默认"}`,title:`推理强度:${Nt?Co[Nt]:"默认"}(点击切换)`,onClick:()=>q(l=>!l),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"})]})}),Ot&&e.jsxs("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:[e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":!Nt,className:Nt?void 0:"is-active",onClick:()=>{ce({reasoningEffort:void 0}),q(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Nt?"":"✓"}),"默认"]}),Mr.map(l=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Nt===l,className:Nt===l?"is-active":void 0,onClick:()=>{ce({reasoningEffort:l}),q(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Nt===l?"✓":""}),Co[l]]},l))]})]}):xt?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:Ws,children:[e.jsx("button",{type:"button",className:"web-native-effort-button","aria-expanded":Gr,"aria-label":`推理强度:${rc[Re]}`,title:`推理强度:${rc[Re]}(点击切换)`,onClick:()=>Tr(l=>!l),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"})]})}),Gr&&e.jsx("div",{className:"web-native-effort-menu",role:"menu","aria-label":"推理强度",children:Ld.map(l=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":Re===l.value,className:Re===l.value?"is-active":void 0,onClick:()=>{Nn("reasoningEffort",l.value),_n(),Tr(!1)},children:[e.jsx("span",{className:"web-native-effort-check","aria-hidden":"true",children:Re===l.value?"✓":""}),l.label]},l.value))})]}),e.jsx("button",{type:"button",onClick:Fa,disabled:!an||Fs>0||!En.trim(),className:"web-native-send-button","aria-label":Dn?"排队发送":"发送",title:Dn?"排队发送":"发送",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 发送",hr?"目标":Dn?"(排队)":""," · @智能体(可多选)· /技能 · Shift+Enter 换行",Sa?" · 🎤 正在聆听…":""]})]}),e.jsx(hg,{image:Os,onClose:()=>Kr(null)}),zr&&Vs!==null&&Ra.length>0&&$n.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-zr.top+8,left:zr.left,width:zr.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:"智能体"}),Ra.map(l=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),au(l)},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:["@",l.name]}),l.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1},children:l.description})]},l.id))]}),document.body),zr&&Jr!==null&&so.length>0&&$n.createPortal(e.jsxs("div",{style:{position:"fixed",bottom:window.innerHeight-zr.top+8,left:zr.left,width:zr.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:["技能 (",so.length,")"]}),e.jsx("div",{style:{overflowY:"auto",flex:1},children:so.map(l=>e.jsxs("button",{onMouseDown:p=>{p.preventDefault(),cu(l)},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:["/",l.name]}),l.description&&e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.description})]},l.name))})]}),document.body)]})}function Io(t,n,r="auto"){const s=t.getBoundingClientRect(),i=n.getBoundingClientRect(),o=t.scrollTop+i.top-s.top-Math.max(0,(t.clientHeight-i.height)/2);t.scrollTo({top:Math.max(0,o),behavior:r})}const Ii=4,Qg=4e6,Xg=8,Yg=.12;function Jg(t,n,r=Yg){if(n<=0)return[];const s=Array.from({length:n},(u,g)=>{const f=Number(t[g]);return Number.isFinite(f)&&f>0?f:1}),i=s.reduce((u,g)=>u+g,0),c=s.map(u=>u/i).map(u=>Math.max(u,r)),d=c.reduce((u,g)=>u+g,0);return c.map(u=>u/d)}function Zg(t,n,r,s=Xg){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 i=Math.min(n,6),o=s*(i-1),c=t.width-o;if(c<=0)return[];const d=Jg(r,i),u=[];let g=t.x;for(let f=0;f<i;f+=1){const y=f===i-1?t.x+t.width-g:Math.floor(c*d[f]);u.push({x:Math.round(g),y:Math.round(t.y),width:Math.round(y),height:Math.round(t.height)}),g+=y+s}return u}function em({siteId:t,name:n,onSetup:r}){const s=window.agentApi,[i,o]=a.useState(null),[c,d]=a.useState({connected:!1,tabs:[]}),[u,g]=a.useState(""),[f,x]=a.useState(!1),[y,v]=a.useState(Date.now()),[S,E]=a.useState(!0),C=a.useRef(null),I=!c.paused&&c.compatible!==!1&&c.tabs.some(W=>W.siteId===t);a.useEffect(()=>{let W=!1,ee=!1,N=!1;s.hubChromeStatus().then(R=>{!W&&!ee&&d(R)}),typeof s.hubChromeConversation!="function"?g("请重启 AI Hub 桌面端以启用消息面板"):s.hubChromeConversation(t).then(R=>{!W&&!N&&o(R)});const T=s.onHubChromeEvent(R=>{R.type==="chrome-conversation"&&R.conversation.siteId===t&&(N=!0,o(L=>!L||R.conversation.revision>L.revision?R.conversation:L),g("")),R.type==="chrome-status"&&(ee=!0,d(R.status),R.status.tabs.some(L=>L.siteId===t)||(o(null),g(""))),R.type==="chrome-page-error"&&R.siteId===t&&g(R.error)}),A=setInterval(()=>v(Date.now()),1e3);return()=>{W=!0,T(),clearInterval(A)}},[s,t]),a.useLayoutEffect(()=>{S&&C.current&&(C.current.scrollTop=C.current.scrollHeight)},[i==null?void 0:i.revision,S]);const j=I&&!!i&&y-i.receivedAt>6e3,k=c.paused?"Chrome 网页连接已暂停,点击下方按钮即可恢复。":c.connected&&c.compatible===!1?"请从「连接 Chrome」加载新版自动连接扩展。":I?i?i.generating?"正在回复…":i.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:k}),e.jsx("div",{ref:C,onScroll:()=>{const W=C.current;W&&E(W.scrollHeight-W.scrollTop-W.clientHeight<60)},style:{flex:1,minHeight:0,overflow:"auto",padding:"18px 16px",overflowWrap:"anywhere"},children:I?i!=null&&i.messages.length?i.messages.map(W=>e.jsxs("article",{"data-message-id":W.id,style:{marginBottom:24,padding:W.role==="user"?"12px 14px":"0 2px",borderRadius:12,background:W.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:W.role==="user"?"你":n}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto","aria-label":`复制 ${W.role==="user"?"消息":n+" 回复"}`,style:{padding:"2px 5px",fontSize:11},onClick:()=>{navigator.clipboard.writeText(W.content).catch(()=>g("未能复制,请选择文字复制"))},children:"复制"})]}),e.jsx("div",{style:{fontSize:15,lineHeight:1.8,whiteSpace:"pre-wrap",color:"var(--text-primary)"},children:zd(W.content)})]},`${i.conversationId}:${W.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:f,style:{padding:"8px 12px",color:"var(--accent)"},onClick:async()=>{x(!0),g("");try{d(await s.hubChromeResume())}catch(W){g(W instanceof Error?W.message:"恢复连接失败,请检查 Chrome 扩展")}finally{x(!1)}},children:f?"正在恢复…":"恢复全部 Chrome 连接"}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{padding:"8px 12px"},onClick:()=>{s.hubOpenChrome(t).catch(()=>g("无法打开 Chrome,请检查是否已安装"))},children:"登录 / 打开原网页"}),e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{padding:"8px 12px"},onClick:r,children:"连接设置"})]})}),!S&&e.jsx("button",{className:"ui-icon-button ui-icon-button--auto",style:{alignSelf:"center",padding:"7px 12px",margin:8},onClick:()=>E(!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 tm({onClose:t}){const n=window.agentApi,[r,s]=a.useState(""),[i,o]=a.useState(!1),[c,d]=a.useState(""),[u,g]=a.useState(!1);a.useEffect(()=>{let x=!0;n.hubChromeStatus().then(v=>{x&&g(v.connected&&v.compatible!==!1)}).catch(()=>{x&&s("暂时无法检测插件连接,请稍后重试")});const y=n.onHubChromeEvent(v=>{v.type==="chrome-status"&&g(v.status.connected&&v.status.compatible!==!1)});return()=>{x=!1,y()}},[n]);const f=async()=>{o(!0),s("");try{const x=await n.hubChromeInstallExtension();d(x.path),s(x.browserOpened?"已打开 Chrome 扩展管理页,插件目录路径已复制。":"未能打开 Chrome。请先安装或打开 Google Chrome,再进入 chrome://extensions;插件目录路径已复制。")}catch{s("未能准备插件,请确认桌面端已启动,稍后重试。")}finally{o(!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:i,className:"ui-icon-button ui-icon-button--auto",onClick:()=>void f(),style:{padding:"5px 10px"},children:i?"正在打开…":"安装浏览器插件"}),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 nm=["chatgpt","gemini","grok"];function Ri(t){return nm.includes(t)}const rm=52,Ro=30,sm=4;function im(t,n){return t.includes(n)?t.length>1?t.filter(r=>r!==n):t:t.length<sm?[...t,n]:t}function om(t){return(t.trim()[0]||"?").toUpperCase()}function oc(t){try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function am({onExit:t,conversationId:n}){const r=typeof window<"u"?window.agentApi:void 0,s=typeof(r==null?void 0:r.hubGetConfig)=="function",[i,o]=a.useState([]),[c,d]=a.useState([]),[u,g]=a.useState([]),[f,x]=a.useState(null),[y,v]=a.useState({}),[S,E]=a.useState({}),[C,I]=a.useState({}),[j,k]=a.useState(""),[W,ee]=a.useState([]),[N,T]=a.useState(""),[A,R]=a.useState(!1),L=a.useRef(null),H=a.useRef(null),[de,Fe]=a.useState(!1),[fe,je]=a.useState([]),[ze,Ge]=a.useState(!1),[Ke,Ct]=a.useState(!1),[it,te]=a.useState(""),[ge,Qe]=a.useState(""),[B,G]=a.useState(!1),[Y,ae]=a.useState([]);a.useEffect(()=>{if(!(r!=null&&r.hubChromeStatus))return;let P=!1,K=!1;const X=ne=>{if(P)return;const ct=ne.connected&&ne.compatible!==!1;ae(ct?ne.tabs.map(ht=>ht.siteId):[]),ct?G(!1):K||G(!0),K=!0};r.hubChromeStatus().then(X).catch(()=>{!P&&!K&&(K=!0,G(!0))});const J=r.onHubChromeEvent(ne=>{ne.type==="chrome-status"&&X(ne.status)});return()=>{P=!0,J()}},[r]);const me=a.useRef(null),le=a.useRef(null);a.useRef(0),a.useLayoutEffect(()=>{const P=H.current;P&&(P.style.height="32px",j&&(P.style.height=`${Math.max(32,Math.min(P.scrollHeight,120))}px`))},[j,c.length]);const Se=async P=>{if(!(de||A)){R(!0),T("");try{if(P.length+W.length>Ii)throw new Error(`最多添加 ${Ii} 张图片`);const K=await Promise.all(P.map(async X=>{if(!/^image\/(png|jpeg|webp)$/.test(X.type))throw new Error("请选择 PNG、JPEG 或 WebP 图片");if(X.size*4/3+32>Qg)throw new Error("单张图片不能超过约 3 MB");return new Promise((J,ne)=>{const ct=new FileReader;ct.onload=()=>J(String(ct.result)),ct.onerror=()=>ne(new Error("图片读取失败,请重试")),ct.readAsDataURL(X)})}));ee(X=>[...X,...K].slice(0,Ii))}catch(K){T(K instanceof Error?K.message:"图片读取失败")}finally{R(!1)}}},Te=a.useMemo(()=>f?Zg(f,c.length,u):[],[f,c.length,u]);a.useEffect(()=>{if(!s||Te.length===0)return;const P=c.map((K,X)=>{const J=Te[X];return{siteId:K,...n?{conversationId:n}:{},x:J.x,y:J.y+Ro,width:J.width,height:Math.max(J.height-Ro,0)}});r==null||r.hubSetBounds(P)},[s,r,Te,c,n]),a.useEffect(()=>{if(s)for(const P of c)r==null||r.hubOpenSite(P,n??void 0)},[s,r,c,n]),a.useEffect(()=>{if(!s)return;const P=me.current;if(!P)return;const K=()=>{const ne=P.getBoundingClientRect();x(ct=>ct&&Math.abs(ct.x-ne.x)<.5&&Math.abs(ct.y-ne.y)<.5&&Math.abs(ct.width-ne.width)<.5&&Math.abs(ct.height-ne.height)<.5?ct:{x:ne.x,y:ne.y,width:ne.width,height:ne.height})},X={current:0},J=new ResizeObserver(()=>{cancelAnimationFrame(X.current),X.current=requestAnimationFrame(K)});return J.observe(P),K(),()=>{J.disconnect(),cancelAnimationFrame(X.current)}},[s,Ke]),a.useEffect(()=>{if(!ze)return;const P=X=>{var J;(J=le.current)!=null&&J.contains(X.target)||Ge(!1)},K=()=>Ge(!1);return document.addEventListener("pointerdown",P),window.addEventListener("blur",K),()=>{document.removeEventListener("pointerdown",P),window.removeEventListener("blur",K)}},[ze]),a.useEffect(()=>{if(!s||!r)return;let P=!1;r.hubGetConfig().then(X=>{P||(o(X.sites),d(J=>J.length>0?J:X.sites.slice(0,1).map(ne=>ne.id)))});const K=r.onHubEvent(X=>{X.type==="load-failed"?(v(J=>({...J,[X.siteId]:X.errorCode??-1})),E(J=>({...J,[X.siteId]:!1}))):X.type==="loaded"?(v(J=>{if(!(X.siteId in J))return J;const ne={...J};return delete ne[X.siteId],ne}),E(J=>({...J,[X.siteId]:!1}))):X.type==="loading"?(E(J=>({...J,[X.siteId]:!0})),I(J=>{if(!(X.siteId in J))return J;const ne={...J};return delete ne[X.siteId],ne})):X.type==="google-auth-external"&&I(J=>({...J,[X.siteId]:!0}))});return()=>{P=!0,K(),r.hubHideAll()}},[s,r]),a.useEffect(()=>{const P=Math.max(c.length,0);g(K=>K.length===P?K:Array.from({length:P},()=>P>0?1/P:0))},[c.length]);const mt=a.useCallback(P=>{d(K=>im(K,P))},[]),$e=a.useCallback(P=>{v(K=>{const X={...K};return delete X[P],X}),r==null||r.hubReload(P,n??void 0),r==null||r.hubOpenSite(P,n??void 0)},[r,n]),yt=a.useCallback(P=>{c.length<=1||(r==null||r.hubCloseSite(P,n??void 0),d(K=>K.filter(X=>X!==P)))},[r,c.length,n]),st=a.useCallback(async()=>{const P=j.trim();if(!(!P&&W.length===0||!r||de||A||c.length===0)){Fe(!0);try{const K=await r.hubBroadcast(P,c,W),X=K.map(J=>({...J,at:Date.now()}));je(X),K.length>0&&K.every(J=>J.ok)&&(k(""),ee([]),T("")),setTimeout(()=>{je(J=>J.filter(ne=>!ne.ok||Date.now()-ne.at<8e3))},8200)}catch(K){T(K instanceof Error?K.message:"发送失败,请重试")}finally{Fe(!1)}}},[r,j,W,A,de,c]),tt=a.useCallback(async()=>{if(!r||!oc(ge))return;const P=ge.trim(),K=it.trim()||new URL(P).hostname,X={id:`custom-${Math.random().toString(36).slice(2,10)}`,name:K,url:P,adapter:"generic"},J=await r.hubSetConfig({version:1,sites:[...i,X]});o(J.sites),te(""),Qe(""),Ct(!1)},[r,it,ge,i]),It=a.useCallback(async P=>{if(!r||i.length<=1)return;r.hubCloseSite(P,n??void 0);const K=await r.hubSetConfig({version:1,sites:i.filter(X=>X.id!==P)});o(K.sites),d(X=>{const J=X.filter(ne=>ne!==P);return J.length>0?J:K.sites.slice(0,1).map(ne=>ne.id)})},[r,i,n]),ft=a.useCallback((P,K)=>{K.preventDefault();const X=Te.length,J=X>1?8:0,ne=((f==null?void 0:f.width)??0)-J*(X-1);if(ne<=0)return;const ct=K.clientX,ht=[...u],ot=Te[P].width,Ue=ht[P]+ht[P+1],$t=Xe=>{const pt=Xe.clientX-ct,Dt=80,Bt=Ue*ne,gn=Math.min(Math.max(ot+pt,Dt),Bt-Dt),Ut=[...ht];Ut[P]=gn/ne,Ut[P+1]=(Bt-gn)/ne,g(Ut)},tn=()=>{window.removeEventListener("pointermove",$t),window.removeEventListener("pointerup",tn)};window.addEventListener("pointermove",$t),window.addEventListener("pointerup",tn)},[u,Te,f]);return s?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:rm,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",style:{WebkitAppRegion:"no-drag",width:34,height:34,flexShrink:0},children:e.jsx(Zo,{size:18,"aria-hidden":"true"})}),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:()=>G(P=>!P),style:{WebkitAppRegion:"no-drag",marginLeft:"auto",padding:"5px 10px"},children:"连接 Chrome"})]}),B&&e.jsx(tm,{onClose:()=>G(!1)}),e.jsxs("div",{ref:me,style:{flex:1,position:"relative",overflow:"hidden",minHeight:0},children:[Te.map((P,K)=>{const X=c[K],J=i.find(ct=>ct.id===X),ne=X in y;return e.jsxs("div",{"data-aihub-pane":X,style:{position:"absolute",left:P.x-((f==null?void 0:f.x)??0),top:P.y-((f==null?void 0:f.y)??0),width:P.width,height:P.height,display:"flex",flexDirection:"column",borderRight:K<Te.length-1?"1px solid var(--border-subtle)":void 0},children:[e.jsxs("div",{style:{height:Ro,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:Ri(X)?Y.includes(X)?"var(--success)":"var(--text-muted)":ne?"#f7768e":S[X]?"var(--accent-glow)":"#9ece6a",flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:40,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(J==null?void 0:J.name)??X}),C[X]&&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 登录已转至浏览器,内嵌请用邮箱"}),Ri(X)&&e.jsx("button",{type:"button","aria-label":`打开 ${(J==null?void 0:J.name)??X} Chrome 页面`,title:"在日常 Chrome 中登录或查看页面",className:"ui-icon-button ui-icon-button--auto",onClick:()=>{r.hubOpenChrome(X).catch(()=>G(!0))},style:{padding:"2px 6px",fontSize:11},children:"Chrome ↗"}),e.jsx("button",{type:"button",title:"刷新","aria-label":`刷新 ${(J==null?void 0:J.name)??X}`,onClick:()=>$e(X),className:"ui-icon-button",style:{padding:2},children:"⟳"}),c.length>1&&e.jsx("button",{type:"button",title:"关闭页面","aria-label":`关闭 ${(J==null?void 0:J.name)??X}`,onClick:()=>yt(X),className:"ui-icon-button",style:{padding:2},children:"×"})]}),e.jsxs("div",{style:{flex:1,position:"relative",background:"var(--bg-surface)"},children:[Ri(X)&&e.jsx(em,{siteId:X,name:(J==null?void 0:J.name)??X,onSetup:()=>G(!0)}),!Ri(X)&&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[X],")"]}),e.jsx("button",{type:"button",onClick:()=>$e(X),className:"ui-icon-button ui-icon-button--auto",style:{justifySelf:"center",padding:"5px 12px"},children:"重试"})]})})]}),K<Te.length-1&&e.jsx("div",{"data-aihub-divider":K,onPointerDown:ct=>ft(K,ct),title:"拖动调整宽度",style:{position:"absolute",top:0,bottom:0,right:-5,width:10,cursor:"col-resize",zIndex:5}})]},X)}),Te.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:le,style:{position:"relative",display:"flex",flexDirection:"column",gap:8},children:[ze&&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:[i.map(P=>{const K=c.includes(P.id),X=P.id.startsWith("custom-");return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsxs("button",{type:"button",role:"option","aria-selected":K,onClick:()=>mt(P.id),style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:0,borderRadius:6,background:K?"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 ${K?"var(--accent)":"var(--border-default)"}`,background:K?"var(--accent)":"transparent",color:K?"var(--bg-workspace)":"transparent",flexShrink:0},children:e.jsx($r,{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:om(P.name)}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13},children:P.name})]}),X&&e.jsx("button",{type:"button",title:`删除站点 ${P.name}`,"aria-label":`删除站点 ${P.name}`,onClick:()=>void It(P.id),className:"ui-icon-button",style:{width:30,height:30,padding:0,flexShrink:0},children:e.jsx(Ts,{size:14,"aria-hidden":"true"})})]},P.id)}),e.jsx("div",{style:{height:1,margin:"4px 6px",background:"var(--border-subtle)"}}),Ke?e.jsxs("div",{style:{display:"grid",gap:6,padding:6},children:[e.jsx("input",{value:it,onChange:P=>te(P.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:ge,onChange:P=>Qe(P.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 tt(),disabled:!oc(ge),className:"ui-icon-button ui-icon-button--auto",style:{padding:"5px 10px",fontSize:12},children:"添加"}),e.jsx("button",{type:"button",onClick:()=>Ct(!1),className:"ui-icon-button ui-icon-button--auto",style:{padding:"5px 10px",fontSize:12},children:"取消"})]})]}):e.jsxs("button",{type:"button",onClick:()=>Ct(!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($o,{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:()=>Ge(P=>!P),"aria-haspopup":"listbox","aria-expanded":ze,"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:[c.length," 个 AI",e.jsx(Li,{size:14,"aria-hidden":"true",style:{transform:ze?"rotate(180deg)":void 0}})]}),e.jsx("input",{ref:L,type:"file",accept:"image/png,image/jpeg,image/webp",multiple:!0,hidden:!0,onChange:P=>{const K=Array.from(P.target.files??[]);P.target.value="",Se(K)}}),e.jsx("button",{type:"button","aria-label":"添加图片附件",title:"添加图片附件(也可粘贴截图)",disabled:de||A||W.length>=Ii,onClick:()=>{var P;return(P=L.current)==null?void 0:P.click()},className:"ui-icon-button",style:{width:34,height:34,padding:0,flexShrink:0},children:e.jsx(ip,{size:17,"aria-hidden":"true"})}),e.jsx("textarea",{ref:H,"aria-label":"发送给选中的 AI",disabled:de,value:j,onChange:P=>k(P.target.value),onPaste:P=>{const K=Array.from(P.clipboardData.files);K.length!==0&&(P.preventDefault(),Se(K))},onKeyDown:P=>{P.nativeEvent.isComposing||P.nativeEvent.keyCode===229||(P.key==="Enter"&&(!P.shiftKey||P.metaKey||P.ctrlKey)?(P.preventDefault(),st()):P.key==="Escape"&&ze&&(P.preventDefault(),Ge(!1)))},rows:1,placeholder:`一次输入,发到 ${c.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:j?"left":"center"}}),e.jsx("button",{type:"button",onClick:()=>void st(),disabled:!j.trim()&&W.length===0||de||A||c.length===0,title:"同步发送(Enter)","aria-label":"同步发送",className:"ui-icon-button",style:{width:36,height:36,padding:0,borderRadius:"50%",background:(j.trim()||W.length>0)&&!de?"var(--accent)":"var(--bg-glass)",color:(j.trim()||W.length>0)&&!de?"var(--bg-workspace)":"var(--text-muted)",flexShrink:0},children:e.jsx(up,{size:16,"aria-hidden":"true"})})]})]}),W.length>0&&e.jsx("div",{"aria-label":"待发送图片",style:{display:"flex",gap:8,flexWrap:"wrap"},children:W.map((P,K)=>e.jsxs("div",{style:{position:"relative",width:56,height:56},children:[e.jsx("img",{src:P,alt:`附件 ${K+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:6}}),e.jsx("button",{type:"button","aria-label":`移除附件 ${K+1}`,disabled:de,onClick:()=>ee(X=>X.filter((J,ne)=>ne!==K)),className:"ui-icon-button",style:{position:"absolute",top:0,right:0,padding:2,background:"var(--bg-workspace)"},children:e.jsx(Rr,{size:12})})]},`${K}-${P.length}`))}),N&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"var(--text-secondary)",textAlign:"center"},children:N}),fe.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center",minHeight:18},children:fe.map(P=>{var K;return e.jsx("span",{role:"status",style:{fontSize:11,padding:"3px 10px",borderRadius:999,color:P.ok?"#9ece6a":"#f7768e",background:"var(--bg-glass)",whiteSpace:"normal",overflowWrap:"anywhere"},children:(((K=i.find(X=>X.id===P.siteId))==null?void 0:K.name)??P.siteId)+(P.ok?" ✓":` ✕ ${P.reason??"失败"}`)},P.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 Pd=new Set(["downloading","installing","reconnecting"]),lm=new Set(["checking",...Pd]),cm=6e3,dm=24e3;function um(){const[t,n]=a.useState(null),[r,s]=a.useState(()=>sessionStorage.getItem("agentroam.dismissed-update"));if(a.useEffect(()=>{var S;let f=!0;const x=window.agentApi,y=((S=x.onUpdateStatus)==null?void 0:S.call(x,E=>{f&&n(E)}))??(()=>{});x.getUpdateStatus().then(E=>{f&&n(E)}).catch(()=>{});const v=window.setTimeout(()=>{x.checkForUpdate().then(E=>{f&&n(E)}).catch(()=>{})},cm+Math.floor(Math.random()*(dm+1)));return()=>{f=!1,window.clearTimeout(v),y()}},[]),a.useEffect(()=>{if(!t||!lm.has(t.phase))return;const f=window.setInterval(()=>{window.agentApi.getUpdateStatus().then(n).catch(()=>{})},1500);return()=>window.clearInterval(f)},[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 i=Pd.has(t.phase),o=t.phase==="failed",c=t.phase==="complete",d=i?t.phase==="downloading"?`正在下载${t.progress!==void 0?` ${t.progress}%`:""}`:t.phase==="installing"?"正在安装":"正在重连":o?"更新失败,重试":c?t.message??"更新已就绪":`发现 AgentRoam ${t.targetVersion}`,u=async()=>{try{n(await window.agentApi.installUpdate())}catch(f){n({...t,phase:"failed",message:f instanceof Error?f.message:"更新失败"})}},g=()=>{t.targetVersion&&(sessionStorage.setItem("agentroam.dismissed-update",t.targetVersion),s(t.targetVersion))};return e.jsxs("aside",{className:`update-notice${o?" update-notice--failed":""}`,"aria-live":"polite",children:[e.jsxs("div",{className:"update-notice__content",children:[e.jsx("strong",{children:d}),!i&&!c&&e.jsx("span",{children:"点击后才会下载安装文件"}),o&&t.message&&e.jsx("span",{children:t.message})]}),!i&&!c&&e.jsxs("button",{className:"update-notice__action",type:"button",onClick:()=>void u(),title:o?"重试更新":"下载更新",children:[o?e.jsx(_s,{size:16}):e.jsx(ta,{size:16}),e.jsx("span",{children:o?"重试":"更新"})]}),!i&&e.jsx("button",{className:"update-notice__close",type:"button",onClick:g,title:"关闭更新提醒","aria-label":"关闭更新提醒",children:e.jsx(Rr,{size:16})})]})}function pm(){const[t,n]=a.useState(null);a.useEffect(()=>{const o=window.agentApi;if(!(o!=null&&o.desktopLiveGetStatus)||!(o!=null&&o.onDesktopLiveStatus))return;let c=!0;o.desktopLiveGetStatus().then(u=>{c&&n(u)}).catch(()=>{});const d=o.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 i=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:"●"}),i?"正在结束远程控制":"正在被远程控制"]})}function Eo(t){return t==="idle"?"completed":t}const Mo={"needs-input":"需要输入",running:"运行中",completed:"执行完成",stale:"状态待刷新",error:"执行错误"};function ha(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 fm(t){return ha(t,(n,r)=>r.created.localeCompare(n.created))}function Qo(t,n){return n==="codex"?[...t]:fm(t)}function ac(t,n){return ha(t,(r,s)=>Number(n(s))-Number(n(r)))}function hm(t,n){return ha(t,(r,s)=>Number(n(s))-Number(n(r)))}const Ao={projectId:null,sessionId:null};function Xo(t){return typeof t=="string"&&t.trim()?t.trim():null}function lc(t){return{projectId:Xo(t),sessionId:null}}function To(t,n){return{projectId:Xo(t),sessionId:Xo(n)}}function gm(t){return t.agentType==="customer-agent"?`确定永久删除会话“${t.title}”吗?此操作不可恢复。`:t.agentType==="codex"?`确定归档 Codex 会话“${t.title}”并从 AgentRoam 中移除吗?可在 Codex 的已归档会话中恢复。`:`确定从 AgentRoam 中移除会话“${t.title}”吗?原生客户端中的历史记录会保留。`}function mm(t,n){const r=new Set(n);return{...t,selectedSessionId:t.selectedSessionId&&r.has(t.selectedSessionId)?null:t.selectedSessionId,sessions:Object.fromEntries(Object.entries(t.sessions).map(([s,i])=>[s,{...i,data:i.data.filter(o=>!r.has(o.id))}]))}}function xm(t,n){const r=new Set(n);let s=!1;const i=Object.fromEntries(Object.entries(t).map(([o,c])=>{const d=c.filter(u=>!r.has(u.id));return d.length!==c.length&&(s=!0),[o,d.length===c.length?c:d]}));return s?i:t}function bm(t,n,r,s){const i=[s,...(n[s]??[]).map(d=>d.id)],o=new Set(i),c=Object.fromEntries(Object.entries(n).flatMap(([d,u])=>{if(o.has(d))return[];const g=u.filter(f=>!o.has(f.id));return[[d,g.length===u.length?u:g]]}));return{sessionsByProject:xm(t,i),childSessionsByParent:c,otherLocalSessions:r.filter(d=>!o.has(d.id)),removedIds:i}}function ym(t){if(!t.trim())return null;const n=Number(t);return Number.isSafeInteger(n)&&n>=0?n:null}function Dd({message:t,type:n}){return t?$n.createPortal(e.jsxs("div",{className:`app-action-notice is-${n}`,role:n==="error"?"alert":"status","aria-live":n==="error"?"assertive":"polite",children:[e.jsx("span",{className:"app-action-notice-mark","aria-hidden":"true",children:n==="success"?"✓":n==="info"?"i":"!"}),e.jsx("span",{children:t})]}),document.body):null}const vm=()=>({id:"",name:"",enabled:!0,allowedTools:[],filesystem:{readRoots:[],writeRoots:[],followSymlinks:!1},commands:{mode:"deny",programs:[],inheritedEnvironment:[]},network:"deny",limits:{timeoutMs:12e4,maxOutputBytes:1048576}});function wm({onNotice:t}){const[n,r]=a.useState([]),[s,i]=a.useState([]),[o,c]=a.useState(null),[d,u]=a.useState(!1),g=a.useMemo(()=>[...s].sort(),[s]),f=async()=>{var S;if(!((S=window.agentApi)!=null&&S.listToolPolicies))return;const v=await window.agentApi.listToolPolicies();r(v.policies),i(v.tools)};a.useEffect(()=>{f().catch(v=>t(String(v),"error"))},[]);const x=async()=>{var v;if(!(!o||!((v=window.agentApi)!=null&&v.saveToolPolicy)))try{await window.agentApi.saveToolPolicy(o,d),await f(),c(null),t("工具策略已保存","success")}catch(S){t(S instanceof Error?S.message:"工具策略保存失败","error")}},y=async v=>{var S;if((S=window.agentApi)!=null&&S.deleteToolPolicy)try{await window.agentApi.deleteToolPolicy(v),await f(),(o==null?void 0:o.id)===v&&c(null),t("工具策略已删除","success")}catch(E){t(E instanceof Error?E.message:"工具策略删除失败","error")}};return e.jsxs("section",{className:"tool-policy-manager",children:[e.jsxs("div",{className:"settings-head-row",children:[e.jsx("h3",{children:"工具执行策略"}),e.jsx("button",{type:"button",className:"tool-policy-button",onClick:()=>{c(vm()),u(!1)},children:"+ 添加"})]}),e.jsxs("div",{className:"tool-policy-list",children:[n.map(v=>e.jsxs("div",{className:"tool-policy-row",children:[e.jsxs("div",{children:[e.jsx("strong",{children:v.name}),e.jsxs("small",{children:[v.id," · ",v.enabled?"已启用":"已停用"]})]}),e.jsxs("div",{className:"tool-policy-actions",children:[e.jsx("button",{type:"button",onClick:()=>{c(structuredClone(v)),u(!0)},children:"编辑"}),e.jsx("button",{type:"button",className:"is-danger",onClick:()=>void y(v.id),children:"删除"})]})]},v.id)),n.length===0&&e.jsx("div",{className:"tool-policy-empty",children:"暂无工具执行策略"})]}),o&&e.jsxs("div",{className:"tool-policy-form",children:[e.jsxs("div",{className:"tool-policy-grid two",children:[e.jsx(hn,{label:"策略 ID",children:e.jsx("input",{value:o.id,disabled:d,onChange:v=>c({...o,id:v.target.value})})}),e.jsx(hn,{label:"名称",children:e.jsx("input",{value:o.name,onChange:v=>c({...o,name:v.target.value})})})]}),e.jsxs("label",{className:"tool-policy-check",children:[e.jsx("input",{type:"checkbox",checked:o.enabled,onChange:v=>c({...o,enabled:v.target.checked})}),"启用"]}),e.jsx(hn,{label:"允许的工具",children:e.jsx("div",{className:"tool-policy-tools",children:g.map(v=>e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:o.allowedTools.includes(v),onChange:()=>c({...o,allowedTools:km(o.allowedTools,v)})}),v]},v))})}),e.jsxs("div",{className:"tool-policy-grid two",children:[e.jsx(hn,{label:"只读根目录(每行一个)",children:e.jsx("textarea",{value:o.filesystem.readRoots.join(`
460
- `),onChange:v=>c({...o,filesystem:{...o.filesystem,readRoots:cc(v.target.value)}})})}),e.jsx(hn,{label:"可写根目录(每行一个)",children:e.jsx("textarea",{value:o.filesystem.writeRoots.join(`
461
- `),onChange:v=>c({...o,filesystem:{...o.filesystem,writeRoots:cc(v.target.value)}})})})]}),e.jsxs("label",{className:"tool-policy-check",children:[e.jsx("input",{type:"checkbox",checked:o.filesystem.followSymlinks,onChange:v=>c({...o,filesystem:{...o.filesystem,followSymlinks:v.target.checked}})}),"允许根目录内符号链接"]}),e.jsxs("div",{className:"tool-policy-grid three",children:[e.jsx(hn,{label:"命令模式",children:e.jsxs("select",{value:o.commands.mode,onChange:v=>c({...o,commands:{...o.commands,mode:v.target.value}}),children:[e.jsx("option",{value:"deny",children:"禁止"}),e.jsx("option",{value:"allowlist",children:"白名单"}),e.jsx("option",{value:"unrestricted",children:"不限制"})]})}),e.jsx(hn,{label:"网络模式",children:e.jsxs("select",{value:o.network,onChange:v=>c({...o,network:v.target.value}),children:[e.jsx("option",{value:"deny",children:"禁止"}),e.jsx("option",{value:"read-only",children:"只读"}),e.jsx("option",{value:"allow",children:"允许"})]})}),e.jsx(hn,{label:"继承环境变量",children:e.jsx("input",{value:o.commands.inheritedEnvironment.join(", "),onChange:v=>c({...o,commands:{...o.commands,inheritedEnvironment:As(v.target.value)}})})})]}),o.commands.mode==="allowlist"&&e.jsxs("div",{className:"tool-policy-programs",children:[e.jsxs("div",{className:"settings-head-row",children:[e.jsx("h4",{children:"允许的程序"}),e.jsx("button",{type:"button",onClick:()=>c({...o,commands:{...o.commands,programs:[...o.commands.programs,{executable:""}]}}),children:"+ 程序"})]}),o.commands.programs.map((v,S)=>e.jsx(jm,{program:v,onChange:E=>c({...o,commands:{...o.commands,programs:Sm(o.commands.programs,S,E)}}),onDelete:()=>c({...o,commands:{...o.commands,programs:o.commands.programs.filter((E,C)=>C!==S)}})},S))]}),e.jsxs("div",{className:"tool-policy-grid two",children:[e.jsx(hn,{label:"超时(毫秒)",children:e.jsx("input",{type:"number",min:100,max:6e5,value:o.limits.timeoutMs,onChange:v=>c({...o,limits:{...o.limits,timeoutMs:Number(v.target.value)}})})}),e.jsx(hn,{label:"最大输出(字节)",children:e.jsx("input",{type:"number",min:1024,max:10485760,value:o.limits.maxOutputBytes,onChange:v=>c({...o,limits:{...o.limits,maxOutputBytes:Number(v.target.value)}})})})]}),e.jsxs("div",{className:"tool-policy-actions",children:[e.jsx("button",{type:"button",className:"is-primary",onClick:()=>void x(),children:"保存策略"}),e.jsx("button",{type:"button",onClick:()=>c(null),children:"取消"})]})]})]})}function jm({program:t,onChange:n,onDelete:r}){return e.jsxs("div",{className:"tool-policy-program",children:[e.jsxs("div",{className:"tool-policy-grid two",children:[e.jsx(hn,{label:"可执行文件",children:e.jsx("input",{value:t.executable,onChange:s=>n({...t,executable:s.target.value})})}),e.jsx(hn,{label:"子命令",children:e.jsx("input",{value:(t.subcommands??[]).join(", "),onChange:s=>n({...t,subcommands:As(s.target.value)})})})]}),e.jsxs("div",{className:"tool-policy-grid three",children:[e.jsx(hn,{label:"允许参数",children:e.jsx("input",{value:(t.allowedFlags??[]).join(", "),onChange:s=>n({...t,allowedFlags:As(s.target.value)})})}),e.jsx(hn,{label:"禁止参数",children:e.jsx("input",{value:(t.deniedFlags??[]).join(", "),onChange:s=>n({...t,deniedFlags:As(s.target.value)})})}),e.jsx(hn,{label:"路径参数",children:e.jsx("input",{value:(t.pathFlags??[]).join(", "),onChange:s=>n({...t,pathFlags:As(s.target.value)})})})]}),e.jsxs("div",{className:"tool-policy-program-footer",children:[e.jsx(hn,{label:"位置路径索引",children:e.jsx("input",{value:(t.positionalPathIndexes??[]).join(", "),onChange:s=>n({...t,positionalPathIndexes:As(s.target.value).map(Number)})})}),e.jsx("button",{type:"button",className:"is-danger",onClick:r,children:"删除程序"})]})]})}function hn({label:t,children:n}){return e.jsxs("label",{className:"tool-policy-field",children:[e.jsx("span",{children:t}),n]})}function cc(t){return t.split(`
462
- `).map(n=>n.trim()).filter(Boolean)}function As(t){return t.split(",").map(n=>n.trim()).filter(Boolean)}function km(t,n){return t.includes(n)?t.filter(r=>r!==n):[...t,n]}function Sm(t,n,r){return t.map((s,i)=>i===n?r:s)}const Cm=[{value:"anthropic",label:"Anthropic"},{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"aihub",label:"AI Hub(网页版)"}],dc={anthropic:"claude-sonnet-4-6",openai:"gpt-4o",deepseek:"deepseek-chat",aihub:"deepseek"},Fi={anthropic:120,openai:300,deepseek:300,aihub:240};function uc(){return{name:"",provider:"anthropic",modelId:"claude-sonnet-4-6",apiKey:"",baseUrl:"",maxOutputTokens:16384,requestTimeoutSeconds:Fi.anthropic}}function Im(){const{maxIterations:t,contextWindow:n,isConfigured:r,profiles:s,activeProfileId:i,taskNotifications:o,setField:c,loadFromSystem:d,saveToSystem:u,addProfile:g,updateProfile:f,deleteProfile:x,switchActiveProfile:y}=Ui(),[v,S]=a.useState(null),[E,C]=a.useState("success"),[I,j]=a.useState(null),[k,W]=a.useState(String(t)),[ee,N]=a.useState(String(Math.round((n??100)*1e3)));a.useEffect(()=>{W(String(t))},[t]),a.useEffect(()=>{N(String(Math.round((n??100)*1e3)))},[n]);const[T,A]=a.useState(null),[R,L]=a.useState(!1),[H,de]=a.useState(uc());a.useEffect(()=>{d()},[]),a.useEffect(()=>{if(!I)return;const te=window.setTimeout(()=>j(null),I.type==="error"?4e3:2500);return()=>window.clearTimeout(te)},[I]);const Fe=()=>{L(!0),A(null),de(uc())},fe=te=>{L(!1),A(te.id),de({name:te.name,provider:te.provider,modelId:te.modelId,apiKey:["managed","__agentroam_stored_secret__"].includes(te.apiKey)?"":te.apiKey,baseUrl:te.baseUrl,maxOutputTokens:te.maxOutputTokens??16384,requestTimeoutSeconds:te.requestTimeoutSeconds??Fi[te.provider]??300})},je=()=>{A(null),L(!1)},ze=async()=>{const te=H.provider!=="aihub",ge=T?s.find(B=>B.id===T):void 0,Qe=ge?["managed","__agentroam_stored_secret__"].includes(ge.apiKey):!1;if(!H.name.trim()||te&&!H.apiKey.trim()&&!Qe||!H.modelId.trim()){S(te?"名称、API Key 和模型 ID 为必填项":"名称和模型 ID(AI Hub 站点 ID)为必填项"),C("error");return}if(H.maxOutputTokens!==void 0&&(!Number.isInteger(H.maxOutputTokens)||H.maxOutputTokens<256||H.maxOutputTokens>131072)){S("单轮最大输出请输入 256 到 131072 之间的整数 tokens"),C("error");return}if(H.requestTimeoutSeconds!==void 0&&(!Number.isInteger(H.requestTimeoutSeconds)||H.requestTimeoutSeconds<30||H.requestTimeoutSeconds>1800)){S("单次请求超时请输入 30 到 1800 之间的整数秒"),C("error");return}try{R?g(H):T&&f(T,H),await u(),A(null),L(!1),S(null),j({message:"模型配置保存成功",type:"success"})}catch(B){j({message:B instanceof Error?B.message:"模型配置保存失败",type:"error"})}},Ge=async te=>{x(te),setTimeout(()=>u(),0)},Ke=async te=>{await y(te),S("已切换模型"),C("success"),setTimeout(()=>S(null),1500)},Ct=async()=>{S(null);const te=ym(k);if(te===null){S("最大迭代次数不能为空,请输入非负整数;0 表示无限制。"),C("error");return}const ge=Number(ee);if(!Number.isInteger(ge)||ge<1024||ge>2e6){S("上下文窗口请输入 1024 到 2000000 之间的整数 tokens,例如 8192。"),C("error");return}c("maxIterations",te),c("contextWindow",ge/1e3);try{await u(),S(null),j({message:"设置保存成功",type:"success"})}catch(Qe){j({message:Qe instanceof Error?Qe.message:"设置保存失败",type:"error"})}},it=R||T!==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:Fe,style:Em,children:"+ 添加"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.length===0&&!it&&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(te=>{const ge=te.id===i,Qe=te.id===T,B=["managed","__agentroam_stored_secret__"].includes(te.apiKey);return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${ge?"var(--accent)":"var(--border-default)"}`,background:ge?"var(--accent-dim)":"var(--bg-surface)",overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{className:"profile-row",style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px"},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",padding:"2px 7px",borderRadius:4,background:ge?"var(--accent)":"var(--bg-deep)",color:ge?"#fff":"var(--text-muted)",flexShrink:0},children:te.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:te.name||te.modelId}),e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:te.modelId})]}),ge&&e.jsx("span",{style:{fontSize:11,color:"var(--accent)",fontWeight:600,flexShrink:0},children:"● 使用中"}),e.jsxs("div",{className:"profile-row-actions",style:{display:"flex",gap:6,flexShrink:0},children:[!ge&&e.jsx("button",{onClick:()=>Ke(te.id),style:No,children:"切换"}),e.jsx("button",{onClick:()=>Qe?je():fe(te),style:No,children:Qe?"收起":"编辑"}),e.jsx("button",{onClick:()=>Ge(te.id),style:{...No,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),Qe&&e.jsx(pc,{draft:H,setDraft:de,hasStoredApiKey:B,onSave:ze,onCancel:je})]},te.id)}),R&&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(pc,{draft:H,setDraft:de,hasStoredApiKey:!1,onSave:ze,onCancel:je})]})]})]}),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.jsxs(Sr,{label:"最大迭代次数",children:[e.jsx("input",{type:"number",value:k,onChange:te=>W(te.target.value),min:0,step:1,style:Cr}),e.jsx("div",{style:{fontSize:12,opacity:.65},children:"输入 0 表示不限制迭代次数。"})]}),e.jsxs(Sr,{label:"上下文窗口(tokens,输入与输出合计)",children:[e.jsx("input",{type:"number",value:ee,onChange:te=>N(te.target.value),min:1024,max:2e6,step:1,style:Cr}),e.jsx("div",{style:{fontSize:12,opacity:.65},children:"8K 模型填 8192;不能超过模型服务实际启动的上下文大小。"})]})]})]}),e.jsxs("section",{style:{marginTop:40},children:[e.jsx("h3",{style:{fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},children:"任务完成提醒"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[["completionEnabled","任务完成通知"],["soundEnabled","播放提示音"],["notifyWhileForeground","前台运行时也通知"]].map(([te,ge])=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,color:"var(--text-primary)",fontSize:14},children:[e.jsx("input",{type:"checkbox",checked:o[te],onChange:Qe=>c("taskNotifications",{...o,[te]:Qe.target.checked})}),ge]},te))})]}),e.jsx(wm,{onNotice:(te,ge)=>j({message:te,type:ge})}),e.jsxs("div",{style:{marginTop:28,display:"flex",gap:14,alignItems:"center"},children:[e.jsx("button",{onClick:Ct,style:Wd,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?"● 已连接":"○ 未配置"})]}),v&&e.jsx("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:"var(--radius-sm)",border:E==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:E==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:E==="success"?"var(--success)":"var(--danger)",fontSize:13},children:v}),e.jsx(Dd,{message:(I==null?void 0:I.message)??null,type:(I==null?void 0:I.type)??"success"})]})}function pc({draft:t,setDraft:n,hasStoredApiKey:r,onSave:s,onCancel:i}){const o=(c,d)=>n(u=>{const g={...u,[c]:d};return c==="provider"&&!u.modelId&&(g.modelId=dc[d]??""),g});return e.jsxs("div",{style:{padding:"12px 14px 14px",display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(Sr,{label:"名称",children:e.jsx("input",{value:t.name,onChange:c=>o("name",c.target.value),placeholder:"我的 Claude",style:Cr})}),e.jsx(Sr,{label:"提供商",children:e.jsx("select",{value:t.provider,onChange:c=>{const d=c.target.value;n(u=>({...u,provider:d,modelId:dc[d]??"",requestTimeoutSeconds:Fi[d]??300}))},style:Cr,children:Cm.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})})]}),e.jsx(Sr,{label:"模型 ID",children:e.jsx("input",{value:t.modelId,onChange:c=>o("modelId",c.target.value),placeholder:t.provider==="aihub"?"deepseek":"claude-sonnet-4-6",style:Cr})}),e.jsx(Sr,{label:"单轮最大输出(tokens)",children:e.jsx("input",{type:"number",value:t.maxOutputTokens??16384,onChange:c=>n(d=>({...d,maxOutputTokens:Number(c.target.value)})),min:256,max:131072,step:1024,style:Cr})}),e.jsx(Sr,{label:"单次请求超时(秒)",children:e.jsx("input",{type:"number",value:t.requestTimeoutSeconds??Fi[t.provider]??300,onChange:c=>n(d=>({...d,requestTimeoutSeconds:Number(c.target.value)})),min:30,max:1800,step:30,style:Cr})}),t.provider==="aihub"?e.jsx("div",{style:{padding:"8px 10px",background:"rgba(96,165,250,0.08)",border:"1px solid rgba(96,165,250,0.2)",borderRadius:8,fontSize:12,lineHeight:1.6},children:"AI Hub 网页模型来源:模型 ID 填 AI Hub 站点 ID(deepseek / chatgpt / gemini / grok 或自定义站点),无需 API Key。 运行时由桌面端 AI Hub 把上下文模拟人为发送给该站点并抓取回复;支持通过受控 JSON 协议调用 Agent 工具。需要桌面 App 在线且站点已登录。"}):e.jsxs(e.Fragment,{children:[e.jsx(Sr,{label:"API 密钥",children:e.jsx("input",{type:"password",value:t.apiKey,onChange:c=>o("apiKey",c.target.value),placeholder:r?"••••••••••••":"sk-...","aria-label":r?"API 密钥(已保存)":"API 密钥",style:Cr})}),e.jsx(Sr,{label:"接口地址(可选)",children:e.jsx("input",{value:t.baseUrl,onChange:c=>o("baseUrl",c.target.value),placeholder:"https://api.anthropic.com",style:Cr})})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:2},children:[e.jsx("button",{onClick:s,style:Wd,children:"保存"}),e.jsx("button",{onClick:i,style:Rm,children:"取消"})]})]})}function Sr({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 Cr={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"},Wd={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)"},Rm={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)"},Em={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)"},No={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)"},Mm={fontSize:13,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:14},fc={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 Am({onboarding:t=!1}){const n=typeof window>"u"?void 0:window.agentApi,r=!!(n!=null&&n.desktopLiveGetStatus),[s,i]=a.useState(null),[o,c]=a.useState(!1),[d,u]=a.useState(null),[g,f]=a.useState(!0);a.useEffect(()=>{if(!(n!=null&&n.desktopLiveGetStatus)||!(n!=null&&n.onDesktopLiveStatus))return;let C=!0;n.desktopLiveSetup().then(j=>{C&&(i(j.status),f(j.supported))}).catch(()=>{});const I=n.onDesktopLiveStatus(j=>i(j));return()=>{C=!1,I()}},[n]);const x=async()=>{if(n!=null&&n.desktopLiveRecheck)try{i(await n.desktopLiveRecheck()),u(null)}catch(C){u(C instanceof Error?C.message:String(C))}};a.useEffect(()=>{if(!r||!g)return;let C=!0,I=!1;const j=async()=>{if(!I){I=!0;try{const W=await n.desktopLiveRecheck();C&&i(W)}catch{}finally{I=!1}}};window.addEventListener("focus",j);const k=s!=null&&s.enabled&&(s.permissionScreen!=="granted"||s.accessibilityTrusted!==!0)?window.setInterval(j,3e3):void 0;return()=>{C=!1,window.removeEventListener("focus",j),k&&window.clearInterval(k)}},[n,r,g,s==null?void 0:s.enabled,s==null?void 0:s.permissionScreen,s==null?void 0:s.accessibilityTrusted]);const y=async C=>{if(n){c(!0);try{i(await n.desktopLiveSetEnabled(!0)),await n.desktopLiveOpenPermission(C),u(null)}catch(I){u(I instanceof Error?I.message:String(I))}finally{c(!1)}}};if(!r)return null;const v=async()=>{if(n!=null&&n.desktopLiveSetEnabled){c(!0);try{i(await n.desktopLiveSetEnabled(!(s!=null&&s.enabled))),u(null)}catch(C){u(C instanceof Error?C.message:String(C))}finally{c(!1)}}},S=(s==null?void 0:s.permissionScreen)==="granted",E=(s==null?void 0:s.accessibilityTrusted)===!0;return e.jsxs("section",{className:"desktop-permission-settings",children:[e.jsx("h3",{style:Mm,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 v(),disabled:o||!g,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:o?"处理中…":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?"● 已连接,可从手机查看":"○ 未连接"})]}),!g&&e.jsx("p",{role:"status",children:"当前远程桌面仅支持 macOS,其他桌面功能可正常使用。"}),g&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{className:"desktop-permission-row",style:fc,children:[e.jsx("span",{children:"屏幕录制(画面采集)"}),e.jsx("span",{style:{color:S?"var(--success)":"var(--danger)",fontWeight:600},children:S?"已授权":"未授权"}),!S&&e.jsx("button",{type:"button",className:"ui-quiet-button desktop-permission-button",disabled:o,onClick:()=>void y("screen"),children:"去授权"})]}),e.jsxs("div",{className:"desktop-permission-row",style:fc,children:[e.jsx("span",{children:"辅助功能(键鼠控制)"}),e.jsx("span",{style:{color:E?"var(--success)":"var(--danger)",fontWeight:600},children:(s==null?void 0:s.accessibilityTrusted)===null?"待检测":E?"已授权":"未授权"}),!E&&e.jsx("button",{type:"button",className:"ui-quiet-button desktop-permission-button",disabled:o,onClick:()=>void y("accessibility"),children:"去授权"})]})]}),g&&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 x(),children:"重新检测"}),!S&&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 Tm({onClose:t}){const n=a.useRef(null);return a.useEffect(()=>{var r;(r=n.current)==null||r.showModal()},[]),$n.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(Am,{}),e.jsx("div",{className:"desktop-permission-footer",children:e.jsx("button",{type:"button",className:"ui-quiet-button",onClick:t,children:"关闭"})})]})}),document.body)}const _o={id:"",name:"",command:"",args:"",url:"",headersRaw:""};function Nm(){const[t,n]=a.useState([]),[r,s]=a.useState("stdio"),[i,o]=a.useState(_o),[c,d]=a.useState(!1),[u,g]=a.useState({id:!1,command:!1,url:!1}),[f,x]=a.useState({}),[y,v]=a.useState({}),[S,E]=a.useState(new Set),[C,I]=a.useState(null),[j,k]=a.useState(""),[W,ee]=a.useState(!1),N=async B=>{var Y;if(!((Y=window.agentApi)!=null&&Y.mcpProbe))return;E(ae=>new Set([...ae,B.id])),v(ae=>{const me={...ae};return delete me[B.id],me});const G=new Promise((ae,me)=>setTimeout(()=>me(new Error("连接超时(15s)")),15e3));try{const ae=await Promise.race([window.agentApi.mcpProbe(B),G]);x(me=>({...me,[B.id]:ae}))}catch(ae){const me=ae instanceof Error?ae.message:String(ae);console.warn(`[MCP] probe failed for ${B.id}:`,me),x(le=>{const Se={...le};return delete Se[B.id],Se}),v(le=>({...le,[B.id]:me})),(B.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(me))&&(k(""),I({server:B}))}finally{E(ae=>{const me=new Set(ae);return me.delete(B.id),me})}};a.useEffect(()=>{window.agentApi&&window.agentApi.mcpList().then(B=>{n(B),B.filter(G=>G.enabled!==!1).forEach(G=>N(G))}).catch(console.error)},[]);const[T,A]=a.useState(""),[R,L]=a.useState(""),[H,de]=a.useState(!1),Fe=async()=>{L("");let B;try{B=JSON.parse(T.trim());const G=B.mcpServers??B,Y=Object.entries(G);if(Y.length===0){L("未找到任何服务器");return}de(!0);const ae=[];for(const[le,Se]of Y){const Te=Se,mt=Te.name||le,yt=Te.disabled!==!0;let st;if(Te.url||Te.type==="streamableHttp"||Te.type==="sse"){const tt=Te.type==="sse"?"sse":"streamableHttp";st={id:le,name:mt,transport:tt,url:Te.url,headers:Te.headers??{},env:Te.env??{},enabled:yt}}else st={id:le,name:mt,transport:"stdio",command:Te.command,args:Te.args??[],env:Te.env??{},enabled:yt};await window.agentApi.mcpSave(st),ae.push(st)}const me=await window.agentApi.mcpList();n(me),A(""),ae.filter(le=>le.enabled!==!1).forEach(le=>N(le))}catch(G){L(G instanceof Error?G.message:"JSON 解析失败")}finally{de(!1)}},fe=()=>i.id.trim()!==""&&i.command.trim()!=="",je=()=>i.id.trim()!==""&&i.url.trim()!=="",ze=B=>{const G={};for(const Y of B.split(`
463
- `)){const ae=Y.indexOf(":");if(ae<1)continue;const me=Y.slice(0,ae).trim(),le=Y.slice(ae+1).trim();me&&(G[me]=le)}return G},Ge=async()=>{if(g({id:!0,command:!0,url:!0}),!(r==="stdio"&&!fe())&&!((r==="sse"||r==="streamableHttp")&&!je())){d(!0);try{const B=r==="sse"||r==="streamableHttp"?ze(i.headersRaw):{},G=r==="stdio"?{id:i.id,name:i.name||i.id,transport:"stdio",command:i.command,args:i.args.split(" ").filter(Boolean),enabled:!0}:{id:i.id,name:i.name||i.id,transport:r,url:i.url,headers:B,enabled:!0};await window.agentApi.mcpSave(G);const Y=await window.agentApi.mcpList();n(Y),o(_o),g({id:!1,command:!1,url:!1}),N(G)}catch(B){console.error("Failed to save MCP server",B)}finally{d(!1)}}},Ke=async B=>{await window.agentApi.mcpDelete(B),n(t.filter(G=>G.id!==B))},Ct=async(B,G)=>{await window.agentApi.mcpSetEnabled(B,G),n(t.map(Y=>Y.id===B?{...Y,enabled:G}:Y))},it=async()=>{if(!(!C||!j.trim())){ee(!0);try{const B=C.server.transport==="streamableHttp"?{...C.server,headers:{...C.server.headers??{},Authorization:`Bearer ${j.trim()}`}}:{...C.server,env:{...C.server.env??{},Authorization:`Bearer ${j.trim()}`}};await window.agentApi.mcpSave(B);const G=await window.agentApi.mcpList();n(G),I(null),k("");const Y=G.find(ae=>ae.id===B.id)??B;N(Y)}finally{ee(!1)}}},te=B=>B==="stdio"?"本地":B==="streamableHttp"?"HTTP":"SSE",ge=B=>B==="stdio"?"#68d391":B==="streamableHttp"?"#f6ad55":"#63b3ed",Qe=B=>B==="stdio"?"rgba(154,230,180,0.15)":B==="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(B=>e.jsx("button",{onClick:()=>{s(B),g({id:!1,command:!1,url:!1}),o(G=>({..._o,id:G.id,name:G.name}))},style:{padding:"5px 14px",border:"none",fontSize:12,fontWeight:500,cursor:"pointer",fontFamily:"var(--font-body)",transition:"background 0.15s",background:r===B?"var(--accent)":"transparent",color:r===B?"var(--text-inverse)":"var(--text-muted)"},children:B==="stdio"?"本地 stdio":B==="sse"?"远程 SSE":"HTTP"},B))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.id,onChange:B=>o(G=>({...G,id:B.target.value})),onBlur:()=>g(B=>({...B,id:!0})),placeholder:"服务器 ID *",style:{...Br,...u.id&&!i.id?zo:{}}}),u.id&&!i.id&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.name,onChange:B=>o(G=>({...G,name:B.target.value})),placeholder:"显示名称",style:{...Br,flex:1}})]}),r==="stdio"?e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.command,onChange:B=>o(G=>({...G,command:B.target.value})),onBlur:()=>g(B=>({...B,command:!0})),placeholder:"命令(如 npx)*",style:{...Br,...u.command&&!i.command?zo:{}}}),u.command&&!i.command&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsx("input",{value:i.args,onChange:B=>o(G=>({...G,args:B.target.value})),placeholder:"参数(如 -y @anthropic/mcp-server)",style:{...Br,flex:2}})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("input",{value:i.url,onChange:B=>o(G=>({...G,url:B.target.value})),onBlur:()=>g(B=>({...B,url:!0})),placeholder:r==="streamableHttp"?"HTTP URL(如 http://host/mcp)*":"SSE URL(如 https://mcp.example.com/sse)*",style:{...Br,...u.url&&!i.url?zo:{}}}),u.url&&!i.url&&e.jsx("span",{style:{fontSize:11,color:"var(--danger)"},children:"必填"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx("label",{style:{fontSize:12,color:"var(--text-muted)"},children:"请求头(每行 key: value)"}),e.jsx("textarea",{value:i.headersRaw,onChange:B=>o(G=>({...G,headersRaw:B.target.value})),placeholder:`access_token: abc123
464
- Authorization: Bearer sk-...`,rows:3,style:{...Br,fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical"}})]})]}),e.jsx("button",{onClick:Ge,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:B=>{A(B.target.value),L("")},placeholder:`{
465
- "my-server": {
466
- "command": "npx",
467
- "args": ["-y", "some-mcp"]
468
- }
469
- }`,rows:5,style:{...Br,width:"100%",boxSizing:"border-box",fontFamily:"var(--font-mono)",fontSize:12,resize:"vertical",marginBottom:8}}),R&&e.jsx("div",{style:{fontSize:12,color:"var(--danger)",marginBottom:8},children:R}),e.jsx("button",{onClick:Fe,disabled:!T.trim()||H,style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:T.trim()&&!H?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:T.trim()&&!H?1:.5},children:H?"导入中…":"导入"})]}),t.filter(B=>B.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(B=>B.transport===r).map(B=>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:B.name||B.id}),e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:Qe(B.transport),color:ge(B.transport),fontWeight:600},children:te(B.transport)})]}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:2,fontFamily:"var(--font-mono)"},children:[B.transport==="stdio"?`${B.command} ${(B.args??[]).join(" ")}`:B.url,B.transport!=="stdio"&&B.headers&&Object.keys(B.headers).length>0&&e.jsxs("span",{style:{marginLeft:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-body)"},children:["· ",Object.keys(B.headers).length," 个请求头"]})]}),S.has(B.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"}}),"探测工具中…"]}):y[B.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:y[B.id]}),B.transport==="sse"||/401|403|unauthorized|forbidden|需要认证|访问被拒绝/i.test(y[B.id])?e.jsx("button",{onClick:()=>{k(""),I({server:B})},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:()=>N(B),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:"重试"})]}):f[B.id]&&f[B.id].length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:6},children:f[B.id].map(G=>e.jsx("span",{title:G.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:G.name},G.name))}):f[B.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:B.enabled!==!1,onChange:G=>Ct(B.id,G.target.checked),style:{cursor:"pointer"}}),"启用"]}),e.jsx("button",{onClick:()=>Ke(B.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:G=>{G.currentTarget.style.background="rgba(248,113,113,0.1)"},onMouseLeave:G=>{G.currentTarget.style.background="transparent"},children:"移除"})]})]},B.id))}),C&&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:B=>{B.target===B.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:C.server.name||C.server.id})," 返回了 401/403,请输入访问令牌(Bearer Token)。"]}),e.jsx("input",{autoFocus:!0,type:"password",value:j,onChange:B=>k(B.target.value),onKeyDown:B=>{B.key==="Enter"&&it(),B.key==="Escape"&&I(null)},placeholder:"sk-… 或 Bearer token",style:{...Br,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:it,disabled:!j.trim()||W,style:{padding:"8px 18px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"var(--text-inverse)",fontSize:13,fontWeight:600,cursor:j.trim()&&!W?"pointer":"not-allowed",fontFamily:"var(--font-body)",opacity:j.trim()&&!W?1:.5},children:W?"保存中…":"保存并重试"})]})]})}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}const Br={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)"},zo={border:"1px solid var(--danger)",boxShadow:"0 0 0 2px rgba(248,113,113,0.15)"};function _m(){const[t,n]=a.useState([]),[r,s]=a.useState(""),[i,o]=a.useState(null),[c,d]=a.useState(!1),[u,g]=a.useState(""),[f,x]=a.useState(""),[y,v]=a.useState("user"),[S,E]=a.useState(""),[C,I]=a.useState(null),[j,k]=a.useState("success"),W=async()=>{if(window.agentApi){const A=await window.agentApi.listMemories();n(A)}};a.useEffect(()=>{W()},[]);const ee=async()=>{if(!r.trim()){W();return}if(window.agentApi){const A=await window.agentApi.searchMemories(r);n(A.map(R=>R.entry))}},N=async()=>{if(!(!u.trim()||!window.agentApi))try{await window.agentApi.setMemory({name:u.trim(),description:f,type:y,content:S,created:(i==null?void 0:i.created)??new Date().toISOString(),updated:new Date().toISOString()}),d(!1),o(null),g(""),x(""),E(""),v("user"),I("保存成功"),k("success"),await W()}catch(A){I(A instanceof Error?A.message:"保存失败"),k("error")}},T=A=>{o(A),g(A.name),x(A.description),v(A.type),E(A.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),o(null),g(""),x(""),E(""),v("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:A=>s(A.target.value),onKeyDown:A=>A.key==="Enter"&&ee(),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:ee,style:hc,children:"搜索"})]}),C&&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:C}),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:A=>g(A.target.value),placeholder:"名称",style:{...Ei,marginBottom:10},disabled:!!i}),e.jsx("input",{value:f,onChange:A=>x(A.target.value),placeholder:"描述",style:{...Ei,marginBottom:10}}),e.jsxs("select",{value:y,onChange:A=>v(A.target.value),style:{...Ei,marginBottom:10},children:[e.jsx("option",{value:"user",children:"用户"}),e.jsx("option",{value:"feedback",children:"反馈"}),e.jsx("option",{value:"project",children:"项目"}),e.jsx("option",{value:"reference",children:"参考"})]}),e.jsx("textarea",{value:S,onChange:A=>E(A.target.value),placeholder:"内容",rows:5,style:{...Ei,marginBottom:12,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:N,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:hc,children:"取消"})]})]}),t.map(A=>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:A.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:A.type})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>T(A),style:gc,children:"编辑"}),e.jsx("button",{onClick:async()=>{if(window.agentApi)try{await window.agentApi.deleteMemory(A.name),I("删除成功"),k("success"),await W()}catch(R){I(R instanceof Error?R.message:"删除失败"),k("error")}},style:{...gc,color:"var(--danger)"},children:"删除"})]})]}),A.description&&e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:4},children:A.description}),e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:[A.content.slice(0,180),A.content.length>180?"…":""]})]},A.name)),t.length===0&&!c&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:14,padding:"60px 0",textAlign:"center"},children:"暂无记忆,点击「新建」创建一条。"})]})}const Ei={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"},hc={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)"},gc={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},zm=()=>({name:"",description:"",triggers:[],prompt:"",filePath:"",enabled:!0});function Lm(){const[t,n]=a.useState([]),[r,s]=a.useState(null),[i,o]=a.useState(!1),[c,d]=a.useState(null),[u,g]=a.useState("success"),[f,x]=a.useState(""),y=(T,A="success")=>{d(T),g(A),setTimeout(()=>d(null),3e3)},v=async()=>{if(!window.agentApi)return;const T=await window.agentApi.listSkills();n(T)};a.useEffect(()=>{v()},[]);const S=T=>{s({...T}),x((T.triggers??[]).join(", ")),o(!1)},E=()=>{s(zm()),x(""),o(!0)},C=()=>{s(null),o(!1)},I=async()=>{if(!r||!window.agentApi)return;if(!r.name.trim()){y("名称不能为空","error");return}const T=f.split(",").map(A=>A.trim()).filter(Boolean);try{await window.agentApi.saveSkill({name:r.name.trim(),description:r.description,triggers:T,prompt:r.prompt,filePath:r.filePath??""}),y(i?"技能已创建":"技能已保存"),s(null),await v()}catch(A){y(A instanceof Error?A.message:"保存失败","error")}},j=async T=>{if(window.agentApi)try{await window.agentApi.deleteSkill(T),y("已删除"),(r==null?void 0:r.name)===T&&s(null),await v()}catch(A){y(A instanceof Error?A.message:"删除失败","error")}},k=async T=>{if(!window.agentApi)return;const A=!T.enabled;await window.agentApi.setSkillEnabled(T.name,A),await v()},W=async()=>{if(window.agentApi)try{const T=await window.agentApi.importSkill();if(!T)return;y(`已导入技能「${T.name}」,本次会话立即生效`),await v()}catch(T){y(T instanceof Error?T.message:"导入失败","error")}},ee={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"},N={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:W,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:E,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:i?"新建技能":`编辑:${r.name}`}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:N,children:"名称"}),e.jsx("input",{style:ee,value:r.name,disabled:!i,onChange:T=>s({...r,name:T.target.value}),placeholder:"技能唯一标识,如 code-review"})]}),e.jsxs("div",{children:[e.jsx("label",{style:N,children:"描述"}),e.jsx("input",{style:ee,value:r.description,onChange:T=>s({...r,description:T.target.value}),placeholder:"简短说明这个技能的用途"})]}),e.jsxs("div",{children:[e.jsx("label",{style:N,children:"触发词(逗号分隔)"}),e.jsx("input",{style:ee,value:f,onChange:T=>x(T.target.value),placeholder:"代码审查, review, 审查代码"})]}),e.jsxs("div",{children:[e.jsx("label",{style:N,children:"提示词"}),e.jsx("textarea",{style:{...ee,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:C,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 A;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:()=>k(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}),((A=T.triggers)==null?void 0:A.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:()=>S(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 Mi=[{name:"read_file",label:"读取文件"},{name:"write_file",label:"写入文件"},{name:"bash",label:"执行命令"},{name:"web_fetch",label:"网页抓取"},{name:"web_search",label:"网络搜索"},{name:"grep",label:"文件搜索"}];function Bd(){return{profileId:"",enabledTools:[],enabledSkills:[],enabledMCPServers:[]}}function Pm(){return{name:"",description:"",systemPrompt:"",contextPlaceholders:[],capabilities:Bd(),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"},ii={padding:"3px 9px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-muted)",fontSize:11,cursor:"pointer"},Or={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"},Fr={fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:5,display:"block"};function Dm({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:Or,placeholder:"变量名 (e.g. project)",value:t.key,onChange:s=>n({...t,key:s.target.value})}),e.jsx("input",{style:Or,placeholder:"说明",value:t.description,onChange:s=>n({...t,description:s.target.value})}),e.jsx("input",{style:Or,placeholder:"默认值",value:t.defaultValue,onChange:s=>n({...t,defaultValue:s.target.value})}),e.jsx("button",{onClick:r,style:{...ii,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)",flexShrink:0},children:"✕"})]})}function mc({initial:t,activeAgentId:n,onSave:r,onCancel:s}){const{profiles:i}=Ui(),[o,c]=a.useState([]),[d,u]=a.useState([]),[g,f]=a.useState({...Pm(),...t,capabilities:{...Bd(),...t.capabilities??{}}}),[x,y]=a.useState(null),[v,S]=a.useState(!1);a.useEffect(()=>{var R,L;window.agentApi&&(window.agentApi.listSkills().then(H=>{c(H.filter(de=>de.name))}),(L=(R=window.agentApi).listMCPServers)==null||L.call(R).then(H=>{u(H??[])}).catch(()=>{}))},[]);const E=R=>f(L=>({...L,capabilities:{...L.capabilities,...R}})),C=R=>{const L=g.capabilities.enabledTools;if(L.length===0){const H=Mi.map(de=>de.name).filter(de=>de!==R);E({enabledTools:H})}else if(L.includes(R)){const H=L.filter(de=>de!==R);E({enabledTools:H})}else{const H=[...L,R];H.length===Mi.length?E({enabledTools:[]}):E({enabledTools:H})}},I=R=>{const L=g.capabilities.enabledSkills;E({enabledSkills:L.includes(R)?L.filter(H=>H!==R):[...L,R]})},j=R=>{const L=g.capabilities.enabledMCPServers;E({enabledMCPServers:L.includes(R)?L.filter(H=>H!==R):[...L,R]})},k=()=>f(R=>({...R,contextPlaceholders:[...R.contextPlaceholders,{key:"",description:"",defaultValue:""}]})),W=(R,L)=>f(H=>{const de=[...H.contextPlaceholders];return de[R]=L,{...H,contextPlaceholders:de}}),ee=R=>f(L=>({...L,contextPlaceholders:L.contextPlaceholders.filter((H,de)=>de!==R)})),N=async()=>{if(!g.name.trim()){y("名称为必填项");return}S(!0);try{await r(g)}catch(R){y(R instanceof Error?R.message:"保存失败")}finally{S(!1)}},T=R=>g.capabilities.enabledTools.length===0||g.capabilities.enabledTools.includes(R),A={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:[x&&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:x}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:Fr,children:"名称 *"}),e.jsx("input",{style:Or,value:g.name,onChange:R=>f(L=>({...L,name:R.target.value})),placeholder:"智能体名称"})]}),e.jsxs("div",{children:[e.jsx("label",{style:Fr,children:"描述"}),e.jsx("input",{style:Or,value:g.description,onChange:R=>f(L=>({...L,description:R.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:{...Fr,marginBottom:0},children:"角色设定 / 工作指令"}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-muted)",opacity:.6},children:["支持 ","{{变量名}}"," 占位符"]})]}),e.jsx("textarea",{value:g.systemPrompt,onChange:R=>f(L=>({...L,systemPrompt:R.target.value})),placeholder:`你是一名专业的代码审查助手,请用中文回复所有问题。
470
-
471
- 当前项目:{{project_name}}`,rows:6,style:{...Or,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.6}})]}),e.jsx("p",{style:A,children:"上下文占位符"}),g.contextPlaceholders.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:8},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.5fr 1fr auto",gap:6},children:["变量名","说明","默认值",""].map(R=>e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",letterSpacing:"0.05em"},children:R},R))}),g.contextPlaceholders.map((R,L)=>e.jsx(Dm,{ph:R,onChange:H=>W(L,H),onDelete:()=>ee(L)},L))]}),e.jsx("button",{onClick:k,style:{...ii,color:"var(--accent)",borderColor:"rgba(79,110,247,0.25)"},children:"+ 添加占位符"}),e.jsx("p",{style:A,children:"能力配置"}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("label",{style:Fr,children:"模型"}),e.jsxs("select",{value:g.capabilities.profileId,onChange:R=>E({profileId:R.target.value}),style:{...Or,cursor:"pointer"},children:[e.jsx("option",{value:"",children:"使用全局活跃模型"}),i.map(R=>e.jsxs("option",{value:R.id,children:[R.name||R.modelId," (",R.provider,")"]},R.id))]})]}),e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Fr,children:["内置工具 ",g.capabilities.enabledTools.length===0?"(全部启用)":`(${g.capabilities.enabledTools.length}/${Mi.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Mi.map(R=>{const L=T(R.name);return e.jsx("button",{onClick:()=>C(R.name),style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:R.label},R.name)})}),e.jsx("p",{style:{fontSize:11,color:"var(--text-muted)",marginTop:5,opacity:.7},children:'点击切换;全选时恢复为"全部启用"'})]}),o.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Fr,children:["技能 ",g.capabilities.enabledSkills.length===0?"(全部)":`(${g.capabilities.enabledSkills.length}/${o.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:o.map(R=>{const L=g.capabilities.enabledSkills.length===0||g.capabilities.enabledSkills.includes(R.name);return e.jsx("button",{onClick:()=>I(R.name),title:R.description,style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:R.name},R.name)})})]}),d.length>0&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("label",{style:Fr,children:["MCP 服务器 ",g.capabilities.enabledMCPServers.length===0?"(全部)":`(${g.capabilities.enabledMCPServers.length}/${d.length})`]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:d.map(R=>{const L=g.capabilities.enabledMCPServers.length===0||g.capabilities.enabledMCPServers.includes(R.id);return e.jsx("button",{onClick:()=>j(R.id),style:{padding:"4px 10px",borderRadius:20,border:L?"1px solid var(--accent)":"1px solid var(--border-subtle)",background:L?"var(--accent-dim)":"transparent",color:L?"var(--accent)":"var(--text-muted)",fontSize:12,cursor:"pointer",transition:"all 0.12s"},children:R.name},R.id)})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:Fr,children:"最大迭代次数(0 = 全局)"}),e.jsx("input",{type:"number",style:Or,value:g.maxIterations,min:0,max:100,onChange:R=>f(L=>({...L,maxIterations:Number(R.target.value)}))})]}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",paddingBottom:2},children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:"var(--text-secondary)"},children:[e.jsx("input",{type:"checkbox",checked:g.isDefault,onChange:R=>f(L=>({...L,isDefault:R.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:N,disabled:v,style:{...Yo,background:"var(--accent)",color:"#fff",border:"none",fontWeight:600,opacity:v?.6:1},children:v?"保存中…":"保存"}),e.jsx("button",{onClick:s,style:Yo,children:"取消"})]})]})}function Wm(){const[t,n]=a.useState([]),[r,s]=a.useState([]),[i,o]=a.useState(null),[c,d]=a.useState(!1),[u,g]=a.useState(null),[f,x]=a.useState("success"),y=(j,k="success")=>{g(j),x(k),setTimeout(()=>g(null),2e3)},v=async()=>{if(!window.agentApi)return;const j=await window.agentApi.listAgentDefs();n(j);const k=await window.agentApi.getSettings();s(k.activeAgentIds??[])};a.useEffect(()=>{v()},[]);const S=async j=>{await window.agentApi.createAgentDef(j),d(!1),y("智能体已创建"),await v()},E=async(j,k)=>{await window.agentApi.updateAgentDef(j,k),o(null),y("保存成功"),await v()},C=async j=>{await window.agentApi.deleteAgentDef(j),i===j&&o(null),y("已删除"),await v()},I=async j=>{const W=(await window.agentApi.setActiveAgentDef(j)).activeAgentIds??[];s(W),y(W.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:f==="success"?"1px solid rgba(52,211,153,0.35)":"1px solid rgba(244,63,94,0.35)",background:f==="success"?"rgba(52,211,153,0.08)":"rgba(244,63,94,0.08)",color:f==="success"?"var(--success)":"var(--danger)",fontSize:13},children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:14},children:e.jsx("button",{onClick:()=>{d(!0),o(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(mc,{initial:{},activeAgentId:r[0]??"",onSave:S,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 k=r.includes(j.id),W=j.id===i;return e.jsxs("div",{style:{borderRadius:"var(--radius-sm)",border:`1px solid ${k?"var(--accent)":"var(--border-default)"}`,background:k?"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:k?"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:k?"#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}),k&&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:{...ii,color:k?"var(--accent)":"var(--text-muted)",borderColor:k?"var(--accent)":"var(--border-default)",background:k?"var(--accent-dim)":"transparent"},children:k?"取消激活":"激活"}),e.jsx("button",{onClick:()=>o(W?null:j.id),style:ii,children:W?"收起":"编辑"}),e.jsx("button",{onClick:()=>C(j.id),style:{...ii,color:"var(--danger)",borderColor:"rgba(244,63,94,0.25)"},children:"删除"})]})]}),W&&e.jsx(mc,{initial:j,activeAgentId:r[0]??"",onSave:ee=>E(j.id,ee),onCancel:()=>o(null)})]},j.id)})]})]})}const Bm=[{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"}],Lo={id:"",name:"",language:"",fileTypes:"",command:"",args:"",envRaw:""};function Fm(){const[t,n]=a.useState([]),[r,s]=a.useState(Lo),[i,o]=a.useState(!1),[c,d]=a.useState(null),[u,g]=a.useState(null),f=async()=>{var j;if((j=window.agentApi)!=null&&j.lspList)try{const k=await window.agentApi.lspList();n(k)}catch(k){console.error("[LSP] load error",k)}};a.useEffect(()=>{f()},[]);const x=j=>{s(k=>({...k,name:j.label,language:j.language,fileTypes:j.fileTypes,command:j.command,args:j.args}))},y=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(([k,W])=>`${k}=${W}`).join(`
472
- `):""}),g(null)},v=()=>{d(null),s(Lo)},S=async()=>{var N;if(!((N=window.agentApi)!=null&&N.lspSave))return;const j=r.name.trim(),k=r.command.trim();if(!j||!k)return;let W;if(r.envRaw.trim()){W={};for(const T of r.envRaw.split(`
473
- `)){const A=T.indexOf("=");A>0&&(W[T.slice(0,A).trim()]=T.slice(A+1).trim())}}const ee={id:c??crypto.randomUUID(),name:j,language:r.language.trim(),fileTypes:r.fileTypes.split(",").map(T=>T.trim()).filter(Boolean),command:k,args:r.args.trim()?r.args.trim().split(/\s+/):[],env:W,enabled:!0};o(!0);try{await window.agentApi.lspSave(ee),await f(),v()}finally{o(!1)}},E=async j=>{var k;(k=window.agentApi)!=null&&k.lspDelete&&confirm("删除此 LSP 服务器配置?")&&(await window.agentApi.lspDelete(j),await f())},C=async j=>{var k;(k=window.agentApi)!=null&&k.lspSetEnabled&&(await window.agentApi.lspSetEnabled(j.id,!j.enabled),await f())},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(Lo)},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:()=>g(u===j.id?null:j.id),children:[e.jsx("div",{onClick:k=>{k.stopPropagation(),C(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:k=>{k.stopPropagation(),y(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:k=>{k.stopPropagation(),E(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(([k,W])=>`${k}=${W}`).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:rs,children:"快速预设"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:Bm.map(j=>e.jsx("button",{onClick:()=>x(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:rs,children:["名称 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.name,onChange:j=>s(k=>({...k,name:j.target.value})),placeholder:"TypeScript Language Server",style:Ms})]}),e.jsxs("div",{children:[e.jsx("label",{style:rs,children:"语言"}),e.jsx("input",{value:r.language,onChange:j=>s(k=>({...k,language:j.target.value})),placeholder:"typescript",style:Ms})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rs,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(k=>({...k,fileTypes:j.target.value})),placeholder:".ts,.tsx,.js,.jsx",style:Ms})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{children:[e.jsxs("label",{style:rs,children:["命令 ",e.jsx("span",{style:{color:"var(--danger, #f43f5e)",textTransform:"none"},children:"*"})]}),e.jsx("input",{value:r.command,onChange:j=>s(k=>({...k,command:j.target.value})),placeholder:"typescript-language-server",style:{...Ms,fontFamily:"var(--font-mono, monospace)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rs,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(k=>({...k,args:j.target.value})),placeholder:"--stdio",style:{...Ms,fontFamily:"var(--font-mono, monospace)"}})]})]}),e.jsxs("div",{children:[e.jsxs("label",{style:rs,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(k=>({...k,envRaw:j.target.value})),placeholder:`NODE_ENV=production
474
- TSPROTOCOL_LOG=verbose`,rows:3,style:{...Ms,fontFamily:"var(--font-mono, monospace)",resize:"vertical"}})]}),r.language==="java"&&e.jsxs("div",{style:{background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.3)",borderRadius:"var(--radius-sm)",padding:"10px 14px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.65},children:[e.jsx("strong",{style:{color:"rgba(202,138,4,1)"},children:"Java 提示:"})," ","使用 ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"jdtls"})," 预设需先通过"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"brew install jdtls"})," ","安装包装脚本。若手动安装,请将命令改为"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"java"}),", 并在参数中填入完整的 JVM 参数和"," ",e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",background:"var(--bg-deep)",padding:"1px 5px",borderRadius:3},children:"-jar .../launcher.jar -data /path/to/workspace"}),"。"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{onClick:()=>void S(),disabled:i||!r.name.trim()||!r.command.trim(),style:{padding:"8px 20px",borderRadius:"var(--radius-sm)",border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",opacity:i||!r.name.trim()||!r.command.trim()?.45:1,fontFamily:"var(--font-body)"},children:i?"保存中…":"保存"}),e.jsx("button",{onClick:v,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 Ms={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"},rs={fontSize:11,color:"var(--text-muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4,display:"block"};function Om({trigger:t,heardText:n}){const[r,s]=a.useState(!1);return a.useEffect(()=>{if(t<=0)return;s(!0);const i=setTimeout(()=>s(!1),2400);return()=>clearTimeout(i)},[t]),r?$n.createPortal(e.jsxs("div",{style:{position:"fixed",inset:0,zIndex:3e4,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:22,background:"radial-gradient(circle at 50% 50%, var(--accent-glow), transparent 60%)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",animation:"fadeIn 0.3s var(--ease-out)",pointerEvents:"none",WebkitAppRegion:"no-drag"},children:[e.jsxs("div",{style:{position:"relative",width:120,height:120},children:[[0,.45,.9].map(i=>e.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",border:"2px solid var(--accent)",animation:`wakeRing 1.6s ${i}s var(--ease-out) infinite`}},i)),e.jsx("div",{style:{position:"absolute",inset:30,borderRadius:"50%",background:"var(--accent)",display:"flex",alignItems:"center",justifyContent:"center",animation:"wakeCore 1.6s var(--ease-out) infinite"},children:e.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-inverse)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})]}),e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",letterSpacing:"0.12em",animation:"wakeText 0.9s var(--ease-out) both",fontFamily:"var(--font-display)"},children:"已唤醒 · 随时待命"}),n&&e.jsxs("div",{style:{fontSize:12,color:"var(--text-muted)",maxWidth:320,textAlign:"center",animation:"fadeIn 0.6s var(--ease-out) 0.3s both"},children:["“",n.slice(0,40),"”"]})]},t),document.body):null}const $m=[{agentType:"customer-agent",label:"Customer Agent"},{agentType:"codex",label:"Codex"},{agentType:"claude-code",label:"Claude Code"},{agentType:"opencode",label:"OpenCode"}];function Um({value:t,health:n,onChange:r}){return e.jsx("div",{className:"agent-workspace-switcher",role:"tablist","aria-label":"切换 Agent",children:$m.map(s=>{const i=n.find(c=>c.agentType===s.agentType),o=(i==null?void 0:i.available)===!1;return e.jsxs("button",{type:"button",role:"tab","aria-selected":t===s.agentType,"aria-label":s.label,title:o?`${s.label} 不可用:${(i==null?void 0:i.error)??"未检测到运行时"}`:s.label,className:t===s.agentType?"is-active":"",onClick:()=>r(s.agentType),children:[e.jsx(ia,{agentType:s.agentType,size:22}),e.jsx("i",{className:o?"is-unavailable":"","aria-hidden":"true"})]},s.agentType)})})}function Hm({onOpenFlowStudio:t,openingFlowStudio:n=!1}){return e.jsx("div",{className:"desktop-app-actions",role:"toolbar","aria-label":"应用快捷操作",children:e.jsx("button",{type:"button",className:"ui-icon-button desktop-app-action desktop-app-action--flow-studio",onClick:t,disabled:n,title:"数字人 · Flow Studio","aria-label":"打开 Flow Studio","aria-busy":n,children:n?e.jsx(lt,{className:"desktop-app-action-spinner",size:17,"aria-hidden":"true"}):e.jsx(Wu,{size:17,"aria-hidden":"true"})})})}function qm({entryUrl:t,onBack:n}){const r=typeof window<"u"?window.agentApi:void 0,s=typeof(r==null?void 0:r.flowStudioOpen)=="function",i=a.useRef(null),o=a.useRef(null),[c,d]=a.useState("loading"),u=a.useCallback(()=>{o.current&&(r==null||r.flowStudioSetBounds(o.current))},[r]),g=a.useCallback(async()=>{if(!s||!r){d("error");return}if(d("loading"),!(await r.flowStudioOpen(t).catch(()=>({ok:!1}))).ok){d("error");return}u()},[r,s,t,u]);return a.useEffect(()=>{if(!s||!r){d("error");return}const f=r.onFlowStudioEvent(x=>{x.siteId==="flow-studio"&&(x.type==="loading"&&d("loading"),x.type==="loaded"&&(d("ready"),u()),x.type==="load-failed"&&d("error"))});return g(),()=>{f(),r.flowStudioSetBounds(null)}},[r,s,g,u]),a.useEffect(()=>{if(!s||!r)return;const f=i.current;if(!f)return;let x=0;const y=()=>{const S=f.getBoundingClientRect(),E={x:S.x,y:S.y,width:S.width,height:S.height};o.current=E,r.flowStudioSetBounds(E)},v=new ResizeObserver(()=>{cancelAnimationFrame(x),x=requestAnimationFrame(y)});return v.observe(f),y(),()=>{v.disconnect(),cancelAnimationFrame(x)}},[r,s]),e.jsxs("section",{className:"desktop-flow-studio-view","aria-label":"Flow Studio","aria-busy":c==="loading",children:[e.jsx("header",{className:"desktop-flow-studio-topbar",children:e.jsx("button",{type:"button",className:"desktop-flow-studio-back ui-icon-button",onClick:n,title:"返回 AgentRoam","aria-label":"返回 AgentRoam",children:e.jsx(Zo,{size:18,"aria-hidden":"true"})})}),e.jsx("div",{ref:i,className:"desktop-flow-studio-content",children:c!=="ready"&&e.jsxs("div",{className:"desktop-flow-studio-status",role:c==="error"?"alert":"status","aria-live":"polite",children:[c==="loading"?e.jsx(lt,{className:"desktop-flow-studio-spinner",size:20,"aria-hidden":"true"}):null,e.jsx("strong",{children:c==="error"?"无法打开 Flow Studio":"正在打开 Flow Studio"}),c==="error"&&e.jsxs("button",{type:"button",className:"desktop-flow-studio-retry",onClick:()=>void g(),children:[e.jsx(cp,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"重试"})]})]})})]})}const Po=264,xc=126;function Vm(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-Po,n-Po-8)),i=t.top+t.height+7,o=i+xc<=r-8?i:Math.max(8,t.top-xc-7);return{left:s,top:o,width:Po}}function bc({title:t,message:n,anchor:r,mobile:s,pending:i,onCancel:o,onConfirm:c}){const d=u=>u.stopPropagation();return e.jsx("div",{className:`sidebar-delete-confirmation-layer${s?" is-mobile":""}`,onClick:i?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:s?void 0:Vm(r),onClick:d,children:[e.jsx("strong",{id:"sidebar-delete-confirmation-title",children:t??"删除会话"}),e.jsx("p",{id:"sidebar-delete-confirmation-message",children:n}),e.jsxs("div",{className:"sidebar-delete-confirmation-actions",children:[e.jsx("button",{type:"button",onClick:o,disabled:i,children:"取消"}),e.jsx("button",{type:"button",className:"is-danger",onClick:c,disabled:i,children:i?"正在删除...":"删除"})]})]})})}function Do({session:t,deleteLabel:n="删除会话",onSelect:r,onPin:s,onDelete:i}){var o,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}),((o=t.compatibility)==null?void 0:o.status)==="checking"&&e.jsx("span",{className:"sidebar-session-compatibility",title:`正在验证 Codex ${t.compatibility.producerVersion??"未知版本"} 会话兼容性`,"aria-label":"正在验证会话兼容性",children:e.jsx(lt,{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(zc,{size:13,"aria-hidden":"true"})}),t.occupiedExternally&&e.jsx("span",{className:"sidebar-session-lock",title:"原客户端正在使用,只读","aria-label":"原客户端正在使用,只读",children:e.jsx(Xu,{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(ap,{size:14,"aria-hidden":"true"})}),t.canDelete&&i&&e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation();const u=d.currentTarget.getBoundingClientRect();i({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(Ts,{size:14,"aria-hidden":"true"})})]})}const Gm=[["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"])]],Km=new Map([["dockerfile","code"],["makefile","code"],["gemfile","code"],["rakefile","code"],["license","text"]]);function Fd(t){var i;const n=t.toLocaleLowerCase(),r=Km.get(n);if(r)return r;if(n.startsWith(".env")||n===".gitignore"||n===".npmrc")return"text";const s=n.includes(".")&&n.split(".").pop()||"";return((i=Gm.find(([,o])=>o.has(s)))==null?void 0:i[0])??"file"}const Qm={folder:{icon:Oo,label:"文件夹"},code:{icon:Wc,label:"代码文件"},style:{icon:qc,label:"样式文件"},image:{icon:Bc,label:"图片文件"},video:{icon:$c,label:"视频文件"},audio:{icon:Dc,label:"音频文件"},markdown:{icon:Hc,label:"Markdown 文件"},text:{icon:ai,label:"文本文件"},json:{icon:Fc,label:"JSON 文件"},archive:{icon:Pc,label:"压缩文件"},spreadsheet:{icon:Oc,label:"表格文件"},presentation:{icon:Vc,label:"演示文件"},database:{icon:Lc,label:"数据库文件"},file:{icon:Uc,label:"文件"}};function Xm(t,n){return n==="directory"?"folder":Fd(t)}const yc=t=>t.replace(/\\/g,"/").replace(/\/+$/,"")||"/";function Ym(t,n){const r=yc(t),s=yc(n),o=[{label:r==="/"?"/":r.split("/").filter(Boolean).pop()||r,path:r}];if(s===r)return o;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}`,o.push({label:u,path:d});return o}function Jm({open:t,onCancel:n,onConfirm:r}){const[s,i]=a.useState([]),[o,c]=a.useState(""),[d,u]=a.useState(""),[g,f]=a.useState([]),[x,y]=a.useState(!1),[v,S]=a.useState(""),[E,C]=a.useState(!1),I=a.useMemo(()=>Ym(o||"/",d||o||"/"),[o,d]),j=async N=>{if(window.agentApi){y(!0),S("");try{const T=await window.agentApi.listProjectDirectories(N);f(T),u(N)}catch(T){S(T instanceof Error?T.message:"无法读取目录")}finally{y(!1)}}};if(a.useEffect(()=>{if(!t||!window.agentApi)return;let N=!1;return y(!0),S(""),window.agentApi.listProjectRoots().then(async T=>{if(N)return;i(T);const A=T[0]??"";c(A),A?await j(A):S("未配置可用的宿主机目录")}).catch(T=>{N||S(T instanceof Error?T.message:"无法读取宿主机目录")}).finally(()=>{N||y(!1)}),()=>{N=!0}},[t]),a.useEffect(()=>{if(!t)return;const N=T=>{T.key==="Escape"&&n()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,n]),!t)return null;const k=N=>{c(N),j(N)},W=()=>{I.length<=1||j(I[I.length-2].path)},ee=async()=>{if(!(!d||E)){C(!0),S("");try{await r(d)}catch(N){S(N instanceof Error?N.message:"项目导入失败")}finally{C(!1)}}};return $n.createPortal(e.jsx("div",{className:"host-project-picker-backdrop",role:"presentation",onMouseDown:N=>{N.target===N.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(Rr,{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:o,onChange:N=>k(N.target.value),children:s.map(N=>e.jsx("option",{value:N,children:N},N))})]}),e.jsxs("nav",{className:"host-project-picker-nav","aria-label":"当前目录",children:[e.jsx("button",{type:"button",className:"ui-icon-button",onClick:W,disabled:I.length<=1,"aria-label":"返回上级目录",title:"返回上级目录",children:e.jsx(Zo,{size:16,"aria-hidden":"true"})}),e.jsx("div",{className:"host-project-picker-breadcrumbs",children:I.map((N,T)=>e.jsxs("span",{children:[T>0&&e.jsx("i",{children:"/"}),e.jsx("button",{type:"button",onClick:()=>void j(N.path),children:N.label})]},N.path))}),e.jsx("button",{type:"button",className:"ui-icon-button",onClick:()=>d&&void j(d),disabled:!d||x,"aria-label":"刷新目录",title:"刷新目录",children:e.jsx(_s,{size:15,"aria-hidden":"true"})})]}),o==="/"&&e.jsx("div",{className:"host-project-picker-warning",children:"当前允许访问宿主机根目录,请谨慎选择项目。"}),e.jsx("div",{className:"host-project-picker-list","aria-busy":x,children:x?e.jsx("div",{className:"host-project-picker-state",children:"正在读取目录…"}):v?e.jsx("div",{className:"host-project-picker-state is-error",children:v}):g.length===0?e.jsx("div",{className:"host-project-picker-state",children:"此目录为空"}):g.map(N=>{const T=Xm(N.name,N.kind),{icon:A,label:R}=Qm[T],L=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`host-project-picker-entry-icon is-${T}`,"aria-hidden":"true",children:e.jsx(A,{size:18,strokeWidth:1.8})}),e.jsx("span",{className:"host-project-picker-name",children:N.name})]});return N.kind==="file"?e.jsx("div",{className:"host-project-picker-row is-file",title:R,children:L},`${N.name}:${N.path}`):e.jsxs("button",{type:"button",className:"host-project-picker-row is-directory",onClick:()=>void j(N.path),title:R,children:[L,N.hasChildren&&e.jsx("span",{className:"host-project-picker-chevron","aria-hidden":"true",children:e.jsx(Ur,{size:16})})]},`${N.name}:${N.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||x||E,onClick:()=>void ee(),children:E?"正在导入…":"选择此文件夹"})]})]})]})}),document.body)}const Zm=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function ex(t){if(!t.trim())return{rows:[],added:0,removed:0};const n=[];let r=0,s=0,i=!1,o=0,c=0;for(const d of t.replace(/\n$/,"").split(`
475
- `)){const u=d.match(Zm);if(u){r=Number(u[1]),s=Number(u[2]),i=!0,n.push({kind:"hunk",text:d,oldLine:null,newLine:null});continue}if(!i){!d.startsWith("diff --git ")&&!d.startsWith("index ")&&!d.startsWith("--- ")&&!d.startsWith("+++ ")&&n.push({kind:"meta",text:d,oldLine:null,newLine:null});continue}d.startsWith("+")?(n.push({kind:"added",text:d.slice(1),oldLine:null,newLine:s}),s+=1,o+=1):d.startsWith("-")?(n.push({kind:"removed",text:d.slice(1),oldLine:r,newLine:null}),r+=1,c+=1):d.startsWith(" ")?(n.push({kind:"context",text:d.slice(1),oldLine:r,newLine:s}),r+=1,s+=1):n.push({kind:"note",text:d,oldLine:null,newLine:null})}return{rows:n,added:o,removed:c}}const Od=new Set(["ts","tsx","js","jsx","mjs","cjs","json","md","markdown","mdown","mkdn","mdx","css","scss","html","htm","xml","yml","yaml","toml","sh","zsh","bash","py","rb","go","rs","java","kt","c","h","cpp","hpp","sql","env","gitignore","dockerfile","txt","log","conf","properties","gradle","lock","csv","vue","svelte","astro","graphql","prisma","proto"]),tx=new Set(["png","jpg","jpeg","gif","webp","bmp","ico","svg"]),nx=new Set(["html","htm"]),rx=new Set(["md","markdown","mdown","mkdn","mdx"]),sx=new Set(Od),ix="allow-scripts allow-popups allow-forms allow-modals",ox=new Set(["mp4","webm","mov","m4v"]),ax=new Set(["mp3","wav","m4a","aac","ogg","flac"]),lx=new Set(["pdf"]),cx=8*1024*1024,dx=4096,ux=512*1024,px=256*1024*1024,fx={aac:"audio/aac",csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",gif:"image/gif",html:"text/html",jpeg:"image/jpeg",jpg:"image/jpeg",json:"application/json",m4a:"audio/mp4",m4v:"video/mp4",md:"text/markdown",mov:"video/quicktime",mp3:"audio/mpeg",mp4:"video/mp4",ogg:"audio/ogg",pdf:"application/pdf",png:"image/png",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",svg:"image/svg+xml",tar:"application/x-tar",txt:"text/plain",wav:"audio/wav",webm:"video/webm",webp:"image/webp",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",zip:"application/zip"};function hx(t,n){return n?!t.share||!t.canShare?"unsupported-browser":"ready":"insecure-context"}function gx(t){var r;const n=((r=t.split(".").pop())==null?void 0:r.toLowerCase())??"";return fx[n]??"application/octet-stream"}async function mx(t,n){var r;if(!n.share||!((r=n.canShare)!=null&&r.call(n,{files:[t]})))return"unsupported";try{return await n.share({files:[t],title:t.name}),"shared"}catch(s){if(s&&typeof s=="object"&&"name"in s&&s.name==="AbortError")return"cancelled";throw s}}function ga(t){return Uint8Array.from(atob(t),n=>n.charCodeAt(0))}function xx(t,n,r){return t.decode(ga(n),{stream:!r})}async function vc(t,n,r=()=>{},s=ux){const i=await n("fs:stat",{path:t});if(i.dir)throw new Error("文件夹不能下载");if(i.size>px)throw new Error("文件超过 256M,请通过终端传输");const o=[];let c=0;do{const d=await n("fs:read",{path:t,offset:c,length:s},6e4),u=ga(d.data);if(u.byteLength!==d.bytes)throw new Error("文件分块长度不一致,请重试");o.push(u.slice().buffer);const g=d.offset+d.bytes;if(!d.eof&&g<=c)throw new Error("文件下载未取得进展,请重试");if(c=g,r(i.size===0?100:Math.min(100,Math.round(c/i.size*100))),d.eof)break}while(c<i.size);return new Blob(o,{type:"application/octet-stream"})}function bx(t){var r;const n=((r=t.split(".").pop())==null?void 0:r.toLowerCase())??"";return nx.has(n)}function yx(t){var r;const n=((r=t.split(".").pop())==null?void 0:r.toLowerCase())??"";return rx.has(n)}function wc(t){var r;const n=((r=t.split(".").pop())==null?void 0:r.toLowerCase())??"";return sx.has(n)}function vx(t){var r;const n=((r=t.split(".").pop())==null?void 0:r.toLowerCase())??"";return Od.has(n)||!t.includes(".")?"text":tx.has(n)?"image":ox.has(n)?"video":ax.has(n)?"audio":lx.has(n)?"pdf":"hex"}function wx({path:t,gateway:n,onClose:r}){const s=n.request,[i,o]=a.useState([]),[c,d]=a.useState(null),[u,g]=a.useState(""),[f,x]=a.useState(null),[y,v]=a.useState("initial-loading"),[S,E]=a.useState(!1),[C,I]=a.useState(0),[j,k]=a.useState(null),[W,ee]=a.useState(null),[N,T]=a.useState(null),[A,R]=a.useState(null),[L,H]=a.useState(!1),[de,Fe]=a.useState(null),[fe,je]=a.useState(null),[ze,Ge]=a.useState(!1),[Ke,Ct]=a.useState(!0),[it,te]=a.useState(null),[ge,Qe]=a.useState("unavailable"),[B,G]=a.useState(!1),[Y,ae]=a.useState(null),[me,le]=a.useState("file"),[Se,Te]=a.useState(!1),[mt,$e]=a.useState(!1),[yt,st]=a.useState(!1),[tt,It]=a.useState(!1),[ft,P]=a.useState(""),[K,X]=a.useState(!1),[J,ne]=a.useState(null),[ct,ht]=a.useState(!1),ot=a.useRef(null),Ue=a.useRef(null),$t=a.useRef(0),tn=a.useRef(!1),Xe=a.useRef(0),pt=a.useRef(!1),Dt=a.useRef(new TextDecoder("utf-8",{fatal:!1})),Bt=a.useRef(null),gn=a.useRef(null),Ut=a.useRef(!1),Re=t?vx(t):"unsupported",Tn=t?bx(t):!1,Nn=t?yx(t):!1,_n=Tn||Nn,Z=t?wc(t):!1,_t=a.useMemo(()=>i.join(""),[i]),Xt=a.useCallback(()=>{const q=Bt.current;Bt.current=null,q&&s("fs:preview-close",{ticketId:q}).catch(()=>{})},[s]),Tt=a.useCallback(async(q,re=!1,ce=Xe.current)=>{if(!pt.current){pt.current=!0,v(re?"initial-loading":"loading-more"),k(null);try{const Ce=re?0:$t.current,He=await s("fs:read",{path:q,offset:Ce,length:256*1024});if(ce!==Xe.current)return;const xn=He.offset+He.bytes;if(!He.eof&&xn<=Ce)throw new Error("文件加载未取得进展,请重试");re&&(Dt.current=new TextDecoder("utf-8",{fatal:!1}));const Jn=xx(Dt.current,He.data,He.eof);$t.current=xn,Ct(He.eof),I(xn),o(Lt=>re?[Jn]:[...Lt,Jn]),x(Lt=>({size:He.size,mtime:(Lt==null?void 0:Lt.mtime)??0})),ee(null),v("ready")}catch(Ce){if(ce!==Xe.current)return;const He=Ce.message??String(Ce);re?(ee(He),v("error")):(k(He),v("ready"))}finally{ce===Xe.current&&(pt.current=!1)}}},[s]),Et=a.useCallback(async(q,re)=>{try{const ce=await s("fs:inspect-text-status",{path:q});if(re!==Xe.current)return;x({size:ce.size,mtime:ce.mtime}),Qe(ce.diffStatus),$e(!ce.tooLarge),ht(!1),ne(null)}catch{}},[s]),at=a.useCallback(async(q,re=Xe.current)=>{Xt(),v("initial-loading"),ee(null);try{const ce=await s("fs:preview-open",{path:q});if(re!==Xe.current){s("fs:preview-close",{ticketId:ce.ticketId}).catch(()=>{});return}Bt.current=ce.ticketId,gn.current=ce.url,d(ce.url),x({size:ce.size,mtime:ce.mtime})}catch(ce){if(re!==Xe.current)return;ee(ce.message??String(ce)),v("error")}},[Xt,s]),Ft=a.useCallback(async(q,re=Xe.current)=>{v("initial-loading"),ee(null);try{const ce=await s("fs:read",{path:q,offset:0,length:dx});if(re!==Xe.current)return;qt(ce.data),I(ce.bytes),x(Ce=>({size:ce.size,mtime:(Ce==null?void 0:Ce.mtime)??0})),v("ready")}catch(ce){if(re!==Xe.current)return;ee(ce.message??String(ce)),v("error")}},[s]);function qt(q){const re=atob(q),ce=[];for(let Ce=0;Ce+16<=re.length||Ce===0;Ce+=16){const He=re.slice(Ce,Ce+16),xn=[...He].map(Lt=>Lt.charCodeAt(0).toString(16).padStart(2,"0")).join(" ").padEnd(47," "),Jn=[...He].map(Lt=>Lt.charCodeAt(0)>=32&&Lt.charCodeAt(0)<127?Lt:".").join("");if(ce.push(`${Ce.toString(16).padStart(8,"0")} ${xn} |${Jn}|`),Ce+16>re.length)break}g(ce.join(`
476
- `))}const zt=a.useCallback((q,re)=>{const ce=++Xe.current,Ce=wc(q);pt.current=!1,Xt(),gn.current=null,o([]),d(null),g(""),x(null),ee(null),k(null),I(0),T(null),R(null),H(!1),Fe(null),je(null),Ge(!1),Ct(!0),te(null),Qe("unavailable"),G(!1),ae(null),le("file"),$e(!1),st(!1),It(!1),P(""),ne(null),ht(!1),v("initial-loading"),tn.current=!1,$t.current=0,Dt.current=new TextDecoder("utf-8",{fatal:!1}),s("fs:watch",{path:jx(q)}).catch(()=>{}),re==="text"?(Et(q,ce),Tt(q,!0,ce),Ce&&Ut.current&&at(q,ce)):re==="image"||re==="video"||re==="audio"||re==="pdf"?at(q,ce):re==="hex"&&(s("fs:stat",{path:q}).then(He=>{ce===Xe.current&&x(He)}).catch(()=>{}),Ft(q,ce))},[Tt,Ft,at,Et,Xt,s]);a.useEffect(()=>{if(t)return Ut.current=!1,Te(!1),zt(t,Re),()=>{Xe.current++,pt.current=!1,Xt()}},[t]),a.useEffect(()=>{let q=null;const re=ce=>{const Ce=ce.detail;!Ce||Ce!==t||(q!==null&&window.clearTimeout(q),q=window.setTimeout(()=>{Re==="text"&&tn.current?ht(!0):t&&zt(t,Re)},350))};return window.addEventListener("file-changed",re),()=>{window.removeEventListener("file-changed",re),q!==null&&window.clearTimeout(q)}},[t,Re,zt]),a.useEffect(()=>{tn.current=tt},[tt]),a.useEffect(()=>{if(y!=="initial-loading"){E(!1);return}const q=window.setTimeout(()=>E(!0),120);return()=>window.clearTimeout(q)},[t,y]),a.useEffect(()=>{const q=Ue.current,re=ot.current;if(!q||!re||!t||Re!=="text"||Ke||tt||me!=="file"||y!=="ready"||j)return;const ce=new IntersectionObserver(Ce=>{Ce.some(He=>He.isIntersecting)&&Tt(t)},{root:re,rootMargin:"0px 0px 360px 0px"});return ce.observe(q),()=>ce.disconnect()},[tt,Ke,Re,Tt,j,t,y,me]);const Sn=a.useCallback((q,re)=>{const ce=URL.createObjectURL(q),Ce=document.createElement("a");Ce.href=ce,Ce.download=ri(re),Ce.style.display="none",document.body.appendChild(Ce),Ce.click(),Ce.remove(),window.setTimeout(()=>URL.revokeObjectURL(ce),1e3)},[]),tr=a.useCallback(async()=>{if(!t||A!==null||fe!==null)return;const q=t;T(null),Fe(null),H(!1),R(0);try{const re=await vc(q,s,R);Sn(re,q),H(!0),window.setTimeout(()=>H(!1),1500)}catch(re){T((re==null?void 0:re.message)??String(re))}finally{R(null)}},[Sn,A,t,s,fe]),Qn=a.useCallback(async()=>{if(!t||fe!==null||A!==null)return;const q=t;T(null),Fe(null),Ge(!1);const re=hx(navigator,window.isSecureContext);if(re==="insecure-context"){Fe("当前页面是 HTTP,手机 Chrome 仅允许 HTTPS 页面分享文件,请改用 HTTPS 地址后重试");return}if(re==="unsupported-browser"){Fe("当前浏览器不支持分享文件,请使用最新版手机 Chrome 或系统浏览器");return}je(0);try{const ce=await vc(q,s,je),Ce=new File([ce],ri(q),{type:gx(q),lastModified:(f==null?void 0:f.mtime)??Date.now()}),He=await mx(Ce,navigator);He==="unsupported"?Fe("当前浏览器不支持分享此文件类型,请使用下载按钮"):He==="shared"&&(Ge(!0),window.setTimeout(()=>Ge(!1),1500))}catch(ce){Fe((ce==null?void 0:ce.message)??String(ce))}finally{je(null)}},[A,f==null?void 0:f.mtime,t,s,fe]),Cn=a.useCallback(async(q,re)=>{const ce=await s("fs:inspect-text",{path:q},6e4);return re!==Xe.current?null:(x({size:ce.size,mtime:ce.mtime}),Qe(ce.diffStatus),te(ce.patch),$e(!ce.tooLarge&&ce.validUtf8),ce)},[s]),Un=a.useCallback(async()=>{if(!t||yt)return;const q=Xe.current;st(!0),ne(null);try{const re=await Cn(t,q);if(!re)return;if(re.tooLarge||re.data===null)throw new Error("文件超过 8M,无法在线编辑");if(!re.validUtf8)throw new Error("此文件不是有效的 UTF-8 文本,无法在线编辑");const ce=new TextDecoder("utf-8",{fatal:!1}).decode(ga(re.data));o([ce]),I(re.size),$t.current=re.size,Ct(!0),P(ce),ht(!1),tn.current=!0,It(!0)}catch(re){q===Xe.current&&ne(re.message??String(re))}finally{q===Xe.current&&st(!1)}},[yt,Cn,t]),Yt=a.useCallback(async()=>{if(!t||B||(le("diff"),it!==null))return;const q=Xe.current;G(!0),ae(null);try{await Cn(t,q)}catch(re){q===Xe.current&&ae(re.message??String(re))}finally{q===Xe.current&&G(!1)}},[B,Cn,it,t]),Xn=a.useCallback(()=>{if(!t)return;const q=!Se;Ut.current=q,Te(q),q&&!c&&at(t,Xe.current)},[at,c,t,Se]),mn=a.useCallback(q=>{gn.current===q&&(ee(null),v("ready"))},[]),Ie=a.useCallback(q=>{gn.current===q&&(ee("文件预览加载失败,请重试"),v("error"))},[]),xt=a.useCallback(()=>{t&&zt(t,Re)},[Re,t,zt]),Vt=a.useCallback(()=>{ft!==_t&&!window.confirm("放弃未保存的修改?")||(tn.current=!1,It(!1),P(""),ne(null),ht(!1))},[ft,_t]),Yn=a.useCallback(()=>{tt&&ft!==_t&&!window.confirm("放弃未保存的修改并关闭预览?")||(Xe.current++,Xt(),r())},[ft,tt,r,Xt,_t]),Hn=a.useCallback(()=>{t&&(tn.current=!1,It(!1),P(""),zt(t,"text"))},[t,zt]),on=a.useCallback(async()=>{if(!(!t||!f||K||ft===_t)){X(!0),ne(null);try{await s("fs:write-text",{path:t,content:ft,expectedSize:f.size,expectedMtime:f.mtime},6e4),tn.current=!1,It(!1),P(""),zt(t,"text")}catch(q){ne((q==null?void 0:q.message)??String(q))}finally{X(!1)}}},[ft,f,t,s,K,zt,_t]),O=a.useMemo(()=>ex(it??""),[it]);if(!t)return null;const Ye=((f==null?void 0:f.size)??0)>cx,qn=!Ye&&(ge==="changed"||ge==="untracked"),Ot=Re==="text"&&mt&&y!=="initial-loading"&&!yt&&!W;return e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--ui-term-col-bg, #101014)",color:"var(--ui-text, #e8e8ee)",colorScheme:"var(--ui-color-scheme, dark)",accentColor:"var(--ui-tab-accent, #7aa2f7)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"9px 12px",borderBottom:"1px solid var(--ui-tree-border, #222)",background:"var(--ui-tree-bg, #121218)",flexShrink:0},children:[e.jsx("span",{className:"pv-name",style:{minWidth:0,flex:"1 1 auto",fontSize:12.5,color:"var(--ui-text, #e8e8ee)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ri(t)}),f&&e.jsx("span",{style:{fontSize:10.5,color:"var(--ui-history-meta, #666)",flexShrink:0},children:Wo(f.size)}),tt?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Vt,disabled:K,style:ss,"aria-label":"取消编辑",title:"取消编辑",children:e.jsx(ra,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:on,disabled:K||ft===_t,style:{...ss,color:"var(--ui-tab-accent, #7aa2f7)",opacity:K||ft===_t?.55:1},"aria-label":K?"正在保存":"保存修改",title:K?"正在保存":"保存修改",children:K?e.jsx(lt,{className:"tree-spin",size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(dp,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]}):e.jsxs(e.Fragment,{children:[Re==="text"&&e.jsx("button",{type:"button",onClick:Un,disabled:!Ot,style:{...ss,opacity:Ot?1:.45},"aria-label":"编辑文件",title:Ye?"文件超过 8M,无法在线编辑":mt?"编辑文件":"此文件不可编辑",children:e.jsx(na,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:tr,disabled:A!==null||fe!==null,style:{...ss,opacity:A!==null||fe!==null?.72:1},"aria-label":A===null?"下载到当前设备":`正在下载 ${A}%`,title:A===null?"下载到当前设备":`正在下载 ${A}%`,children:A!==null?e.jsx(lt,{className:"tree-spin",size:15,strokeWidth:1.8,"aria-hidden":"true"}):L?e.jsx($r,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(ta,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:Qn,disabled:fe!==null||A!==null,style:{...ss,opacity:fe!==null||A!==null?.72:1},"aria-label":"分享文件",title:fe===null?"分享文件":`正在准备 ${fe}%`,children:fe!==null?e.jsx(lt,{className:"tree-spin",size:15,strokeWidth:1.8,"aria-hidden":"true"}):ze?e.jsx($r,{size:15,strokeWidth:1.8,"aria-hidden":"true"}):e.jsx(pp,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),Z&&e.jsx("button",{type:"button",onClick:Xn,"aria-pressed":Se,style:{...ss,...Se?{color:"var(--ui-tab-accent, #7aa2f7)",borderColor:"var(--ui-tab-accent, #7aa2f7)"}:{}},"aria-label":Se?"退出浏览器预览":"浏览器预览",title:Se?"退出浏览器预览":Tn?"在浏览器中预览渲染效果":Nn?"预览 Markdown 排版效果":"在浏览器中查看原始文件",children:e.jsx(Uu,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]}),e.jsx("button",{type:"button",onClick:Yn,style:ss,"aria-label":"关闭预览",title:"关闭预览",children:e.jsx(Rr,{size:15,strokeWidth:1.8,"aria-hidden":"true"})})]}),Re==="text"&&qn&&!tt&&!Se&&e.jsxs("div",{style:{display:"flex",alignItems:"center",minHeight:34,padding:"0 12px",borderBottom:"1px solid var(--ui-tree-border, #222)",background:"var(--ui-tree-bg, #121218)",flexShrink:0},children:[e.jsxs("div",{role:"tablist","aria-label":"文件预览模式",style:{display:"inline-flex",gap:2,padding:2,border:"1px solid var(--ui-panel-input-border, #333)",borderRadius:6,background:"var(--ui-muted-surface, #1b1b22)"},children:[e.jsx(jc,{active:me==="diff",onClick:Yt,children:"变更"}),e.jsx(jc,{active:me==="file",onClick:()=>le("file"),children:"文件"})]}),e.jsxs("span",{style:{marginLeft:9,display:"inline-flex",gap:7,fontFamily:'"SF Mono", Menlo, Consolas, monospace',fontSize:10.5},children:[O.added>0&&e.jsxs("span",{style:{color:"var(--ui-success, #059669)"},children:["+",O.added]}),O.removed>0&&e.jsxs("span",{style:{color:"var(--ui-error, #dc2626)"},children:["-",O.removed]})]})]}),de&&e.jsxs("div",{role:"alert",style:{flexShrink:0,padding:"8px 12px",borderBottom:"1px solid var(--ui-tree-border, #222)",background:"var(--ui-tree-bg, #121218)",color:"var(--ui-error, #f7768e)",fontSize:12.5,lineHeight:1.5},children:["分享失败:",de]}),e.jsxs("div",{ref:ot,className:"pv-body",style:{position:"relative",flex:1,minHeight:0,overflow:"auto",background:"var(--ui-term-col-bg, #101014)",WebkitOverflowScrolling:"touch"},children:[N&&e.jsxs("div",{style:{padding:"10px 14px 0",color:"var(--ui-error, #f7768e)",fontSize:12.5},children:["下载失败:",N]}),J&&e.jsx("div",{role:"alert",style:{padding:"10px 14px",color:"var(--ui-error, #f7768e)",fontSize:12.5},children:J}),ct&&tt&&e.jsxs("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--ui-tree-border, #222)",color:"var(--ui-error, #f7768e)",fontSize:12},children:[e.jsx("span",{style:{flex:1},children:"文件已在其他位置更新"}),e.jsxs("button",{type:"button",onClick:Hn,style:Jo,children:[e.jsx(_s,{size:13,strokeWidth:1.8,"aria-hidden":"true"}),"重新加载"]})]}),c&&!W&&Re==="image"&&e.jsx("img",{src:c,alt:t,onLoad:()=>mn(c),onError:()=>Ie(c),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",display:"block",margin:"0 auto"}}),c&&!W&&Re==="video"&&e.jsx("video",{src:c,controls:!0,autoPlay:!0,onLoadedMetadata:()=>mn(c),onError:()=>Ie(c),style:{maxWidth:"100%",maxHeight:"100%",display:"block",margin:"0 auto"}}),c&&!W&&Re==="audio"&&e.jsx("div",{style:{display:"grid",placeItems:"center",height:"100%"},children:e.jsx("audio",{src:c,controls:!0,autoPlay:!0,onLoadedMetadata:()=>mn(c),onError:()=>Ie(c),style:{width:"min(420px, 88%)"}})}),c&&!W&&Re==="pdf"&&e.jsx("iframe",{src:c,title:t,onLoad:()=>mn(c),onError:()=>Ie(c),style:{width:"100%",height:"100%",border:"none"}}),c&&!W&&Re==="text"&&Z&&Se&&!tt&&e.jsx("iframe",{src:_n?`${c}/${encodeURIComponent(ri(t))}`:c,sandbox:ix,title:t,onLoad:()=>mn(c),onError:()=>Ie(c),style:{width:"100%",height:"100%",border:"none",background:"#fff"}}),Re==="text"&&tt&&!W&&e.jsx("textarea",{value:ft,onChange:q=>P(q.target.value),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off","aria-label":`编辑 ${ri(t)}`,style:{width:"100%",minHeight:"100%",boxSizing:"border-box",resize:"none",margin:0,padding:"12px 14px calc(env(safe-area-inset-bottom) + 36px)",border:0,outline:0,background:"var(--ui-term-col-bg, #101014)",color:"var(--ui-history-item-text, var(--ui-text, #d6d6de))",fontFamily:'"SF Mono", Menlo, Consolas, monospace',fontSize:12,lineHeight:1.5,tabSize:2}}),Re==="text"&&!tt&&!W&&qn&&me==="diff"&&(Y?e.jsx(Ai,{label:Y,actionLabel:"重试",onAction:()=>void Yt(),tone:"error"}):B?e.jsx(Ai,{label:"正在加载变更"}):e.jsx(kx,{rows:O.rows})),(Re==="hex"||Re==="text"&&!tt&&!Se&&(!qn||me==="file"))&&!W&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{style:{margin:0,padding:"11px 13px calc(env(safe-area-inset-bottom) + 36px)",fontFamily:'"SF Mono", Menlo, Consolas, monospace',fontSize:Re==="hex"?10.5:12,lineHeight:1.45,color:Re==="hex"?"var(--ui-muted-text, #9aa)":"var(--ui-history-item-text, var(--ui-text, #d6d6de))",whiteSpace:Re==="hex"?"pre":"pre-wrap",wordBreak:Re==="hex"?"normal":"break-word"},children:Re==="hex"?u:i.map((q,re)=>e.jsx("span",{children:q},re))}),Re==="text"&&!Ke&&e.jsxs("div",{ref:Ue,role:"status","aria-live":"polite",style:{minHeight:44,padding:"0 14px calc(env(safe-area-inset-bottom) + 8px)",display:"flex",alignItems:"center",justifyContent:"center",gap:7,color:"var(--ui-history-meta, #666)",fontSize:11.5},children:[y==="loading-more"&&e.jsx(lt,{className:"tree-spin",size:14,strokeWidth:1.8,"aria-hidden":"true",style:{color:"var(--ui-tab-accent, #7aa2f7)"}}),j?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"加载失败"}),e.jsxs("button",{type:"button",onClick:()=>Tt(t),style:Jo,children:[e.jsx(_s,{size:13,strokeWidth:1.8,"aria-hidden":"true"}),"重试"]})]}):e.jsx("span",{children:y==="loading-more"?"正在加载更多":`${Wo(C)} / ${Wo((f==null?void 0:f.size)??C)}`})]})]}),S&&y==="initial-loading"&&e.jsx(Ai,{label:"正在加载文件"}),W&&y==="error"&&e.jsx(Ai,{label:W,actionLabel:"重试",onAction:xt,tone:"error"})]})]})}function ri(t){return t.slice(t.lastIndexOf("/")+1)||t}function jx(t){const n=t.lastIndexOf("/");return n>0?t.slice(0,n):"/"}function Wo(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}K`:`${(t/1024/1024).toFixed(1)}M`}const ss={width:28,height:28,borderRadius:7,border:"1px solid var(--ui-panel-input-border, #333)",display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--ui-muted-surface, #1b1b22)",color:"var(--ui-muted-text, #ccc)",flexShrink:0,cursor:"pointer",WebkitAppRegion:"no-drag"},Jo={minHeight:28,padding:"0 9px",borderRadius:6,border:"1px solid var(--ui-panel-input-border, #333)",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--ui-muted-surface, #1b1b22)",color:"var(--ui-muted-text, #ccc)",cursor:"pointer",fontSize:11};function Ai({label:t,actionLabel:n,onAction:r,tone:s="muted"}){return e.jsxs("div",{role:s==="error"?"alert":"status",style:{position:"absolute",inset:0,minHeight:120,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,color:s==="error"?"var(--ui-error, #f7768e)":"var(--ui-muted-text, #9aa)",fontSize:12.5},children:[s!=="error"&&e.jsx(lt,{className:"tree-spin",size:18,strokeWidth:1.8,"aria-hidden":"true",style:{color:"var(--ui-tab-accent, #7aa2f7)"}}),e.jsx("span",{children:t}),n&&r&&e.jsxs("button",{type:"button",onClick:r,style:Jo,children:[e.jsx(_s,{size:13,strokeWidth:1.8,"aria-hidden":"true"}),n]})]})}function jc({active:t,onClick:n,children:r}){return e.jsx("button",{type:"button",role:"tab","aria-selected":t,onClick:n,style:{minWidth:48,height:24,padding:"0 9px",border:0,borderRadius:4,background:t?"var(--ui-tab-accent, #7aa2f7)":"transparent",color:t?"var(--ui-tab-active-text, #fff)":"var(--ui-muted-text, #9aa)",fontSize:11,fontWeight:600,cursor:"pointer"},children:r})}function kx({rows:t}){return e.jsx("div",{style:{minWidth:"100%",width:"max-content",paddingBottom:"calc(env(safe-area-inset-bottom) + 36px)",fontFamily:'"SF Mono", Menlo, Consolas, monospace',fontSize:11.5,lineHeight:1.55},children:t.map((n,r)=>{const s=n.kind==="added",i=n.kind==="removed",o=n.kind==="hunk"||n.kind==="meta"||n.kind==="note",c=s?"color-mix(in srgb, var(--ui-success, #059669) 12%, transparent)":i?"color-mix(in srgb, var(--ui-error, #dc2626) 11%, transparent)":n.kind==="hunk"?"color-mix(in srgb, var(--ui-tab-accent, #7aa2f7) 10%, transparent)":"transparent",d=s?"var(--ui-success, #059669)":i?"var(--ui-error, #dc2626)":o?"var(--ui-muted-text, #9aa)":"var(--ui-history-item-text, var(--ui-text, #d6d6de))";return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"42px 42px 22px minmax(0, 1fr)",minHeight:18,background:c,color:d},children:[e.jsx("span",{style:kc,children:n.oldLine??""}),e.jsx("span",{style:kc,children:n.newLine??""}),e.jsx("span",{style:{textAlign:"center",userSelect:"none",color:d},children:s?"+":i?"-":" "}),e.jsx("span",{style:{padding:"0 12px 0 6px",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:n.text||" "})]},`${n.kind}-${r}`)})})}const kc={padding:"0 6px",borderRight:"1px solid var(--ui-tree-border, #222)",color:"var(--ui-history-meta, #666)",textAlign:"right",userSelect:"none"};function Oi(t){const n=t.replace(/\/{2,}/g,"/");return n.length>1?n.replace(/\/+$/,""):n}function $d(t){const n=Oi(t),r=n.lastIndexOf("/");return r<=0?"/":n.slice(0,r)}function Ud(t,n){const r=Oi(t),s=Oi(n);return s==="/"?r.startsWith("/"):r.startsWith(`${s}/`)}function Sx(t,n){const r=Oi(t);if(!Ud(n,r))return[];const s=$d(n);if(s===r)return[r];const i=s.slice(r==="/"?1:r.length+1),o=[r];let c=r;for(const d of i.split("/").filter(Boolean))c=c==="/"?`/${d}`:`${c}/${d}`,o.push(c);return o}const Cx={code:{icon:Wc,color:"#7aa2f7",label:"代码文件"},style:{icon:qc,color:"#bb9af7",label:"样式文件"},image:{icon:Bc,color:"#9ece6a",label:"图片文件"},video:{icon:$c,color:"#f7768e",label:"视频文件"},audio:{icon:Dc,color:"#c099ff",label:"音频文件"},markdown:{icon:Hc,color:"#73daca",label:"Markdown 文件"},text:{icon:ai,color:"#a9b1d6",label:"文本文件"},json:{icon:Fc,color:"#e0af68",label:"JSON 文件"},archive:{icon:Pc,color:"#ff9e64",label:"压缩文件"},spreadsheet:{icon:Oc,color:"#9ece6a",label:"表格文件"},presentation:{icon:Vc,color:"#f7768e",label:"演示文件"},database:{icon:Lc,color:"#2ac3de",label:"数据库文件"},file:{icon:Uc,color:"#c8c8d0",label:"文件"}};function Ix(t){return Cx[Fd(t)]}function Sc(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}K`:t<1024*1024*1024?`${(t/1024/1024).toFixed(1)}M`:`${(t/1024/1024/1024).toFixed(1)}G`}function Rx({gateway:t,onOpenFile:n,selectedPath:r,ready:s,cwd:i,followCwd:o,initialRoot:c,initialFollow:d=!0,onTreeStateChange:u,revealRequest:g}){const f=t.request,x=t.subscribe,[y,v]=a.useState(null),[S,E]=a.useState(""),[C,I]=a.useState(""),[j,k]=a.useState(!d),[W,ee]=a.useState(""),N=a.useRef(new Map),T=a.useRef(null),A=a.useRef(null),R=a.useRef(0),L=a.useRef(0),[,H]=a.useState(0),de=()=>H(Y=>Y+1),Fe=a.useCallback(async(Y,ae)=>{const me={path:Y,depth:ae,expanded:!0,children:null,loading:!0};N.current.set(Y,me),de();try{const le=await f("fs:list",{path:Y});me.children=le.entries,f("fs:watch",{path:Y}).catch(()=>{})}catch(le){me.children=[],me.error=(le==null?void 0:le.message)??"read failed"}return me.loading=!1,de(),me},[f]),fe=!!o&&!j,je=a.useCallback(Y=>{const ae=Y.length>1?Y.replace(/\/+$/,""):Y;T.current=ae,N.current.clear(),v({path:ae,depth:0,expanded:!1,children:null,loading:!1}),I(ae)},[]);a.useEffect(()=>{!s||!i||!fe||T.current!==i&&(je(i),u==null||u(i,!0))},[s,i,fe,je]),a.useEffect(()=>{!s||!c||d||T.current||(k(!0),je(c))},[s,c,d,je]),a.useEffect(()=>{s&&f("hello").then(Y=>{ee(Y.home),fe&&!i&&!T.current&&je(Y.home)}).catch(()=>{})},[s,i,fe,f,je]);const ze=()=>{let Y=C.trim();Y&&(Y==="~"?Y=W||i||"/":Y.startsWith("~/")?Y=`${W||i||""}${Y.slice(1)}`:Y.startsWith("/")||(Y=`${i||(y==null?void 0:y.path)||W||"/"}/${Y}`),Y=Y.replace(/\/+/g,"/"),k(!0),je(Y),u==null||u(Y,!1))},Ge=()=>{k(!1),i&&(je(i),u==null||u(i,!0))},Ke=a.useCallback(async Y=>{let ae=N.current.get(Y);ae||(ae={path:Y,depth:0,expanded:!1,children:null,loading:!1},N.current.set(Y,ae)),ae.expanded?ae.expanded=!1:(ae.expanded=!0,!ae.children&&!ae.loading&&await Fe(Y,ae.depth)),de()},[Fe]),Ct=a.useCallback(async(Y,ae)=>{let me=N.current.get(Y);me?!me.children&&!me.loading&&await Fe(Y,ae):me=await Fe(Y,ae),me.expanded=!0,de()},[Fe]),it=a.useCallback(async(Y,ae)=>{const me=$d(Y);let le=(y==null?void 0:y.path)??me;Ud(Y,le)||(le=me,k(!0),je(le),u==null||u(le,!1));const Se=Sx(le,Y);for(let mt=0;mt<Se.length;mt+=1){if(R.current!==ae)return;await Ct(Se[mt],mt)}const Te=()=>{var $e;if(R.current!==ae)return;const mt=Array.from((($e=A.current)==null?void 0:$e.querySelectorAll("[data-tree-path]"))??[]).find(yt=>yt.dataset.treePath===Y);mt==null||mt.scrollIntoView({block:"center",inline:"nearest"})};requestAnimationFrame(()=>requestAnimationFrame(Te))},[je,u,Ct,y==null?void 0:y.path]);a.useEffect(()=>{!s||!g||L.current!==g.requestId&&(L.current=g.requestId,R.current=g.requestId,it(g.path,g.requestId))},[s,it,g==null?void 0:g.requestId]),a.useEffect(()=>x("fs:event",Y=>{for(const ae of Y.events??[]){const me=ae.path;me===r&&window.dispatchEvent(new CustomEvent("file-changed",{detail:me}));const le=me.slice(0,me.lastIndexOf("/"))||"/",Se=N.current.get(le);Se!=null&&Se.expanded&&Se.children&&!Se.loading&&Fe(le,Se.depth).catch(()=>{})}}),[x,r,Fe]);const te=(Y,ae)=>Y.endsWith("/")?Y+ae:`${Y}/${ae}`,ge=S.trim().toLowerCase(),Qe=(Y,ae)=>{var Se;if(!ge||ae.name.toLowerCase().includes(ge))return!0;if(!ae.dir)return!1;const me=te(Y,ae.name),le=(Se=N.current.get(me))==null?void 0:Se.children;return(le==null?void 0:le.some(Te=>Qe(me,Te)))??!1},B=(Y,ae,me)=>ae.filter(le=>Qe(Y,le)).map(le=>{const Se=te(Y,le.name);if(le.dir){const $e=N.current.get(Se),yt=($e==null?void 0:$e.expanded)??!1;return e.jsxs("div",{children:[e.jsxs("div",{className:"tree-row",onClick:()=>Ke(Se),style:{paddingLeft:6+me*12},children:[e.jsx("span",{className:"tree-disclosure","aria-hidden":"true",children:$e!=null&&$e.loading?e.jsx(lt,{className:"tree-spin",size:13}):yt?e.jsx(Li,{size:13}):e.jsx(Ur,{size:13})}),e.jsx("span",{className:"tree-entry-icon tree-folder-icon","aria-hidden":"true",children:yt?e.jsx(sl,{size:16}):e.jsx(Oo,{size:16})}),e.jsx("span",{className:"tree-entry-name",children:le.name})]}),yt&&($e.error?e.jsx("div",{className:"tree-error",role:"alert",style:{paddingLeft:22+me*12},children:$e.error}):$e.children?B(Se,$e.children,me+1):e.jsx("div",{className:"tree-row",style:{paddingLeft:22+me*12,color:"#556"},children:"…"}))]},Se)}const Te=Ix(le.name),mt=Te.icon;return e.jsxs("div",{className:"tree-row","data-tree-path":Se,"data-selected":Se===r?"1":void 0,onClick:()=>n(Se),title:`${Te.label} · ${Se} · ${Sc(le.size)}`,style:{paddingLeft:6+me*12},children:[e.jsx("span",{className:"tree-disclosure","aria-hidden":"true"}),e.jsx("span",{className:"tree-entry-icon",style:{color:Te.color},"aria-hidden":"true",children:e.jsx(mt,{size:16,strokeWidth:1.8})}),e.jsx("span",{className:"tree-entry-name",children:le.name}),e.jsx("span",{className:"tree-size",children:Sc(le.size)})]},Se)});if(!y)return e.jsx("div",{style:{padding:14,fontSize:12,color:"#556"},children:fe?s?"等待终端目录…":"连接中…":"…"});const G=N.current.get(y.path);return e.jsxs("div",{className:"tree-scroll",ref:A,children:[e.jsxs("div",{className:"tree-location",children:[e.jsx("input",{value:C,onChange:Y=>I(Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&ze()},placeholder:"输入目录路径","aria-label":"文件树目录路径",spellCheck:!1}),e.jsx("button",{tabIndex:-1,onClick:ze,title:"定位目录","aria-label":"定位目录",children:e.jsx(Ou,{size:14,"aria-hidden":"true"})}),e.jsx("button",{tabIndex:-1,onClick:Ge,title:"跟随终端目录","aria-label":"跟随终端目录","data-active":fe?"1":void 0,children:e.jsx(Qu,{size:14,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"tree-filter",children:[e.jsx(sa,{size:14,"aria-hidden":"true"}),e.jsx("input",{value:S,onChange:Y=>E(Y.target.value),placeholder:"筛选已加载文件","aria-label":"筛选文件树"}),S&&e.jsx("button",{tabIndex:-1,onClick:()=>E(""),"aria-label":"清除筛选",children:e.jsx(Rr,{size:13,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"tree-row",onClick:()=>Ke(y.path),children:[e.jsx("span",{className:"tree-disclosure","aria-hidden":"true",children:G!=null&&G.loading?e.jsx(lt,{className:"tree-spin",size:13}):G!=null&&G.expanded?e.jsx(Li,{size:13}):e.jsx(Ur,{size:13})}),e.jsx("span",{className:"tree-entry-icon tree-folder-icon","aria-hidden":"true",children:G!=null&&G.expanded?e.jsx(sl,{size:16}):e.jsx(Oo,{size:16})}),e.jsx("span",{className:"tree-entry-name",style:{direction:"rtl",textAlign:"left"},children:y.path})]}),(G==null?void 0:G.expanded)&&(G.error?e.jsx("div",{className:"tree-error",role:"alert",children:G.error}):G.children?B(y.path,G.children,1):e.jsx("div",{className:"tree-row",style:{paddingLeft:24,color:"#556"},children:"…"}))]})}function Ex({open:t,tab:n,gateway:r,cwd:s,selectedPath:i,revealRequest:o,onTabChange:c,onSelectPath:d,onClose:u}){return t?e.jsxs("section",{className:`desktop-file-workspace${i?" has-preview":""}`,"aria-label":"我的文件",children:[e.jsxs("aside",{className:"desktop-file-drawer",children:[e.jsxs("header",{className:"desktop-file-drawer-header",children:[e.jsxs("div",{className:"desktop-file-drawer-tabs",role:"tablist","aria-label":"文件工作区视图",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":n==="files",className:n==="files"?"is-active":"",onClick:()=>c("files"),children:"文件"}),e.jsx("button",{type:"button",role:"tab","aria-selected":n==="history",className:n==="history"?"is-active":"",onClick:()=>c("history"),children:"历史"})]}),e.jsx("button",{type:"button",className:"desktop-file-workspace-close ui-icon-button ui-icon-button--small",onClick:u,"aria-label":"关闭我的文件",title:"关闭",children:e.jsx(Rr,{size:15,"aria-hidden":"true"})})]}),n==="files"?s?e.jsx(Rx,{gateway:r,ready:!0,followCwd:!0,cwd:s,onOpenFile:g=>d(g),selectedPath:i,revealRequest:o}):e.jsx("div",{className:"desktop-file-workspace-empty",children:"请先选择一个项目目录"}):e.jsxs("div",{className:"desktop-file-workspace-empty",children:[e.jsx("strong",{children:"终端历史在 Web 控制台中可用"}),e.jsx("span",{children:"Electron 当前没有终端上下文,因此不会提供填入或执行操作。"})]}),e.jsxs("footer",{className:"desktop-file-drawer-footer",children:[e.jsx("span",{}),"实时同步"]})]}),i&&e.jsx("div",{className:"desktop-file-preview",children:e.jsx(wx,{path:i,gateway:r,onClose:()=>d(null)})})]}):null}const Hd="agentroam.agent-workspaces.v2",Mx=2,qd=["customer-agent","codex","claude-code","opencode"];function Cc(){return{version:2,activeAgent:"customer-agent",agents:{}}}function Ic(){return{workspaces:[],nextCursor:null,watermark:null,expandedWorkspaceIds:[],selectedWorkspaceId:null,selectedSessionId:null,sidebarScrollTop:0,sessions:{}}}function Ax(t=localStorage){try{const n=JSON.parse(t.getItem(Hd)??"null");if(!is(n)||n.version!==Mx)return Cc();const r=Lx(n.activeAgent)?n.activeAgent:"customer-agent",s=is(n.agents)?n.agents:{},i={};for(const o of qd){const c=zx(s[o],o);c&&(i[o]=c)}return{version:2,activeAgent:r,agents:i}}catch{return Cc()}}function Rc(t,n=localStorage){try{n.setItem(Hd,JSON.stringify(t))}catch{}}function Tx(t,n,r){const s=new Set(n.data.map(c=>c.workspaceId)),i=r?n.nextCursor?[...n.data,...t.filter(c=>!s.has(c.workspaceId))]:n.data:[...t,...n.data],o=new Set;return i.filter(c=>o.has(c.workspaceId)?!1:(o.add(c.workspaceId),!0))}function Vd(t,n,r){const s=new Set(n.data.map(u=>u.id)),i=new Map(n.data.map(u=>[u.id,u])),o=new Set(t.map(u=>u.id)),c=r?n.nextCursor?[...n.data,...t.filter(u=>!s.has(u.id))]:n.data:[...t.map(u=>i.get(u.id)??u),...n.data.filter(u=>!o.has(u.id))],d=new Set;return c.filter(u=>d.has(u.id)?!1:(d.add(u.id),!0))}async function Nx(t,n,r,s){if(n.stale)return n;const i=new Set(n.data.map(f=>f.id)),o=new Set(t.filter(f=>f.status==="running"&&f.id!==s&&!i.has(f.id)).map(f=>f.id));if(o.size===0||!n.nextCursor)return n;let c=[...n.data],d=n.nextCursor,u=n.watermark;const g=new Set;for(;d&&o.size>0;){const f=d;if(g.has(f))return{data:c,nextCursor:f,watermark:u,stale:!0};g.add(f);const x=await r(f);if(x.stale)return{data:c,nextCursor:f,watermark:u,stale:!0};c=Vd(c,x,!1);for(const y of x.data)o.delete(y.id);d=x.nextCursor,u=x.watermark??u}return{data:c,nextCursor:d,watermark:u}}function _x(t,n){return!n||t.some(r=>r.id===n.id)?[...t]:[n,...t]}function zx(t,n){if(!is(t))return null;const r=Array.isArray(t.workspaces)?t.workspaces.filter(i=>is(i)&&i.agentType===n&&typeof i.workspaceId=="string"&&typeof i.name=="string"&&Array.isArray(i.roots)&&i.roots.every(o=>typeof o=="string")&&typeof i.order=="number"&&(i.canCreateSession===void 0||typeof i.canCreateSession=="boolean")):[],s={};if(is(t.sessions))for(const[i,o]of Object.entries(t.sessions))!is(o)||!Array.isArray(o.data)||(s[i]={data:o.data.filter(c=>is(c)&&c.agentType===n&&typeof c.id=="string"),nextCursor:typeof o.nextCursor=="string"?o.nextCursor:null,loaded:o.loaded===!0});return{workspaces:r,nextCursor:typeof t.nextCursor=="string"?t.nextCursor:null,watermark:typeof t.watermark=="string"?t.watermark:null,expandedWorkspaceIds:Array.isArray(t.expandedWorkspaceIds)?t.expandedWorkspaceIds.filter(i=>typeof i=="string"):[],selectedWorkspaceId:typeof t.selectedWorkspaceId=="string"?t.selectedWorkspaceId:null,selectedSessionId:typeof t.selectedSessionId=="string"?t.selectedSessionId:null,sidebarScrollTop:typeof t.sidebarScrollTop=="number"&&t.sidebarScrollTop>=0?t.sidebarScrollTop:0,sessions:s}}function Lx(t){return typeof t=="string"&&qd.includes(t)}function is(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Px(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\/]+[\\/][^\\/]+/.test(t)}function Dx(t,n){if(n.webShell||n.isInvalid||!n.supported)return null;const r=t.description;return!r||/[\0\r\n]/.test(r)||!Px(r)?null:r}function Wx(t){return{request:(n,r)=>t.fileWorkspaceRequest(n,r),subscribe:(n,r)=>n!=="fs:event"?()=>{}:t.onFileWorkspaceEvent(r)}}function Bx(t){try{const n=new URL(t);return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.toString()}catch{return null}}async function Fx(){var t;try{const n=window.sharedServiceApi;if(!(n!=null&&n.request))return null;const r=await n.request("/api/flow-studio/config","GET");if(r.status!==200)return null;const s=(t=JSON.parse(r.body).entryUrl)==null?void 0:t.trim();return s?Bx(s):null}catch{return null}}function Ox({authoritativeStatus:t,locallyRunning:n,needsInput:r,stale:s}){return t==="failed"||t==="error"?"error":s&&!n?"stale":n||t==="running"?r?"needs-input":"running":"idle"}function $x(t,n){const r=new Set;t&&r.add(t);for(const s of n)s&&r.add(s);return[...r]}function Ux(t,n,r){return[...t].filter(s=>!n.has(s)&&!r.has(s))}function Ec(t,n){var i;const r={},s={};for(const[o,c]of Object.entries(t)){const d=c.data;r[o]=Qo(d.filter(u=>!u.parentSessionId),n);for(const u of d.filter(g=>g.parentSessionId))(s[i=u.parentSessionId]??(s[i]=[])).push(u)}for(const o of Object.values(s))o.sort((c,d)=>c.created.localeCompare(d.created));return{roots:r,children:s,projectIds:new Set(Object.entries(t).filter(([,o])=>o.loaded).map(([o])=>o))}}function Mc(t,n,r){return t==="codex"&&(n==null?void 0:n.canCreateSession)!==!1?!0:r}function Bo(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 Ac(){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 Tc(t,n){n&&t.detail>0&&t.currentTarget.blur()}function Hx(){const t=document.activeElement;t instanceof HTMLElement&&(t.matches("input, textarea, select")||t.isContentEditable)&&t.blur()}function Kx(){var Qr,$s,Fn,xr,Vn,On;const[t]=a.useState(Ax),n=t.activeAgent,r=t.agents[n]??Ic(),[s]=a.useState(()=>Ec(r.sessions,n)),i=a.useRef(t),[o,c]=a.useState(n),d=a.useRef(o);d.current=o;const[u,g]=a.useState(r.workspaces.map(Bo)),[f,x]=a.useState(r.nextCursor),[y,v]=a.useState(r.watermark),[S,E]=a.useState(!1),[C,I]=a.useState(!1),[j,k]=a.useState(null),[W,ee]=a.useState(!1),[N,T]=a.useState(s.roots),[A,R]=a.useState(""),[L,H]=a.useState(!1),[de,Fe]=a.useState(10),[fe,je]=a.useState(null),[ze,Ge]=a.useState(!1),[Ke,Ct]=a.useState(null),[it,te]=a.useState(!1),[ge,Qe]=a.useState(null),B=a.useRef(!1),[G,Y]=a.useState([]),[ae,me]=a.useState(s.children),le=a.useRef(N),Se=a.useRef(ae);le.current=N,Se.current=ae;const[Te,mt]=a.useState(s.projectIds),[$e,yt]=a.useState(new Set),[st,tt]=a.useState({}),[It,ft]=a.useState(new Set),[P,K]=a.useState(Object.fromEntries(Object.entries(r.sessions).map(([m,_])=>[m,_.nextCursor]))),X=a.useRef(new Map),J=a.useRef(new Map),[ne,ct]=a.useState(r.selectedWorkspaceId),[ht,ot]=a.useState(r.selectedSessionId),Ue=a.useRef(ne),$t=a.useRef(ht);Ue.current=ne,$t.current=ht;const[tn,Xe]=a.useState(new Set),[pt,Dt]=a.useState(new Set(r.expandedWorkspaceIds)),[Bt,gn]=a.useState(new Set),[Ut,Re]=a.useState(!1),[Tn,Nn]=a.useState(!1),[_n,Z]=a.useState(!1),[_t,Xt]=a.useState("settings"),Tt=et(m=>m.setTodos),Et=fn(m=>m.skin),at=fn(m=>m.layout),Ft=fn(m=>m.wakeEnabled),qt=fn(m=>m.wakeWord),zt=fn(m=>m.setSkin),Sn=fn(m=>m.setLayout),tr=fn(m=>m.setWakeEnabled),Qn=fn(m=>m.setWakeWord),Cn=fn(m=>m.autoSpeak),Un=fn(m=>m.setAutoSpeak),Yt=fn(m=>m.runningFirst),Xn=fn(m=>m.setRunningFirst),mn=fn(m=>m.pinnedSessionIds),Ie=fn(m=>m.togglePinnedSession),xt=fn(m=>m.removePinnedSessions),Vt=new Set(mn),Yn=et(m=>m.runningSessionId),Hn=et(vp(m=>Object.entries(m.messagesBySession).filter(([,_])=>_.some(U=>U.askUser&&!U.askUser.answered)).map(([_])=>_))),on=a.useCallback((m,_=m.projectId)=>Ox({authoritativeStatus:m.status,locallyRunning:Yn===m.id,needsInput:Hn.includes(m.id),stale:!!(_&&(It.has(_)||st[_]))}),[st,Yn,Hn,It]),O=a.useCallback(m=>{const _=on(m);return _==="running"||_==="needs-input"},[on]),Ye=()=>{Dt(new Set),Xe(new Set(Object.keys(ae)))},qn=()=>{const m=u.filter(U=>!Bt.has(U.id)),_=m.map(U=>U.id);Dt(new Set(_)),Xe(new Set);for(const U of m){const V=U.id;if(gt.current.has(V))continue;const Q=yn.current.has(V),we=Mc(d.current,U,Q);cn(V,{refresh:we,background:Q})}},Ot=Fo(),q=Tu(),re=Ot&&q,[ce,Ce]=a.useState(!1),[He,xn]=a.useState(!1),[Jn,Lt]=a.useState("files"),[nn,Gt]=a.useState(null),[Er,Mr]=a.useState(null),Nt=a.useMemo(()=>{var m;return!Ot&&typeof((m=window.agentApi)==null?void 0:m.fileWorkspaceRequest)=="function"?Wx(window.agentApi):null},[Ot]),as=a.useCallback(m=>{if(Ot){oh(m);return}Nt&&(Lt("files"),xn(!0),Gt(m),Mr(_=>({path:m,requestId:((_==null?void 0:_.requestId)??0)+1})))},[Nt,Ot]);a.useEffect(()=>{Gt(null),Mr(null)},[ne]);const[nr,bn]=a.useState(!1),[zn,rn]=a.useState(null),[dr,Hr]=a.useState(0),[ls,ur]=a.useState(void 0),an=a.useRef(null),dt=a.useRef(!1),[Jt,Ln]=a.useState(null),In=a.useRef(null),Pn=a.useRef(!1),Zt=a.useRef(u);Zt.current=u;const rr=a.useRef(Bt);rr.current=Bt;const yn=a.useRef(Te);yn.current=Te;const gt=a.useRef($e);gt.current=$e;const Dn=a.useRef(null);a.useEffect(()=>{document.documentElement.setAttribute("data-skin",Et)},[Et]),a.useEffect(()=>{document.body.classList.toggle("layout-compact",at==="compact")},[at]),a.useEffect(()=>{var V;const m=u.map((Q,we)=>({agentType:o,workspaceId:Q.id,name:Q.name,roots:Q.description?[Q.description]:[],order:we,updatedAt:Q.updated||void 0,source:Q.source??(Q.agentType==="claude-code"?"derived":"native"),canCreateSession:Q.canCreateSession})),_=Object.fromEntries(u.map(Q=>[Q.id,{data:[...N[Q.id]??[],...Object.values(ae).flat().filter(we=>(N[Q.id]??[]).some(ve=>ve.id===we.parentSessionId))],nextCursor:P[Q.id]??null,loaded:Te.has(Q.id)}])),U={...i.current,version:2,activeAgent:o,agents:{...i.current.agents,[o]:{workspaces:m,nextCursor:f,watermark:y,expandedWorkspaceIds:[...pt],selectedWorkspaceId:ne,selectedSessionId:ht,sidebarScrollTop:((V=Dn.current)==null?void 0:V.scrollTop)??0,sessions:_}}};i.current=U,Rc(U)},[o,ae,pt,Te,u,ne,ht,P,N,f,y]);const sn=a.useCallback(()=>{if(!window.agentApi||!Ft||dt.current||an.current)return;const m=()=>{gf()&&!an.current&&(an.current=xf({wakeWord:qt,onWake:_=>{var U;ur(_),Hr(V=>V+1),(U=window.agentApi)==null||U.showWindow()},onError:_=>console.warn("[wake]",_)}))};typeof window.agentApi.wakeStart=="function"?(dt.current=!0,window.agentApi.wakeStart(qt).then(_=>{_.ok||(dt.current=!1,m())}).catch(()=>{dt.current=!1,m()})):m()},[Ft,qt]);a.useEffect(()=>{var m;if((m=window.agentApi)!=null&&m.onWake)return window.agentApi.onWake(_=>{dt.current=!1,ur(_),Hr(U=>U+1)})},[]),a.useEffect(()=>{var m;if((m=window.agentApi)!=null&&m.onWakeAiHub)return window.agentApi.onWakeAiHub(()=>{Z(!0),Sn("focus")})},[]),a.useEffect(()=>{var m;if((m=window.agentApi)!=null&&m.onWakeCommand)return window.agentApi.onWakeCommand(_=>{var we;const U=((_==null?void 0:_.text)||"").trim();if(!U)return;const V=In.current&&Date.now()<In.current.until?In.current:null;if(V){V.until=Date.now()+9e4,ot(V.sessionId),(we=window.agentApi)==null||we.wakeConversation(!0),Ln({text:U,projectId:null,sessionId:V.sessionId,nonce:Date.now()}),Ve(`语音追问:${U.length>40?U.slice(0,40)+"…":U}`),en("success"),setTimeout(()=>Ve(null),4e3);return}const Q=Zt.current.find(ve=>ve.name&&U.includes(ve.name)&&!rr.current.has(ve.id));Q&&(ct(Q.id),Dt(ve=>{const Le=new Set(ve);return Le.add(Q.id),Le})),ot(null),Pn.current=!0,Un(!0),Ln({text:U,projectId:(Q==null?void 0:Q.id)??null,nonce:Date.now()}),Ve(`语音指令:${U.length>40?U.slice(0,40)+"…":U}${Q?`(项目:${Q.name})`:""}`),en("success"),setTimeout(()=>Ve(null),4e3)})},[]);const qr=a.useCallback(async()=>{window.agentApi&&(sn(),await window.agentApi.hideWindow())},[sn]),Rn=a.useCallback(m=>{Re(!1),rn({right:m.right,bottom:m.bottom}),bn(_=>!_)},[]),Vr=a.useCallback(()=>{bn(!1),Re(m=>!m)},[]);a.useEffect(()=>{if(!nr)return;const m=()=>{const U=document.querySelector(".chat-header-action--appearance");if(!U)return;const V=U.getBoundingClientRect();rn(Q=>(Q==null?void 0:Q.right)===V.right&&Q.bottom===V.bottom?Q:{right:V.right,bottom:V.bottom})},_=window.requestAnimationFrame(m);return window.addEventListener("resize",m),()=>{window.cancelAnimationFrame(_),window.removeEventListener("resize",m)}},[at,nr]),a.useEffect(()=>{window.agentApi&&sn()},[sn]),a.useEffect(()=>{const m=()=>{var _;(_=an.current)==null||_.stop(),an.current=null};return window.addEventListener("focus",m),()=>window.removeEventListener("focus",m)},[]),a.useEffect(()=>{var m,_;Ft||((m=an.current)==null||m.stop(),an.current=null,dt.current=!1,(_=window.agentApi)==null||_.wakeStop())},[Ft]),a.useEffect(()=>{!Ft||!window.agentApi||dt.current&&window.agentApi.wakeStart(qt)},[qt]),a.useEffect(()=>()=>{var m;(m=an.current)==null||m.stop()},[]);const pr=[...Object.values(N).flat(),...Object.values(ae).flat()],Ar=hm(pr,m=>Vt.has(m.id)),Ps=Object.entries(N).flatMap(([m,_])=>_.filter(U=>Vt.has(U.id)).map(U=>({projectId:m,session:U,created:U.created}))),cs=Qo(Ps,o),En=Yt?ac(cs,({session:m})=>O(m)):cs,Kt=pr,b=A.trim().toLowerCase(),M=b?Ar.filter(m=>m.title.toLowerCase().includes(b)||(m.cwd||"").toLowerCase().includes(b)):null,F=ht?Kt.find(m=>m.id===ht):void 0,ie=F==null?void 0:F.title,ue=(F==null?void 0:F.cwd)||((Qr=u.find(m=>m.id===ne))==null?void 0:Qr.description)||null,Je=u.filter(m=>!Bt.has(m.id)).map(m=>m.id),Ne=[...u.filter(m=>!Bt.has(m.id)),...u.filter(m=>Bt.has(m.id))],Ee=Je.length>0&&Je.every(m=>!pt.has(m)),[qe,vt]=a.useState(300),[Mn,vn]=a.useState(!1),ds=a.useRef(!1),us=a.useRef(0),Gr=a.useRef(0),Tr=a.useCallback(m=>{if(!ds.current)return;const _=Math.min(480,Math.max(160,Gr.current+m.clientX-us.current));vt(_)},[]),Nr=a.useCallback(()=>{ds.current=!1,vn(!1),document.removeEventListener("mousemove",Tr),document.removeEventListener("mouseup",Nr)},[Tr]),ps=a.useCallback(m=>{ds.current=!0,vn(!0),us.current=m.clientX,Gr.current=qe,document.addEventListener("mousemove",Tr),document.addEventListener("mouseup",Nr)},[qe,Tr,Nr]),[fr,Ve]=a.useState(null),[hr,en]=a.useState("success"),[gr,fs]=a.useState(null),[hs,Ds]=a.useState(!1),Ws=a.useCallback(async()=>{if(!hs){Ds(!0);try{const m=await Fx();if(m){Z(!1),Ce(!1),fs(m);return}Ve("Flow Studio 入口不可用,请检查服务配置"),en("error"),setTimeout(()=>Ve(null),4e3)}finally{Ds(!1)}}},[hs]),ln=m=>{Ue.current=m.projectId,$t.current=m.sessionId,ct(m.projectId),ot(m.sessionId),m.sessionId||Tt([])},wn=m=>{var ve;if(m===d.current)return;const _=d.current,U=i.current.agents[_];U&&(i.current={...i.current,agents:{...i.current.agents,[_]:{...U,sidebarScrollTop:((ve=Dn.current)==null?void 0:ve.scrollTop)??U.sidebarScrollTop}}});const V=i.current.agents[m]??Ic(),Q=Ec(V.sessions,m),we=V.workspaces.map(Bo);d.current=m,Zt.current=we,c(m),g(we),x(V.nextCursor),v(V.watermark),E(!1),I(!1),k(null),le.current=Q.roots,Se.current=Q.children,T(Q.roots),me(Q.children),mt(Q.projectIds),yn.current=Q.projectIds,yt(new Set),gt.current=new Set,tt({}),ft(new Set),K(Object.fromEntries(Object.entries(V.sessions).map(([Le,Ze])=>[Le,Ze.nextCursor]))),Dt(new Set(V.expandedWorkspaceIds)),gn(new Set),ln({projectId:V.selectedWorkspaceId,sessionId:V.selectedSessionId}),window.requestAnimationFrame(()=>{Dn.current&&(Dn.current.scrollTop=V.sidebarScrollTop)}),Wn(m,{refresh:V.workspaces.length>0,since:V.watermark})},[gs,_e]=a.useState([]),sr=a.useCallback(m=>{_e(_=>_.filter(U=>U.id!==m))},[]),ir=a.useCallback(m=>{const _=crypto.randomUUID();_e(U=>[...U,{...m,id:_}]),setTimeout(()=>sr(_),12e3)},[sr]);async function Wn(m=d.current,_={}){if(!window.agentApi)return;const U=(J.current.get(m)??0)+1;J.current.set(m,U),E(!0),k(null);try{const V=await window.agentApi.listAgentWorkspaces(m,{cursor:_.cursor,limit:50,refresh:_.refresh,since:_.refresh?_.since??y:null});if(d.current!==m||J.current.get(m)!==U)return;const Q=Zt.current.map((Me,bt)=>({agentType:m,workspaceId:Me.id,name:Me.name,roots:Me.description?[Me.description]:[],order:bt,updatedAt:Me.updated,source:Me.source??(m==="claude-code"?"derived":"native"),canCreateSession:Me.canCreateSession})),ve=Tx(Q,V,!_.cursor).map(Bo);Zt.current=ve,g(ve),x(V.nextCursor),v(V.watermark),I(V.stale===!0);const Le=new Set(ve.map(Me=>Me.id)),Ze=Ue.current;Ze&&!Le.has(Ze)&&ln(Ao);const Qt=new Set([...yn.current].filter(Me=>Le.has(Me)));Ze&&Le.has(Ze)&&Qt.add(Ze),T(Me=>Object.fromEntries(Object.entries(Me).filter(([bt])=>Le.has(bt)))),mt(Me=>{const bt=new Set([...Me].filter(jn=>Le.has(jn)));return yn.current=bt,bt}),yt(Me=>{const bt=new Set([...Me].filter(jn=>Le.has(jn)));return gt.current=bt,bt}),tt(Me=>Object.fromEntries(Object.entries(Me).filter(([bt])=>Le.has(bt))));const An=new Set;if(await Promise.all(ve.map(async Me=>{Me.description&&!await window.agentApi.checkProjectPath(Me.description)&&An.add(Me.id)})),d.current!==m||J.current.get(m)!==U)return;if(gn(An),_.refreshLoadedSessions!==!1)for(const Me of Qt)An.has(Me)||gt.current.has(Me)||cn(Me,{refresh:!0,background:!0})}catch(V){d.current===m&&(Zt.current.length>0&&I(!0),k(V instanceof Error?V.message:"目录加载失败"))}finally{d.current===m&&J.current.get(m)===U&&E(!1)}}async function cn(m,_={}){var ve;const U=window.agentApi;if(!U)return;const V=d.current,Q=`${V}:${m}`,we=(X.current.get(Q)??0)+1;X.current.set(Q,we),yt(Le=>{const Ze=new Set(Le).add(m);return gt.current=Ze,Ze}),tt(Le=>{if(!(m in Le))return Le;const Ze={...Le};return delete Ze[m],Ze});try{const Le=await U.listAgentWorkspaceSessions(V,m,{cursor:_.cursor,limit:20,refresh:_.refresh});if(d.current!==V||X.current.get(Q)!==we)return;const Ze=le.current[m]??[],Qt=_.pendingSession?{..._.pendingSession,projectId:m}:void 0,An=Qt?[Qt,...Ze.filter(nt=>nt.id!==Qt.id)]:Ze,Me=new Set(An.map(nt=>nt.id)),bt=[...An,...[...Me].flatMap(nt=>Se.current[nt]??[])],jn=_.refresh&&!_.cursor?await Nx(bt,Le,nt=>U.listAgentWorkspaceSessions(V,m,{cursor:nt,limit:200,refresh:!1}),Qt==null?void 0:Qt.id):Le;if(d.current!==V||X.current.get(Q)!==we)return;const Mt=Vd(bt,jn,!_.cursor).map(nt=>({...nt,projectId:nt.projectId??m})),or=Qo(Mt.filter(nt=>!nt.parentSessionId),V),ar=Ue.current,Gn=$t.current,Xr=_x(or,Qt);ar===m&&Gn&&!Mt.some(nt=>nt.id===Gn)&&!Xr.some(nt=>nt.id===Gn)&&ln(Ao);const br={};for(const nt of Mt.filter(ut=>ut.parentSessionId))(br[ve=nt.parentSessionId]??(br[ve]=[])).push(nt);for(const nt of Object.values(br))nt.sort((ut,bs)=>ut.created.localeCompare(bs.created));K(nt=>({...nt,[m]:jn.nextCursor})),ft(nt=>{const ut=new Set(nt);return jn.stale?ut.add(m):ut.delete(m),ut});const Ht={...le.current,[m]:Xr},lr={...Se.current};for(const nt of Me)delete lr[nt];for(const[nt,ut]of Object.entries(br))lr[nt]=ut;le.current=Ht,Se.current=lr,T(Ht),me(lr),mt(nt=>{const ut=new Set(nt).add(m);return yn.current=ut,ut})}catch(Le){if(X.current.get(Q)!==we)return;ft(Ze=>new Set(Ze).add(m)),tt(Ze=>({...Ze,[m]:Le instanceof Error?Le.message:"会话加载失败"}))}finally{X.current.get(Q)===we&&yt(Le=>{const Ze=new Set(Le);return Ze.delete(m),gt.current=Ze,Ze})}}const ci=async m=>{if(!window.agentApi)return;const _=await window.agentApi.listChildSessions(m);me(U=>({...U,[m]:_.sort((V,Q)=>V.created<Q.created?-1:1)}))},di=async(m,_)=>{if(!window.agentApi)return;const U=Zt.current.find(V=>V.id===m);if(!U||U.canCreateSession===!1){Ve("请先选择目录"),en("info"),setTimeout(()=>Ve(null),3e3);return}if(!B.current){B.current=!0,Qe({projectId:m,agentType:_});try{const V=(U==null?void 0:U.source)==="imported"?void 0:m,Q=await window.agentApi.createSession("新会话",V,_,U==null?void 0:U.description);if(d.current!==_)return;const we=Q.projectId===m?Q:{...Q,projectId:m},ve={...le.current,[m]:[we,...(le.current[m]??[]).filter(Le=>Le.id!==Q.id)]};le.current=ve,T(ve),ln({projectId:m,sessionId:Q.id}),re&&Ce(!1),_==="customer-agent"&&cn(m,{refresh:!0,background:!0,pendingSession:we})}catch(V){Ve(V instanceof Error?V.message:"新建会话失败"),en("error"),setTimeout(()=>Ve(null),3e3)}finally{B.current=!1,Qe(null)}}},ui=()=>{const m=Zt.current.find(_=>_.id===ne);if(!ne||(m==null?void 0:m.canCreateSession)===!1){Ve("请先选择目录"),en("info"),setTimeout(()=>Ve(null),3e3);return}di(ne,o)};a.useEffect(()=>{var m;window.agentApi&&(Wn(d.current,{refresh:(((m=i.current.agents[d.current])==null?void 0:m.workspaces.length)??0)>0}),Ui.getState().loadFromSystem(),window.agentApi.getRuntimeHealth().then(Y).catch(()=>{}))},[]),a.useEffect(()=>{const m=window.setInterval(()=>{document.visibilityState!=="visible"||S||Wn(o,{refresh:!0,since:y,refreshLoadedSessions:!1})},15e3);return()=>window.clearInterval(m)},[o,S,y]),a.useEffect(()=>{if(!window.agentApi)return;let m=!1;const _=()=>{if(m||document.visibilityState!=="visible")return;const Q=$x(ne,pt),we=Ux(Q,rr.current,gt.current);for(const ve of we)cn(ve,{refresh:!0,background:yn.current.has(ve)})},U=()=>{document.visibilityState==="visible"&&_()},V=window.setInterval(_,1e4);return window.addEventListener("focus",_),document.addEventListener("visibilitychange",U),()=>{m=!0,window.clearInterval(V),window.removeEventListener("focus",_),document.removeEventListener("visibilitychange",U)}},[o,pt,ne]),a.useEffect(()=>{if(!ne||!window.agentApi)return;const m=u.find(U=>U.id===ne),_=m==null?void 0:m.description;_&&window.agentApi.setProjectWorkingDir(_)},[ne,u]);const Bs=m=>{ln(lc(m));const _=!pt.has(m);if(Dt(U=>{const V=new Set(U);return _?V.add(m):V.delete(m),V}),_&&!gt.current.has(m)){const U=yn.current.has(m),V=Zt.current.find(we=>we.id===m),Q=Mc(d.current,V,U);cn(m,{refresh:Q,background:U})}},mr=async m=>{if(!window.agentApi)throw new Error("agentApi 未就绪,请重启应用");const _=m.replace(/\\/g,"/"),U=_.split("/").filter(Boolean),V=U[U.length-1]||_||"导入的项目",Q=await window.agentApi.importAgentWorkspace(d.current,_,V);await Wn(d.current,{refresh:!0,refreshLoadedSessions:!1}),ln(lc(Q.workspace.workspaceId)),await cn(Q.workspace.workspaceId,{refresh:!0}),Dt(we=>{const ve=new Set(we);return ve.add(Q.workspace.workspaceId),ve}),Ve(Q.existing?"该文件夹已在当前 Agent 的目录中":`已导入:${Q.workspace.name}`),en(Q.existing?"info":"success"),setTimeout(()=>Ve(null),3e3)},dn=async()=>{try{if(!window.agentApi){Ve("agentApi 未就绪,请重启应用"),en("error");return}if(Ot){ee(!0);return}const m=await window.agentApi.openFileDialog();if(console.log("[import] selectedPath:",m),!m)return;await mr(m)}catch(m){console.error("[import] error:",m),Ve(m instanceof Error?m.message:String(m)),en("error"),setTimeout(()=>Ve(null),5e3)}},Fs=async m=>{if(window.agentApi)try{await window.agentApi.deleteProject(m),ne===m&&(ct(null),ot(null),Tt([])),Ve("项目删除成功"),en("success"),setTimeout(()=>Ve(null),2500),await Wn()}catch(_){Ve(_ instanceof Error?_.message:"项目删除失败"),en("error"),setTimeout(()=>Ve(null),4e3)}},ms=(m,_,U)=>{var we;const V=(we=window.agentApi)==null?void 0:we.showDirectoryContextMenu,Q=Dx(_,{isInvalid:U,supported:typeof V=="function",webShell:Ot});!Q||!V||(m.preventDefault(),V(Q).catch(ve=>{Ve(ve instanceof Error?ve.message:"无法打开当前文件夹"),en("error"),setTimeout(()=>Ve(null),4e3)}))},Os=(m,_)=>{je({session:m,anchor:_})},Kr=(m,_)=>{const U=_.getBoundingClientRect();Ct({project:m,anchor:{top:U.top,left:U.left,width:U.width,height:U.height}})},Bn=async()=>{if(!window.agentApi||!Ke||it)return;const{project:m}=Ke,_=d.current;te(!0);try{let U=null,V=0;do{const Q=await window.agentApi.listAgentWorkspaceSessions(_,m.id,{cursor:U,limit:50,refresh:U===null});for(const we of Q.data)await window.agentApi.deleteSession(we.id),V+=1;U=Q.data.length>0?Q.nextCursor:null}while(U);Ue.current===m.id&&ln(Ao),Ve(V>0?`已删除目录「${m.name}」及 ${V} 个会话`:`已删除目录「${m.name}」`),en("success"),setTimeout(()=>Ve(null),2500),await Wn(_,{refresh:!0})}catch(U){Ve(U instanceof Error?U.message:"目录删除失败"),en("error"),setTimeout(()=>Ve(null),4e3)}finally{te(!1),Ct(null)}},pi=async()=>{if(!window.agentApi||!fe||ze)return;const{session:m}=fe;Ge(!0);try{await window.agentApi.deleteSession(m.id);const _=m.projectId??Ue.current,U=m.agentType;if(_){const we=`${U}:${_}`;X.current.set(we,(X.current.get(we)??0)+1)}const V=bm(le.current,Se.current,[],m.id);le.current=V.sessionsByProject,Se.current=V.childSessionsByParent,T(V.sessionsByProject),me(V.childSessionsByParent),xt(V.removedIds);const Q=i.current.agents[U];if(Q){const we={...i.current,agents:{...i.current.agents,[U]:mm(Q,V.removedIds)}};i.current=we,Rc(we)}$t.current&&V.removedIds.includes($t.current)&&ln({projectId:Ue.current,sessionId:null}),Ve("会话删除成功"),en("success"),setTimeout(()=>Ve(null),2500),je(null),_&&cn(_,{refresh:!0,background:!0})}catch(_){Ve(_ instanceof Error?_.message:"会话删除失败"),en("error"),setTimeout(()=>Ve(null),4e3)}finally{Ge(!1)}},_r=[{id:"settings",label:"设置"},{id:"mcp",label:"MCP"},{id:"memory",label:"记忆"},{id:"skill",label:"技能"},{id:"agent",label:"智能体"},{id:"lsp",label:"LSP"}],xs=(m,_)=>{const U=ht===m.id,V=Eo(on(m,_)),Q=ae[m.id]??[],we=!tn.has(m.id);return e.jsxs("div",{className:"sidebar-session-tree",children:[e.jsx(Do,{session:{id:m.id,title:m.title,visualState:V,statusLabel:Mo[V],occupiedExternally:m.agentType!=="codex"&&m.occupancy==="owned-externally",canDelete:m.canDelete,active:U,hasChildren:Q.length>0,expanded:we,compatibility:m.compatibility,pinned:Vt.has(m.id)},onSelect:()=>{re&&Ce(!1),ln(To(_,m.id)),Q.length>0&&Xe(ve=>{const Le=new Set(ve);return Le.has(m.id)?Le.delete(m.id):Le.add(m.id),Le})},onPin:()=>Ie(m.id),onDelete:ve=>Os(m,ve)}),e.jsx("div",{className:"sidebar-child-sessions",style:{maxHeight:we?Q.length*40:0,opacity:we?1:0},children:Q.map(ve=>{const Le=Eo(on(ve,_));return e.jsx(Do,{session:{id:ve.id,title:ve.title,visualState:Le,statusLabel:Mo[Le],occupiedExternally:ve.agentType!=="codex"&&ve.occupancy==="owned-externally",canDelete:ve.canDelete,active:ht===ve.id,child:!0,compatibility:ve.compatibility},deleteLabel:"删除子会话",onSelect:()=>{re&&Ce(!1),ln(To(_,ve.id))},onDelete:Ze=>Os(ve,Ze)},ve.id)})})]},m.id)};return e.jsxs("div",{className:"app-shell",style:{display:"flex",height:Ot?"100dvh":"100vh",width:"100vw",background:"var(--bg-deepest)",position:"relative",overflow:"hidden"},children:[e.jsx(um,{}),e.jsx(pm,{}),!gr&&re&&ce&&e.jsx("div",{className:"mobile-drawer-scrim",onClick:()=>Ce(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:1150}}),!gr&&re&&!ce&&e.jsx("button",{className:"mobile-drawer-toggle",onClick:()=>Ce(!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}}),at!=="focus"&&!gr&&e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"app-sidebar",style:{width:qe,display:"flex",flexDirection:"column",background:"var(--bg-surface)",borderRight:"1px solid var(--border-subtle)",padding:"56px 0 0",position:"relative",zIndex:10,overflow:"hidden",...re?{position:"fixed",top:0,bottom:0,left:0,width:"min(82vw, 320px)",zIndex:1200,transform:ce?"translateX(0)":"translateX(-103%)",transition:"transform .24s ease",boxShadow:"12px 0 32px rgba(0,0,0,.5)",padding:"calc(env(safe-area-inset-top) + 12px) 0 0"}:{}},children:[e.jsx("div",{className:"app-sidebar-brand",style:{padding:"0 20px 10px"},children:e.jsxs("div",{className:"sidebar-brand-row",children:[e.jsx("div",{className:"sidebar-brand-mark","aria-hidden":"true",children:e.jsx(ia,{agentType:"customer-agent",size:24})}),e.jsx("span",{className:"sidebar-brand-name",children:"AgentRoam"}),!Ot&&e.jsx(Hm,{onOpenFlowStudio:Ws,openingFlowStudio:hs})]})}),e.jsx(Um,{value:o,health:G,onChange:wn}),e.jsxs("button",{type:"button",className:"sidebar-search-field",onClick:()=>{H(!0),Fe(10)},title:"搜索会话","aria-label":"搜索会话",children:[e.jsx(sa,{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:m=>{Ee?qn():Ye(),Tc(m,Ee)},title:Ee?"展开全部会话":"折叠全部会话","aria-label":Ee?"展开全部会话":"折叠全部会话","aria-pressed":Ee,disabled:Je.length===0,className:`ui-icon-button sidebar-collapse-all${Ee?" 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:Ee?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:m=>{Xn(!Yt),Tc(m,Yt)},title:Yt?"按新建时间排序":"进行中会话优先","aria-label":Yt?"按新建时间排序":"进行中会话优先","aria-pressed":Yt,className:`ui-icon-button sidebar-session-sort${Yt?" 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 dn(),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:Dn,className:"app-sidebar-scroll",onPointerDownCapture:Hx,onScroll:m=>{const _=m.currentTarget;if(_.scrollHeight-_.scrollTop-_.clientHeight<120&&f&&!S&&Wn(o,{cursor:f}),re){const V=_.getBoundingClientRect(),Q=_.querySelectorAll("[data-sidebar-project-id]");for(const we of Q){const ve=we.dataset.sidebarProjectId;if(!ve||!pt.has(ve))continue;const Le=we.getBoundingClientRect();if(Le.bottom<V.top||Le.bottom>V.bottom+120)continue;const Ze=P[ve];Ze&&!gt.current.has(ve)&&cn(ve,{cursor:Ze})}}},style:{minHeight:0,flex:1,overflow:"auto",padding:"0 10px"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:12},children:[En.length>0&&e.jsxs("section",{className:"sidebar-pinned-section","aria-label":"置顶会话",children:[e.jsx("div",{className:"sidebar-pinned-heading",children:"置顶"}),En.map(({projectId:m,session:_})=>xs(_,m))]}),Ne.map(m=>{var jn;const _=ne===m.id&&ht===null,U=pt.has(m.id),V=Te.has(m.id),Q=$e.has(m.id),we=st[m.id],ve=N[m.id]??[],Le=ve.filter(Mt=>!Vt.has(Mt.id)),Qt=Yt?ac(Le,O):Le,An=Qt.length>10,Me=Bt.has(m.id),bt=(ge==null?void 0:ge.agentType)===o&&ge.projectId===m.id;return e.jsxs("div",{className:"sidebar-project-block","data-sidebar-project-id":m.id,"aria-busy":Q,children:[e.jsxs("div",{className:`sidebar-row sidebar-project-row ${_&&!Me?"sidebar-row-active":""}`,onContextMenu:Mt=>ms(Mt,m,Me),style:{paddingRight:4,opacity:Me?.45:1},children:[e.jsxs("button",{className:"sidebar-project-button",onClick:()=>{Me||Bs(m.id)},disabled:Me,"aria-expanded":U,"aria-pressed":_,title:Me?`路径不存在:${m.description}`:m.name,style:{flex:1,display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"8px 10px",border:"none",background:"transparent",color:Me?"var(--text-muted)":_?"var(--accent)":"var(--text-secondary)",fontSize:13,fontWeight:_&&!Me?600:400,cursor:Me?"not-allowed":"pointer",textAlign:"left",transition:"color 0.15s"},children:[Me?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"})]}):m.canCreateSession===!1?e.jsx(qu,{size:13,"aria-hidden":"true",style:{flexShrink:0,opacity:_?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:_?1:.5},children:U?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:m.name})]}),o==="customer-agent"&&!Ot&&m.canCreateSession!==!1?e.jsx("button",{onClick:Mt=>{Mt.stopPropagation(),Fs(m.id)},title:"删除目录","aria-label":`删除目录:${m.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(Ac,{})}):Me?e.jsx("button",{onClick:Mt=>{Mt.stopPropagation(),Kr(m,Mt.currentTarget)},title:"删除失效目录","aria-label":`删除失效目录:${m.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(Ac,{})}):null,m.canCreateSession!==!1&&e.jsx("button",{type:"button",onClick:Mt=>{Mt.stopPropagation(),di(m.id,o)},title:bt?"正在创建会话":`新建 ${o==="customer-agent"?"Customer Agent":o==="claude-code"?"Claude Code":o==="codex"?"Codex":"OpenCode"} 会话`,"aria-label":bt?"正在创建会话":`在 ${m.name} 中新建会话`,"aria-busy":bt,disabled:ge!==null||Me||((jn=G.find(Mt=>Mt.agentType===o))==null?void 0:jn.available)===!1,className:"sidebar-runtime-create sidebar-project-add-action ui-icon-button ui-icon-button--small",children:bt?e.jsx(lt,{size:13,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):e.jsx($o,{size:13,"aria-hidden":"true"})})]}),e.jsx("div",{style:{overflow:"hidden",maxHeight:U?re?1e5:An?300:800:0,opacity:U?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:Mt=>{const or=Mt.currentTarget,ar=or.scrollHeight-or.scrollTop-or.clientHeight<80,Gn=P[m.id];ar&&Gn&&!Q&&cn(m.id,{cursor:Gn})},style:{display:"flex",flexDirection:"column",gap:1,marginTop:2,paddingLeft:10,paddingBottom:4,...An&&!re?{maxHeight:280,overflowY:"auto"}:{}},children:[Qt.map(Mt=>xs(Mt,m.id)),Q&&!V&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"正在加载会话..."}),we&&e.jsxs("div",{title:we,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 cn(m.id,{refresh:V,background:V}),style:{border:0,background:"transparent",color:"inherit",fontSize:11,cursor:"pointer",padding:0},children:"重试"})]}),It.has(m.id)&&!we&&e.jsx("div",{className:"sidebar-cache-state",children:"显示缓存,会话将在下次刷新时更新"}),ve.length===0&&V&&!Q&&!we&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"4px 10px",opacity:.7},children:"暂无会话"})]})})]},m.id)}),u.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"24px 10px",textAlign:"center",opacity:.7},children:S?"正在加载目录...":"暂无目录"}),u.length>0&&S&&e.jsx("div",{className:"sidebar-cache-state",children:"正在同步目录..."}),C&&!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 Wn(o,{refresh:u.length>0}),children:"重试"})]})]})}),e.jsx("div",{className:"sidebar-bottom-action",children:e.jsx("button",{type:"button",className:"sidebar-new-session-primary",disabled:ge!==null||ne!==null&&Bt.has(ne)||(($s=G.find(m=>m.agentType===o))==null?void 0:$s.available)===!1,"aria-busy":ge!==null,"aria-disabled":ge!==null||!ne||((Fn=u.find(m=>m.id===ne))==null?void 0:Fn.canCreateSession)===!1,title:ge?"正在创建会话":ne&&((xr=u.find(m=>m.id===ne))==null?void 0:xr.canCreateSession)!==!1?"新建会话":"请先选择目录",onClick:ui,children:ge?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:16,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}),e.jsx("span",{children:"正在创建..."})]}):e.jsxs(e.Fragment,{children:[e.jsx($o,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:"新建会话"})]})})})]}),fe&&e.jsx(bc,{message:gm(fe.session),anchor:fe.anchor,mobile:re,pending:ze,onCancel:()=>je(null),onConfirm:()=>void pi()}),Ke&&e.jsx(bc,{title:"删除失效目录",message:`目录「${Ke.project.name}」的路径(${Ke.project.description||"未知"})已不存在。删除将同时归档其下的全部会话记录,确定删除吗?`,anchor:Ke.anchor,mobile:re,pending:it,onCancel:()=>Ct(null),onConfirm:()=>void Bn()}),!re&&e.jsx("div",{className:`app-sidebar-resizer${Mn?" is-dragging":""}`,onMouseDown:ps,style:{left:qe}}),L&&e.jsx("div",{onClick:()=>H(!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:m=>m.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:A,onChange:m=>R(m.target.value),onKeyDown:m=>{m.key==="Escape"&&H(!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:[b&&M&&M.length>0&&e.jsxs("div",{style:{padding:"4px 10px 3px",fontSize:9,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-muted)"},children:[M.length," 个结果"]}),b&&M&&M.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"无匹配会话"}),!b&&Ar.length===0&&e.jsx("div",{style:{color:"var(--text-muted)",fontSize:12,padding:"16px 10px",textAlign:"center",opacity:.7},children:"暂无会话"}),(M??Ar.slice(0,de)).map(m=>{const _=ht===m.id,U=Eo(on(m));return e.jsx(Do,{session:{id:m.id,title:m.title,visualState:U,statusLabel:Mo[U],occupiedExternally:m.agentType!=="codex"&&m.occupancy==="owned-externally",canDelete:m.canDelete,active:_,child:!!m.parentSessionId,compatibility:m.compatibility,pinned:Vt.has(m.id)},onSelect:()=>{const V=m.projectId&&u.some(Q=>Q.id===m.projectId)?m.projectId:null;ln(To(V,m.id)),H(!1),re&&Ce(!1)},onPin:m.parentSessionId?void 0:()=>Ie(m.id),onDelete:V=>Os(m,V)},m.id)}),!b&&Ar.length>de&&e.jsx("button",{type:"button",onClick:()=>Fe(m=>m+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:"更多…"})]})]})})]}),e.jsx(Dd,{message:fr,type:hr}),e.jsxs("main",{className:`app-main${Nt?" file-workspace-capable":""}${He&&Nt?" file-workspace-open":""}${He&&Nt&&nn?" file-workspace-preview-open":""}`,style:{flex:1,overflow:"hidden",background:"var(--bg-workspace)",position:"relative",zIndex:5},children:[at==="focus"&&!gr&&e.jsx("button",{onClick:()=>Sn("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",{className:"app-chat-surface",style:{height:"100%",paddingTop:0,display:_n?"none":void 0,background:"var(--chat-history-bg)"},children:e.jsx(Kg,{activeAgentType:o,selectedProjectId:ne,selectedSessionId:ht,sessionTitle:ie,sessionSummary:F,workspacePath:ue,voiceCommand:Jt,onOpenSettings:Vr,settingsOpen:Ut,desktopLiveOpen:Tn,fileDrawerOpen:He,onOpenArtifact:as,onToggleFiles:Nt?()=>{xn(m=>!m),Lt("files")}:void 0,onOpenDesktopLive:!Ot&&((Vn=window.agentApi)!=null&&Vn.desktopLiveGetStatus)?()=>Nn(!0):void 0,onHideToBackground:()=>void qr(),onOpenHub:(On=window.agentApi)!=null&&On.hubGetConfig?()=>Z(!0):void 0,onToggleAppearance:Rn,appearanceOpen:nr,hideToBackgroundTitle:Ft?`隐藏到后台(说“${qt}”唤醒)`:"隐藏到后台",onSessionCreated:async(m,_)=>{var V;const U=Ue.current;ln({projectId:U,sessionId:m}),Pn.current&&(Pn.current=!1,In.current={sessionId:m,until:Date.now()+9e4},(V=window.agentApi)==null||V.wakeConversation(!0)),U&&await cn(U,{pendingSession:_})},onSubSessionCreated:async m=>{await ci(m)},onSelectSession:m=>{ot(m)},onSubAgentEvent:m=>{m.type==="started"?ir({type:"info",title:"子会话已启动",body:`${m.agentName}:${m.task.slice(0,60)}`,sessionId:m.subSessionId}):m.type==="completed"?ir({type:"success",title:"子会话已完成",body:`${m.agentName}:${m.task.slice(0,60)}`,sessionId:m.subSessionId}):ir({type:"error",title:"子会话出错",body:`${m.agentName}:${m.task.slice(0,60)}`,sessionId:m.subSessionId})},onMessageSent:(m,_)=>{T(U=>{const V={};for(const[Q,we]of Object.entries(U))V[Q]=we.map(ve=>ve.id===m?{...ve,title:_.slice(0,60)||ve.title}:ve);return V})},onRunComplete:async(m,_)=>{var we;const U=In.current,V=yg(U,_);In.current=V,V!==U&&((we=window.agentApi)==null||we.wakeConversation(!0));const Q=m||ne;Q&&await cn(Q,{refresh:!0,background:!0})}})}),_n&&e.jsx(am,{conversationId:ht,onExit:()=>Z(!1)}),Nt&&e.jsx(Ex,{open:He,tab:Jn,gateway:Nt,cwd:ue,selectedPath:nn,revealRequest:Er,onTabChange:Lt,onSelectPath:Gt,onClose:()=>xn(!1)}),gr&&e.jsx(qm,{entryUrl:gr,onBack:()=>fs(null)})]}),Tn&&e.jsx(Tm,{onClose:()=>Nn(!1)}),Ut&&$n.createPortal(e.jsx("div",{onClick:()=>Re(!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:m=>m.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:_r.map(m=>e.jsx("button",{onClick:()=>Xt(m.id),className:`settings-tab ${_t===m.id?"settings-tab-active":""}`,children:m.label},m.id))}),e.jsx("button",{onClick:()=>Re(!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:[_t==="settings"&&e.jsx(Im,{}),_t==="mcp"&&e.jsx(Nm,{}),_t==="memory"&&e.jsx(_m,{}),_t==="skill"&&e.jsx(Lm,{}),_t==="agent"&&e.jsx(Wm,{}),_t==="lsp"&&e.jsx(Fm,{})]})]})}),document.body),e.jsx("div",{className:"noise-overlay"}),nr&&zn&&$n.createPortal(e.jsx("div",{onClick:()=>bn(!1),style:{position:"fixed",inset:0,zIndex:1e4,WebkitAppRegion:"no-drag"},children:e.jsxs("div",{onClick:m=>m.stopPropagation(),className:"appearance-panel",style:{position:"absolute",left:Math.max(12,Math.min(zn.right-320,window.innerWidth-332)),top:zn.bottom+8,width:320,maxHeight:`calc(100vh - ${zn.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:Nu.map(m=>e.jsxs("button",{onClick:()=>zt(m.id),className:`appearance-choice ${Et===m.id?"appearance-choice-active":""}`,children:[e.jsx("span",{className:"appearance-swatch",style:{background:`linear-gradient(135deg, ${m.preview[0]} 55%, ${m.preview[1]} 55%)`}}),e.jsx("span",{className:"appearance-choice-label",style:{fontWeight:Et===m.id?600:400},children:m.label}),Et===m.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"})})]},m.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:_u.map(m=>e.jsx("button",{onClick:()=>Sn(m.id),title:m.description,className:`appearance-segment ${at===m.id?"appearance-segment-active":""}`,children:m.label},m.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:Cn,onChange:m=>Un(m.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:Ft,onChange:m=>tr(m.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:qt,onChange:m=>Qn(m.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(Jm,{open:W,onCancel:()=>ee(!1),onConfirm:async m=>{await mr(m),ee(!1)}}),e.jsx(Om,{trigger:dr,heardText:ls}),gs.length>0&&$n.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:gs.map(m=>e.jsxs("div",{style:{pointerEvents:"auto",width:320,background:"var(--bg-surface)",border:`1px solid ${m.type==="error"?"rgba(220,38,38,0.25)":m.type==="success"?"rgba(5,150,105,0.25)":"var(--border-default)"}`,borderLeft:`3px solid ${m.type==="error"?"var(--danger)":m.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:m.type==="error"?"var(--danger)":m.type==="success"?"var(--success)":"var(--accent)",display:"flex",alignItems:"center",gap:5},children:[m.type==="error"?"✕":m.type==="success"?"✓":"◎"," ",m.title]}),e.jsx("button",{onClick:()=>sr(m.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:_=>_.currentTarget.style.color="var(--text-primary)",onMouseLeave:_=>_.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:m.body}),m.sessionId&&e.jsx("button",{onClick:()=>{ot(m.sessionId),sr(m.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:_=>_.currentTarget.style.background="var(--accent-glow)",onMouseLeave:_=>_.currentTarget.style.background="var(--accent-dim)",children:"进入会话 →"})]},m.id))}),document.body)]})}export{Kx as default};